@chromvoid/uikit 0.1.0
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/LICENSE +8 -0
- package/README.md +96 -0
- package/dist/components/cv-accordion-item.d.ts +69 -0
- package/dist/components/cv-accordion-item.js +176 -0
- package/dist/components/cv-accordion.d.ts +79 -0
- package/dist/components/cv-accordion.js +310 -0
- package/dist/components/cv-alert-dialog.d.ts +86 -0
- package/dist/components/cv-alert-dialog.js +393 -0
- package/dist/components/cv-alert.d.ts +48 -0
- package/dist/components/cv-alert.js +156 -0
- package/dist/components/cv-badge.d.ts +56 -0
- package/dist/components/cv-badge.js +280 -0
- package/dist/components/cv-breadcrumb-item.d.ts +35 -0
- package/dist/components/cv-breadcrumb-item.js +64 -0
- package/dist/components/cv-breadcrumb.d.ts +39 -0
- package/dist/components/cv-breadcrumb.js +160 -0
- package/dist/components/cv-button.d.ts +83 -0
- package/dist/components/cv-button.js +541 -0
- package/dist/components/cv-callout.d.ts +32 -0
- package/dist/components/cv-callout.js +221 -0
- package/dist/components/cv-card.d.ts +48 -0
- package/dist/components/cv-card.js +269 -0
- package/dist/components/cv-carousel-slide.d.ts +25 -0
- package/dist/components/cv-carousel-slide.js +51 -0
- package/dist/components/cv-carousel.d.ts +96 -0
- package/dist/components/cv-carousel.js +457 -0
- package/dist/components/cv-checkbox.d.ts +84 -0
- package/dist/components/cv-checkbox.js +274 -0
- package/dist/components/cv-combobox-group.d.ts +15 -0
- package/dist/components/cv-combobox-group.js +34 -0
- package/dist/components/cv-combobox-option.d.ts +30 -0
- package/dist/components/cv-combobox-option.js +66 -0
- package/dist/components/cv-combobox.d.ts +135 -0
- package/dist/components/cv-combobox.js +834 -0
- package/dist/components/cv-command-item.d.ts +30 -0
- package/dist/components/cv-command-item.js +68 -0
- package/dist/components/cv-command-palette.d.ts +105 -0
- package/dist/components/cv-command-palette.js +578 -0
- package/dist/components/cv-context-menu.d.ts +98 -0
- package/dist/components/cv-context-menu.js +515 -0
- package/dist/components/cv-copy-button.d.ts +61 -0
- package/dist/components/cv-copy-button.js +318 -0
- package/dist/components/cv-date-picker.d.ts +161 -0
- package/dist/components/cv-date-picker.js +803 -0
- package/dist/components/cv-dialog.d.ts +89 -0
- package/dist/components/cv-dialog.js +459 -0
- package/dist/components/cv-disclosure.d.ts +57 -0
- package/dist/components/cv-disclosure.js +241 -0
- package/dist/components/cv-drawer.d.ts +102 -0
- package/dist/components/cv-drawer.js +595 -0
- package/dist/components/cv-feed-article.d.ts +26 -0
- package/dist/components/cv-feed-article.js +52 -0
- package/dist/components/cv-feed.d.ts +62 -0
- package/dist/components/cv-feed.js +310 -0
- package/dist/components/cv-grid-cell.d.ts +30 -0
- package/dist/components/cv-grid-cell.js +57 -0
- package/dist/components/cv-grid-column.d.ts +30 -0
- package/dist/components/cv-grid-column.js +43 -0
- package/dist/components/cv-grid-row.d.ts +30 -0
- package/dist/components/cv-grid-row.js +42 -0
- package/dist/components/cv-grid.d.ts +119 -0
- package/dist/components/cv-grid.js +567 -0
- package/dist/components/cv-icon.d.ts +57 -0
- package/dist/components/cv-icon.js +352 -0
- package/dist/components/cv-input.d.ts +127 -0
- package/dist/components/cv-input.js +482 -0
- package/dist/components/cv-landmark.d.ts +32 -0
- package/dist/components/cv-landmark.js +62 -0
- package/dist/components/cv-link.d.ts +22 -0
- package/dist/components/cv-link.js +99 -0
- package/dist/components/cv-listbox-group.d.ts +15 -0
- package/dist/components/cv-listbox-group.js +42 -0
- package/dist/components/cv-listbox.d.ts +81 -0
- package/dist/components/cv-listbox.js +388 -0
- package/dist/components/cv-menu-button.d.ts +118 -0
- package/dist/components/cv-menu-button.js +822 -0
- package/dist/components/cv-menu-group.d.ts +20 -0
- package/dist/components/cv-menu-group.js +48 -0
- package/dist/components/cv-menu-item.d.ts +52 -0
- package/dist/components/cv-menu-item.js +105 -0
- package/dist/components/cv-menu.d.ts +62 -0
- package/dist/components/cv-menu.js +414 -0
- package/dist/components/cv-meter.d.ts +66 -0
- package/dist/components/cv-meter.js +154 -0
- package/dist/components/cv-number.d.ts +139 -0
- package/dist/components/cv-number.js +553 -0
- package/dist/components/cv-option.d.ts +30 -0
- package/dist/components/cv-option.js +84 -0
- package/dist/components/cv-popover.d.ts +87 -0
- package/dist/components/cv-popover.js +373 -0
- package/dist/components/cv-progress-ring.d.ts +45 -0
- package/dist/components/cv-progress-ring.js +169 -0
- package/dist/components/cv-progress.d.ts +45 -0
- package/dist/components/cv-progress.js +148 -0
- package/dist/components/cv-radio-group.d.ts +79 -0
- package/dist/components/cv-radio-group.js +398 -0
- package/dist/components/cv-radio.d.ts +36 -0
- package/dist/components/cv-radio.js +123 -0
- package/dist/components/cv-select-group.d.ts +15 -0
- package/dist/components/cv-select-group.js +44 -0
- package/dist/components/cv-select-option.d.ts +30 -0
- package/dist/components/cv-select-option.js +66 -0
- package/dist/components/cv-select.d.ts +128 -0
- package/dist/components/cv-select.js +666 -0
- package/dist/components/cv-sidebar-item.d.ts +26 -0
- package/dist/components/cv-sidebar-item.js +142 -0
- package/dist/components/cv-sidebar.d.ts +171 -0
- package/dist/components/cv-sidebar.js +767 -0
- package/dist/components/cv-slider-multi-thumb.d.ts +73 -0
- package/dist/components/cv-slider-multi-thumb.js +374 -0
- package/dist/components/cv-slider.d.ts +84 -0
- package/dist/components/cv-slider.js +328 -0
- package/dist/components/cv-spinbutton.d.ts +121 -0
- package/dist/components/cv-spinbutton.js +486 -0
- package/dist/components/cv-spinner.d.ts +18 -0
- package/dist/components/cv-spinner.js +95 -0
- package/dist/components/cv-switch.d.ts +81 -0
- package/dist/components/cv-switch.js +285 -0
- package/dist/components/cv-tab-panel.d.ts +20 -0
- package/dist/components/cv-tab-panel.js +37 -0
- package/dist/components/cv-tab.d.ts +40 -0
- package/dist/components/cv-tab.js +132 -0
- package/dist/components/cv-table-cell.d.ts +31 -0
- package/dist/components/cv-table-cell.js +49 -0
- package/dist/components/cv-table-column.d.ts +37 -0
- package/dist/components/cv-table-column.js +63 -0
- package/dist/components/cv-table-row.d.ts +30 -0
- package/dist/components/cv-table-row.js +45 -0
- package/dist/components/cv-table.d.ts +147 -0
- package/dist/components/cv-table.js +607 -0
- package/dist/components/cv-tabs.d.ts +70 -0
- package/dist/components/cv-tabs.js +524 -0
- package/dist/components/cv-textarea.d.ts +108 -0
- package/dist/components/cv-textarea.js +328 -0
- package/dist/components/cv-toast-region.d.ts +39 -0
- package/dist/components/cv-toast-region.js +162 -0
- package/dist/components/cv-toast.d.ts +67 -0
- package/dist/components/cv-toast.js +315 -0
- package/dist/components/cv-toolbar-item.d.ts +25 -0
- package/dist/components/cv-toolbar-item.js +72 -0
- package/dist/components/cv-toolbar-separator.d.ts +25 -0
- package/dist/components/cv-toolbar-separator.js +45 -0
- package/dist/components/cv-toolbar.d.ts +63 -0
- package/dist/components/cv-toolbar.js +295 -0
- package/dist/components/cv-tooltip.d.ts +83 -0
- package/dist/components/cv-tooltip.js +455 -0
- package/dist/components/cv-treegrid-cell.d.ts +30 -0
- package/dist/components/cv-treegrid-cell.js +57 -0
- package/dist/components/cv-treegrid-column.d.ts +37 -0
- package/dist/components/cv-treegrid-column.js +53 -0
- package/dist/components/cv-treegrid-row.d.ts +55 -0
- package/dist/components/cv-treegrid-row.js +90 -0
- package/dist/components/cv-treegrid.d.ts +96 -0
- package/dist/components/cv-treegrid.js +632 -0
- package/dist/components/cv-treeitem.d.ts +58 -0
- package/dist/components/cv-treeitem.js +144 -0
- package/dist/components/cv-treeview.d.ts +70 -0
- package/dist/components/cv-treeview.js +396 -0
- package/dist/components/cv-window-splitter.d.ts +79 -0
- package/dist/components/cv-window-splitter.js +316 -0
- package/dist/components/index.d.ts +94 -0
- package/dist/components/index.js +79 -0
- package/dist/dialog/create-dialog-controller.d.ts +31 -0
- package/dist/dialog/create-dialog-controller.js +320 -0
- package/dist/dialog/index.d.ts +2 -0
- package/dist/dialog/index.js +1 -0
- package/dist/form-associated/FormAssociatedReatomElement.d.ts +25 -0
- package/dist/form-associated/FormAssociatedReatomElement.js +70 -0
- package/dist/form-associated/withFormAssociated.d.ts +5 -0
- package/dist/form-associated/withFormAssociated.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/reatom-lit/ReatomLitElement.d.ts +27 -0
- package/dist/reatom-lit/ReatomLitElement.js +118 -0
- package/dist/reatom-lit/html.d.ts +4 -0
- package/dist/reatom-lit/html.js +10 -0
- package/dist/reatom-lit/index.d.ts +4 -0
- package/dist/reatom-lit/index.js +4 -0
- package/dist/reatom-lit/watch.d.ts +15 -0
- package/dist/reatom-lit/watch.js +40 -0
- package/dist/reatom-lit/withReatomElement.d.ts +4 -0
- package/dist/reatom-lit/withReatomElement.js +57 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +84 -0
- package/dist/styles/component-styles.d.ts +4 -0
- package/dist/styles/component-styles.js +78 -0
- package/dist/theme/cv-theme-provider.d.ts +32 -0
- package/dist/theme/cv-theme-provider.js +110 -0
- package/dist/theme/index.d.ts +4 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/theme-engine.d.ts +4 -0
- package/dist/theme/theme-engine.js +67 -0
- package/dist/theme/tokens.css +265 -0
- package/dist/theme/types.d.ts +7 -0
- package/dist/theme/types.js +1 -0
- package/dist/toast/create-toast-controller.d.ts +12 -0
- package/dist/toast/create-toast-controller.js +12 -0
- package/dist/toast/index.d.ts +2 -0
- package/dist/toast/index.js +1 -0
- package/package.json +146 -0
- package/specs/_template.md +110 -0
- package/specs/components/accordion.md +207 -0
- package/specs/components/alert.md +83 -0
- package/specs/components/badge.md +183 -0
- package/specs/components/breadcrumb.md +152 -0
- package/specs/components/button.md +227 -0
- package/specs/components/callout.md +153 -0
- package/specs/components/card.md +192 -0
- package/specs/components/carousel.md +232 -0
- package/specs/components/checkbox.md +141 -0
- package/specs/components/combobox.md +427 -0
- package/specs/components/context-menu.md +375 -0
- package/specs/components/copy-button.md +236 -0
- package/specs/components/date-picker.md +290 -0
- package/specs/components/dialog.md +184 -0
- package/specs/components/disclosure.md +151 -0
- package/specs/components/drawer.md +216 -0
- package/specs/components/feed.md +266 -0
- package/specs/components/grid.md +423 -0
- package/specs/components/input.md +237 -0
- package/specs/components/landmark.md +92 -0
- package/specs/components/link.md +117 -0
- package/specs/components/listbox.md +327 -0
- package/specs/components/menu.md +508 -0
- package/specs/components/meter.md +148 -0
- package/specs/components/number.md +268 -0
- package/specs/components/option.md +167 -0
- package/specs/components/popover.md +207 -0
- package/specs/components/progress-ring.md +134 -0
- package/specs/components/progress.md +110 -0
- package/specs/components/radio.md +208 -0
- package/specs/components/select.md +305 -0
- package/specs/components/sidebar.md +204 -0
- package/specs/components/spinbutton.md +157 -0
- package/specs/components/spinner.md +83 -0
- package/specs/components/switch.md +145 -0
- package/specs/components/table.md +372 -0
- package/specs/components/tabs.md +242 -0
- package/specs/components/textarea.md +166 -0
- package/specs/components/theme.md +364 -0
- package/specs/components/toast.md +198 -0
- package/specs/components/toolbar.md +258 -0
- package/specs/components/tooltip.md +152 -0
- package/specs/components/treegrid.md +363 -0
- package/specs/components/treeview.md +263 -0
- package/specs/components/window-splitter.md +225 -0
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
import { createMenuButton } from '@chromvoid/headless-ui/menu-button';
|
|
2
|
+
import { css, html, nothing } from 'lit';
|
|
3
|
+
import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
|
|
4
|
+
import { CVIcon } from './cv-icon.js';
|
|
5
|
+
import { CVMenuItem } from './cv-menu-item.js';
|
|
6
|
+
const menuButtonKeysToPrevent = new Set([
|
|
7
|
+
'ArrowUp',
|
|
8
|
+
'ArrowDown',
|
|
9
|
+
'Home',
|
|
10
|
+
'End',
|
|
11
|
+
'Enter',
|
|
12
|
+
' ',
|
|
13
|
+
'Spacebar',
|
|
14
|
+
'Escape',
|
|
15
|
+
'Tab',
|
|
16
|
+
]);
|
|
17
|
+
let cvMenuButtonNonce = 0;
|
|
18
|
+
export class CVMenuButton extends ReatomLitElement {
|
|
19
|
+
static elementName = 'cv-menu-button';
|
|
20
|
+
static hostDisplay = 'inline-block';
|
|
21
|
+
static get properties() {
|
|
22
|
+
return {
|
|
23
|
+
value: { type: String, reflect: true },
|
|
24
|
+
open: { type: Boolean, reflect: true },
|
|
25
|
+
disabled: { type: Boolean, reflect: true },
|
|
26
|
+
split: { type: Boolean, reflect: true },
|
|
27
|
+
size: { type: String, reflect: true },
|
|
28
|
+
variant: { type: String, reflect: true },
|
|
29
|
+
closeOnSelect: { type: Boolean, attribute: 'close-on-select', reflect: true },
|
|
30
|
+
ariaLabel: { type: String, attribute: 'aria-label' },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
idBase = `cv-menu-button-${++cvMenuButtonNonce}`;
|
|
34
|
+
itemRecords = [];
|
|
35
|
+
itemListeners = new WeakMap();
|
|
36
|
+
hasPrefixContent = false;
|
|
37
|
+
hasLabelContent = false;
|
|
38
|
+
hasSuffixContent = false;
|
|
39
|
+
model;
|
|
40
|
+
hasLayoutListeners = false;
|
|
41
|
+
layoutFrame = -1;
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
this.value = '';
|
|
45
|
+
this.open = false;
|
|
46
|
+
this.disabled = false;
|
|
47
|
+
this.split = false;
|
|
48
|
+
this.size = 'medium';
|
|
49
|
+
this.variant = 'default';
|
|
50
|
+
this.closeOnSelect = true;
|
|
51
|
+
this.ariaLabel = '';
|
|
52
|
+
}
|
|
53
|
+
static styles = [
|
|
54
|
+
css `
|
|
55
|
+
:host {
|
|
56
|
+
--cv-menu-button-min-height: 36px;
|
|
57
|
+
--cv-menu-button-padding-inline: var(--cv-space-3, 12px);
|
|
58
|
+
--cv-menu-button-padding-block: var(--cv-space-2, 8px);
|
|
59
|
+
--cv-menu-button-border-radius: var(--cv-radius-sm, 6px);
|
|
60
|
+
--cv-menu-button-gap: var(--cv-space-2, 8px);
|
|
61
|
+
--cv-menu-button-font-size: inherit;
|
|
62
|
+
--cv-menu-button-menu-offset: var(--cv-space-1, 4px);
|
|
63
|
+
--cv-menu-button-menu-min-inline-size: 180px;
|
|
64
|
+
--cv-menu-button-menu-z-index: 20;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
[part='base'] {
|
|
68
|
+
position: relative;
|
|
69
|
+
display: inline-flex;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* --- shared button styles --- */
|
|
73
|
+
[part='trigger'],
|
|
74
|
+
[part='action'],
|
|
75
|
+
[part='dropdown'] {
|
|
76
|
+
display: inline-flex;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
gap: var(--cv-menu-button-gap);
|
|
79
|
+
min-block-size: var(--cv-menu-button-min-height);
|
|
80
|
+
padding: var(--cv-menu-button-padding-block) var(--cv-menu-button-padding-inline);
|
|
81
|
+
font-size: var(--cv-menu-button-font-size);
|
|
82
|
+
color: var(--cv-color-text, #e8ecf6);
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
font: inherit;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[part='trigger']:focus-visible,
|
|
88
|
+
[part='action']:focus-visible,
|
|
89
|
+
[part='dropdown']:focus-visible {
|
|
90
|
+
outline: 2px solid var(--cv-color-primary, #65d7ff);
|
|
91
|
+
outline-offset: 1px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* --- label / prefix / suffix / dropdown-icon --- */
|
|
95
|
+
[part='dropdown-icon'] svg {
|
|
96
|
+
width: 12px;
|
|
97
|
+
height: 12px;
|
|
98
|
+
fill: currentColor;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* --- menu popup --- */
|
|
102
|
+
[part='menu'] {
|
|
103
|
+
position: absolute;
|
|
104
|
+
left: 0;
|
|
105
|
+
top: calc(100% + var(--cv-menu-button-menu-offset));
|
|
106
|
+
z-index: var(--cv-menu-button-menu-z-index);
|
|
107
|
+
box-sizing: border-box;
|
|
108
|
+
inline-size: fit-content;
|
|
109
|
+
min-inline-size: var(--cv-menu-button-menu-min-inline-size);
|
|
110
|
+
max-inline-size: var(--cv-menu-button-menu-max-inline-size, calc(100vw - 16px));
|
|
111
|
+
max-block-size: var(--cv-menu-button-menu-max-block-size, calc(100dvh - 16px));
|
|
112
|
+
display: inline-grid;
|
|
113
|
+
gap: var(--cv-space-1, 4px);
|
|
114
|
+
align-content: start;
|
|
115
|
+
padding: var(--cv-space-1, 4px);
|
|
116
|
+
background: var(--cv-color-surface-elevated, #1d2432);
|
|
117
|
+
overflow-y: auto;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
::slotted([slot='menu']) {
|
|
121
|
+
display: block;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* --- :host([open]) --- */
|
|
125
|
+
:host([open]) [part='trigger'],
|
|
126
|
+
:host([open]) [part='dropdown'] {
|
|
127
|
+
border-color: var(--cv-color-primary, #65d7ff);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* --- :host([disabled]) --- */
|
|
131
|
+
:host([disabled]) {
|
|
132
|
+
opacity: 0.55;
|
|
133
|
+
pointer-events: none;
|
|
134
|
+
cursor: not-allowed;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* --- :host([split]) --- */
|
|
138
|
+
:host([split]) [part='base'] {
|
|
139
|
+
display: inline-flex;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
:host([split]) [part='action'] {
|
|
143
|
+
border-start-end-radius: 0;
|
|
144
|
+
border-end-end-radius: 0;
|
|
145
|
+
border-inline-end: none;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
:host([split]) [part='dropdown'] {
|
|
149
|
+
border-start-start-radius: 0;
|
|
150
|
+
border-end-start-radius: 0;
|
|
151
|
+
padding-inline: var(--cv-space-2, 8px);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* --- sizes --- */
|
|
155
|
+
:host([size='small']) {
|
|
156
|
+
--cv-menu-button-min-height: 30px;
|
|
157
|
+
--cv-menu-button-padding-inline: var(--cv-space-2, 8px);
|
|
158
|
+
--cv-menu-button-padding-block: var(--cv-space-1, 4px);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
:host([size='large']) {
|
|
162
|
+
--cv-menu-button-min-height: 42px;
|
|
163
|
+
--cv-menu-button-padding-inline: var(--cv-space-4, 16px);
|
|
164
|
+
--cv-menu-button-padding-block: var(--cv-space-2, 8px);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* --- variant: default --- */
|
|
168
|
+
:host([variant='default']) [part='trigger'],
|
|
169
|
+
:host([variant='default']) [part='action'],
|
|
170
|
+
:host([variant='default']) [part='dropdown'] {
|
|
171
|
+
border-color: var(--cv-color-border, #2a3245);
|
|
172
|
+
background: var(--cv-color-surface, #141923);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* --- variant: primary --- */
|
|
176
|
+
:host([variant='primary']) [part='trigger'],
|
|
177
|
+
:host([variant='primary']) [part='action'],
|
|
178
|
+
:host([variant='primary']) [part='dropdown'] {
|
|
179
|
+
border-color: color-mix(
|
|
180
|
+
in oklab,
|
|
181
|
+
var(--cv-color-primary, #65d7ff) 52%,
|
|
182
|
+
var(--cv-color-border, #2a3245)
|
|
183
|
+
);
|
|
184
|
+
background: color-mix(
|
|
185
|
+
in oklab,
|
|
186
|
+
var(--cv-color-primary, #65d7ff) 22%,
|
|
187
|
+
var(--cv-color-surface, #141923)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* --- variant: danger --- */
|
|
192
|
+
:host([variant='danger']) [part='trigger'],
|
|
193
|
+
:host([variant='danger']) [part='action'],
|
|
194
|
+
:host([variant='danger']) [part='dropdown'] {
|
|
195
|
+
border-color: color-mix(
|
|
196
|
+
in oklab,
|
|
197
|
+
var(--cv-color-danger, #ff7d86) 52%,
|
|
198
|
+
var(--cv-color-border, #2a3245)
|
|
199
|
+
);
|
|
200
|
+
background: color-mix(
|
|
201
|
+
in oklab,
|
|
202
|
+
var(--cv-color-danger, #ff7d86) 22%,
|
|
203
|
+
var(--cv-color-surface, #141923)
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* --- variant: ghost --- */
|
|
208
|
+
:host([variant='ghost']) [part='trigger'],
|
|
209
|
+
:host([variant='ghost']) [part='action'],
|
|
210
|
+
:host([variant='ghost']) [part='dropdown'] {
|
|
211
|
+
background: transparent;
|
|
212
|
+
border-color: transparent;
|
|
213
|
+
}
|
|
214
|
+
`,
|
|
215
|
+
];
|
|
216
|
+
static define() {
|
|
217
|
+
if (!customElements.get(this.elementName)) {
|
|
218
|
+
customElements.define(this.elementName, this);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
connectedCallback() {
|
|
222
|
+
super.connectedCallback();
|
|
223
|
+
this.syncContentParts();
|
|
224
|
+
if (!this.model) {
|
|
225
|
+
this.rebuildModelFromSlot(false, false);
|
|
226
|
+
}
|
|
227
|
+
this.syncOutsidePointerListener();
|
|
228
|
+
}
|
|
229
|
+
disconnectedCallback() {
|
|
230
|
+
super.disconnectedCallback();
|
|
231
|
+
this.detachItemListeners();
|
|
232
|
+
this.syncOutsidePointerListener(true);
|
|
233
|
+
this.toggleLayoutListeners(false);
|
|
234
|
+
this.cancelLayoutFrame();
|
|
235
|
+
}
|
|
236
|
+
willUpdate(changedProperties) {
|
|
237
|
+
super.willUpdate(changedProperties);
|
|
238
|
+
if (changedProperties.has('closeOnSelect') ||
|
|
239
|
+
changedProperties.has('ariaLabel') ||
|
|
240
|
+
changedProperties.has('split')) {
|
|
241
|
+
this.rebuildModelFromSlot(true, false);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (!this.model)
|
|
245
|
+
return;
|
|
246
|
+
if (changedProperties.has('value')) {
|
|
247
|
+
const next = this.value.trim();
|
|
248
|
+
if (next.length > 0 && this.value !== next) {
|
|
249
|
+
this.value = next;
|
|
250
|
+
}
|
|
251
|
+
if (next.length > 0) {
|
|
252
|
+
const record = this.itemRecords.find((item) => item.id === next);
|
|
253
|
+
if (record && !record.disabled) {
|
|
254
|
+
const previous = this.captureState();
|
|
255
|
+
this.model.actions.select(next);
|
|
256
|
+
this.applyInteractionResult(previous, next);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (changedProperties.has('open') && this.model.state.isOpen() !== this.open) {
|
|
261
|
+
const previous = this.captureState();
|
|
262
|
+
if (this.open) {
|
|
263
|
+
this.model.actions.open();
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
this.model.actions.close();
|
|
267
|
+
}
|
|
268
|
+
this.applyInteractionResult(previous);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
updated(changedProperties) {
|
|
272
|
+
super.updated(changedProperties);
|
|
273
|
+
this.syncOutsidePointerListener();
|
|
274
|
+
const shouldTrackLayout = this.open;
|
|
275
|
+
this.toggleLayoutListeners(shouldTrackLayout);
|
|
276
|
+
if (this.open) {
|
|
277
|
+
const menu = this.getMenuElement();
|
|
278
|
+
if (menu) {
|
|
279
|
+
menu.style.visibility = 'hidden';
|
|
280
|
+
}
|
|
281
|
+
this.scheduleLayout();
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
this.cancelLayoutFrame();
|
|
285
|
+
const menu = this.getMenuElement();
|
|
286
|
+
if (menu) {
|
|
287
|
+
this.clearInlineLayout(menu);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (!changedProperties.has('value') && !changedProperties.has('open')) {
|
|
291
|
+
this.syncItemElements();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
getMenuElement() {
|
|
295
|
+
return this.shadowRoot?.querySelector('[part="menu"]');
|
|
296
|
+
}
|
|
297
|
+
getBaseElement() {
|
|
298
|
+
return this.shadowRoot?.querySelector('[part="base"]');
|
|
299
|
+
}
|
|
300
|
+
clearInlineLayout(menu) {
|
|
301
|
+
menu.style.position = '';
|
|
302
|
+
menu.style.top = '';
|
|
303
|
+
menu.style.left = '';
|
|
304
|
+
menu.style.bottom = '';
|
|
305
|
+
menu.style.right = '';
|
|
306
|
+
menu.style.transform = '';
|
|
307
|
+
menu.style.translate = '';
|
|
308
|
+
menu.style.minWidth = '';
|
|
309
|
+
menu.style.visibility = '';
|
|
310
|
+
}
|
|
311
|
+
getMenuOffset() {
|
|
312
|
+
const raw = getComputedStyle(this).getPropertyValue('--cv-menu-button-menu-offset').trim();
|
|
313
|
+
const parsed = Number.parseFloat(raw);
|
|
314
|
+
return Number.isFinite(parsed) ? parsed : 4;
|
|
315
|
+
}
|
|
316
|
+
getMenuMinInlineSize() {
|
|
317
|
+
const raw = getComputedStyle(this).getPropertyValue('--cv-menu-button-menu-min-inline-size').trim();
|
|
318
|
+
const parsed = Number.parseFloat(raw);
|
|
319
|
+
return Number.isFinite(parsed) ? parsed : 180;
|
|
320
|
+
}
|
|
321
|
+
applyMenuLayout(menu, base) {
|
|
322
|
+
const baseRect = base.getBoundingClientRect();
|
|
323
|
+
const minWidth = Math.max(this.getMenuMinInlineSize(), Math.ceil(baseRect.width));
|
|
324
|
+
menu.style.position = 'absolute';
|
|
325
|
+
menu.style.minWidth = `${minWidth}px`;
|
|
326
|
+
menu.style.top = '0px';
|
|
327
|
+
menu.style.left = '0px';
|
|
328
|
+
menu.style.bottom = 'auto';
|
|
329
|
+
menu.style.right = 'auto';
|
|
330
|
+
menu.style.transform = 'none';
|
|
331
|
+
menu.style.translate = 'none';
|
|
332
|
+
menu.style.visibility = 'hidden';
|
|
333
|
+
const menuRect = menu.getBoundingClientRect();
|
|
334
|
+
const viewportWidth = window.innerWidth;
|
|
335
|
+
const viewportHeight = window.innerHeight;
|
|
336
|
+
const gap = this.getMenuOffset();
|
|
337
|
+
const viewportPadding = 8;
|
|
338
|
+
const spaceAbove = Math.max(0, baseRect.top - viewportPadding - gap);
|
|
339
|
+
const spaceBelow = Math.max(0, viewportHeight - baseRect.bottom - viewportPadding - gap);
|
|
340
|
+
const placeAbove = spaceBelow < menuRect.height + gap && spaceAbove > spaceBelow;
|
|
341
|
+
let top = placeAbove ? baseRect.top - menuRect.height - gap : baseRect.bottom + gap;
|
|
342
|
+
let left = baseRect.left;
|
|
343
|
+
const maxLeft = Math.max(viewportPadding, viewportWidth - menuRect.width - viewportPadding);
|
|
344
|
+
const maxTop = Math.max(viewportPadding, viewportHeight - menuRect.height - viewportPadding);
|
|
345
|
+
left = Math.min(Math.max(left, viewportPadding), maxLeft);
|
|
346
|
+
top = Math.min(Math.max(top, viewportPadding), maxTop);
|
|
347
|
+
menu.style.position = 'absolute';
|
|
348
|
+
menu.style.top = `${top - baseRect.top}px`;
|
|
349
|
+
menu.style.left = `${left - baseRect.left}px`;
|
|
350
|
+
menu.style.bottom = 'auto';
|
|
351
|
+
menu.style.right = 'auto';
|
|
352
|
+
menu.style.transform = 'none';
|
|
353
|
+
menu.style.translate = 'none';
|
|
354
|
+
menu.style.visibility = 'visible';
|
|
355
|
+
}
|
|
356
|
+
syncMenuLayout() {
|
|
357
|
+
const menu = this.getMenuElement();
|
|
358
|
+
const base = this.getBaseElement();
|
|
359
|
+
if (!menu || !base)
|
|
360
|
+
return;
|
|
361
|
+
this.applyMenuLayout(menu, base);
|
|
362
|
+
}
|
|
363
|
+
cancelLayoutFrame() {
|
|
364
|
+
if (this.layoutFrame === -1)
|
|
365
|
+
return;
|
|
366
|
+
cancelAnimationFrame(this.layoutFrame);
|
|
367
|
+
this.layoutFrame = -1;
|
|
368
|
+
}
|
|
369
|
+
scheduleLayout() {
|
|
370
|
+
this.cancelLayoutFrame();
|
|
371
|
+
this.layoutFrame = requestAnimationFrame(() => {
|
|
372
|
+
this.layoutFrame = -1;
|
|
373
|
+
this.syncMenuLayout();
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
toggleLayoutListeners(nextState) {
|
|
377
|
+
if (this.hasLayoutListeners === nextState)
|
|
378
|
+
return;
|
|
379
|
+
this.hasLayoutListeners = nextState;
|
|
380
|
+
if (nextState) {
|
|
381
|
+
window.addEventListener('resize', this.handleViewportChange);
|
|
382
|
+
window.addEventListener('scroll', this.handleViewportChange, true);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
window.removeEventListener('resize', this.handleViewportChange);
|
|
386
|
+
window.removeEventListener('scroll', this.handleViewportChange, true);
|
|
387
|
+
}
|
|
388
|
+
handleViewportChange = () => {
|
|
389
|
+
if (!this.open)
|
|
390
|
+
return;
|
|
391
|
+
this.scheduleLayout();
|
|
392
|
+
};
|
|
393
|
+
getItemElements() {
|
|
394
|
+
return Array.from(this.querySelectorAll(':scope > [slot="menu"]')).filter((element) => element.tagName.toLowerCase() === CVMenuItem.elementName);
|
|
395
|
+
}
|
|
396
|
+
syncContentParts() {
|
|
397
|
+
const nextPrefixContent = this.hasNamedSlotContent('prefix');
|
|
398
|
+
const nextLabelContent = this.hasDefaultSlotContent();
|
|
399
|
+
const nextSuffixContent = this.hasNamedSlotContent('suffix');
|
|
400
|
+
const changed = this.hasPrefixContent !== nextPrefixContent ||
|
|
401
|
+
this.hasLabelContent !== nextLabelContent ||
|
|
402
|
+
this.hasSuffixContent !== nextSuffixContent;
|
|
403
|
+
this.hasPrefixContent = nextPrefixContent;
|
|
404
|
+
this.hasLabelContent = nextLabelContent;
|
|
405
|
+
this.hasSuffixContent = nextSuffixContent;
|
|
406
|
+
return changed;
|
|
407
|
+
}
|
|
408
|
+
hasNamedSlotContent(slotName) {
|
|
409
|
+
return Array.from(this.children).some((node) => node.getAttribute('slot') === slotName);
|
|
410
|
+
}
|
|
411
|
+
hasDefaultSlotContent() {
|
|
412
|
+
for (const node of this.childNodes) {
|
|
413
|
+
if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const element = node;
|
|
420
|
+
const slotName = element.getAttribute('slot');
|
|
421
|
+
if (!slotName) {
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
ensureItemValue(item, index) {
|
|
428
|
+
const normalized = item.value?.trim();
|
|
429
|
+
if (normalized)
|
|
430
|
+
return normalized;
|
|
431
|
+
const fallback = `item-${index + 1}`;
|
|
432
|
+
item.value = fallback;
|
|
433
|
+
return fallback;
|
|
434
|
+
}
|
|
435
|
+
rebuildModelFromSlot(preserveState, requestRender = true) {
|
|
436
|
+
const itemElements = this.getItemElements();
|
|
437
|
+
const previous = preserveState
|
|
438
|
+
? this.captureState()
|
|
439
|
+
: { activeId: null, open: this.open, value: this.value || null };
|
|
440
|
+
this.detachItemListeners();
|
|
441
|
+
this.itemRecords = itemElements.map((element, index) => {
|
|
442
|
+
const id = this.ensureItemValue(element, index);
|
|
443
|
+
const label = element.textContent?.trim() || id;
|
|
444
|
+
return {
|
|
445
|
+
id,
|
|
446
|
+
label,
|
|
447
|
+
disabled: element.disabled,
|
|
448
|
+
element,
|
|
449
|
+
};
|
|
450
|
+
});
|
|
451
|
+
const enabledIds = new Set(this.itemRecords.filter((record) => !record.disabled).map((record) => record.id));
|
|
452
|
+
const initialActiveId = previous.activeId && enabledIds.has(previous.activeId) ? previous.activeId : null;
|
|
453
|
+
this.model = createMenuButton({
|
|
454
|
+
idBase: this.idBase,
|
|
455
|
+
items: this.itemRecords.map((record) => ({
|
|
456
|
+
id: record.id,
|
|
457
|
+
label: record.label,
|
|
458
|
+
disabled: record.disabled,
|
|
459
|
+
})),
|
|
460
|
+
ariaLabel: this.ariaLabel || undefined,
|
|
461
|
+
initialOpen: previous.open,
|
|
462
|
+
initialActiveId,
|
|
463
|
+
closeOnSelect: this.closeOnSelect,
|
|
464
|
+
});
|
|
465
|
+
this.value = previous.value ?? '';
|
|
466
|
+
this.open = this.model.state.isOpen();
|
|
467
|
+
this.prefetchMenuIcons();
|
|
468
|
+
this.attachItemListeners();
|
|
469
|
+
this.syncItemElements();
|
|
470
|
+
if (requestRender) {
|
|
471
|
+
this.requestUpdate();
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
prefetchMenuIcons() {
|
|
475
|
+
const names = [];
|
|
476
|
+
for (const record of this.itemRecords) {
|
|
477
|
+
const icons = record.element.querySelectorAll(CVIcon.elementName);
|
|
478
|
+
for (const icon of icons) {
|
|
479
|
+
const name = icon.getAttribute('name');
|
|
480
|
+
if (name)
|
|
481
|
+
names.push(name);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (names.length > 0) {
|
|
485
|
+
CVIcon.prefetch(names);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
detachItemListeners() {
|
|
489
|
+
for (const record of this.itemRecords) {
|
|
490
|
+
const listeners = this.itemListeners.get(record.element);
|
|
491
|
+
if (!listeners)
|
|
492
|
+
continue;
|
|
493
|
+
record.element.removeEventListener('click', listeners.click);
|
|
494
|
+
record.element.removeEventListener('keydown', listeners.keydown);
|
|
495
|
+
this.itemListeners.delete(record.element);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
attachItemListeners() {
|
|
499
|
+
if (!this.model)
|
|
500
|
+
return;
|
|
501
|
+
for (const record of this.itemRecords) {
|
|
502
|
+
const click = (event) => {
|
|
503
|
+
event.preventDefault();
|
|
504
|
+
this.handleItemClick(record.id);
|
|
505
|
+
};
|
|
506
|
+
const keydown = (event) => {
|
|
507
|
+
event.stopPropagation();
|
|
508
|
+
this.handleKeyDown(event);
|
|
509
|
+
};
|
|
510
|
+
record.element.addEventListener('click', click);
|
|
511
|
+
record.element.addEventListener('keydown', keydown);
|
|
512
|
+
this.itemListeners.set(record.element, { click, keydown });
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
syncItemElements() {
|
|
516
|
+
if (!this.model)
|
|
517
|
+
return;
|
|
518
|
+
for (const record of this.itemRecords) {
|
|
519
|
+
const props = this.model.contracts.getItemProps(record.id);
|
|
520
|
+
record.element.id = props.id;
|
|
521
|
+
record.element.setAttribute('role', props.role);
|
|
522
|
+
record.element.setAttribute('tabindex', props.tabindex);
|
|
523
|
+
if (props['aria-disabled']) {
|
|
524
|
+
record.element.setAttribute('aria-disabled', props['aria-disabled']);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
record.element.removeAttribute('aria-disabled');
|
|
528
|
+
}
|
|
529
|
+
record.element.setAttribute('data-active', props['data-active']);
|
|
530
|
+
record.element.active = props['data-active'] === 'true';
|
|
531
|
+
record.element.selected = this.value === record.id;
|
|
532
|
+
record.element.disabled = props['aria-disabled'] === 'true';
|
|
533
|
+
record.element.hidden = !this.open;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
captureState() {
|
|
537
|
+
return {
|
|
538
|
+
value: this.value.trim() || null,
|
|
539
|
+
activeId: this.model?.state.activeId() ?? null,
|
|
540
|
+
open: this.model?.state.isOpen() ?? this.open,
|
|
541
|
+
restoreTargetId: this.model?.state.restoreTargetId() ?? null,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
dispatchInput(detail) {
|
|
545
|
+
this.dispatchEvent(new CustomEvent('cv-input', {
|
|
546
|
+
detail,
|
|
547
|
+
bubbles: true,
|
|
548
|
+
composed: true,
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
551
|
+
dispatchChange(detail) {
|
|
552
|
+
this.dispatchEvent(new CustomEvent('cv-change', {
|
|
553
|
+
detail,
|
|
554
|
+
bubbles: true,
|
|
555
|
+
composed: true,
|
|
556
|
+
}));
|
|
557
|
+
}
|
|
558
|
+
dispatchAction() {
|
|
559
|
+
this.dispatchEvent(new CustomEvent('cv-action', {
|
|
560
|
+
detail: {},
|
|
561
|
+
bubbles: true,
|
|
562
|
+
composed: true,
|
|
563
|
+
}));
|
|
564
|
+
}
|
|
565
|
+
focusActiveItem() {
|
|
566
|
+
if (!this.model || !this.open)
|
|
567
|
+
return;
|
|
568
|
+
const activeId = this.model.state.activeId();
|
|
569
|
+
if (!activeId)
|
|
570
|
+
return;
|
|
571
|
+
const activeRecord = this.itemRecords.find((record) => record.id === activeId);
|
|
572
|
+
activeRecord?.element.focus();
|
|
573
|
+
}
|
|
574
|
+
applyInteractionResult(previous, nextSelectedValue) {
|
|
575
|
+
if (!this.model)
|
|
576
|
+
return;
|
|
577
|
+
const next = this.captureState();
|
|
578
|
+
const value = nextSelectedValue === undefined ? previous.value : nextSelectedValue;
|
|
579
|
+
this.value = value ?? '';
|
|
580
|
+
this.open = next.open;
|
|
581
|
+
this.syncItemElements();
|
|
582
|
+
const valueChanged = previous.value !== value;
|
|
583
|
+
const activeChanged = previous.activeId !== next.activeId;
|
|
584
|
+
const openChanged = previous.open !== next.open;
|
|
585
|
+
if (valueChanged || activeChanged || openChanged) {
|
|
586
|
+
const detail = {
|
|
587
|
+
value,
|
|
588
|
+
activeId: next.activeId,
|
|
589
|
+
open: next.open,
|
|
590
|
+
};
|
|
591
|
+
this.dispatchInput(detail);
|
|
592
|
+
if (valueChanged) {
|
|
593
|
+
this.dispatchChange(detail);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (activeChanged) {
|
|
597
|
+
this.focusActiveItem();
|
|
598
|
+
}
|
|
599
|
+
if (next.restoreTargetId) {
|
|
600
|
+
const trigger = this.shadowRoot?.querySelector(`[id="${next.restoreTargetId}"]`);
|
|
601
|
+
trigger?.focus();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
syncOutsidePointerListener(forceOff = false) {
|
|
605
|
+
const shouldListen = !forceOff && this.open;
|
|
606
|
+
if (shouldListen) {
|
|
607
|
+
document.addEventListener('pointerdown', this.handleDocumentPointerDown);
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
document.removeEventListener('pointerdown', this.handleDocumentPointerDown);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
handleDocumentPointerDown = (event) => {
|
|
614
|
+
if (!this.model || !this.model.state.isOpen())
|
|
615
|
+
return;
|
|
616
|
+
const path = event.composedPath();
|
|
617
|
+
if (path.includes(this))
|
|
618
|
+
return;
|
|
619
|
+
const previous = this.captureState();
|
|
620
|
+
this.model.actions.handleOutsidePointer();
|
|
621
|
+
this.applyInteractionResult(previous);
|
|
622
|
+
};
|
|
623
|
+
handleItemClick(id) {
|
|
624
|
+
if (!this.model)
|
|
625
|
+
return;
|
|
626
|
+
const record = this.itemRecords.find((item) => item.id === id);
|
|
627
|
+
if (!record || record.disabled)
|
|
628
|
+
return;
|
|
629
|
+
const previous = this.captureState();
|
|
630
|
+
this.model.actions.select(id);
|
|
631
|
+
this.applyInteractionResult(previous, id);
|
|
632
|
+
}
|
|
633
|
+
handleTriggerClick() {
|
|
634
|
+
if (this.disabled || !this.model)
|
|
635
|
+
return;
|
|
636
|
+
const previous = this.captureState();
|
|
637
|
+
this.model.contracts.getTriggerProps().onClick();
|
|
638
|
+
this.applyInteractionResult(previous);
|
|
639
|
+
}
|
|
640
|
+
handleActionClick() {
|
|
641
|
+
if (this.disabled)
|
|
642
|
+
return;
|
|
643
|
+
this.dispatchAction();
|
|
644
|
+
}
|
|
645
|
+
handleDropdownClick() {
|
|
646
|
+
if (this.disabled || !this.model)
|
|
647
|
+
return;
|
|
648
|
+
const previous = this.captureState();
|
|
649
|
+
this.model.contracts.getTriggerProps().onClick();
|
|
650
|
+
this.applyInteractionResult(previous);
|
|
651
|
+
}
|
|
652
|
+
handleKeyDown(event) {
|
|
653
|
+
if (!this.model)
|
|
654
|
+
return;
|
|
655
|
+
if (menuButtonKeysToPrevent.has(event.key)) {
|
|
656
|
+
event.preventDefault();
|
|
657
|
+
}
|
|
658
|
+
const previous = this.captureState();
|
|
659
|
+
const selectedCandidate = this.model.state.isOpen() && (event.key === 'Enter' || event.key === ' ' || event.key === 'Spacebar')
|
|
660
|
+
? this.model.state.activeId()
|
|
661
|
+
: previous.value;
|
|
662
|
+
this.model.actions.handleKeyDown({
|
|
663
|
+
key: event.key,
|
|
664
|
+
shiftKey: event.shiftKey,
|
|
665
|
+
ctrlKey: event.ctrlKey,
|
|
666
|
+
metaKey: event.metaKey,
|
|
667
|
+
altKey: event.altKey,
|
|
668
|
+
});
|
|
669
|
+
this.applyInteractionResult(previous, selectedCandidate);
|
|
670
|
+
}
|
|
671
|
+
handleMenuSlotChange() {
|
|
672
|
+
this.rebuildModelFromSlot(true, true);
|
|
673
|
+
}
|
|
674
|
+
handleContentSlotChange() {
|
|
675
|
+
if (this.syncContentParts()) {
|
|
676
|
+
this.requestUpdate();
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
renderDropdownIcon() {
|
|
680
|
+
return html `
|
|
681
|
+
<span part="dropdown-icon" class="cv-u-icon-slot" aria-hidden="true"
|
|
682
|
+
><svg viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
683
|
+
<path
|
|
684
|
+
d="M2.5 4.5L6 8L9.5 4.5"
|
|
685
|
+
stroke="currentColor"
|
|
686
|
+
stroke-width="1.5"
|
|
687
|
+
stroke-linecap="round"
|
|
688
|
+
stroke-linejoin="round"
|
|
689
|
+
fill="none"
|
|
690
|
+
/></svg
|
|
691
|
+
></span>
|
|
692
|
+
`;
|
|
693
|
+
}
|
|
694
|
+
renderSplitMode() {
|
|
695
|
+
const triggerProps = this.model?.contracts.getTriggerProps();
|
|
696
|
+
const menuProps = this.model?.contracts.getMenuProps() ?? {
|
|
697
|
+
id: `${this.idBase}-menu`,
|
|
698
|
+
role: 'menu',
|
|
699
|
+
tabindex: '-1',
|
|
700
|
+
'aria-label': this.ariaLabel || undefined,
|
|
701
|
+
hidden: !this.open,
|
|
702
|
+
};
|
|
703
|
+
return html `
|
|
704
|
+
<div part="base">
|
|
705
|
+
<button
|
|
706
|
+
type="button"
|
|
707
|
+
part="action"
|
|
708
|
+
class="cv-u-control-shell"
|
|
709
|
+
?disabled=${this.disabled}
|
|
710
|
+
@click=${this.handleActionClick}
|
|
711
|
+
>
|
|
712
|
+
<span part="prefix" class="cv-u-icon-slot" ?hidden=${!this.hasPrefixContent}
|
|
713
|
+
><slot name="prefix" @slotchange=${this.handleContentSlotChange}></slot
|
|
714
|
+
></span>
|
|
715
|
+
<span part="label" class="cv-u-row" ?hidden=${!this.hasLabelContent}
|
|
716
|
+
><slot @slotchange=${this.handleContentSlotChange}></slot
|
|
717
|
+
></span>
|
|
718
|
+
<span part="suffix" class="cv-u-icon-slot" ?hidden=${!this.hasSuffixContent}
|
|
719
|
+
><slot name="suffix" @slotchange=${this.handleContentSlotChange}></slot
|
|
720
|
+
></span>
|
|
721
|
+
</button>
|
|
722
|
+
|
|
723
|
+
<button
|
|
724
|
+
id=${triggerProps?.id ?? `${this.idBase}-trigger`}
|
|
725
|
+
type="button"
|
|
726
|
+
part="dropdown"
|
|
727
|
+
tabindex=${triggerProps?.tabindex ?? '0'}
|
|
728
|
+
aria-haspopup=${triggerProps?.['aria-haspopup'] ?? 'menu'}
|
|
729
|
+
aria-expanded=${triggerProps?.['aria-expanded'] ?? (this.open ? 'true' : 'false')}
|
|
730
|
+
aria-controls=${triggerProps?.['aria-controls'] ?? `${this.idBase}-menu`}
|
|
731
|
+
aria-label=${triggerProps?.['aria-label'] ?? 'More options'}
|
|
732
|
+
?disabled=${this.disabled}
|
|
733
|
+
@click=${this.handleDropdownClick}
|
|
734
|
+
@keydown=${this.handleKeyDown}
|
|
735
|
+
class="cv-u-control-shell"
|
|
736
|
+
>
|
|
737
|
+
${this.renderDropdownIcon()}
|
|
738
|
+
</button>
|
|
739
|
+
|
|
740
|
+
<div
|
|
741
|
+
id=${menuProps.id}
|
|
742
|
+
role=${menuProps.role}
|
|
743
|
+
tabindex=${menuProps.tabindex}
|
|
744
|
+
aria-label=${menuProps['aria-label'] ?? nothing}
|
|
745
|
+
?hidden=${menuProps.hidden}
|
|
746
|
+
part="menu"
|
|
747
|
+
class="cv-u-panel-shell"
|
|
748
|
+
@keydown=${this.handleKeyDown}
|
|
749
|
+
>
|
|
750
|
+
<slot name="menu" @slotchange=${this.handleMenuSlotChange}></slot>
|
|
751
|
+
</div>
|
|
752
|
+
</div>
|
|
753
|
+
`;
|
|
754
|
+
}
|
|
755
|
+
renderStandardMode() {
|
|
756
|
+
const triggerProps = this.model?.contracts.getTriggerProps() ?? {
|
|
757
|
+
id: `${this.idBase}-trigger`,
|
|
758
|
+
role: 'button',
|
|
759
|
+
tabindex: '0',
|
|
760
|
+
'aria-haspopup': 'menu',
|
|
761
|
+
'aria-expanded': this.open ? 'true' : 'false',
|
|
762
|
+
'aria-controls': `${this.idBase}-menu`,
|
|
763
|
+
'aria-label': this.ariaLabel || undefined,
|
|
764
|
+
};
|
|
765
|
+
const menuProps = this.model?.contracts.getMenuProps() ?? {
|
|
766
|
+
id: `${this.idBase}-menu`,
|
|
767
|
+
role: 'menu',
|
|
768
|
+
tabindex: '-1',
|
|
769
|
+
'aria-label': this.ariaLabel || undefined,
|
|
770
|
+
hidden: !this.open,
|
|
771
|
+
};
|
|
772
|
+
return html `
|
|
773
|
+
<div part="base">
|
|
774
|
+
<button
|
|
775
|
+
id=${triggerProps.id}
|
|
776
|
+
role=${triggerProps.role}
|
|
777
|
+
tabindex=${triggerProps.tabindex}
|
|
778
|
+
aria-haspopup=${triggerProps['aria-haspopup']}
|
|
779
|
+
aria-expanded=${triggerProps['aria-expanded']}
|
|
780
|
+
aria-controls=${triggerProps['aria-controls']}
|
|
781
|
+
aria-label=${triggerProps['aria-label'] ?? nothing}
|
|
782
|
+
type="button"
|
|
783
|
+
part="trigger"
|
|
784
|
+
class="cv-u-control-shell"
|
|
785
|
+
?disabled=${this.disabled}
|
|
786
|
+
@click=${this.handleTriggerClick}
|
|
787
|
+
@keydown=${this.handleKeyDown}
|
|
788
|
+
>
|
|
789
|
+
<span part="prefix" class="cv-u-icon-slot" ?hidden=${!this.hasPrefixContent}
|
|
790
|
+
><slot name="prefix" @slotchange=${this.handleContentSlotChange}></slot
|
|
791
|
+
></span>
|
|
792
|
+
<span part="label" class="cv-u-row" ?hidden=${!this.hasLabelContent}
|
|
793
|
+
><slot @slotchange=${this.handleContentSlotChange}></slot
|
|
794
|
+
></span>
|
|
795
|
+
<span part="suffix" class="cv-u-icon-slot" ?hidden=${!this.hasSuffixContent}
|
|
796
|
+
><slot name="suffix" @slotchange=${this.handleContentSlotChange}></slot
|
|
797
|
+
></span>
|
|
798
|
+
${this.renderDropdownIcon()}
|
|
799
|
+
</button>
|
|
800
|
+
|
|
801
|
+
<div
|
|
802
|
+
id=${menuProps.id}
|
|
803
|
+
role=${menuProps.role}
|
|
804
|
+
tabindex=${menuProps.tabindex}
|
|
805
|
+
aria-label=${menuProps['aria-label'] ?? nothing}
|
|
806
|
+
?hidden=${menuProps.hidden}
|
|
807
|
+
part="menu"
|
|
808
|
+
class="cv-u-panel-shell"
|
|
809
|
+
@keydown=${this.handleKeyDown}
|
|
810
|
+
>
|
|
811
|
+
<slot name="menu" @slotchange=${this.handleMenuSlotChange}></slot>
|
|
812
|
+
</div>
|
|
813
|
+
</div>
|
|
814
|
+
`;
|
|
815
|
+
}
|
|
816
|
+
render() {
|
|
817
|
+
if (this.split) {
|
|
818
|
+
return this.renderSplitMode();
|
|
819
|
+
}
|
|
820
|
+
return this.renderStandardMode();
|
|
821
|
+
}
|
|
822
|
+
}
|