@devschile/chucao 2.1.0 → 2.3.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/dist/chucao/chucao.esm.js +1 -1
- package/dist/chucao/p-37e7f9cc.entry.js +2 -0
- package/dist/chucao/p-37e7f9cc.entry.js.map +1 -0
- package/dist/chucao/p-3db38c49.entry.js +2 -0
- package/dist/chucao/p-3db38c49.entry.js.map +1 -0
- package/dist/chucao/p-60c2fd71.entry.js +2 -0
- package/dist/chucao/p-60c2fd71.entry.js.map +1 -0
- package/dist/chucao/{p-121fbfc8.entry.js → p-6a4bc80c.entry.js} +2 -2
- package/dist/chucao/p-6c617158.entry.js +2 -0
- package/dist/chucao/p-6c617158.entry.js.map +1 -0
- package/dist/chucao/{p-4bc8e098.entry.js → p-aeea9cbe.entry.js} +2 -2
- package/dist/chucao/p-bb2445d1.entry.js +2 -0
- package/dist/chucao/{p-5fe8bfff.entry.js → p-c4806e96.entry.js} +2 -2
- package/dist/chucao/{p-9bb81a65.entry.js → p-c986036f.entry.js} +2 -2
- package/dist/chucao/p-d8DfpzMR.js +2 -0
- package/dist/chucao/p-d8DfpzMR.js.map +1 -0
- package/dist/chucao/{p-1b1e56cd.entry.js → p-e3265e38.entry.js} +2 -2
- package/dist/chucao/{p-d5a9e340.entry.js → p-f78f0163.entry.js} +2 -2
- package/dist/cjs/ch-alert_8.cjs.entry.js +54 -11
- package/dist/cjs/ch-alert_8.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/ch-divider.cjs.entry.js +1 -1
- package/dist/cjs/ch-drawer.cjs.entry.js +153 -0
- package/dist/cjs/ch-drawer.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-emoji.cjs.entry.js +1 -1
- package/dist/cjs/ch-modal.cjs.entry.js +12 -24
- package/dist/cjs/ch-modal.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-radio.cjs.entry.js +1 -1
- package/dist/cjs/ch-segmented-control.cjs.entry.js +112 -0
- package/dist/cjs/ch-segmented-control.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-tabs.cjs.entry.js +1 -1
- package/dist/cjs/ch-textarea.cjs.entry.js +1 -1
- package/dist/cjs/ch-tooltip.cjs.entry.js +1 -1
- package/dist/cjs/chucao.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/scroll-lock-DIRqLP4K.js +49 -0
- package/dist/cjs/scroll-lock-DIRqLP4K.js.map +1 -0
- package/dist/collection/collection-manifest.json +3 -1
- package/dist/collection/components/ch-button/ch-button.css +56 -18
- package/dist/collection/components/ch-button/ch-button.js +135 -8
- package/dist/collection/components/ch-button/ch-button.js.map +1 -1
- package/dist/collection/components/ch-card/ch-card.js +1 -1
- package/dist/collection/components/ch-checkbox/ch-checkbox.js +1 -1
- package/dist/collection/components/ch-divider/ch-divider.js +1 -1
- package/dist/collection/components/ch-drawer/ch-drawer.css +152 -0
- package/dist/collection/components/ch-drawer/ch-drawer.js +285 -0
- package/dist/collection/components/ch-drawer/ch-drawer.js.map +1 -0
- package/dist/collection/components/ch-emoji/ch-emoji.js +1 -1
- package/dist/collection/components/ch-input/ch-input.js +1 -1
- package/dist/collection/components/ch-modal/ch-modal.css +12 -1
- package/dist/collection/components/ch-modal/ch-modal.js +37 -23
- package/dist/collection/components/ch-modal/ch-modal.js.map +1 -1
- package/dist/collection/components/ch-radio/ch-radio.js +1 -1
- package/dist/collection/components/ch-segmented-control/ch-segmented-control.css +88 -0
- package/dist/collection/components/ch-segmented-control/ch-segmented-control.js +295 -0
- package/dist/collection/components/ch-segmented-control/ch-segmented-control.js.map +1 -0
- package/dist/collection/components/ch-select/ch-select.js +1 -1
- package/dist/collection/components/ch-spinner/ch-spinner.js +1 -1
- package/dist/collection/components/ch-switch/ch-switch.js +1 -1
- package/dist/collection/components/ch-tabs/ch-tabs.js +1 -1
- package/dist/collection/components/ch-textarea/ch-textarea.js +1 -1
- package/dist/collection/components/ch-tooltip/ch-tooltip.js +1 -1
- package/dist/collection/utils/scroll-lock.js +42 -0
- package/dist/collection/utils/scroll-lock.js.map +1 -0
- package/dist/components/ch-button.js +1 -1
- package/dist/components/ch-button.js.map +1 -1
- package/dist/components/ch-card.js +1 -1
- package/dist/components/ch-card.js.map +1 -1
- package/dist/components/ch-checkbox.js +1 -1
- package/dist/components/ch-divider.js +1 -1
- package/dist/components/ch-drawer.d.ts +11 -0
- package/dist/components/ch-drawer.js +2 -0
- package/dist/components/ch-drawer.js.map +1 -0
- package/dist/components/ch-emoji.js +1 -1
- package/dist/components/ch-input.js +1 -1
- package/dist/components/ch-modal.js +1 -1
- package/dist/components/ch-modal.js.map +1 -1
- package/dist/components/ch-radio.js +1 -1
- package/dist/components/ch-segmented-control.d.ts +11 -0
- package/dist/components/ch-segmented-control.js +2 -0
- package/dist/components/ch-segmented-control.js.map +1 -0
- package/dist/components/ch-select.js +1 -1
- package/dist/components/ch-spinner.js +1 -1
- package/dist/components/ch-spinner.js.map +1 -1
- package/dist/components/ch-switch.js +1 -1
- package/dist/components/ch-tabs.js +1 -1
- package/dist/components/ch-textarea.js +1 -1
- package/dist/components/ch-tooltip.js +1 -1
- package/dist/components/p-C1995t1C.js +2 -0
- package/dist/components/p-C1995t1C.js.map +1 -0
- package/dist/components/p-d8DfpzMR.js +2 -0
- package/dist/components/p-d8DfpzMR.js.map +1 -0
- package/dist/esm/ch-alert_8.entry.js +54 -11
- package/dist/esm/ch-alert_8.entry.js.map +1 -1
- package/dist/esm/ch-checkbox.entry.js +1 -1
- package/dist/esm/ch-divider.entry.js +1 -1
- package/dist/esm/ch-drawer.entry.js +151 -0
- package/dist/esm/ch-drawer.entry.js.map +1 -0
- package/dist/esm/ch-emoji.entry.js +1 -1
- package/dist/esm/ch-modal.entry.js +12 -24
- package/dist/esm/ch-modal.entry.js.map +1 -1
- package/dist/esm/ch-radio.entry.js +1 -1
- package/dist/esm/ch-segmented-control.entry.js +110 -0
- package/dist/esm/ch-segmented-control.entry.js.map +1 -0
- package/dist/esm/ch-tabs.entry.js +1 -1
- package/dist/esm/ch-textarea.entry.js +1 -1
- package/dist/esm/ch-tooltip.entry.js +1 -1
- package/dist/esm/chucao.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/scroll-lock-d8DfpzMR.js +46 -0
- package/dist/esm/scroll-lock-d8DfpzMR.js.map +1 -0
- package/dist/types/components/ch-button/ch-button.d.ts +29 -5
- package/dist/types/components/ch-drawer/ch-drawer.d.ts +68 -0
- package/dist/types/components/ch-modal/ch-modal.d.ts +8 -0
- package/dist/types/components/ch-segmented-control/ch-segmented-control.d.ts +72 -0
- package/dist/types/components.d.ts +346 -6
- package/dist/types/utils/scroll-lock.d.ts +17 -0
- package/dist-react/components.d.ts +12 -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 +30 -0
- package/dist-vue/index.ts +34 -0
- package/hydrate/index.js +428 -43
- package/hydrate/index.mjs +428 -43
- package/package.json +4 -3
- package/dist/chucao/p-11083711.entry.js +0 -2
- package/dist/chucao/p-11083711.entry.js.map +0 -1
- package/dist/chucao/p-2ab4a6a8.entry.js +0 -2
- package/dist/chucao/p-a955eebf.entry.js +0 -2
- package/dist/chucao/p-a955eebf.entry.js.map +0 -1
- /package/dist/chucao/{p-121fbfc8.entry.js.map → p-6a4bc80c.entry.js.map} +0 -0
- /package/dist/chucao/{p-4bc8e098.entry.js.map → p-aeea9cbe.entry.js.map} +0 -0
- /package/dist/chucao/{p-2ab4a6a8.entry.js.map → p-bb2445d1.entry.js.map} +0 -0
- /package/dist/chucao/{p-5fe8bfff.entry.js.map → p-c4806e96.entry.js.map} +0 -0
- /package/dist/chucao/{p-9bb81a65.entry.js.map → p-c986036f.entry.js.map} +0 -0
- /package/dist/chucao/{p-1b1e56cd.entry.js.map → p-e3265e38.entry.js.map} +0 -0
- /package/dist/chucao/{p-d5a9e340.entry.js.map → p-f78f0163.entry.js.map} +0 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
import { lockScroll as lockPageScroll, unlockScroll as unlockPageScroll } from "../../utils/scroll-lock";
|
|
3
|
+
/**
|
|
4
|
+
* Sliding side panel for navigation, editing forms and quick detail views.
|
|
5
|
+
*
|
|
6
|
+
* Built on the native `<dialog>` element and opened with `showModal()`, exactly
|
|
7
|
+
* like `ch-modal`, so the browser owns focus management, the inert background,
|
|
8
|
+
* `Escape`, the top layer, `::backdrop`, and the implicit `dialog` role with
|
|
9
|
+
* `aria-modal="true"`. The only differences are placement — anchored to one
|
|
10
|
+
* edge instead of centred — and the longer content it is meant for, which is
|
|
11
|
+
* why it exposes `header` and `footer` slots around a scrollable body.
|
|
12
|
+
*
|
|
13
|
+
* Scroll locking is shared with `ch-modal` through `utils/scroll-lock`, so a
|
|
14
|
+
* drawer and a modal opened together cannot unlock the page early.
|
|
15
|
+
*/
|
|
16
|
+
export class ChDrawer {
|
|
17
|
+
/**
|
|
18
|
+
* Whether the drawer is open. Kept in sync when the user closes it with
|
|
19
|
+
* `Escape`, the close button or a click outside.
|
|
20
|
+
*/
|
|
21
|
+
open = false;
|
|
22
|
+
/**
|
|
23
|
+
* The edge the panel slides in from. `start`/`end` follow the writing
|
|
24
|
+
* direction, so `start` is the left edge in LTR and the right edge in RTL.
|
|
25
|
+
*/
|
|
26
|
+
side = 'end';
|
|
27
|
+
/**
|
|
28
|
+
* Accessible name for the drawer, set as `aria-label`. A slotted heading
|
|
29
|
+
* cannot be referenced with `aria-labelledby` across the shadow boundary, so
|
|
30
|
+
* the name comes through this prop — and a modal dialog needs one, so pass
|
|
31
|
+
* the same text as the heading.
|
|
32
|
+
*/
|
|
33
|
+
label;
|
|
34
|
+
/**
|
|
35
|
+
* Accessible label for the close button, set as `aria-label`. Setting it is
|
|
36
|
+
* what adds the button: its only content is a decorative glyph, so without a
|
|
37
|
+
* label it would have no accessible name.
|
|
38
|
+
*/
|
|
39
|
+
closeLabel;
|
|
40
|
+
/**
|
|
41
|
+
* Emitted after the drawer opens.
|
|
42
|
+
*/
|
|
43
|
+
chOpen;
|
|
44
|
+
/**
|
|
45
|
+
* Emitted after the drawer closes, however it was closed.
|
|
46
|
+
*/
|
|
47
|
+
chClose;
|
|
48
|
+
dialog;
|
|
49
|
+
scrollLocked = false;
|
|
50
|
+
pointerDownedOutside = false;
|
|
51
|
+
componentDidLoad() {
|
|
52
|
+
// Wired here rather than in JSX because Stencil derives a listener's event
|
|
53
|
+
// name from whether `on<name>` exists on `window`, which differs between
|
|
54
|
+
// the browser and the test environment for pointer events.
|
|
55
|
+
this.dialog?.addEventListener('close', this.handleNativeClose);
|
|
56
|
+
this.dialog?.addEventListener('pointerdown', this.handlePointerDown);
|
|
57
|
+
this.dialog?.addEventListener('click', this.handleClick);
|
|
58
|
+
if (this.open) {
|
|
59
|
+
this.showDialog();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
disconnectedCallback() {
|
|
63
|
+
this.dialog?.removeEventListener('close', this.handleNativeClose);
|
|
64
|
+
this.dialog?.removeEventListener('pointerdown', this.handlePointerDown);
|
|
65
|
+
this.dialog?.removeEventListener('click', this.handleClick);
|
|
66
|
+
this.unlockScroll();
|
|
67
|
+
}
|
|
68
|
+
handleOpenChange(open) {
|
|
69
|
+
if (open) {
|
|
70
|
+
this.showDialog();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.closeDialog();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
showDialog() {
|
|
77
|
+
if (typeof this.dialog?.showModal !== 'function') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.lockScroll();
|
|
81
|
+
this.dialog.showModal();
|
|
82
|
+
this.chOpen.emit();
|
|
83
|
+
}
|
|
84
|
+
closeDialog() {
|
|
85
|
+
if (typeof this.dialog?.close === 'function' && this.dialog.open) {
|
|
86
|
+
this.dialog.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
lockScroll() {
|
|
90
|
+
if (this.scrollLocked) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.scrollLocked = true;
|
|
94
|
+
lockPageScroll();
|
|
95
|
+
}
|
|
96
|
+
unlockScroll() {
|
|
97
|
+
if (!this.scrollLocked) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.scrollLocked = false;
|
|
101
|
+
unlockPageScroll();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* True for a pointer event on the backdrop: the `<dialog>` is the event
|
|
105
|
+
* target for its own box only, and the coordinates fall outside that box.
|
|
106
|
+
*/
|
|
107
|
+
isOnBackdrop(event) {
|
|
108
|
+
if (!this.dialog || event.target !== this.dialog) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const box = this.dialog.getBoundingClientRect();
|
|
112
|
+
return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;
|
|
113
|
+
}
|
|
114
|
+
handlePointerDown = (event) => {
|
|
115
|
+
this.pointerDownedOutside = this.isOnBackdrop(event);
|
|
116
|
+
};
|
|
117
|
+
handleClick = (event) => {
|
|
118
|
+
// Requiring the press to have started on the backdrop too keeps a
|
|
119
|
+
// selection dragged out of the drawer, and a keyboard-synthesised click
|
|
120
|
+
// (which reports coordinates of 0), from closing it.
|
|
121
|
+
const dismiss = this.pointerDownedOutside && this.isOnBackdrop(event);
|
|
122
|
+
this.pointerDownedOutside = false;
|
|
123
|
+
if (dismiss) {
|
|
124
|
+
this.closeDialog();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
handleNativeClose = () => {
|
|
128
|
+
this.unlockScroll();
|
|
129
|
+
if (this.open) {
|
|
130
|
+
this.open = false;
|
|
131
|
+
}
|
|
132
|
+
this.chClose.emit();
|
|
133
|
+
};
|
|
134
|
+
handleCloseClick = () => {
|
|
135
|
+
if (typeof this.dialog?.close === 'function' && this.dialog.open) {
|
|
136
|
+
this.dialog.close();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.open = false;
|
|
140
|
+
this.chClose.emit();
|
|
141
|
+
};
|
|
142
|
+
render() {
|
|
143
|
+
return (h(Host, { key: '8ee0dd329f7304e3f4804c26c75514372d49b4b8' }, h("dialog", { key: '7f99c8edf6f820b595d4360ccc90123da37f9314', class: { drawer: true, [`drawer--${this.side}`]: true }, "aria-label": this.label, ref: el => (this.dialog = el) }, h("div", { key: '65c2a386b36305ece253fe644db2a198bc245d12', class: "drawer-head" }, h("slot", { key: '6c259b14a1fea3a38014c832d917554e3d431e18', name: "header" }), this.closeLabel && (h("button", { key: '4d259fbd9850ea4f379f07be50f863e896e67312', class: "drawer-close", type: "button", "aria-label": this.closeLabel, onClick: this.handleCloseClick }, h("span", { key: 'f1623602e84587020e77ec84c4b997c726414193', "aria-hidden": "true" }, "\u00D7")))), h("div", { key: 'b239b7da3c9b00a6e80d33290d810297301206de', class: "drawer-body" }, h("slot", { key: 'c3739f84975fc5f4717986214217c23eacb4432f' })), h("slot", { key: '469be1ccedaf474fe40a9c2d264b6c128715cfc7', name: "footer" }))));
|
|
144
|
+
}
|
|
145
|
+
static get is() { return "ch-drawer"; }
|
|
146
|
+
static get encapsulation() { return "shadow"; }
|
|
147
|
+
static get originalStyleUrls() {
|
|
148
|
+
return {
|
|
149
|
+
"$": ["ch-drawer.css"]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
static get styleUrls() {
|
|
153
|
+
return {
|
|
154
|
+
"$": ["ch-drawer.css"]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
static get properties() {
|
|
158
|
+
return {
|
|
159
|
+
"open": {
|
|
160
|
+
"type": "boolean",
|
|
161
|
+
"mutable": true,
|
|
162
|
+
"complexType": {
|
|
163
|
+
"original": "boolean",
|
|
164
|
+
"resolved": "boolean",
|
|
165
|
+
"references": {}
|
|
166
|
+
},
|
|
167
|
+
"required": false,
|
|
168
|
+
"optional": false,
|
|
169
|
+
"docs": {
|
|
170
|
+
"tags": [],
|
|
171
|
+
"text": "Whether the drawer is open. Kept in sync when the user closes it with\n`Escape`, the close button or a click outside."
|
|
172
|
+
},
|
|
173
|
+
"getter": false,
|
|
174
|
+
"setter": false,
|
|
175
|
+
"reflect": false,
|
|
176
|
+
"attribute": "open",
|
|
177
|
+
"defaultValue": "false"
|
|
178
|
+
},
|
|
179
|
+
"side": {
|
|
180
|
+
"type": "string",
|
|
181
|
+
"mutable": false,
|
|
182
|
+
"complexType": {
|
|
183
|
+
"original": "ChDrawerSide",
|
|
184
|
+
"resolved": "\"bottom\" | \"end\" | \"start\" | \"top\"",
|
|
185
|
+
"references": {
|
|
186
|
+
"ChDrawerSide": {
|
|
187
|
+
"location": "local",
|
|
188
|
+
"path": "/home/runner/work/chucao/chucao/src/components/ch-drawer/ch-drawer.tsx",
|
|
189
|
+
"id": "src/components/ch-drawer/ch-drawer.tsx::ChDrawerSide"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"required": false,
|
|
194
|
+
"optional": false,
|
|
195
|
+
"docs": {
|
|
196
|
+
"tags": [],
|
|
197
|
+
"text": "The edge the panel slides in from. `start`/`end` follow the writing\ndirection, so `start` is the left edge in LTR and the right edge in RTL."
|
|
198
|
+
},
|
|
199
|
+
"getter": false,
|
|
200
|
+
"setter": false,
|
|
201
|
+
"reflect": false,
|
|
202
|
+
"attribute": "side",
|
|
203
|
+
"defaultValue": "'end'"
|
|
204
|
+
},
|
|
205
|
+
"label": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"mutable": false,
|
|
208
|
+
"complexType": {
|
|
209
|
+
"original": "string",
|
|
210
|
+
"resolved": "string",
|
|
211
|
+
"references": {}
|
|
212
|
+
},
|
|
213
|
+
"required": false,
|
|
214
|
+
"optional": true,
|
|
215
|
+
"docs": {
|
|
216
|
+
"tags": [],
|
|
217
|
+
"text": "Accessible name for the drawer, 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."
|
|
218
|
+
},
|
|
219
|
+
"getter": false,
|
|
220
|
+
"setter": false,
|
|
221
|
+
"reflect": false,
|
|
222
|
+
"attribute": "label"
|
|
223
|
+
},
|
|
224
|
+
"closeLabel": {
|
|
225
|
+
"type": "string",
|
|
226
|
+
"mutable": false,
|
|
227
|
+
"complexType": {
|
|
228
|
+
"original": "string",
|
|
229
|
+
"resolved": "string",
|
|
230
|
+
"references": {}
|
|
231
|
+
},
|
|
232
|
+
"required": false,
|
|
233
|
+
"optional": true,
|
|
234
|
+
"docs": {
|
|
235
|
+
"tags": [],
|
|
236
|
+
"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."
|
|
237
|
+
},
|
|
238
|
+
"getter": false,
|
|
239
|
+
"setter": false,
|
|
240
|
+
"reflect": false,
|
|
241
|
+
"attribute": "close-label"
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
static get events() {
|
|
246
|
+
return [{
|
|
247
|
+
"method": "chOpen",
|
|
248
|
+
"name": "chOpen",
|
|
249
|
+
"bubbles": true,
|
|
250
|
+
"cancelable": true,
|
|
251
|
+
"composed": true,
|
|
252
|
+
"docs": {
|
|
253
|
+
"tags": [],
|
|
254
|
+
"text": "Emitted after the drawer opens."
|
|
255
|
+
},
|
|
256
|
+
"complexType": {
|
|
257
|
+
"original": "void",
|
|
258
|
+
"resolved": "void",
|
|
259
|
+
"references": {}
|
|
260
|
+
}
|
|
261
|
+
}, {
|
|
262
|
+
"method": "chClose",
|
|
263
|
+
"name": "chClose",
|
|
264
|
+
"bubbles": true,
|
|
265
|
+
"cancelable": true,
|
|
266
|
+
"composed": true,
|
|
267
|
+
"docs": {
|
|
268
|
+
"tags": [],
|
|
269
|
+
"text": "Emitted after the drawer closes, however it was closed."
|
|
270
|
+
},
|
|
271
|
+
"complexType": {
|
|
272
|
+
"original": "void",
|
|
273
|
+
"resolved": "void",
|
|
274
|
+
"references": {}
|
|
275
|
+
}
|
|
276
|
+
}];
|
|
277
|
+
}
|
|
278
|
+
static get watchers() {
|
|
279
|
+
return [{
|
|
280
|
+
"propName": "open",
|
|
281
|
+
"methodName": "handleOpenChange"
|
|
282
|
+
}];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=ch-drawer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ch-drawer.js","sourceRoot":"","sources":["../../../../src/components/ch-drawer/ch-drawer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIzG;;;;;;;;;;;;GAYG;AAMH,MAAM,OAAO,QAAQ;IACnB;;;OAGG;IACsB,IAAI,GAAG,KAAK,CAAC;IAEtC;;;OAGG;IACK,IAAI,GAAiB,KAAK,CAAC;IAEnC;;;;;OAKG;IACK,KAAK,CAAU;IAEvB;;;;OAIG;IACK,UAAU,CAAU;IAE5B;;OAEG;IACM,MAAM,CAAqB;IAEpC;;OAEG;IACM,OAAO,CAAqB;IAE7B,MAAM,CAAqB;IAC3B,YAAY,GAAG,KAAK,CAAC;IACrB,oBAAoB,GAAG,KAAK,CAAC;IAErC,gBAAgB;QACd,2EAA2E;QAC3E,yEAAyE;QACzE,2DAA2D;QAC3D,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, Watch, h } from '@stencil/core';\n\nimport { lockScroll as lockPageScroll, unlockScroll as unlockPageScroll } from '../../utils/scroll-lock';\n\nexport type ChDrawerSide = 'start' | 'end' | 'top' | 'bottom';\n\n/**\n * Sliding side panel for navigation, editing forms and quick detail views.\n *\n * Built on the native `<dialog>` element and opened with `showModal()`, exactly\n * like `ch-modal`, so the browser owns focus management, the inert background,\n * `Escape`, the top layer, `::backdrop`, and the implicit `dialog` role with\n * `aria-modal=\"true\"`. The only differences are placement — anchored to one\n * edge instead of centred — and the longer content it is meant for, which is\n * why it exposes `header` and `footer` slots around a scrollable body.\n *\n * Scroll locking is shared with `ch-modal` through `utils/scroll-lock`, so a\n * drawer and a modal opened together cannot unlock the page early.\n */\n@Component({\n tag: 'ch-drawer',\n styleUrl: 'ch-drawer.css',\n shadow: true,\n})\nexport class ChDrawer {\n /**\n * Whether the drawer 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 * The edge the panel slides in from. `start`/`end` follow the writing\n * direction, so `start` is the left edge in LTR and the right edge in RTL.\n */\n @Prop() side: ChDrawerSide = 'end';\n\n /**\n * Accessible name for the drawer, 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 drawer opens.\n */\n @Event() chOpen: EventEmitter<void>;\n\n /**\n * Emitted after the drawer 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 lockPageScroll();\n }\n\n private unlockScroll() {\n if (!this.scrollLocked) {\n return;\n }\n this.scrollLocked = false;\n unlockPageScroll();\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 drawer, 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={{ drawer: true, [`drawer--${this.side}`]: true }} aria-label={this.label} ref={el => (this.dialog = el as HTMLDialogElement)}>\n <div class=\"drawer-head\">\n <slot name=\"header\"></slot>\n {this.closeLabel && (\n <button class=\"drawer-close\" type=\"button\" aria-label={this.closeLabel} onClick={this.handleCloseClick}>\n <span aria-hidden=\"true\">×</span>\n </button>\n )}\n </div>\n <div class=\"drawer-body\">\n <slot></slot>\n </div>\n <slot name=\"footer\"></slot>\n </dialog>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -49,7 +49,7 @@ export class ChEmoji {
|
|
|
49
49
|
this.loaded = true;
|
|
50
50
|
};
|
|
51
51
|
render() {
|
|
52
|
-
return (h(Host, { key: '
|
|
52
|
+
return (h(Host, { key: '494b67e2300a9e1e9bb013aeefa6154cd26984ee' }, h("img", { key: 'f05cacf5cdfdf09ba21a5841a6571741aa86e8b5', class: {
|
|
53
53
|
'emoji': true,
|
|
54
54
|
[`emoji--${this.size}`]: true,
|
|
55
55
|
'emoji--hidden': !this.loaded,
|
|
@@ -109,7 +109,7 @@ export class ChInput {
|
|
|
109
109
|
return undefined;
|
|
110
110
|
}
|
|
111
111
|
render() {
|
|
112
|
-
return (h(Host, { key: '
|
|
112
|
+
return (h(Host, { key: 'cf143097fd39199c6c8a81484a4e8621e7c4d9cb' }, this.label && (h("label", { key: '40643f72949b11fc7dcdd4a43794a37103708992', class: "label", htmlFor: this.inputId }, this.label)), h("input", { key: 'ab3a0b8cc51e9c863001ddb089516bbf0874e889', id: this.label ? this.inputId : undefined, class: { 'input': true, 'input--invalid': this.invalid }, type: this.type, name: this.name, placeholder: this.placeholder, disabled: this.disabled || this.formDisabled, required: this.required, value: this.value, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onInput: this.handleInput, onChange: this.handleChange }), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: 'ad7eb7b40aaab69b6bc929c632ce4736fe3c39a5', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '6f7738076128a8242d1dcc97ac99ee1275fc7e14', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
113
113
|
}
|
|
114
114
|
static get is() { return "ch-input"; }
|
|
115
115
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
.modal {
|
|
2
2
|
box-sizing: border-box;
|
|
3
|
-
max-width: min(32rem, calc(100vw - var(--spacing-6xl)));
|
|
4
3
|
max-height: calc(100vh - var(--spacing-6xl));
|
|
5
4
|
padding: var(--spacing-5xl);
|
|
6
5
|
border: var(--border-width) solid var(--border);
|
|
@@ -11,6 +10,18 @@
|
|
|
11
10
|
font-size: var(--typography-size-md);
|
|
12
11
|
}
|
|
13
12
|
|
|
13
|
+
.modal--sm {
|
|
14
|
+
max-width: min(var(--ch-modal-width, 24rem), calc(100vw - var(--spacing-6xl)));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.modal--md {
|
|
18
|
+
max-width: min(var(--ch-modal-width, 32rem), calc(100vw - var(--spacing-6xl)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.modal--lg {
|
|
22
|
+
max-width: min(var(--ch-modal-width, 48rem), calc(100vw - var(--spacing-6xl)));
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
.modal::backdrop {
|
|
15
26
|
background: var(--color-scrim-default);
|
|
16
27
|
backdrop-filter: blur(var(--effect-blur));
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
|
-
|
|
3
|
-
let previousOverflow = '';
|
|
4
|
-
let previousPaddingRight = '';
|
|
2
|
+
import { lockScroll as lockPageScroll, unlockScroll as unlockPageScroll } from "../../utils/scroll-lock";
|
|
5
3
|
/**
|
|
6
4
|
* Modal dialog, built on the native `<dialog>` element and opened with
|
|
7
5
|
* `showModal()`.
|
|
@@ -39,6 +37,13 @@ export class ChModal {
|
|
|
39
37
|
* label it would have no accessible name.
|
|
40
38
|
*/
|
|
41
39
|
closeLabel;
|
|
40
|
+
/**
|
|
41
|
+
* The maximum width of the dialog. One of `sm` (24rem), `md` (32rem), or
|
|
42
|
+
* `lg` (48rem). The `--ch-modal-width` custom property overrides it for a
|
|
43
|
+
* width none of the three cover. Either way the dialog never exceeds the
|
|
44
|
+
* viewport.
|
|
45
|
+
*/
|
|
46
|
+
size = 'md';
|
|
42
47
|
/**
|
|
43
48
|
* Emitted after the dialog opens.
|
|
44
49
|
*/
|
|
@@ -93,31 +98,14 @@ export class ChModal {
|
|
|
93
98
|
return;
|
|
94
99
|
}
|
|
95
100
|
this.scrollLocked = true;
|
|
96
|
-
|
|
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
|
-
}
|
|
101
|
+
lockPageScroll();
|
|
108
102
|
}
|
|
109
103
|
unlockScroll() {
|
|
110
104
|
if (!this.scrollLocked) {
|
|
111
105
|
return;
|
|
112
106
|
}
|
|
113
107
|
this.scrollLocked = false;
|
|
114
|
-
|
|
115
|
-
if (openModals > 0) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const root = document.documentElement;
|
|
119
|
-
root.style.overflow = previousOverflow;
|
|
120
|
-
root.style.paddingRight = previousPaddingRight;
|
|
108
|
+
unlockPageScroll();
|
|
121
109
|
}
|
|
122
110
|
/**
|
|
123
111
|
* True for a pointer event on the backdrop: the `<dialog>` is the event
|
|
@@ -159,7 +147,7 @@ export class ChModal {
|
|
|
159
147
|
this.chClose.emit();
|
|
160
148
|
};
|
|
161
149
|
render() {
|
|
162
|
-
return (h(Host, { key: '
|
|
150
|
+
return (h(Host, { key: 'd4dfbaad43391e3f34eb890b0d04a6ee38fa82e5' }, h("dialog", { key: '3a3142c9baee06b381c7aaa920718f92bb8f1176', class: { modal: true, [`modal--${this.size}`]: true }, "aria-label": this.label, ref: el => (this.dialog = el) }, h("div", { key: '34855134cc5cb2701a9b8b60ee46087d4f00fd13', class: "modal-head" }, h("slot", { key: '7fa6a49a0f6b914fc8b825009bb46f5cd799f33b', name: "heading" }), this.closeLabel && (h("button", { key: '55f15f81f94c7a08f54e9d6f9a722452b32f01af', class: "modal-close", type: "button", "aria-label": this.closeLabel, onClick: this.handleCloseClick }, h("span", { key: '545af17e1065c558a1cc5274a444f610a77a3044', "aria-hidden": "true" }, "\u00D7")))), h("div", { key: 'a78ea4c9f66c03d641c9ef1aa14058b6371160fb', class: "modal-body" }, h("slot", { key: 'ffc1accb70cfc2e8ee6f11088a3a1da09a8b3430' })))));
|
|
163
151
|
}
|
|
164
152
|
static get is() { return "ch-modal"; }
|
|
165
153
|
static get encapsulation() { return "shadow"; }
|
|
@@ -232,6 +220,32 @@ export class ChModal {
|
|
|
232
220
|
"setter": false,
|
|
233
221
|
"reflect": false,
|
|
234
222
|
"attribute": "close-label"
|
|
223
|
+
},
|
|
224
|
+
"size": {
|
|
225
|
+
"type": "string",
|
|
226
|
+
"mutable": false,
|
|
227
|
+
"complexType": {
|
|
228
|
+
"original": "ChModalSize",
|
|
229
|
+
"resolved": "\"lg\" | \"md\" | \"sm\"",
|
|
230
|
+
"references": {
|
|
231
|
+
"ChModalSize": {
|
|
232
|
+
"location": "local",
|
|
233
|
+
"path": "/home/runner/work/chucao/chucao/src/components/ch-modal/ch-modal.tsx",
|
|
234
|
+
"id": "src/components/ch-modal/ch-modal.tsx::ChModalSize"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"required": false,
|
|
239
|
+
"optional": false,
|
|
240
|
+
"docs": {
|
|
241
|
+
"tags": [],
|
|
242
|
+
"text": "The maximum width of the dialog. One of `sm` (24rem), `md` (32rem), or\n`lg` (48rem). The `--ch-modal-width` custom property overrides it for a\nwidth none of the three cover. Either way the dialog never exceeds the\nviewport."
|
|
243
|
+
},
|
|
244
|
+
"getter": false,
|
|
245
|
+
"setter": false,
|
|
246
|
+
"reflect": false,
|
|
247
|
+
"attribute": "size",
|
|
248
|
+
"defaultValue": "'md'"
|
|
235
249
|
}
|
|
236
250
|
};
|
|
237
251
|
}
|
|
@@ -1 +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;IACM,MAAM,CAAqB;IAEpC;;OAEG;IACM,OAAO,CAAqB;IAE7B,MAAM,CAAqB;IAC3B,YAAY,GAAG,KAAK,CAAC;IACrB,oBAAoB,GAAG,KAAK,CAAC;IAErC,gBAAgB;QACd,2EAA2E;QAC3E,yEAAyE;QACzE,2DAA2D;QAC3D,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,E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,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"]}
|
|
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,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIzG;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,OAAO,OAAO;IAClB;;;OAGG;IACsB,IAAI,GAAG,KAAK,CAAC;IAEtC;;;;;OAKG;IACK,KAAK,CAAU;IAEvB;;;;OAIG;IACK,UAAU,CAAU;IAE5B;;;;;OAKG;IACK,IAAI,GAAgB,IAAI,CAAC;IAEjC;;OAEG;IACM,MAAM,CAAqB;IAEpC;;OAEG;IACM,OAAO,CAAqB;IAE7B,MAAM,CAAqB;IAC3B,YAAY,GAAG,KAAK,CAAC;IACrB,oBAAoB,GAAG,KAAK,CAAC;IAErC,gBAAgB;QACd,2EAA2E;QAC3E,yEAAyE;QACzE,2DAA2D;QAC3D,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACzD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAED,oBAAoB;QAClB,IAAI,CAAC,MAAM,EAAE,mBAA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,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,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAc,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,EAAuB,CAAC;gBACvI,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\nimport { lockScroll as lockPageScroll, unlockScroll as unlockPageScroll } from '../../utils/scroll-lock';\n\nexport type ChModalSize = 'sm' | 'md' | 'lg';\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 * The maximum width of the dialog. One of `sm` (24rem), `md` (32rem), or\n * `lg` (48rem). The `--ch-modal-width` custom property overrides it for a\n * width none of the three cover. Either way the dialog never exceeds the\n * viewport.\n */\n @Prop() size: ChModalSize = 'md';\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 lockPageScroll();\n }\n\n private unlockScroll() {\n if (!this.scrollLocked) {\n return;\n }\n this.scrollLocked = false;\n unlockPageScroll();\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: true, [`modal--${this.size}`]: true }} 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"]}
|
|
@@ -100,7 +100,7 @@ export class ChRadio {
|
|
|
100
100
|
}
|
|
101
101
|
render() {
|
|
102
102
|
const groupName = this.name || `${this.groupId}-group`;
|
|
103
|
-
return (h(Host, { key: '
|
|
103
|
+
return (h(Host, { key: '67d5306b86b9c5f6a085748cf18bcd8421afb7df' }, this.label && (h("span", { key: '65ff0ced1f1954899765b1df3e77a0a10830b952', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '65d1a571a6a88ded21b3adc25dff9bd9cfbc5634', 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: '328c40801e34c823de319f5de92be8eb19360bcb', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '3606463c798a7bd3ff0545e7691107cf506a2df1', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
104
104
|
}
|
|
105
105
|
static get is() { return "ch-radio"; }
|
|
106
106
|
static get encapsulation() { return "shadow"; }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
max-width: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.group-label {
|
|
7
|
+
display: block;
|
|
8
|
+
margin-bottom: var(--spacing-sm);
|
|
9
|
+
font-size: var(--typography-size-sm);
|
|
10
|
+
font-weight: var(--typography-weight-semibold);
|
|
11
|
+
color: var(--text);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.segmented {
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: stretch;
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
padding: var(--spacing-2xs);
|
|
19
|
+
border: var(--border-width) solid var(--border);
|
|
20
|
+
border-radius: var(--radius-pill);
|
|
21
|
+
background: var(--surface);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.control {
|
|
25
|
+
position: relative;
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
border-radius: var(--radius-pill);
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
transition: background-color var(--duration-normal) var(--easing-default);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.control:hover:not(.control--disabled) {
|
|
35
|
+
background: var(--surface-hover);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.control--disabled {
|
|
39
|
+
opacity: var(--opacity-disabled);
|
|
40
|
+
cursor: not-allowed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.input {
|
|
44
|
+
position: absolute;
|
|
45
|
+
inset: 0;
|
|
46
|
+
margin: 0;
|
|
47
|
+
opacity: 0;
|
|
48
|
+
cursor: inherit;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.input:checked ~ .label-text {
|
|
52
|
+
background: var(--accent);
|
|
53
|
+
color: var(--color-accent-text);
|
|
54
|
+
font-weight: var(--typography-weight-semibold);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.input:focus-visible ~ .label-text {
|
|
58
|
+
outline: var(--focus-outline-width) solid var(--accent);
|
|
59
|
+
outline-offset: var(--focus-outline-offset);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.label-text {
|
|
63
|
+
display: block;
|
|
64
|
+
padding: var(--spacing-2xs) var(--spacing-3xl);
|
|
65
|
+
border-radius: inherit;
|
|
66
|
+
font-size: var(--typography-size-sm);
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
transition:
|
|
69
|
+
background-color var(--duration-normal) var(--easing-default),
|
|
70
|
+
color var(--duration-normal) var(--easing-default);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.segmented--sm .label-text {
|
|
74
|
+
padding: var(--spacing-2xs) var(--spacing-2xl);
|
|
75
|
+
font-size: var(--typography-size-xs);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:host([data-touched]:invalid) .segmented,
|
|
79
|
+
:host(:user-invalid) .segmented {
|
|
80
|
+
border-color: var(--color-status-warning);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@media (prefers-reduced-motion: reduce) {
|
|
84
|
+
.control,
|
|
85
|
+
.label-text {
|
|
86
|
+
transition: none;
|
|
87
|
+
}
|
|
88
|
+
}
|