Refactor #3832 Refactor #3833 - For AutoComplete

pull/3841/head
Tuğçe Küçükoğlu 2023-04-04 15:38:11 +03:00
parent 78d4e84c0b
commit 9bc6ca49ca
3 changed files with 64 additions and 14 deletions

View File

@ -161,12 +161,30 @@ const AutoCompleteProps = [
default: 'null', default: 'null',
description: 'Uses to pass all properties of the HTMLDivElement to the overlay panel inside the component.' description: 'Uses to pass all properties of the HTMLDivElement to the overlay panel inside the component.'
}, },
{
name: 'dropdownIcon',
type: 'string',
default: 'null',
description: 'Icon to display in the dropdown.'
},
{
name: 'dropdownClass',
type: 'string',
default: 'null',
description: 'Style class of the dropdown button.'
},
{ {
name: 'loadingIcon', name: 'loadingIcon',
type: 'string', type: 'string',
default: 'pi pi-spinner', default: 'null',
description: 'Icon to display in loading state.' description: 'Icon to display in loading state.'
}, },
{
name: 'removeTokenIcon',
type: 'string',
default: 'null',
description: 'Icon to display in chip remove action.'
},
{ {
name: 'virtualScrollerOptions', name: 'virtualScrollerOptions',
type: 'object', type: 'object',
@ -396,6 +414,18 @@ const AutoCompleteSlots = [
{ {
name: 'empty', name: 'empty',
description: 'Custom empty template when there is no data to display.' description: 'Custom empty template when there is no data to display.'
},
{
name: 'dropdownicon',
description: 'Custom dropdown icon template.'
},
{
name: 'removetokenicon',
description: 'Custom remove token icon template.'
},
{
name: 'loadingicon',
description: 'Custom loading icon template.'
} }
]; ];

View File

@ -206,7 +206,6 @@ export interface AutoCompleteProps {
panelProps?: HTMLAttributes | undefined; panelProps?: HTMLAttributes | undefined;
/** /**
* Icon to display in the dropdown. * Icon to display in the dropdown.
* @defaultValue pi pi-chevron-down
*/ */
dropdownIcon?: string | undefined; dropdownIcon?: string | undefined;
/** /**
@ -215,12 +214,10 @@ export interface AutoCompleteProps {
dropdownClass?: string | object | undefined; dropdownClass?: string | object | undefined;
/** /**
* Icon to display in loading state. * Icon to display in loading state.
* @defaultValue pi pi-spinner pi-spin
*/ */
loadingIcon?: string | undefined; loadingIcon?: string | undefined;
/** /**
* Icon to display in chip remove action. * Icon to display in chip remove action.
* @defaultValue pi pi-times-circle
*/ */
removeTokenIcon?: string | undefined; removeTokenIcon?: string | undefined;
/** /**
@ -406,6 +403,18 @@ export interface AutoCompleteSlots {
* Custom empty template when there is no data to display. * Custom empty template when there is no data to display.
*/ */
empty(): VNode[]; empty(): VNode[];
/**
* Custom dropdown icon template.
*/
dropdownicon(): VNode[];
/**
* Custom remove token icon template in multiple mode.
*/
removetokenicon(): VNode[];
/**
* Custom loading icon template.
*/
loadingicon(): VNode[];
} }
/** /**

View File

@ -53,7 +53,9 @@
<slot name="chip" :value="option"> <slot name="chip" :value="option">
<span class="p-autocomplete-token-label">{{ getOptionLabel(option) }}</span> <span class="p-autocomplete-token-label">{{ getOptionLabel(option) }}</span>
</slot> </slot>
<span :class="['p-autocomplete-token-icon', removeTokenIcon]" @click="removeOption($event, i)" aria-hidden="true"></span> <slot name="removetokenicon">
<component :is="removeTokenIcon ? 'span' : 'TimesCircleIcon'" :class="['p-autocomplete-token-icon', removeTokenIcon]" @click="removeOption($event, i)" aria-hidden="true" />
</slot>
</li> </li>
<li class="p-autocomplete-input-token" role="option"> <li class="p-autocomplete-input-token" role="option">
<input <input
@ -83,8 +85,14 @@
/> />
</li> </li>
</ul> </ul>
<i v-if="searching" :class="loadingIconClass" aria-hidden="true"></i> <slot v-if="searching" name="loadingicon">
<Button v-if="dropdown" ref="dropdownButton" type="button" :icon="dropdownIcon" :class="['p-autocomplete-dropdown', dropdownClass]" tabindex="-1" :disabled="disabled" aria-hidden="true" @click="onDropdownClick" /> <component :is="loadingIcon ? 'i' : 'SpinnerIcon'" :class="['p-autocomplete-loader', loadingIcon]" spin aria-hidden="true" />
</slot>
<Button v-if="dropdown" ref="dropdownButton" type="button" tabindex="-1" :class="['p-autocomplete-dropdown', dropdownClass]" :disabled="disabled" aria-hidden="true" @click="onDropdownClick">
<slot name="dropdownicon">
<component :is="dropdownIcon ? 'span' : 'ChevronDownIcon'" :class="dropdownIcon" />
</slot>
</Button>
<span role="status" aria-live="polite" class="p-hidden-accessible"> <span role="status" aria-live="polite" class="p-hidden-accessible">
{{ searchResultMessageText }} {{ searchResultMessageText }}
</span> </span>
@ -140,6 +148,9 @@
<script> <script>
import Button from 'primevue/button'; import Button from 'primevue/button';
import ChevronDownIcon from 'primevue/icon/chevrondown';
import SpinnerIcon from 'primevue/icon/spinner';
import TimesCircleIcon from 'primevue/icon/timescircle';
import OverlayEventBus from 'primevue/overlayeventbus'; import OverlayEventBus from 'primevue/overlayeventbus';
import Portal from 'primevue/portal'; import Portal from 'primevue/portal';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
@ -247,7 +258,7 @@ export default {
}, },
dropdownIcon: { dropdownIcon: {
type: String, type: String,
default: 'pi pi-chevron-down' default: undefined
}, },
dropdownClass: { dropdownClass: {
type: [String, Object], type: [String, Object],
@ -255,11 +266,11 @@ export default {
}, },
loadingIcon: { loadingIcon: {
type: String, type: String,
default: 'pi pi-spinner' default: undefined
}, },
removeTokenIcon: { removeTokenIcon: {
type: String, type: String,
default: 'pi pi-times-circle' default: undefined
}, },
virtualScrollerOptions: { virtualScrollerOptions: {
type: Object, type: Object,
@ -1020,9 +1031,6 @@ export default {
} }
]; ];
}, },
loadingIconClass() {
return ['p-autocomplete-loader pi-spin', this.loadingIcon];
},
visibleOptions() { visibleOptions() {
return this.optionGroupLabel ? this.flatOptions(this.suggestions) : this.suggestions || []; return this.optionGroupLabel ? this.flatOptions(this.suggestions) : this.suggestions || [];
}, },
@ -1079,7 +1087,10 @@ export default {
components: { components: {
Button: Button, Button: Button,
VirtualScroller: VirtualScroller, VirtualScroller: VirtualScroller,
Portal: Portal Portal: Portal,
ChevronDownIcon: ChevronDownIcon,
SpinnerIcon: SpinnerIcon,
TimesCircleIcon: TimesCircleIcon
}, },
directives: { directives: {
ripple: Ripple ripple: Ripple