primevue-mirror/components/lib/badge/BaseBadge.vue

89 lines
2.0 KiB
Vue
Raw Normal View History

2023-05-25 06:38:12 +00:00
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
import { ObjectUtils } from 'primevue/utils';
2023-05-25 13:06:54 +00:00
2023-05-25 06:38:12 +00:00
const styles = `
2023-09-26 09:14:27 +00:00
@layer primevue {
2023-09-25 19:11:55 +00:00
.p-badge {
display: inline-block;
border-radius: 10px;
text-align: center;
padding: 0 .5rem;
}
.p-overlay-badge {
position: relative;
}
.p-overlay-badge .p-badge {
position: absolute;
top: 0;
right: 0;
transform: translate(50%,-50%);
transform-origin: 100% 0;
margin: 0;
}
.p-badge-dot {
width: .5rem;
min-width: .5rem;
height: .5rem;
border-radius: 50%;
padding: 0;
}
.p-badge-no-gutter {
padding: 0;
border-radius: 50%;
}
2023-05-25 06:38:12 +00:00
}
`;
const classes = {
2023-05-30 10:19:28 +00:00
root: ({ props, instance }) => [
2023-05-25 06:38:12 +00:00
'p-badge p-component',
{
'p-badge-no-gutter': ObjectUtils.isNotEmpty(props.value) && String(props.value).length === 1,
2023-05-30 10:19:28 +00:00
'p-badge-dot': ObjectUtils.isEmpty(props.value) && !instance.$slots.default,
2023-05-25 06:38:12 +00:00
'p-badge-lg': props.size === 'large',
'p-badge-xl': props.size === 'xlarge',
'p-badge-info': props.severity === 'info',
'p-badge-success': props.severity === 'success',
'p-badge-warning': props.severity === 'warning',
'p-badge-danger': props.severity === 'danger'
}
]
};
const { load: loadStyle } = useStyle(styles, { name: 'badge', manual: true });
2023-05-25 06:38:12 +00:00
export default {
2023-05-25 13:33:56 +00:00
name: 'BaseBadge',
2023-05-25 06:38:12 +00:00
extends: BaseComponent,
props: {
value: {
type: [String, Number],
default: null
},
severity: {
type: String,
default: null
},
size: {
type: String,
default: null
}
},
css: {
classes,
loadStyle
2023-05-25 06:38:12 +00:00
},
provide() {
return {
$parentInstance: this
};
2023-05-25 06:38:12 +00:00
}
};
</script>