@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,221 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <el-checkbox-card>
|
|
7
|
+
* Rich multi-selection card primitive inspired by Radix Themes.
|
|
8
|
+
* Supports title, description, badge/meta, and checkbox checkmark indicator.
|
|
9
|
+
*/
|
|
10
|
+
export class ElCheckboxCard 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
|
+
.checkbox-box {
|
|
79
|
+
width: 18px;
|
|
80
|
+
height: 18px;
|
|
81
|
+
border-radius: var(--el-radius-sm, 4px);
|
|
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
|
+
color: #ffffff;
|
|
89
|
+
font-size: 11px;
|
|
90
|
+
font-weight: 700;
|
|
91
|
+
transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
:host([checked]) .checkbox-box {
|
|
95
|
+
border-color: var(--el-primary, #2563eb);
|
|
96
|
+
background-color: var(--el-primary, #2563eb);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
:host-context([data-theme="dark"]) .checkbox-box {
|
|
100
|
+
border-color: #475569;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
:host-context([data-theme="dark"]):host([checked]) .checkbox-box {
|
|
104
|
+
border-color: #3b82f6;
|
|
105
|
+
background-color: #3b82f6;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.content {
|
|
109
|
+
flex: 1;
|
|
110
|
+
min-width: 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
::slotted([slot="title"]) {
|
|
114
|
+
font-weight: 600;
|
|
115
|
+
font-size: var(--el-text-base, 1rem);
|
|
116
|
+
color: var(--el-text-primary, #0f172a);
|
|
117
|
+
margin-bottom: 4px;
|
|
118
|
+
display: block;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
:host-context([data-theme="dark"]) ::slotted([slot="title"]) {
|
|
122
|
+
color: #f8fafc;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
::slotted([slot="description"]) {
|
|
126
|
+
font-size: var(--el-text-sm, 0.875rem);
|
|
127
|
+
color: var(--el-text-muted, #64748b);
|
|
128
|
+
line-height: 1.4;
|
|
129
|
+
display: block;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
:host-context([data-theme="dark"]) ::slotted([slot="description"]) {
|
|
133
|
+
color: #94a3b8;
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
connected() {
|
|
138
|
+
this.value.value = this.getAttribute('value') || '';
|
|
139
|
+
this.checked.value = this.hasAttribute('checked');
|
|
140
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
141
|
+
|
|
142
|
+
if (!this.hasAttribute('tabindex') && !this.disabled.value) {
|
|
143
|
+
this.setAttribute('tabindex', '0');
|
|
144
|
+
}
|
|
145
|
+
this.setAttribute('role', 'checkbox');
|
|
146
|
+
this.setAttribute('aria-checked', this.checked.value ? 'true' : 'false');
|
|
147
|
+
|
|
148
|
+
this.addEventListener('click', this.#onClick);
|
|
149
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
disconnected() {
|
|
153
|
+
this.removeEventListener('click', this.#onClick);
|
|
154
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
attributeChanged(name, oldValue, newValue) {
|
|
158
|
+
if (name === 'value') this.value.value = newValue || '';
|
|
159
|
+
if (name === 'checked') {
|
|
160
|
+
const isChecked = newValue !== null;
|
|
161
|
+
this.checked.value = isChecked;
|
|
162
|
+
this.setAttribute('aria-checked', isChecked ? 'true' : 'false');
|
|
163
|
+
this.setFormValue(isChecked ? this.value.value || 'on' : null);
|
|
164
|
+
}
|
|
165
|
+
if (name === 'disabled') {
|
|
166
|
+
this.disabled.value = newValue !== null;
|
|
167
|
+
if (this.disabled.value) {
|
|
168
|
+
this.setAttribute('aria-disabled', 'true');
|
|
169
|
+
this.removeAttribute('tabindex');
|
|
170
|
+
} else {
|
|
171
|
+
this.removeAttribute('aria-disabled');
|
|
172
|
+
this.setAttribute('tabindex', '0');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
#onClick = () => {
|
|
178
|
+
if (this.disabled.value) return;
|
|
179
|
+
this.toggle();
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
#onKeyDown = (e) => {
|
|
183
|
+
if (this.disabled.value) return;
|
|
184
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
this.toggle();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
toggle() {
|
|
191
|
+
const next = !this.checked.value;
|
|
192
|
+
if (next) {
|
|
193
|
+
this.setAttribute('checked', '');
|
|
194
|
+
} else {
|
|
195
|
+
this.removeAttribute('checked');
|
|
196
|
+
}
|
|
197
|
+
this.checked.value = next;
|
|
198
|
+
this.setFormValue(next ? this.value.value || 'on' : null);
|
|
199
|
+
this.emit('change', { checked: next, value: this.value.value });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
render() {
|
|
203
|
+
return html`
|
|
204
|
+
<div class="card">
|
|
205
|
+
<div class="checkbox-box">
|
|
206
|
+
${() => (this.checked.value ? '✓' : '')}
|
|
207
|
+
</div>
|
|
208
|
+
<div class="content">
|
|
209
|
+
<slot name="title"></slot>
|
|
210
|
+
<slot name="description"></slot>
|
|
211
|
+
<slot></slot>
|
|
212
|
+
</div>
|
|
213
|
+
<slot name="extra"></slot>
|
|
214
|
+
</div>
|
|
215
|
+
`;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-checkbox-card')) {
|
|
220
|
+
customElements.define('el-checkbox-card', ElCheckboxCard);
|
|
221
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-checkbox>
|
|
3
|
+
* Accessible, zero-dependency tri-state checkbox primitive inspired by Base UI.
|
|
4
|
+
* Supports checked, unchecked, and indeterminate states, form association,
|
|
5
|
+
* keyboard controls, and native constraint validation.
|
|
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 ElCheckbox extends Elementum {
|
|
13
|
+
static formAssociated = true;
|
|
14
|
+
static observedAttributes = ['checked', 'indeterminate', 'disabled', 'required', 'name', 'value', 'label'];
|
|
15
|
+
|
|
16
|
+
checked = signal(false);
|
|
17
|
+
indeterminate = signal(false);
|
|
18
|
+
disabled = signal(false);
|
|
19
|
+
required = signal(false);
|
|
20
|
+
name = signal('');
|
|
21
|
+
value = signal('on');
|
|
22
|
+
label = signal('');
|
|
23
|
+
|
|
24
|
+
static styles = css`
|
|
25
|
+
:host {
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
gap: 8px;
|
|
29
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
color: var(--el-text-primary, #0f172a);
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
user-select: none;
|
|
34
|
+
outline: none;
|
|
35
|
+
line-height: 1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:host([disabled]) {
|
|
39
|
+
cursor: not-allowed;
|
|
40
|
+
opacity: 0.5;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.checkbox-box {
|
|
44
|
+
width: 18px;
|
|
45
|
+
height: 18px;
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
background: var(--el-surface-base, #ffffff);
|
|
50
|
+
border: 1px solid var(--el-surface-border, #cbd5e1);
|
|
51
|
+
border-radius: var(--el-radius-sm, 4px);
|
|
52
|
+
transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
flex-shrink: 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:host(:hover:not([disabled])) .checkbox-box {
|
|
58
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:host(:focus-visible) .checkbox-box {
|
|
62
|
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
|
|
63
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.checkbox-box.checked,
|
|
67
|
+
.checkbox-box.indeterminate {
|
|
68
|
+
background: var(--el-color-primary, #2563eb);
|
|
69
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
70
|
+
color: #ffffff;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.icon {
|
|
74
|
+
width: 12px;
|
|
75
|
+
height: 12px;
|
|
76
|
+
fill: none;
|
|
77
|
+
stroke: currentColor;
|
|
78
|
+
stroke-width: 2.5;
|
|
79
|
+
stroke-linecap: round;
|
|
80
|
+
stroke-linejoin: round;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:root[data-theme="dark"] .checkbox-box {
|
|
84
|
+
background: var(--el-surface-card, #111827);
|
|
85
|
+
border-color: #475569;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
:root[data-theme="dark"] .checkbox-box.checked,
|
|
89
|
+
:root[data-theme="dark"] .checkbox-box.indeterminate {
|
|
90
|
+
background: var(--el-color-primary, #2563eb);
|
|
91
|
+
border-color: var(--el-color-primary, #2563eb);
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
connected() {
|
|
96
|
+
this.#syncAttributes();
|
|
97
|
+
this.tabIndex = this.disabled.value ? -1 : 0;
|
|
98
|
+
this.setAttribute('role', 'checkbox');
|
|
99
|
+
this.#updateAria();
|
|
100
|
+
this.setFormValue(this.checked.value ? this.value.value : null);
|
|
101
|
+
|
|
102
|
+
this.addEventListener('click', this.#onClick);
|
|
103
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
attributeChanged(name, oldValue, newValue) {
|
|
107
|
+
if (name === 'checked') {
|
|
108
|
+
this.checked.value = newValue !== null && newValue !== 'false';
|
|
109
|
+
} else if (name === 'indeterminate') {
|
|
110
|
+
this.indeterminate.value = newValue !== null && newValue !== 'false';
|
|
111
|
+
} else if (name === 'disabled') {
|
|
112
|
+
this.disabled.value = newValue !== null && newValue !== 'false';
|
|
113
|
+
this.tabIndex = this.disabled.value ? -1 : 0;
|
|
114
|
+
} else if (name === 'required') {
|
|
115
|
+
this.required.value = newValue !== null && newValue !== 'false';
|
|
116
|
+
} else if (name === 'value') {
|
|
117
|
+
this.value.value = newValue || 'on';
|
|
118
|
+
} else if (name === 'label') {
|
|
119
|
+
this.label.value = newValue || '';
|
|
120
|
+
}
|
|
121
|
+
this.#updateAria();
|
|
122
|
+
this.setFormValue(this.checked.value ? this.value.value : null);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#syncAttributes() {
|
|
127
|
+
this.checked.value = this.hasAttribute('checked');
|
|
128
|
+
this.indeterminate.value = this.hasAttribute('indeterminate');
|
|
129
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
130
|
+
this.required.value = this.hasAttribute('required');
|
|
131
|
+
if (this.hasAttribute('value')) this.value.value = this.getAttribute('value');
|
|
132
|
+
if (this.hasAttribute('label')) this.label.value = this.getAttribute('label');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#updateAria() {
|
|
136
|
+
if (this.indeterminate.value) {
|
|
137
|
+
this.setAttribute('aria-checked', 'mixed');
|
|
138
|
+
} else {
|
|
139
|
+
this.setAttribute('aria-checked', this.checked.value ? 'true' : 'false');
|
|
140
|
+
}
|
|
141
|
+
this.setAttribute('aria-disabled', String(this.disabled.value));
|
|
142
|
+
this.setAttribute('aria-required', String(this.required.value));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#onClick = (e) => {
|
|
146
|
+
if (this.disabled.value) return;
|
|
147
|
+
this.toggle();
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
#onKeyDown = (e) => {
|
|
151
|
+
if (this.disabled.value) return;
|
|
152
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
this.toggle();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
toggle() {
|
|
159
|
+
if (this.disabled.value) return;
|
|
160
|
+
if (this.indeterminate.value) {
|
|
161
|
+
this.indeterminate.value = false;
|
|
162
|
+
this.checked.value = true;
|
|
163
|
+
} else {
|
|
164
|
+
this.checked.value = !this.checked.value;
|
|
165
|
+
}
|
|
166
|
+
this.#updateAria();
|
|
167
|
+
this.setFormValue(this.checked.value ? this.value.value : null);
|
|
168
|
+
this.emit('change', { checked: this.checked.value });
|
|
169
|
+
this.emit('input', { checked: this.checked.value });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
render() {
|
|
173
|
+
return html`
|
|
174
|
+
<div
|
|
175
|
+
class=${() => {
|
|
176
|
+
let cls = 'checkbox-box';
|
|
177
|
+
if (this.checked.value) cls += ' checked';
|
|
178
|
+
if (this.indeterminate.value) cls += ' indeterminate';
|
|
179
|
+
return cls;
|
|
180
|
+
}}
|
|
181
|
+
part="box"
|
|
182
|
+
>
|
|
183
|
+
${() => {
|
|
184
|
+
if (this.indeterminate.value) {
|
|
185
|
+
return html`
|
|
186
|
+
<svg class="icon" viewBox="0 0 24 24">
|
|
187
|
+
<line x1="5" y1="12" x2="19" y2="12"></line>
|
|
188
|
+
</svg>
|
|
189
|
+
`;
|
|
190
|
+
}
|
|
191
|
+
if (this.checked.value) {
|
|
192
|
+
return html`
|
|
193
|
+
<svg class="icon" viewBox="0 0 24 24">
|
|
194
|
+
<polyline points="20 6 9 17 4 12"></polyline>
|
|
195
|
+
</svg>
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
return '';
|
|
199
|
+
}}
|
|
200
|
+
</div>
|
|
201
|
+
<slot>${() => this.label.value || ''}</slot>
|
|
202
|
+
`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-checkbox')) {
|
|
207
|
+
customElements.define('el-checkbox', ElCheckbox);
|
|
208
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
export class ElChip extends Elementum {
|
|
6
|
+
static observedAttributes = ['variant', 'size', 'removable', 'selectable', 'selected', 'value', 'disabled', 'label', 'auto-remove'];
|
|
7
|
+
|
|
8
|
+
variant = signal('muted'); // 'primary' | 'success' | 'danger' | 'warning' | 'muted'
|
|
9
|
+
size = signal('md'); // 'sm' | 'md'
|
|
10
|
+
removable = signal(false);
|
|
11
|
+
selectable = signal(false);
|
|
12
|
+
selected = signal(false);
|
|
13
|
+
value = signal('');
|
|
14
|
+
disabled = signal(false);
|
|
15
|
+
label = signal('');
|
|
16
|
+
|
|
17
|
+
connected() {
|
|
18
|
+
this.#syncValues();
|
|
19
|
+
this.addEventListener('click', this.#onClick);
|
|
20
|
+
this.addEventListener('keydown', this.#onKeyDown);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
disconnected() {
|
|
24
|
+
this.removeEventListener('click', this.#onClick);
|
|
25
|
+
this.removeEventListener('keydown', this.#onKeyDown);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
attributeChanged(name, oldValue, newValue) {
|
|
29
|
+
this.#syncValues();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#syncValues() {
|
|
33
|
+
this.variant.value = this.getAttribute('variant') || 'muted';
|
|
34
|
+
this.size.value = this.getAttribute('size') || 'md';
|
|
35
|
+
this.removable.value = this.hasAttribute('removable');
|
|
36
|
+
this.selectable.value = this.hasAttribute('selectable');
|
|
37
|
+
this.selected.value = this.hasAttribute('selected');
|
|
38
|
+
this.value.value = this.getAttribute('value') || '';
|
|
39
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
40
|
+
this.label.value = this.getAttribute('label') || '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toggleSelected() {
|
|
44
|
+
if (this.disabled.value || !this.selectable.value) return;
|
|
45
|
+
const nextState = !this.selected.value;
|
|
46
|
+
this.selected.value = nextState;
|
|
47
|
+
if (nextState) {
|
|
48
|
+
this.setAttribute('selected', '');
|
|
49
|
+
} else {
|
|
50
|
+
this.removeAttribute('selected');
|
|
51
|
+
}
|
|
52
|
+
this.emit('change', { selected: nextState, value: this.value.value });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#onRemoveClick = (e) => {
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
if (this.disabled.value) return;
|
|
58
|
+
const ev = this.emit('remove', { value: this.value.value });
|
|
59
|
+
if (this.hasAttribute('auto-remove') && !ev.defaultPrevented) {
|
|
60
|
+
this.remove();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
#onClick = () => {
|
|
65
|
+
if (this.selectable.value) {
|
|
66
|
+
this.toggleSelected();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
#onKeyDown = (e) => {
|
|
71
|
+
if (this.disabled.value) return;
|
|
72
|
+
if (this.selectable.value && (e.key === 'Enter' || e.key === ' ')) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
this.toggleSelected();
|
|
75
|
+
} else if (this.removable.value && (e.key === 'Backspace' || e.key === 'Delete')) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
const ev = this.emit('remove', { value: this.value.value });
|
|
78
|
+
if (this.hasAttribute('auto-remove') && !ev.defaultPrevented) {
|
|
79
|
+
this.remove();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
static styles = css`
|
|
85
|
+
:host {
|
|
86
|
+
display: inline-flex;
|
|
87
|
+
vertical-align: middle;
|
|
88
|
+
box-sizing: border-box;
|
|
89
|
+
user-select: none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.chip {
|
|
93
|
+
display: inline-flex;
|
|
94
|
+
align-items: center;
|
|
95
|
+
gap: 6px;
|
|
96
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
97
|
+
font-family: var(--el-font-sans, system-ui, sans-serif);
|
|
98
|
+
font-weight: 500;
|
|
99
|
+
transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.12s var(--el-ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
|
|
100
|
+
box-sizing: border-box;
|
|
101
|
+
touch-action: manipulation;
|
|
102
|
+
-webkit-tap-highlight-color: transparent;
|
|
103
|
+
border: 1px solid transparent;
|
|
104
|
+
outline: none;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.chip:active:not([aria-disabled="true"]) {
|
|
108
|
+
transform: scale(0.97);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@media (prefers-reduced-motion: reduce) {
|
|
112
|
+
.chip {
|
|
113
|
+
transition: none;
|
|
114
|
+
}
|
|
115
|
+
.chip:active:not([aria-disabled="true"]) {
|
|
116
|
+
transform: none;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Sizes */
|
|
121
|
+
.size-sm {
|
|
122
|
+
height: 24px;
|
|
123
|
+
padding: 0 8px;
|
|
124
|
+
font-size: 0.75rem;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.size-md {
|
|
128
|
+
height: 30px;
|
|
129
|
+
padding: 0 12px;
|
|
130
|
+
font-size: 0.8125rem;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.size-lg {
|
|
134
|
+
height: 36px;
|
|
135
|
+
padding: 0 16px;
|
|
136
|
+
font-size: 0.9375rem;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Variants */
|
|
140
|
+
.variant-muted {
|
|
141
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
142
|
+
color: var(--el-text-primary, #1e293b);
|
|
143
|
+
border-color: var(--el-surface-border, #e2e8f0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.variant-secondary {
|
|
147
|
+
background: var(--el-surface-muted, #f1f5f9);
|
|
148
|
+
color: var(--el-text-secondary, #475569);
|
|
149
|
+
border-color: var(--el-surface-border, #cbd5e1);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.variant-primary {
|
|
153
|
+
background: #eff6ff;
|
|
154
|
+
color: var(--el-color-primary, #2563eb);
|
|
155
|
+
border-color: #bfdbfe;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.variant-success {
|
|
159
|
+
background: #ecfdf5;
|
|
160
|
+
color: #059669;
|
|
161
|
+
border-color: #a7f3d0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.variant-info {
|
|
165
|
+
background: #f0f9ff;
|
|
166
|
+
color: #0284c7;
|
|
167
|
+
border-color: #bae6fd;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.variant-warning {
|
|
171
|
+
background: #fffbeb;
|
|
172
|
+
color: #d97706;
|
|
173
|
+
border-color: #fde68a;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.variant-danger {
|
|
177
|
+
background: #fef2f2;
|
|
178
|
+
color: var(--el-color-danger, #ef4444);
|
|
179
|
+
border-color: #fecaca;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Selectable */
|
|
183
|
+
.selectable {
|
|
184
|
+
cursor: pointer;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.selectable:hover:not(.disabled) {
|
|
188
|
+
filter: brightness(0.96);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
:host([selected]) .chip,
|
|
192
|
+
.selected {
|
|
193
|
+
background: var(--el-color-primary, #2563eb) !important;
|
|
194
|
+
color: #ffffff !important;
|
|
195
|
+
border-color: var(--el-color-primary, #2563eb) !important;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
:host(:focus-visible) .chip {
|
|
199
|
+
outline: 2px solid var(--el-color-primary, #2563eb);
|
|
200
|
+
outline-offset: 1px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.disabled {
|
|
204
|
+
opacity: 0.5;
|
|
205
|
+
cursor: not-allowed;
|
|
206
|
+
pointer-events: none;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* Remove button */
|
|
210
|
+
.remove-btn {
|
|
211
|
+
display: inline-flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
justify-content: center;
|
|
214
|
+
border: none;
|
|
215
|
+
background: transparent;
|
|
216
|
+
color: currentColor;
|
|
217
|
+
opacity: 0.7;
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
padding: 0;
|
|
220
|
+
margin: 0;
|
|
221
|
+
width: 14px;
|
|
222
|
+
height: 14px;
|
|
223
|
+
border-radius: var(--el-radius-full, 9999px);
|
|
224
|
+
font-size: 11px;
|
|
225
|
+
line-height: 1;
|
|
226
|
+
transition: opacity 0.15s ease, background 0.15s ease;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.remove-btn:hover {
|
|
230
|
+
opacity: 1;
|
|
231
|
+
background: rgba(0, 0, 0, 0.12);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.remove-btn:focus-visible {
|
|
235
|
+
outline: 1px solid currentColor;
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
|
|
239
|
+
render() {
|
|
240
|
+
return html`
|
|
241
|
+
<div
|
|
242
|
+
class=${() =>
|
|
243
|
+
`chip size-${this.size.value} variant-${this.variant.value} ${
|
|
244
|
+
this.selectable.value ? 'selectable' : ''
|
|
245
|
+
} ${this.selected.value ? 'selected' : ''} ${this.disabled.value ? 'disabled' : ''}`}
|
|
246
|
+
part="chip"
|
|
247
|
+
role=${() => (this.selectable.value ? 'button' : 'status')}
|
|
248
|
+
aria-pressed=${() => (this.selectable.value ? String(this.selected.value) : null)}
|
|
249
|
+
tabindex=${() => (this.selectable.value && !this.disabled.value ? '0' : null)}
|
|
250
|
+
>
|
|
251
|
+
<slot name="prefix"></slot>
|
|
252
|
+
<slot>${() => this.label.value || ''}</slot>
|
|
253
|
+
<slot name="suffix"></slot>
|
|
254
|
+
|
|
255
|
+
${() =>
|
|
256
|
+
this.removable.value
|
|
257
|
+
? html`
|
|
258
|
+
<button
|
|
259
|
+
type="button"
|
|
260
|
+
class="remove-btn"
|
|
261
|
+
part="remove-button"
|
|
262
|
+
aria-label="Remove tag"
|
|
263
|
+
@click=${this.#onRemoveClick}
|
|
264
|
+
>
|
|
265
|
+
✕
|
|
266
|
+
</button>
|
|
267
|
+
`
|
|
268
|
+
: null}
|
|
269
|
+
</div>
|
|
270
|
+
`;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-chip')) {
|
|
275
|
+
customElements.define('el-chip', ElChip);
|
|
276
|
+
}
|