@dialpad/dialtone-vue
Version:
Vue component library for Dialpad's design system Dialtone
121 lines (120 loc) • 3.98 kB
JavaScript
import { BADGE_DECORATION_MODIFIERS as o, BADGE_KIND_MODIFIERS as n, BADGE_TYPE_MODIFIERS as i } from "./badge-constants.js";
import { n as s } from "../../_plugin-vue2_normalizer-DSLOjnn3.js";
const r = {
name: "DtBadge",
props: {
/**
* 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(n).includes(e)
},
/**
* Color for the badge background
* @values default, info, success, warning, critical, bulletin, ai
*/
type: {
type: String,
default: "default",
validator: (e) => Object.keys(i).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(o).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: i,
BADGE_KIND_MODIFIERS: n,
BADGE_DECORATION_MODIFIERS: o
};
},
computed: {
hasLeftIcon() {
return this.$scopedSlots.leftIcon && this.$scopedSlots.leftIcon();
},
hasRightIcon() {
return this.$scopedSlots.rightIcon && this.$scopedSlots.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."));
}
}
};
var d = function() {
var t = this, a = t._self._c;
return a("span", { class: [
"d-badge",
t.BADGE_TYPE_MODIFIERS[t.type],
t.BADGE_KIND_MODIFIERS[t.kind],
t.BADGE_DECORATION_MODIFIERS[t.decoration],
{ "d-badge--subtle": t.subtle },
{ "d-badge--outlined": t.outlined }
], attrs: { "data-qa": "dt-badge" } }, [t.decoration ? a("span", { staticClass: "d-badge__decorative" }) : t._e(), t.hasLeftIcon ? a("span", { staticClass: "d-badge__icon-left" }, [t._t("leftIcon", null, { iconSize: "200" })], 2) : t._e(), a("span", { class: ["d-badge__label", t.labelClass] }, [t._t("default", function() {
return [t._v(" " + t._s(t.text) + " ")];
})], 2), t.hasRightIcon ? a("span", { staticClass: "d-badge__icon-right" }, [t._t("rightIcon", null, { iconSize: "200" })], 2) : t._e()]);
}, l = [], c = /* @__PURE__ */ s(
r,
d,
l
);
const _ = c.exports;
export {
_ as default
};
//# sourceMappingURL=badge.js.map