@wcomp/elementum 0.0.0-stage → 0.2.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 +282 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +593 -0
- package/package.json +77 -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/behaviors/index.js +760 -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 +231 -0
- package/src/components/el-calendar.js +436 -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 +230 -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 +229 -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 +183 -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 +164 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +231 -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 +220 -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 +504 -0
- package/src/index.d.ts +1093 -0
- package/src/index.js +112 -0
- package/src/signal.js +215 -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,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-toolbar>
|
|
3
|
+
* Accessible action & tool strip container primitive inspired by Base UI.
|
|
4
|
+
* Implements WAI-ARIA Toolbar role with roving tabindex keyboard navigation,
|
|
5
|
+
* orientation support, and seamless grouping of controls.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Elementum } from '../elementum.js';
|
|
9
|
+
import { html, css } from '../template.js';
|
|
10
|
+
import { signal } from '../signal.js';
|
|
11
|
+
|
|
12
|
+
export class ElToolbar extends Elementum {
|
|
13
|
+
static observedAttributes = ['orientation', 'disabled'];
|
|
14
|
+
|
|
15
|
+
orientation = signal('horizontal'); // 'horizontal' | 'vertical'
|
|
16
|
+
disabled = signal(false);
|
|
17
|
+
|
|
18
|
+
static styles = css`
|
|
19
|
+
:host {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
max-width: 100%;
|
|
22
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.toolbar {
|
|
27
|
+
display: inline-flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: var(--el-spacing-xs, 4px);
|
|
30
|
+
padding: var(--el-spacing-xs, 4px);
|
|
31
|
+
background: var(--el-surface-base, #ffffff);
|
|
32
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
33
|
+
border-radius: var(--el-radius-md, 8px);
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
max-width: 100%;
|
|
36
|
+
overflow-x: auto;
|
|
37
|
+
-webkit-overflow-scrolling: touch;
|
|
38
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:root[data-theme="dark"] .toolbar {
|
|
42
|
+
background: #1e293b;
|
|
43
|
+
border-color: #334155;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
:host([orientation="vertical"]) .toolbar {
|
|
47
|
+
flex-direction: column;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
:host([disabled]) {
|
|
51
|
+
opacity: 0.6;
|
|
52
|
+
pointer-events: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
::slotted(*) {
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
#focusedIndex = 0;
|
|
61
|
+
|
|
62
|
+
connected() {
|
|
63
|
+
if (this.hasAttribute('orientation')) {
|
|
64
|
+
this.orientation.value = this.getAttribute('orientation');
|
|
65
|
+
}
|
|
66
|
+
if (this.hasAttribute('disabled')) {
|
|
67
|
+
this.disabled.value = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
71
|
+
this.addEventListener('focusin', this.#onFocusIn);
|
|
72
|
+
|
|
73
|
+
// Initial roving tabindex setup
|
|
74
|
+
const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
|
|
75
|
+
const slot = this.shadowRoot?.querySelector('slot');
|
|
76
|
+
slot?.addEventListener('slotchange', () => this.#updateRovingTabindex());
|
|
77
|
+
// Also run immediately
|
|
78
|
+
raf(() => this.#updateRovingTabindex());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
disconnected() {
|
|
82
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
83
|
+
this.removeEventListener('focusin', this.#onFocusIn);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
attributeChanged(name, oldValue, newValue) {
|
|
87
|
+
if (name === 'orientation') {
|
|
88
|
+
this.orientation.value = newValue || 'horizontal';
|
|
89
|
+
} else if (name === 'disabled') {
|
|
90
|
+
this.disabled.value = newValue !== null;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#getItems() {
|
|
96
|
+
const candidates = Array.from(this.querySelectorAll('*')).filter((el) => {
|
|
97
|
+
// Must be a direct child or button/input/select/custom element
|
|
98
|
+
if (el.parentElement !== this) return false;
|
|
99
|
+
const tag = el.tagName.toLowerCase();
|
|
100
|
+
if (['el-separator', 'hr'].includes(tag)) return false;
|
|
101
|
+
if (el.hasAttribute('disabled') || el.getAttribute('aria-hidden') === 'true') return false;
|
|
102
|
+
return true;
|
|
103
|
+
});
|
|
104
|
+
return candidates;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#updateRovingTabindex(activeIndex = 0) {
|
|
108
|
+
const items = this.#getItems();
|
|
109
|
+
if (items.length === 0) return;
|
|
110
|
+
this.#focusedIndex = Math.max(0, Math.min(activeIndex, items.length - 1));
|
|
111
|
+
|
|
112
|
+
items.forEach((item, idx) => {
|
|
113
|
+
if (idx === this.#focusedIndex) {
|
|
114
|
+
item.setAttribute('tabindex', '0');
|
|
115
|
+
} else {
|
|
116
|
+
item.setAttribute('tabindex', '-1');
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#onFocusIn = (e) => {
|
|
122
|
+
const items = this.#getItems();
|
|
123
|
+
const idx = items.indexOf(e.target);
|
|
124
|
+
if (idx !== -1) {
|
|
125
|
+
this.#focusedIndex = idx;
|
|
126
|
+
this.#updateRovingTabindex(idx);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
#onKeyDown = (e) => {
|
|
131
|
+
if (this.disabled.value) return;
|
|
132
|
+
const items = this.#getItems();
|
|
133
|
+
if (items.length === 0) return;
|
|
134
|
+
|
|
135
|
+
const isVert = this.orientation.value === 'vertical';
|
|
136
|
+
const prevKey = isVert ? 'ArrowUp' : 'ArrowLeft';
|
|
137
|
+
const nextKey = isVert ? 'ArrowDown' : 'ArrowRight';
|
|
138
|
+
|
|
139
|
+
if (e.key === prevKey) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
this.#focusedIndex = (this.#focusedIndex - 1 + items.length) % items.length;
|
|
142
|
+
this.#focusCurrent(items);
|
|
143
|
+
} else if (e.key === nextKey) {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
this.#focusedIndex = (this.#focusedIndex + 1) % items.length;
|
|
146
|
+
this.#focusCurrent(items);
|
|
147
|
+
} else if (e.key === 'Home') {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
this.#focusedIndex = 0;
|
|
150
|
+
this.#focusCurrent(items);
|
|
151
|
+
} else if (e.key === 'End') {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
this.#focusedIndex = items.length - 1;
|
|
154
|
+
this.#focusCurrent(items);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
#focusCurrent(items) {
|
|
159
|
+
const target = items[this.#focusedIndex];
|
|
160
|
+
if (target) {
|
|
161
|
+
this.#updateRovingTabindex(this.#focusedIndex);
|
|
162
|
+
target.focus();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
render() {
|
|
167
|
+
return html`
|
|
168
|
+
<div
|
|
169
|
+
class="toolbar"
|
|
170
|
+
part="toolbar"
|
|
171
|
+
role="toolbar"
|
|
172
|
+
aria-orientation=${() => this.orientation.value}
|
|
173
|
+
aria-disabled=${() => (this.disabled.value ? 'true' : 'false')}
|
|
174
|
+
>
|
|
175
|
+
<slot></slot>
|
|
176
|
+
</div>
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-toolbar')) {
|
|
182
|
+
customElements.define('el-toolbar', ElToolbar);
|
|
183
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-tooltip>
|
|
3
|
+
* Accessible lightweight tooltip anchored to wrapped trigger element.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Elementum } from '../elementum.js';
|
|
7
|
+
import { html, css } from '../template.js';
|
|
8
|
+
import { signal } from '../signal.js';
|
|
9
|
+
|
|
10
|
+
let lastTooltipClosedAt = 0;
|
|
11
|
+
|
|
12
|
+
export class ElTooltip extends Elementum {
|
|
13
|
+
static observedAttributes = ['content', 'placement', 'delay', 'disabled'];
|
|
14
|
+
|
|
15
|
+
content = signal('');
|
|
16
|
+
placement = signal('top'); // 'top' | 'bottom' | 'left' | 'right'
|
|
17
|
+
delay = signal(150);
|
|
18
|
+
disabled = signal(false);
|
|
19
|
+
visible = signal(false);
|
|
20
|
+
|
|
21
|
+
#timeoutId = null;
|
|
22
|
+
|
|
23
|
+
static styles = css`
|
|
24
|
+
:host {
|
|
25
|
+
position: relative;
|
|
26
|
+
display: inline-block;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.tooltip-bubble {
|
|
30
|
+
position: absolute;
|
|
31
|
+
z-index: 1000;
|
|
32
|
+
padding: 6px 10px;
|
|
33
|
+
font-size: 0.8125rem;
|
|
34
|
+
line-height: 1.25;
|
|
35
|
+
font-weight: 500;
|
|
36
|
+
color: var(--el-tooltip-text, #ffffff) !important;
|
|
37
|
+
background: var(--el-tooltip-bg, #0f172a) !important;
|
|
38
|
+
border: 1px solid var(--el-tooltip-border, rgba(255, 255, 255, 0.15));
|
|
39
|
+
border-radius: var(--el-radius-sm, 6px);
|
|
40
|
+
box-shadow: 0 4px 14px -2px rgba(0, 0, 0, 0.4);
|
|
41
|
+
white-space: nowrap;
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
opacity: 0;
|
|
44
|
+
visibility: hidden;
|
|
45
|
+
transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.tooltip-bubble ::slotted(*),
|
|
49
|
+
.tooltip-bubble slot {
|
|
50
|
+
color: var(--el-tooltip-text, #ffffff) !important;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.tooltip-bubble.visible {
|
|
54
|
+
opacity: 1;
|
|
55
|
+
visibility: visible;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Placements (origin-aware toward trigger edge) */
|
|
59
|
+
.tooltip-bubble.top {
|
|
60
|
+
bottom: calc(100% + 8px);
|
|
61
|
+
left: 50%;
|
|
62
|
+
transform-origin: bottom center;
|
|
63
|
+
transform: translateX(-50%) translateY(4px) scale(0.96);
|
|
64
|
+
}
|
|
65
|
+
.tooltip-bubble.top.visible {
|
|
66
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.tooltip-bubble.bottom {
|
|
70
|
+
top: calc(100% + 8px);
|
|
71
|
+
left: 50%;
|
|
72
|
+
transform-origin: top center;
|
|
73
|
+
transform: translateX(-50%) translateY(-4px) scale(0.96);
|
|
74
|
+
}
|
|
75
|
+
.tooltip-bubble.bottom.visible {
|
|
76
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.tooltip-bubble.left {
|
|
80
|
+
right: calc(100% + 8px);
|
|
81
|
+
top: 50%;
|
|
82
|
+
transform-origin: right center;
|
|
83
|
+
transform: translateY(-50%) translateX(4px) scale(0.96);
|
|
84
|
+
}
|
|
85
|
+
.tooltip-bubble.left.visible {
|
|
86
|
+
transform: translateY(-50%) translateX(0) scale(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.tooltip-bubble.right {
|
|
90
|
+
left: calc(100% + 8px);
|
|
91
|
+
top: 50%;
|
|
92
|
+
transform-origin: left center;
|
|
93
|
+
transform: translateY(-50%) translateX(-4px) scale(0.96);
|
|
94
|
+
}
|
|
95
|
+
.tooltip-bubble.right.visible {
|
|
96
|
+
transform: translateY(-50%) translateX(0) scale(1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@media (prefers-reduced-motion: reduce) {
|
|
100
|
+
.tooltip-bubble {
|
|
101
|
+
transition: none;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
connected() {
|
|
107
|
+
this.setAttribute('data-state', this.visible.value ? 'open' : 'closed');
|
|
108
|
+
this.setAttribute('data-side', this.placement.value);
|
|
109
|
+
this.addEventListener('mouseenter', this.#onEnter);
|
|
110
|
+
this.addEventListener('mouseleave', this.#onLeave);
|
|
111
|
+
this.addEventListener('focusin', this.#onEnter);
|
|
112
|
+
this.addEventListener('focusout', this.#onLeave);
|
|
113
|
+
window.addEventListener('keydown', this.#onWindowKeyDown, { signal: this.signal });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
show() {
|
|
117
|
+
if (this.disabled.value) return;
|
|
118
|
+
clearTimeout(this.#timeoutId);
|
|
119
|
+
const recentGroupSwitch = Date.now() - lastTooltipClosedAt < 350;
|
|
120
|
+
const delayMs = recentGroupSwitch ? 0 : (Number(this.delay.value) || 0);
|
|
121
|
+
const doShow = () => {
|
|
122
|
+
this.visible.value = true;
|
|
123
|
+
this.setAttribute('data-state', 'open');
|
|
124
|
+
this.setAttribute('data-side', this.placement.value);
|
|
125
|
+
};
|
|
126
|
+
if (delayMs > 0) {
|
|
127
|
+
this.#timeoutId = setTimeout(doShow, delayMs);
|
|
128
|
+
} else {
|
|
129
|
+
doShow();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
hide() {
|
|
134
|
+
clearTimeout(this.#timeoutId);
|
|
135
|
+
if (this.visible.value) {
|
|
136
|
+
lastTooltipClosedAt = Date.now();
|
|
137
|
+
}
|
|
138
|
+
this.visible.value = false;
|
|
139
|
+
this.setAttribute('data-state', 'closed');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#onEnter = () => {
|
|
143
|
+
this.show();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
#onLeave = () => {
|
|
147
|
+
this.hide();
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
#onWindowKeyDown = (e) => {
|
|
151
|
+
if (e.key === 'Escape' && this.visible.value) {
|
|
152
|
+
this.hide();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
render() {
|
|
157
|
+
return html`
|
|
158
|
+
<slot></slot>
|
|
159
|
+
<div
|
|
160
|
+
role="tooltip"
|
|
161
|
+
part="bubble"
|
|
162
|
+
class=${() => `tooltip-bubble ${this.placement.value} ${this.visible.value ? 'visible' : ''}`}
|
|
163
|
+
>
|
|
164
|
+
<slot name="content">${this.content}</slot>
|
|
165
|
+
</div>
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-tooltip')) {
|
|
171
|
+
customElements.define('el-tooltip', ElTooltip);
|
|
172
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-tree-view> & <el-tree-item>
|
|
3
|
+
* Accessible multi-level hierarchical tree explorer inspired by shadcn/ui.
|
|
4
|
+
* Supports keyboard navigation (ArrowUp, ArrowDown, ArrowRight, ArrowLeft),
|
|
5
|
+
* selection, auto-collapse/expand, custom icons, and folder/leaf roles.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Elementum } from '../elementum.js';
|
|
9
|
+
import { html, css } from '../template.js';
|
|
10
|
+
import { signal } from '../signal.js';
|
|
11
|
+
|
|
12
|
+
export class ElTreeItem extends Elementum {
|
|
13
|
+
static observedAttributes = ['label', 'expanded', 'selected', 'disabled'];
|
|
14
|
+
|
|
15
|
+
label = signal('');
|
|
16
|
+
expanded = signal(false);
|
|
17
|
+
selected = signal(false);
|
|
18
|
+
disabled = signal(false);
|
|
19
|
+
hasChildren = signal(false);
|
|
20
|
+
|
|
21
|
+
static styles = css`
|
|
22
|
+
:host {
|
|
23
|
+
display: block;
|
|
24
|
+
user-select: none;
|
|
25
|
+
-webkit-user-select: none;
|
|
26
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.item-row {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: 6px;
|
|
34
|
+
padding: 6px 8px;
|
|
35
|
+
border-radius: var(--el-radius-sm, 6px);
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
font-size: 0.875rem;
|
|
38
|
+
color: var(--el-text-primary, #0f172a);
|
|
39
|
+
transition: background-color 0.12s ease;
|
|
40
|
+
outline: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.item-row:hover {
|
|
44
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:root[data-theme="dark"] .item-row {
|
|
48
|
+
color: #f8fafc;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:root[data-theme="dark"] .item-row:hover {
|
|
52
|
+
background: #1e293b;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:host([selected]) .item-row {
|
|
56
|
+
background: var(--el-surface-border, #e2e8f0);
|
|
57
|
+
font-weight: 600;
|
|
58
|
+
color: var(--el-color-primary, #2563eb);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:root[data-theme="dark"] :host([selected]) .item-row {
|
|
62
|
+
background: #334155;
|
|
63
|
+
color: #93c5fd;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.chevron {
|
|
67
|
+
width: 16px;
|
|
68
|
+
height: 16px;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: center;
|
|
72
|
+
transition: transform 0.2s ease;
|
|
73
|
+
color: var(--el-text-muted, #94a3b8);
|
|
74
|
+
flex-shrink: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.chevron.hidden {
|
|
78
|
+
visibility: hidden;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.chevron.open {
|
|
82
|
+
transform: rotate(90deg);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.icon {
|
|
86
|
+
display: flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
justify-content: center;
|
|
89
|
+
flex-shrink: 0;
|
|
90
|
+
color: var(--el-text-secondary, #64748b);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.label {
|
|
94
|
+
flex: 1;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
text-overflow: ellipsis;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.sub-tree {
|
|
101
|
+
display: none;
|
|
102
|
+
padding-left: 20px;
|
|
103
|
+
position: relative;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.sub-tree::before {
|
|
107
|
+
content: '';
|
|
108
|
+
position: absolute;
|
|
109
|
+
top: 0;
|
|
110
|
+
bottom: 8px;
|
|
111
|
+
left: 14px;
|
|
112
|
+
width: 1px;
|
|
113
|
+
background: var(--el-surface-border, #e2e8f0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
:root[data-theme="dark"] .sub-tree::before {
|
|
117
|
+
background: #334155;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
:host([expanded]) .sub-tree {
|
|
121
|
+
display: block;
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
connected() {
|
|
126
|
+
this.#syncAttrs();
|
|
127
|
+
this.#checkChildren();
|
|
128
|
+
|
|
129
|
+
const observer = new MutationObserver(() => this.#checkChildren());
|
|
130
|
+
observer.observe(this, { childList: true });
|
|
131
|
+
this._observer = observer;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
disconnected() {
|
|
135
|
+
this._observer?.disconnect();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
attributeChanged(name, oldValue, newValue) {
|
|
139
|
+
this.#syncAttrs();
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#syncAttrs() {
|
|
144
|
+
this.label.value = this.getAttribute('label') || '';
|
|
145
|
+
this.expanded.value = this.hasAttribute('expanded');
|
|
146
|
+
this.selected.value = this.hasAttribute('selected');
|
|
147
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#checkChildren() {
|
|
151
|
+
const childItems = this.querySelectorAll('el-tree-item');
|
|
152
|
+
this.hasChildren.value = childItems.length > 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
toggle = (e) => {
|
|
156
|
+
e?.stopPropagation();
|
|
157
|
+
if (this.disabled.value) return;
|
|
158
|
+
|
|
159
|
+
if (this.hasChildren.value) {
|
|
160
|
+
if (this.expanded.value) {
|
|
161
|
+
this.expanded.value = false;
|
|
162
|
+
this.removeAttribute('expanded');
|
|
163
|
+
this.emit('collapse', { item: this });
|
|
164
|
+
} else {
|
|
165
|
+
this.expanded.value = true;
|
|
166
|
+
this.setAttribute('expanded', '');
|
|
167
|
+
this.emit('expand', { item: this });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
this.select();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
select() {
|
|
175
|
+
const tree = this.closest('el-tree-view');
|
|
176
|
+
if (tree) {
|
|
177
|
+
tree.querySelectorAll('el-tree-item').forEach(it => {
|
|
178
|
+
if (it !== this) {
|
|
179
|
+
it.selected.value = false;
|
|
180
|
+
it.removeAttribute('selected');
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
this.selected.value = true;
|
|
186
|
+
this.setAttribute('selected', '');
|
|
187
|
+
this.emit('select', { item: this, label: this.label.value });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
render() {
|
|
191
|
+
return html`
|
|
192
|
+
<div
|
|
193
|
+
class="item-row"
|
|
194
|
+
part="item"
|
|
195
|
+
role="treeitem"
|
|
196
|
+
aria-expanded=${() => (this.hasChildren.value ? String(this.expanded.value) : false)}
|
|
197
|
+
aria-selected=${() => String(this.selected.value)}
|
|
198
|
+
tabindex="0"
|
|
199
|
+
onclick=${this.toggle}
|
|
200
|
+
>
|
|
201
|
+
<span class=${() => `chevron ${!this.hasChildren.value ? 'hidden' : ''} ${this.expanded.value ? 'open' : ''}`}>
|
|
202
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="m9 18 6-6-6-6"/></svg>
|
|
203
|
+
</span>
|
|
204
|
+
<span class="icon" part="icon">
|
|
205
|
+
<slot name="icon">
|
|
206
|
+
${() =>
|
|
207
|
+
this.hasChildren.value
|
|
208
|
+
? html`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 8 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>`
|
|
209
|
+
: html`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></svg>`
|
|
210
|
+
}
|
|
211
|
+
</slot>
|
|
212
|
+
</span>
|
|
213
|
+
<span class="label" part="label">${() => this.label.value || html`<slot name="label"></slot>`}</span>
|
|
214
|
+
</div>
|
|
215
|
+
<div class="sub-tree" part="subtree" role="group">
|
|
216
|
+
<slot></slot>
|
|
217
|
+
</div>
|
|
218
|
+
`;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export class ElTreeView extends Elementum {
|
|
223
|
+
static observedAttributes = ['max-width'];
|
|
224
|
+
|
|
225
|
+
static styles = css`
|
|
226
|
+
:host {
|
|
227
|
+
display: block;
|
|
228
|
+
width: 100%;
|
|
229
|
+
box-sizing: border-box;
|
|
230
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
231
|
+
}
|
|
232
|
+
`;
|
|
233
|
+
|
|
234
|
+
connected() {
|
|
235
|
+
this.setAttribute('role', 'tree');
|
|
236
|
+
this.#applyMaxWidth();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
attributeChanged(name, oldValue, newValue) {
|
|
240
|
+
if (name === 'max-width') {
|
|
241
|
+
this.#applyMaxWidth();
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
#applyMaxWidth() {
|
|
247
|
+
if (this.hasAttribute('max-width')) {
|
|
248
|
+
const mw = this.getAttribute('max-width');
|
|
249
|
+
this.style.maxWidth = mw ? (isNaN(mw) ? mw : `${mw}px`) : '';
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
render() {
|
|
254
|
+
return html`<slot></slot>`;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (typeof customElements !== 'undefined') {
|
|
259
|
+
if (!customElements.get('el-tree-item')) customElements.define('el-tree-item', ElTreeItem);
|
|
260
|
+
if (!customElements.get('el-tree-view')) customElements.define('el-tree-view', ElTreeView);
|
|
261
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <el-visually-hidden>
|
|
6
|
+
* Accessibility primitive inspired by Radix Primitives.
|
|
7
|
+
* Hides content visually while keeping it fully accessible to assistive technologies.
|
|
8
|
+
*/
|
|
9
|
+
export class ElVisuallyHidden extends Elementum {
|
|
10
|
+
static styles = css`
|
|
11
|
+
:host {
|
|
12
|
+
border: 0 !important;
|
|
13
|
+
clip: rect(0 0 0 0) !important;
|
|
14
|
+
clip-path: inset(50%) !important;
|
|
15
|
+
height: 1px !important;
|
|
16
|
+
margin: -1px !important;
|
|
17
|
+
overflow: hidden !important;
|
|
18
|
+
padding: 0 !important;
|
|
19
|
+
position: absolute !important;
|
|
20
|
+
white-space: nowrap !important;
|
|
21
|
+
width: 1px !important;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
return html`<slot></slot>`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-visually-hidden')) {
|
|
31
|
+
customElements.define('el-visually-hidden', ElVisuallyHidden);
|
|
32
|
+
}
|