UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

406 lines (405 loc) 13.1 kB
import { LEFTBAR_GENERAL_ROW_TYPES as b, LEFTBAR_GENERAL_ROW_CONTACT_CENTER_COLORS as v, LEFTBAR_GENERAL_ROW_ICON_SIZES as k, LEFTBAR_GENERAL_ROW_CONTACT_CENTER_VALIDATION_ERROR as O } from "./general-row-constants.js"; import { DtIconPhone as U, DtIconWaveform as N } from "@dialpad/dialtone-icons/vue3"; import W from "../emoji-text-wrapper/emoji-text-wrapper.js"; import q from "./leftbar-general-row-icon.js"; import { extractVueListeners as M, safeConcatStrings as F, returnFirstEl as m, removeClassStyleAttrs as z, addClassStyleAttrs as D } from "../../common/utils/index.js"; import { resolveComponent as o, openBlock as r, createElementBlock as h, mergeProps as R, createElementVNode as l, toHandlers as x, renderSlot as A, createVNode as c, normalizeStyle as j, withCtx as i, createTextVNode as g, toDisplayString as C, createBlock as y, createCommentVNode as u, normalizeClass as E, withModifiers as G } from "vue"; import { _ as I } from "../../_plugin-vue_export-helper-CHgC5LLL.js"; import V from "../badge/badge.js"; import P from "../button/button.js"; import H from "../tooltip/tooltip.js"; const K = { compatConfig: { MODE: 3 }, name: "DtRecipeGeneralRow", components: { DtEmojiTextWrapper: W, DtBadge: V, DtButton: P, DtTooltip: H, DtIconPhone: U, DtIconWaveform: N, DtRecipeLeftbarGeneralRowIcon: q }, inheritAttrs: !1, props: { /** * Determines the icon to show. * If type is contact center, the color prop must be provided and will determine the color of the icon */ type: { type: String, default: "inbox", validator: (e) => Object.values(b).includes(e) }, /** * Will be read out by a screen reader upon focus of this row. If not defined "description" will be read. */ ariaLabel: { type: String, default: "" }, /** * Text displayed next to the icon. Required. Even if you are overriding this field using the label slot * you still must input this as it will be displayed as the "title" attribute for the row. */ description: { type: String, required: !0 }, /** * Determines the color of the contact center icon */ color: { type: String, default: null, validator: (e) => Object.keys(v).includes(e) }, /** * The channel setting, either 'mention' or 'always'. * @values 'mention', 'always', null. */ channelSetting: { type: String, default: null }, /** * Styles the row with an increased font weight to convey it has unreads. This must be true to see * the unread count badge. */ hasUnreads: { type: Boolean, default: !1 }, /** * Number of unread messages */ unreadCount: { type: String, default: null }, /** * Number of unread mention messages */ unreadMentionCount: { type: String, default: null }, /** * Text shown when the unread count is hovered. */ unreadCountTooltip: { type: String, default: "" }, /** * Determines if the row is selected */ selected: { type: Boolean, default: !1 }, /** * Gives a faded style to be used when muted */ muted: { type: Boolean, default: !1 }, /** * Shows styling to represent an active voice chat. This will display over unreadCount. */ activeVoiceChat: { type: Boolean, default: !1 }, /** * Acronym used to represent "Do not Disturb" state. If entered will display the entered text alongside * unreadCount. */ dndText: { type: String, default: "" }, /** * Text shown in tooltip when you hover the dndText */ dndTextTooltip: { type: String, default: "" }, /** * Whether the row should have a call button. Usually only applicable to individual contact rows. */ hasCallButton: { type: Boolean, default: !1 }, /** * Text shown when the call button is hovered. */ callButtonTooltip: { type: String, default: "" }, /** * Shows an "is typing" animation over the avatar when true. */ isTyping: { type: Boolean, default: !1 }, /** * Sets the size of the icon. */ iconSize: { type: String, default: "300", validator: (e) => k.includes(e) } }, emits: [ /** * Call button clicked * * @event call * @type {PointerEvent | KeyboardEvent} */ "call" ], data() { return { actionFocused: !1, labelWidth: "100%" }; }, computed: { leftbarGeneralRowClasses() { return [ "d-recipe-leftbar-row", { "d-recipe-leftbar-row--no-action": !this.hasCallButton, "d-recipe-leftbar-row--has-unread": this.hasUnreads, "d-recipe-leftbar-row__unread-count": this.showUnreadCount || this.showUnreadMentionCount, "d-recipe-leftbar-row--selected": this.selected, "d-recipe-leftbar-row--muted": this.muted, "d-recipe-leftbar-row--action-focused": this.actionFocused } ]; }, getIcon() { switch (this.type) { case b.CHANNELS: if (this.hasUnreads) return "channel unread"; break; case b.LOCKED_CHANNEL: if (this.hasUnreads) return "locked channel unread"; break; } return this.type; }, generalRowListeners() { return M(this.$attrs); }, getAriaLabel() { return this.ariaLabel ? this.ariaLabel : F([this.description, this.unreadCountTooltip, this.dndTextTooltip]); }, hasActions() { return this.dndText || this.activeVoiceChat || this.showUnreadCount || this.hasCallButton || this.showUnreadMentionCount; }, showUnreadCount() { return !!this.unreadCount && this.hasUnreads; }, showUnreadMentionCount() { return !!this.unreadMentionCount && this.hasUnreads; }, hasUnreadCount() { return this.unreadCount !== null; }, hasUnreadMentionCount() { return this.unreadMentionCount !== null; }, shouldApplyCustomStyleForCountBadge() { return this.hasUnreadCount && this.hasUnreadMentionCount; }, /** * When a channel in 'always' setting, meaning the user should see both unread count and unread mention count, * if there are only mention messages, we should apply the theme design tokens var(--dt-theme-mention-color-[background||foreground]-strong). * @returns {boolean} */ shouldApplyCustomStyleForMentionOnly() { return this.channelSetting === "always" && !this.hasUnreadCount && this.hasUnreadMentionCount; } }, watch: { $props: { immediate: !0, deep: !0, async handler() { this.validateProps(), await this.$nextTick(), this.adjustLabelWidth(); } } }, mounted() { this.resizeObserver = new ResizeObserver(this.adjustLabelWidth), this.resizeObserver.observe(m(this.$el)), this.adjustLabelWidth(); }, beforeUnmount: function() { this.resizeObserver.disconnect(); }, methods: { removeClassStyleAttrs: z, addClassStyleAttrs: D, validateProps() { this.type === b.CONTACT_CENTER && !Object.keys(v).includes(this.color) && console.error(O); }, adjustLabelWidth() { var s, a, p, _, d, f; const e = ((a = (s = m(this.$el)) == null ? void 0 : s.querySelector(".d-recipe-leftbar-row__primary")) == null ? void 0 : a.clientWidth) || 0, n = ((_ = (p = m(this.$el)) == null ? void 0 : p.querySelector(".d-recipe-leftbar-row__omega")) == null ? void 0 : _.clientWidth) || 0, t = ((f = (d = m(this.$el)) == null ? void 0 : d.querySelector(".d-recipe-leftbar-row__alpha")) == null ? void 0 : f.clientWidth) || 0, S = 16; this.labelWidth = e - (n + t + S) + "px"; } } }, Y = ["data-qa", "aria-label", "title", "href"], Z = { class: "d-recipe-leftbar-row__alpha" }, J = { key: 0, class: "d-recipe-leftbar-row__is-typing" }, Q = /* @__PURE__ */ l("span", null, null, -1), X = /* @__PURE__ */ l("span", null, null, -1), $ = /* @__PURE__ */ l("span", null, null, -1), ee = [ Q, X, $ ], te = { key: 0, class: "d-recipe-leftbar-row__omega" }, ae = { key: 1, class: "d-recipe-leftbar-row__active-voice" }, re = { key: 3, class: "d-recipe-leftbar-row__action", "data-qa": "dt-recipe-leftbar-row-action" }; function ne(e, n, t, S, s, a) { const p = o("dt-recipe-leftbar-general-row-icon"), _ = o("dt-emoji-text-wrapper"), d = o("dt-tooltip"), f = o("dt-icon-waveform"), T = o("dt-badge"), B = o("dt-icon-phone"), L = o("dt-button"); return r(), h("div", R({ class: a.leftbarGeneralRowClasses }, a.addClassStyleAttrs(e.$attrs), { "data-qa": "dt-recipe-leftbar-row" }), [ l("a", R({ class: "d-recipe-leftbar-row__primary", "data-qa": "data-qa" in e.$attrs ? e.$attrs["data-qa"] : "d-recipe-leftbar-row-link", "aria-label": a.getAriaLabel, title: t.description, href: "href" in e.$attrs ? e.$attrs.href : "javascript:void(0)" }, a.removeClassStyleAttrs(e.$attrs), x(a.generalRowListeners, !0)), [ l("div", Z, [ t.isTyping ? (r(), h("div", J, ee)) : A(e.$slots, "left", { key: 1 }, () => [ c(p, { type: a.getIcon, color: t.color, "icon-size": t.iconSize, "data-qa": "dt-recipe-leftbar-row-icon" }, null, 8, ["type", "color", "icon-size"]) ]) ]), l("div", { class: "d-recipe-leftbar-row__label", style: j(`flex-basis: ${s.labelWidth}`) }, [ A(e.$slots, "label", {}, () => [ c(_, { class: "d-recipe-leftbar-row__description", "data-qa": "dt-recipe-leftbar-row-description", size: "200" }, { default: i(() => [ g(C(t.description), 1) ]), _: 1 }) ]) ], 4) ], 16, Y), a.hasActions ? (r(), h("div", te, [ t.dndText ? (r(), y(d, { key: 0, placement: "top", message: t.dndTextTooltip }, { anchor: i(() => [ l("div", { ref: "d-recipe-leftbar-row-dnd", class: "d-recipe-leftbar-row__dnd", "data-qa": "dt-recipe-leftbar-row-dnd" }, C(t.dndText), 513) ]), _: 1 }, 8, ["message"])) : u("", !0), t.activeVoiceChat ? (r(), h("div", ae, [ c(f, { size: "300" }) ])) : a.showUnreadCount || a.showUnreadMentionCount ? (r(), y(d, { key: 2, message: t.unreadCountTooltip, placement: "top" }, { anchor: i(() => [ a.showUnreadCount ? (r(), y(T, { key: 0, kind: "count", type: "bulletin", "data-qa": "dt-recipe-leftbar-row-unread-badge", class: E(["d-recipe-leftbar-row__unread-badge", { "d-recipe-leftbar-row__unread-count-badge": a.shouldApplyCustomStyleForCountBadge }]) }, { default: i(() => [ g(C(t.unreadCount), 1) ]), _: 1 }, 8, ["class"])) : u("", !0), a.showUnreadMentionCount ? (r(), y(T, { key: 1, kind: "count", type: "bulletin", "data-qa": "dt-recipe-leftbar-row-unread-mention-badge", class: E([ "d-recipe-leftbar-row__unread-badge", { "d-recipe-leftbar-row__unread-mention-count-badge": a.shouldApplyCustomStyleForCountBadge }, { "d-recipe-leftbar-row__unread-mention-only-count-badge": a.shouldApplyCustomStyleForMentionOnly } ]) }, { default: i(() => [ g(C(t.unreadMentionCount), 1) ]), _: 1 }, 8, ["class"])) : u("", !0) ]), _: 1 }, 8, ["message"])) : u("", !0), t.hasCallButton ? (r(), h("div", re, [ c(d, { message: t.callButtonTooltip, placement: "top" }, { anchor: i(() => [ c(L, { class: "d-recipe-leftbar-row__action-button", "data-qa": "dt-recipe-leftbar-row-action-call-button", circle: !0, size: "xs", kind: "inverted", "aria-label": t.callButtonTooltip, onFocus: n[0] || (n[0] = (w) => s.actionFocused = !0), onBlur: n[1] || (n[1] = (w) => s.actionFocused = !1), onClick: n[2] || (n[2] = G((w) => e.$emit("call", w), ["stop"])) }, { icon: i(() => [ c(B, { size: "200" }) ]), _: 1 }, 8, ["aria-label"]) ]), _: 1 }, 8, ["message"]) ])) : u("", !0) ])) : u("", !0) ], 16); } const fe = /* @__PURE__ */ I(K, [["render", ne]]); export { fe as default }; //# sourceMappingURL=general-row.js.map