@joralvmel/cosmos-elements 0.3.0 → 0.4.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/README.md +9 -4
- package/dist/components/badge/cosm-badge.d.ts +64 -0
- package/dist/components/badge/cosm-badge.d.ts.map +1 -0
- package/dist/components/badge/cosm-badge.js +162 -0
- package/dist/components/badge/cosm-badge.js.map +1 -0
- package/dist/components/button/cosm-button.d.ts.map +1 -1
- package/dist/components/button/cosm-button.js +2 -0
- package/dist/components/button/cosm-button.js.map +1 -1
- package/dist/components/calendar/cosm-calendar.d.ts +77 -0
- package/dist/components/calendar/cosm-calendar.d.ts.map +1 -0
- package/dist/components/calendar/cosm-calendar.js +696 -0
- package/dist/components/calendar/cosm-calendar.js.map +1 -0
- package/dist/components/checkbox/cosm-checkbox.d.ts +122 -0
- package/dist/components/checkbox/cosm-checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/cosm-checkbox.js +433 -0
- package/dist/components/checkbox/cosm-checkbox.js.map +1 -0
- package/dist/components/dialog/cosm-dialog.d.ts +103 -0
- package/dist/components/dialog/cosm-dialog.d.ts.map +1 -0
- package/dist/components/dialog/cosm-dialog.js +497 -0
- package/dist/components/dialog/cosm-dialog.js.map +1 -0
- package/dist/components/icon/cosm-icon.d.ts +7 -15
- package/dist/components/icon/cosm-icon.d.ts.map +1 -1
- package/dist/components/icon/cosm-icon.js +29 -30
- package/dist/components/icon/cosm-icon.js.map +1 -1
- package/dist/components/icon-button/cosm-icon-button.d.ts.map +1 -1
- package/dist/components/icon-button/cosm-icon-button.js +6 -0
- package/dist/components/icon-button/cosm-icon-button.js.map +1 -1
- package/dist/components/listbox/cosm-listbox.d.ts +1 -5
- package/dist/components/listbox/cosm-listbox.d.ts.map +1 -1
- package/dist/components/listbox/cosm-listbox.js +3 -18
- package/dist/components/listbox/cosm-listbox.js.map +1 -1
- package/dist/components/pagination/cosm-pagination.d.ts +118 -0
- package/dist/components/pagination/cosm-pagination.d.ts.map +1 -0
- package/dist/components/pagination/cosm-pagination.js +315 -0
- package/dist/components/pagination/cosm-pagination.js.map +1 -0
- package/dist/components/popover/cosm-popover.d.ts +0 -22
- package/dist/components/popover/cosm-popover.d.ts.map +1 -1
- package/dist/components/popover/cosm-popover.js +21 -54
- package/dist/components/popover/cosm-popover.js.map +1 -1
- package/dist/components/radio-group/cosm-radio-group.d.ts +111 -0
- package/dist/components/radio-group/cosm-radio-group.d.ts.map +1 -0
- package/dist/components/radio-group/cosm-radio-group.js +478 -0
- package/dist/components/radio-group/cosm-radio-group.js.map +1 -0
- package/dist/components/select/cosm-select.d.ts +126 -0
- package/dist/components/select/cosm-select.d.ts.map +1 -0
- package/dist/components/select/cosm-select.js +682 -0
- package/dist/components/select/cosm-select.js.map +1 -0
- package/dist/components/switch/cosm-switch.d.ts +103 -0
- package/dist/components/switch/cosm-switch.d.ts.map +1 -0
- package/dist/components/switch/cosm-switch.js +359 -0
- package/dist/components/switch/cosm-switch.js.map +1 -0
- package/dist/components/text-field/cosm-text-field.d.ts +8 -18
- package/dist/components/text-field/cosm-text-field.d.ts.map +1 -1
- package/dist/components/text-field/cosm-text-field.js +30 -67
- package/dist/components/text-field/cosm-text-field.js.map +1 -1
- package/dist/components/textarea/cosm-textarea.d.ts +131 -0
- package/dist/components/textarea/cosm-textarea.d.ts.map +1 -0
- package/dist/components/textarea/cosm-textarea.js +445 -0
- package/dist/components/textarea/cosm-textarea.js.map +1 -0
- package/dist/custom-elements.json +5915 -1330
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/current-page.d.ts +7 -0
- package/dist/internal/current-page.d.ts.map +1 -0
- package/dist/internal/current-page.js +18 -0
- package/dist/internal/current-page.js.map +1 -0
- package/llms.md +306 -20
- package/package.json +39 -3
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { getRadioGroupInitialActive, radioGroupContract, validateRadioGroupOptions, validateRadioGroupValue, validateSize, } from '@joralvmel/cosmos-core';
|
|
2
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
3
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
4
|
+
import { define } from '../../internal/define.js';
|
|
5
|
+
import { boxSizing, focusRing } from '../../internal/styles.js';
|
|
6
|
+
let instance = 0;
|
|
7
|
+
const styles = css `
|
|
8
|
+
:host {
|
|
9
|
+
--_radio-size: var(--cosm-icon-size-md, 20px);
|
|
10
|
+
display: block;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
color: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
13
|
+
font-family: var(--cosm-font-sans, system-ui, sans-serif);
|
|
14
|
+
}
|
|
15
|
+
:host([size='sm']) {
|
|
16
|
+
--_radio-size: var(--cosm-icon-size-sm, 16px);
|
|
17
|
+
}
|
|
18
|
+
:host([size='lg']) {
|
|
19
|
+
--_radio-size: var(--cosm-icon-size-lg, 24px);
|
|
20
|
+
}
|
|
21
|
+
.base {
|
|
22
|
+
min-width: 0;
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 0;
|
|
25
|
+
border: 0;
|
|
26
|
+
}
|
|
27
|
+
.label {
|
|
28
|
+
display: block;
|
|
29
|
+
margin-block-end: var(--cosm-space-xs, 0.25rem);
|
|
30
|
+
color: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
31
|
+
font-size: var(--cosm-text-sm, 0.875rem);
|
|
32
|
+
font-weight: var(--cosm-weight-medium, 500);
|
|
33
|
+
}
|
|
34
|
+
.options {
|
|
35
|
+
display: flex;
|
|
36
|
+
min-width: 0;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
gap: var(--cosm-radio-group-gap, var(--cosm-space-xs, 0.25rem));
|
|
39
|
+
}
|
|
40
|
+
.options[data-orientation='horizontal'] {
|
|
41
|
+
flex-direction: row;
|
|
42
|
+
flex-wrap: wrap;
|
|
43
|
+
column-gap: var(--cosm-radio-group-gap, var(--cosm-space-md, 0.75rem));
|
|
44
|
+
}
|
|
45
|
+
.option {
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
min-width: 0;
|
|
48
|
+
min-height: var(--cosm-control-md, 2.5rem);
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: var(--cosm-radio-group-option-gap, var(--cosm-space-sm, 0.5rem));
|
|
51
|
+
color: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
.input {
|
|
55
|
+
position: absolute;
|
|
56
|
+
width: 1px;
|
|
57
|
+
height: 1px;
|
|
58
|
+
padding: 0;
|
|
59
|
+
margin: -1px;
|
|
60
|
+
overflow: hidden;
|
|
61
|
+
clip: rect(0, 0, 0, 0);
|
|
62
|
+
clip-path: inset(50%);
|
|
63
|
+
white-space: nowrap;
|
|
64
|
+
border: 0;
|
|
65
|
+
}
|
|
66
|
+
.control {
|
|
67
|
+
display: grid;
|
|
68
|
+
width: var(--cosm-radio-group-control-size, var(--_radio-size));
|
|
69
|
+
height: var(--cosm-radio-group-control-size, var(--_radio-size));
|
|
70
|
+
flex: none;
|
|
71
|
+
place-items: center;
|
|
72
|
+
box-sizing: border-box;
|
|
73
|
+
border: 1px solid
|
|
74
|
+
var(--cosm-radio-group-border, var(--cosm-border-strong, oklch(0.64 0.01 268)));
|
|
75
|
+
border-radius: 50%;
|
|
76
|
+
background: var(--cosm-bg, oklch(0.985 0.007 268));
|
|
77
|
+
}
|
|
78
|
+
.indicator {
|
|
79
|
+
width: 48%;
|
|
80
|
+
height: 48%;
|
|
81
|
+
border-radius: 50%;
|
|
82
|
+
background: var(--cosm-radio-group-indicator, var(--cosm-primary, oklch(0.55 0.2 268)));
|
|
83
|
+
opacity: 0;
|
|
84
|
+
}
|
|
85
|
+
.input:checked + .control {
|
|
86
|
+
border-color: var(
|
|
87
|
+
--cosm-radio-group-selected-border,
|
|
88
|
+
var(--cosm-primary, oklch(0.55 0.2 268))
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
.input:checked + .control .indicator {
|
|
92
|
+
opacity: 1;
|
|
93
|
+
}
|
|
94
|
+
.input:focus-visible + .control {
|
|
95
|
+
outline: 2px solid
|
|
96
|
+
var(--cosm-radio-group-focus, var(--cosm-focus-ring, oklch(0.55 0.2 268)));
|
|
97
|
+
outline-offset: 2px;
|
|
98
|
+
}
|
|
99
|
+
.content {
|
|
100
|
+
display: grid;
|
|
101
|
+
min-width: 0;
|
|
102
|
+
gap: var(--cosm-space-3xs, 0.125rem);
|
|
103
|
+
}
|
|
104
|
+
.option-label,
|
|
105
|
+
.description,
|
|
106
|
+
.message {
|
|
107
|
+
overflow-wrap: anywhere;
|
|
108
|
+
}
|
|
109
|
+
.option-label {
|
|
110
|
+
font-size: var(--cosm-text-sm, 0.875rem);
|
|
111
|
+
}
|
|
112
|
+
.description,
|
|
113
|
+
.message {
|
|
114
|
+
color: var(--cosm-fg-muted, oklch(0.48 0.01 268));
|
|
115
|
+
font-size: var(--cosm-text-xs, 0.75rem);
|
|
116
|
+
}
|
|
117
|
+
.option[data-disabled='true'] {
|
|
118
|
+
color: var(--cosm-fg-muted, oklch(0.48 0.01 268));
|
|
119
|
+
cursor: not-allowed;
|
|
120
|
+
}
|
|
121
|
+
.base[data-disabled='true'] .option {
|
|
122
|
+
cursor: not-allowed;
|
|
123
|
+
}
|
|
124
|
+
.base[data-invalid='true'] .control,
|
|
125
|
+
.base[data-invalid='true'] .input:checked + .control {
|
|
126
|
+
border-color: var(--cosm-danger, oklch(0.55 0.16 19));
|
|
127
|
+
}
|
|
128
|
+
.base[data-invalid='true'] .indicator {
|
|
129
|
+
background: var(--cosm-danger, oklch(0.55 0.16 19));
|
|
130
|
+
}
|
|
131
|
+
.message {
|
|
132
|
+
display: block;
|
|
133
|
+
margin-block-start: var(--cosm-space-2xs, 0.125rem);
|
|
134
|
+
}
|
|
135
|
+
.error {
|
|
136
|
+
color: var(--cosm-danger-text, var(--cosm-danger, oklch(0.48 0.14 19)));
|
|
137
|
+
}
|
|
138
|
+
@media (hover: hover) {
|
|
139
|
+
.option:where([data-disabled='false'][data-invalid='false']):hover .control {
|
|
140
|
+
border-color: var(--cosm-radio-group-border, var(--cosm-primary, oklch(0.55 0.2 268)));
|
|
141
|
+
}
|
|
142
|
+
.option:where([data-disabled='false'][data-invalid='false']):hover
|
|
143
|
+
.input:checked
|
|
144
|
+
+ .control {
|
|
145
|
+
border-color: var(
|
|
146
|
+
--cosm-radio-group-selected-border,
|
|
147
|
+
var(--cosm-primary-hover, oklch(0.49 0.2 268))
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
@media (forced-colors: active) {
|
|
152
|
+
.control {
|
|
153
|
+
forced-color-adjust: none;
|
|
154
|
+
border-color: ButtonText;
|
|
155
|
+
background: Canvas;
|
|
156
|
+
}
|
|
157
|
+
.option .input:checked + .control {
|
|
158
|
+
border-color: Highlight;
|
|
159
|
+
}
|
|
160
|
+
.input:checked + .control .indicator {
|
|
161
|
+
background: Highlight;
|
|
162
|
+
}
|
|
163
|
+
.base[data-invalid='true'] .control,
|
|
164
|
+
.base[data-invalid='true'] .input:checked + .control {
|
|
165
|
+
border-color: CanvasText;
|
|
166
|
+
}
|
|
167
|
+
.base[data-invalid='true'] .indicator {
|
|
168
|
+
background: CanvasText;
|
|
169
|
+
}
|
|
170
|
+
.input:focus-visible + .control {
|
|
171
|
+
outline-color: Highlight;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
`;
|
|
175
|
+
/**
|
|
176
|
+
* Selects one option from an accessible, form-associated radio group.
|
|
177
|
+
*
|
|
178
|
+
* @tag cosm-radio-group
|
|
179
|
+
* @slot - No content slot; options are supplied through the `options` property.
|
|
180
|
+
* @csspart base - Group wrapper and accessible fieldset.
|
|
181
|
+
* @csspart label - Visible group label.
|
|
182
|
+
* @csspart options - Option collection.
|
|
183
|
+
* @csspart option - Selectable option row.
|
|
184
|
+
* @csspart input - Native radio input and Web focus target.
|
|
185
|
+
* @csspart control - Visible circular radio boundary.
|
|
186
|
+
* @csspart indicator - Selected radio dot.
|
|
187
|
+
* @csspart option-label - Primary option text.
|
|
188
|
+
* @csspart description - Optional option description.
|
|
189
|
+
* @csspart help-text - Supporting text associated with the group.
|
|
190
|
+
* @csspart error-text - Error description associated with the group.
|
|
191
|
+
* @fires {CustomEvent<RadioGroupChangeDetail>} cosm-change - Proposed selection value.
|
|
192
|
+
* @cssprop --cosm-radio-group-gap - Space between option rows.
|
|
193
|
+
* @cssprop --cosm-radio-group-option-gap - Space between control and option content.
|
|
194
|
+
* @cssprop --cosm-radio-group-control-size - Diameter of the visible radio control.
|
|
195
|
+
* @cssprop --cosm-radio-group-border - Unchecked radio boundary color.
|
|
196
|
+
* @cssprop --cosm-radio-group-selected-border - Selected radio boundary color.
|
|
197
|
+
* @cssprop --cosm-radio-group-indicator - Selected radio dot color.
|
|
198
|
+
* @cssprop --cosm-radio-group-focus - Visible keyboard focus indicator color.
|
|
199
|
+
*/
|
|
200
|
+
export class CosmRadioGroup extends CosmElement {
|
|
201
|
+
static formAssociated = true;
|
|
202
|
+
static shadowRootOptions = {
|
|
203
|
+
...LitElement.shadowRootOptions,
|
|
204
|
+
delegatesFocus: true,
|
|
205
|
+
};
|
|
206
|
+
static properties = {
|
|
207
|
+
label: {},
|
|
208
|
+
options: { attribute: false },
|
|
209
|
+
value: { attribute: false, noAccessor: true },
|
|
210
|
+
defaultValue: { attribute: false },
|
|
211
|
+
orientation: { reflect: true },
|
|
212
|
+
size: { reflect: true },
|
|
213
|
+
disabled: { type: Boolean, reflect: true },
|
|
214
|
+
required: { type: Boolean, reflect: true },
|
|
215
|
+
invalid: { type: Boolean, reflect: true },
|
|
216
|
+
helperText: { attribute: 'helper-text' },
|
|
217
|
+
errorText: { attribute: 'error-text' },
|
|
218
|
+
name: { reflect: true },
|
|
219
|
+
};
|
|
220
|
+
static styles = [boxSizing, focusRing, styles];
|
|
221
|
+
/** Framework adapters set ownership when a value binding is present. */
|
|
222
|
+
valueControlled = false;
|
|
223
|
+
#internals;
|
|
224
|
+
#id = `cosm-radio-group-${++instance}`;
|
|
225
|
+
#radioName = `cosm-radio-group-options-${instance}`;
|
|
226
|
+
#value = null;
|
|
227
|
+
#formDisabled = false;
|
|
228
|
+
#initialized = false;
|
|
229
|
+
#showNativeError = false;
|
|
230
|
+
constructor() {
|
|
231
|
+
super();
|
|
232
|
+
const props = radioGroupContract.props;
|
|
233
|
+
this.label = '';
|
|
234
|
+
this.options = [];
|
|
235
|
+
this.defaultValue = undefined;
|
|
236
|
+
this.orientation = props.orientation.default;
|
|
237
|
+
this.size = props.size.default;
|
|
238
|
+
this.disabled = props.disabled.default;
|
|
239
|
+
this.required = props.required.default;
|
|
240
|
+
this.invalid = props.invalid.default;
|
|
241
|
+
this.helperText = '';
|
|
242
|
+
this.errorText = '';
|
|
243
|
+
this.name = undefined;
|
|
244
|
+
this.#internals =
|
|
245
|
+
typeof this.attachInternals === 'function' ? this.attachInternals() : undefined;
|
|
246
|
+
}
|
|
247
|
+
get value() {
|
|
248
|
+
return this.#value;
|
|
249
|
+
}
|
|
250
|
+
set value(value) {
|
|
251
|
+
this.valueControlled = value !== undefined;
|
|
252
|
+
this.#setValue(value ?? null);
|
|
253
|
+
}
|
|
254
|
+
connectedCallback() {
|
|
255
|
+
super.connectedCallback();
|
|
256
|
+
this.addEventListener('invalid', this.#onInvalid);
|
|
257
|
+
}
|
|
258
|
+
disconnectedCallback() {
|
|
259
|
+
this.removeEventListener('invalid', this.#onInvalid);
|
|
260
|
+
super.disconnectedCallback();
|
|
261
|
+
}
|
|
262
|
+
get form() {
|
|
263
|
+
return this.#internals?.form ?? this.closest('form');
|
|
264
|
+
}
|
|
265
|
+
focus(options) {
|
|
266
|
+
const value = getRadioGroupInitialActive(this.options, this.value);
|
|
267
|
+
const input = this.#inputFor(value) ?? this.#inputs()[0];
|
|
268
|
+
input?.focus(options);
|
|
269
|
+
}
|
|
270
|
+
checkValidity() {
|
|
271
|
+
return this.#internals?.checkValidity() ?? this.#inputFor(null)?.checkValidity() ?? true;
|
|
272
|
+
}
|
|
273
|
+
reportValidity() {
|
|
274
|
+
this.#showNativeError = true;
|
|
275
|
+
this.requestUpdate();
|
|
276
|
+
this.#syncFormState();
|
|
277
|
+
const input = this.#inputFor(null);
|
|
278
|
+
return this.#internals?.reportValidity() ?? input?.reportValidity() ?? true;
|
|
279
|
+
}
|
|
280
|
+
formDisabledCallback(disabled) {
|
|
281
|
+
this.#formDisabled = disabled;
|
|
282
|
+
this.requestUpdate();
|
|
283
|
+
}
|
|
284
|
+
formResetCallback() {
|
|
285
|
+
this.#showNativeError = false;
|
|
286
|
+
const resetValue = this.defaultValue ?? null;
|
|
287
|
+
if (this.valueControlled) {
|
|
288
|
+
this.emit('cosm-change', { value: resetValue });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
this.#setValue(resetValue);
|
|
292
|
+
}
|
|
293
|
+
formStateRestoreCallback(state) {
|
|
294
|
+
if (typeof state !== 'string')
|
|
295
|
+
return;
|
|
296
|
+
const restoredValue = state || null;
|
|
297
|
+
validateRadioGroupValue(restoredValue, this.options, 'value');
|
|
298
|
+
this.#showNativeError = false;
|
|
299
|
+
if (this.valueControlled) {
|
|
300
|
+
this.emit('cosm-change', { value: restoredValue });
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
this.#setValue(restoredValue);
|
|
304
|
+
}
|
|
305
|
+
willUpdate() {
|
|
306
|
+
validateSize(this.size, 'RadioGroup');
|
|
307
|
+
if (typeof this.label !== 'string' || !this.label.trim()) {
|
|
308
|
+
throw new TypeError('RadioGroup requires a non-empty label.');
|
|
309
|
+
}
|
|
310
|
+
if (this.orientation !== 'vertical' && this.orientation !== 'horizontal') {
|
|
311
|
+
throw new TypeError('RadioGroup orientation must be vertical or horizontal.');
|
|
312
|
+
}
|
|
313
|
+
for (const [name, value] of [
|
|
314
|
+
['disabled', this.disabled],
|
|
315
|
+
['required', this.required],
|
|
316
|
+
['invalid', this.invalid],
|
|
317
|
+
]) {
|
|
318
|
+
if (typeof value !== 'boolean')
|
|
319
|
+
throw new TypeError(`RadioGroup ${name} must be a boolean.`);
|
|
320
|
+
}
|
|
321
|
+
if (typeof this.helperText !== 'string' ||
|
|
322
|
+
typeof this.errorText !== 'string' ||
|
|
323
|
+
(typeof this.name !== 'string' && this.name !== undefined)) {
|
|
324
|
+
throw new TypeError('RadioGroup helperText, errorText and name must be strings.');
|
|
325
|
+
}
|
|
326
|
+
validateRadioGroupOptions(this.options);
|
|
327
|
+
validateRadioGroupValue(this.value, this.options, 'value');
|
|
328
|
+
validateRadioGroupValue(this.defaultValue, this.options, 'defaultValue');
|
|
329
|
+
if (!this.#initialized) {
|
|
330
|
+
if (!this.valueControlled)
|
|
331
|
+
this.#setValue(this.defaultValue ?? null);
|
|
332
|
+
this.#initialized = true;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
updated() {
|
|
336
|
+
this.#syncFormState();
|
|
337
|
+
}
|
|
338
|
+
#inputs = () => [
|
|
339
|
+
...this.renderRoot.querySelectorAll('input[type="radio"]'),
|
|
340
|
+
];
|
|
341
|
+
#inputFor = (value) => this.#inputs().find(input => value === null || input.value === value);
|
|
342
|
+
#setValue(value) {
|
|
343
|
+
const previous = this.#value;
|
|
344
|
+
this.#value = value;
|
|
345
|
+
this.requestUpdate('value', previous);
|
|
346
|
+
}
|
|
347
|
+
#syncFormState() {
|
|
348
|
+
const disabled = this.disabled || this.#formDisabled;
|
|
349
|
+
const inputs = this.#inputs();
|
|
350
|
+
const input = inputs.find(radio => !radio.disabled) ?? inputs[0];
|
|
351
|
+
if (!input)
|
|
352
|
+
return;
|
|
353
|
+
for (const radio of inputs) {
|
|
354
|
+
radio.disabled = disabled || this.#optionDisabled(radio.value);
|
|
355
|
+
radio.required = this.required;
|
|
356
|
+
radio.checked = radio.value === this.value;
|
|
357
|
+
}
|
|
358
|
+
if (!this.#internals)
|
|
359
|
+
return;
|
|
360
|
+
const selectedOptionDisabled = typeof this.value === 'string' && this.#optionDisabled(this.value);
|
|
361
|
+
this.#internals.setFormValue(disabled || selectedOptionDisabled ? null : (this.value ?? null), this.value ?? '');
|
|
362
|
+
if (disabled || !this.required || (this.value !== null && !selectedOptionDisabled)) {
|
|
363
|
+
this.#internals.setValidity({});
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
this.#internals.setValidity({ valueMissing: true }, input.validationMessage, input);
|
|
367
|
+
}
|
|
368
|
+
#optionDisabled(value) {
|
|
369
|
+
return this.options.find(option => option.value === value)?.disabled === true;
|
|
370
|
+
}
|
|
371
|
+
#onInvalid = () => {
|
|
372
|
+
this.#showNativeError = true;
|
|
373
|
+
this.requestUpdate();
|
|
374
|
+
};
|
|
375
|
+
#onChange = (event) => {
|
|
376
|
+
const input = event.currentTarget;
|
|
377
|
+
const nextValue = input.value;
|
|
378
|
+
if (this.disabled || this.#formDisabled || this.#optionDisabled(nextValue)) {
|
|
379
|
+
input.checked = input.value === this.value;
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (nextValue === this.value)
|
|
383
|
+
return;
|
|
384
|
+
this.#showNativeError = false;
|
|
385
|
+
if (!this.valueControlled) {
|
|
386
|
+
this.#setValue(nextValue);
|
|
387
|
+
}
|
|
388
|
+
this.emit('cosm-change', { value: nextValue });
|
|
389
|
+
if (this.valueControlled)
|
|
390
|
+
this.#syncFormState();
|
|
391
|
+
};
|
|
392
|
+
render() {
|
|
393
|
+
const effectiveDisabled = this.disabled || this.#formDisabled;
|
|
394
|
+
const errorText = this.errorText?.trim() ? this.errorText : '';
|
|
395
|
+
const invalid = this.invalid || Boolean(errorText);
|
|
396
|
+
const input = this.#inputFor(null);
|
|
397
|
+
const nativeInvalid = this.#showNativeError && !(input?.validity.valid ?? true);
|
|
398
|
+
const shownError = errorText || (nativeInvalid ? input?.validationMessage : '') || '';
|
|
399
|
+
const currentInvalid = invalid || nativeInvalid;
|
|
400
|
+
const describedBy = [
|
|
401
|
+
this.helperText ? `${this.#id}-help` : '',
|
|
402
|
+
shownError ? `${this.#id}-error` : '',
|
|
403
|
+
]
|
|
404
|
+
.filter(Boolean)
|
|
405
|
+
.join(' ');
|
|
406
|
+
return html `
|
|
407
|
+
<fieldset
|
|
408
|
+
part="base"
|
|
409
|
+
class="base"
|
|
410
|
+
role="radiogroup"
|
|
411
|
+
data-disabled=${effectiveDisabled ? 'true' : 'false'}
|
|
412
|
+
data-invalid=${currentInvalid ? 'true' : 'false'}
|
|
413
|
+
aria-required=${this.required ? 'true' : 'false'}
|
|
414
|
+
aria-disabled=${effectiveDisabled ? 'true' : 'false'}
|
|
415
|
+
aria-invalid=${currentInvalid ? 'true' : nothing}
|
|
416
|
+
aria-describedby=${describedBy || nothing}
|
|
417
|
+
?disabled=${effectiveDisabled}
|
|
418
|
+
>
|
|
419
|
+
<legend part="label" class="label">${this.label}</legend>
|
|
420
|
+
<div part="options" class="options" data-orientation=${this.orientation}>
|
|
421
|
+
${this.options.map((option) => html `
|
|
422
|
+
<label
|
|
423
|
+
part="option"
|
|
424
|
+
class="option"
|
|
425
|
+
data-disabled=${effectiveDisabled || option.disabled ? 'true' : 'false'}
|
|
426
|
+
data-invalid=${currentInvalid ? 'true' : 'false'}
|
|
427
|
+
>
|
|
428
|
+
<input
|
|
429
|
+
part="input"
|
|
430
|
+
class="input"
|
|
431
|
+
type="radio"
|
|
432
|
+
name=${this.#radioName}
|
|
433
|
+
.value=${option.value}
|
|
434
|
+
.checked=${this.value === option.value}
|
|
435
|
+
?required=${this.required}
|
|
436
|
+
?disabled=${effectiveDisabled || option.disabled === true}
|
|
437
|
+
aria-describedby=${option.description
|
|
438
|
+
? `${this.#id}-option-${this.options.indexOf(option)}`
|
|
439
|
+
: nothing}
|
|
440
|
+
@change=${this.#onChange}
|
|
441
|
+
/>
|
|
442
|
+
<span part="control" class="control" aria-hidden="true">
|
|
443
|
+
<span part="indicator" class="indicator"></span>
|
|
444
|
+
</span>
|
|
445
|
+
<span class="content">
|
|
446
|
+
<span part="option-label" class="option-label">${option.label}</span>
|
|
447
|
+
${option.description
|
|
448
|
+
? html `<span
|
|
449
|
+
part="description"
|
|
450
|
+
class="description"
|
|
451
|
+
id=${`${this.#id}-option-${this.options.indexOf(option)}`}
|
|
452
|
+
>${option.description}</span
|
|
453
|
+
>`
|
|
454
|
+
: nothing}
|
|
455
|
+
</span>
|
|
456
|
+
</label>
|
|
457
|
+
`)}
|
|
458
|
+
</div>
|
|
459
|
+
${this.helperText
|
|
460
|
+
? html `<span part="help-text" class="message" id=${`${this.#id}-help`}
|
|
461
|
+
>${this.helperText}</span
|
|
462
|
+
>`
|
|
463
|
+
: nothing}
|
|
464
|
+
${shownError
|
|
465
|
+
? html `<span
|
|
466
|
+
part="error-text"
|
|
467
|
+
class="message error"
|
|
468
|
+
id=${`${this.#id}-error`}
|
|
469
|
+
role="alert"
|
|
470
|
+
>${shownError}</span
|
|
471
|
+
>`
|
|
472
|
+
: nothing}
|
|
473
|
+
</fieldset>
|
|
474
|
+
`;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
define('cosm-radio-group', CosmRadioGroup);
|
|
478
|
+
//# sourceMappingURL=cosm-radio-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-radio-group.js","sourceRoot":"","sources":["../../../src/components/radio-group/cosm-radio-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAI1B,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAMhE,I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I,CAAA;;;6BAGC,GAAG,IAAI,CAAC,GAAG,WAAW,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;2BACtD,MAAM,CAAC,WAAW;wBACrB;YACF,CAAC,CAAC,OACN;;;aAGL,CACF;;UAGD,IAAI,CAAC,UAAU;YACb,CAAC,CAAC,IAAI,CAAA,6CAA6C,GAAG,IAAI,CAAC,GAAG,OAAO;iBAChE,IAAI,CAAC,UAAU;cAClB;YACF,CAAC,CAAC,OACN;UAEE,UAAU;YACR,CAAC,CAAC,IAAI,CAAA;;;mBAGC,GAAG,IAAI,CAAC,GAAG,QAAQ;;iBAErB,UAAU;cACb;YACF,CAAC,CAAC,OACN;;KAEH,CAAC;IACJ,CAAC;;AAGH,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type ContractProps, type SelectItems, type SelectValue, selectContract } from '@joralvmel/cosmos-core';
|
|
2
|
+
import '../icon/cosm-icon.js';
|
|
3
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
4
|
+
type Props = Required<ContractProps<typeof selectContract, 'web', {
|
|
5
|
+
SelectItems: SelectItems;
|
|
6
|
+
SelectValue: SelectValue;
|
|
7
|
+
}>>;
|
|
8
|
+
type Variant = NonNullable<Props['variant']>;
|
|
9
|
+
type Size = NonNullable<Props['size']>;
|
|
10
|
+
/**
|
|
11
|
+
* Labeled, single-selection combobox with a flat popup and native Web form behavior.
|
|
12
|
+
*
|
|
13
|
+
* @tag cosm-select
|
|
14
|
+
* @csspart base - Field wrapper.
|
|
15
|
+
* @csspart label - Visible accessible label.
|
|
16
|
+
* @csspart trigger - Select-only combobox trigger.
|
|
17
|
+
* @csspart value - Selected option text.
|
|
18
|
+
* @csspart placeholder - Text displayed when no option is selected.
|
|
19
|
+
* @csspart popup - Anchored option surface.
|
|
20
|
+
* @csspart listbox - Single-selection option collection.
|
|
21
|
+
* @csspart option - Selectable option row.
|
|
22
|
+
* @csspart content - Option text wrapper.
|
|
23
|
+
* @csspart option-label - Primary option text.
|
|
24
|
+
* @csspart help - Supporting text.
|
|
25
|
+
* @csspart error - Error description.
|
|
26
|
+
* @fires {CustomEvent<SelectChangeDetail>} cosm-change - Proposes a selection.
|
|
27
|
+
* @cssprop --cosm-select-background - Control background.
|
|
28
|
+
* @cssprop --cosm-select-color - Control and value text color.
|
|
29
|
+
* @cssprop --cosm-select-placeholder - Placeholder text color.
|
|
30
|
+
* @cssprop --cosm-select-border - Control boundary color.
|
|
31
|
+
* @cssprop --cosm-select-focus - Visible keyboard focus indicator color.
|
|
32
|
+
* @cssprop --cosm-select-radius - Control corner radius.
|
|
33
|
+
* @cssprop --cosm-select-trigger-min-height - Custom minimum trigger height.
|
|
34
|
+
* @cssprop --cosm-select-option-selected-background - Selected option background.
|
|
35
|
+
* @cssprop --cosm-select-option-selected-color - Selected option text color.
|
|
36
|
+
*/
|
|
37
|
+
export declare class CosmSelect extends CosmElement {
|
|
38
|
+
#private;
|
|
39
|
+
static formAssociated: boolean;
|
|
40
|
+
static shadowRootOptions: ShadowRootInit;
|
|
41
|
+
static properties: {
|
|
42
|
+
label: {
|
|
43
|
+
type: StringConstructor;
|
|
44
|
+
};
|
|
45
|
+
items: {
|
|
46
|
+
attribute: boolean;
|
|
47
|
+
};
|
|
48
|
+
value: {
|
|
49
|
+
attribute: boolean;
|
|
50
|
+
noAccessor: boolean;
|
|
51
|
+
};
|
|
52
|
+
defaultValue: {
|
|
53
|
+
attribute: boolean;
|
|
54
|
+
};
|
|
55
|
+
placeholder: {
|
|
56
|
+
type: StringConstructor;
|
|
57
|
+
};
|
|
58
|
+
variant: {
|
|
59
|
+
reflect: boolean;
|
|
60
|
+
};
|
|
61
|
+
size: {
|
|
62
|
+
reflect: boolean;
|
|
63
|
+
};
|
|
64
|
+
disabled: {
|
|
65
|
+
type: BooleanConstructor;
|
|
66
|
+
reflect: boolean;
|
|
67
|
+
};
|
|
68
|
+
required: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
reflect: boolean;
|
|
71
|
+
};
|
|
72
|
+
invalid: {
|
|
73
|
+
type: BooleanConstructor;
|
|
74
|
+
reflect: boolean;
|
|
75
|
+
};
|
|
76
|
+
helperText: {
|
|
77
|
+
type: StringConstructor;
|
|
78
|
+
attribute: string;
|
|
79
|
+
};
|
|
80
|
+
errorText: {
|
|
81
|
+
type: StringConstructor;
|
|
82
|
+
attribute: string;
|
|
83
|
+
};
|
|
84
|
+
name: {
|
|
85
|
+
type: StringConstructor;
|
|
86
|
+
reflect: boolean;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
static styles: import("lit").CSSResult[];
|
|
90
|
+
label: Props['label'];
|
|
91
|
+
items: Props['items'];
|
|
92
|
+
defaultValue: Props['defaultValue'] | undefined;
|
|
93
|
+
placeholder: Props['placeholder'];
|
|
94
|
+
variant: Variant;
|
|
95
|
+
size: Size;
|
|
96
|
+
disabled: Props['disabled'];
|
|
97
|
+
required: Props['required'];
|
|
98
|
+
invalid: Props['invalid'];
|
|
99
|
+
helperText: Props['helperText'];
|
|
100
|
+
errorText: Props['errorText'];
|
|
101
|
+
name: Props['name'] | undefined;
|
|
102
|
+
/** Set by adapters to distinguish a bound value, including null, from autonomous state. */
|
|
103
|
+
valueControlled: boolean;
|
|
104
|
+
get value(): SelectValue;
|
|
105
|
+
set value(value: SelectValue | undefined);
|
|
106
|
+
constructor();
|
|
107
|
+
connectedCallback(): void;
|
|
108
|
+
disconnectedCallback(): void;
|
|
109
|
+
get form(): HTMLFormElement | null;
|
|
110
|
+
focus(options?: FocusOptions): void;
|
|
111
|
+
checkValidity(): boolean;
|
|
112
|
+
reportValidity(): boolean;
|
|
113
|
+
formDisabledCallback(disabled: boolean): void;
|
|
114
|
+
formResetCallback(): void;
|
|
115
|
+
formStateRestoreCallback(state: string | File | FormData): void;
|
|
116
|
+
protected willUpdate(): void;
|
|
117
|
+
protected updated(changed: Map<PropertyKey, unknown>): void;
|
|
118
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
119
|
+
}
|
|
120
|
+
declare global {
|
|
121
|
+
interface HTMLElementTagNameMap {
|
|
122
|
+
'cosm-select': CosmSelect;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=cosm-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-select.d.ts","sourceRoot":"","sources":["../../../src/components/select/cosm-select.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAOlB,KAAK,WAAW,EAEhB,KAAK,WAAW,EAChB,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAIhC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAI7D,KAAK,KAAK,GAAG,QAAQ,CACnB,aAAa,CACX,OAAO,cAAc,EACrB,KAAK,EACL;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAE,CACvD,CACF,CAAC;AACF,KAAK,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7C,KAAK,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAuLvC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,UAAW,SAAQ,WAAW;;IACzC,MAAM,CAAC,cAAc,UAAQ;IAC7B,OAAgB,iBAAiB,EAAE,cAAc,CAG/C;IACF,OAAgB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAcxB;IACF,OAAgB,MAAM,4BAAkC;IAEhD,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACtB,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,GA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