@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,230 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal, computed } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <el-task-list>
|
|
7
|
+
* Multi-step AI agent plan and execution progress tracker.
|
|
8
|
+
*
|
|
9
|
+
* @element el-task-list
|
|
10
|
+
* @attr {string} heading - Plan heading (default: 'Agent Execution Plan')
|
|
11
|
+
* @attr {string} tasks - JSON array of { id, label, status, detail?, duration? }
|
|
12
|
+
* @attr {boolean} compact - Compact dense row mode
|
|
13
|
+
*/
|
|
14
|
+
export class ElTaskList extends Elementum {
|
|
15
|
+
static observedAttributes = ['heading', 'tasks', 'compact'];
|
|
16
|
+
|
|
17
|
+
heading = signal('Agent Execution Plan');
|
|
18
|
+
tasks = signal([]);
|
|
19
|
+
compact = signal(false);
|
|
20
|
+
|
|
21
|
+
progress = computed(() => {
|
|
22
|
+
const list = Array.isArray(this.tasks.value) ? this.tasks.value : [];
|
|
23
|
+
const completed = list.filter((t) => t.status === 'completed').length;
|
|
24
|
+
return { completed, total: list.length };
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
connected() {
|
|
28
|
+
this.#sync();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
attributeChanged() {
|
|
32
|
+
this.#sync();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#sync() {
|
|
36
|
+
if (this.hasAttribute('heading')) this.heading.value = this.getAttribute('heading') || 'Agent Execution Plan';
|
|
37
|
+
this.compact.value = this.hasAttribute('compact') && this.getAttribute('compact') !== 'false';
|
|
38
|
+
const raw = this.getAttribute('tasks');
|
|
39
|
+
if (raw) {
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(raw);
|
|
42
|
+
if (Array.isArray(parsed)) this.tasks.value = parsed;
|
|
43
|
+
} catch {
|
|
44
|
+
// Ignore invalid JSON
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Surgically updates or inserts a task by id (ideal for AG-UI STEP_STARTED / STEP_FINISHED).
|
|
51
|
+
*/
|
|
52
|
+
updateTask(id, patch) {
|
|
53
|
+
const list = Array.isArray(this.tasks.value) ? [...this.tasks.value] : [];
|
|
54
|
+
const idx = list.findIndex((t) => t.id === id);
|
|
55
|
+
if (idx === -1) {
|
|
56
|
+
list.push({ id, label: patch.label || id, status: patch.status || 'running', ...patch });
|
|
57
|
+
} else {
|
|
58
|
+
list[idx] = { ...list[idx], ...patch };
|
|
59
|
+
}
|
|
60
|
+
this.tasks.value = list;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static styles = css`
|
|
64
|
+
:host {
|
|
65
|
+
display: block;
|
|
66
|
+
font-family: var(--el-font-sans, system-ui, -apple-system, sans-serif);
|
|
67
|
+
box-sizing: border-box;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.task-card {
|
|
71
|
+
border: 1px solid var(--el-surface-border, #e2e8f0);
|
|
72
|
+
border-radius: var(--el-radius-md, 10px);
|
|
73
|
+
background: var(--el-surface-base, #ffffff);
|
|
74
|
+
overflow: hidden;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.task-header {
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
justify-content: space-between;
|
|
81
|
+
gap: 12px;
|
|
82
|
+
padding: 10px 14px;
|
|
83
|
+
background: var(--el-surface-muted, #f8fafc);
|
|
84
|
+
border-bottom: 1px solid var(--el-surface-border, #e2e8f0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.title {
|
|
88
|
+
font-size: 0.85rem;
|
|
89
|
+
font-weight: 700;
|
|
90
|
+
color: var(--el-text-primary, #0f172a);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.counter {
|
|
94
|
+
font-size: 0.75rem;
|
|
95
|
+
font-weight: 600;
|
|
96
|
+
color: var(--el-text-secondary, #475569);
|
|
97
|
+
font-variant-numeric: tabular-nums;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.rows {
|
|
101
|
+
list-style: none;
|
|
102
|
+
margin: 0;
|
|
103
|
+
padding: 6px 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.row {
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: flex-start;
|
|
109
|
+
gap: 10px;
|
|
110
|
+
padding: 8px 14px;
|
|
111
|
+
font-size: 0.85rem;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
:host([compact]) .row {
|
|
115
|
+
padding: 5px 12px;
|
|
116
|
+
font-size: 0.8rem;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.status-icon {
|
|
120
|
+
flex-shrink: 0;
|
|
121
|
+
width: 18px;
|
|
122
|
+
height: 18px;
|
|
123
|
+
border-radius: 9999px;
|
|
124
|
+
display: inline-flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: center;
|
|
127
|
+
font-size: 0.7rem;
|
|
128
|
+
font-weight: 700;
|
|
129
|
+
margin-top: 1px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.status-completed { background: #d1fae5; color: #047857; }
|
|
133
|
+
.status-running {
|
|
134
|
+
background: #dbeafe;
|
|
135
|
+
color: #1d4ed8;
|
|
136
|
+
animation: el-task-pulse 1.2s ease-out infinite;
|
|
137
|
+
}
|
|
138
|
+
.status-error { background: #fee2e2; color: #b91c1c; }
|
|
139
|
+
.status-pending, .status-skipped { background: #f1f5f9; color: #64748b; }
|
|
140
|
+
|
|
141
|
+
@keyframes el-task-pulse {
|
|
142
|
+
0%, 100% { opacity: 1; transform: scale(1); }
|
|
143
|
+
50% { opacity: 0.55; transform: scale(0.92); }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.row-main {
|
|
147
|
+
flex: 1;
|
|
148
|
+
min-width: 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.row-label {
|
|
152
|
+
font-weight: 600;
|
|
153
|
+
color: var(--el-text-primary, #0f172a);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.row.is-skipped .row-label {
|
|
157
|
+
color: var(--el-text-muted, #94a3b8);
|
|
158
|
+
text-decoration: line-through;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.row-detail {
|
|
162
|
+
font-size: 0.76rem;
|
|
163
|
+
color: var(--el-text-secondary, #64748b);
|
|
164
|
+
margin-top: 2px;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.duration {
|
|
168
|
+
flex-shrink: 0;
|
|
169
|
+
font-family: var(--el-font-mono, ui-monospace, monospace);
|
|
170
|
+
font-size: 0.72rem;
|
|
171
|
+
color: var(--el-text-muted, #64748b);
|
|
172
|
+
font-variant-numeric: tabular-nums;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
:root[data-theme="dark"] .task-card {
|
|
176
|
+
background: #0f172a;
|
|
177
|
+
border-color: #334155;
|
|
178
|
+
}
|
|
179
|
+
:root[data-theme="dark"] .task-header {
|
|
180
|
+
background: #1e293b;
|
|
181
|
+
border-color: #334155;
|
|
182
|
+
}
|
|
183
|
+
:root[data-theme="dark"] .title,
|
|
184
|
+
:root[data-theme="dark"] .row-label {
|
|
185
|
+
color: #f8fafc;
|
|
186
|
+
}
|
|
187
|
+
:root[data-theme="dark"] .counter,
|
|
188
|
+
:root[data-theme="dark"] .row-detail {
|
|
189
|
+
color: #94a3b8;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@media (prefers-reduced-motion: reduce) {
|
|
193
|
+
.status-running { animation: none; }
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
|
|
197
|
+
render() {
|
|
198
|
+
return html`
|
|
199
|
+
<div class="task-card" part="container">
|
|
200
|
+
<div class="task-header" part="header">
|
|
201
|
+
<span class="title">${this.heading}</span>
|
|
202
|
+
<span class="counter">${() => `${this.progress.value.completed} / ${this.progress.value.total} completed`}</span>
|
|
203
|
+
</div>
|
|
204
|
+
<ul class="rows" role="list" part="list">
|
|
205
|
+
${() => {
|
|
206
|
+
const list = Array.isArray(this.tasks.value) ? this.tasks.value : [];
|
|
207
|
+
return list.map((t) => {
|
|
208
|
+
const st = t.status || 'pending';
|
|
209
|
+
const glyph = st === 'completed' ? '✓' : st === 'error' ? '✕' : st === 'running' ? '●' : '○';
|
|
210
|
+
return html`
|
|
211
|
+
<li class=${`row is-${st}`}>
|
|
212
|
+
<span class=${`status-icon status-${st}`} aria-label=${st}>${glyph}</span>
|
|
213
|
+
<div class="row-main">
|
|
214
|
+
<div class="row-label">${t.label || t.id}</div>
|
|
215
|
+
${t.detail ? html`<div class="row-detail">${t.detail}</div>` : ''}
|
|
216
|
+
</div>
|
|
217
|
+
${t.duration ? html`<span class="duration">${t.duration}</span>` : ''}
|
|
218
|
+
</li>
|
|
219
|
+
`;
|
|
220
|
+
});
|
|
221
|
+
}}
|
|
222
|
+
</ul>
|
|
223
|
+
</div>
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-task-list')) {
|
|
229
|
+
customElements.define('el-task-list', ElTaskList);
|
|
230
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-textarea>
|
|
3
|
+
* Accessible auto-resizing multi-line text input inspired by shadcn/ui.
|
|
4
|
+
* Implements Form Associated Custom Element (FACE), auto-resize, character count limit,
|
|
5
|
+
* clear on form reset, and full accessibility.
|
|
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 ElTextarea extends Elementum {
|
|
13
|
+
static formAssociated = true;
|
|
14
|
+
static observedAttributes = ['value', 'placeholder', 'disabled', 'required', 'rows', 'maxlength', 'auto-resize', 'name'];
|
|
15
|
+
|
|
16
|
+
value = signal('');
|
|
17
|
+
placeholder = signal('');
|
|
18
|
+
disabled = signal(false);
|
|
19
|
+
required = signal(false);
|
|
20
|
+
rows = signal(3);
|
|
21
|
+
maxlength = signal(null);
|
|
22
|
+
autoResize = signal(false);
|
|
23
|
+
|
|
24
|
+
static styles = css`
|
|
25
|
+
:host {
|
|
26
|
+
display: block;
|
|
27
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
width: 100%;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.wrapper {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
position: relative;
|
|
36
|
+
width: 100%;
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
textarea {
|
|
41
|
+
width: 100%;
|
|
42
|
+
min-height: 80px;
|
|
43
|
+
padding: 10px 14px;
|
|
44
|
+
font-family: inherit;
|
|
45
|
+
font-size: 0.875rem;
|
|
46
|
+
line-height: 1.5;
|
|
47
|
+
color: var(--el-text-primary, #0f172a);
|
|
48
|
+
background: var(--el-surface-base, #ffffff);
|
|
49
|
+
border: 1px solid var(--el-surface-border, #cbd5e1);
|
|
50
|
+
border-radius: var(--el-radius-md, 8px);
|
|
51
|
+
box-sizing: border-box;
|
|
52
|
+
outline: none;
|
|
53
|
+
resize: vertical;
|
|
54
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:host([auto-resize]) textarea {
|
|
58
|
+
resize: none;
|
|
59
|
+
overflow-y: hidden;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
textarea:focus {
|
|
63
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
64
|
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:root[data-theme="dark"] textarea {
|
|
68
|
+
background: #1e293b;
|
|
69
|
+
border-color: #334155;
|
|
70
|
+
color: #f8fafc;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
:root[data-theme="dark"] textarea:focus {
|
|
74
|
+
border-color: #3b82f6;
|
|
75
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:host([disabled]) textarea {
|
|
79
|
+
opacity: 0.6;
|
|
80
|
+
cursor: not-allowed;
|
|
81
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.footer {
|
|
85
|
+
display: flex;
|
|
86
|
+
justify-content: flex-end;
|
|
87
|
+
align-items: center;
|
|
88
|
+
margin-top: 4px;
|
|
89
|
+
font-size: 0.75rem;
|
|
90
|
+
color: var(--el-text-muted, #94a3b8);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@media (pointer: coarse) {
|
|
94
|
+
textarea {
|
|
95
|
+
font-size: max(16px, 1em);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
connected() {
|
|
101
|
+
this.#syncAttrs();
|
|
102
|
+
this.setFormValue(this.value.value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
attributeChanged(name, oldValue, newValue) {
|
|
106
|
+
this.#syncAttrs();
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#syncAttrs() {
|
|
111
|
+
if (this.hasAttribute('value') && this.getAttribute('value') !== this.value.value) {
|
|
112
|
+
this.value.value = this.getAttribute('value') || '';
|
|
113
|
+
}
|
|
114
|
+
this.placeholder.value = this.getAttribute('placeholder') || '';
|
|
115
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
116
|
+
this.required.value = this.hasAttribute('required');
|
|
117
|
+
this.rows.value = parseInt(this.getAttribute('rows') || '3', 10);
|
|
118
|
+
this.maxlength.value = this.hasAttribute('maxlength') ? parseInt(this.getAttribute('maxlength'), 10) : null;
|
|
119
|
+
this.autoResize.value = this.hasAttribute('auto-resize');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
formReset() {
|
|
123
|
+
this.value.value = this.getAttribute('value') || '';
|
|
124
|
+
this.setFormValue(this.value.value);
|
|
125
|
+
const textarea = this.shadowRoot?.querySelector('textarea');
|
|
126
|
+
if (textarea) textarea.value = this.value.value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#onInput = (e) => {
|
|
130
|
+
const val = e.target.value;
|
|
131
|
+
this.value.value = val;
|
|
132
|
+
this.setFormValue(val);
|
|
133
|
+
this.emit('input', { value: val });
|
|
134
|
+
|
|
135
|
+
if (this.autoResize.value) {
|
|
136
|
+
e.target.style.height = 'auto';
|
|
137
|
+
e.target.style.height = `${e.target.scrollHeight}px`;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
#onChange = (e) => {
|
|
142
|
+
this.emit('change', { value: this.value.value });
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
render() {
|
|
146
|
+
return html`
|
|
147
|
+
<div class="wrapper" part="wrapper">
|
|
148
|
+
<textarea
|
|
149
|
+
part="textarea"
|
|
150
|
+
rows=${() => this.rows.value}
|
|
151
|
+
placeholder=${() => this.placeholder.value}
|
|
152
|
+
?disabled=${() => this.disabled.value}
|
|
153
|
+
?required=${() => this.required.value}
|
|
154
|
+
maxlength=${() => (this.maxlength.value !== null ? this.maxlength.value : false)}
|
|
155
|
+
.value=${() => this.value.value}
|
|
156
|
+
oninput=${this.#onInput}
|
|
157
|
+
onchange=${this.#onChange}
|
|
158
|
+
></textarea>
|
|
159
|
+
${() =>
|
|
160
|
+
this.maxlength.value !== null
|
|
161
|
+
? html`
|
|
162
|
+
<div class="footer" part="footer">
|
|
163
|
+
<span class="count">${() => `${this.value.value.length} / ${this.maxlength.value}`}</span>
|
|
164
|
+
</div>
|
|
165
|
+
`
|
|
166
|
+
: ''
|
|
167
|
+
}
|
|
168
|
+
</div>
|
|
169
|
+
`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-textarea')) {
|
|
174
|
+
customElements.define('el-textarea', ElTextarea);
|
|
175
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-theme-switch>
|
|
3
|
+
* Interactive toggle for switching between Light and Dark design system themes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Elementum } from '../elementum.js';
|
|
7
|
+
import { html, css } from '../template.js';
|
|
8
|
+
import { signal } from '../signal.js';
|
|
9
|
+
|
|
10
|
+
export class ElThemeSwitch extends Elementum {
|
|
11
|
+
static observedAttributes = ['theme'];
|
|
12
|
+
|
|
13
|
+
theme = signal('light'); // 'light' | 'dark' | 'system'
|
|
14
|
+
|
|
15
|
+
static styles = css`
|
|
16
|
+
:host {
|
|
17
|
+
display: inline-block;
|
|
18
|
+
user-select: none;
|
|
19
|
+
font-family: inherit;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
button {
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
gap: var(--el-spacing-xs, 4px);
|
|
26
|
+
padding: 6px 12px;
|
|
27
|
+
font-size: 0.8125rem;
|
|
28
|
+
font-weight: 500;
|
|
29
|
+
color: var(--el-text-primary, #0f172a);
|
|
30
|
+
background: var(--el-surface-muted, #f3f4f6);
|
|
31
|
+
border: 1px solid var(--el-surface-border, #e5e7eb);
|
|
32
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
|
|
35
|
+
outline: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
button:hover {
|
|
39
|
+
background: var(--el-step-4, var(--el-surface-border, #e2e8f0));
|
|
40
|
+
color: var(--el-text-primary, #0f172a);
|
|
41
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
button:focus-visible {
|
|
45
|
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.icon {
|
|
49
|
+
font-size: 1rem;
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
connected() {
|
|
54
|
+
if (this.hasAttribute('theme')) {
|
|
55
|
+
this.#applyThemeValue(this.getAttribute('theme'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Detect existing or saved theme
|
|
60
|
+
if (typeof window !== 'undefined') {
|
|
61
|
+
const saved = localStorage.getItem('elementum-theme');
|
|
62
|
+
if (saved === 'dark' || saved === 'light') {
|
|
63
|
+
this.setTheme(saved);
|
|
64
|
+
} else if (window.matchMedia?.('(prefers-color-scheme: dark)').matches) {
|
|
65
|
+
this.setTheme('dark');
|
|
66
|
+
} else {
|
|
67
|
+
this.setTheme('light');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
attributeChanged(name, oldValue, newValue) {
|
|
73
|
+
if (name === 'theme') {
|
|
74
|
+
this.#applyThemeValue(newValue);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#applyThemeValue(val) {
|
|
79
|
+
if (val === 'dark' || val === 'light') {
|
|
80
|
+
this.setTheme(val);
|
|
81
|
+
} else if (val === 'system') {
|
|
82
|
+
const isDark = typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches;
|
|
83
|
+
this.setTheme(isDark ? 'dark' : 'light');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setTheme(theme) {
|
|
88
|
+
this.theme.value = theme;
|
|
89
|
+
if (typeof document !== 'undefined') {
|
|
90
|
+
document.documentElement.setAttribute('data-theme', theme);
|
|
91
|
+
}
|
|
92
|
+
if (typeof localStorage !== 'undefined') {
|
|
93
|
+
localStorage.setItem('elementum-theme', theme);
|
|
94
|
+
}
|
|
95
|
+
this.emit('themechange', { theme });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
toggle = () => {
|
|
99
|
+
const next = this.theme.value === 'dark' ? 'light' : 'dark';
|
|
100
|
+
this.setTheme(next);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
render() {
|
|
104
|
+
return html`
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
part="button"
|
|
108
|
+
@click=${this.toggle}
|
|
109
|
+
aria-label=${() => `${this.theme.value === 'dark' ? 'Dark' : 'Light'} — toggle color theme`}
|
|
110
|
+
>
|
|
111
|
+
<span class="icon" aria-hidden="true">${() => (this.theme.value === 'dark' ? '🌙' : '☀️')}</span>
|
|
112
|
+
<span>${() => (this.theme.value === 'dark' ? 'Dark' : 'Light')}</span>
|
|
113
|
+
</button>
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-theme-switch')) {
|
|
119
|
+
customElements.define('el-theme-switch', ElThemeSwitch);
|
|
120
|
+
}
|