2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-12-08 11:04:25 +00:00
|
|
|
<div v-if="visible" :class="containerClass" :aria-label="label">
|
2023-04-18 07:35:20 +00:00
|
|
|
<slot></slot>
|
|
|
|
<template v-if="!$slots.default">
|
2022-09-14 11:26:01 +00:00
|
|
|
<img v-if="image" :src="image" />
|
2023-04-18 07:35:20 +00:00
|
|
|
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-chip-icon" />
|
|
|
|
<span v-else-if="icon" :class="['p-chip-icon', icon]" />
|
2022-09-14 11:26:01 +00:00
|
|
|
<div v-if="label" class="p-chip-text">{{ label }}</div>
|
2023-04-18 07:35:20 +00:00
|
|
|
</template>
|
|
|
|
<slot v-if="removable" name="removeicon" :onClick="close" :onKeydown="onKeydown">
|
|
|
|
<component :is="removeIcon ? 'span' : 'TimesCircleIcon'" tabindex="0" :class="['p-chip-remove-icon', removeIcon]" @click="close" @keydown="onKeydown"></component>
|
2023-04-10 19:42:57 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-18 12:53:43 +00:00
|
|
|
import TimesCircleIcon from 'primevue/icons/timescircle';
|
2023-04-14 14:10:51 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'Chip',
|
|
|
|
emits: ['remove'],
|
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
removable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
removeIcon: {
|
|
|
|
type: String,
|
2023-04-10 19:42:57 +00:00
|
|
|
default: undefined
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
visible: true
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2022-12-08 11:04:25 +00:00
|
|
|
onKeydown(event) {
|
|
|
|
if (event.key === 'Enter' || event.key === 'Backspace') {
|
|
|
|
this.close(event);
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
close(event) {
|
|
|
|
this.visible = false;
|
|
|
|
this.$emit('remove', event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-chip p-component',
|
|
|
|
{
|
|
|
|
'p-chip-image': this.image != null
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2023-04-10 19:42:57 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
TimesCircleIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.p-chip {
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-chip-text {
|
|
|
|
line-height: 1.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-chip-icon.pi {
|
|
|
|
line-height: 1.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-chip-remove-icon {
|
|
|
|
line-height: 1.5;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-chip img {
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
</style>
|