Skip to content

Commit

Permalink
Refactor #3832 Refactor #3833 - For AutoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Apr 4, 2023
1 parent 78d4e84 commit 9bc6ca4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
32 changes: 31 additions & 1 deletion api-generator/components/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,30 @@ const AutoCompleteProps = [
default: 'null',
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',
type: 'string',
default: 'pi pi-spinner',
default: 'null',
description: 'Icon to display in loading state.'
},
{
name: 'removeTokenIcon',
type: 'string',
default: 'null',
description: 'Icon to display in chip remove action.'
},
{
name: 'virtualScrollerOptions',
type: 'object',
Expand Down Expand Up @@ -396,6 +414,18 @@ const AutoCompleteSlots = [
{
name: 'empty',
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.'
}
];

Expand Down
15 changes: 12 additions & 3 deletions components/lib/autocomplete/AutoComplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export interface AutoCompleteProps {
panelProps?: HTMLAttributes | undefined;
/**
* Icon to display in the dropdown.
* @defaultValue pi pi-chevron-down
*/
dropdownIcon?: string | undefined;
/**
Expand All @@ -215,12 +214,10 @@ export interface AutoCompleteProps {
dropdownClass?: string | object | undefined;
/**
* Icon to display in loading state.
* @defaultValue pi pi-spinner pi-spin
*/
loadingIcon?: string | undefined;
/**
* Icon to display in chip remove action.
* @defaultValue pi pi-times-circle
*/
removeTokenIcon?: string | undefined;
/**
Expand Down Expand Up @@ -406,6 +403,18 @@ export interface AutoCompleteSlots {
* Custom empty template when there is no data to display.
*/
empty(): VNode[];
/**
* Custom dropdown icon template.
*/
dropdownicon(): VNode[];
/**
* Custom remove token icon template in multiple mode.
*/
removetokenicon(): VNode[];
/**
* Custom loading icon template.
*/
loadingicon(): VNode[];
}

/**
Expand Down
31 changes: 21 additions & 10 deletions components/lib/autocomplete/AutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
<slot name="chip" :value="option">
<span class="p-autocomplete-token-label">{{ getOptionLabel(option) }}</span>
</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 class="p-autocomplete-input-token" role="option">
<input
Expand Down Expand Up @@ -83,8 +85,14 @@
/>
</li>
</ul>
<i v-if="searching" :class="loadingIconClass" aria-hidden="true"></i>
<Button v-if="dropdown" ref="dropdownButton" type="button" :icon="dropdownIcon" :class="['p-autocomplete-dropdown', dropdownClass]" tabindex="-1" :disabled="disabled" aria-hidden="true" @click="onDropdownClick" />
<slot v-if="searching" name="loadingicon">
<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">
{{ searchResultMessageText }}
</span>
Expand Down Expand Up @@ -140,6 +148,9 @@

<script>
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 Portal from 'primevue/portal';
import Ripple from 'primevue/ripple';
Expand Down Expand Up @@ -247,19 +258,19 @@ export default {
},
dropdownIcon: {
type: String,
default: 'pi pi-chevron-down'
default: undefined
},
dropdownClass: {
type: [String, Object],
default: null
},
loadingIcon: {
type: String,
default: 'pi pi-spinner'
default: undefined
},
removeTokenIcon: {
type: String,
default: 'pi pi-times-circle'
default: undefined
},
virtualScrollerOptions: {
type: Object,
Expand Down Expand Up @@ -1020,9 +1031,6 @@ export default {
}
];
},
loadingIconClass() {
return ['p-autocomplete-loader pi-spin', this.loadingIcon];
},
visibleOptions() {
return this.optionGroupLabel ? this.flatOptions(this.suggestions) : this.suggestions || [];
},
Expand Down Expand Up @@ -1079,7 +1087,10 @@ export default {
components: {
Button: Button,
VirtualScroller: VirtualScroller,
Portal: Portal
Portal: Portal,
ChevronDownIcon: ChevronDownIcon,
SpinnerIcon: SpinnerIcon,
TimesCircleIcon: TimesCircleIcon
},
directives: {
ripple: Ripple
Expand Down

0 comments on commit 9bc6ca4

Please sign in to comment.