primevue-mirror/components/lib/baseicon/BaseIcon.vue

55 lines
1.3 KiB
Vue
Raw Normal View History

2023-03-31 21:45:03 +00:00
<script>
import BaseComponent from 'primevue/basecomponent';
import BaseIconStyle from 'primevue/baseicon/style';
import { ObjectUtils, UniqueComponentId } from 'primevue/utils';
2023-03-31 21:45:03 +00:00
export default {
name: 'BaseIcon',
extends: BaseComponent,
data() {
return {
id: this.$attrs.id
};
},
2023-03-31 21:45:03 +00:00
props: {
label: {
type: String,
2023-04-26 08:57:02 +00:00
default: undefined
2023-03-31 21:45:03 +00:00
},
spin: {
type: Boolean,
2023-04-26 08:57:02 +00:00
default: false
2023-03-31 21:45:03 +00:00
}
},
style: BaseIconStyle,
mounted() {
this.id = this.id || UniqueComponentId();
},
watch: {
'$attrs.id': function (newValue) {
this.id = newValue || UniqueComponentId();
}
},
2023-03-31 21:45:03 +00:00
methods: {
pti() {
const isLabelEmpty = ObjectUtils.isEmpty(this.label);
return {
...(!this.isUnstyled && {
class: [
'p-icon',
{
'p-icon-spin': this.spin
}
]
}),
id: this.id,
2023-03-31 21:45:03 +00:00
role: !isLabelEmpty ? 'img' : undefined,
2023-04-03 08:26:51 +00:00
'aria-label': !isLabelEmpty ? this.label : undefined,
2023-03-31 21:45:03 +00:00
'aria-hidden': isLabelEmpty
};
}
}
};
</script>