@wcomp/elementum 0.0.0-stage → 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 +21 -0
- package/README.md +266 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +408 -0
- package/package.json +72 -4
- package/skills/elementum-break-ui/CATALOG.md +11 -0
- package/skills/elementum-break-ui/SKILL.md +16 -0
- package/skills/elementum-mobile/SKILL.md +18 -0
- package/skills/elementum-motion/SKILL.md +18 -0
- package/skills/elementum-motion/STANDARDS.md +15 -0
- package/skills/elementum-penpot/SKILL.md +45 -0
- package/skills/elementum-ui/CATALOG.md +14 -0
- package/skills/elementum-ui/SKILL.md +21 -0
- package/src/ag-ui.js +474 -0
- package/src/components/el-accordion.js +201 -0
- package/src/components/el-alert-dialog.js +186 -0
- package/src/components/el-alert.js +254 -0
- package/src/components/el-aspect-ratio.js +73 -0
- package/src/components/el-autocomplete.js +775 -0
- package/src/components/el-avatar.js +271 -0
- package/src/components/el-badge.js +131 -0
- package/src/components/el-border-beam.js +135 -0
- package/src/components/el-breadcrumb.js +203 -0
- package/src/components/el-button.js +220 -0
- package/src/components/el-calendar.js +413 -0
- package/src/components/el-callout.js +158 -0
- package/src/components/el-card.js +298 -0
- package/src/components/el-carousel.js +308 -0
- package/src/components/el-chart.js +632 -0
- package/src/components/el-checkbox-card.js +221 -0
- package/src/components/el-checkbox.js +208 -0
- package/src/components/el-chip.js +276 -0
- package/src/components/el-code-block.js +228 -0
- package/src/components/el-collapsible.js +124 -0
- package/src/components/el-command.js +556 -0
- package/src/components/el-context-menu.js +328 -0
- package/src/components/el-data-list.js +210 -0
- package/src/components/el-datepicker.js +192 -0
- package/src/components/el-dialog.js +272 -0
- package/src/components/el-diff-viewer.js +441 -0
- package/src/components/el-drawer.js +782 -0
- package/src/components/el-dropdown.js +182 -0
- package/src/components/el-dropzone.js +242 -0
- package/src/components/el-empty-state.js +130 -0
- package/src/components/el-field.js +394 -0
- package/src/components/el-form.js +185 -0
- package/src/components/el-input.js +212 -0
- package/src/components/el-inset.js +90 -0
- package/src/components/el-insight-card.js +263 -0
- package/src/components/el-kbd.js +151 -0
- package/src/components/el-menubar.js +254 -0
- package/src/components/el-meter.js +182 -0
- package/src/components/el-navbar.js +294 -0
- package/src/components/el-navigation-menu.js +327 -0
- package/src/components/el-number-field.js +510 -0
- package/src/components/el-number-flow.js +153 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +229 -0
- package/src/components/el-popover.js +288 -0
- package/src/components/el-preview-card.js +202 -0
- package/src/components/el-progress.js +179 -0
- package/src/components/el-prompt-input.js +383 -0
- package/src/components/el-radio-card.js +360 -0
- package/src/components/el-radio.js +257 -0
- package/src/components/el-rating.js +165 -0
- package/src/components/el-reasoning-card.js +293 -0
- package/src/components/el-resizable.js +324 -0
- package/src/components/el-router.js +305 -0
- package/src/components/el-scroll-area.js +150 -0
- package/src/components/el-segmented-control.js +282 -0
- package/src/components/el-select.js +219 -0
- package/src/components/el-separator.js +85 -0
- package/src/components/el-sidebar.js +386 -0
- package/src/components/el-skeleton.js +156 -0
- package/src/components/el-slider.js +351 -0
- package/src/components/el-sources.js +288 -0
- package/src/components/el-spinner.js +159 -0
- package/src/components/el-streaming-text.js +199 -0
- package/src/components/el-switch.js +221 -0
- package/src/components/el-table.js +397 -0
- package/src/components/el-tabs.js +235 -0
- package/src/components/el-task-list.js +230 -0
- package/src/components/el-textarea.js +175 -0
- package/src/components/el-theme-switch.js +120 -0
- package/src/components/el-timeline.js +254 -0
- package/src/components/el-toast.js +778 -0
- package/src/components/el-toggle.js +311 -0
- package/src/components/el-tool-call.js +386 -0
- package/src/components/el-toolbar.js +183 -0
- package/src/components/el-tooltip.js +172 -0
- package/src/components/el-tree-view.js +261 -0
- package/src/components/el-visually-hidden.js +32 -0
- package/src/elementum.js +485 -0
- package/src/index.d.ts +1007 -0
- package/src/index.js +99 -0
- package/src/signal.js +194 -0
- package/src/ssr.js +136 -0
- package/src/template.js +321 -0
- package/src/tokens.css +416 -0
- package/tokens/figma-tokens.json +69 -0
- package/tokens/penpot-tokens.json +98 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-navbar>
|
|
3
|
+
* Responsive sticky top navigation bar with brand, badge, leading/trailing action slots,
|
|
4
|
+
* and automatic mobile drawer collapse for slotted navigation links.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Elementum } from '../elementum.js';
|
|
8
|
+
import { html, css } from '../template.js';
|
|
9
|
+
import { signal } from '../signal.js';
|
|
10
|
+
import './el-badge.js';
|
|
11
|
+
|
|
12
|
+
export class ElNavbar extends Elementum {
|
|
13
|
+
static observedAttributes = ['brand', 'href', 'badge', 'badge-variant', 'sticky', 'open'];
|
|
14
|
+
|
|
15
|
+
brand = signal('');
|
|
16
|
+
href = signal('#');
|
|
17
|
+
badge = signal('');
|
|
18
|
+
// 'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'outline'
|
|
19
|
+
badgeVariant = signal('primary');
|
|
20
|
+
sticky = signal(false);
|
|
21
|
+
open = signal(false);
|
|
22
|
+
|
|
23
|
+
static styles = css`
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
width: 100%;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
position: relative;
|
|
29
|
+
z-index: 1000;
|
|
30
|
+
font-family: var(--el-font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:host([sticky]) {
|
|
34
|
+
position: sticky;
|
|
35
|
+
top: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.navbar-inner {
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: space-between;
|
|
42
|
+
gap: 12px;
|
|
43
|
+
padding: 10px 16px;
|
|
44
|
+
width: 100%;
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
position: relative;
|
|
47
|
+
background: var(--el-surface-card, #ffffff);
|
|
48
|
+
background: color-mix(in srgb, var(--el-surface-card, #ffffff) 92%, transparent);
|
|
49
|
+
backdrop-filter: blur(14px);
|
|
50
|
+
-webkit-backdrop-filter: blur(14px);
|
|
51
|
+
border-bottom: 1px solid var(--el-surface-border, #e2e8f0);
|
|
52
|
+
color: var(--el-text-primary, #0f172a);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.left-group {
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
gap: 10px;
|
|
59
|
+
min-width: 0;
|
|
60
|
+
flex: 1 1 auto;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.brand-link {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
gap: 8px;
|
|
67
|
+
min-width: 0;
|
|
68
|
+
max-width: 100%;
|
|
69
|
+
font-weight: 800;
|
|
70
|
+
font-size: 1.05rem;
|
|
71
|
+
text-decoration: none;
|
|
72
|
+
color: inherit;
|
|
73
|
+
letter-spacing: -0.02em;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.brand-text {
|
|
77
|
+
white-space: nowrap;
|
|
78
|
+
overflow: hidden;
|
|
79
|
+
text-overflow: ellipsis;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.nav-links {
|
|
83
|
+
display: none;
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: 100%;
|
|
86
|
+
left: 0;
|
|
87
|
+
right: 0;
|
|
88
|
+
flex-direction: column;
|
|
89
|
+
align-items: stretch;
|
|
90
|
+
gap: 6px;
|
|
91
|
+
padding: 14px 16px;
|
|
92
|
+
background: var(--el-surface-card, #ffffff);
|
|
93
|
+
border-bottom: 1px solid var(--el-surface-border, #e2e8f0);
|
|
94
|
+
box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.14);
|
|
95
|
+
z-index: 1001;
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.nav-links.open,
|
|
100
|
+
:host([open]) .nav-links {
|
|
101
|
+
display: flex;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
::slotted(a),
|
|
105
|
+
::slotted(el-route-link) {
|
|
106
|
+
display: inline-flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
font-size: 0.9rem;
|
|
109
|
+
font-weight: 500;
|
|
110
|
+
color: var(--el-text-secondary, #475569);
|
|
111
|
+
text-decoration: none;
|
|
112
|
+
padding: 8px 12px;
|
|
113
|
+
border-radius: var(--el-radius-md, 6px);
|
|
114
|
+
transition: background-color 0.15s ease, color 0.15s ease;
|
|
115
|
+
white-space: nowrap;
|
|
116
|
+
box-sizing: border-box;
|
|
117
|
+
width: 100%;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
::slotted(a:hover),
|
|
121
|
+
::slotted(a.active),
|
|
122
|
+
::slotted(a[active]),
|
|
123
|
+
::slotted(el-route-link:hover),
|
|
124
|
+
::slotted(el-route-link[active]) {
|
|
125
|
+
color: var(--el-color-primary, #2563eb);
|
|
126
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
127
|
+
font-weight: 600;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.right-group {
|
|
131
|
+
display: flex;
|
|
132
|
+
align-items: center;
|
|
133
|
+
gap: 8px;
|
|
134
|
+
flex-shrink: 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.mobile-menu-btn {
|
|
138
|
+
display: inline-flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
width: 36px;
|
|
142
|
+
height: 36px;
|
|
143
|
+
padding: 0;
|
|
144
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
145
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
146
|
+
border-radius: var(--el-radius-md, 8px);
|
|
147
|
+
color: var(--el-text-primary, #0f172a);
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
transition: background-color 0.15s ease, border-color 0.15s ease;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.mobile-menu-btn:hover {
|
|
153
|
+
background: var(--el-step-4, #e2e8f0);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.mobile-menu-btn:focus-visible {
|
|
157
|
+
outline: 2px solid var(--el-color-primary, #2563eb);
|
|
158
|
+
outline-offset: 2px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@media (min-width: 860px) {
|
|
162
|
+
.navbar-inner {
|
|
163
|
+
padding: 10px 28px;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.left-group {
|
|
167
|
+
flex: 0 0 auto;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.nav-links,
|
|
171
|
+
:host([open]) .nav-links {
|
|
172
|
+
display: flex;
|
|
173
|
+
position: static;
|
|
174
|
+
flex-direction: row;
|
|
175
|
+
align-items: center;
|
|
176
|
+
gap: 6px;
|
|
177
|
+
padding: 0;
|
|
178
|
+
background: transparent;
|
|
179
|
+
border-bottom: none;
|
|
180
|
+
box-shadow: none;
|
|
181
|
+
width: auto;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
::slotted(a),
|
|
185
|
+
::slotted(el-route-link) {
|
|
186
|
+
width: auto;
|
|
187
|
+
font-size: 0.875rem;
|
|
188
|
+
padding: 6px 12px;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.mobile-menu-btn {
|
|
192
|
+
display: none;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
|
|
197
|
+
connected() {
|
|
198
|
+
this.addEventListener(
|
|
199
|
+
'click',
|
|
200
|
+
(e) => {
|
|
201
|
+
if (!this.open.value) return;
|
|
202
|
+
const link = e.target?.closest?.('a, el-route-link');
|
|
203
|
+
if (link && this.contains(link)) {
|
|
204
|
+
this.closeMenu();
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
{ signal: this.signal }
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (typeof document !== 'undefined') {
|
|
211
|
+
document.addEventListener(
|
|
212
|
+
'click',
|
|
213
|
+
(e) => {
|
|
214
|
+
if (!this.open.value) return;
|
|
215
|
+
const path = typeof e.composedPath === 'function' ? e.composedPath() : [];
|
|
216
|
+
if (!path.includes(this) && !this.contains(e.target)) {
|
|
217
|
+
this.closeMenu();
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{ signal: this.signal }
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
document.addEventListener(
|
|
224
|
+
'keydown',
|
|
225
|
+
(e) => {
|
|
226
|
+
if (e.key === 'Escape' && this.open.value) {
|
|
227
|
+
this.closeMenu();
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
{ signal: this.signal }
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
toggleMenu(e) {
|
|
236
|
+
if (e) e.stopPropagation();
|
|
237
|
+
this.open.value = !this.open.value;
|
|
238
|
+
this.emit('toggle', { open: this.open.value });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
closeMenu() {
|
|
242
|
+
if (!this.open.value) return;
|
|
243
|
+
this.open.value = false;
|
|
244
|
+
this.emit('toggle', { open: false });
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
render() {
|
|
248
|
+
return html`
|
|
249
|
+
<header class="navbar-inner" part="header">
|
|
250
|
+
<div class="left-group" part="start">
|
|
251
|
+
<slot name="start"></slot>
|
|
252
|
+
<slot name="brand">
|
|
253
|
+
<a class="brand-link" href=${() => this.href.value || '#'} part="brand">
|
|
254
|
+
${() => (this.brand.value ? html`<span class="brand-text">${() => this.brand.value}</span>` : '')}
|
|
255
|
+
${() =>
|
|
256
|
+
this.badge.value
|
|
257
|
+
? html`<el-badge size="sm" variant=${() => this.badgeVariant.value || 'primary'} count=${() => this.badge.value}></el-badge>`
|
|
258
|
+
: ''}
|
|
259
|
+
</a>
|
|
260
|
+
</slot>
|
|
261
|
+
</div>
|
|
262
|
+
|
|
263
|
+
<nav
|
|
264
|
+
class=${() => (this.open.value ? 'nav-links open' : 'nav-links')}
|
|
265
|
+
part="nav"
|
|
266
|
+
aria-label="Primary navigation"
|
|
267
|
+
>
|
|
268
|
+
<slot></slot>
|
|
269
|
+
</nav>
|
|
270
|
+
|
|
271
|
+
<div class="right-group" part="actions">
|
|
272
|
+
<slot name="actions"></slot>
|
|
273
|
+
<button
|
|
274
|
+
class="mobile-menu-btn"
|
|
275
|
+
part="toggle"
|
|
276
|
+
type="button"
|
|
277
|
+
aria-label="Toggle navigation"
|
|
278
|
+
aria-expanded=${() => (this.open.value ? 'true' : 'false')}
|
|
279
|
+
onclick=${(e) => this.toggleMenu(e)}
|
|
280
|
+
>
|
|
281
|
+
${() =>
|
|
282
|
+
this.open.value
|
|
283
|
+
? html`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`
|
|
284
|
+
: html`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>`}
|
|
285
|
+
</button>
|
|
286
|
+
</div>
|
|
287
|
+
</header>
|
|
288
|
+
`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-navbar')) {
|
|
293
|
+
customElements.define('el-navbar', ElNavbar);
|
|
294
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <el-navigation-menu>
|
|
7
|
+
* Desktop mega-menu navigation primitive inspired by Radix Primitives.
|
|
8
|
+
* Supports horizontal links, interactive popover cards, and roving keyboard navigation.
|
|
9
|
+
*/
|
|
10
|
+
export class ElNavigationMenu extends Elementum {
|
|
11
|
+
static observedAttributes = ['orientation'];
|
|
12
|
+
|
|
13
|
+
orientation = signal('horizontal');
|
|
14
|
+
|
|
15
|
+
static styles = css`
|
|
16
|
+
:host {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
position: relative;
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
font-family: inherit;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
nav {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
gap: 6px;
|
|
28
|
+
list-style: none;
|
|
29
|
+
margin: 0;
|
|
30
|
+
padding: 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:host([orientation="vertical"]) nav {
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
align-items: stretch;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media (prefers-reduced-motion: reduce) {
|
|
39
|
+
*, *::before, *::after {
|
|
40
|
+
animation: none !important;
|
|
41
|
+
transition: none !important;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
connected() {
|
|
47
|
+
this.orientation.value = this.getAttribute('orientation') || 'horizontal';
|
|
48
|
+
this.setAttribute('role', 'navigation');
|
|
49
|
+
this.#syncOrientation();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
rendered() {
|
|
53
|
+
this.#syncOrientation();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
attributeChanged(name, oldValue, newValue) {
|
|
57
|
+
if (name === 'orientation') {
|
|
58
|
+
this.orientation.value = newValue || 'horizontal';
|
|
59
|
+
this.#syncOrientation();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#syncOrientation() {
|
|
64
|
+
const orient = this.orientation.value || 'horizontal';
|
|
65
|
+
this.querySelectorAll('el-navigation-menu-item').forEach((item) => {
|
|
66
|
+
item.setAttribute('data-orientation', orient);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
render() {
|
|
71
|
+
return html`<nav><slot></slot></nav>`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* <el-navigation-menu-item>
|
|
77
|
+
* Wrapper for a navigation menu entry (either a direct link or a trigger + content popover).
|
|
78
|
+
*/
|
|
79
|
+
export class ElNavigationMenuItem extends Elementum {
|
|
80
|
+
open = signal(false);
|
|
81
|
+
#closeTimer = null;
|
|
82
|
+
|
|
83
|
+
static styles = css`
|
|
84
|
+
:host {
|
|
85
|
+
position: relative;
|
|
86
|
+
display: inline-block;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.viewport {
|
|
90
|
+
position: absolute;
|
|
91
|
+
top: 100%;
|
|
92
|
+
left: 0;
|
|
93
|
+
margin-top: 8px;
|
|
94
|
+
min-width: 280px;
|
|
95
|
+
padding: 16px;
|
|
96
|
+
background-color: var(--el-surface-card, #ffffff);
|
|
97
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
98
|
+
border-radius: var(--el-radius-lg, 12px);
|
|
99
|
+
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
|
|
100
|
+
z-index: 1050;
|
|
101
|
+
display: none;
|
|
102
|
+
animation: el-nav-fade-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Invisible hover bridge so cursor movement across margin-top does not collapse menu */
|
|
106
|
+
.viewport::before {
|
|
107
|
+
content: '';
|
|
108
|
+
position: absolute;
|
|
109
|
+
top: -14px;
|
|
110
|
+
left: 0;
|
|
111
|
+
right: 0;
|
|
112
|
+
height: 14px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:host([data-orientation="vertical"]) .viewport {
|
|
116
|
+
top: 0;
|
|
117
|
+
left: 100%;
|
|
118
|
+
margin-top: 0;
|
|
119
|
+
margin-left: 8px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
:host([data-orientation="vertical"]) .viewport::before {
|
|
123
|
+
top: 0;
|
|
124
|
+
left: -14px;
|
|
125
|
+
right: auto;
|
|
126
|
+
width: 14px;
|
|
127
|
+
height: 100%;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
:host-context([data-theme="dark"]) .viewport {
|
|
131
|
+
background-color: #1e293b;
|
|
132
|
+
border-color: #334155;
|
|
133
|
+
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
:host([open]) .viewport {
|
|
137
|
+
display: block;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@keyframes el-nav-fade-in {
|
|
141
|
+
from {
|
|
142
|
+
opacity: 0;
|
|
143
|
+
transform: translateY(-4px);
|
|
144
|
+
}
|
|
145
|
+
to {
|
|
146
|
+
opacity: 1;
|
|
147
|
+
transform: translateY(0);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
connected() {
|
|
153
|
+
const parentMenu = this.closest('el-navigation-menu');
|
|
154
|
+
if (parentMenu) {
|
|
155
|
+
this.setAttribute('data-orientation', parentMenu.getAttribute('orientation') || 'horizontal');
|
|
156
|
+
}
|
|
157
|
+
this.addEventListener('mouseenter', this.#onMouseEnter);
|
|
158
|
+
this.addEventListener('mouseleave', this.#onMouseLeave);
|
|
159
|
+
document.addEventListener('click', this.#onDocClick);
|
|
160
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
disconnected() {
|
|
164
|
+
clearTimeout(this.#closeTimer);
|
|
165
|
+
this.removeEventListener('mouseenter', this.#onMouseEnter);
|
|
166
|
+
this.removeEventListener('mouseleave', this.#onMouseLeave);
|
|
167
|
+
document.removeEventListener('click', this.#onDocClick);
|
|
168
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#onMouseEnter = () => {
|
|
172
|
+
clearTimeout(this.#closeTimer);
|
|
173
|
+
if (this.querySelector('el-navigation-menu-content')) {
|
|
174
|
+
this.openMenu();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
#onMouseLeave = () => {
|
|
179
|
+
clearTimeout(this.#closeTimer);
|
|
180
|
+
if (this.querySelector('el-navigation-menu-content')) {
|
|
181
|
+
this.#closeTimer = setTimeout(() => {
|
|
182
|
+
this.closeMenu();
|
|
183
|
+
}, 150);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
#onDocClick = (e) => {
|
|
188
|
+
if (!this.contains(e.target)) {
|
|
189
|
+
this.closeMenu();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
#onKeyDown = (e) => {
|
|
194
|
+
if (e.key === 'Escape') {
|
|
195
|
+
this.closeMenu();
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
openMenu() {
|
|
200
|
+
clearTimeout(this.#closeTimer);
|
|
201
|
+
this.open.value = true;
|
|
202
|
+
this.setAttribute('open', '');
|
|
203
|
+
const trigger = this.querySelector('el-navigation-menu-trigger');
|
|
204
|
+
if (trigger) trigger.setAttribute('aria-expanded', 'true');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
closeMenu() {
|
|
208
|
+
clearTimeout(this.#closeTimer);
|
|
209
|
+
this.open.value = false;
|
|
210
|
+
this.removeAttribute('open');
|
|
211
|
+
const trigger = this.querySelector('el-navigation-menu-trigger');
|
|
212
|
+
if (trigger) trigger.setAttribute('aria-expanded', 'false');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
toggleMenu() {
|
|
216
|
+
if (this.open.value) this.closeMenu();
|
|
217
|
+
else this.openMenu();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
#onViewportClick = (e) => {
|
|
221
|
+
const link = e.target.closest('a, button, [role="menuitem"]');
|
|
222
|
+
if (link) {
|
|
223
|
+
this.emit('select', { value: link.textContent?.trim() || '' });
|
|
224
|
+
this.closeMenu();
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
render() {
|
|
229
|
+
return html`
|
|
230
|
+
<slot name="trigger"></slot>
|
|
231
|
+
<slot></slot>
|
|
232
|
+
<div class="viewport" role="region" @click=${this.#onViewportClick}>
|
|
233
|
+
<slot name="content"></slot>
|
|
234
|
+
</div>
|
|
235
|
+
`;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* <el-navigation-menu-trigger>
|
|
241
|
+
* Button that toggles an <el-navigation-menu-item>'s dropdown.
|
|
242
|
+
*/
|
|
243
|
+
export class ElNavigationMenuTrigger extends Elementum {
|
|
244
|
+
static styles = css`
|
|
245
|
+
:host {
|
|
246
|
+
display: inline-flex;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
button {
|
|
250
|
+
display: inline-flex;
|
|
251
|
+
align-items: center;
|
|
252
|
+
gap: 6px;
|
|
253
|
+
padding: 8px 12px;
|
|
254
|
+
font-size: var(--el-text-sm, 0.875rem);
|
|
255
|
+
font-weight: 500;
|
|
256
|
+
color: var(--el-text-primary, #0f172a);
|
|
257
|
+
background: transparent;
|
|
258
|
+
border: none;
|
|
259
|
+
border-radius: var(--el-radius-md, 6px);
|
|
260
|
+
cursor: pointer;
|
|
261
|
+
transition: background-color 0.15s ease, color 0.15s ease;
|
|
262
|
+
outline: none;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
button:hover, :host-context([open]) button {
|
|
266
|
+
background-color: var(--el-surface-muted, #f1f5f9);
|
|
267
|
+
color: var(--el-primary, #2563eb);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
:host-context([data-theme="dark"]) button {
|
|
271
|
+
color: #f8fafc;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
:host-context([data-theme="dark"]) button:hover,
|
|
275
|
+
:host-context([data-theme="dark"]):host-context([open]) button {
|
|
276
|
+
background-color: #1e293b;
|
|
277
|
+
color: #60a5fa;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.chevron {
|
|
281
|
+
font-size: 10px;
|
|
282
|
+
transition: transform 0.2s ease;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
:host-context([open]) .chevron {
|
|
286
|
+
transform: rotate(180deg);
|
|
287
|
+
}
|
|
288
|
+
`;
|
|
289
|
+
|
|
290
|
+
connected() {
|
|
291
|
+
const btn = this.shadowRoot.querySelector('button');
|
|
292
|
+
btn?.addEventListener('click', () => {
|
|
293
|
+
const parent = this.closest('el-navigation-menu-item');
|
|
294
|
+
if (parent) parent.toggleMenu();
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
render() {
|
|
299
|
+
return html`
|
|
300
|
+
<button type="button" aria-haspopup="true" aria-expanded="false">
|
|
301
|
+
<slot></slot>
|
|
302
|
+
<span class="chevron" aria-hidden="true">▼</span>
|
|
303
|
+
</button>
|
|
304
|
+
`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* <el-navigation-menu-content>
|
|
310
|
+
* Container for the menu item's expanded content.
|
|
311
|
+
*/
|
|
312
|
+
export class ElNavigationMenuContent extends Elementum {
|
|
313
|
+
connected() {
|
|
314
|
+
this.setAttribute('slot', 'content');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
render() {
|
|
318
|
+
return html`<slot></slot>`;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (typeof customElements !== 'undefined') {
|
|
323
|
+
if (!customElements.get('el-navigation-menu')) customElements.define('el-navigation-menu', ElNavigationMenu);
|
|
324
|
+
if (!customElements.get('el-navigation-menu-item')) customElements.define('el-navigation-menu-item', ElNavigationMenuItem);
|
|
325
|
+
if (!customElements.get('el-navigation-menu-trigger')) customElements.define('el-navigation-menu-trigger', ElNavigationMenuTrigger);
|
|
326
|
+
if (!customElements.get('el-navigation-menu-content')) customElements.define('el-navigation-menu-content', ElNavigationMenuContent);
|
|
327
|
+
}
|