UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

135 lines (134 loc) 4.62 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const badge_constants = require("./badge_constants.cjs"); const _pluginVue2_normalizer = require("../../_virtual/_plugin-vue2_normalizer.cjs"); const _sfc_main = { 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: (kind) => Object.keys(badge_constants.BADGE_KIND_MODIFIERS).includes(kind) }, /** * Color for the badge background * @values default, info, success, warning, critical, bulletin, ai */ type: { type: String, default: "default", validator: (type) => Object.keys(badge_constants.BADGE_TYPE_MODIFIERS).includes(type) }, /** * 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: (type) => Object.keys(badge_constants.BADGE_DECORATION_MODIFIERS).includes(type) }, /** * 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: false }, /** * Outlines the badge with a border */ outlined: { type: Boolean, default: false } }, data() { return { BADGE_TYPE_MODIFIERS: badge_constants.BADGE_TYPE_MODIFIERS, BADGE_KIND_MODIFIERS: badge_constants.BADGE_KIND_MODIFIERS, BADGE_DECORATION_MODIFIERS: badge_constants.BADGE_DECORATION_MODIFIERS }; }, 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() { if (this.type === "ai" && this.kind === "count") { console.error("DtBadge error: type: 'ai' with kind: 'count' is an invalid combination."); } if (this.type !== "bulletin" && this.subtle) { console.error("DtBadge error: subtle can only be used with type 'bulletin'"); } }, validateDecorationPropCombination() { if (!this.decoration) return; if (this.kind !== "label" || this.type !== "default") { console.error("DtBadge error: decoration prop can only be used with kind: 'label' and type: 'default'."); } if (this.hasIcons) { console.error("DtBadge error: decoration prop cannot be used with leftIcon or rightIcon."); } } } }; var _sfc_render = function render() { var _vm = this, _c = _vm._self._c; return _c("span", { class: [ "d-badge", _vm.BADGE_TYPE_MODIFIERS[_vm.type], _vm.BADGE_KIND_MODIFIERS[_vm.kind], _vm.BADGE_DECORATION_MODIFIERS[_vm.decoration], { "d-badge--subtle": _vm.subtle }, { "d-badge--outlined": _vm.outlined } ], attrs: { "data-qa": "dt-badge" } }, [_vm.decoration ? _c("span", { staticClass: "d-badge__decorative" }) : _vm._e(), _vm.hasLeftIcon ? _c("span", { staticClass: "d-badge__icon-left" }, [_vm._t("leftIcon", null, { "iconSize": "200" })], 2) : _vm._e(), _c("span", { class: ["d-badge__label", _vm.labelClass] }, [_vm._t("default", function() { return [_vm._v(" " + _vm._s(_vm.text) + " ")]; })], 2), _vm.hasRightIcon ? _c("span", { staticClass: "d-badge__icon-right" }, [_vm._t("rightIcon", null, { "iconSize": "200" })], 2) : _vm._e()]); }; var _sfc_staticRenderFns = []; var __component__ = /* @__PURE__ */ _pluginVue2_normalizer.default( _sfc_main, _sfc_render, _sfc_staticRenderFns ); const DtBadge = __component__.exports; exports.default = DtBadge; //# sourceMappingURL=badge.vue.cjs.map