@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
154 lines (153 loc) • 4.62 kB
JavaScript
import { BADGE_DECORATION_MODIFIERS as l, BADGE_KIND_MODIFIERS as d, BADGE_TYPE_MODIFIERS as c } from "./badge-constants.js";
import { hasSlotContent as u } from "../../common/utils/index.js";
import { createElementBlock as o, openBlock as a, normalizeClass as h, createCommentVNode as n, createElementVNode as f, renderSlot as r, createTextVNode as b, toDisplayString as I } from "vue";
import { _ } from "../../_plugin-vue_export-helper-CHgC5LLL.js";
import { ICON_SIZE_MODIFIERS as g } from "../icon/icon-constants.js";
const p = {
compatConfig: { MODE: 3 },
name: "DtBadge",
props: {
/**
* The size of the left and right icons.
* @values 100, 200, 300, 400, 500, 600, 700, 800
*/
iconSize: {
type: String,
default: "200",
validator: (e) => Object.keys(g).includes(e)
},
/**
* Text for the badge content
*/
text: {
type: String,
default: ""
},
/**
* The kind of badge which determines the styling
* @values label, count
*/
kind: {
type: String,
default: "label",
validator: (e) => Object.keys(d).includes(e)
},
/**
* Color for the badge background
* @values default, info, success, warning, critical, bulletin, ai
*/
type: {
type: String,
default: "default",
validator: (e) => Object.keys(c).includes(e)
},
/**
* Decoration for the badge. This can be only used with kind: label and type: default
* with no left and right icons
* @values default, black-400, black-500, black-900, red-200, red-300, red-400, purple-200,
* purple-300, purple-400, purple-500, blue-200, blue-300, blue-400, green-300, green-400,
* green-500, gold-300, gold-400, gold-500, magenta-200, magenta-300, magenta-400
*/
decoration: {
type: String,
default: void 0,
validator: (e) => Object.keys(l).includes(e)
},
/**
* Used to customize the label container
*/
labelClass: {
type: [String, Array, Object],
default: ""
},
/**
* Shows a subtle appearance for the badge
* Currently only affects the badge when type is bulletin.
*/
subtle: {
type: Boolean,
default: !1
},
/**
* Outlines the badge with a border
*/
outlined: {
type: Boolean,
default: !1
}
},
data() {
return {
BADGE_TYPE_MODIFIERS: c,
BADGE_KIND_MODIFIERS: d,
BADGE_DECORATION_MODIFIERS: l
};
},
computed: {
hasLeftIcon() {
return u(this.$slots.leftIcon);
},
hasRightIcon() {
return u(this.$slots.rightIcon);
},
hasIcons() {
return this.hasLeftIcon || this.hasRightIcon;
}
},
updated() {
this.validateProps();
},
methods: {
validateProps() {
this.validateTypePropCombination(), this.validateDecorationPropCombination();
},
validateTypePropCombination() {
this.type === "ai" && this.kind === "count" && console.error("DtBadge error: type: 'ai' with kind: 'count' is an invalid combination."), this.type !== "bulletin" && this.subtle && console.error("DtBadge error: subtle can only be used with type 'bulletin'");
},
validateDecorationPropCombination() {
this.decoration && ((this.kind !== "label" || this.type !== "default") && console.error("DtBadge error: decoration prop can only be used with kind: 'label' and type: 'default'."), this.hasIcons && console.error("DtBadge error: decoration prop cannot be used with leftIcon or rightIcon."));
}
}
}, y = {
key: 0,
class: "d-badge__decorative"
}, D = {
key: 1,
class: "d-badge__icon-left"
}, m = {
key: 2,
class: "d-badge__icon-right"
};
function S(e, E, t, O, i, s) {
return a(), o("span", {
class: h([
"d-badge",
i.BADGE_TYPE_MODIFIERS[t.type],
i.BADGE_KIND_MODIFIERS[t.kind],
i.BADGE_DECORATION_MODIFIERS[t.decoration],
{ "d-badge--subtle": t.subtle },
{ "d-badge--outlined": t.outlined }
]),
"data-qa": "dt-badge"
}, [
t.decoration ? (a(), o("span", y)) : n("", !0),
s.hasLeftIcon ? (a(), o("span", D, [
r(e.$slots, "leftIcon", { iconSize: t.iconSize })
])) : n("", !0),
f("span", {
class: h(["d-badge__label", t.labelClass])
}, [
r(e.$slots, "default", {}, () => [
b(I(t.text), 1)
])
], 2),
s.hasRightIcon ? (a(), o("span", m, [
r(e.$slots, "rightIcon", { iconSize: t.iconSize })
])) : n("", !0)
], 2);
}
const A = /* @__PURE__ */ _(p, [["render", S]]);
export {
A as default
};
//# sourceMappingURL=badge.js.map