@devschile/chucao 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/chucao/chucao.esm.js +1 -1
- package/dist/chucao/chucao.esm.js.map +1 -1
- package/dist/chucao/{p-a0ec231a.entry.js → p-04dbcfa0.entry.js} +2 -2
- package/dist/chucao/{p-96c852f5.entry.js → p-077dc2a6.entry.js} +2 -2
- package/dist/chucao/{p-19dde4f9.entry.js → p-079c2017.entry.js} +2 -2
- package/dist/chucao/p-37e7f9cc.entry.js +2 -0
- package/dist/chucao/p-37e7f9cc.entry.js.map +1 -0
- package/dist/chucao/{p-f04d2f75.entry.js → p-5ae89a19.entry.js} +2 -2
- package/dist/chucao/p-70285203.entry.js +2 -0
- package/dist/chucao/p-70285203.entry.js.map +1 -0
- package/dist/chucao/{p-2e20c7a1.entry.js → p-9c072600.entry.js} +2 -2
- package/dist/chucao/{p-BaKXvAYc.js → p-DWC12BJ-.js} +2 -2
- package/dist/chucao/p-DWC12BJ-.js.map +1 -0
- package/dist/chucao/p-b678a7e2.entry.js +2 -0
- package/dist/chucao/p-b678a7e2.entry.js.map +1 -0
- package/dist/chucao/p-b8bd0310.entry.js +2 -0
- package/dist/chucao/p-b8bd0310.entry.js.map +1 -0
- package/dist/chucao/p-bb2445d1.entry.js +2 -0
- package/dist/chucao/p-c986036f.entry.js +2 -0
- package/dist/chucao/p-c986036f.entry.js.map +1 -0
- package/dist/chucao/p-d8DfpzMR.js +2 -0
- package/dist/chucao/p-d8DfpzMR.js.map +1 -0
- package/dist/chucao/{p-10658dc9.entry.js → p-e3265e38.entry.js} +2 -2
- package/dist/chucao/{p-f62e1da2.entry.js → p-ff5f5c1f.entry.js} +2 -2
- package/dist/cjs/ch-accordion.cjs.entry.js +1 -1
- package/dist/cjs/ch-alert_8.cjs.entry.js +55 -12
- package/dist/cjs/ch-alert_8.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-checkbox.cjs.entry.js +2 -2
- package/dist/cjs/ch-divider.cjs.entry.js +2 -2
- 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 +104 -0
- package/dist/cjs/ch-emoji.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-link.cjs.entry.js +1 -1
- package/dist/cjs/ch-modal.cjs.entry.js +5 -24
- package/dist/cjs/ch-modal.cjs.entry.js.map +1 -1
- package/dist/cjs/ch-radio.cjs.entry.js +2 -2
- 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 +2 -2
- package/dist/cjs/ch-textarea.cjs.entry.js +2 -2
- package/dist/cjs/ch-tooltip.cjs.entry.js +2 -2
- package/dist/cjs/chucao.cjs.js +3 -3
- package/dist/cjs/chucao.cjs.js.map +1 -1
- package/dist/cjs/{index-C9Abf0td.js → index-C9cpLteP.js} +15 -8
- package/dist/cjs/index-C9cpLteP.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- 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 +4 -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.css +33 -0
- package/dist/collection/components/ch-emoji/ch-emoji.js +151 -0
- package/dist/collection/components/ch-emoji/ch-emoji.js.map +1 -0
- package/dist/collection/components/ch-input/ch-input.js +1 -1
- package/dist/collection/components/ch-modal/ch-modal.js +4 -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-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-button.js.map +1 -1
- package/dist/components/ch-card.js +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.d.ts +11 -0
- package/dist/components/ch-emoji.js +2 -0
- package/dist/components/ch-emoji.js.map +1 -0
- package/dist/components/ch-input.js +1 -1
- package/dist/components/ch-link.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/index.js +1 -1
- package/dist/components/{p-DL-bL54o.js → p-BhAZrOxf.js} +2 -2
- package/dist/components/p-BhAZrOxf.js.map +1 -0
- package/dist/components/p-C4eGmLcE.js +2 -0
- package/dist/components/p-C4eGmLcE.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-accordion.entry.js +1 -1
- package/dist/esm/ch-alert_8.entry.js +55 -12
- package/dist/esm/ch-alert_8.entry.js.map +1 -1
- package/dist/esm/ch-checkbox.entry.js +2 -2
- package/dist/esm/ch-divider.entry.js +2 -2
- 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 +102 -0
- package/dist/esm/ch-emoji.entry.js.map +1 -0
- package/dist/esm/ch-link.entry.js +1 -1
- package/dist/esm/ch-modal.entry.js +5 -24
- package/dist/esm/ch-modal.entry.js.map +1 -1
- package/dist/esm/ch-radio.entry.js +2 -2
- 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 +2 -2
- package/dist/esm/ch-textarea.entry.js +2 -2
- package/dist/esm/ch-tooltip.entry.js +2 -2
- package/dist/esm/chucao.js +4 -4
- package/dist/esm/chucao.js.map +1 -1
- package/dist/esm/{index-BaKXvAYc.js → index-DWC12BJ-.js} +15 -8
- package/dist/esm/index-DWC12BJ-.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- 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-emoji/ch-emoji.d.ts +32 -0
- package/dist/types/components/ch-segmented-control/ch-segmented-control.d.ts +72 -0
- package/dist/types/components.d.ts +405 -6
- package/dist/types/stencil-public-runtime.d.ts +1 -0
- package/dist/types/utils/scroll-lock.d.ts +17 -0
- package/dist-react/components.d.ts +15 -1
- package/dist-react/components.js +30 -0
- package/dist-react/components.ts +43 -1
- package/dist-vue/index.d.ts +3 -0
- package/dist-vue/index.js +35 -0
- package/dist-vue/index.ts +41 -0
- package/hydrate/index.js +541 -46
- package/hydrate/index.mjs +541 -46
- package/loader/index.d.ts +1 -1
- package/package.json +5 -3
- package/dist/chucao/p-66dce533.entry.js +0 -2
- package/dist/chucao/p-66dce533.entry.js.map +0 -1
- package/dist/chucao/p-75184fe1.entry.js +0 -2
- package/dist/chucao/p-75184fe1.entry.js.map +0 -1
- package/dist/chucao/p-BaKXvAYc.js.map +0 -1
- package/dist/chucao/p-e48912c7.entry.js +0 -2
- package/dist/cjs/index-C9Abf0td.js.map +0 -1
- package/dist/components/p-DL-bL54o.js.map +0 -1
- package/dist/esm/index-BaKXvAYc.js.map +0 -1
- /package/dist/chucao/{p-a0ec231a.entry.js.map → p-04dbcfa0.entry.js.map} +0 -0
- /package/dist/chucao/{p-96c852f5.entry.js.map → p-077dc2a6.entry.js.map} +0 -0
- /package/dist/chucao/{p-19dde4f9.entry.js.map → p-079c2017.entry.js.map} +0 -0
- /package/dist/chucao/{p-f04d2f75.entry.js.map → p-5ae89a19.entry.js.map} +0 -0
- /package/dist/chucao/{p-2e20c7a1.entry.js.map → p-9c072600.entry.js.map} +0 -0
- /package/dist/chucao/{p-e48912c7.entry.js.map → p-bb2445d1.entry.js.map} +0 -0
- /package/dist/chucao/{p-10658dc9.entry.js.map → p-e3265e38.entry.js.map} +0 -0
- /package/dist/chucao/{p-f62e1da2.entry.js.map → p-ff5f5c1f.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,CAAC;QACrE,I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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"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
vertical-align: middle;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.emoji {
|
|
7
|
+
display: block;
|
|
8
|
+
object-fit: contain;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.emoji--sm {
|
|
12
|
+
width: 16px;
|
|
13
|
+
height: 16px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.emoji--md {
|
|
17
|
+
width: 24px;
|
|
18
|
+
height: 24px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.emoji--lg {
|
|
22
|
+
width: 32px;
|
|
23
|
+
height: 32px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.emoji--xl {
|
|
27
|
+
width: 48px;
|
|
28
|
+
height: 48px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.emoji--hidden {
|
|
32
|
+
display: none;
|
|
33
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
import emojiMap from "./emoji-map.json";
|
|
3
|
+
const CDN_BASE = 'https://static.devschile.cl/emoji';
|
|
4
|
+
const EXTENSIONS = ['png', 'gif', 'jpg', 'svg'];
|
|
5
|
+
/**
|
|
6
|
+
* Inline emoji from the devsChile CDN.
|
|
7
|
+
*
|
|
8
|
+
* Given a name (or alias from the emoji map), the component resolves the
|
|
9
|
+
* asset URL and tries each possible file extension until one loads.
|
|
10
|
+
* Size is controlled via the `size` prop.
|
|
11
|
+
*/
|
|
12
|
+
export class ChEmoji {
|
|
13
|
+
extIndex = 0;
|
|
14
|
+
loaded = false;
|
|
15
|
+
/**
|
|
16
|
+
* The emoji name or alias, e.g. `"huemul-love"` or `"heart"`.
|
|
17
|
+
*/
|
|
18
|
+
name;
|
|
19
|
+
/**
|
|
20
|
+
* Accessible alt text for the image. Defaults to the `name` prop.
|
|
21
|
+
*/
|
|
22
|
+
alt;
|
|
23
|
+
/**
|
|
24
|
+
* Size of the emoji. Either `sm`, `md`, `lg`, or `xl`.
|
|
25
|
+
*/
|
|
26
|
+
size = 'md';
|
|
27
|
+
componentWillLoad() {
|
|
28
|
+
this.resolveAsset();
|
|
29
|
+
}
|
|
30
|
+
handleNameChange() {
|
|
31
|
+
this.resolveAsset();
|
|
32
|
+
}
|
|
33
|
+
resolveAsset() {
|
|
34
|
+
this.extIndex = 0;
|
|
35
|
+
this.loaded = false;
|
|
36
|
+
}
|
|
37
|
+
get assetName() {
|
|
38
|
+
return emojiMap[this.name] ?? this.name;
|
|
39
|
+
}
|
|
40
|
+
get currentSrc() {
|
|
41
|
+
return `${CDN_BASE}/${this.assetName}.${EXTENSIONS[this.extIndex]}`;
|
|
42
|
+
}
|
|
43
|
+
handleError = () => {
|
|
44
|
+
if (this.extIndex < EXTENSIONS.length - 1) {
|
|
45
|
+
this.extIndex++;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
handleLoad = () => {
|
|
49
|
+
this.loaded = true;
|
|
50
|
+
};
|
|
51
|
+
render() {
|
|
52
|
+
return (h(Host, { key: '494b67e2300a9e1e9bb013aeefa6154cd26984ee' }, h("img", { key: 'f05cacf5cdfdf09ba21a5841a6571741aa86e8b5', class: {
|
|
53
|
+
'emoji': true,
|
|
54
|
+
[`emoji--${this.size}`]: true,
|
|
55
|
+
'emoji--hidden': !this.loaded,
|
|
56
|
+
}, src: this.currentSrc, alt: this.alt ?? this.name, onError: this.handleError, onLoad: this.handleLoad })));
|
|
57
|
+
}
|
|
58
|
+
static get is() { return "ch-emoji"; }
|
|
59
|
+
static get encapsulation() { return "shadow"; }
|
|
60
|
+
static get originalStyleUrls() {
|
|
61
|
+
return {
|
|
62
|
+
"$": ["ch-emoji.css"]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static get styleUrls() {
|
|
66
|
+
return {
|
|
67
|
+
"$": ["ch-emoji.css"]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
static get properties() {
|
|
71
|
+
return {
|
|
72
|
+
"name": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"mutable": false,
|
|
75
|
+
"complexType": {
|
|
76
|
+
"original": "string",
|
|
77
|
+
"resolved": "string",
|
|
78
|
+
"references": {}
|
|
79
|
+
},
|
|
80
|
+
"required": true,
|
|
81
|
+
"optional": false,
|
|
82
|
+
"docs": {
|
|
83
|
+
"tags": [],
|
|
84
|
+
"text": "The emoji name or alias, e.g. `\"huemul-love\"` or `\"heart\"`."
|
|
85
|
+
},
|
|
86
|
+
"getter": false,
|
|
87
|
+
"setter": false,
|
|
88
|
+
"reflect": false,
|
|
89
|
+
"attribute": "name"
|
|
90
|
+
},
|
|
91
|
+
"alt": {
|
|
92
|
+
"type": "string",
|
|
93
|
+
"mutable": false,
|
|
94
|
+
"complexType": {
|
|
95
|
+
"original": "string",
|
|
96
|
+
"resolved": "string",
|
|
97
|
+
"references": {}
|
|
98
|
+
},
|
|
99
|
+
"required": false,
|
|
100
|
+
"optional": true,
|
|
101
|
+
"docs": {
|
|
102
|
+
"tags": [],
|
|
103
|
+
"text": "Accessible alt text for the image. Defaults to the `name` prop."
|
|
104
|
+
},
|
|
105
|
+
"getter": false,
|
|
106
|
+
"setter": false,
|
|
107
|
+
"reflect": false,
|
|
108
|
+
"attribute": "alt"
|
|
109
|
+
},
|
|
110
|
+
"size": {
|
|
111
|
+
"type": "string",
|
|
112
|
+
"mutable": false,
|
|
113
|
+
"complexType": {
|
|
114
|
+
"original": "ChEmojiSize",
|
|
115
|
+
"resolved": "\"lg\" | \"md\" | \"sm\" | \"xl\"",
|
|
116
|
+
"references": {
|
|
117
|
+
"ChEmojiSize": {
|
|
118
|
+
"location": "local",
|
|
119
|
+
"path": "/home/runner/work/chucao/chucao/src/components/ch-emoji/ch-emoji.tsx",
|
|
120
|
+
"id": "src/components/ch-emoji/ch-emoji.tsx::ChEmojiSize"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"required": false,
|
|
125
|
+
"optional": false,
|
|
126
|
+
"docs": {
|
|
127
|
+
"tags": [],
|
|
128
|
+
"text": "Size of the emoji. Either `sm`, `md`, `lg`, or `xl`."
|
|
129
|
+
},
|
|
130
|
+
"getter": false,
|
|
131
|
+
"setter": false,
|
|
132
|
+
"reflect": false,
|
|
133
|
+
"attribute": "size",
|
|
134
|
+
"defaultValue": "'md'"
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
static get states() {
|
|
139
|
+
return {
|
|
140
|
+
"extIndex": {},
|
|
141
|
+
"loaded": {}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
static get watchers() {
|
|
145
|
+
return [{
|
|
146
|
+
"propName": "name",
|
|
147
|
+
"methodName": "handleNameChange"
|
|
148
|
+
}];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=ch-emoji.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ch-emoji.js","sourceRoot":"","sources":["../../../../src/components/ch-emoji/ch-emoji.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE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AO,CACL,EAAC,IAAI;YACH,4DACE,KAAK,EAAE;oBACL,OAAO,EAAE,IAAI;oBACb,CAAC,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI;oBAC7B,eAAe,EAAE,CAAC,IAAI,CAAC,MAAM;iBAC9B,EACD,GAAG,EAAE,IAAI,CAAC,UAAU,EACpB,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,EAC1B,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,MAAM,EAAE,IAAI,CAAC,UAAU,GACvB,CACG,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Host, Prop, State, Watch, h } from '@stencil/core';\n\nimport emojiMap from './emoji-map.json';\n\nexport type ChEmojiSize = 'sm' | 'md' | 'lg' | 'xl';\n\nconst CDN_BASE = 'https://static.devschile.cl/emoji';\nconst EXTENSIONS = ['png', 'gif', 'jpg', 'svg'];\n\n/**\n * Inline emoji from the devsChile CDN.\n *\n * Given a name (or alias from the emoji map), the component resolves the\n * asset URL and tries each possible file extension until one loads.\n * Size is controlled via the `size` prop.\n */\n@Component({\n tag: 'ch-emoji',\n styleUrl: 'ch-emoji.css',\n shadow: true,\n})\nexport class ChEmoji {\n @State() private extIndex = 0;\n @State() private loaded = false;\n\n /**\n * The emoji name or alias, e.g. `\"huemul-love\"` or `\"heart\"`.\n */\n @Prop() name!: string;\n\n /**\n * Accessible alt text for the image. Defaults to the `name` prop.\n */\n @Prop() alt?: string;\n\n /**\n * Size of the emoji. Either `sm`, `md`, `lg`, or `xl`.\n */\n @Prop() size: ChEmojiSize = 'md';\n\n componentWillLoad(): void {\n this.resolveAsset();\n }\n\n @Watch('name')\n handleNameChange(): void {\n this.resolveAsset();\n }\n\n private resolveAsset(): void {\n this.extIndex = 0;\n this.loaded = false;\n }\n\n private get assetName(): string {\n return (emojiMap as Record<string, string>)[this.name] ?? this.name;\n }\n\n private get currentSrc(): string {\n return `${CDN_BASE}/${this.assetName}.${EXTENSIONS[this.extIndex]}`;\n }\n\n private handleError = (): void => {\n if (this.extIndex < EXTENSIONS.length - 1) {\n this.extIndex++;\n }\n };\n\n private handleLoad = (): void => {\n this.loaded = true;\n };\n\n render() {\n return (\n <Host>\n <img\n class={{\n 'emoji': true,\n [`emoji--${this.size}`]: true,\n 'emoji--hidden': !this.loaded,\n }}\n src={this.currentSrc}\n alt={this.alt ?? this.name}\n onError={this.handleError}\n onLoad={this.handleLoad}\n />\n </Host>\n );\n }\n}\n"]}
|
|
@@ -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: '8f06015ae952c02467d45bb97d306eb7525a7429' }, this.label && (h("label", { key: '300cf07bfc4e79eb5904140e105d33fa96f09efe', class: "label", htmlFor: this.inputId }, this.label)), h("input", { key: '85ab8a0f5a35f421c9af6137bc691e6fb543e940', 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: '4a64db0bc1f03dd756dd55ecf6ff8b95de00dfe1', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'c1c8a0c8f719f53941180ae05b17710a5f7c212b', 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,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()`.
|
|
@@ -93,31 +91,14 @@ export class ChModal {
|
|
|
93
91
|
return;
|
|
94
92
|
}
|
|
95
93
|
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
|
-
}
|
|
94
|
+
lockPageScroll();
|
|
108
95
|
}
|
|
109
96
|
unlockScroll() {
|
|
110
97
|
if (!this.scrollLocked) {
|
|
111
98
|
return;
|
|
112
99
|
}
|
|
113
100
|
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;
|
|
101
|
+
unlockPageScroll();
|
|
121
102
|
}
|
|
122
103
|
/**
|
|
123
104
|
* True for a pointer event on the backdrop: the `<dialog>` is the event
|
|
@@ -159,7 +140,7 @@ export class ChModal {
|
|
|
159
140
|
this.chClose.emit();
|
|
160
141
|
};
|
|
161
142
|
render() {
|
|
162
|
-
return (h(Host, { key: '
|
|
143
|
+
return (h(Host, { key: '2a8271f9606bc98d0b054016a60afbcb36dfaa48' }, h("dialog", { key: '8c866544fd071b98a0b2e58df1690705347a183c', class: "modal", "aria-label": this.label, ref: el => (this.dialog = el) }, h("div", { key: 'fceb7d0e17ecfe639f518c26ea75abf96bf3469e', class: "modal-head" }, h("slot", { key: '89359d0e82b4c5694b8ad76bd7c67b2a1a80f11a', name: "heading" }), this.closeLabel && (h("button", { key: 'edcf61410f993d367613a4bd485c63336ee82619', class: "modal-close", type: "button", "aria-label": this.closeLabel, onClick: this.handleCloseClick }, h("span", { key: '80ce411b41882508b805aeb1ad0caee07fbbeaaa', "aria-hidden": "true" }, "\u00D7")))), h("div", { key: 'd0f72191474917a8e4c68c4996a40340c4494651', class: "modal-body" }, h("slot", { key: '46c1d56f416a742176b4be753aa7a8af14bb579d' })))));
|
|
163
144
|
}
|
|
164
145
|
static get is() { return "ch-modal"; }
|
|
165
146
|
static get encapsulation() { return "shadow"; }
|
|
@@ -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;QAC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D,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"]}
|
|
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;AAEzG;;;;;;;;;;;;;;;;;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,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,mBA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C,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\nimport { lockScroll as lockPageScroll, unlockScroll as unlockPageScroll } from '../../utils/scroll-lock';\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 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\" 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: '3cd55c205d303df45671dc76756b1fcc78baf760' }, this.label && (h("span", { key: '0e9ab53baa202dff829a46e8674d7f994f9f14b9', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '584e1e36954f7daad8b71c9b690f7fe42f53bb09', 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: '9030ddc9030ea728d56fa2f5520f9df26df75f0d', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'e2ba85ff960ae61f4b882190e19558f6189c569b', 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"; }
|