primevue-mirror/components/chip/Chip.vue

91 lines
1.8 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2022-09-14 11:26:01 +00:00
<div v-if="visible" :class="containerClass">
2022-09-06 12:03:37 +00:00
<slot>
2022-09-14 11:26:01 +00:00
<img v-if="image" :src="image" />
<span v-else-if="icon" :class="iconClass"></span>
<div v-if="label" class="p-chip-text">{{ label }}</div>
2022-09-06 12:03:37 +00:00
</slot>
2022-09-14 11:26:01 +00:00
<span v-if="removable" tabindex="0" :class="removeIconClass" @click="close" @keydown.enter="close"></span>
2022-09-06 12:03:37 +00:00
</div>
</template>
<script>
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,
default: 'pi pi-times-circle'
}
},
data() {
return {
visible: true
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
methods: {
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
},
iconClass() {
return ['p-chip-icon', this.icon];
},
removeIconClass() {
return ['p-chip-remove-icon', this.removeIcon];
}
}
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>