Refactor #3965 - For Tag

pull/3997/head
Bahadır Sofuoğlu 2023-05-24 14:57:02 +03:00
parent f9f5eed7ab
commit dca48d7ef4
3 changed files with 71 additions and 46 deletions

View File

@ -0,0 +1,61 @@
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
const styles = `
.p-tag {
display: inline-flex;
align-items: center;
justify-content: center;
}
.p-tag-icon,
.p-tag-value,
.p-tag-icon.pi {
line-height: 1.5;
}
.p-tag.p-tag-rounded {
border-radius: 10rem;
}
`;
const classes = {
root: ({ props }) => [
'p-tag p-component',
{
'p-tag-info': props.severity === 'info',
'p-tag-success': props.severity === 'success',
'p-tag-warning': props.severity === 'warning',
'p-tag-danger': props.severity === 'danger',
'p-tag-rounded': props.rounded
}
],
icon: ({ props }) => ['p-tag-icon', props.icon],
value: 'p-tag-value'
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_tag_style', manual: true });
export default {
name: 'BaseTag',
extends: BaseComponent,
props: {
value: null,
severity: null,
rounded: Boolean,
icon: String
},
css: {
classes
},
watch: {
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && loadStyle();
}
}
}
};
</script>

View File

@ -72,6 +72,11 @@ export interface TagProps {
* @type {TagPassThroughOptions}
*/
pt?: TagPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}
/**

View File

@ -1,9 +1,9 @@
<template>
<span :class="containerClass" v-bind="ptm('root')">
<component v-if="$slots.icon" :is="$slots.icon" class="p-tag-icon" v-bind="ptm('icon')" />
<span v-else-if="icon" :class="iconClass" v-bind="ptm('icon')"></span>
<span :class="cx('root')" v-bind="ptm('root')">
<component v-if="$slots.icon" :is="$slots.icon" :class="cx('icon')" v-bind="ptm('icon')" />
<span v-else-if="icon" :class="cx('icon')" v-bind="ptm('icon')"></span>
<slot>
<span class="p-tag-value" v-bind="ptm('value')">{{ value }}</span>
<span :class="cx('value')" v-bind="ptm('value')">{{ value }}</span>
</slot>
</span>
</template>
@ -13,47 +13,6 @@ import BaseComponent from 'primevue/basecomponent';
export default {
name: 'Tag',
extends: BaseComponent,
props: {
value: null,
severity: null,
rounded: Boolean,
icon: String
},
computed: {
containerClass() {
return [
'p-tag p-component',
{
'p-tag-info': this.severity === 'info',
'p-tag-success': this.severity === 'success',
'p-tag-warning': this.severity === 'warning',
'p-tag-danger': this.severity === 'danger',
'p-tag-rounded': this.rounded
}
];
},
iconClass() {
return ['p-tag-icon', this.icon];
}
}
extends: BaseComponent
};
</script>
<style>
.p-tag {
display: inline-flex;
align-items: center;
justify-content: center;
}
.p-tag-icon,
.p-tag-value,
.p-tag-icon.pi {
line-height: 1.5;
}
.p-tag.p-tag-rounded {
border-radius: 10rem;
}
</style>