@devschile/chucao 1.7.0 → 2.0.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 +14 -12
- package/dist/chucao/chucao.css +1 -1
- package/dist/chucao/chucao.esm.js +1 -1
- package/dist/chucao/index.esm.js +1 -1
- package/dist/chucao/index.esm.js.map +1 -1
- package/dist/chucao/p-10658dc9.entry.js +2 -0
- package/dist/chucao/p-10658dc9.entry.js.map +1 -0
- package/dist/chucao/p-19dde4f9.entry.js +2 -0
- package/dist/chucao/p-19dde4f9.entry.js.map +1 -0
- package/dist/chucao/p-2e20c7a1.entry.js +2 -0
- package/dist/chucao/p-2e20c7a1.entry.js.map +1 -0
- package/dist/chucao/p-66dce533.entry.js +2 -0
- package/dist/chucao/p-66dce533.entry.js.map +1 -0
- package/dist/chucao/p-75184fe1.entry.js +2 -0
- package/dist/chucao/p-75184fe1.entry.js.map +1 -0
- package/dist/chucao/p-96c852f5.entry.js +2 -0
- package/dist/chucao/p-96c852f5.entry.js.map +1 -0
- package/dist/chucao/p-BaKXvAYc.js +3 -0
- package/dist/chucao/p-BaKXvAYc.js.map +1 -0
- package/dist/chucao/{p-fe8e9537.entry.js → p-a0ec231a.entry.js} +2 -2
- package/dist/chucao/{p-488c7838.entry.js → p-e48912c7.entry.js} +2 -2
- package/dist/chucao/{p-20492b73.entry.js → p-f04d2f75.entry.js} +2 -2
- package/dist/chucao/{p-053d58a4.entry.js → p-f62e1da2.entry.js} +2 -2
- package/dist/cjs/ch-accordion.cjs.entry.js +1 -1
- package/dist/cjs/ch-alert_8.cjs.entry.js +185 -8
- package/dist/cjs/ch-alert_8.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-checkbox.cjs.entry.js +62 -3
- package/dist/cjs/ch-checkbox.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-divider.cjs.entry.js +1 -1
- package/dist/cjs/ch-link.cjs.entry.js +1 -1
- package/dist/cjs/ch-modal.cjs.entry.js +167 -0
- package/dist/cjs/ch-modal.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-radio.cjs.entry.js +62 -3
- package/dist/cjs/ch-radio.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-tabs.cjs.entry.js +1 -1
- package/dist/cjs/ch-textarea.cjs.entry.js +62 -3
- package/dist/cjs/ch-textarea.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-tooltip.cjs.entry.js +82 -0
- package/dist/cjs/ch-tooltip.cjs.entry.js.map +1 -0
- package/dist/cjs/chucao.cjs.js +2 -2
- package/dist/cjs/{index-ls4U227d.js → index-C9Abf0td.js} +204 -9
- package/dist/cjs/index-C9Abf0td.js.map +1 -0
- package/dist/cjs/index.cjs.js +5 -0
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +2 -0
- package/dist/collection/components/ch-card/ch-card.js +1 -1
- package/dist/collection/components/ch-checkbox/ch-checkbox.css +10 -0
- package/dist/collection/components/ch-checkbox/ch-checkbox.js +64 -4
- package/dist/collection/components/ch-checkbox/ch-checkbox.js.map +1 -1
- package/dist/collection/components/ch-input/ch-input.css +11 -0
- package/dist/collection/components/ch-input/ch-input.js +64 -4
- package/dist/collection/components/ch-input/ch-input.js.map +1 -1
- package/dist/collection/components/ch-modal/ch-modal.css +69 -0
- package/dist/collection/components/ch-modal/ch-modal.js +278 -0
- package/dist/collection/components/ch-modal/ch-modal.js.map +1 -0
- package/dist/collection/components/ch-radio/ch-radio.css +10 -0
- package/dist/collection/components/ch-radio/ch-radio.js +64 -4
- package/dist/collection/components/ch-radio/ch-radio.js.map +1 -1
- package/dist/collection/components/ch-select/ch-select.css +11 -0
- package/dist/collection/components/ch-select/ch-select.js +64 -4
- package/dist/collection/components/ch-select/ch-select.js.map +1 -1
- package/dist/collection/components/ch-switch/ch-switch.css +10 -0
- package/dist/collection/components/ch-switch/ch-switch.js +64 -4
- package/dist/collection/components/ch-switch/ch-switch.js.map +1 -1
- package/dist/collection/components/ch-textarea/ch-textarea.css +11 -0
- package/dist/collection/components/ch-textarea/ch-textarea.js +64 -4
- package/dist/collection/components/ch-textarea/ch-textarea.js.map +1 -1
- package/dist/collection/components/ch-tooltip/ch-tooltip.css +100 -0
- package/dist/collection/components/ch-tooltip/ch-tooltip.js +168 -0
- package/dist/collection/components/ch-tooltip/ch-tooltip.js.map +1 -0
- package/dist/collection/tokens/tokens.js +4 -0
- package/dist/collection/tokens/tokens.js.map +1 -1
- package/dist/collection/tokens/types.js.map +1 -1
- package/dist/components/ch-accordion.js +1 -1
- package/dist/components/ch-alert.js +1 -1
- package/dist/components/ch-badge.js +1 -1
- package/dist/components/ch-button.js +1 -1
- package/dist/components/ch-card.js +1 -1
- package/dist/components/ch-checkbox.js +1 -1
- package/dist/components/ch-checkbox.js.map +1 -1
- package/dist/components/ch-divider.js +1 -1
- package/dist/components/ch-input.js +1 -1
- package/dist/components/ch-input.js.map +1 -1
- package/dist/components/ch-link.js +1 -1
- package/dist/components/ch-modal.d.ts +11 -0
- package/dist/components/ch-modal.js +2 -0
- package/dist/components/ch-modal.js.map +1 -0
- package/dist/components/ch-radio.js +1 -1
- package/dist/components/ch-radio.js.map +1 -1
- package/dist/components/ch-select.js +1 -1
- package/dist/components/ch-select.js.map +1 -1
- package/dist/components/ch-spinner.js +1 -1
- package/dist/components/ch-switch.js +1 -1
- package/dist/components/ch-switch.js.map +1 -1
- package/dist/components/ch-tabs.js +1 -1
- package/dist/components/ch-textarea.js +1 -1
- package/dist/components/ch-textarea.js.map +1 -1
- package/dist/components/ch-tooltip.d.ts +11 -0
- package/dist/components/ch-tooltip.js +2 -0
- package/dist/components/ch-tooltip.js.map +1 -0
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/p-DL-bL54o.js +2 -0
- package/dist/components/p-DL-bL54o.js.map +1 -0
- package/dist/esm/ch-accordion.entry.js +1 -1
- package/dist/esm/ch-alert_8.entry.js +185 -8
- package/dist/esm/ch-alert_8.entry.js.map +1 -1
- package/dist/esm/ch-checkbox.entry.js +62 -3
- package/dist/esm/ch-checkbox.entry.js.map +1 -1
- package/dist/esm/ch-divider.entry.js +1 -1
- package/dist/esm/ch-link.entry.js +1 -1
- package/dist/esm/ch-modal.entry.js +165 -0
- package/dist/esm/ch-modal.entry.js.map +1 -0
- package/dist/esm/ch-radio.entry.js +62 -3
- package/dist/esm/ch-radio.entry.js.map +1 -1
- package/dist/esm/ch-tabs.entry.js +1 -1
- package/dist/esm/ch-textarea.entry.js +62 -3
- package/dist/esm/ch-textarea.entry.js.map +1 -1
- package/dist/esm/ch-tooltip.entry.js +80 -0
- package/dist/esm/ch-tooltip.entry.js.map +1 -0
- package/dist/esm/chucao.js +3 -3
- package/dist/esm/{index-pfWAsOzE.js → index-BaKXvAYc.js} +204 -10
- package/dist/esm/index-BaKXvAYc.js.map +1 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/types/components/ch-checkbox/ch-checkbox.d.ts +9 -0
- package/dist/types/components/ch-input/ch-input.d.ts +9 -0
- package/dist/types/components/ch-modal/ch-modal.d.ts +67 -0
- package/dist/types/components/ch-radio/ch-radio.d.ts +9 -0
- package/dist/types/components/ch-select/ch-select.d.ts +9 -0
- package/dist/types/components/ch-switch/ch-switch.d.ts +9 -0
- package/dist/types/components/ch-textarea/ch-textarea.d.ts +9 -0
- package/dist/types/components/ch-tooltip/ch-tooltip.d.ts +47 -0
- package/dist/types/components.d.ts +240 -0
- package/dist/types/tokens/tokens.d.ts +4 -0
- package/dist/types/tokens/types.d.ts +1 -1
- package/dist-react/components.d.ts +10 -1
- package/dist-react/components.js +21 -0
- package/dist-react/components.ts +31 -1
- package/dist-vue/index.d.ts +2 -0
- package/dist-vue/index.js +15 -0
- package/dist-vue/index.ts +19 -0
- package/hydrate/index.js +836 -61
- package/hydrate/index.mjs +836 -61
- package/package.json +4 -1
- package/dist/chucao/p-0305f2eb.entry.js +0 -2
- package/dist/chucao/p-0305f2eb.entry.js.map +0 -1
- package/dist/chucao/p-9a614e82.entry.js +0 -2
- package/dist/chucao/p-9a614e82.entry.js.map +0 -1
- package/dist/chucao/p-ad3206a2.entry.js +0 -2
- package/dist/chucao/p-ad3206a2.entry.js.map +0 -1
- package/dist/chucao/p-c598f978.entry.js +0 -2
- package/dist/chucao/p-c598f978.entry.js.map +0 -1
- package/dist/chucao/p-pfWAsOzE.js +0 -3
- package/dist/chucao/p-pfWAsOzE.js.map +0 -1
- package/dist/cjs/index-ls4U227d.js.map +0 -1
- package/dist/components/p-ONE3uKkF.js +0 -2
- package/dist/components/p-ONE3uKkF.js.map +0 -1
- package/dist/esm/index-pfWAsOzE.js.map +0 -1
- /package/dist/chucao/{p-fe8e9537.entry.js.map → p-a0ec231a.entry.js.map} +0 -0
- /package/dist/chucao/{p-488c7838.entry.js.map → p-e48912c7.entry.js.map} +0 -0
- /package/dist/chucao/{p-20492b73.entry.js.map → p-f04d2f75.entry.js.map} +0 -0
- /package/dist/chucao/{p-053d58a4.entry.js.map → p-f62e1da2.entry.js.map} +0 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
let openModals = 0;
|
|
3
|
+
let previousOverflow = '';
|
|
4
|
+
let previousPaddingRight = '';
|
|
5
|
+
/**
|
|
6
|
+
* Modal dialog, built on the native `<dialog>` element and opened with
|
|
7
|
+
* `showModal()`.
|
|
8
|
+
*
|
|
9
|
+
* The browser therefore supplies the parts that are easy to get wrong: moving
|
|
10
|
+
* focus into the dialog and returning it afterwards, marking the rest of the
|
|
11
|
+
* document inert, `Escape` to close, the top layer, `::backdrop`, and the
|
|
12
|
+
* implicit `dialog` role with `aria-modal="true"`. Notably it does not trap
|
|
13
|
+
* focus, which is deliberate — the W3C APA group concluded a modal should let
|
|
14
|
+
* keyboard users reach browser UI, so a hand-rolled trap would be less
|
|
15
|
+
* correct, not more.
|
|
16
|
+
*
|
|
17
|
+
* What the platform does not cover, and this component adds: locking the page
|
|
18
|
+
* behind the dialog so it cannot scroll, and closing when the backdrop is
|
|
19
|
+
* clicked. The latter is `closedby="any"` in the platform, which Safari does
|
|
20
|
+
* not support yet, so it is implemented here for every browser alike rather
|
|
21
|
+
* than only for some.
|
|
22
|
+
*/
|
|
23
|
+
export class ChModal {
|
|
24
|
+
/**
|
|
25
|
+
* Whether the dialog is open. Kept in sync when the user closes it with
|
|
26
|
+
* `Escape`, the close button or a click outside.
|
|
27
|
+
*/
|
|
28
|
+
open = false;
|
|
29
|
+
/**
|
|
30
|
+
* Accessible name for the dialog, set as `aria-label`. A slotted heading
|
|
31
|
+
* cannot be referenced with `aria-labelledby` across the shadow boundary, so
|
|
32
|
+
* the name comes through this prop — and a modal dialog needs one, so pass
|
|
33
|
+
* the same text as the heading.
|
|
34
|
+
*/
|
|
35
|
+
label;
|
|
36
|
+
/**
|
|
37
|
+
* Accessible label for the close button, set as `aria-label`. Setting it is
|
|
38
|
+
* what adds the button: its only content is a decorative glyph, so without a
|
|
39
|
+
* label it would have no accessible name.
|
|
40
|
+
*/
|
|
41
|
+
closeLabel;
|
|
42
|
+
/**
|
|
43
|
+
* Emitted after the dialog opens.
|
|
44
|
+
*/
|
|
45
|
+
chOpen;
|
|
46
|
+
/**
|
|
47
|
+
* Emitted after the dialog closes, however it was closed.
|
|
48
|
+
*/
|
|
49
|
+
chClose;
|
|
50
|
+
dialog;
|
|
51
|
+
scrollLocked = false;
|
|
52
|
+
pointerDownedOutside = false;
|
|
53
|
+
componentDidLoad() {
|
|
54
|
+
// Wired here rather than in JSX because Stencil derives a listener's event
|
|
55
|
+
// name from whether `on<name>` exists on `window`, which differs between
|
|
56
|
+
// the browser and the test environment for pointer events.
|
|
57
|
+
this.dialog?.addEventListener('close', this.handleNativeClose);
|
|
58
|
+
this.dialog?.addEventListener('pointerdown', this.handlePointerDown);
|
|
59
|
+
this.dialog?.addEventListener('click', this.handleClick);
|
|
60
|
+
if (this.open) {
|
|
61
|
+
this.showDialog();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
this.dialog?.removeEventListener('close', this.handleNativeClose);
|
|
66
|
+
this.dialog?.removeEventListener('pointerdown', this.handlePointerDown);
|
|
67
|
+
this.dialog?.removeEventListener('click', this.handleClick);
|
|
68
|
+
this.unlockScroll();
|
|
69
|
+
}
|
|
70
|
+
handleOpenChange(open) {
|
|
71
|
+
if (open) {
|
|
72
|
+
this.showDialog();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.closeDialog();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
showDialog() {
|
|
79
|
+
if (typeof this.dialog?.showModal !== 'function') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.lockScroll();
|
|
83
|
+
this.dialog.showModal();
|
|
84
|
+
this.chOpen.emit();
|
|
85
|
+
}
|
|
86
|
+
closeDialog() {
|
|
87
|
+
if (typeof this.dialog?.close === 'function' && this.dialog.open) {
|
|
88
|
+
this.dialog.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
lockScroll() {
|
|
92
|
+
if (this.scrollLocked) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.scrollLocked = true;
|
|
96
|
+
openModals += 1;
|
|
97
|
+
if (openModals > 1) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const root = document.documentElement;
|
|
101
|
+
const scrollbar = window.innerWidth - root.clientWidth;
|
|
102
|
+
previousOverflow = root.style.overflow;
|
|
103
|
+
previousPaddingRight = root.style.paddingRight;
|
|
104
|
+
root.style.overflow = 'hidden';
|
|
105
|
+
if (scrollbar > 0) {
|
|
106
|
+
root.style.paddingRight = `${scrollbar}px`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
unlockScroll() {
|
|
110
|
+
if (!this.scrollLocked) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.scrollLocked = false;
|
|
114
|
+
openModals -= 1;
|
|
115
|
+
if (openModals > 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const root = document.documentElement;
|
|
119
|
+
root.style.overflow = previousOverflow;
|
|
120
|
+
root.style.paddingRight = previousPaddingRight;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* True for a pointer event on the backdrop: the `<dialog>` is the event
|
|
124
|
+
* target for its own box only, and the coordinates fall outside that box.
|
|
125
|
+
*/
|
|
126
|
+
isOnBackdrop(event) {
|
|
127
|
+
if (!this.dialog || event.target !== this.dialog) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const box = this.dialog.getBoundingClientRect();
|
|
131
|
+
return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;
|
|
132
|
+
}
|
|
133
|
+
handlePointerDown = (event) => {
|
|
134
|
+
this.pointerDownedOutside = this.isOnBackdrop(event);
|
|
135
|
+
};
|
|
136
|
+
handleClick = (event) => {
|
|
137
|
+
// Requiring the press to have started on the backdrop too keeps a
|
|
138
|
+
// selection dragged out of the dialog, and a keyboard-synthesised click
|
|
139
|
+
// (which reports coordinates of 0), from closing it.
|
|
140
|
+
const dismiss = this.pointerDownedOutside && this.isOnBackdrop(event);
|
|
141
|
+
this.pointerDownedOutside = false;
|
|
142
|
+
if (dismiss) {
|
|
143
|
+
this.closeDialog();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
handleNativeClose = () => {
|
|
147
|
+
this.unlockScroll();
|
|
148
|
+
if (this.open) {
|
|
149
|
+
this.open = false;
|
|
150
|
+
}
|
|
151
|
+
this.chClose.emit();
|
|
152
|
+
};
|
|
153
|
+
handleCloseClick = () => {
|
|
154
|
+
if (typeof this.dialog?.close === 'function' && this.dialog.open) {
|
|
155
|
+
this.dialog.close();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this.open = false;
|
|
159
|
+
this.chClose.emit();
|
|
160
|
+
};
|
|
161
|
+
render() {
|
|
162
|
+
return (h(Host, { key: '92edf16d3ff079f72a4785ec9852e3e25218fd35' }, h("dialog", { key: '546fc72a098e1e2d8c05fafa2f11eac19ff83fd3', class: "modal", "aria-label": this.label, ref: el => (this.dialog = el) }, h("div", { key: '5a67aa39b6687db89d97533eb54d3a3b663bed56', class: "modal-head" }, h("slot", { key: '2e44b59a7c5e6af4a110a7f86362964ddd30d215', name: "heading" }), this.closeLabel && (h("button", { key: 'ce70baaa876c9f7b82865f0547e8e8cef5d5dfde', class: "modal-close", type: "button", "aria-label": this.closeLabel, onClick: this.handleCloseClick }, h("span", { key: 'df4536a8851a1ca9d3d2c46d15d18856660a54f6', "aria-hidden": "true" }, "\u00D7")))), h("div", { key: '5de77062134ccd90643df17d7b0d0ddb161f6a5f', class: "modal-body" }, h("slot", { key: '3b64493e9236b311a4b2f5250c5027f866bce8fd' })))));
|
|
163
|
+
}
|
|
164
|
+
static get is() { return "ch-modal"; }
|
|
165
|
+
static get encapsulation() { return "shadow"; }
|
|
166
|
+
static get originalStyleUrls() {
|
|
167
|
+
return {
|
|
168
|
+
"$": ["ch-modal.css"]
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
static get styleUrls() {
|
|
172
|
+
return {
|
|
173
|
+
"$": ["ch-modal.css"]
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
static get properties() {
|
|
177
|
+
return {
|
|
178
|
+
"open": {
|
|
179
|
+
"type": "boolean",
|
|
180
|
+
"mutable": true,
|
|
181
|
+
"complexType": {
|
|
182
|
+
"original": "boolean",
|
|
183
|
+
"resolved": "boolean",
|
|
184
|
+
"references": {}
|
|
185
|
+
},
|
|
186
|
+
"required": false,
|
|
187
|
+
"optional": false,
|
|
188
|
+
"docs": {
|
|
189
|
+
"tags": [],
|
|
190
|
+
"text": "Whether the dialog is open. Kept in sync when the user closes it with\n`Escape`, the close button or a click outside."
|
|
191
|
+
},
|
|
192
|
+
"getter": false,
|
|
193
|
+
"setter": false,
|
|
194
|
+
"reflect": false,
|
|
195
|
+
"attribute": "open",
|
|
196
|
+
"defaultValue": "false"
|
|
197
|
+
},
|
|
198
|
+
"label": {
|
|
199
|
+
"type": "string",
|
|
200
|
+
"mutable": false,
|
|
201
|
+
"complexType": {
|
|
202
|
+
"original": "string",
|
|
203
|
+
"resolved": "string",
|
|
204
|
+
"references": {}
|
|
205
|
+
},
|
|
206
|
+
"required": false,
|
|
207
|
+
"optional": true,
|
|
208
|
+
"docs": {
|
|
209
|
+
"tags": [],
|
|
210
|
+
"text": "Accessible name for the dialog, set as `aria-label`. A slotted heading\ncannot be referenced with `aria-labelledby` across the shadow boundary, so\nthe name comes through this prop \u2014 and a modal dialog needs one, so pass\nthe same text as the heading."
|
|
211
|
+
},
|
|
212
|
+
"getter": false,
|
|
213
|
+
"setter": false,
|
|
214
|
+
"reflect": false,
|
|
215
|
+
"attribute": "label"
|
|
216
|
+
},
|
|
217
|
+
"closeLabel": {
|
|
218
|
+
"type": "string",
|
|
219
|
+
"mutable": false,
|
|
220
|
+
"complexType": {
|
|
221
|
+
"original": "string",
|
|
222
|
+
"resolved": "string",
|
|
223
|
+
"references": {}
|
|
224
|
+
},
|
|
225
|
+
"required": false,
|
|
226
|
+
"optional": true,
|
|
227
|
+
"docs": {
|
|
228
|
+
"tags": [],
|
|
229
|
+
"text": "Accessible label for the close button, set as `aria-label`. Setting it is\nwhat adds the button: its only content is a decorative glyph, so without a\nlabel it would have no accessible name."
|
|
230
|
+
},
|
|
231
|
+
"getter": false,
|
|
232
|
+
"setter": false,
|
|
233
|
+
"reflect": false,
|
|
234
|
+
"attribute": "close-label"
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
static get events() {
|
|
239
|
+
return [{
|
|
240
|
+
"method": "chOpen",
|
|
241
|
+
"name": "chOpen",
|
|
242
|
+
"bubbles": true,
|
|
243
|
+
"cancelable": true,
|
|
244
|
+
"composed": true,
|
|
245
|
+
"docs": {
|
|
246
|
+
"tags": [],
|
|
247
|
+
"text": "Emitted after the dialog opens."
|
|
248
|
+
},
|
|
249
|
+
"complexType": {
|
|
250
|
+
"original": "void",
|
|
251
|
+
"resolved": "void",
|
|
252
|
+
"references": {}
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
"method": "chClose",
|
|
256
|
+
"name": "chClose",
|
|
257
|
+
"bubbles": true,
|
|
258
|
+
"cancelable": true,
|
|
259
|
+
"composed": true,
|
|
260
|
+
"docs": {
|
|
261
|
+
"tags": [],
|
|
262
|
+
"text": "Emitted after the dialog closes, however it was closed."
|
|
263
|
+
},
|
|
264
|
+
"complexType": {
|
|
265
|
+
"original": "void",
|
|
266
|
+
"resolved": "void",
|
|
267
|
+
"references": {}
|
|
268
|
+
}
|
|
269
|
+
}];
|
|
270
|
+
}
|
|
271
|
+
static get watchers() {
|
|
272
|
+
return [{
|
|
273
|
+
"propName": "open",
|
|
274
|
+
"methodName": "handleOpenChange"
|
|
275
|
+
}];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=ch-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ch-modal.js","sourceRoot":"","sources":["../../../../src/components/ch-modal/ch-modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE1F,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,IAAI,gBAAgB,GAAG,EAAE,CAAC;AAC1B,IAAI,oBAAoB,GAAG,EAAE,CAAC;AAE9B;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,OAAO,OAAO;IAClB;;;OAGG;IACsB,IAAI,GAAG,KAAK,CAAC;IAEtC;;;;;OAKG;IACK,KAAK,CAAU;IAEvB;;;;OAIG;IACK,UAAU,CAAU;IAE5B;;OAEG;IAC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AAG,EAAE;QAC9B,IAAI,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,KAAK,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC,CAAC;IAEF,MAAM;QACJ,OAAO,CACL,EAAC,IAAI;YACH,+DAAQ,KAAK,EAAC,OAAO,gBAAa,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,EAAuB,CAAC;gBAC9F,4DAAK,KAAK,EAAC,YAAY;oBACrB,6DAAM,IAAI,EAAC,SAAS,GAAQ;oBAC3B,IAAI,CAAC,UAAU,IAAI,CAClB,+DAAQ,KAAK,EAAC,aAAa,EAAC,IAAI,EAAC,QAAQ,gBAAa,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB;wBACnG,4EAAkB,MAAM,aAAS,CAC1B,CACV,CACG;gBACN,4DAAK,KAAK,EAAC,YAAY;oBACrB,8DAAa,CACT,CACC,CACJ,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, Watch, h } from '@stencil/core';\n\nlet openModals = 0;\nlet previousOverflow = '';\nlet previousPaddingRight = '';\n\n/**\n * Modal dialog, built on the native `<dialog>` element and opened with\n * `showModal()`.\n *\n * The browser therefore supplies the parts that are easy to get wrong: moving\n * focus into the dialog and returning it afterwards, marking the rest of the\n * document inert, `Escape` to close, the top layer, `::backdrop`, and the\n * implicit `dialog` role with `aria-modal=\"true\"`. Notably it does not trap\n * focus, which is deliberate — the W3C APA group concluded a modal should let\n * keyboard users reach browser UI, so a hand-rolled trap would be less\n * correct, not more.\n *\n * What the platform does not cover, and this component adds: locking the page\n * behind the dialog so it cannot scroll, and closing when the backdrop is\n * clicked. The latter is `closedby=\"any\"` in the platform, which Safari does\n * not support yet, so it is implemented here for every browser alike rather\n * than only for some.\n */\n@Component({\n tag: 'ch-modal',\n styleUrl: 'ch-modal.css',\n shadow: true,\n})\nexport class ChModal {\n /**\n * Whether the dialog is open. Kept in sync when the user closes it with\n * `Escape`, the close button or a click outside.\n */\n @Prop({ mutable: true }) open = false;\n\n /**\n * Accessible name for the dialog, set as `aria-label`. A slotted heading\n * cannot be referenced with `aria-labelledby` across the shadow boundary, so\n * the name comes through this prop — and a modal dialog needs one, so pass\n * the same text as the heading.\n */\n @Prop() label?: string;\n\n /**\n * Accessible label for the close button, set as `aria-label`. Setting it is\n * what adds the button: its only content is a decorative glyph, so without a\n * label it would have no accessible name.\n */\n @Prop() closeLabel?: string;\n\n /**\n * Emitted after the dialog opens.\n */\n @Event() chOpen: EventEmitter<void>;\n\n /**\n * Emitted after the dialog closes, however it was closed.\n */\n @Event() chClose: EventEmitter<void>;\n\n private dialog?: HTMLDialogElement;\n private scrollLocked = false;\n private pointerDownedOutside = false;\n\n componentDidLoad() {\n // Wired here rather than in JSX because Stencil derives a listener's event\n // name from whether `on<name>` exists on `window`, which differs between\n // the browser and the test environment for pointer events.\n this.dialog?.addEventListener('close', this.handleNativeClose);\n this.dialog?.addEventListener('pointerdown', this.handlePointerDown);\n this.dialog?.addEventListener('click', this.handleClick);\n if (this.open) {\n this.showDialog();\n }\n }\n\n disconnectedCallback() {\n this.dialog?.removeEventListener('close', this.handleNativeClose);\n this.dialog?.removeEventListener('pointerdown', this.handlePointerDown);\n this.dialog?.removeEventListener('click', this.handleClick);\n this.unlockScroll();\n }\n\n @Watch('open')\n handleOpenChange(open: boolean) {\n if (open) {\n this.showDialog();\n } else {\n this.closeDialog();\n }\n }\n\n private showDialog() {\n if (typeof this.dialog?.showModal !== 'function') {\n return;\n }\n this.lockScroll();\n this.dialog.showModal();\n this.chOpen.emit();\n }\n\n private closeDialog() {\n if (typeof this.dialog?.close === 'function' && this.dialog.open) {\n this.dialog.close();\n }\n }\n\n private lockScroll() {\n if (this.scrollLocked) {\n return;\n }\n this.scrollLocked = true;\n openModals += 1;\n if (openModals > 1) {\n return;\n }\n const root = document.documentElement;\n const scrollbar = window.innerWidth - root.clientWidth;\n previousOverflow = root.style.overflow;\n previousPaddingRight = root.style.paddingRight;\n root.style.overflow = 'hidden';\n if (scrollbar > 0) {\n root.style.paddingRight = `${scrollbar}px`;\n }\n }\n\n private unlockScroll() {\n if (!this.scrollLocked) {\n return;\n }\n this.scrollLocked = false;\n openModals -= 1;\n if (openModals > 0) {\n return;\n }\n const root = document.documentElement;\n root.style.overflow = previousOverflow;\n root.style.paddingRight = previousPaddingRight;\n }\n\n /**\n * True for a pointer event on the backdrop: the `<dialog>` is the event\n * target for its own box only, and the coordinates fall outside that box.\n */\n private isOnBackdrop(event: MouseEvent) {\n if (!this.dialog || event.target !== this.dialog) {\n return false;\n }\n const box = this.dialog.getBoundingClientRect();\n return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;\n }\n\n private handlePointerDown = (event: Event) => {\n this.pointerDownedOutside = this.isOnBackdrop(event as MouseEvent);\n };\n\n private handleClick = (event: Event) => {\n // Requiring the press to have started on the backdrop too keeps a\n // selection dragged out of the dialog, and a keyboard-synthesised click\n // (which reports coordinates of 0), from closing it.\n const dismiss = this.pointerDownedOutside && this.isOnBackdrop(event as MouseEvent);\n this.pointerDownedOutside = false;\n if (dismiss) {\n this.closeDialog();\n }\n };\n\n private handleNativeClose = () => {\n this.unlockScroll();\n if (this.open) {\n this.open = false;\n }\n this.chClose.emit();\n };\n\n private handleCloseClick = () => {\n if (typeof this.dialog?.close === 'function' && this.dialog.open) {\n this.dialog.close();\n return;\n }\n this.open = false;\n this.chClose.emit();\n };\n\n render() {\n return (\n <Host>\n <dialog class=\"modal\" aria-label={this.label} ref={el => (this.dialog = el as HTMLDialogElement)}>\n <div class=\"modal-head\">\n <slot name=\"heading\"></slot>\n {this.closeLabel && (\n <button class=\"modal-close\" type=\"button\" aria-label={this.closeLabel} onClick={this.handleCloseClick}>\n <span aria-hidden=\"true\">×</span>\n </button>\n )}\n </div>\n <div class=\"modal-body\">\n <slot></slot>\n </div>\n </dialog>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -73,6 +73,16 @@
|
|
|
73
73
|
outline-color: var(--color-status-warning);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
:host([data-touched]:invalid) .input,
|
|
77
|
+
:host(:user-invalid) .input {
|
|
78
|
+
border-color: var(--color-status-warning);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
:host([data-touched]:invalid) .input:focus-visible,
|
|
82
|
+
:host(:user-invalid) .input:focus-visible {
|
|
83
|
+
outline-color: var(--color-status-warning);
|
|
84
|
+
}
|
|
85
|
+
|
|
76
86
|
.label-text {
|
|
77
87
|
color: var(--text);
|
|
78
88
|
}
|
|
@@ -5,6 +5,10 @@ export class ChRadio {
|
|
|
5
5
|
labelId = `${this.groupId}-label`;
|
|
6
6
|
hintId = `${this.groupId}-hint`;
|
|
7
7
|
errorId = `${this.groupId}-error`;
|
|
8
|
+
initialValue;
|
|
9
|
+
internals;
|
|
10
|
+
formDisabled = false;
|
|
11
|
+
host;
|
|
8
12
|
/**
|
|
9
13
|
* Visible label describing the radio group, associated with it via
|
|
10
14
|
* `aria-labelledby`.
|
|
@@ -52,6 +56,39 @@ export class ChRadio {
|
|
|
52
56
|
this.value = ev.target.value;
|
|
53
57
|
this.chChange.emit(this.value);
|
|
54
58
|
};
|
|
59
|
+
syncForm() {
|
|
60
|
+
const internals = this.internals;
|
|
61
|
+
if (typeof internals?.setFormValue !== 'function') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
internals.setFormValue(this.value ?? null);
|
|
65
|
+
const flags = {};
|
|
66
|
+
let message;
|
|
67
|
+
if (this.required && !this.value) {
|
|
68
|
+
flags.valueMissing = true;
|
|
69
|
+
}
|
|
70
|
+
if (this.invalid && this.errorMessage) {
|
|
71
|
+
flags.customError = true;
|
|
72
|
+
}
|
|
73
|
+
message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
|
|
74
|
+
internals.setValidity(flags, message);
|
|
75
|
+
}
|
|
76
|
+
componentDidLoad() {
|
|
77
|
+
this.initialValue = this.value;
|
|
78
|
+
this.syncForm();
|
|
79
|
+
this.host.addEventListener('change', this.markTouched);
|
|
80
|
+
this.host.addEventListener('focusout', this.markTouched);
|
|
81
|
+
this.host.addEventListener('invalid', this.markTouched);
|
|
82
|
+
}
|
|
83
|
+
markTouched = () => {
|
|
84
|
+
this.host.setAttribute('data-touched', '');
|
|
85
|
+
};
|
|
86
|
+
formResetCallback() {
|
|
87
|
+
this.value = this.initialValue;
|
|
88
|
+
}
|
|
89
|
+
formDisabledCallback(isDisabled) {
|
|
90
|
+
this.formDisabled = isDisabled;
|
|
91
|
+
}
|
|
55
92
|
get describedBy() {
|
|
56
93
|
if (this.invalid && this.errorMessage) {
|
|
57
94
|
return this.errorId;
|
|
@@ -63,10 +100,11 @@ export class ChRadio {
|
|
|
63
100
|
}
|
|
64
101
|
render() {
|
|
65
102
|
const groupName = this.name || `${this.groupId}-group`;
|
|
66
|
-
return (h(Host, { key: '
|
|
103
|
+
return (h(Host, { key: '1a2562301b8daf00c557764c7f4cdfd54e6e11ef' }, this.label && (h("span", { key: '873958acd3422069572031d59be22c06e3e705a6', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '860c71f128b6fb84dce3c14d2086fd77cc1a4a1e', class: "radio-group", role: "radiogroup", "aria-labelledby": this.label ? this.labelId : undefined }, this.options.map(option => (h("label", { class: { 'control': true, 'control--disabled': this.disabled || this.formDisabled || option.disabled } }, h("input", { class: { 'input': true, 'input--invalid': this.invalid }, type: "radio", name: groupName, value: option.value, checked: option.value === this.value, disabled: this.disabled || this.formDisabled || option.disabled, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { class: "mark" }), h("span", { class: "label-text" }, option.label))))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '2b358f659d1ef21b1e90ecb67c41d6a0054806e3', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '4e60f0303e42668c4532f076143a47daa216dff8', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
67
104
|
}
|
|
68
105
|
static get is() { return "ch-radio"; }
|
|
69
106
|
static get encapsulation() { return "shadow"; }
|
|
107
|
+
static get formAssociated() { return true; }
|
|
70
108
|
static get originalStyleUrls() {
|
|
71
109
|
return {
|
|
72
110
|
"$": ["ch-radio.css"]
|
|
@@ -157,7 +195,7 @@ export class ChRadio {
|
|
|
157
195
|
},
|
|
158
196
|
"getter": false,
|
|
159
197
|
"setter": false,
|
|
160
|
-
"reflect":
|
|
198
|
+
"reflect": true,
|
|
161
199
|
"attribute": "name"
|
|
162
200
|
},
|
|
163
201
|
"disabled": {
|
|
@@ -176,7 +214,7 @@ export class ChRadio {
|
|
|
176
214
|
},
|
|
177
215
|
"getter": false,
|
|
178
216
|
"setter": false,
|
|
179
|
-
"reflect":
|
|
217
|
+
"reflect": true,
|
|
180
218
|
"attribute": "disabled",
|
|
181
219
|
"defaultValue": "false"
|
|
182
220
|
},
|
|
@@ -196,7 +234,7 @@ export class ChRadio {
|
|
|
196
234
|
},
|
|
197
235
|
"getter": false,
|
|
198
236
|
"setter": false,
|
|
199
|
-
"reflect":
|
|
237
|
+
"reflect": true,
|
|
200
238
|
"attribute": "required",
|
|
201
239
|
"defaultValue": "false"
|
|
202
240
|
},
|
|
@@ -260,6 +298,11 @@ export class ChRadio {
|
|
|
260
298
|
}
|
|
261
299
|
};
|
|
262
300
|
}
|
|
301
|
+
static get states() {
|
|
302
|
+
return {
|
|
303
|
+
"formDisabled": {}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
263
306
|
static get events() {
|
|
264
307
|
return [{
|
|
265
308
|
"method": "chChange",
|
|
@@ -278,5 +321,22 @@ export class ChRadio {
|
|
|
278
321
|
}
|
|
279
322
|
}];
|
|
280
323
|
}
|
|
324
|
+
static get elementRef() { return "host"; }
|
|
325
|
+
static get watchers() {
|
|
326
|
+
return [{
|
|
327
|
+
"propName": "value",
|
|
328
|
+
"methodName": "syncForm"
|
|
329
|
+
}, {
|
|
330
|
+
"propName": "required",
|
|
331
|
+
"methodName": "syncForm"
|
|
332
|
+
}, {
|
|
333
|
+
"propName": "invalid",
|
|
334
|
+
"methodName": "syncForm"
|
|
335
|
+
}, {
|
|
336
|
+
"propName": "errorMessage",
|
|
337
|
+
"methodName": "syncForm"
|
|
338
|
+
}];
|
|
339
|
+
}
|
|
340
|
+
static get attachInternalsMemberName() { return "internals"; }
|
|
281
341
|
}
|
|
282
342
|
//# sourceMappingURL=ch-radio.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"ch-radio.js","sourceRoot":"","sources":["../../../../src/components/ch-radio/ch-radio.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAQ3H,IAAI,QAAQ,GAAG,CAAC,CAAC;AAQjB,MAAM,OAAO,OAAO;IACD,OAAO,GAAG,YAAY,EAAE,QAAQ,EAA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IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CACpD,0DAAG,KAAK,EAAC,MAAM,EAAC,EAAE,EAAE,IAAI,CAAC,MAAM,IAC5B,IAAI,CAAC,IAAI,CACR,CACL;YACA,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,CACpC,0DAAG,KAAK,EAAC,OAAO,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAC,OAAO,IAC5C,IAAI,CAAC,YAAY,CAChB,CACL,CACI,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { AttachInternals, Component, Element, Event, type EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core';\n\nexport interface ChRadioOption {\n label: string;\n value: string;\n disabled?: boolean;\n}\n\nlet radioIds = 0;\n\n@Component({\n tag: 'ch-radio',\n styleUrl: 'ch-radio.css',\n shadow: true,\n formAssociated: true,\n})\nexport class ChRadio {\n private readonly groupId = `ch-radio-${++radioIds}`;\n private readonly labelId = `${this.groupId}-label`;\n private readonly hintId = `${this.groupId}-hint`;\n private readonly errorId = `${this.groupId}-error`;\n private initialValue: string | undefined;\n\n @AttachInternals() internals!: ElementInternals;\n @State() formDisabled = false;\n @Element() private host!: HTMLElement;\n\n /**\n * Visible label describing the radio group, associated with it via\n * `aria-labelledby`.\n */\n @Prop() label?: string;\n\n /**\n * The list of options rendered as radio inputs.\n */\n @Prop() options: ChRadioOption[] = [];\n\n /**\n * The value of the selected option.\n */\n @Prop({ mutable: true }) value?: string;\n\n /**\n * The name shared by all radio inputs in the group. Defaults to an\n * auto-generated group name so options are mutually exclusive out of the box.\n */\n @Prop({ reflect: true }) name?: string;\n\n /**\n * Whether all radios in the group are disabled.\n */\n @Prop({ reflect: true }) disabled = false;\n\n /**\n * Whether a value is required.\n */\n @Prop({ reflect: true }) required = false;\n\n /**\n * Helper text rendered below the radio group, associated via `aria-describedby`.\n * Replaced by `errorMessage` when the group is invalid.\n */\n @Prop() hint?: string;\n\n /**\n * Error message rendered below the radio group when it is invalid.\n */\n @Prop() errorMessage?: string;\n\n /**\n * Whether the radio group is in an invalid state; toggles `aria-invalid` and error styling.\n */\n @Prop() invalid = false;\n\n /**\n * Emitted when a new option is selected, with the selected value.\n */\n @Event() chChange: EventEmitter<string>;\n\n private handleChange = (ev: Event) => {\n this.value = (ev.target as HTMLInputElement).value;\n this.chChange.emit(this.value);\n };\n\n @Watch('value')\n @Watch('required')\n @Watch('invalid')\n @Watch('errorMessage')\n protected syncForm(): void {\n const internals = this.internals;\n if (typeof internals?.setFormValue !== 'function') {\n return;\n }\n internals.setFormValue(this.value ?? null);\n const flags: ValidityStateFlags = {};\n let message: string | undefined;\n if (this.required && !this.value) {\n flags.valueMissing = true;\n }\n if (this.invalid && this.errorMessage) {\n flags.customError = true;\n }\n message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);\n internals.setValidity(flags, message);\n }\n\n componentDidLoad() {\n this.initialValue = this.value;\n this.syncForm();\n this.host.addEventListener('change', this.markTouched);\n this.host.addEventListener('focusout', this.markTouched);\n this.host.addEventListener('invalid', this.markTouched);\n }\n\n private markTouched = (): void => {\n this.host.setAttribute('data-touched', '');\n };\n\n formResetCallback(): void {\n this.value = this.initialValue;\n }\n\n formDisabledCallback(isDisabled: boolean): void {\n this.formDisabled = isDisabled;\n }\n\n private get describedBy(): string | undefined {\n if (this.invalid && this.errorMessage) {\n return this.errorId;\n }\n if (this.hint) {\n return this.hintId;\n }\n return undefined;\n }\n\n render() {\n const groupName = this.name || `${this.groupId}-group`;\n return (\n <Host>\n {this.label && (\n <span class=\"group-label\" id={this.labelId}>\n {this.label}\n </span>\n )}\n <div class=\"radio-group\" role=\"radiogroup\" aria-labelledby={this.label ? this.labelId : undefined}>\n {this.options.map(option => (\n <label class={{ 'control': true, 'control--disabled': this.disabled || this.formDisabled || option.disabled }}>\n <input\n class={{ 'input': true, 'input--invalid': this.invalid }}\n type=\"radio\"\n name={groupName}\n value={option.value}\n checked={option.value === this.value}\n disabled={this.disabled || this.formDisabled || option.disabled}\n aria-invalid={this.invalid ? 'true' : undefined}\n aria-describedby={this.describedBy}\n onChange={this.handleChange}\n />\n <span class=\"mark\"></span>\n <span class=\"label-text\">{option.label}</span>\n </label>\n ))}\n </div>\n {this.hint && !(this.invalid && this.errorMessage) && (\n <p class=\"hint\" id={this.hintId}>\n {this.hint}\n </p>\n )}\n {this.invalid && this.errorMessage && (\n <p class=\"error\" id={this.errorId} role=\"alert\">\n {this.errorMessage}\n </p>\n )}\n </Host>\n );\n }\n}\n"]}
|
|
@@ -43,6 +43,17 @@
|
|
|
43
43
|
box-shadow: 0 0 0 3px var(--color-status-warning-background);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
:host([data-touched]:invalid) .select,
|
|
47
|
+
:host(:user-invalid) .select {
|
|
48
|
+
border-color: var(--color-status-warning);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:host([data-touched]:invalid) .select:focus,
|
|
52
|
+
:host(:user-invalid) .select:focus {
|
|
53
|
+
border-color: var(--color-status-warning);
|
|
54
|
+
box-shadow: 0 0 0 3px var(--color-status-warning-background);
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
.select:disabled {
|
|
47
58
|
opacity: var(--opacity-disabled);
|
|
48
59
|
cursor: not-allowed;
|
|
@@ -4,6 +4,10 @@ export class ChSelect {
|
|
|
4
4
|
selectId = `ch-select-${++selectIds}`;
|
|
5
5
|
hintId = `${this.selectId}-hint`;
|
|
6
6
|
errorId = `${this.selectId}-error`;
|
|
7
|
+
initialValue;
|
|
8
|
+
internals;
|
|
9
|
+
formDisabled = false;
|
|
10
|
+
host;
|
|
7
11
|
/**
|
|
8
12
|
* Visible label rendered above the select and associated with it via
|
|
9
13
|
* `for`/`id`, so assistive technology announces the select's purpose.
|
|
@@ -54,6 +58,39 @@ export class ChSelect {
|
|
|
54
58
|
this.value = ev.target.value;
|
|
55
59
|
this.chChange.emit(this.value);
|
|
56
60
|
};
|
|
61
|
+
syncForm() {
|
|
62
|
+
const internals = this.internals;
|
|
63
|
+
if (typeof internals?.setFormValue !== 'function') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
internals.setFormValue(this.value ?? '');
|
|
67
|
+
const flags = {};
|
|
68
|
+
let message;
|
|
69
|
+
if (this.required && !this.value) {
|
|
70
|
+
flags.valueMissing = true;
|
|
71
|
+
}
|
|
72
|
+
if (this.invalid && this.errorMessage) {
|
|
73
|
+
flags.customError = true;
|
|
74
|
+
}
|
|
75
|
+
message = this.errorMessage ?? (flags.valueMissing ? 'Please fill out this field.' : undefined);
|
|
76
|
+
internals.setValidity(flags, message);
|
|
77
|
+
}
|
|
78
|
+
componentDidLoad() {
|
|
79
|
+
this.initialValue = this.value;
|
|
80
|
+
this.syncForm();
|
|
81
|
+
this.host.addEventListener('change', this.markTouched);
|
|
82
|
+
this.host.addEventListener('focusout', this.markTouched);
|
|
83
|
+
this.host.addEventListener('invalid', this.markTouched);
|
|
84
|
+
}
|
|
85
|
+
markTouched = () => {
|
|
86
|
+
this.host.setAttribute('data-touched', '');
|
|
87
|
+
};
|
|
88
|
+
formResetCallback() {
|
|
89
|
+
this.value = this.initialValue;
|
|
90
|
+
}
|
|
91
|
+
formDisabledCallback(isDisabled) {
|
|
92
|
+
this.formDisabled = isDisabled;
|
|
93
|
+
}
|
|
57
94
|
get describedBy() {
|
|
58
95
|
if (this.invalid && this.errorMessage) {
|
|
59
96
|
return this.errorId;
|
|
@@ -64,10 +101,11 @@ export class ChSelect {
|
|
|
64
101
|
return undefined;
|
|
65
102
|
}
|
|
66
103
|
render() {
|
|
67
|
-
return (h(Host, { key: '
|
|
104
|
+
return (h(Host, { key: 'b3336d43945543f23e903df41eaefef23fde6ff4' }, this.label && (h("label", { key: '1928d359fce76001c24c969ccc59c5bc7c67e676', class: "label", htmlFor: this.selectId }, this.label)), h("select", { key: '7896282971021ef35d9bd3926335e02bc0efc804', id: this.label ? this.selectId : undefined, class: { 'select': true, 'select--invalid': this.invalid }, name: this.name, disabled: this.disabled || this.formDisabled, required: this.required, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }, this.placeholder && (h("option", { key: '4acfff84e5616092c6a8d0741cdf6bf959a4cfee', value: "", disabled: true, hidden: true, selected: !this.value }, this.placeholder)), this.options.map(option => (h("option", { value: option.value, disabled: option.disabled, selected: option.value === this.value }, option.label)))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: 'cb079b5ed1a64e53b6bc3ba07f63dee0baa0f78f', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '87e730d857a4a8c44378c98759ac8ecc7cfde366', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
68
105
|
}
|
|
69
106
|
static get is() { return "ch-select"; }
|
|
70
107
|
static get encapsulation() { return "shadow"; }
|
|
108
|
+
static get formAssociated() { return true; }
|
|
71
109
|
static get originalStyleUrls() {
|
|
72
110
|
return {
|
|
73
111
|
"$": ["ch-select.css"]
|
|
@@ -177,7 +215,7 @@ export class ChSelect {
|
|
|
177
215
|
},
|
|
178
216
|
"getter": false,
|
|
179
217
|
"setter": false,
|
|
180
|
-
"reflect":
|
|
218
|
+
"reflect": true,
|
|
181
219
|
"attribute": "name"
|
|
182
220
|
},
|
|
183
221
|
"disabled": {
|
|
@@ -196,7 +234,7 @@ export class ChSelect {
|
|
|
196
234
|
},
|
|
197
235
|
"getter": false,
|
|
198
236
|
"setter": false,
|
|
199
|
-
"reflect":
|
|
237
|
+
"reflect": true,
|
|
200
238
|
"attribute": "disabled",
|
|
201
239
|
"defaultValue": "false"
|
|
202
240
|
},
|
|
@@ -216,7 +254,7 @@ export class ChSelect {
|
|
|
216
254
|
},
|
|
217
255
|
"getter": false,
|
|
218
256
|
"setter": false,
|
|
219
|
-
"reflect":
|
|
257
|
+
"reflect": true,
|
|
220
258
|
"attribute": "required",
|
|
221
259
|
"defaultValue": "false"
|
|
222
260
|
},
|
|
@@ -280,6 +318,11 @@ export class ChSelect {
|
|
|
280
318
|
}
|
|
281
319
|
};
|
|
282
320
|
}
|
|
321
|
+
static get states() {
|
|
322
|
+
return {
|
|
323
|
+
"formDisabled": {}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
283
326
|
static get events() {
|
|
284
327
|
return [{
|
|
285
328
|
"method": "chChange",
|
|
@@ -298,5 +341,22 @@ export class ChSelect {
|
|
|
298
341
|
}
|
|
299
342
|
}];
|
|
300
343
|
}
|
|
344
|
+
static get elementRef() { return "host"; }
|
|
345
|
+
static get watchers() {
|
|
346
|
+
return [{
|
|
347
|
+
"propName": "value",
|
|
348
|
+
"methodName": "syncForm"
|
|
349
|
+
}, {
|
|
350
|
+
"propName": "required",
|
|
351
|
+
"methodName": "syncForm"
|
|
352
|
+
}, {
|
|
353
|
+
"propName": "invalid",
|
|
354
|
+
"methodName": "syncForm"
|
|
355
|
+
}, {
|
|
356
|
+
"propName": "errorMessage",
|
|
357
|
+
"methodName": "syncForm"
|
|
358
|
+
}];
|
|
359
|
+
}
|
|
360
|
+
static get attachInternalsMemberName() { return "internals"; }
|
|
301
361
|
}
|
|
302
362
|
//# sourceMappingURL=ch-select.js.map
|