@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,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-menubar>
|
|
3
|
+
* Desktop-grade application menubar primitive inspired by Base UI.
|
|
4
|
+
* Features WAI-ARIA role="menubar", horizontal keyboard navigation (ArrowLeft/ArrowRight),
|
|
5
|
+
* automatic hover-switching between menus when open, and light-dismiss.
|
|
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 ElMenubar extends Elementum {
|
|
13
|
+
static observedAttributes = ['disabled'];
|
|
14
|
+
|
|
15
|
+
activeMenu = signal(null); // id or trigger element currently open
|
|
16
|
+
disabled = signal(false);
|
|
17
|
+
|
|
18
|
+
static styles = css`
|
|
19
|
+
:host {
|
|
20
|
+
display: flex;
|
|
21
|
+
width: 100%;
|
|
22
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.menubar {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 2px;
|
|
30
|
+
padding: 3px 6px;
|
|
31
|
+
width: 100%;
|
|
32
|
+
overflow-x: auto;
|
|
33
|
+
-webkit-overflow-scrolling: touch;
|
|
34
|
+
background: var(--el-surface-base, #ffffff);
|
|
35
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
36
|
+
border-radius: var(--el-radius-md, 8px);
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:root[data-theme="dark"] .menubar {
|
|
41
|
+
background: #1e293b;
|
|
42
|
+
border-color: #334155;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
:host([disabled]) {
|
|
46
|
+
opacity: 0.6;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
::slotted([role="menuitem"]),
|
|
51
|
+
::slotted(.menubar-item),
|
|
52
|
+
::slotted(button) {
|
|
53
|
+
display: inline-flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
padding: 4px 10px;
|
|
56
|
+
font-size: 13px;
|
|
57
|
+
font-weight: 500;
|
|
58
|
+
color: var(--el-text-base, #111827);
|
|
59
|
+
background: transparent;
|
|
60
|
+
border: none;
|
|
61
|
+
border-radius: var(--el-radius-sm, 4px);
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
font-family: inherit;
|
|
64
|
+
outline: none;
|
|
65
|
+
transition: background-color 0.12s ease, color 0.12s ease;
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
::slotted([role="menuitem"]:hover),
|
|
70
|
+
::slotted(.menubar-item:hover),
|
|
71
|
+
::slotted(button:hover),
|
|
72
|
+
::slotted([role="menuitem"]:focus-visible),
|
|
73
|
+
::slotted(button:focus-visible) {
|
|
74
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
75
|
+
color: var(--el-color-primary, #2563eb);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:root[data-theme="dark"] ::slotted([role="menuitem"]:hover),
|
|
79
|
+
:root[data-theme="dark"] ::slotted(.menubar-item:hover),
|
|
80
|
+
:root[data-theme="dark"] ::slotted(button:hover) {
|
|
81
|
+
background: #334155;
|
|
82
|
+
color: #93c5fd;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
::slotted([data-state="open"]) {
|
|
86
|
+
background: var(--el-surface-muted, #f1f5f9) !important;
|
|
87
|
+
color: var(--el-color-primary, #2563eb) !important;
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
#focusedIndex = 0;
|
|
92
|
+
|
|
93
|
+
connected() {
|
|
94
|
+
if (this.hasAttribute('disabled')) this.disabled.value = true;
|
|
95
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
96
|
+
this.addEventListener('pointerenter', this.#onPointerEnterItem, true);
|
|
97
|
+
this.addEventListener('click', this.#onClickItem, true);
|
|
98
|
+
|
|
99
|
+
const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
|
|
100
|
+
raf(() => this.#initItems());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
disconnected() {
|
|
104
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
105
|
+
this.removeEventListener('pointerenter', this.#onPointerEnterItem, true);
|
|
106
|
+
this.removeEventListener('click', this.#onClickItem, true);
|
|
107
|
+
this.#removeGlobalListeners();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
attributeChanged(name, oldValue, newValue) {
|
|
111
|
+
if (name === 'disabled') this.disabled.value = newValue !== null;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#getItems() {
|
|
116
|
+
return Array.from(this.querySelectorAll('*')).filter((el) => {
|
|
117
|
+
if (el.parentElement !== this) return false;
|
|
118
|
+
const tag = el.tagName.toLowerCase();
|
|
119
|
+
if (['el-separator', 'hr'].includes(tag)) return false;
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#initItems() {
|
|
125
|
+
const items = this.#getItems();
|
|
126
|
+
items.forEach((item, idx) => {
|
|
127
|
+
item.setAttribute('role', 'menuitem');
|
|
128
|
+
item.setAttribute('tabindex', idx === 0 ? '0' : '-1');
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#onClickItem = (e) => {
|
|
133
|
+
const items = this.#getItems();
|
|
134
|
+
const item = items.find((i) => i === e.target || i.contains(e.target));
|
|
135
|
+
if (!item) return;
|
|
136
|
+
|
|
137
|
+
if (this.activeMenu.value === item) {
|
|
138
|
+
this.closeMenu();
|
|
139
|
+
} else {
|
|
140
|
+
this.openMenu(item);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
#onPointerEnterItem = (e) => {
|
|
145
|
+
// If ANY menu is already open, hovering an adjacent item switches to it!
|
|
146
|
+
if (!this.activeMenu.value) return;
|
|
147
|
+
const items = this.#getItems();
|
|
148
|
+
const item = items.find((i) => i === e.target || i.contains(e.target));
|
|
149
|
+
if (item && item !== this.activeMenu.value) {
|
|
150
|
+
this.openMenu(item);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
openMenu(item) {
|
|
155
|
+
if (this.activeMenu.value) {
|
|
156
|
+
this.activeMenu.value.removeAttribute('data-state');
|
|
157
|
+
this.activeMenu.value.setAttribute('aria-expanded', 'false');
|
|
158
|
+
}
|
|
159
|
+
this.activeMenu.value = item;
|
|
160
|
+
item.setAttribute('data-state', 'open');
|
|
161
|
+
item.setAttribute('aria-expanded', 'true');
|
|
162
|
+
this.#addGlobalListeners();
|
|
163
|
+
this.emit('open', { item });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
closeMenu() {
|
|
167
|
+
if (!this.activeMenu.value) return;
|
|
168
|
+
this.activeMenu.value.removeAttribute('data-state');
|
|
169
|
+
this.activeMenu.value.setAttribute('aria-expanded', 'false');
|
|
170
|
+
this.activeMenu.value = null;
|
|
171
|
+
this.#removeGlobalListeners();
|
|
172
|
+
this.emit('close');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#addGlobalListeners() {
|
|
176
|
+
this.#removeGlobalListeners();
|
|
177
|
+
document.addEventListener('pointerdown', this.#onPointerDownOutside, true);
|
|
178
|
+
window.addEventListener('keydown', this.#onWindowKeyDown, true);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#removeGlobalListeners() {
|
|
182
|
+
document.removeEventListener('pointerdown', this.#onPointerDownOutside, true);
|
|
183
|
+
window.removeEventListener('keydown', this.#onWindowKeyDown, true);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#onPointerDownOutside = (e) => {
|
|
187
|
+
if (!this.activeMenu.value) return;
|
|
188
|
+
const path = e.composedPath ? e.composedPath() : [];
|
|
189
|
+
if (!path.includes(this)) {
|
|
190
|
+
this.closeMenu();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
#onWindowKeyDown = (e) => {
|
|
195
|
+
if (!this.activeMenu.value) return;
|
|
196
|
+
if (e.key === 'Escape') {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
this.closeMenu();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
#onKeyDown = (e) => {
|
|
203
|
+
const items = this.#getItems();
|
|
204
|
+
if (items.length === 0) return;
|
|
205
|
+
|
|
206
|
+
if (e.key === 'ArrowRight') {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
this.#focusedIndex = (this.#focusedIndex + 1) % items.length;
|
|
209
|
+
this.#focusItem(items[this.#focusedIndex]);
|
|
210
|
+
if (this.activeMenu.value) this.openMenu(items[this.#focusedIndex]);
|
|
211
|
+
} else if (e.key === 'ArrowLeft') {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
this.#focusedIndex = (this.#focusedIndex - 1 + items.length) % items.length;
|
|
214
|
+
this.#focusItem(items[this.#focusedIndex]);
|
|
215
|
+
if (this.activeMenu.value) this.openMenu(items[this.#focusedIndex]);
|
|
216
|
+
} else if (e.key === 'Home') {
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
this.#focusedIndex = 0;
|
|
219
|
+
this.#focusItem(items[0]);
|
|
220
|
+
} else if (e.key === 'End') {
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
this.#focusedIndex = items.length - 1;
|
|
223
|
+
this.#focusItem(items[items.length - 1]);
|
|
224
|
+
} else if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
const current = items[this.#focusedIndex];
|
|
227
|
+
if (current) this.openMenu(current);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
#focusItem(item) {
|
|
232
|
+
const items = this.#getItems();
|
|
233
|
+
items.forEach((it) => it.setAttribute('tabindex', it === item ? '0' : '-1'));
|
|
234
|
+
item?.focus();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
render() {
|
|
238
|
+
return html`
|
|
239
|
+
<div
|
|
240
|
+
class="menubar"
|
|
241
|
+
part="menubar"
|
|
242
|
+
role="menubar"
|
|
243
|
+
aria-orientation="horizontal"
|
|
244
|
+
aria-disabled=${() => (this.disabled.value ? 'true' : 'false')}
|
|
245
|
+
>
|
|
246
|
+
<slot></slot>
|
|
247
|
+
</div>
|
|
248
|
+
`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-menubar')) {
|
|
253
|
+
customElements.define('el-menubar', ElMenubar);
|
|
254
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-meter>
|
|
3
|
+
* Accessible scalar measurement gauge primitive inspired by Base UI.
|
|
4
|
+
* Displays a known scalar value or fractional measurement within a bounded range
|
|
5
|
+
* (e.g. disk storage, password strength, battery, quota limits) with semantic threshold statuses.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Elementum } from '../elementum.js';
|
|
9
|
+
import { html, css } from '../template.js';
|
|
10
|
+
import { signal, computed, effect } from '../signal.js';
|
|
11
|
+
|
|
12
|
+
export class ElMeter extends Elementum {
|
|
13
|
+
static observedAttributes = ['value', 'min', 'max', 'low', 'high', 'optimum', 'size'];
|
|
14
|
+
|
|
15
|
+
value = signal(0);
|
|
16
|
+
min = signal(0);
|
|
17
|
+
max = signal(100);
|
|
18
|
+
low = signal(null);
|
|
19
|
+
high = signal(null);
|
|
20
|
+
optimum = signal(null);
|
|
21
|
+
size = signal('md'); // 'sm' | 'md' | 'lg'
|
|
22
|
+
|
|
23
|
+
percentage = computed(() => {
|
|
24
|
+
const val = Number(this.value.value) || 0;
|
|
25
|
+
const minVal = Number(this.min.value) || 0;
|
|
26
|
+
const maxVal = Number(this.max.value) || 100;
|
|
27
|
+
if (maxVal <= minVal) return 0;
|
|
28
|
+
const pct = ((val - minVal) / (maxVal - minVal)) * 100;
|
|
29
|
+
return Math.min(100, Math.max(0, pct));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
status = computed(() => {
|
|
33
|
+
const val = Number(this.value.value) || 0;
|
|
34
|
+
const lowVal = this.low.value !== null ? Number(this.low.value) : null;
|
|
35
|
+
const highVal = this.high.value !== null ? Number(this.high.value) : null;
|
|
36
|
+
const optVal = this.optimum.value !== null ? Number(this.optimum.value) : null;
|
|
37
|
+
|
|
38
|
+
if (lowVal === null || highVal === null) {
|
|
39
|
+
return 'default';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const optimum = optVal !== null ? optVal : (lowVal + highVal) / 2;
|
|
43
|
+
|
|
44
|
+
// Higher is better (e.g., battery, storage remaining)
|
|
45
|
+
if (optimum >= highVal) {
|
|
46
|
+
if (val >= highVal) return 'safe';
|
|
47
|
+
if (val >= lowVal) return 'warning';
|
|
48
|
+
return 'critical';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Lower is better (e.g., CPU load, disk usage)
|
|
52
|
+
if (optimum <= lowVal) {
|
|
53
|
+
if (val <= lowVal) return 'safe';
|
|
54
|
+
if (val <= highVal) return 'warning';
|
|
55
|
+
return 'critical';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Medium is optimum
|
|
59
|
+
if (val >= lowVal && val <= highVal) return 'safe';
|
|
60
|
+
return 'warning';
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
static styles = css`
|
|
64
|
+
:host {
|
|
65
|
+
display: block;
|
|
66
|
+
width: 100%;
|
|
67
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
68
|
+
font-variant-numeric: tabular-nums;
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.meter-container {
|
|
73
|
+
width: 100%;
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
gap: 4px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.track {
|
|
80
|
+
width: 100%;
|
|
81
|
+
background: var(--el-surface-muted, #e2e8f0);
|
|
82
|
+
border-radius: 9999px;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
position: relative;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:host([size="sm"]) .track {
|
|
88
|
+
height: 4px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:host([size="md"]) .track,
|
|
92
|
+
:host(:not([size])) .track {
|
|
93
|
+
height: 8px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
:host([size="lg"]) .track {
|
|
97
|
+
height: 12px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
:root[data-theme="dark"] .track {
|
|
101
|
+
background: #334155;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.fill {
|
|
105
|
+
height: 100%;
|
|
106
|
+
border-radius: inherit;
|
|
107
|
+
transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
|
|
108
|
+
background: var(--el-color-primary, #2563eb);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
:host([data-status="safe"]) .fill {
|
|
112
|
+
background: var(--el-color-success, #16a34a);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:host([data-status="warning"]) .fill {
|
|
116
|
+
background: var(--el-color-warning, #eab308);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
:host([data-status="critical"]) .fill {
|
|
120
|
+
background: var(--el-color-danger, #dc2626);
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
|
|
124
|
+
#stopEffect = null;
|
|
125
|
+
|
|
126
|
+
connected() {
|
|
127
|
+
this.#syncAttributes();
|
|
128
|
+
this.#stopEffect = effect(() => {
|
|
129
|
+
this.setAttribute('data-status', this.status.value);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
disconnected() {
|
|
134
|
+
this.#stopEffect?.();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
attributeChanged(name, oldValue, newValue) {
|
|
138
|
+
if (name === 'value') this.value.value = Number(newValue) || 0;
|
|
139
|
+
else if (name === 'min') this.min.value = Number(newValue) || 0;
|
|
140
|
+
else if (name === 'max') this.max.value = Number(newValue) || 100;
|
|
141
|
+
else if (name === 'low') this.low.value = newValue !== null ? Number(newValue) : null;
|
|
142
|
+
else if (name === 'high') this.high.value = newValue !== null ? Number(newValue) : null;
|
|
143
|
+
else if (name === 'optimum') this.optimum.value = newValue !== null ? Number(newValue) : null;
|
|
144
|
+
else if (name === 'size') this.size.value = newValue || 'md';
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#syncAttributes() {
|
|
149
|
+
if (this.hasAttribute('value')) this.value.value = Number(this.getAttribute('value')) || 0;
|
|
150
|
+
if (this.hasAttribute('min')) this.min.value = Number(this.getAttribute('min')) || 0;
|
|
151
|
+
if (this.hasAttribute('max')) this.max.value = Number(this.getAttribute('max')) || 100;
|
|
152
|
+
if (this.hasAttribute('low')) this.low.value = Number(this.getAttribute('low'));
|
|
153
|
+
if (this.hasAttribute('high')) this.high.value = Number(this.getAttribute('high'));
|
|
154
|
+
if (this.hasAttribute('optimum')) this.optimum.value = Number(this.getAttribute('optimum'));
|
|
155
|
+
if (this.hasAttribute('size')) this.size.value = this.getAttribute('size');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
render() {
|
|
159
|
+
return html`
|
|
160
|
+
<div
|
|
161
|
+
class="meter-container"
|
|
162
|
+
role="meter"
|
|
163
|
+
aria-valuenow=${() => this.value.value}
|
|
164
|
+
aria-valuemin=${() => this.min.value}
|
|
165
|
+
aria-valuemax=${() => this.max.value}
|
|
166
|
+
aria-valuetext=${() => `${Math.round(this.percentage.value)}%`}
|
|
167
|
+
>
|
|
168
|
+
<div class="track" part="track">
|
|
169
|
+
<div
|
|
170
|
+
class="fill"
|
|
171
|
+
part="fill"
|
|
172
|
+
style=${() => `width: ${this.percentage.value}%;`}
|
|
173
|
+
></div>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-meter')) {
|
|
181
|
+
customElements.define('el-meter', ElMeter);
|
|
182
|
+
}
|