UNPKG

2.94 kBJavaScriptView Raw
1import {
2 menu_item_styles_default
3} from "./chunk.ZMJGXRI5.js";
4import {
5 getTextContent
6} from "./chunk.3IYPB6RR.js";
7import {
8 o
9} from "./chunk.IAELDRGJ.js";
10import {
11 watch
12} from "./chunk.W6MGCO4G.js";
13import {
14 emit
15} from "./chunk.UY5AQKHP.js";
16import {
17 e,
18 i,
19 n
20} from "./chunk.VKNZYXSO.js";
21import {
22 $,
23 s
24} from "./chunk.WWAD5WF4.js";
25import {
26 __decorateClass
27} from "./chunk.K2NRSETB.js";
28
29// src/components/menu-item/menu-item.ts
30var SlMenuItem = class extends s {
31 constructor() {
32 super(...arguments);
33 this.checked = false;
34 this.value = "";
35 this.disabled = false;
36 }
37 firstUpdated() {
38 this.setAttribute("role", "menuitem");
39 }
40 getTextLabel() {
41 return getTextContent(this.defaultSlot);
42 }
43 handleCheckedChange() {
44 this.setAttribute("aria-checked", this.checked ? "true" : "false");
45 }
46 handleDisabledChange() {
47 this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
48 }
49 handleDefaultSlotChange() {
50 const textLabel = this.getTextLabel();
51 if (typeof this.cachedTextLabel === "undefined") {
52 this.cachedTextLabel = textLabel;
53 return;
54 }
55 if (textLabel !== this.cachedTextLabel) {
56 this.cachedTextLabel = textLabel;
57 emit(this, "sl-label-change");
58 }
59 }
60 render() {
61 return $`
62 <div
63 part="base"
64 class=${o({
65 "menu-item": true,
66 "menu-item--checked": this.checked,
67 "menu-item--disabled": this.disabled,
68 "menu-item--has-submenu": false
69 })}
70 >
71 <span part="checked-icon" class="menu-item__check">
72 <sl-icon name="check-lg" library="system" aria-hidden="true"></sl-icon>
73 </span>
74
75 <span part="prefix" class="menu-item__prefix">
76 <slot name="prefix"></slot>
77 </span>
78
79 <span part="label" class="menu-item__label">
80 <slot @slotchange=${this.handleDefaultSlotChange}></slot>
81 </span>
82
83 <span part="suffix" class="menu-item__suffix">
84 <slot name="suffix"></slot>
85 </span>
86
87 <span class="menu-item__chevron">
88 <sl-icon name="chevron-right" library="system" aria-hidden="true"></sl-icon>
89 </span>
90 </div>
91 `;
92 }
93};
94SlMenuItem.styles = menu_item_styles_default;
95__decorateClass([
96 i("slot:not([name])")
97], SlMenuItem.prototype, "defaultSlot", 2);
98__decorateClass([
99 i(".menu-item")
100], SlMenuItem.prototype, "menuItem", 2);
101__decorateClass([
102 e({ type: Boolean, reflect: true })
103], SlMenuItem.prototype, "checked", 2);
104__decorateClass([
105 e()
106], SlMenuItem.prototype, "value", 2);
107__decorateClass([
108 e({ type: Boolean, reflect: true })
109], SlMenuItem.prototype, "disabled", 2);
110__decorateClass([
111 watch("checked")
112], SlMenuItem.prototype, "handleCheckedChange", 1);
113__decorateClass([
114 watch("disabled")
115], SlMenuItem.prototype, "handleDisabledChange", 1);
116SlMenuItem = __decorateClass([
117 n("sl-menu-item")
118], SlMenuItem);
119
120export {
121 SlMenuItem
122};