@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,360 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <el-radio-card>
|
|
7
|
+
* Rich selection card primitive inspired by Radix Themes.
|
|
8
|
+
* Supports title, description, badge/meta, and radio indicator.
|
|
9
|
+
*/
|
|
10
|
+
export class ElRadioCard extends Elementum {
|
|
11
|
+
static formAssociated = true;
|
|
12
|
+
static observedAttributes = ['value', 'checked', 'disabled'];
|
|
13
|
+
|
|
14
|
+
value = signal('');
|
|
15
|
+
checked = signal(false);
|
|
16
|
+
disabled = signal(false);
|
|
17
|
+
|
|
18
|
+
static styles = css`
|
|
19
|
+
:host {
|
|
20
|
+
display: block;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
user-select: none;
|
|
23
|
+
font-family: inherit;
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
outline: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:host([disabled]) {
|
|
29
|
+
cursor: not-allowed;
|
|
30
|
+
opacity: 0.6;
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.card {
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: flex-start;
|
|
37
|
+
gap: 14px;
|
|
38
|
+
padding: 16px;
|
|
39
|
+
border-radius: var(--el-radius-lg, 12px);
|
|
40
|
+
border: 2px solid var(--el-surface-border, #e2e8f0);
|
|
41
|
+
background-color: var(--el-surface-card, #ffffff);
|
|
42
|
+
transition: background-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
43
|
+
position: relative;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
:host-context([data-theme="dark"]) .card {
|
|
47
|
+
background-color: #111827;
|
|
48
|
+
border-color: #334155;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:host(:hover:not([disabled])) .card {
|
|
52
|
+
border-color: var(--el-primary-subtle, #93c5fd);
|
|
53
|
+
background-color: var(--el-surface-muted, #f8fafc);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:host-context([data-theme="dark"]):host(:hover:not([disabled])) .card {
|
|
57
|
+
background-color: #1e293b;
|
|
58
|
+
border-color: #475569;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:host([checked]) .card {
|
|
62
|
+
border-color: var(--el-primary, #2563eb);
|
|
63
|
+
background-color: rgba(37, 99, 235, 0.04);
|
|
64
|
+
box-shadow: 0 0 0 1px var(--el-primary, #2563eb);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:host-context([data-theme="dark"]):host([checked]) .card {
|
|
68
|
+
border-color: #3b82f6;
|
|
69
|
+
background-color: rgba(59, 130, 246, 0.1);
|
|
70
|
+
box-shadow: 0 0 0 1px #3b82f6;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
:host(:focus-visible) .card {
|
|
74
|
+
outline: 2px solid var(--el-primary, #2563eb);
|
|
75
|
+
outline-offset: 2px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.radio-circle {
|
|
79
|
+
width: 18px;
|
|
80
|
+
height: 18px;
|
|
81
|
+
border-radius: 50%;
|
|
82
|
+
border: 2px solid var(--el-surface-border, #cbd5e1);
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
flex-shrink: 0;
|
|
87
|
+
margin-top: 2px;
|
|
88
|
+
transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:host([checked]) .radio-circle {
|
|
92
|
+
border-color: var(--el-primary, #2563eb);
|
|
93
|
+
background-color: var(--el-primary, #2563eb);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
:host-context([data-theme="dark"]) .radio-circle {
|
|
97
|
+
border-color: #475569;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
:host-context([data-theme="dark"]):host([checked]) .radio-circle {
|
|
101
|
+
border-color: #3b82f6;
|
|
102
|
+
background-color: #3b82f6;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.dot {
|
|
106
|
+
width: 6px;
|
|
107
|
+
height: 6px;
|
|
108
|
+
border-radius: 50%;
|
|
109
|
+
background-color: #ffffff;
|
|
110
|
+
opacity: 0;
|
|
111
|
+
transform: scale(0.4);
|
|
112
|
+
transition: background-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:host([checked]) .dot {
|
|
116
|
+
opacity: 1;
|
|
117
|
+
transform: scale(1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.content {
|
|
121
|
+
flex: 1;
|
|
122
|
+
min-width: 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
::slotted([slot="title"]) {
|
|
126
|
+
font-weight: 600;
|
|
127
|
+
font-size: var(--el-text-base, 1rem);
|
|
128
|
+
color: var(--el-text-primary, #0f172a);
|
|
129
|
+
margin-bottom: 4px;
|
|
130
|
+
display: block;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
:host-context([data-theme="dark"]) ::slotted([slot="title"]) {
|
|
134
|
+
color: #f8fafc;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
::slotted([slot="description"]) {
|
|
138
|
+
font-size: var(--el-text-sm, 0.875rem);
|
|
139
|
+
color: var(--el-text-muted, #64748b);
|
|
140
|
+
line-height: 1.4;
|
|
141
|
+
display: block;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
:host-context([data-theme="dark"]) ::slotted([slot="description"]) {
|
|
145
|
+
color: #94a3b8;
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
connected() {
|
|
150
|
+
this.value.value = this.getAttribute('value') || '';
|
|
151
|
+
this.checked.value = this.hasAttribute('checked');
|
|
152
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
153
|
+
|
|
154
|
+
if (!this.hasAttribute('tabindex') && !this.disabled.value) {
|
|
155
|
+
this.setAttribute('tabindex', this.checked.value ? '0' : '-1');
|
|
156
|
+
}
|
|
157
|
+
this.setAttribute('role', 'radio');
|
|
158
|
+
this.setAttribute('aria-checked', this.checked.value ? 'true' : 'false');
|
|
159
|
+
|
|
160
|
+
this.addEventListener('click', this.#onClick);
|
|
161
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
disconnected() {
|
|
165
|
+
this.removeEventListener('click', this.#onClick);
|
|
166
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
attributeChanged(name, oldValue, newValue) {
|
|
170
|
+
if (name === 'value') this.value.value = newValue || '';
|
|
171
|
+
if (name === 'checked') {
|
|
172
|
+
const isChecked = newValue !== null;
|
|
173
|
+
this.checked.value = isChecked;
|
|
174
|
+
this.setAttribute('aria-checked', isChecked ? 'true' : 'false');
|
|
175
|
+
this.setAttribute('tabindex', isChecked ? '0' : '-1');
|
|
176
|
+
}
|
|
177
|
+
if (name === 'disabled') {
|
|
178
|
+
this.disabled.value = newValue !== null;
|
|
179
|
+
if (this.disabled.value) {
|
|
180
|
+
this.setAttribute('aria-disabled', 'true');
|
|
181
|
+
this.removeAttribute('tabindex');
|
|
182
|
+
} else {
|
|
183
|
+
this.removeAttribute('aria-disabled');
|
|
184
|
+
this.setAttribute('tabindex', this.checked.value ? '0' : '-1');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#onClick = () => {
|
|
190
|
+
if (this.disabled.value) return;
|
|
191
|
+
this.select();
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
#onKeyDown = (e) => {
|
|
195
|
+
if (this.disabled.value) return;
|
|
196
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
this.select();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
select() {
|
|
203
|
+
const parentGroup = this.closest('el-radio-card-group');
|
|
204
|
+
if (parentGroup) {
|
|
205
|
+
parentGroup.setValue(this.value.value);
|
|
206
|
+
} else {
|
|
207
|
+
this.setAttribute('checked', '');
|
|
208
|
+
this.checked.value = true;
|
|
209
|
+
}
|
|
210
|
+
this.emit('change', { value: this.value.value });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
render() {
|
|
214
|
+
return html`
|
|
215
|
+
<div class="card">
|
|
216
|
+
<div class="radio-circle">
|
|
217
|
+
<div class="dot"></div>
|
|
218
|
+
</div>
|
|
219
|
+
<div class="content">
|
|
220
|
+
<slot name="title"></slot>
|
|
221
|
+
<slot name="description"></slot>
|
|
222
|
+
<slot></slot>
|
|
223
|
+
</div>
|
|
224
|
+
<slot name="extra"></slot>
|
|
225
|
+
</div>
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* <el-radio-card-group>
|
|
232
|
+
* Container for <el-radio-card> providing keyboard navigation and value coordination.
|
|
233
|
+
*/
|
|
234
|
+
export class ElRadioCardGroup extends Elementum {
|
|
235
|
+
static formAssociated = true;
|
|
236
|
+
static observedAttributes = ['name', 'value', 'columns'];
|
|
237
|
+
|
|
238
|
+
name = signal('');
|
|
239
|
+
value = signal('');
|
|
240
|
+
columns = signal('1');
|
|
241
|
+
|
|
242
|
+
static styles = css`
|
|
243
|
+
:host {
|
|
244
|
+
display: grid;
|
|
245
|
+
gap: 12px;
|
|
246
|
+
width: 100%;
|
|
247
|
+
box-sizing: border-box;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
:host([columns="2"]) {
|
|
251
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
:host([columns="3"]) {
|
|
255
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@media (max-width: 640px) {
|
|
259
|
+
:host([columns="2"]), :host([columns="3"]) {
|
|
260
|
+
grid-template-columns: 1fr;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
`;
|
|
264
|
+
|
|
265
|
+
connected() {
|
|
266
|
+
this.name.value = this.getAttribute('name') || '';
|
|
267
|
+
this.value.value = this.getAttribute('value') || '';
|
|
268
|
+
this.columns.value = this.getAttribute('columns') || '1';
|
|
269
|
+
|
|
270
|
+
this.setAttribute('role', 'radiogroup');
|
|
271
|
+
this.#syncChildren();
|
|
272
|
+
if (typeof queueMicrotask !== 'undefined') {
|
|
273
|
+
queueMicrotask(() => this.#syncChildren());
|
|
274
|
+
}
|
|
275
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
disconnected() {
|
|
279
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
attributeChanged(name, oldValue, newValue) {
|
|
283
|
+
if (name === 'value') {
|
|
284
|
+
this.value.value = newValue || '';
|
|
285
|
+
this.#syncChildren();
|
|
286
|
+
}
|
|
287
|
+
if (name === 'columns') this.columns.value = newValue || '1';
|
|
288
|
+
if (name === 'name') this.name.value = newValue || '';
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
#syncChildren() {
|
|
292
|
+
const cards = this.querySelectorAll('el-radio-card');
|
|
293
|
+
let hasChecked = false;
|
|
294
|
+
cards.forEach((card) => {
|
|
295
|
+
const isMatch = card.getAttribute('value') === this.value.value;
|
|
296
|
+
if (isMatch && !hasChecked) {
|
|
297
|
+
card.setAttribute('checked', '');
|
|
298
|
+
if (card.checked && typeof card.checked === 'object' && 'value' in card.checked) {
|
|
299
|
+
card.checked.value = true;
|
|
300
|
+
}
|
|
301
|
+
card.setAttribute('tabindex', '0');
|
|
302
|
+
hasChecked = true;
|
|
303
|
+
} else {
|
|
304
|
+
card.removeAttribute('checked');
|
|
305
|
+
if (card.checked && typeof card.checked === 'object' && 'value' in card.checked) {
|
|
306
|
+
card.checked.value = false;
|
|
307
|
+
}
|
|
308
|
+
card.setAttribute('tabindex', '-1');
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
if (!hasChecked && cards.length > 0) {
|
|
313
|
+
cards[0].setAttribute('tabindex', '0');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
this.setFormValue(this.value.value);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
setValue(val) {
|
|
320
|
+
this.value.value = val;
|
|
321
|
+
this.setAttribute('value', val);
|
|
322
|
+
this.#syncChildren();
|
|
323
|
+
this.emit('change', { value: val });
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#onKeyDown = (e) => {
|
|
327
|
+
const cards = Array.from(this.querySelectorAll('el-radio-card:not([disabled])'));
|
|
328
|
+
if (cards.length === 0) return;
|
|
329
|
+
|
|
330
|
+
const currentIndex = cards.findIndex((c) => c.getAttribute('value') === this.value.value);
|
|
331
|
+
let nextIndex = -1;
|
|
332
|
+
|
|
333
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowRight') {
|
|
334
|
+
e.preventDefault();
|
|
335
|
+
nextIndex = currentIndex < cards.length - 1 ? currentIndex + 1 : 0;
|
|
336
|
+
} else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') {
|
|
337
|
+
e.preventDefault();
|
|
338
|
+
nextIndex = currentIndex > 0 ? currentIndex - 1 : cards.length - 1;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (nextIndex >= 0) {
|
|
342
|
+
cards[nextIndex].focus();
|
|
343
|
+
cards[nextIndex].select();
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
formReset() {
|
|
348
|
+
const initial = this.getAttribute('value') || '';
|
|
349
|
+
this.setValue(initial);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
render() {
|
|
353
|
+
return html`<slot></slot>`;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (typeof customElements !== 'undefined') {
|
|
358
|
+
if (!customElements.get('el-radio-card')) customElements.define('el-radio-card', ElRadioCard);
|
|
359
|
+
if (!customElements.get('el-radio-card-group')) customElements.define('el-radio-card-group', ElRadioCardGroup);
|
|
360
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-radio> & <el-radio-group>
|
|
3
|
+
* Accessible, zero-dependency radio primitives inspired by Base UI.
|
|
4
|
+
* Features roving tabindex, arrow key navigation, form integration, and clean state attributes.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Elementum } from '../elementum.js';
|
|
8
|
+
import { html, css } from '../template.js';
|
|
9
|
+
import { signal } from '../signal.js';
|
|
10
|
+
|
|
11
|
+
export class ElRadio extends Elementum {
|
|
12
|
+
static observedAttributes = ['value', 'disabled', 'checked', 'label'];
|
|
13
|
+
|
|
14
|
+
value = signal('');
|
|
15
|
+
disabled = signal(false);
|
|
16
|
+
checked = signal(false);
|
|
17
|
+
label = signal('');
|
|
18
|
+
|
|
19
|
+
static styles = css`
|
|
20
|
+
:host {
|
|
21
|
+
display: inline-flex;
|
|
22
|
+
align-items: center;
|
|
23
|
+
gap: 8px;
|
|
24
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
25
|
+
font-size: 14px;
|
|
26
|
+
color: var(--el-text-primary, #0f172a);
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
user-select: none;
|
|
29
|
+
outline: none;
|
|
30
|
+
line-height: 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:host([disabled]) {
|
|
34
|
+
cursor: not-allowed;
|
|
35
|
+
opacity: 0.5;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.circle {
|
|
39
|
+
width: 18px;
|
|
40
|
+
height: 18px;
|
|
41
|
+
border-radius: 50%;
|
|
42
|
+
background: var(--el-surface-base, #ffffff);
|
|
43
|
+
border: 1px solid var(--el-surface-border, #cbd5e1);
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
|
|
48
|
+
box-sizing: border-box;
|
|
49
|
+
flex-shrink: 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
:host(:hover:not([disabled])) .circle {
|
|
53
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:host(:focus-visible) .circle {
|
|
57
|
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
|
|
58
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.circle.checked {
|
|
62
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.dot {
|
|
66
|
+
width: 8px;
|
|
67
|
+
height: 8px;
|
|
68
|
+
border-radius: 50%;
|
|
69
|
+
background: var(--el-color-primary, #2563eb);
|
|
70
|
+
transform: scale(0);
|
|
71
|
+
transition: transform 120ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.circle.checked .dot {
|
|
75
|
+
transform: scale(1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:root[data-theme="dark"] .circle {
|
|
79
|
+
background: var(--el-surface-card, #111827);
|
|
80
|
+
border-color: #475569;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:root[data-theme="dark"] .circle.checked {
|
|
84
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
connected() {
|
|
89
|
+
if (this.hasAttribute('value')) this.value.value = this.getAttribute('value');
|
|
90
|
+
if (this.hasAttribute('label')) this.label.value = this.getAttribute('label');
|
|
91
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
92
|
+
this.checked.value = this.hasAttribute('checked');
|
|
93
|
+
this.setAttribute('role', 'radio');
|
|
94
|
+
this.tabIndex = this.checked.value ? 0 : -1;
|
|
95
|
+
this.setAttribute('aria-checked', this.checked.value ? 'true' : 'false');
|
|
96
|
+
|
|
97
|
+
this.addEventListener('click', () => {
|
|
98
|
+
if (this.disabled.value) return;
|
|
99
|
+
this.select();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
attributeChanged(name, oldValue, newValue) {
|
|
104
|
+
if (name === 'value') this.value.value = newValue || '';
|
|
105
|
+
else if (name === 'label') this.label.value = newValue || '';
|
|
106
|
+
else if (name === 'disabled') this.disabled.value = newValue !== null && newValue !== 'false';
|
|
107
|
+
else if (name === 'checked') {
|
|
108
|
+
this.checked.value = newValue !== null && newValue !== 'false';
|
|
109
|
+
this.tabIndex = this.checked.value ? 0 : -1;
|
|
110
|
+
this.setAttribute('aria-checked', this.checked.value ? 'true' : 'false');
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
select() {
|
|
116
|
+
const group = this.closest('el-radio-group');
|
|
117
|
+
if (group && typeof group.selectValue === 'function') {
|
|
118
|
+
group.selectValue(this.value.value);
|
|
119
|
+
} else {
|
|
120
|
+
this.checked.value = true;
|
|
121
|
+
this.tabIndex = 0;
|
|
122
|
+
this.setAttribute('aria-checked', 'true');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
render() {
|
|
127
|
+
return html`
|
|
128
|
+
<div class=${() => `circle ${this.checked.value ? 'checked' : ''}`} part="circle">
|
|
129
|
+
<div class="dot" part="dot"></div>
|
|
130
|
+
</div>
|
|
131
|
+
<slot>${() => this.label.value || ''}</slot>
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export class ElRadioGroup extends Elementum {
|
|
137
|
+
static formAssociated = true;
|
|
138
|
+
static observedAttributes = ['value', 'name', 'disabled', 'required', 'orientation'];
|
|
139
|
+
|
|
140
|
+
value = signal('');
|
|
141
|
+
disabled = signal(false);
|
|
142
|
+
required = signal(false);
|
|
143
|
+
orientation = signal('vertical');
|
|
144
|
+
|
|
145
|
+
static styles = css`
|
|
146
|
+
:host {
|
|
147
|
+
display: inline-flex;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
gap: 10px;
|
|
150
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
151
|
+
box-sizing: border-box;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
:host([orientation="horizontal"]) {
|
|
155
|
+
flex-direction: row;
|
|
156
|
+
gap: 16px;
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
connected() {
|
|
161
|
+
if (this.hasAttribute('value')) this.value.value = this.getAttribute('value');
|
|
162
|
+
if (this.hasAttribute('orientation')) this.orientation.value = this.getAttribute('orientation');
|
|
163
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
164
|
+
this.required.value = this.hasAttribute('required');
|
|
165
|
+
this.setAttribute('role', 'radiogroup');
|
|
166
|
+
this.setAttribute('aria-required', String(this.required.value));
|
|
167
|
+
this.setFormValue(this.value.value);
|
|
168
|
+
|
|
169
|
+
this.#syncChildren();
|
|
170
|
+
if (typeof queueMicrotask !== 'undefined') {
|
|
171
|
+
queueMicrotask(() => this.#syncChildren());
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
attributeChanged(name, oldValue, newValue) {
|
|
178
|
+
if (name === 'value') {
|
|
179
|
+
this.value.value = newValue || '';
|
|
180
|
+
this.#syncChildren();
|
|
181
|
+
this.setFormValue(this.value.value);
|
|
182
|
+
} else if (name === 'orientation') {
|
|
183
|
+
this.orientation.value = newValue === 'horizontal' ? 'horizontal' : 'vertical';
|
|
184
|
+
} else if (name === 'disabled') {
|
|
185
|
+
this.disabled.value = newValue !== null && newValue !== 'false';
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#syncChildren() {
|
|
191
|
+
const radios = Array.from(this.querySelectorAll('el-radio'));
|
|
192
|
+
const val = this.value.value;
|
|
193
|
+
let hasChecked = false;
|
|
194
|
+
|
|
195
|
+
radios.forEach((r) => {
|
|
196
|
+
const match = r.getAttribute('value') === val;
|
|
197
|
+
if (match) {
|
|
198
|
+
r.setAttribute('checked', '');
|
|
199
|
+
} else {
|
|
200
|
+
r.removeAttribute('checked');
|
|
201
|
+
}
|
|
202
|
+
if (r.checked && typeof r.checked === 'object' && 'value' in r.checked) {
|
|
203
|
+
r.checked.value = match;
|
|
204
|
+
}
|
|
205
|
+
r.tabIndex = match ? 0 : -1;
|
|
206
|
+
r.setAttribute('aria-checked', match ? 'true' : 'false');
|
|
207
|
+
if (match) hasChecked = true;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (!hasChecked && radios.length > 0) {
|
|
211
|
+
radios[0].tabIndex = 0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
selectValue(val) {
|
|
216
|
+
if (this.disabled.value) return;
|
|
217
|
+
this.value.value = val;
|
|
218
|
+
this.#syncChildren();
|
|
219
|
+
this.setFormValue(val);
|
|
220
|
+
this.emit('change', { value: val });
|
|
221
|
+
this.emit('input', { value: val });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#onKeyDown = (e) => {
|
|
225
|
+
if (this.disabled.value) return;
|
|
226
|
+
const radios = Array.from(this.querySelectorAll('el-radio:not([disabled])'));
|
|
227
|
+
if (!radios.length) return;
|
|
228
|
+
|
|
229
|
+
const currentIdx = radios.findIndex((r) => r.checked.value);
|
|
230
|
+
let nextIdx = currentIdx;
|
|
231
|
+
|
|
232
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowRight') {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
nextIdx = currentIdx < radios.length - 1 ? currentIdx + 1 : 0;
|
|
235
|
+
} else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') {
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
nextIdx = currentIdx > 0 ? currentIdx - 1 : radios.length - 1;
|
|
238
|
+
} else {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const nextRadio = radios[nextIdx];
|
|
243
|
+
if (nextRadio) {
|
|
244
|
+
this.selectValue(nextRadio.getAttribute('value') || '');
|
|
245
|
+
nextRadio.focus();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
render() {
|
|
250
|
+
return html`<slot></slot>`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (typeof customElements !== 'undefined') {
|
|
255
|
+
if (!customElements.get('el-radio')) customElements.define('el-radio', ElRadio);
|
|
256
|
+
if (!customElements.get('el-radio-group')) customElements.define('el-radio-group', ElRadioGroup);
|
|
257
|
+
}
|