Refactor #3832 Refactor #3833 - For Chip

pull/3852/head
Bahadır Sofuoğlu 2023-04-10 22:42:57 +03:00
parent edc09b8bc6
commit a9185a87e7
3 changed files with 31 additions and 7 deletions

View File

@ -45,11 +45,19 @@ const ChipEvents = [
} }
]; ];
const ChipSlots = [
{
name: 'removeicon',
description: 'Custom remove icon template of chip component.'
}
];
module.exports = { module.exports = {
chip: { chip: {
name: 'Chip', name: 'Chip',
description: 'Chip represents entities using icons, labels and images', description: 'Chip represents entities using icons, labels and images',
props: ChipProps, props: ChipProps,
events: ChipEvents events: ChipEvents,
slots: ChipSlots
} }
}; };

View File

@ -33,7 +33,6 @@ export interface ChipProps {
removable?: boolean; removable?: boolean;
/** /**
* Icon of the remove element. * Icon of the remove element.
* @defaultValue pi pi-times-circle
*/ */
removeIcon?: string; removeIcon?: string;
} }
@ -46,6 +45,20 @@ export interface ChipSlots {
* Content can easily be customized with the default slot instead of using the built-in modes. * Content can easily be customized with the default slot instead of using the built-in modes.
*/ */
default(): VNode[]; default(): VNode[];
/**
* Custom remove icon template of chip component.
* @param {Object} scope - remove icon slot's params.
*/
removeicon(scope: {
/**
* Remove icon click event
*/
click(): void;
/**
* Remove icon keydown event
*/
keydown(): void;
}): VNode[];
} }
/** /**

View File

@ -5,11 +5,14 @@
<span v-else-if="icon" :class="iconClass"></span> <span v-else-if="icon" :class="iconClass"></span>
<div v-if="label" class="p-chip-text">{{ label }}</div> <div v-if="label" class="p-chip-text">{{ label }}</div>
</slot> </slot>
<span v-if="removable" tabindex="0" :class="removeIconClass" @click="close" @keydown="onKeydown"></span> <slot name="removeicon" :click="close" :keydown="onKeydown">
<component v-if="removable" :is="removeIcon ? 'span' : 'TimesCircleIcon'" tabindex="0" :class="['p-chip-remove-icon', removeIcon]" @click="close" @keydown="onKeydown"></component>
</slot>
</div> </div>
</template> </template>
<script> <script>
import TimesCircleIcon from 'primevue/icon/timescircle';
export default { export default {
name: 'Chip', name: 'Chip',
emits: ['remove'], emits: ['remove'],
@ -32,7 +35,7 @@ export default {
}, },
removeIcon: { removeIcon: {
type: String, type: String,
default: 'pi pi-times-circle' default: undefined
} }
}, },
data() { data() {
@ -62,10 +65,10 @@ export default {
}, },
iconClass() { iconClass() {
return ['p-chip-icon', this.icon]; return ['p-chip-icon', this.icon];
},
removeIconClass() {
return ['p-chip-remove-icon', this.removeIcon];
} }
},
components: {
TimesCircleIcon
} }
}; };
</script> </script>