Refactor #5548 - For AutoComplete

pull/5677/head
tugcekucukoglu 2024-04-08 15:20:42 +03:00
parent a829fac29b
commit 916825df76
6 changed files with 64 additions and 36 deletions

View File

@ -9,6 +9,7 @@
*/ */
import { TransitionProps, VNode } from 'vue'; import { TransitionProps, VNode } from 'vue';
import { ComponentHooks } from '../basecomponent'; import { ComponentHooks } from '../basecomponent';
import { ChipPassThroughOptions } from '../chip';
import { InputTextPassThroughOptions } from '../inputtext'; import { InputTextPassThroughOptions } from '../inputtext';
import { PassThroughOptions } from '../passthrough'; import { PassThroughOptions } from '../passthrough';
import { ClassComponent, DesignToken, GlobalComponentConstructor, HintedString, Nullable, PassThrough } from '../ts-helpers'; import { ClassComponent, DesignToken, GlobalComponentConstructor, HintedString, Nullable, PassThrough } from '../ts-helpers';
@ -156,9 +157,10 @@ export interface AutoCompletePassThroughOptions {
*/ */
token?: AutoCompletePassThroughOptionType; token?: AutoCompletePassThroughOptionType;
/** /**
* Used to pass attributes to the token label's DOM element. * Used to pass attributes to the Chip.
* @see {@link ChipPassThroughOptions}
*/ */
tokenLabel?: AutoCompletePassThroughOptionType; tokenLabel?: ChipPassThroughOptions<AutoCompleteSharedPassThroughMethodOptions>;
/** /**
* Used to pass attributes to the remove token icon's DOM element. * Used to pass attributes to the remove token icon's DOM element.
*/ */

View File

@ -45,7 +45,7 @@
> >
<li <li
v-for="(option, i) of modelValue" v-for="(option, i) of modelValue"
:key="i" :key="`${i}_${getOptionLabel(option)}`"
:id="id + '_multiple_option_' + i" :id="id + '_multiple_option_' + i"
:class="cx('token', { i })" :class="cx('token', { i })"
role="option" role="option"
@ -55,11 +55,12 @@
:aria-posinset="i + 1" :aria-posinset="i + 1"
v-bind="ptm('token')" v-bind="ptm('token')"
> >
<slot name="chip" :value="option"> <slot name="chip" :value="option" :index="i" :removeCallback="(event) => removeOption(event, i)">
<span :class="cx('tokenLabel')" v-bind="ptm('tokenLabel')">{{ getOptionLabel(option) }}</span> <Chip :class="cx('tokenLabel')" :label="getOptionLabel(option)" :removeIcon="removeTokenIcon" removable @remove="removeOption($event, i)" :pt="ptm('tokenLabel')">
</slot> <template #removeicon>
<slot name="removetokenicon" :class="cx('removeTokenIcon')" :index="i" :onClick="(event) => removeOption(event, i)" :removeCallback="(event) => removeOption(event, i)"> <slot name="removetokenicon" :class="cx('removeTokenIcon')" :index="i" :removeCallback="(event) => removeOption(event, i)" />
<component :is="removeTokenIcon ? 'span' : 'TimesCircleIcon'" :class="[cx('removeTokenIcon'), removeTokenIcon]" @click="removeOption($event, i)" aria-hidden="true" v-bind="ptm('removeTokenIcon')" /> </template>
</Chip>
</slot> </slot>
</li> </li>
<li :class="cx('inputToken')" role="option" v-bind="ptm('inputToken')"> <li :class="cx('inputToken')" role="option" v-bind="ptm('inputToken')">
@ -182,9 +183,9 @@
</template> </template>
<script> <script>
import Chip from 'primevue/chip';
import ChevronDownIcon from 'primevue/icons/chevrondown'; import ChevronDownIcon from 'primevue/icons/chevrondown';
import SpinnerIcon from 'primevue/icons/spinner'; import SpinnerIcon from 'primevue/icons/spinner';
import TimesCircleIcon from 'primevue/icons/timescircle';
import InputText from 'primevue/inputtext'; import InputText from 'primevue/inputtext';
import OverlayEventBus from 'primevue/overlayeventbus'; import OverlayEventBus from 'primevue/overlayeventbus';
import Portal from 'primevue/portal'; import Portal from 'primevue/portal';
@ -968,7 +969,7 @@ export default {
Portal, Portal,
ChevronDownIcon, ChevronDownIcon,
SpinnerIcon, SpinnerIcon,
TimesCircleIcon Chip
}, },
directives: { directives: {
ripple: Ripple ripple: Ripple

View File

@ -12,12 +12,12 @@ import { ComponentHooks } from '../basecomponent';
import { PassThroughOptions } from '../passthrough'; import { PassThroughOptions } from '../passthrough';
import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers'; import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers';
export declare type ChipPassThroughOptionType = ChipPassThroughAttributes | ((options: ChipPassThroughMethodOptions) => ChipPassThroughAttributes | string) | string | null | undefined; export declare type ChipPassThroughOptionType<T = any> = ChipPassThroughAttributes | ((options: ChipPassThroughMethodOptions<T>) => ChipPassThroughAttributes | string) | string | null | undefined;
/** /**
* Custom passthrough(pt) option method. * Custom passthrough(pt) option method.
*/ */
export interface ChipPassThroughMethodOptions { export interface ChipPassThroughMethodOptions<T> {
/** /**
* Defines instance. * Defines instance.
*/ */
@ -37,7 +37,7 @@ export interface ChipPassThroughMethodOptions {
/** /**
* Defines parent options. * Defines parent options.
*/ */
parent: any; parent: T;
/** /**
* Defines passthrough(pt) options in global config. * Defines passthrough(pt) options in global config.
*/ */
@ -48,27 +48,27 @@ export interface ChipPassThroughMethodOptions {
* Custom passthrough(pt) options. * Custom passthrough(pt) options.
* @see {@link ChipProps.pt} * @see {@link ChipProps.pt}
*/ */
export interface ChipPassThroughOptions { export interface ChipPassThroughOptions<T = any> {
/** /**
* Used to pass attributes to the root's DOM element. * Used to pass attributes to the root's DOM element.
*/ */
root?: ChipPassThroughOptionType; root?: ChipPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the image's DOM element. * Used to pass attributes to the image's DOM element.
*/ */
image?: ChipPassThroughOptionType; image?: ChipPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the icon's DOM element. * Used to pass attributes to the icon's DOM element.
*/ */
icon?: ChipPassThroughOptionType; icon?: ChipPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the label' DOM element. * Used to pass attributes to the label' DOM element.
*/ */
label?: ChipPassThroughOptionType; label?: ChipPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the removeIcon's DOM element. * Used to pass attributes to the removeIcon's DOM element.
*/ */
removeIcon?: ChipPassThroughOptionType; removeIcon?: ChipPassThroughOptionType<T>;
/** /**
* Used to manage all lifecycle hooks. * Used to manage all lifecycle hooks.
* @see {@link BaseComponent.ComponentHooks} * @see {@link BaseComponent.ComponentHooks}

View File

@ -3313,9 +3313,9 @@
"name": "tokenLabel", "name": "tokenLabel",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "AutoCompletePassThroughOptionType", "type": "ChipPassThroughOptions<AutoCompleteSharedPassThroughMethodOptions>",
"default": "", "default": "",
"description": "Used to pass attributes to the token label's DOM element." "description": "Used to pass attributes to the Chip."
}, },
{ {
"name": "removeTokenIcon", "name": "removeTokenIcon",
@ -11969,7 +11969,7 @@
"name": "parent", "name": "parent",
"optional": false, "optional": false,
"readonly": false, "readonly": false,
"type": "any", "type": "T",
"default": "", "default": "",
"description": "Defines parent options." "description": "Defines parent options."
}, },
@ -11992,7 +11992,7 @@
"name": "root", "name": "root",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "ChipPassThroughOptionType", "type": "ChipPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the root's DOM element." "description": "Used to pass attributes to the root's DOM element."
}, },
@ -12000,7 +12000,7 @@
"name": "image", "name": "image",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "ChipPassThroughOptionType", "type": "ChipPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the image's DOM element." "description": "Used to pass attributes to the image's DOM element."
}, },
@ -12008,7 +12008,7 @@
"name": "icon", "name": "icon",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "ChipPassThroughOptionType", "type": "ChipPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the icon's DOM element." "description": "Used to pass attributes to the icon's DOM element."
}, },
@ -12016,7 +12016,7 @@
"name": "label", "name": "label",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "ChipPassThroughOptionType", "type": "ChipPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the label' DOM element." "description": "Used to pass attributes to the label' DOM element."
}, },
@ -12024,7 +12024,7 @@
"name": "removeIcon", "name": "removeIcon",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "ChipPassThroughOptionType", "type": "ChipPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the removeIcon's DOM element." "description": "Used to pass attributes to the removeIcon's DOM element."
}, },
@ -12125,7 +12125,7 @@
"name": "pt", "name": "pt",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "PassThrough<ChipPassThroughOptions>", "type": "PassThrough<ChipPassThroughOptions<any>>",
"default": "", "default": "",
"description": "Used to pass attributes to DOM elements inside the component." "description": "Used to pass attributes to DOM elements inside the component."
}, },
@ -12342,6 +12342,29 @@
], ],
"methods": [] "methods": []
}, },
"ChipsSharedPassThroughMethodOptions": {
"description": "Custom shared passthrough(pt) option method.",
"relatedProp": "",
"props": [
{
"name": "props",
"optional": false,
"readonly": false,
"type": "ChipsProps",
"default": "",
"description": "Defines valid properties."
},
{
"name": "state",
"optional": false,
"readonly": false,
"type": "ChipsState",
"default": "",
"description": "Defines current inline state."
}
],
"methods": []
},
"ChipsAddEvent": { "ChipsAddEvent": {
"description": "Custom add event.", "description": "Custom add event.",
"relatedProp": "ChipsEmits.add", "relatedProp": "ChipsEmits.add",
@ -12422,9 +12445,9 @@
"name": "label", "name": "label",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "ChipsPassThroughOptionType", "type": "ChipPassThroughOptions<ChipsSharedPassThroughMethodOptions>",
"default": "", "default": "",
"description": "Used to pass attributes to the label's DOM element." "description": "Used to pass attributes to the Chip component."
}, },
{ {
"name": "removeTokenIcon", "name": "removeTokenIcon",
@ -15330,7 +15353,7 @@
"name": "chip", "name": "chip",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "DefaultPassThrough<ChipPassThroughOptions>", "type": "DefaultPassThrough<ChipPassThroughOptions<any>>",
"default": "" "default": ""
}, },
{ {
@ -37960,9 +37983,9 @@
"name": "tokenLabel", "name": "tokenLabel",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "MultiSelectPassThroughOptionType", "type": "ChipPassThroughOptions<MultiSelectSharedPassThroughMethodOptions>",
"default": "", "default": "",
"description": "Used to pass attributes to the token label's DOM element." "description": "Used to pass attributes to the Chip."
}, },
{ {
"name": "removeTokenIcon", "name": "removeTokenIcon",
@ -58228,9 +58251,9 @@
"name": "tokenLabel", "name": "tokenLabel",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "TreeSelectPassThroughOptionType", "type": "ChipPassThroughOptions<TreeSelectSharedPassThroughMethodOptions>",
"default": "", "default": "",
"description": "Used to pass attributes to the token label's DOM element." "description": "Used to pass attributes to the Chip."
}, },
{ {
"name": "trigger", "name": "trigger",

View File

@ -255,6 +255,7 @@ export default {
'primevue/badge': path.resolve(__dirname, './components/lib/badge/Badge.vue'), 'primevue/badge': path.resolve(__dirname, './components/lib/badge/Badge.vue'),
'primevue/togglebutton': path.resolve(__dirname, './components/lib/togglebutton/ToggleButton.vue'), 'primevue/togglebutton': path.resolve(__dirname, './components/lib/togglebutton/ToggleButton.vue'),
'primevue/listbox': path.resolve(__dirname, './components/lib/listbox/Listbox.vue'), 'primevue/listbox': path.resolve(__dirname, './components/lib/listbox/Listbox.vue'),
'primevue/chip': path.resolve(__dirname, './components/lib/chip/Chip.vue'),
'primevue/confirmationeventbus': path.resolve(__dirname, './components/lib/confirmationeventbus/ConfirmationEventBus.js'), 'primevue/confirmationeventbus': path.resolve(__dirname, './components/lib/confirmationeventbus/ConfirmationEventBus.js'),
'primevue/toasteventbus': path.resolve(__dirname, './components/lib/toasteventbus/ToastEventBus.js'), 'primevue/toasteventbus': path.resolve(__dirname, './components/lib/toasteventbus/ToastEventBus.js'),
'primevue/overlayeventbus': path.resolve(__dirname, './components/lib/overlayeventbus/OverlayEventBus.js'), 'primevue/overlayeventbus': path.resolve(__dirname, './components/lib/overlayeventbus/OverlayEventBus.js'),

View File

@ -265,6 +265,7 @@ const CORE_DEPENDENCIES = {
'primevue/tieredmenu': 'primevue.tieredmenu', 'primevue/tieredmenu': 'primevue.tieredmenu',
'primevue/badge': 'primevue.badge', 'primevue/badge': 'primevue.badge',
'primevue/listbox': 'primevue.listbox', 'primevue/listbox': 'primevue.listbox',
'primevue/chip': 'primevue.chip',
'primevue/togglebutton': 'primevue.togglebutton', 'primevue/togglebutton': 'primevue.togglebutton',
...CORE_PASSTHROUGH_DEPENDENCIES, ...CORE_PASSTHROUGH_DEPENDENCIES,
...CORE_THEME_DEPENDENCIES ...CORE_THEME_DEPENDENCIES