@warp-ds/elements 2.6.0 → 2.7.0-next.2
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/dist/custom-elements.json +1552 -0
- package/dist/index.d.ts +561 -0
- package/dist/packages/affix/affix.js +11 -11
- package/dist/packages/affix/affix.js.map +3 -3
- package/dist/packages/alert/alert.js +7 -7
- package/dist/packages/alert/alert.js.map +3 -3
- package/dist/packages/attention/attention.js +22 -22
- package/dist/packages/attention/attention.js.map +3 -3
- package/dist/packages/breadcrumbs/breadcrumbs.js +9 -9
- package/dist/packages/breadcrumbs/breadcrumbs.js.map +3 -3
- package/dist/packages/button/button.js +11 -11
- package/dist/packages/button/button.js.map +3 -3
- package/dist/packages/card/card.js +8 -8
- package/dist/packages/card/card.js.map +3 -3
- package/dist/packages/checkbox/checkbox.a11y.test.d.ts +1 -0
- package/dist/packages/checkbox/checkbox.a11y.test.js +73 -0
- package/dist/packages/checkbox/checkbox.d.ts +49 -0
- package/dist/packages/checkbox/checkbox.js +2594 -0
- package/dist/packages/checkbox/checkbox.js.map +7 -0
- package/dist/packages/checkbox/checkbox.react.stories.d.ts +12 -0
- package/dist/packages/checkbox/checkbox.react.stories.js +10 -0
- package/dist/packages/checkbox/checkbox.stories.d.ts +25 -0
- package/dist/packages/checkbox/checkbox.stories.js +183 -0
- package/dist/packages/checkbox/checkbox.test.d.ts +1 -0
- package/dist/packages/checkbox/checkbox.test.js +142 -0
- package/dist/packages/checkbox/react.d.ts +5 -0
- package/dist/packages/checkbox/react.js +15 -0
- package/dist/packages/checkbox/styles.d.ts +1 -0
- package/dist/packages/checkbox/styles.js +134 -0
- package/dist/packages/checkbox-group/checkbox-group.a11y.test.d.ts +2 -0
- package/dist/packages/checkbox-group/checkbox-group.a11y.test.js +109 -0
- package/dist/packages/checkbox-group/checkbox-group.d.ts +33 -0
- package/dist/packages/checkbox-group/checkbox-group.js +71 -0
- package/dist/packages/checkbox-group/checkbox-group.js.map +7 -0
- package/dist/packages/checkbox-group/checkbox-group.test.d.ts +2 -0
- package/dist/packages/checkbox-group/checkbox-group.test.js +112 -0
- package/dist/packages/checkbox-group/locales/da/messages.d.mts +1 -0
- package/dist/packages/checkbox-group/locales/da/messages.mjs +1 -0
- package/dist/packages/checkbox-group/locales/en/messages.d.mts +1 -0
- package/dist/packages/checkbox-group/locales/en/messages.mjs +1 -0
- package/dist/packages/checkbox-group/locales/fi/messages.d.mts +1 -0
- package/dist/packages/checkbox-group/locales/fi/messages.mjs +1 -0
- package/dist/packages/checkbox-group/locales/nb/messages.d.mts +1 -0
- package/dist/packages/checkbox-group/locales/nb/messages.mjs +1 -0
- package/dist/packages/checkbox-group/locales/sv/messages.d.mts +1 -0
- package/dist/packages/checkbox-group/locales/sv/messages.mjs +1 -0
- package/dist/packages/checkbox-group/react.d.ts +2 -0
- package/dist/packages/checkbox-group/react.js +11 -0
- package/dist/packages/combobox/combobox.js +11 -11
- package/dist/packages/combobox/combobox.js.map +3 -3
- package/dist/packages/datepicker/datepicker.js +42 -42
- package/dist/packages/datepicker/datepicker.js.map +3 -3
- package/dist/packages/expandable/expandable.js +11 -11
- package/dist/packages/expandable/expandable.js.map +3 -3
- package/dist/packages/i18n.d.ts +2 -0
- package/dist/packages/i18n.js +87 -2
- package/dist/packages/modal-header/modal-header.js +15 -15
- package/dist/packages/modal-header/modal-header.js.map +3 -3
- package/dist/packages/page-indicator/page-indicator.js +7 -7
- package/dist/packages/page-indicator/page-indicator.js.map +3 -3
- package/dist/packages/pagination/pagination.js +24 -24
- package/dist/packages/pagination/pagination.js.map +3 -3
- package/dist/packages/pill/pill.js +10 -10
- package/dist/packages/pill/pill.js.map +3 -3
- package/dist/packages/select/select.js +20 -20
- package/dist/packages/select/select.js.map +3 -3
- package/dist/packages/slider/Slider.d.ts +2 -0
- package/dist/packages/slider/Slider.js +8 -0
- package/dist/packages/slider/index.d.ts +2 -0
- package/dist/packages/slider/index.js +2 -0
- package/dist/packages/slider/locales/da/messages.d.mts +1 -0
- package/dist/packages/slider/locales/da/messages.mjs +1 -0
- package/dist/packages/slider/locales/en/messages.d.mts +1 -0
- package/dist/packages/slider/locales/en/messages.mjs +1 -0
- package/dist/packages/slider/locales/fi/messages.d.mts +1 -0
- package/dist/packages/slider/locales/fi/messages.mjs +1 -0
- package/dist/packages/slider/locales/nb/messages.d.mts +1 -0
- package/dist/packages/slider/locales/nb/messages.mjs +1 -0
- package/dist/packages/slider/locales/sv/messages.d.mts +1 -0
- package/dist/packages/slider/locales/sv/messages.mjs +1 -0
- package/dist/packages/slider/react.d.ts +3 -0
- package/dist/packages/slider/react.js +13 -0
- package/dist/packages/slider/slider.d.ts +64 -0
- package/dist/packages/slider/slider.js +2641 -0
- package/dist/packages/slider/slider.js.map +7 -0
- package/dist/packages/slider/slider.react.stories.d.ts +19 -0
- package/dist/packages/slider/slider.react.stories.js +161 -0
- package/dist/packages/slider/slider.stories.d.ts +26 -0
- package/dist/packages/slider/slider.stories.js +464 -0
- package/dist/packages/slider/slider.test.d.ts +5 -0
- package/dist/packages/slider/slider.test.js +380 -0
- package/dist/packages/slider/styles/w-slider.styles.d.ts +1 -0
- package/dist/packages/slider/styles/w-slider.styles.js +154 -0
- package/dist/packages/slider/styles.d.ts +1 -0
- package/dist/packages/slider/styles.js +2 -0
- package/dist/packages/slider-thumb/SliderThumb.d.ts +2 -0
- package/dist/packages/slider-thumb/SliderThumb.js +8 -0
- package/dist/packages/slider-thumb/oddbird-css-anchor-positioning.d.ts +2 -0
- package/dist/packages/slider-thumb/oddbird-css-anchor-positioning.js +3 -0
- package/dist/packages/slider-thumb/react.d.ts +6 -0
- package/dist/packages/slider-thumb/react.js +15 -0
- package/dist/packages/slider-thumb/slider-thumb.d.ts +72 -0
- package/dist/packages/slider-thumb/slider-thumb.js +2774 -0
- package/dist/packages/slider-thumb/slider-thumb.js.map +7 -0
- package/dist/packages/slider-thumb/styles/w-slider-thumb.styles.d.ts +1 -0
- package/dist/packages/slider-thumb/styles/w-slider-thumb.styles.js +194 -0
- package/dist/packages/step/step.js +13 -13
- package/dist/packages/step/step.js.map +3 -3
- package/dist/packages/step-indicator/step-indicator.a11y.test.js +6 -2
- package/dist/packages/textarea/textarea.a11y.test.js +1 -1
- package/dist/packages/textarea/textarea.test.js +2 -1
- package/dist/packages/textfield/styles/w-textfield.styles.js +6 -0
- package/dist/packages/textfield/textfield.js +7 -1
- package/dist/packages/textfield/textfield.js.map +2 -2
- package/dist/packages/toast/toast.js +13 -13
- package/dist/packages/toast/toast.js.map +3 -3
- package/dist/setup-tests.js +1 -1
- package/dist/web-types.json +328 -1
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { expect, test, vi } from 'vitest';
|
|
3
|
+
import { render } from 'vitest-browser-lit';
|
|
4
|
+
import './checkbox.js';
|
|
5
|
+
const getInput = (el) => el.shadowRoot?.querySelector('input[type="checkbox"]');
|
|
6
|
+
test('toggles checked on click and dispatches change', async () => {
|
|
7
|
+
render(html `<w-checkbox>Check me</w-checkbox>`);
|
|
8
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
9
|
+
const onChange = vi.fn();
|
|
10
|
+
wCheckbox.addEventListener('change', onChange);
|
|
11
|
+
await wCheckbox.updateComplete;
|
|
12
|
+
wCheckbox.click();
|
|
13
|
+
await wCheckbox.updateComplete;
|
|
14
|
+
expect(wCheckbox.checked).toBe(true);
|
|
15
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
16
|
+
});
|
|
17
|
+
test('associates value with form when checked', async () => {
|
|
18
|
+
render(html `
|
|
19
|
+
<form data-testid="form">
|
|
20
|
+
<w-checkbox name="newsletter" value="yes" checked>Sign up</w-checkbox>
|
|
21
|
+
</form>
|
|
22
|
+
`);
|
|
23
|
+
const form = document.querySelector('form');
|
|
24
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
25
|
+
await wCheckbox.updateComplete;
|
|
26
|
+
let data = new FormData(form);
|
|
27
|
+
expect(data.get('newsletter')).toBe('yes');
|
|
28
|
+
wCheckbox.checked = false;
|
|
29
|
+
await wCheckbox.updateComplete;
|
|
30
|
+
data = new FormData(form);
|
|
31
|
+
expect(data.get('newsletter')).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
test('resets to defaultChecked on form reset', async () => {
|
|
34
|
+
render(html `
|
|
35
|
+
<form>
|
|
36
|
+
<w-checkbox name="updates" value="yes" checked>Updates</w-checkbox>
|
|
37
|
+
</form>
|
|
38
|
+
`);
|
|
39
|
+
const form = document.querySelector('form');
|
|
40
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
41
|
+
await wCheckbox.updateComplete;
|
|
42
|
+
wCheckbox.click();
|
|
43
|
+
await wCheckbox.updateComplete;
|
|
44
|
+
expect(wCheckbox.checked).toBe(false);
|
|
45
|
+
form.reset();
|
|
46
|
+
await wCheckbox.updateComplete;
|
|
47
|
+
expect(wCheckbox.checked).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
test('required checkbox reports validity based on checked state', async () => {
|
|
50
|
+
render(html `<w-checkbox name="terms" required>Accept</w-checkbox>`);
|
|
51
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
52
|
+
await expect.poll(() => wCheckbox.checkValidity()).toBe(false);
|
|
53
|
+
expect(wCheckbox.validity.valueMissing).toBe(true);
|
|
54
|
+
expect(wCheckbox.validationMessage).not.toBe('');
|
|
55
|
+
wCheckbox.checked = true;
|
|
56
|
+
await wCheckbox.updateComplete;
|
|
57
|
+
await expect.poll(() => wCheckbox.checkValidity()).toBe(true);
|
|
58
|
+
expect(wCheckbox.validity.valid).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
test('required checkbox shows invalid state after submit and clears after selection', async () => {
|
|
61
|
+
render(html `
|
|
62
|
+
<form>
|
|
63
|
+
<w-checkbox name="terms" required>Accept</w-checkbox>
|
|
64
|
+
<button type="submit">Submit</button>
|
|
65
|
+
</form>
|
|
66
|
+
`);
|
|
67
|
+
const form = document.querySelector('form');
|
|
68
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
69
|
+
const submit = document.querySelector('button[type="submit"]');
|
|
70
|
+
await wCheckbox.updateComplete;
|
|
71
|
+
expect(wCheckbox.hasAttribute('invalid')).toBe(false);
|
|
72
|
+
submit.click();
|
|
73
|
+
await wCheckbox.updateComplete;
|
|
74
|
+
await expect.poll(() => form.checkValidity()).toBe(false);
|
|
75
|
+
expect(wCheckbox.hasAttribute('invalid')).toBe(true);
|
|
76
|
+
wCheckbox.click();
|
|
77
|
+
await wCheckbox.updateComplete;
|
|
78
|
+
await expect.poll(() => form.checkValidity()).toBe(true);
|
|
79
|
+
expect(wCheckbox.hasAttribute('invalid')).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
test('participates in form submission and blocks submit when required', async () => {
|
|
82
|
+
render(html `
|
|
83
|
+
<form>
|
|
84
|
+
<w-checkbox name="newsletter" value="yes" required>Sign up</w-checkbox>
|
|
85
|
+
<button type="submit">Submit</button>
|
|
86
|
+
</form>
|
|
87
|
+
`);
|
|
88
|
+
const form = document.querySelector('form');
|
|
89
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
90
|
+
const submit = document.querySelector('button[type="submit"]');
|
|
91
|
+
const onSubmit = vi.fn(() => {
|
|
92
|
+
const data = new FormData(form);
|
|
93
|
+
expect(data.get('newsletter')).toBe('yes');
|
|
94
|
+
});
|
|
95
|
+
form.addEventListener('submit', (event) => {
|
|
96
|
+
if (!form.checkValidity()) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
onSubmit();
|
|
102
|
+
});
|
|
103
|
+
await wCheckbox.updateComplete;
|
|
104
|
+
await expect.poll(() => form.checkValidity()).toBe(false);
|
|
105
|
+
submit.click();
|
|
106
|
+
await expect.poll(() => form.checkValidity()).toBe(false);
|
|
107
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
108
|
+
wCheckbox.click();
|
|
109
|
+
await wCheckbox.updateComplete;
|
|
110
|
+
submit.click();
|
|
111
|
+
await wCheckbox.updateComplete;
|
|
112
|
+
await expect.poll(() => form.checkValidity()).toBe(true);
|
|
113
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
114
|
+
});
|
|
115
|
+
test('clears indeterminate on click', async () => {
|
|
116
|
+
render(html `<w-checkbox indeterminate>Partial</w-checkbox>`);
|
|
117
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
118
|
+
await wCheckbox.updateComplete;
|
|
119
|
+
expect(wCheckbox.indeterminate).toBe(true);
|
|
120
|
+
const input = getInput(wCheckbox);
|
|
121
|
+
expect(input).not.toBeNull();
|
|
122
|
+
expect(input?.indeterminate).toBe(true);
|
|
123
|
+
wCheckbox.click();
|
|
124
|
+
await wCheckbox.updateComplete;
|
|
125
|
+
expect(wCheckbox.indeterminate).toBe(false);
|
|
126
|
+
expect(wCheckbox.checked).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
test('does not toggle or emit change when disabled', async () => {
|
|
129
|
+
render(html `<w-checkbox disabled>Disabled</w-checkbox>`);
|
|
130
|
+
const wCheckbox = document.querySelector('w-checkbox');
|
|
131
|
+
const onChange = vi.fn();
|
|
132
|
+
wCheckbox.addEventListener('change', onChange);
|
|
133
|
+
await wCheckbox.updateComplete;
|
|
134
|
+
expect(wCheckbox.checked).toBe(false);
|
|
135
|
+
const input = getInput(wCheckbox);
|
|
136
|
+
expect(input).not.toBeNull();
|
|
137
|
+
expect(input?.disabled).toBe(true);
|
|
138
|
+
wCheckbox.click();
|
|
139
|
+
await wCheckbox.updateComplete;
|
|
140
|
+
expect(wCheckbox.checked).toBe(false);
|
|
141
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createComponent } from '@lit/react';
|
|
2
|
+
import { LitElement } from 'lit';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
// decouple from CDN by providing a dummy class
|
|
5
|
+
class Component extends LitElement {
|
|
6
|
+
}
|
|
7
|
+
export const Checkbox = createComponent({
|
|
8
|
+
tagName: 'w-checkbox',
|
|
9
|
+
elementClass: Component,
|
|
10
|
+
react: React,
|
|
11
|
+
events: {
|
|
12
|
+
onChange: 'change',
|
|
13
|
+
onchange: 'change',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import("lit").CSSResult;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const styles = css `
|
|
3
|
+
:host {
|
|
4
|
+
--_label-font-size: var(--w-c-checkbox-label-font-size, var(--w-font-size-m));
|
|
5
|
+
--_label-line-height: var(--w-c-checkbox-label-line-height, var(--w-line-height-m));
|
|
6
|
+
|
|
7
|
+
--_control-size: var(--w-c-checkbox-control-size, 2rem);
|
|
8
|
+
--_gap: var(--w-c-checkbox-gap, 8px);
|
|
9
|
+
--_radius: var(--w-c-checkbox-radius, 4px);
|
|
10
|
+
--_border-width: var(--w-c-checkbox-border-width, 1px);
|
|
11
|
+
|
|
12
|
+
--_bg-default: var(--w-c-checkbox-bg, var(--w-s-color-background));
|
|
13
|
+
--_border-default: var(--w-c-checkbox-border-color, var(--w-s-color-border-strong));
|
|
14
|
+
--_icon-color: var(--w-c-checkbox-icon-color, var(--w-s-color-icon-inverted));
|
|
15
|
+
|
|
16
|
+
--_bg-checked: var(--w-c-checkbox-bg-checked, var(--w-s-color-background-primary));
|
|
17
|
+
--_border-checked: var(--w-c-checkbox-border-color-checked, var(--w-s-color-border-primary));
|
|
18
|
+
--_checked-icon: var(--w-c-checkbox-checked-icon, var(--w-icon-toggle-checked));
|
|
19
|
+
|
|
20
|
+
--_border-invalid: var(--w-c-checkbox-border-color-invalid, var(--w-s-color-border-negative));
|
|
21
|
+
--_bg-invalid-checked: var(--w-c-checkbox-bg-invalid-checked, var(--w-s-color-background-negative));
|
|
22
|
+
|
|
23
|
+
--_bg-disabled: var(--w-c-checkbox-bg-disabled, var(--w-s-color-background-disabled-subtle));
|
|
24
|
+
--_border-disabled: var(--w-c-checkbox-border-color-disabled, var(--w-s-color-border-disabled));
|
|
25
|
+
--_bg-disabled-checked: var(--w-c-checkbox-bg-disabled-checked, var(--w-s-color-background-disabled));
|
|
26
|
+
|
|
27
|
+
--_outline-width: var(--w-c-checkbox-outline-width, 2px);
|
|
28
|
+
--_outline-color: var(--w-c-checkbox-outline-color, var(--w-s-color-border-focus));
|
|
29
|
+
--_outline-offset: var(--w-c-checkbox-outline-offset, var(--w-outline-offset, 1px));
|
|
30
|
+
|
|
31
|
+
--_transition: var(--w-c-checkbox-transition, all 150ms cubic-bezier(0.4, 0, 0.2, 1));
|
|
32
|
+
|
|
33
|
+
--_bg: var(--_bg-default);
|
|
34
|
+
--_border-color: var(--_border-default);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
:host([type='checkbox']) {
|
|
38
|
+
--_radius: var(--w-c-checkbox-radius, 4px);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:host([checked]),
|
|
42
|
+
:host([indeterminate]) {
|
|
43
|
+
--_bg: var(--_bg-checked);
|
|
44
|
+
--_border-color: var(--_border-checked);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:host([invalid]) {
|
|
48
|
+
--_border-color: var(--_border-invalid);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:host([invalid][checked]),
|
|
52
|
+
:host([invalid][indeterminate]) {
|
|
53
|
+
--_bg: var(--_bg-invalid-checked);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:host([disabled]) {
|
|
57
|
+
--_bg: var(--_bg-disabled);
|
|
58
|
+
--_border-color: var(--_border-disabled);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:host([disabled][checked]),
|
|
62
|
+
:host([disabled][indeterminate]) {
|
|
63
|
+
--_bg: var(--_bg-disabled-checked);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[part~='label'] {
|
|
67
|
+
display: block;
|
|
68
|
+
font-size: var(--_label-font-size);
|
|
69
|
+
line-height: var(--_label-line-height);
|
|
70
|
+
user-select: none;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[part='base'] {
|
|
75
|
+
display: grid;
|
|
76
|
+
grid-template-columns: var(--_control-size) max-content;
|
|
77
|
+
gap: var(--_gap);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
[part='input'] {
|
|
81
|
+
position: absolute;
|
|
82
|
+
padding: 0;
|
|
83
|
+
margin: 0;
|
|
84
|
+
opacity: 0;
|
|
85
|
+
pointer-events: none;
|
|
86
|
+
inset: 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[part='control'] {
|
|
90
|
+
position: relative;
|
|
91
|
+
display: block;
|
|
92
|
+
height: var(--_control-size);
|
|
93
|
+
width: var(--_control-size);
|
|
94
|
+
flex-shrink: 0;
|
|
95
|
+
|
|
96
|
+
border-width: var(--_border-width);
|
|
97
|
+
border-style: solid;
|
|
98
|
+
border-color: var(--_border-color);
|
|
99
|
+
border-radius: var(--_radius);
|
|
100
|
+
|
|
101
|
+
background-color: var(--_bg);
|
|
102
|
+
color: var(--_icon-color);
|
|
103
|
+
|
|
104
|
+
cursor: pointer;
|
|
105
|
+
user-select: none;
|
|
106
|
+
appearance: none;
|
|
107
|
+
transition: var(--_transition);
|
|
108
|
+
|
|
109
|
+
font-weight: 700;
|
|
110
|
+
text-align: center;
|
|
111
|
+
line-height: var(--w-line-height-xs);
|
|
112
|
+
font-size: var(--w-font-size-m);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:host(:focus-visible) {
|
|
116
|
+
outline: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
[part='control']:has(> [part='input']:focus-visible:not(:disabled)),
|
|
120
|
+
:host(:focus-visible) [part='control'] {
|
|
121
|
+
outline: var(--_outline-width) solid var(--_outline-color);
|
|
122
|
+
outline-offset: var(--_outline-offset);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* checked icon (keep driven by actual input state for parity) */
|
|
126
|
+
[part='control']:has(:checked) {
|
|
127
|
+
background-image: var(--_checked-icon);
|
|
128
|
+
background-position: center;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@media (prefers-reduced-motion: reduce) {
|
|
132
|
+
:host { --w-c-checkbox-transition: none; }
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { i18n } from '@lingui/core';
|
|
2
|
+
import { userEvent } from '@vitest/browser/context';
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
import { render } from 'vitest-browser-lit';
|
|
6
|
+
import './checkbox-group.js';
|
|
7
|
+
import '../checkbox/checkbox.js';
|
|
8
|
+
// Initialize i18n with English locale for tests
|
|
9
|
+
i18n.load('en', {
|
|
10
|
+
'checkbox-group.label.optional': ['(optional)'],
|
|
11
|
+
'checkbox-group.validation.required': ['At least one selection is required.'],
|
|
12
|
+
});
|
|
13
|
+
i18n.activate('en');
|
|
14
|
+
const REQUIRED_MESSAGE = 'At least one selection is required.';
|
|
15
|
+
describe('w-checkbox-group accessibility (WCAG 2.2)', () => {
|
|
16
|
+
describe('axe-core automated checks', () => {
|
|
17
|
+
test('default state has no violations', async () => {
|
|
18
|
+
const page = render(html `
|
|
19
|
+
<w-checkbox-group label="Preferences">
|
|
20
|
+
<w-checkbox>One</w-checkbox>
|
|
21
|
+
<w-checkbox>Two</w-checkbox>
|
|
22
|
+
</w-checkbox-group>
|
|
23
|
+
`);
|
|
24
|
+
await expect(page).toHaveNoAxeViolations();
|
|
25
|
+
});
|
|
26
|
+
test('with help text has no violations', async () => {
|
|
27
|
+
const page = render(html `
|
|
28
|
+
<w-checkbox-group label="Preferences" help-text="Select one">
|
|
29
|
+
<w-checkbox>One</w-checkbox>
|
|
30
|
+
<w-checkbox>Two</w-checkbox>
|
|
31
|
+
</w-checkbox-group>
|
|
32
|
+
`);
|
|
33
|
+
await expect(page).toHaveNoAxeViolations();
|
|
34
|
+
});
|
|
35
|
+
test('required invalid state has no violations', async () => {
|
|
36
|
+
const page = render(html `
|
|
37
|
+
<w-checkbox-group label="Preferences" required help-text="Select one">
|
|
38
|
+
<w-checkbox>One</w-checkbox>
|
|
39
|
+
<w-checkbox>Two</w-checkbox>
|
|
40
|
+
</w-checkbox-group>
|
|
41
|
+
`);
|
|
42
|
+
const groupEl = document.querySelector('w-checkbox-group');
|
|
43
|
+
groupEl.reportValidity?.();
|
|
44
|
+
await expect(page).toHaveNoAxeViolations();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('WCAG 1.3.1 - Info and Relationships', () => {
|
|
48
|
+
test('group has accessible name from label', async () => {
|
|
49
|
+
const page = render(html `
|
|
50
|
+
<w-checkbox-group label="Preferences">
|
|
51
|
+
<w-checkbox>One</w-checkbox>
|
|
52
|
+
<w-checkbox>Two</w-checkbox>
|
|
53
|
+
</w-checkbox-group>
|
|
54
|
+
`);
|
|
55
|
+
await expect.element(page.getByRole('group', { name: 'Preferences' })).toBeVisible();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('WCAG 3.3.1 - Error Identification', () => {
|
|
59
|
+
test('invalid state is indicated via aria-invalid', async () => {
|
|
60
|
+
const page = render(html `
|
|
61
|
+
<w-checkbox-group label="Preferences" required help-text="Select one">
|
|
62
|
+
<w-checkbox>One</w-checkbox>
|
|
63
|
+
<w-checkbox>Two</w-checkbox>
|
|
64
|
+
</w-checkbox-group>
|
|
65
|
+
`);
|
|
66
|
+
const groupEl = document.querySelector('w-checkbox-group');
|
|
67
|
+
groupEl.reportValidity?.();
|
|
68
|
+
await expect.element(page.getByRole('group', { name: 'Preferences' })).toHaveAttribute('aria-invalid', 'true');
|
|
69
|
+
await expect.element(page.getByText(REQUIRED_MESSAGE)).toBeVisible();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('WCAG 3.3.2 - Labels or Instructions', () => {
|
|
73
|
+
test('help text is programmatically associated', async () => {
|
|
74
|
+
const page = render(html `
|
|
75
|
+
<w-checkbox-group label="Preferences" help-text="Select one">
|
|
76
|
+
<w-checkbox>One</w-checkbox>
|
|
77
|
+
<w-checkbox>Two</w-checkbox>
|
|
78
|
+
</w-checkbox-group>
|
|
79
|
+
`);
|
|
80
|
+
await expect.element(page.getByRole('group', { name: 'Preferences' })).toHaveAccessibleDescription('Select one');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('WCAG 2.1.1 - Keyboard', () => {
|
|
84
|
+
test('tab moves through checkboxes and space toggles', async () => {
|
|
85
|
+
const page = render(html `
|
|
86
|
+
<button>Before</button>
|
|
87
|
+
<w-checkbox-group label="Preferences">
|
|
88
|
+
<w-checkbox>One</w-checkbox>
|
|
89
|
+
<w-checkbox>Two</w-checkbox>
|
|
90
|
+
</w-checkbox-group>
|
|
91
|
+
<button>After</button>
|
|
92
|
+
`);
|
|
93
|
+
const checkboxes = Array.from(document.querySelectorAll('w-checkbox'));
|
|
94
|
+
const firstCheckbox = checkboxes[0];
|
|
95
|
+
const secondCheckbox = checkboxes[1];
|
|
96
|
+
await firstCheckbox?.updateComplete;
|
|
97
|
+
firstCheckbox?.focus();
|
|
98
|
+
await expect.poll(() => firstCheckbox?.shadowRoot?.activeElement?.tagName).toBe('INPUT');
|
|
99
|
+
expect(firstCheckbox.checked).toBe(false);
|
|
100
|
+
await userEvent.keyboard('[Space]');
|
|
101
|
+
await expect.poll(() => firstCheckbox.checked).toBe(true);
|
|
102
|
+
await secondCheckbox?.updateComplete;
|
|
103
|
+
secondCheckbox?.focus();
|
|
104
|
+
await expect.poll(() => secondCheckbox?.shadowRoot?.activeElement?.tagName).toBe('INPUT');
|
|
105
|
+
await userEvent.keyboard('[Space]');
|
|
106
|
+
await expect.poll(() => secondCheckbox.checked).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
declare const WCheckboxGroup_base: import("@open-wc/form-control").Constructor<import("@open-wc/form-control").FormControlInterface> & typeof LitElement;
|
|
3
|
+
export declare class WCheckboxGroup extends WCheckboxGroup_base {
|
|
4
|
+
#private;
|
|
5
|
+
/** The group label displayed above the checkboxes. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** The name applied to child checkboxes when they do not provide one. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Whether to show optional text next to the label. */
|
|
10
|
+
optional: boolean;
|
|
11
|
+
helpText: string;
|
|
12
|
+
/** Makes the checkbox group required. */
|
|
13
|
+
required: boolean;
|
|
14
|
+
/** Marks the checkbox group as invalid. */
|
|
15
|
+
invalid: boolean;
|
|
16
|
+
static styles: import("lit").CSSResult;
|
|
17
|
+
render(): import("lit").TemplateResult<1>;
|
|
18
|
+
connectedCallback(): void;
|
|
19
|
+
disconnectedCallback(): void;
|
|
20
|
+
/** Checks whether the group passes constraint validation */
|
|
21
|
+
checkValidity(): boolean;
|
|
22
|
+
/** Checks validity and shows the validation message if invalid */
|
|
23
|
+
reportValidity(): boolean;
|
|
24
|
+
/** Sets focus on the checkbox group. */
|
|
25
|
+
focus(options?: FocusOptions): void;
|
|
26
|
+
updated(changedProperties: PropertyValues<this>): void;
|
|
27
|
+
}
|
|
28
|
+
declare global {
|
|
29
|
+
interface HTMLElementTagNameMap {
|
|
30
|
+
'w-checkbox-group': WCheckboxGroup;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var it=Object.create;var fe=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var Te=s=>{throw TypeError(s)};var Ve=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var lt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nt(e))!ot.call(s,i)&&i!==t&&fe(s,i,{get:()=>e[i],enumerable:!(r=Le(e,i))||r.enumerable});return s};var ct=(s,e,t)=>(t=s!=null?it(at(s)):{},lt(e||!s||!s.__esModule?fe(t,"default",{value:s,enumerable:!0}):t,s));var A=(s,e,t,r)=>{for(var i=r>1?void 0:r?Le(e,t):e,l=s.length-1,a;l>=0;l--)(a=s[l])&&(i=(r?a(e,t,i):a(i))||i);return r&&i&&fe(e,t,i),i};var me=(s,e,t)=>e.has(s)||Te("Cannot "+t);var E=(s,e,t)=>(me(s,e,"read from private field"),t?t.call(s):e.get(s)),x=(s,e,t)=>e.has(s)?Te("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),N=(s,e,t,r)=>(me(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),d=(s,e,t)=>(me(s,e,"access private method"),t);var Oe=Ve(P=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.errorMessages=P.ErrorType=void 0;var R;(function(s){s.MalformedUnicode="MALFORMED_UNICODE",s.MalformedHexadecimal="MALFORMED_HEXADECIMAL",s.CodePointLimit="CODE_POINT_LIMIT",s.OctalDeprecation="OCTAL_DEPRECATION",s.EndOfString="END_OF_STRING"})(R=P.ErrorType||(P.ErrorType={}));P.errorMessages=new Map([[R.MalformedUnicode,"malformed Unicode character escape sequence"],[R.MalformedHexadecimal,"malformed hexadecimal character escape sequence"],[R.CodePointLimit,"Unicode codepoint must not be greater than 0x10FFFF in escape sequence"],[R.OctalDeprecation,'"0"-prefixed octal literals and octal escape sequences are deprecated; for octal literals use the "0o" prefix instead'],[R.EndOfString,"malformed escape sequence at end of string"]])});var Ne=Ve(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.unraw=k.errorMessages=k.ErrorType=void 0;var b=Oe();Object.defineProperty(k,"ErrorType",{enumerable:!0,get:function(){return b.ErrorType}});Object.defineProperty(k,"errorMessages",{enumerable:!0,get:function(){return b.errorMessages}});function ut(s){return!s.match(/[^a-f0-9]/i)?parseInt(s,16):NaN}function Y(s,e,t){let r=ut(s);if(Number.isNaN(r)||t!==void 0&&t!==s.length)throw new SyntaxError(b.errorMessages.get(e));return r}function dt(s){let e=Y(s,b.ErrorType.MalformedHexadecimal,2);return String.fromCharCode(e)}function Ie(s,e){let t=Y(s,b.ErrorType.MalformedUnicode,4);if(e!==void 0){let r=Y(e,b.ErrorType.MalformedUnicode,4);return String.fromCharCode(t,r)}return String.fromCharCode(t)}function ht(s){return s.charAt(0)==="{"&&s.charAt(s.length-1)==="}"}function ft(s){if(!ht(s))throw new SyntaxError(b.errorMessages.get(b.ErrorType.MalformedUnicode));let e=s.slice(1,-1),t=Y(e,b.ErrorType.MalformedUnicode);try{return String.fromCodePoint(t)}catch(r){throw r instanceof RangeError?new SyntaxError(b.errorMessages.get(b.ErrorType.CodePointLimit)):r}}function mt(s,e=!1){if(e)throw new SyntaxError(b.errorMessages.get(b.ErrorType.OctalDeprecation));let t=parseInt(s,8);return String.fromCharCode(t)}var pt=new Map([["b","\b"],["f","\f"],["n",`
|
|
2
|
+
`],["r","\r"],["t"," "],["v","\v"],["0","\0"]]);function gt(s){return pt.get(s)||s}var vt=/\\(?:(\\)|x([\s\S]{0,2})|u(\{[^}]*\}?)|u([\s\S]{4})\\u([^{][\s\S]{0,3})|u([\s\S]{0,4})|([0-3]?[0-7]{1,2})|([\s\S])|$)/g;function Ae(s,e=!1){return s.replace(vt,function(t,r,i,l,a,n,u,m,C){if(r!==void 0)return"\\";if(i!==void 0)return dt(i);if(l!==void 0)return ft(l);if(a!==void 0)return Ie(a,n);if(u!==void 0)return Ie(u);if(m==="0")return"\0";if(m!==void 0)return mt(m,!e);if(C!==void 0)return gt(C);throw new SyntaxError(b.errorMessages.get(b.ErrorType.EndOfString))})}k.unraw=Ae;k.default=Ae});var qe=ct(Ne(),1);var O=s=>typeof s=="string",bt=s=>typeof s=="function",Pe=new Map,Ue="en";function be(s){return[...Array.isArray(s)?s:[s],Ue]}function _e(s,e,t){let r=be(s);t||(t="default");let i;if(typeof t=="string")switch(i={day:"numeric",month:"short",year:"numeric"},t){case"full":i.weekday="long";case"long":i.month="long";break;case"short":i.month="numeric";break}else i=t;return ee(()=>te("date",r,t),()=>new Intl.DateTimeFormat(r,i)).format(O(e)?new Date(e):e)}function _t(s,e,t){let r;if(t||(t="default"),typeof t=="string")switch(r={second:"numeric",minute:"numeric",hour:"numeric"},t){case"full":case"long":r.timeZoneName="short";break;case"short":delete r.second}else r=t;return _e(s,e,r)}function pe(s,e,t){let r=be(s);return ee(()=>te("number",r,t),()=>new Intl.NumberFormat(r,t)).format(e)}function De(s,e,t,{offset:r=0,...i}){var n,u;let l=be(s),a=e?ee(()=>te("plural-ordinal",l),()=>new Intl.PluralRules(l,{type:"ordinal"})):ee(()=>te("plural-cardinal",l),()=>new Intl.PluralRules(l,{type:"cardinal"}));return(u=(n=i[t])!=null?n:i[a.select(t-r)])!=null?u:i.other}function ee(s,e){let t=s(),r=Pe.get(t);return r||(r=e(),Pe.set(t,r)),r}function te(s,e,t){let r=e.join("-");return`${s}-${r}-${JSON.stringify(t)}`}var $e=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/,He="%__lingui_octothorpe__%",yt=(s,e,t={})=>{let r=e||s,i=a=>typeof a=="object"?a:t[a],l=(a,n)=>{let u=Object.keys(t).length?i("number"):void 0,m=pe(r,a,u);return n.replace(new RegExp(He,"g"),m)};return{plural:(a,n)=>{let{offset:u=0}=n,m=De(r,!1,a,n);return l(a-u,m)},selectordinal:(a,n)=>{let{offset:u=0}=n,m=De(r,!0,a,n);return l(a-u,m)},select:wt,number:(a,n)=>pe(r,a,i(n)||{style:n}),date:(a,n)=>_e(r,a,i(n)||n),time:(a,n)=>_t(r,a,i(n)||n)}},wt=(s,e)=>{var t;return(t=e[s])!=null?t:e.other};function Mt(s,e,t){return(r={},i)=>{let l=yt(e,t,i),a=(u,m=!1)=>Array.isArray(u)?u.reduce((C,L)=>{if(L==="#"&&m)return C+He;if(O(L))return C+L;let[$,w,T]=L,V={};w==="plural"||w==="selectordinal"||w==="select"?Object.entries(T).forEach(([I,J])=>{V[I]=a(J,w==="plural"||w==="selectordinal")}):V=T;let _;if(w){let I=l[w];_=I(r[$],V)}else _=r[$];return _==null?C:C+_},""):u,n=a(s);return O(n)&&$e.test(n)?(0,qe.unraw)(n):O(n)?n:n?String(n):""}}var Ct=Object.defineProperty,Et=(s,e,t)=>e in s?Ct(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,xt=(s,e,t)=>(Et(s,typeof e!="symbol"?e+"":e,t),t),ge=class{constructor(){xt(this,"_events",{})}on(e,t){var i;var r;return(i=(r=this._events)[e])!=null||(r[e]=[]),this._events[e].push(t),()=>this.removeListener(e,t)}removeListener(e,t){let r=this._getListeners(e);if(!r)return;let i=r.indexOf(t);~i&&r.splice(i,1)}emit(e,...t){let r=this._getListeners(e);r&&r.map(i=>i.apply(this,t))}_getListeners(e){let t=this._events[e];return Array.isArray(t)?t:!1}},Ft=Object.defineProperty,St=(s,e,t)=>e in s?Ft(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,D=(s,e,t)=>(St(s,typeof e!="symbol"?e+"":e,t),t),ve=class extends ge{constructor(e){var t;super(),D(this,"_locale",""),D(this,"_locales"),D(this,"_localeData",{}),D(this,"_messages",{}),D(this,"_missing"),D(this,"_messageCompiler"),D(this,"t",this._.bind(this)),e.missing!=null&&(this._missing=e.missing),e.messages!=null&&this.load(e.messages),e.localeData!=null&&this.loadLocaleData(e.localeData),(typeof e.locale=="string"||e.locales)&&this.activate((t=e.locale)!=null?t:Ue,e.locales)}get locale(){return this._locale}get locales(){return this._locales}get messages(){var e;return(e=this._messages[this._locale])!=null?e:{}}get localeData(){var e;return(e=this._localeData[this._locale])!=null?e:{}}_loadLocaleData(e,t){let r=this._localeData[e];r?Object.assign(r,t):this._localeData[e]=t}setMessagesCompiler(e){return this._messageCompiler=e,this}loadLocaleData(e,t){typeof e=="string"?this._loadLocaleData(e,t):Object.keys(e).forEach(r=>this._loadLocaleData(r,e[r])),this.emit("change")}_load(e,t){let r=this._messages[e];r?Object.assign(r,t):this._messages[e]=t}load(e,t){typeof e=="string"&&typeof t=="object"?this._load(e,t):Object.entries(e).forEach(([r,i])=>this._load(r,i)),this.emit("change")}loadAndActivate({locale:e,locales:t,messages:r}){this._locale=e,this._locales=t||void 0,this._messages[this._locale]=r,this.emit("change")}activate(e,t){this._locale=e,this._locales=t,this.emit("change")}_(e,t,r){if(!this.locale)throw new Error("Lingui: Attempted to call a translation function without setting a locale.\nMake sure to call `i18n.activate(locale)` before using Lingui functions.\nThis issue may also occur due to a race condition in your initialization logic.");let i=r==null?void 0:r.message;e||(e=""),O(e)||(t=e.values||t,i=e.message,e=e.id);let l=this.messages[e],a=l===void 0,n=this._missing;if(n&&a)return bt(n)?n(this._locale,e):n;a&&this.emit("missing",{id:e,locale:this._locale});let u=l||i||e;return O(u)&&(this._messageCompiler?u=this._messageCompiler(u):console.warn(`Uncompiled message detected! Message:
|
|
3
|
+
|
|
4
|
+
> ${u}
|
|
5
|
+
|
|
6
|
+
That means you use raw catalog or your catalog doesn't have a translation for the message and fallback was used.
|
|
7
|
+
ICU features such as interpolation and plurals will not work properly for that message.
|
|
8
|
+
|
|
9
|
+
Please compile your catalog first.
|
|
10
|
+
`)),O(u)&&$e.test(u)?JSON.parse(`"${u}"`):O(u)?u:Mt(u,this._locale,this._locales)(t,r==null?void 0:r.formats)}date(e,t){return _e(this._locales||this._locale,e,t)}number(e,t){return pe(this._locales||this._locale,e,t)}};function kt(s={}){return new ve(s)}var y=kt();var f=function(s,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(s):r?r.value:e.get(s)},g=function(s,e,t,r,i){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?s!==e||!i:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?i.call(s,t):i?i.value=t:e.set(s,t),t};function Re(s){var e,t,r,i,l,a,n,u,m,C,L,$,w,T,V,_,I,J,ue;class rt extends s{constructor(...c){var h,p,v;super(...c),e.add(this),this.internals=this.attachInternals(),t.set(this,!1),r.set(this,!1),i.set(this,!1),l.set(this,void 0),a.set(this,void 0),n.set(this,!0),m.set(this,""),C.set(this,()=>{g(this,i,!0,"f"),g(this,t,!0,"f"),f(this,e,"m",_).call(this)}),L.set(this,()=>{g(this,t,!1,"f"),f(this,e,"m",I).call(this,this.shouldFormValueUpdate()?f(this,m,"f"):""),!this.validity.valid&&f(this,i,"f")&&g(this,r,!0,"f");let S=f(this,e,"m",_).call(this);this.validationMessageCallback&&this.validationMessageCallback(S?this.internals.validationMessage:"")}),$.set(this,()=>{var S;f(this,n,"f")&&this.validationTarget&&(this.internals.setValidity(this.validity,this.validationMessage,this.validationTarget),g(this,n,!1,"f")),g(this,i,!0,"f"),g(this,r,!0,"f"),f(this,e,"m",_).call(this),(S=this===null||this===void 0?void 0:this.validationMessageCallback)===null||S===void 0||S.call(this,this.showError?this.internals.validationMessage:"")}),w.set(this,void 0),T.set(this,!1),V.set(this,Promise.resolve()),(h=this.addEventListener)===null||h===void 0||h.call(this,"focus",f(this,C,"f")),(p=this.addEventListener)===null||p===void 0||p.call(this,"blur",f(this,L,"f")),(v=this.addEventListener)===null||v===void 0||v.call(this,"invalid",f(this,$,"f")),this.setValue(null)}static get formAssociated(){return!0}static get validators(){return this.formControlValidators||[]}static get observedAttributes(){let c=this.validators.map(v=>v.attribute).flat(),h=super.observedAttributes||[];return[...new Set([...h,...c])]}static getValidator(c){return this.validators.find(h=>h.attribute===c)||null}static getValidators(c){return this.validators.filter(h=>{var p;if(h.attribute===c||!((p=h.attribute)===null||p===void 0)&&p.includes(c))return!0})}get form(){return this.internals.form}get showError(){return f(this,e,"m",_).call(this)}checkValidity(){return this.internals.checkValidity()}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}attributeChangedCallback(c,h,p){var v;(v=super.attributeChangedCallback)===null||v===void 0||v.call(this,c,h,p);let G=this.constructor.getValidators(c);G!=null&&G.length&&this.validationTarget&&this.setValue(f(this,m,"f"))}setValue(c){var h;g(this,r,!1,"f"),(h=this.validationMessageCallback)===null||h===void 0||h.call(this,""),g(this,m,c,"f");let v=this.shouldFormValueUpdate()?c:null;this.internals.setFormValue(v),f(this,e,"m",I).call(this,v),this.valueChangedCallback&&this.valueChangedCallback(v),f(this,e,"m",_).call(this)}shouldFormValueUpdate(){return!0}get validationComplete(){return new Promise(c=>c(f(this,V,"f")))}formResetCallback(){var c,h;g(this,i,!1,"f"),g(this,r,!1,"f"),f(this,e,"m",_).call(this),(c=this.resetFormControl)===null||c===void 0||c.call(this),(h=this.validationMessageCallback)===null||h===void 0||h.call(this,f(this,e,"m",_).call(this)?this.validationMessage:"")}}return t=new WeakMap,r=new WeakMap,i=new WeakMap,l=new WeakMap,a=new WeakMap,n=new WeakMap,m=new WeakMap,C=new WeakMap,L=new WeakMap,$=new WeakMap,w=new WeakMap,T=new WeakMap,V=new WeakMap,e=new WeakSet,u=function(){let c=this.getRootNode(),h=`${this.localName}[name="${this.getAttribute("name")}"]`;return c.querySelectorAll(h)},_=function(){if(this.hasAttribute("disabled"))return!1;let c=f(this,r,"f")||f(this,i,"f")&&!this.validity.valid&&!f(this,t,"f");return c&&this.internals.states?this.internals.states.add("--show-error"):this.internals.states&&this.internals.states.delete("--show-error"),c},I=function(c){let h=this.constructor,p={},v=h.validators,S=[],G=v.some(M=>M.isValid instanceof Promise);f(this,T,"f")||(g(this,V,new Promise(M=>{g(this,w,M,"f")}),"f"),g(this,T,!0,"f")),f(this,l,"f")&&(f(this,l,"f").abort(),g(this,a,f(this,l,"f"),"f"));let K=new AbortController;g(this,l,K,"f");let X,ke=!1;v.length&&(v.forEach(M=>{let de=M.key||"customError",H=M.isValid(this,c,K.signal);H instanceof Promise?(S.push(H),H.then(he=>{he!=null&&(p[de]=!he,X=f(this,e,"m",ue).call(this,M,c),f(this,e,"m",J).call(this,p,X))})):(p[de]=!H,this.validity[de]!==!H&&(ke=!0),!H&&!X&&(X=f(this,e,"m",ue).call(this,M,c)))}),Promise.allSettled(S).then(()=>{var M;K!=null&&K.signal.aborted||(g(this,T,!1,"f"),(M=f(this,w,"f"))===null||M===void 0||M.call(this))}),(ke||!G)&&f(this,e,"m",J).call(this,p,X))},J=function(c,h){if(this.validationTarget)this.internals.setValidity(c,h,this.validationTarget),g(this,n,!1,"f");else{if(this.internals.setValidity(c,h),this.internals.validity.valid)return;g(this,n,!0,"f")}},ue=function(c,h){if(this.validityCallback){let p=this.validityCallback(c.key||"customError");if(p)return p}return c.message instanceof Function?c.message(this,h):c.message},rt}import{css as At,html as re,LitElement as Nt,nothing as we}from"lit";import{property as j}from"lit/decorators.js";import{ifDefined as Me}from"lit/directives/if-defined.js";var Lt=["en","nb","fi","da","sv"],ye="en",se=s=>Lt.find(e=>s===e||s.toLowerCase().includes(e))||ye;function ze(){if(typeof window=="undefined"){let s=process.env.NMP_LANGUAGE||Intl.DateTimeFormat().resolvedOptions().locale;return se(s)}try{let s=We(document);if(s)return se(s);let e=It();if(e)return se(e);let t=We(Ge());return t?se(t):ye}catch(s){return console.warn("could not detect locale, falling back to source locale",s),ye}}var Je=(s,e,t,r,i)=>{y.load("en",s),y.load("nb",e),y.load("fi",t),y.load("da",r),y.load("sv",i);let l=ze();y.activate(l),Be(),Vt()},Tt="warp-i18n-change";function Be(){typeof window!="undefined"&&window.dispatchEvent(new Event(Tt))}var je=!1;function Vt(){if(je||typeof window=="undefined"||!(document!=null&&document.documentElement))return;je=!0;let s=()=>{let i=ze();y.locale!==i&&(y.activate(i),Be())},e=new MutationObserver(i=>{for(let l of i)if(l.type==="attributes"&&l.attributeName==="lang"){s();break}});e.observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]});let t=Ge();t&&t.documentElement&&t!==document&&e.observe(t.documentElement,{attributes:!0,attributeFilter:["lang"]});let r=Ot();r&&e.observe(r,{attributes:!0,attributeFilter:["lang"]})}function Ge(){var s,e;try{return(e=(s=window.parent)==null?void 0:s.document)!=null?e:null}catch(t){return null}}function We(s){var e,t;try{return(t=(e=s==null?void 0:s.documentElement)==null?void 0:e.lang)!=null?t:""}catch(r){return""}}function Ot(){var s;try{return(s=window.frameElement)!=null?s:null}catch(e){return null}}function It(){var s,e,t;try{return(t=(e=(s=window.frameElement)==null?void 0:s.getAttribute)==null?void 0:e.call(s,"lang"))!=null?t:""}catch(r){return""}}var Ke=JSON.parse('{"checkbox-group.validation.required":["Mindst \xE9n valgt mulighed er p\xE5kr\xE6vet."],"checkbox-group.label.optional":["Valgfri"]}');var Xe=JSON.parse('{"checkbox-group.validation.required":["At least one selection is required."],"checkbox-group.label.optional":["Optional"]}');var Qe=JSON.parse('{"checkbox-group.validation.required":["V\xE4hint\xE4\xE4n yksi valinta vaaditaan."],"checkbox-group.label.optional":["Valinnainen"]}');var Ze=JSON.parse('{"checkbox-group.validation.required":["Minst ett valg er p\xE5krevd."],"checkbox-group.label.optional":["Valgfri"]}');var Ye=JSON.parse('{"checkbox-group.validation.required":["Minst ett val kr\xE4vs."],"checkbox-group.label.optional":["Valfritt"]}');Je(Xe,Ze,Qe,Ke,Ye);var Pt=()=>y._({id:"checkbox-group.validation.required",message:"At least one selection is required.",comment:"Shown when required checkbox group has no selections"}),W,Z,U,z,ae,oe,le,o,ie,ce,Ce,Ee,ne,xe,Q,et,tt,Fe,st,q,Se,F=class extends Re(Nt){constructor(){super(...arguments);x(this,o);x(this,W,!1);x(this,Z,!1);x(this,U,!1);x(this,z);x(this,ae,()=>{d(this,o,ie).call(this),d(this,o,q).call(this),this.requestUpdate()});x(this,oe,()=>{d(this,o,ie).call(this),d(this,o,q).call(this),this.requestUpdate()});x(this,le,()=>{d(this,o,Ee).call(this),d(this,o,q).call(this),this.requestUpdate()});x(this,ce,()=>{this.requestUpdate()})}render(){let t=d(this,o,Ce).call(this)>0,i=this.required&&!t&&E(this,W),l=this.invalid||i,a=l?d(this,o,et).call(this):this.helpText,n=a?"checkbox-group__help":void 0,u=this.label?"checkbox-group__label":void 0,m=l?"true":void 0;return re`
|
|
11
|
+
<div class="wrapper">
|
|
12
|
+
${this.label?re`
|
|
13
|
+
<div class="label" id="${u}">
|
|
14
|
+
<span>${this.label}</span>
|
|
15
|
+
${this.optional?re`
|
|
16
|
+
<span class="optional">
|
|
17
|
+
${y._({id:"checkbox-group.label.optional",message:"Optional",comment:"Shown behind label when marked as optional"})}
|
|
18
|
+
</span>
|
|
19
|
+
`:we}
|
|
20
|
+
</div>
|
|
21
|
+
`:we}
|
|
22
|
+
<div
|
|
23
|
+
class="checkbox-group"
|
|
24
|
+
role="group"
|
|
25
|
+
aria-labelledby=${Me(u)}
|
|
26
|
+
aria-describedby=${Me(n)}
|
|
27
|
+
aria-invalid=${Me(m)}
|
|
28
|
+
>
|
|
29
|
+
<slot></slot>
|
|
30
|
+
</div>
|
|
31
|
+
${a?re`<div class="${l?"help-text error":"help-text"}" id="${n}">${a}</div>`:we}
|
|
32
|
+
</div>
|
|
33
|
+
`}connectedCallback(){super.connectedCallback(),this.addEventListener("change",E(this,ae)),this.addEventListener("invalid",E(this,oe)),this.addEventListener("slotchange",E(this,le)),N(this,z,y.on("change",E(this,ce))),this.setValue(null),d(this,o,Se).call(this)}disconnectedCallback(){var t;(t=E(this,z))==null||t.call(this),N(this,z,void 0),super.disconnectedCallback()}checkValidity(){return d(this,o,q).call(this),this.internals.checkValidity()}reportValidity(){return d(this,o,ie).call(this),d(this,o,q).call(this),this.internals.checkValidity()}focus(t){let r=d(this,o,xe).call(this);if(r!=null&&r.focus){r.focus(t);return}HTMLElement.prototype.focus.call(this,t)}updated(t){super.updated(t),d(this,o,tt).call(this,t)&&(t.has("name")&&d(this,o,Ee).call(this),d(this,o,q).call(this))}};W=new WeakMap,Z=new WeakMap,U=new WeakMap,z=new WeakMap,ae=new WeakMap,oe=new WeakMap,le=new WeakMap,o=new WeakSet,ie=function(){N(this,W,!0)},ce=new WeakMap,Ce=function(){return d(this,o,Q).call(this).filter(t=>t.checked).length},Ee=function(){if(this.name)for(let t of d(this,o,Q).call(this)){let r=t;r&&typeof r=="object"&&!r.name&&(r.name=this.name)}},ne=function(t){for(let r of d(this,o,Q).call(this))"invalid"in r&&(r.invalid=t)},xe=function(){return d(this,o,Q).call(this)[0]},Q=function(){var r,i;let t=(r=this.shadowRoot)==null?void 0:r.querySelector("slot");return(i=t==null?void 0:t.assignedElements({flatten:!0}))!=null?i:[]},et=function(){return Pt()},tt=function(t){return t.has("invalid")||t.has("required")||t.has("helpText")||t.has("name")},Fe=function(t){let r=d(this,o,xe).call(this);this.internals.setValidity(t," ",r!=null?r:void 0)},st=function(t){if(!(this.hasAttribute("tabindex")&&!E(this,U))){if(t){this.tabIndex=0,N(this,U,!0);return}E(this,U)&&(this.removeAttribute("tabindex"),N(this,U,!1))}},q=function(){d(this,o,Se).call(this);let t=d(this,o,Ce).call(this)>0,r=this.required&&!t,i=this.invalid,l=r&&E(this,W),a=i||l;if(d(this,o,st).call(this,a),r){d(this,o,Fe).call(this,{valueMissing:!0}),d(this,o,ne).call(this,a);return}if(i){d(this,o,Fe).call(this,{customError:!0}),d(this,o,ne).call(this,!0);return}this.internals.setValidity({}),d(this,o,ne).call(this,!1)},Se=function(){E(this,Z)||this.internals.form&&(this.name&&this.name.trim().length>0||(console.warn('w-checkbox-group: "name" is required for form submission.'),N(this,Z,!0)))},F.styles=At`
|
|
34
|
+
.wrapper {
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
gap: 16px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.checkbox-group {
|
|
41
|
+
display: grid;
|
|
42
|
+
gap: 16px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.label {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 8px;
|
|
49
|
+
font-size: var(--w-font-size-s);
|
|
50
|
+
line-height: var(--w-line-height-s);
|
|
51
|
+
font-weight: 700;
|
|
52
|
+
color: var(--w-s-color-text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.optional {
|
|
56
|
+
font-weight: 400;
|
|
57
|
+
color: var(--w-s-color-text-subtle);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.help-text {
|
|
61
|
+
display: block;
|
|
62
|
+
font-size: var(--w-font-size-xs);
|
|
63
|
+
line-height: var(--w-line-height-xs);
|
|
64
|
+
color: var(--w-s-color-text-subtle);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.error {
|
|
68
|
+
color: var(--w-s-color-text-negative);
|
|
69
|
+
}
|
|
70
|
+
`,A([j({type:String,reflect:!0})],F.prototype,"label",2),A([j({type:String,reflect:!0})],F.prototype,"name",2),A([j({type:Boolean,reflect:!0})],F.prototype,"optional",2),A([j({type:String,reflect:!0,attribute:"help-text"})],F.prototype,"helpText",2),A([j({type:Boolean,reflect:!0})],F.prototype,"required",2),A([j({type:Boolean,reflect:!0})],F.prototype,"invalid",2);customElements.get("w-checkbox-group")||customElements.define("w-checkbox-group",F);export{F as WCheckboxGroup};
|
|
71
|
+
//# sourceMappingURL=checkbox-group.js.map
|