@api-client/ui 0.5.23 → 0.5.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/lit-best-practices.mdc +12 -1
- package/.github/instructions/lit-best-practices.instructions.md +2 -0
- package/build/src/md/dropdown-list/internals/UiDropdownList.d.ts.map +1 -1
- package/build/src/md/dropdown-list/internals/UiDropdownList.js +4 -3
- package/build/src/md/dropdown-list/internals/UiDropdownList.js.map +1 -1
- package/build/src/md/input/Input.d.ts +8 -4
- package/build/src/md/input/Input.d.ts.map +1 -1
- package/build/src/md/input/Input.js +8 -36
- package/build/src/md/input/Input.js.map +1 -1
- package/build/src/md/list/internals/List.d.ts +3 -1
- package/build/src/md/list/internals/List.d.ts.map +1 -1
- package/build/src/md/list/internals/List.js +10 -5
- package/build/src/md/list/internals/List.js.map +1 -1
- package/build/src/md/menu/internal/Menu.d.ts +8 -7
- package/build/src/md/menu/internal/Menu.d.ts.map +1 -1
- package/build/src/md/menu/internal/Menu.js +39 -29
- package/build/src/md/menu/internal/Menu.js.map +1 -1
- package/build/src/md/menu/internal/Menu.styles.d.ts.map +1 -1
- package/build/src/md/menu/internal/Menu.styles.js +66 -1
- package/build/src/md/menu/internal/Menu.styles.js.map +1 -1
- package/build/src/md/select/index.d.ts +4 -0
- package/build/src/md/select/index.d.ts.map +1 -0
- package/build/src/md/select/index.js +3 -0
- package/build/src/md/select/index.js.map +1 -0
- package/build/src/md/select/internals/Option.d.ts +125 -0
- package/build/src/md/select/internals/Option.d.ts.map +1 -0
- package/build/src/md/select/internals/Option.js +242 -0
- package/build/src/md/select/internals/Option.js.map +1 -0
- package/build/src/md/select/internals/Option.styles.d.ts +3 -0
- package/build/src/md/select/internals/Option.styles.d.ts.map +1 -0
- package/build/src/md/select/internals/Option.styles.js +139 -0
- package/build/src/md/select/internals/Option.styles.js.map +1 -0
- package/build/src/md/select/internals/Select.d.ts +250 -0
- package/build/src/md/select/internals/Select.d.ts.map +1 -0
- package/build/src/md/select/internals/Select.js +606 -0
- package/build/src/md/select/internals/Select.js.map +1 -0
- package/build/src/md/select/internals/Select.styles.d.ts +3 -0
- package/build/src/md/select/internals/Select.styles.d.ts.map +1 -0
- package/build/src/md/select/internals/Select.styles.js +22 -0
- package/build/src/md/select/internals/Select.styles.js.map +1 -0
- package/build/src/md/select/ui-option.d.ts +12 -0
- package/build/src/md/select/ui-option.d.ts.map +1 -0
- package/build/src/md/select/ui-option.js +29 -0
- package/build/src/md/select/ui-option.js.map +1 -0
- package/build/src/md/select/ui-select.d.ts +12 -0
- package/build/src/md/select/ui-select.d.ts.map +1 -0
- package/build/src/md/select/ui-select.js +27 -0
- package/build/src/md/select/ui-select.js.map +1 -0
- package/build/src/md/text-field/internals/TextField.d.ts.map +1 -1
- package/build/src/md/text-field/internals/TextField.js +1 -0
- package/build/src/md/text-field/internals/TextField.js.map +1 -1
- package/demo/md/index.html +2 -0
- package/demo/md/inputs/input.ts +4 -0
- package/demo/md/select/index.html +16 -0
- package/demo/md/select/index.ts +202 -0
- package/package.json +1 -1
- package/src/md/dropdown-list/internals/UiDropdownList.ts +4 -3
- package/src/md/input/Input.ts +8 -37
- package/src/md/list/internals/List.ts +13 -6
- package/src/md/menu/internal/Menu.styles.ts +66 -1
- package/src/md/menu/internal/Menu.ts +41 -18
- package/src/md/select/index.ts +3 -0
- package/src/md/select/internals/Option.styles.ts +139 -0
- package/src/md/select/internals/Option.ts +210 -0
- package/src/md/select/internals/Select.styles.ts +22 -0
- package/src/md/select/internals/Select.ts +534 -0
- package/src/md/select/ui-option.ts +18 -0
- package/src/md/select/ui-select.ts +17 -0
- package/src/md/text-field/internals/TextField.ts +1 -0
- package/test/md/menu/SubMenu.test.ts +2 -3
- package/test/md/select/Select.test.ts +667 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
2
|
import { html } from 'lit';
|
|
3
|
-
import { property, state
|
|
3
|
+
import { property, state } from 'lit/decorators.js';
|
|
4
4
|
import { classMap } from 'lit/directives/class-map.js';
|
|
5
5
|
import { nanoid } from 'nanoid';
|
|
6
6
|
import UiList from '../../list/internals/List.js';
|
|
7
|
-
import UiMenuItem from './MenuItem.js';
|
|
8
7
|
import { setDisabled } from '../../../lib/disabled.js';
|
|
9
8
|
import { bound } from '../../../decorators/bound.js';
|
|
10
9
|
let Menu = (() => {
|
|
@@ -19,9 +18,6 @@ let Menu = (() => {
|
|
|
19
18
|
let _activeSubMenu_decorators;
|
|
20
19
|
let _activeSubMenu_initializers = [];
|
|
21
20
|
let _activeSubMenu_extraInitializers = [];
|
|
22
|
-
let _assignedMenuItems_decorators;
|
|
23
|
-
let _assignedMenuItems_initializers = [];
|
|
24
|
-
let _assignedMenuItems_extraInitializers = [];
|
|
25
21
|
let _handleSubMenuSelect_decorators;
|
|
26
22
|
return class Menu extends _classSuper {
|
|
27
23
|
static {
|
|
@@ -29,12 +25,10 @@ let Menu = (() => {
|
|
|
29
25
|
_open_decorators = [property({ type: Boolean, reflect: true })];
|
|
30
26
|
_disabled_decorators = [property({ type: Boolean, reflect: true })];
|
|
31
27
|
_activeSubMenu_decorators = [state()];
|
|
32
|
-
_assignedMenuItems_decorators = [queryAssignedElements({ selector: 'ui-menu-item' })];
|
|
33
28
|
_handleSubMenuSelect_decorators = [bound];
|
|
34
29
|
__esDecorate(this, null, _open_decorators, { kind: "accessor", name: "open", static: false, private: false, access: { has: obj => "open" in obj, get: obj => obj.open, set: (obj, value) => { obj.open = value; } }, metadata: _metadata }, _open_initializers, _open_extraInitializers);
|
|
35
30
|
__esDecorate(this, null, _disabled_decorators, { kind: "accessor", name: "disabled", static: false, private: false, access: { has: obj => "disabled" in obj, get: obj => obj.disabled, set: (obj, value) => { obj.disabled = value; } }, metadata: _metadata }, _disabled_initializers, _disabled_extraInitializers);
|
|
36
31
|
__esDecorate(this, null, _activeSubMenu_decorators, { kind: "accessor", name: "activeSubMenu", static: false, private: false, access: { has: obj => "activeSubMenu" in obj, get: obj => obj.activeSubMenu, set: (obj, value) => { obj.activeSubMenu = value; } }, metadata: _metadata }, _activeSubMenu_initializers, _activeSubMenu_extraInitializers);
|
|
37
|
-
__esDecorate(this, null, _assignedMenuItems_decorators, { kind: "accessor", name: "assignedMenuItems", static: false, private: false, access: { has: obj => "assignedMenuItems" in obj, get: obj => obj.assignedMenuItems, set: (obj, value) => { obj.assignedMenuItems = value; } }, metadata: _metadata }, _assignedMenuItems_initializers, _assignedMenuItems_extraInitializers);
|
|
38
32
|
__esDecorate(this, null, _handleSubMenuSelect_decorators, { kind: "method", name: "handleSubMenuSelect", static: false, private: false, access: { has: obj => "handleSubMenuSelect" in obj, get: obj => obj.handleSubMenuSelect }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
39
33
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
40
34
|
}
|
|
@@ -61,25 +55,15 @@ let Menu = (() => {
|
|
|
61
55
|
*/
|
|
62
56
|
get disabled() { return this.#disabled_accessor_storage; }
|
|
63
57
|
set disabled(value) { this.#disabled_accessor_storage = value; }
|
|
64
|
-
#activeSubMenu_accessor_storage = (__runInitializers(this, _disabled_extraInitializers), __runInitializers(this, _activeSubMenu_initializers, null
|
|
65
|
-
/**
|
|
66
|
-
* Assigned menu items from light DOM
|
|
67
|
-
*/
|
|
68
|
-
));
|
|
58
|
+
#activeSubMenu_accessor_storage = (__runInitializers(this, _disabled_extraInitializers), __runInitializers(this, _activeSubMenu_initializers, null));
|
|
69
59
|
/**
|
|
70
60
|
* Currently active sub-menu
|
|
71
61
|
*/
|
|
72
62
|
get activeSubMenu() { return this.#activeSubMenu_accessor_storage; }
|
|
73
63
|
set activeSubMenu(value) { this.#activeSubMenu_accessor_storage = value; }
|
|
74
|
-
#assignedMenuItems_accessor_storage = (__runInitializers(this, _activeSubMenu_extraInitializers), __runInitializers(this, _assignedMenuItems_initializers, void 0));
|
|
75
|
-
/**
|
|
76
|
-
* Assigned menu items from light DOM
|
|
77
|
-
*/
|
|
78
|
-
get assignedMenuItems() { return this.#assignedMenuItems_accessor_storage; }
|
|
79
|
-
set assignedMenuItems(value) { this.#assignedMenuItems_accessor_storage = value; }
|
|
80
64
|
constructor() {
|
|
81
65
|
super();
|
|
82
|
-
__runInitializers(this,
|
|
66
|
+
__runInitializers(this, _activeSubMenu_extraInitializers);
|
|
83
67
|
this.selector = 'ui-menu-item';
|
|
84
68
|
this.ariaExpanded = 'false';
|
|
85
69
|
this.addEventListener('beforetoggle', this.handleBeforeToggle.bind(this));
|
|
@@ -112,13 +96,26 @@ let Menu = (() => {
|
|
|
112
96
|
}
|
|
113
97
|
return result;
|
|
114
98
|
}
|
|
99
|
+
queryMenuItems() {
|
|
100
|
+
const slot = this.shadowRoot?.querySelector('slot');
|
|
101
|
+
if (!slot)
|
|
102
|
+
return [];
|
|
103
|
+
const { selector } = this;
|
|
104
|
+
return Array.from(slot.assignedElements({ flatten: true })).filter((el) => el.matches(selector));
|
|
105
|
+
}
|
|
106
|
+
show() {
|
|
107
|
+
this.showPopover();
|
|
108
|
+
}
|
|
109
|
+
hide() {
|
|
110
|
+
this.hidePopover();
|
|
111
|
+
}
|
|
115
112
|
/**
|
|
116
113
|
* Shows the menu
|
|
117
114
|
*/
|
|
118
|
-
|
|
115
|
+
showPopover() {
|
|
119
116
|
this.tabIndex = 0; // Make menu focusable
|
|
120
117
|
this.ariaExpanded = 'true';
|
|
121
|
-
|
|
118
|
+
super.showPopover();
|
|
122
119
|
this.open = true;
|
|
123
120
|
this.positionMenu();
|
|
124
121
|
this.focus();
|
|
@@ -127,10 +124,10 @@ let Menu = (() => {
|
|
|
127
124
|
/**
|
|
128
125
|
* Hides the menu
|
|
129
126
|
*/
|
|
130
|
-
|
|
127
|
+
hidePopover() {
|
|
131
128
|
this.tabIndex = -1;
|
|
132
129
|
this.ariaExpanded = 'false';
|
|
133
|
-
|
|
130
|
+
super.hidePopover();
|
|
134
131
|
this.open = false;
|
|
135
132
|
this.closeSubMenu();
|
|
136
133
|
this.dispatchEvent(new CustomEvent('close', { bubbles: false, composed: true }));
|
|
@@ -144,6 +141,19 @@ let Menu = (() => {
|
|
|
144
141
|
// Reset any previous manual positioning to let CSS anchor positioning work
|
|
145
142
|
this.style.removeProperty('position-area');
|
|
146
143
|
this.style.removeProperty('max-height');
|
|
144
|
+
// Detect if menu is positioned above or below the anchor
|
|
145
|
+
// by checking if the menu is in the upper or lower half of the viewport
|
|
146
|
+
const viewportMiddle = innerHeight / 2;
|
|
147
|
+
const isMenuInUpperHalf = box.top < viewportMiddle;
|
|
148
|
+
// Add CSS class to control animation direction
|
|
149
|
+
if (isMenuInUpperHalf) {
|
|
150
|
+
this.classList.add('menu-positioned-above');
|
|
151
|
+
this.classList.remove('menu-positioned-below');
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
this.classList.add('menu-positioned-below');
|
|
155
|
+
this.classList.remove('menu-positioned-above');
|
|
156
|
+
}
|
|
147
157
|
// Only set max-height if the menu would overflow
|
|
148
158
|
if (menuBottom > innerHeight) {
|
|
149
159
|
const availableHeight = innerHeight - box.top;
|
|
@@ -223,10 +233,8 @@ let Menu = (() => {
|
|
|
223
233
|
}
|
|
224
234
|
notifySelect(item, index) {
|
|
225
235
|
// Handle single selection
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
item.selected = true;
|
|
229
|
-
}
|
|
236
|
+
this.clearSelection();
|
|
237
|
+
item.selected = true;
|
|
230
238
|
this.hide();
|
|
231
239
|
return super.notifySelect(item, index);
|
|
232
240
|
}
|
|
@@ -234,7 +242,8 @@ let Menu = (() => {
|
|
|
234
242
|
* Clears selection from all menu items
|
|
235
243
|
*/
|
|
236
244
|
clearSelection() {
|
|
237
|
-
this.
|
|
245
|
+
const items = this.queryMenuItems();
|
|
246
|
+
items.forEach((menuItem) => {
|
|
238
247
|
menuItem.selected = false;
|
|
239
248
|
});
|
|
240
249
|
}
|
|
@@ -242,7 +251,8 @@ let Menu = (() => {
|
|
|
242
251
|
* Gets the currently selected menu item
|
|
243
252
|
*/
|
|
244
253
|
get selectedItem() {
|
|
245
|
-
|
|
254
|
+
const items = this.queryMenuItems();
|
|
255
|
+
return items.find((item) => item.selected) || null;
|
|
246
256
|
}
|
|
247
257
|
/**
|
|
248
258
|
* Sets the selected menu item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../../../src/md/menu/internal/Menu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAkC,MAAM,KAAK,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,MAAM,MAAM,8BAA8B,CAAA;AACjD,OAAO,UAAU,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;;sBAUlB,MAAM;;;;;;;;;;;;;;;iBAAnB,IAAK,SAAQ,WAAM;;;gCAKrC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oCAM1C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yCAK1C,KAAK,EAAE;6CAKP,qBAAqB,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;+CAiInD,KAAK;YAjJsC,iKAAS,IAAI,6BAAJ,IAAI,mFAAQ;YAMrB,6KAAS,QAAQ,6BAAR,QAAQ,2FAAQ;YAK5D,4LAAS,aAAa,6BAAb,aAAa,qGAAyB;YAKH,wMAAmB,iBAAiB,6BAAjB,iBAAiB,6GAAe;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C;QAED;;WAEG;QACO,gBAAgB;YACxB,kDAAkD;YAClD,IAAI,CAAC,WAAW,EAAE,CAAA;QACpB,CAAC;QAEQ,MAAM;YACb,MAAM,OAAO,GAAG,QAAQ,CAAC;gBACvB,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAA;YAEF,OAAO,IAAI,CAAA;mBACI,OAAO;4BACE,IAAI,CAAC,gBAAgB;;KAE5C,CAAA;QACH,CAAC;;;AA/PH;;;;;;;GAOG;AACH,oBAwPC","sourcesContent":["import { html, PropertyValues, TemplateResult } from 'lit'\nimport { property, state, queryAssignedElements } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { nanoid } from 'nanoid'\nimport UiList from '../../list/internals/List.js'\nimport UiMenuItem from './MenuItem.js'\nimport UiSubMenu from './SubMenu.js'\nimport { setDisabled } from '../../../lib/disabled.js'\nimport UiListItem from '../../list/internals/ListItem.js'\nimport { bound } from '../../../decorators/bound.js'\n\n/**\n * Material Design 3 Menu component with sub-menu support.\n * Uses Popover API and Anchor Positioning API for modern positioning.\n *\n * @fires select - Dispatched when a menu item is selected\n * @fires close - Dispatched when the menu is closed\n * @fires open - Dispatched when the menu is opened\n */\nexport default class Menu extends UiList {\n /**\n * Whether the menu is currently open\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor open = false\n\n /**\n * Whether the menu is disabled\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor disabled = false\n\n /**\n * Currently active sub-menu\n */\n @state() accessor activeSubMenu: UiSubMenu | null = null\n\n /**\n * Assigned menu items from light DOM\n */\n @queryAssignedElements({ selector: 'ui-menu-item' }) protected accessor assignedMenuItems!: UiMenuItem[]\n\n constructor() {\n super()\n this.selector = 'ui-menu-item'\n this.ariaExpanded = 'false'\n this.addEventListener('beforetoggle', this.handleBeforeToggle.bind(this))\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.setAttribute('role', 'menu')\n this.setAttribute('tabindex', '-1')\n if (!this.hasAttribute('popover')) {\n this.setAttribute('popover', 'auto')\n }\n if (!this.id) {\n this.id = nanoid()\n }\n }\n\n protected override updated(changedProperties: PropertyValues<this>): void {\n super.updated(changedProperties)\n\n if (changedProperties.has('disabled')) {\n setDisabled(this, this.disabled)\n }\n }\n\n override togglePopover(force?: boolean): boolean {\n this.open = !this.open\n this.ariaExpanded = String(this.open)\n this.tabIndex = this.open ? 0 : -1\n const result = super.togglePopover(force)\n if (this.open) {\n this.positionMenu()\n this.focus()\n }\n return result\n }\n\n /**\n * Shows the menu\n */\n show(): void {\n this.tabIndex = 0 // Make menu focusable\n this.ariaExpanded = 'true'\n this.showPopover()\n this.open = true\n this.positionMenu()\n this.focus()\n this.dispatchEvent(new CustomEvent('open', { bubbles: false, composed: true }))\n }\n\n /**\n * Hides the menu\n */\n hide(): void {\n this.tabIndex = -1\n this.ariaExpanded = 'false'\n this.hidePopover()\n this.open = false\n this.closeSubMenu()\n this.dispatchEvent(new CustomEvent('close', { bubbles: false, composed: true }))\n }\n\n positionMenu(): void {\n // Let CSS anchor positioning handle the positioning automatically\n // Only intervene if we need to set max-height for overflow cases\n const box = this.getBoundingClientRect()\n const menuBottom = box.top + box.height\n const menuRight = box.left + box.width\n\n // Reset any previous manual positioning to let CSS anchor positioning work\n this.style.removeProperty('position-area')\n this.style.removeProperty('max-height')\n\n // Only set max-height if the menu would overflow\n if (menuBottom > innerHeight) {\n const availableHeight = innerHeight - box.top\n this.style.maxHeight = `${Math.max(200, availableHeight - 20)}px`\n }\n\n if (menuRight > innerWidth) {\n const availableWidth = innerWidth - box.left\n // Let CSS anchor positioning handle horizontal flipping\n // We could set max-width if needed\n if (availableWidth < 200) {\n this.style.maxWidth = `${Math.max(180, availableWidth - 20)}px`\n }\n }\n }\n\n /**\n * Handles beforetoggle event from popover\n */\n protected handleBeforeToggle(e: Event): void {\n const toggleEvent = e as ToggleEvent\n if (toggleEvent.newState === 'closed') {\n this.open = false\n this.closeSubMenu()\n }\n }\n\n /**\n * Handles keyboard navigation for the menu\n */\n override handleKeydown(e: KeyboardEvent): void {\n if (!this.open || e.defaultPrevented) return\n\n switch (e.key) {\n case 'Escape':\n e.preventDefault()\n this.hide()\n break\n case 'ArrowRight':\n e.preventDefault()\n this.openSubMenu()\n break\n case 'ArrowLeft':\n e.preventDefault()\n this.closeSubMenu()\n break\n default:\n // Let the parent UiList handle other keys\n super.handleKeydown(e)\n }\n }\n\n @bound\n handleSubMenuSelect(e: CustomEvent): void {\n super.notifySelect(e.detail.item, e.detail.index)\n }\n\n /**\n * Opens the sub-menu for the currently active item\n */\n protected openSubMenu(): void {\n const activeItem = this.activeListItem as UiMenuItem\n if (activeItem?.hasSubMenu) {\n activeItem.openSubMenu()\n }\n }\n\n /**\n * Closes the currently open sub-menu\n */\n closeSubMenu(): void {\n if (this.activeSubMenu) {\n this.activeSubMenu.removeEventListener('select', this.handleSubMenuSelect as EventListener)\n this.activeSubMenu.hide()\n this.activeSubMenu = null\n }\n }\n\n /**\n * Sets the active sub-menu\n */\n setActiveSubMenu(subMenu: UiSubMenu | null): void {\n this.activeSubMenu = subMenu\n subMenu?.addEventListener('select', this.handleSubMenuSelect as EventListener)\n }\n\n override notifySelect(item: UiListItem, index?: number): boolean {\n // Handle single selection\n if (item instanceof UiMenuItem) {\n this.clearSelection()\n item.selected = true\n }\n\n this.hide()\n return super.notifySelect(item, index)\n }\n\n /**\n * Clears selection from all menu items\n */\n protected clearSelection(): void {\n this.assignedMenuItems.forEach((menuItem) => {\n menuItem.selected = false\n })\n }\n\n /**\n * Gets the currently selected menu item\n */\n get selectedItem(): UiMenuItem | null {\n return this.assignedMenuItems.find((item) => item.selected) || null\n }\n\n /**\n * Sets the selected menu item\n */\n setSelectedItem(item: UiMenuItem | null): void {\n this.clearSelection()\n if (item) {\n item.selected = true\n }\n }\n\n /**\n * Handles sub-menu opening\n */\n protected handleSubMenuOpen(e: CustomEvent): void {\n const subMenu = e.detail.subMenu\n this.setActiveSubMenu(subMenu)\n }\n\n /**\n * Handles slot changes to update menu items\n */\n protected handleSlotChange(): void {\n // Update the items list when slot content changes\n this.updateItems()\n }\n\n override render(): TemplateResult {\n const classes = classMap({\n 'menu-container': true,\n })\n\n return html`\n <div class=${classes}>\n <slot @slotchange=${this.handleSlotChange}></slot>\n </div>\n `\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../../../src/md/menu/internal/Menu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAkC,MAAM,KAAK,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,MAAM,MAAM,8BAA8B,CAAA;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;;sBAUlB,MAAM;;;;;;;;;;;;iBAAnB,IAAK,SAAQ,WAAM;;;gCAKrC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oCAM1C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yCAK1C,KAAK,EAAE;+CA8JP,KAAK;YAzKsC,iKAAS,IAAI,6BAAJ,IAAI,mFAAQ;YAMrB,6KAAS,QAAQ,6BAAR,QAAQ,2FAAQ;YAK5D,4LAAS,aAAa,6BAAb,aAAa,qGAAyB;YA+JxD,4MAAA,mBAAmB,6DAElB;;;QA5K2C,0BALzB,mDAAI,8CAKqC,KAAK;QAEjE;;;WAGG;WAL8D;QAJjE;;;WAGG;QACyC,IAAS,IAAI,0CAAQ;QAArB,IAAS,IAAI,gDAAQ;QAMrB,gIAAoB,KAAK;QAErE;;WAEG;WAJkE;QAJrE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,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;YACnC,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACzB,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAA;YAC3B,CAAC,CAAC,CAAA;QACJ,CAAC;QAED;;WAEG;QACH,IAAI,YAAY;YACd,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;YACnC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAA;QACpD,CAAC;QAED;;WAEG;QACH,eAAe,CAAC,IAAuB;YACrC,IAAI,CAAC,cAAc,EAAE,CAAA;YACrB,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;YACtB,CAAC;QACH,CAAC;QAED;;WAEG;QACO,iBAAiB,CAAC,CAAc;YACxC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAA;YAChC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;QAChC,CAAC;QAED;;WAEG;QACO,gBAAgB;YACxB,kDAAkD;YAClD,IAAI,CAAC,WAAW,EAAE,CAAA;QACpB,CAAC;QAEQ,MAAM;YACb,MAAM,OAAO,GAAG,QAAQ,CAAC;gBACvB,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAA;YAEF,OAAO,IAAI,CAAA;mBACI,OAAO;4BACE,IAAI,CAAC,gBAAgB;;KAE5C,CAAA;QACH,CAAC;;;AAtRH;;;;;;;GAOG;AACH,oBA+QC","sourcesContent":["import { html, PropertyValues, TemplateResult } from 'lit'\nimport { property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { nanoid } from 'nanoid'\nimport UiList from '../../list/internals/List.js'\nimport UiMenuItem from './MenuItem.js'\nimport UiSubMenu from './SubMenu.js'\nimport { setDisabled } from '../../../lib/disabled.js'\nimport UiListItem from '../../list/internals/ListItem.js'\nimport { bound } from '../../../decorators/bound.js'\n\n/**\n * Material Design 3 Menu component with sub-menu support.\n * Uses Popover API and Anchor Positioning API for modern positioning.\n *\n * @fires select - Dispatched when a menu item is selected\n * @fires close - Dispatched when the menu is closed\n * @fires open - Dispatched when the menu is opened\n */\nexport default class Menu extends UiList {\n /**\n * Whether the menu is currently open\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor open = false\n\n /**\n * Whether the menu is disabled\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor disabled = false\n\n /**\n * Currently active sub-menu\n */\n @state() accessor activeSubMenu: UiSubMenu | null = null\n\n constructor() {\n super()\n this.selector = 'ui-menu-item'\n this.ariaExpanded = 'false'\n this.addEventListener('beforetoggle', this.handleBeforeToggle.bind(this))\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.setAttribute('role', 'menu')\n this.setAttribute('tabindex', '-1')\n if (!this.hasAttribute('popover')) {\n this.setAttribute('popover', 'auto')\n }\n if (!this.id) {\n this.id = nanoid()\n }\n }\n\n protected override updated(changedProperties: PropertyValues<this>): void {\n super.updated(changedProperties)\n\n if (changedProperties.has('disabled')) {\n setDisabled(this, this.disabled)\n }\n }\n\n override togglePopover(force?: boolean): boolean {\n this.open = !this.open\n this.ariaExpanded = String(this.open)\n this.tabIndex = this.open ? 0 : -1\n const result = super.togglePopover(force)\n if (this.open) {\n this.positionMenu()\n this.focus()\n }\n return result\n }\n\n protected queryMenuItems(): UiMenuItem[] {\n const slot = this.shadowRoot?.querySelector('slot')\n if (!slot) return []\n const { selector } = this\n return Array.from(slot.assignedElements({ flatten: true })).filter((el) => el.matches(selector)) as UiMenuItem[]\n }\n\n show(): void {\n this.showPopover()\n }\n\n hide(): void {\n this.hidePopover()\n }\n\n /**\n * Shows the menu\n */\n override showPopover(): void {\n this.tabIndex = 0 // Make menu focusable\n this.ariaExpanded = 'true'\n super.showPopover()\n this.open = true\n this.positionMenu()\n this.focus()\n this.dispatchEvent(new CustomEvent('open', { bubbles: false, composed: true }))\n }\n\n /**\n * Hides the menu\n */\n override hidePopover(): void {\n this.tabIndex = -1\n this.ariaExpanded = 'false'\n super.hidePopover()\n this.open = false\n this.closeSubMenu()\n this.dispatchEvent(new CustomEvent('close', { bubbles: false, composed: true }))\n }\n\n positionMenu(): void {\n // Let CSS anchor positioning handle the positioning automatically\n // Only intervene if we need to set max-height for overflow cases\n const box = this.getBoundingClientRect()\n const menuBottom = box.top + box.height\n const menuRight = box.left + box.width\n\n // Reset any previous manual positioning to let CSS anchor positioning work\n this.style.removeProperty('position-area')\n this.style.removeProperty('max-height')\n\n // Detect if menu is positioned above or below the anchor\n // by checking if the menu is in the upper or lower half of the viewport\n const viewportMiddle = innerHeight / 2\n const isMenuInUpperHalf = box.top < viewportMiddle\n\n // Add CSS class to control animation direction\n if (isMenuInUpperHalf) {\n this.classList.add('menu-positioned-above')\n this.classList.remove('menu-positioned-below')\n } else {\n this.classList.add('menu-positioned-below')\n this.classList.remove('menu-positioned-above')\n }\n\n // Only set max-height if the menu would overflow\n if (menuBottom > innerHeight) {\n const availableHeight = innerHeight - box.top\n this.style.maxHeight = `${Math.max(200, availableHeight - 20)}px`\n }\n\n if (menuRight > innerWidth) {\n const availableWidth = innerWidth - box.left\n // Let CSS anchor positioning handle horizontal flipping\n // We could set max-width if needed\n if (availableWidth < 200) {\n this.style.maxWidth = `${Math.max(180, availableWidth - 20)}px`\n }\n }\n }\n\n /**\n * Handles beforetoggle event from popover\n */\n protected handleBeforeToggle(e: Event): void {\n const toggleEvent = e as ToggleEvent\n if (toggleEvent.newState === 'closed') {\n this.open = false\n this.closeSubMenu()\n }\n }\n\n /**\n * Handles keyboard navigation for the menu\n */\n override handleKeydown(e: KeyboardEvent): void {\n if (!this.open || e.defaultPrevented) return\n\n switch (e.key) {\n case 'Escape':\n e.preventDefault()\n this.hide()\n break\n case 'ArrowRight':\n e.preventDefault()\n this.openSubMenu()\n break\n case 'ArrowLeft':\n e.preventDefault()\n this.closeSubMenu()\n break\n default:\n // Let the parent UiList handle other keys\n super.handleKeydown(e)\n }\n }\n\n @bound\n handleSubMenuSelect(e: CustomEvent): void {\n super.notifySelect(e.detail.item, e.detail.index)\n }\n\n /**\n * Opens the sub-menu for the currently active item\n */\n protected openSubMenu(): void {\n const activeItem = this.activeListItem as UiMenuItem\n if (activeItem?.hasSubMenu) {\n activeItem.openSubMenu()\n }\n }\n\n /**\n * Closes the currently open sub-menu\n */\n closeSubMenu(): void {\n if (this.activeSubMenu) {\n this.activeSubMenu.removeEventListener('select', this.handleSubMenuSelect as EventListener)\n this.activeSubMenu.hide()\n this.activeSubMenu = null\n }\n }\n\n /**\n * Sets the active sub-menu\n */\n setActiveSubMenu(subMenu: UiSubMenu | null): void {\n this.activeSubMenu = subMenu\n subMenu?.addEventListener('select', this.handleSubMenuSelect as EventListener)\n }\n\n override notifySelect(item: UiListItem & { selected?: boolean }, index?: number): boolean {\n // Handle single selection\n this.clearSelection()\n item.selected = true\n this.hide()\n return super.notifySelect(item, index)\n }\n\n /**\n * Clears selection from all menu items\n */\n protected clearSelection(): void {\n const items = this.queryMenuItems()\n items.forEach((menuItem) => {\n menuItem.selected = false\n })\n }\n\n /**\n * Gets the currently selected menu item\n */\n get selectedItem(): UiMenuItem | null {\n const items = this.queryMenuItems()\n return items.find((item) => item.selected) || null\n }\n\n /**\n * Sets the selected menu item\n */\n setSelectedItem(item: UiMenuItem | null): void {\n this.clearSelection()\n if (item) {\n item.selected = true\n }\n }\n\n /**\n * Handles sub-menu opening\n */\n protected handleSubMenuOpen(e: CustomEvent): void {\n const subMenu = e.detail.subMenu\n this.setActiveSubMenu(subMenu)\n }\n\n /**\n * Handles slot changes to update menu items\n */\n protected handleSlotChange(): void {\n // Update the items list when slot content changes\n this.updateItems()\n }\n\n override render(): TemplateResult {\n const classes = classMap({\n 'menu-container': true,\n })\n\n return html`\n <div class=${classes}>\n <slot @slotchange=${this.handleSlotChange}></slot>\n </div>\n `\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.styles.d.ts","sourceRoot":"","sources":["../../../../../src/md/menu/internal/Menu.styles.ts"],"names":[],"mappings":";AAEA,
|
|
1
|
+
{"version":3,"file":"Menu.styles.d.ts","sourceRoot":"","sources":["../../../../../src/md/menu/internal/Menu.styles.ts"],"names":[],"mappings":";AAEA,wBAuQC"}
|
|
@@ -28,9 +28,47 @@ export default css `
|
|
|
28
28
|
|
|
29
29
|
:host(:popover-open) {
|
|
30
30
|
display: block;
|
|
31
|
-
background-color: var(--md-sys-color-surface-container
|
|
31
|
+
background-color: var(--md-sys-color-surface-container);
|
|
32
32
|
border-radius: var(--md-sys-shape-corner-extra-small);
|
|
33
33
|
box-shadow: var(--md-sys-elevation-3);
|
|
34
|
+
animation: menu-scale-in 0.15s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Scale animation for menus positioned below the anchor */
|
|
38
|
+
@keyframes menu-scale-in {
|
|
39
|
+
0% {
|
|
40
|
+
transform: scaleY(0);
|
|
41
|
+
transform-origin: top center;
|
|
42
|
+
opacity: 0;
|
|
43
|
+
}
|
|
44
|
+
100% {
|
|
45
|
+
transform: scaleY(1);
|
|
46
|
+
transform-origin: top center;
|
|
47
|
+
opacity: 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Scale animation for menus positioned above the anchor */
|
|
52
|
+
@keyframes menu-scale-in-up {
|
|
53
|
+
0% {
|
|
54
|
+
transform: scaleY(0);
|
|
55
|
+
transform-origin: bottom center;
|
|
56
|
+
opacity: 0;
|
|
57
|
+
}
|
|
58
|
+
100% {
|
|
59
|
+
transform: scaleY(1);
|
|
60
|
+
transform-origin: bottom center;
|
|
61
|
+
opacity: 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* Position-specific animations using JavaScript-detected classes */
|
|
66
|
+
:host(.menu-positioned-above):popover-open {
|
|
67
|
+
animation: menu-scale-in-up 0.15s var(--md-sys-motion-easing-standard-accelerate) forwards;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:host(.menu-positioned-below):popover-open {
|
|
71
|
+
animation: menu-scale-in 0.15s var(--md-sys-motion-easing-standard-accelerate) forwards;
|
|
34
72
|
}
|
|
35
73
|
|
|
36
74
|
.menu-container {
|
|
@@ -141,6 +179,21 @@ export default css `
|
|
|
141
179
|
max-width: 320px;
|
|
142
180
|
padding: 8px 0;
|
|
143
181
|
z-index: 1000;
|
|
182
|
+
animation: submenu-scale-in 0.12s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* Submenu scale animation */
|
|
186
|
+
@keyframes submenu-scale-in {
|
|
187
|
+
0% {
|
|
188
|
+
transform: scaleY(0) scaleX(0.8);
|
|
189
|
+
transform-origin: left top;
|
|
190
|
+
opacity: 0;
|
|
191
|
+
}
|
|
192
|
+
100% {
|
|
193
|
+
transform: scaleY(1) scaleX(1);
|
|
194
|
+
transform-origin: left top;
|
|
195
|
+
opacity: 1;
|
|
196
|
+
}
|
|
144
197
|
}
|
|
145
198
|
|
|
146
199
|
/* Fallback positioning for browsers without anchor positioning */
|
|
@@ -196,6 +249,18 @@ export default css `
|
|
|
196
249
|
.menu-item {
|
|
197
250
|
transition: none;
|
|
198
251
|
}
|
|
252
|
+
|
|
253
|
+
:host(:popover-open) {
|
|
254
|
+
animation: none;
|
|
255
|
+
opacity: 1;
|
|
256
|
+
transform: none;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
ui-sub-menu:popover-open {
|
|
260
|
+
animation: none;
|
|
261
|
+
opacity: 1;
|
|
262
|
+
transform: none;
|
|
263
|
+
}
|
|
199
264
|
}
|
|
200
265
|
`;
|
|
201
266
|
//# sourceMappingURL=Menu.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.styles.js","sourceRoot":"","sources":["../../../../../src/md/menu/internal/Menu.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,eAAe,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"Menu.styles.js","sourceRoot":"","sources":["../../../../../src/md/menu/internal/Menu.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,eAAe,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuQjB,CAAA","sourcesContent":["import { css } from 'lit'\n\nexport default css`\n :host {\n display: none;\n position-area: bottom span-right;\n position-try: --menu-fallback-bottom-left, --menu-fallback-top-right, --menu-fallback-top-left, flip-block;\n position: absolute;\n margin: 0;\n padding: 0;\n border: none;\n overflow: hidden;\n /* in most cases the max-height won't matter as this assumes the whole screen to be available, which is rarely the truth. */\n max-height: 90vh;\n overflow: auto;\n }\n\n @position-try --menu-fallback-bottom-left {\n position-area: bottom span-left;\n }\n\n @position-try --menu-fallback-top-right {\n position-area: top span-right;\n }\n\n @position-try --menu-fallback-top-left {\n position-area: top span-left;\n }\n\n :host(:popover-open) {\n display: block;\n background-color: var(--md-sys-color-surface-container);\n border-radius: var(--md-sys-shape-corner-extra-small);\n box-shadow: var(--md-sys-elevation-3);\n animation: menu-scale-in 0.15s cubic-bezier(0.4, 0, 0.2, 1) forwards;\n }\n\n /* Scale animation for menus positioned below the anchor */\n @keyframes menu-scale-in {\n 0% {\n transform: scaleY(0);\n transform-origin: top center;\n opacity: 0;\n }\n 100% {\n transform: scaleY(1);\n transform-origin: top center;\n opacity: 1;\n }\n }\n\n /* Scale animation for menus positioned above the anchor */\n @keyframes menu-scale-in-up {\n 0% {\n transform: scaleY(0);\n transform-origin: bottom center;\n opacity: 0;\n }\n 100% {\n transform: scaleY(1);\n transform-origin: bottom center;\n opacity: 1;\n }\n }\n\n /* Position-specific animations using JavaScript-detected classes */\n :host(.menu-positioned-above):popover-open {\n animation: menu-scale-in-up 0.15s var(--md-sys-motion-easing-standard-accelerate) forwards;\n }\n\n :host(.menu-positioned-below):popover-open {\n animation: menu-scale-in 0.15s var(--md-sys-motion-easing-standard-accelerate) forwards;\n }\n\n .menu-container {\n min-width: 200px;\n padding: 8px 0;\n outline: none;\n }\n\n .menu-divider {\n height: 1px;\n background-color: var(--md-sys-color-outline-variant);\n margin: 8px 0;\n }\n\n /* Menu Item Styles */\n .menu-item {\n position: relative;\n display: flex;\n align-items: center;\n min-height: 48px;\n padding: 0 16px;\n cursor: pointer;\n outline: none;\n transition: background-color 0.2s ease;\n }\n\n .menu-item:hover {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n .menu-item:focus {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n .menu-item[disabled] {\n opacity: 0.38;\n cursor: not-allowed;\n pointer-events: none;\n }\n\n .menu-item-content {\n display: flex;\n align-items: center;\n width: 100%;\n gap: 12px;\n }\n\n .menu-item-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n color: var(--md-sys-color-on-surface);\n font-size: 20px;\n }\n\n .menu-item-label {\n flex: 1;\n color: var(--md-sys-color-on-surface);\n font-family: var(--md-sys-typescale-label-large-font-family-name);\n font-size: var(--md-sys-typescale-label-large-font-size);\n font-weight: var(--md-sys-typescale-label-large-font-weight);\n line-height: var(--md-sys-typescale-label-large-line-height);\n letter-spacing: var(--md-sys-typescale-label-large-letter-spacing);\n }\n\n .menu-item-arrow {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n color: var(--md-sys-color-on-surface);\n font-size: 18px;\n font-weight: 500;\n }\n\n .menu-item-with-submenu {\n position: relative;\n }\n\n .menu-item-with-submenu:hover .menu-item-arrow {\n color: var(--md-sys-color-primary);\n }\n\n /* Sub-menu Styles */\n .submenu-container {\n min-width: 200px;\n max-width: 320px;\n background-color: var(--md-sys-color-surface);\n border-radius: var(--md-sys-shape-corner-extra-small);\n box-shadow: var(--md-sys-elevation-level3);\n padding: 8px 0;\n }\n\n /* Submenu positioning with Anchor API */\n ui-sub-menu {\n display: none;\n }\n\n ui-sub-menu:popover-open {\n display: block;\n background-color: var(--md-sys-color-surface);\n border-radius: var(--md-sys-shape-corner-extra-small);\n box-shadow: var(--md-sys-elevation-level3);\n min-width: 200px;\n max-width: 320px;\n padding: 8px 0;\n z-index: 1000;\n animation: submenu-scale-in 0.12s cubic-bezier(0.4, 0, 0.2, 1) forwards;\n }\n\n /* Submenu scale animation */\n @keyframes submenu-scale-in {\n 0% {\n transform: scaleY(0) scaleX(0.8);\n transform-origin: left top;\n opacity: 0;\n }\n 100% {\n transform: scaleY(1) scaleX(1);\n transform-origin: left top;\n opacity: 1;\n }\n }\n\n /* Fallback positioning for browsers without anchor positioning */\n @supports not (anchor-name: --test) {\n ui-sub-menu:popover-open {\n position: fixed;\n transform: translateX(200px);\n }\n }\n\n /* Focus Ring */\n md-focus-ring {\n --md-focus-ring-color: var(--md-sys-color-primary);\n --md-focus-ring-width: 2px;\n }\n\n /* Ripple Effect */\n ui-ripple {\n --md-ripple-color: var(--md-sys-color-primary);\n --md-ripple-opacity: 0.12;\n }\n\n /* Responsive Design */\n @media (max-width: 600px) {\n .menu-container {\n min-width: 180px;\n max-width: 280px;\n }\n\n .submenu-container {\n min-width: 180px;\n max-width: 280px;\n }\n }\n\n /* High Contrast Mode */\n @media (prefers-contrast: high) {\n .menu-container {\n border: 1px solid var(--md-sys-color-outline);\n }\n\n .submenu-container {\n border: 1px solid var(--md-sys-color-outline);\n }\n\n .menu-divider {\n background-color: var(--md-sys-color-outline);\n }\n }\n\n /* Reduced Motion */\n @media (prefers-reduced-motion: reduce) {\n .menu-item {\n transition: none;\n }\n\n :host(:popover-open) {\n animation: none;\n opacity: 1;\n transform: none;\n }\n\n ui-sub-menu:popover-open {\n animation: none;\n opacity: 1;\n transform: none;\n }\n }\n`\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/md/select/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/md/select/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA","sourcesContent":["export { UiSelectElement } from './ui-select.js'\nexport { UiOptionElement } from './ui-option.js'\nexport type { UiListItemsChange, UiListSelection } from '../list/internals/List.js'\n"]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import UiListItem from '../../list/internals/ListItem.js';
|
|
3
|
+
/**
|
|
4
|
+
* Material Design 3 Select Option component.
|
|
5
|
+
*
|
|
6
|
+
* The `ui-option` component represents a selectable item within a `ui-select` dropdown.
|
|
7
|
+
* It extends `UiListItem` to provide consistent styling and behavior with other list components.
|
|
8
|
+
*
|
|
9
|
+
* @slot - The option content (label, icon, etc.)
|
|
10
|
+
* @slot start - Content to display at the start of the option (icon, avatar, etc.)
|
|
11
|
+
* @slot end - Content to display at the end of the option
|
|
12
|
+
* @slot supporting-text - Supporting text below the main content
|
|
13
|
+
* @fires select - Dispatched when the option is selected. Contains `{ item: UiOption, value: string }` in detail
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* Basic option
|
|
17
|
+
* ```html
|
|
18
|
+
* <ui-option value="apple">Apple</ui-option>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* Option with supporting text
|
|
23
|
+
* ```html
|
|
24
|
+
* <ui-option value="john" lines="two">
|
|
25
|
+
* John Doe
|
|
26
|
+
* <span slot="supporting-text">john@example.com</span>
|
|
27
|
+
* </ui-option>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export default class UiOption extends UiListItem {
|
|
31
|
+
/**
|
|
32
|
+
* The value associated with this option. Used to identify the option when selected.
|
|
33
|
+
* This value is what gets set on the parent select element when this option is chosen.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```html
|
|
37
|
+
* <ui-option value="apple">Apple</ui-option>
|
|
38
|
+
* <ui-option value="banana">Banana</ui-option>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
accessor value: string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Whether this option is currently selected. This is typically managed automatically
|
|
44
|
+
* by the parent select component, but can be set manually for styling purposes.
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
* @example
|
|
48
|
+
* ```html
|
|
49
|
+
* <ui-option value="apple" selected>Apple</ui-option>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
accessor selected: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the text representation of this option for display purposes.
|
|
55
|
+
* This method extracts and combines text content from all child nodes,
|
|
56
|
+
* including special handling for ui-icon elements.
|
|
57
|
+
*
|
|
58
|
+
* @readonly
|
|
59
|
+
* @returns {string} The rendered text value of the option
|
|
60
|
+
* @example
|
|
61
|
+
* ```javascript
|
|
62
|
+
* const option = document.querySelector('ui-option');
|
|
63
|
+
* console.log('Option text:', option.renderValue);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
get renderValue(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Initializes the option when it's connected to the DOM. Sets up ARIA attributes
|
|
69
|
+
* and generates a unique ID if one isn't provided.
|
|
70
|
+
*
|
|
71
|
+
* @protected
|
|
72
|
+
*/
|
|
73
|
+
connectedCallback(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Handles property updates and triggers appropriate side effects.
|
|
76
|
+
* Currently monitors the `selected` property to update selection state.
|
|
77
|
+
*
|
|
78
|
+
* @param {PropertyValues<this>} changedProperties - Map of changed properties
|
|
79
|
+
* @protected
|
|
80
|
+
*/
|
|
81
|
+
protected updated(changedProperties: PropertyValues<this>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Updates the visual and accessibility state when selection changes.
|
|
84
|
+
* Adds/removes CSS classes and ARIA attributes based on selection state.
|
|
85
|
+
*
|
|
86
|
+
* @protected
|
|
87
|
+
* @example
|
|
88
|
+
* ```javascript
|
|
89
|
+
* // This is called automatically when the selected property changes
|
|
90
|
+
* option.selected = true; // Will trigger updateSelectionState()
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
protected updateSelectionState(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Handles click events on the option. Prevents default behavior and dispatches
|
|
96
|
+
* a custom 'select' event that the parent select component can listen to.
|
|
97
|
+
*
|
|
98
|
+
* @param {MouseEvent} e - The click event
|
|
99
|
+
* @protected
|
|
100
|
+
* @fires select - Custom event with option details in event.detail
|
|
101
|
+
* @example
|
|
102
|
+
* ```javascript
|
|
103
|
+
* // Listen for option selection
|
|
104
|
+
* option.addEventListener('select', (e) => {
|
|
105
|
+
* console.log('Selected option:', e.detail.item);
|
|
106
|
+
* console.log('Selected value:', e.detail.value);
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
handleClick(e: MouseEvent): void;
|
|
111
|
+
/**
|
|
112
|
+
* Renders the option's template. Creates the main structure with focus ring,
|
|
113
|
+
* ripple effect, and content areas.
|
|
114
|
+
*
|
|
115
|
+
* @returns {TemplateResult} The rendered template
|
|
116
|
+
* @protected
|
|
117
|
+
*/
|
|
118
|
+
protected render(): TemplateResult;
|
|
119
|
+
/**
|
|
120
|
+
* Renders the end section of the option, including the selection check icon
|
|
121
|
+
* when the option is selected.
|
|
122
|
+
*/
|
|
123
|
+
protected renderEnd(): TemplateResult;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=Option.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../../../../src/md/select/internals/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAG1D,OAAO,UAAU,MAAM,kCAAkC,CAAA;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,UAAU;IAC9C;;;;;;;;;OASG;IACwC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAE7E;;;;;;;;;OASG;IACyC,QAAQ,CAAC,QAAQ,UAAQ;IAErE;;;;;;;;;;;;OAYG;IACH,IAAI,WAAW,IAAI,MAAM,CAkBxB;IAED;;;;;OAKG;IACM,iBAAiB,IAAI,IAAI;IAQlC;;;;;;OAMG;cACgB,OAAO,CAAC,iBAAiB,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IAQzE;;;;;;;;;;OAUG;IACH,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAUtC;;;;;;;;;;;;;;;OAeG;IACM,WAAW,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI;IAoBzC;;;;;;OAMG;cACgB,MAAM,IAAI,cAAc;IAY3C;;;OAGG;cACgB,SAAS,IAAI,cAAc;CAS/C"}
|