@devschile/chucao 2.7.0 → 2.8.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-10109256.entry.js → p-0831c6f2.entry.js} +2 -2
- package/dist/chucao/p-0d7fc720.entry.js +2 -0
- package/dist/chucao/{p-62e762f7.entry.js.map → p-0d7fc720.entry.js.map} +1 -1
- package/dist/chucao/{p-999dba28.entry.js → p-19d90f87.entry.js} +2 -2
- package/dist/chucao/{p-afe45116.entry.js → p-25f4f815.entry.js} +2 -2
- package/dist/chucao/{p-14184080.entry.js → p-3e0d7585.entry.js} +2 -2
- package/dist/chucao/{p-afacd489.entry.js → p-46dae34b.entry.js} +2 -2
- package/dist/chucao/{p-d1e9f563.entry.js → p-5093c486.entry.js} +2 -2
- package/dist/chucao/{p-337d7f68.entry.js → p-51f6327c.entry.js} +2 -2
- package/dist/chucao/{p-bf036509.entry.js → p-5577e0a0.entry.js} +2 -2
- package/dist/chucao/{p-339e3c30.entry.js → p-56e41372.entry.js} +2 -2
- package/dist/chucao/{p-a84d4493.entry.js → p-6c2e5931.entry.js} +2 -2
- package/dist/chucao/{p-1e8d921d.entry.js → p-6e93c392.entry.js} +2 -2
- package/dist/chucao/{p-93f25dd5.entry.js → p-7f99ae48.entry.js} +2 -2
- package/dist/chucao/p-8b09ad3c.entry.js +2 -0
- package/dist/chucao/p-8b09ad3c.entry.js.map +1 -0
- package/dist/chucao/{p-e2fe7c5d.entry.js → p-8fcf6d36.entry.js} +2 -2
- package/dist/chucao/{p-CIV5Gg1o.js → p-8l_6qAY9.js} +3 -3
- package/dist/chucao/p-8l_6qAY9.js.map +1 -0
- package/dist/chucao/{p-d2077ae4.entry.js → p-920d5727.entry.js} +2 -2
- package/dist/chucao/{p-1852dfdb.entry.js → p-ad41da02.entry.js} +2 -2
- package/dist/chucao/p-af088ffd.entry.js +2 -0
- package/dist/chucao/p-af088ffd.entry.js.map +1 -0
- package/dist/chucao/{p-08d90a3d.entry.js → p-b42ec9bf.entry.js} +2 -2
- package/dist/chucao/{p-36c59ad1.entry.js → p-b80c39c3.entry.js} +2 -2
- package/dist/chucao/{p-507d4b69.entry.js → p-ba589c2f.entry.js} +2 -2
- package/dist/chucao/{p-39815ee2.entry.js → p-c4d68ab7.entry.js} +2 -2
- package/dist/chucao/{p-3e6614ee.entry.js → p-c98e2a50.entry.js} +2 -2
- package/dist/chucao/{p-4c8838a0.entry.js → p-ca3179ae.entry.js} +2 -2
- package/dist/chucao/{p-3f9894a4.entry.js → p-d630f662.entry.js} +2 -2
- package/dist/chucao/{p-4cda7f71.entry.js → p-d868bdbc.entry.js} +2 -2
- package/dist/chucao/{p-f17b186f.entry.js → p-e6b7b2da.entry.js} +2 -2
- package/dist/chucao/p-eb39b9c2.entry.js +2 -0
- package/dist/chucao/p-eb39b9c2.entry.js.map +1 -0
- package/dist/chucao/p-f0c288db.entry.js +2 -0
- package/dist/chucao/p-f0c288db.entry.js.map +1 -0
- package/dist/cjs/ch-accordion.cjs.entry.js +2 -2
- package/dist/cjs/ch-alert_8.cjs.entry.js +8 -8
- package/dist/cjs/ch-checkbox.cjs.entry.js +2 -2
- package/dist/cjs/ch-cluster.cjs.entry.js +3 -3
- package/dist/cjs/ch-confirm-dialog.cjs.entry.js +138 -0
- package/dist/cjs/ch-confirm-dialog.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-description-list.cjs.entry.js +2 -2
- package/dist/cjs/ch-divider.cjs.entry.js +2 -2
- package/dist/cjs/ch-drawer.cjs.entry.js +2 -2
- package/dist/cjs/ch-emoji.cjs.entry.js +2 -2
- package/dist/cjs/ch-empty-state.cjs.entry.js +2 -2
- package/dist/cjs/ch-grid.cjs.entry.js +2 -2
- package/dist/cjs/ch-icon-button.cjs.entry.js +2 -2
- package/dist/cjs/ch-icon.cjs.entry.js +2 -2
- package/dist/cjs/ch-link.cjs.entry.js +1 -1
- package/dist/cjs/ch-modal.cjs.entry.js +2 -2
- package/dist/cjs/ch-number-input.cjs.entry.js +3 -3
- package/dist/cjs/ch-otp-input.cjs.entry.js +196 -0
- package/dist/cjs/ch-otp-input.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-page-header.cjs.entry.js +2 -2
- package/dist/cjs/ch-pagination.cjs.entry.js +67 -0
- package/dist/cjs/ch-pagination.cjs.entry.js.map +1 -0
- package/dist/cjs/ch-radio.cjs.entry.js +2 -2
- package/dist/cjs/ch-segmented-control.cjs.entry.js +2 -2
- package/dist/cjs/ch-skeleton.cjs.entry.js +2 -2
- package/dist/cjs/ch-stack.cjs.entry.js +2 -2
- package/dist/cjs/ch-stat.cjs.entry.js +3 -3
- package/dist/cjs/ch-table.cjs.entry.js +2 -2
- package/dist/cjs/ch-tabs.cjs.entry.js +2 -2
- package/dist/cjs/ch-textarea.cjs.entry.js +2 -2
- package/dist/cjs/ch-timeline.cjs.entry.js +2 -2
- package/dist/cjs/ch-tooltip.cjs.entry.js +25 -8
- package/dist/cjs/ch-tooltip.cjs.entry.js.map +1 -1
- package/dist/cjs/chucao.cjs.js +2 -2
- package/dist/cjs/{index-ByZY6aTj.js → index-C6khqyw3.js} +19 -2
- package/dist/cjs/index-C6khqyw3.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +3 -0
- package/dist/collection/components/ch-accordion/ch-accordion.js +1 -1
- package/dist/collection/components/ch-alert/ch-alert.js +1 -1
- package/dist/collection/components/ch-badge/ch-badge.js +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-cluster/ch-cluster.js +2 -2
- package/dist/collection/components/ch-confirm-dialog/ch-confirm-dialog.css +71 -0
- package/dist/collection/components/ch-confirm-dialog/ch-confirm-dialog.js +382 -0
- package/dist/collection/components/ch-confirm-dialog/ch-confirm-dialog.js.map +1 -0
- package/dist/collection/components/ch-description-list/ch-description-list.js +1 -1
- package/dist/collection/components/ch-divider/ch-divider.js +1 -1
- package/dist/collection/components/ch-drawer/ch-drawer.js +1 -1
- package/dist/collection/components/ch-emoji/ch-emoji.js +1 -1
- package/dist/collection/components/ch-empty-state/ch-empty-state.js +1 -1
- package/dist/collection/components/ch-grid/ch-grid.js +1 -1
- package/dist/collection/components/ch-icon/ch-icon.js +1 -1
- package/dist/collection/components/ch-icon-button/ch-icon-button.js +1 -1
- package/dist/collection/components/ch-input/ch-input.js +1 -1
- package/dist/collection/components/ch-modal/ch-modal.js +1 -1
- package/dist/collection/components/ch-number-input/ch-number-input.js +2 -2
- package/dist/collection/components/ch-otp-input/ch-otp-input.css +86 -0
- package/dist/collection/components/ch-otp-input/ch-otp-input.js +478 -0
- package/dist/collection/components/ch-otp-input/ch-otp-input.js.map +1 -0
- package/dist/collection/components/ch-page-header/ch-page-header.js +1 -1
- package/dist/collection/components/ch-pagination/ch-pagination.css +63 -0
- package/dist/collection/components/ch-pagination/ch-pagination.js +228 -0
- package/dist/collection/components/ch-pagination/ch-pagination.js.map +1 -0
- package/dist/collection/components/ch-radio/ch-radio.js +1 -1
- package/dist/collection/components/ch-segmented-control/ch-segmented-control.js +1 -1
- package/dist/collection/components/ch-select/ch-select.js +1 -1
- package/dist/collection/components/ch-skeleton/ch-skeleton.js +1 -1
- package/dist/collection/components/ch-spinner/ch-spinner.js +1 -1
- package/dist/collection/components/ch-stack/ch-stack.js +1 -1
- package/dist/collection/components/ch-stat/ch-stat.js +2 -2
- package/dist/collection/components/ch-switch/ch-switch.js +1 -1
- package/dist/collection/components/ch-table/ch-table.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-timeline/ch-timeline.js +1 -1
- package/dist/collection/components/ch-tooltip/ch-tooltip.css +11 -0
- package/dist/collection/components/ch-tooltip/ch-tooltip.js +23 -6
- package/dist/collection/components/ch-tooltip/ch-tooltip.js.map +1 -1
- package/dist/collection/utils/overlay.js.map +1 -1
- package/dist/components/ch-accordion.js +1 -1
- package/dist/components/ch-alert.js +1 -1
- package/dist/components/ch-badge.js +1 -1
- package/dist/components/ch-button.js +1 -1
- package/dist/components/ch-card.js +1 -1
- package/dist/components/ch-checkbox.js +1 -1
- package/dist/components/ch-cluster.js +1 -1
- package/dist/components/ch-confirm-dialog.d.ts +11 -0
- package/dist/components/ch-confirm-dialog.js +2 -0
- package/dist/components/ch-confirm-dialog.js.map +1 -0
- package/dist/components/ch-description-list.js +1 -1
- package/dist/components/ch-divider.js +1 -1
- package/dist/components/ch-drawer.js +1 -1
- package/dist/components/ch-emoji.js +1 -1
- package/dist/components/ch-empty-state.js +1 -1
- package/dist/components/ch-grid.js +1 -1
- package/dist/components/ch-icon-button.js +1 -1
- package/dist/components/ch-icon.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-number-input.js +1 -1
- package/dist/components/ch-otp-input.d.ts +11 -0
- package/dist/components/ch-otp-input.js +2 -0
- package/dist/components/ch-otp-input.js.map +1 -0
- package/dist/components/ch-page-header.js +1 -1
- package/dist/components/ch-pagination.d.ts +11 -0
- package/dist/components/ch-pagination.js +2 -0
- package/dist/components/ch-pagination.js.map +1 -0
- package/dist/components/ch-radio.js +1 -1
- package/dist/components/ch-segmented-control.js +1 -1
- package/dist/components/ch-select.js +1 -1
- package/dist/components/ch-skeleton.js +1 -1
- package/dist/components/ch-spinner.js +1 -1
- package/dist/components/ch-stack.js +1 -1
- package/dist/components/ch-stat.js +1 -1
- package/dist/components/ch-switch.js +1 -1
- package/dist/components/ch-table.js +1 -1
- package/dist/components/ch-tabs.js +1 -1
- package/dist/components/ch-textarea.js +1 -1
- package/dist/components/ch-timeline.js +1 -1
- package/dist/components/ch-tooltip.js +1 -1
- package/dist/components/ch-tooltip.js.map +1 -1
- package/dist/components/{p-CuczWSQU.js → p-CF1yV0aa.js} +2 -2
- package/dist/components/p-CmMN-UuJ.js +2 -0
- package/dist/components/p-CmMN-UuJ.js.map +1 -0
- package/dist/components/p-qP_9qshx.js.map +1 -1
- package/dist/esm/ch-accordion.entry.js +2 -2
- package/dist/esm/ch-alert_8.entry.js +8 -8
- package/dist/esm/ch-checkbox.entry.js +2 -2
- package/dist/esm/ch-cluster.entry.js +3 -3
- package/dist/esm/ch-confirm-dialog.entry.js +136 -0
- package/dist/esm/ch-confirm-dialog.entry.js.map +1 -0
- package/dist/esm/ch-description-list.entry.js +2 -2
- package/dist/esm/ch-divider.entry.js +2 -2
- package/dist/esm/ch-drawer.entry.js +2 -2
- package/dist/esm/ch-emoji.entry.js +2 -2
- package/dist/esm/ch-empty-state.entry.js +2 -2
- package/dist/esm/ch-grid.entry.js +2 -2
- package/dist/esm/ch-icon-button.entry.js +2 -2
- package/dist/esm/ch-icon.entry.js +2 -2
- package/dist/esm/ch-link.entry.js +1 -1
- package/dist/esm/ch-modal.entry.js +2 -2
- package/dist/esm/ch-number-input.entry.js +3 -3
- package/dist/esm/ch-otp-input.entry.js +194 -0
- package/dist/esm/ch-otp-input.entry.js.map +1 -0
- package/dist/esm/ch-page-header.entry.js +2 -2
- package/dist/esm/ch-pagination.entry.js +65 -0
- package/dist/esm/ch-pagination.entry.js.map +1 -0
- package/dist/esm/ch-radio.entry.js +2 -2
- package/dist/esm/ch-segmented-control.entry.js +2 -2
- package/dist/esm/ch-skeleton.entry.js +2 -2
- package/dist/esm/ch-stack.entry.js +2 -2
- package/dist/esm/ch-stat.entry.js +3 -3
- package/dist/esm/ch-table.entry.js +2 -2
- package/dist/esm/ch-tabs.entry.js +2 -2
- package/dist/esm/ch-textarea.entry.js +2 -2
- package/dist/esm/ch-timeline.entry.js +2 -2
- package/dist/esm/ch-tooltip.entry.js +25 -8
- package/dist/esm/ch-tooltip.entry.js.map +1 -1
- package/dist/esm/chucao.js +3 -3
- package/dist/esm/{index-CIV5Gg1o.js → index-8l_6qAY9.js} +19 -2
- package/dist/esm/index-8l_6qAY9.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/types/components/ch-confirm-dialog/ch-confirm-dialog.d.ts +81 -0
- package/dist/types/components/ch-otp-input/ch-otp-input.d.ts +79 -0
- package/dist/types/components/ch-pagination/ch-pagination.d.ts +44 -0
- package/dist/types/components/ch-tooltip/ch-tooltip.d.ts +7 -0
- package/dist/types/components.d.ts +548 -0
- package/dist/types/utils/overlay.d.ts +1 -1
- package/dist-react/components.d.ts +21 -1
- package/dist-react/components.js +33 -0
- package/dist-react/components.ts +49 -1
- package/dist-vue/index.d.ts +3 -0
- package/dist-vue/index.js +48 -0
- package/dist-vue/index.ts +54 -0
- package/hydrate/index.js +540 -40
- package/hydrate/index.mjs +540 -40
- package/package.json +13 -1
- package/dist/chucao/p-5c253fa0.entry.js +0 -2
- package/dist/chucao/p-5c253fa0.entry.js.map +0 -1
- package/dist/chucao/p-62e762f7.entry.js +0 -2
- package/dist/chucao/p-CIV5Gg1o.js.map +0 -1
- package/dist/cjs/index-ByZY6aTj.js.map +0 -1
- package/dist/esm/index-CIV5Gg1o.js.map +0 -1
- /package/dist/chucao/{p-10109256.entry.js.map → p-0831c6f2.entry.js.map} +0 -0
- /package/dist/chucao/{p-999dba28.entry.js.map → p-19d90f87.entry.js.map} +0 -0
- /package/dist/chucao/{p-afe45116.entry.js.map → p-25f4f815.entry.js.map} +0 -0
- /package/dist/chucao/{p-14184080.entry.js.map → p-3e0d7585.entry.js.map} +0 -0
- /package/dist/chucao/{p-afacd489.entry.js.map → p-46dae34b.entry.js.map} +0 -0
- /package/dist/chucao/{p-d1e9f563.entry.js.map → p-5093c486.entry.js.map} +0 -0
- /package/dist/chucao/{p-337d7f68.entry.js.map → p-51f6327c.entry.js.map} +0 -0
- /package/dist/chucao/{p-bf036509.entry.js.map → p-5577e0a0.entry.js.map} +0 -0
- /package/dist/chucao/{p-339e3c30.entry.js.map → p-56e41372.entry.js.map} +0 -0
- /package/dist/chucao/{p-a84d4493.entry.js.map → p-6c2e5931.entry.js.map} +0 -0
- /package/dist/chucao/{p-1e8d921d.entry.js.map → p-6e93c392.entry.js.map} +0 -0
- /package/dist/chucao/{p-93f25dd5.entry.js.map → p-7f99ae48.entry.js.map} +0 -0
- /package/dist/chucao/{p-e2fe7c5d.entry.js.map → p-8fcf6d36.entry.js.map} +0 -0
- /package/dist/chucao/{p-d2077ae4.entry.js.map → p-920d5727.entry.js.map} +0 -0
- /package/dist/chucao/{p-1852dfdb.entry.js.map → p-ad41da02.entry.js.map} +0 -0
- /package/dist/chucao/{p-08d90a3d.entry.js.map → p-b42ec9bf.entry.js.map} +0 -0
- /package/dist/chucao/{p-36c59ad1.entry.js.map → p-b80c39c3.entry.js.map} +0 -0
- /package/dist/chucao/{p-507d4b69.entry.js.map → p-ba589c2f.entry.js.map} +0 -0
- /package/dist/chucao/{p-39815ee2.entry.js.map → p-c4d68ab7.entry.js.map} +0 -0
- /package/dist/chucao/{p-3e6614ee.entry.js.map → p-c98e2a50.entry.js.map} +0 -0
- /package/dist/chucao/{p-4c8838a0.entry.js.map → p-ca3179ae.entry.js.map} +0 -0
- /package/dist/chucao/{p-3f9894a4.entry.js.map → p-d630f662.entry.js.map} +0 -0
- /package/dist/chucao/{p-4cda7f71.entry.js.map → p-d868bdbc.entry.js.map} +0 -0
- /package/dist/chucao/{p-f17b186f.entry.js.map → p-e6b7b2da.entry.js.map} +0 -0
- /package/dist/components/{p-CuczWSQU.js.map → p-CF1yV0aa.js.map} +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Host, h } from "@stencil/core";
|
|
2
|
+
let paginationIds = 0;
|
|
3
|
+
/**
|
|
4
|
+
* Controlled pagination for a known total.
|
|
5
|
+
*
|
|
6
|
+
* It holds no page state: `page` and `pageSize` come from the consumer and
|
|
7
|
+
* every action emits `chPageChange` with the page it wants. That matches
|
|
8
|
+
* `ch-table`, so a consumer wiring the two together has one model to reason
|
|
9
|
+
* about — the table shows the rows for `page`, the pagination asks for the
|
|
10
|
+
* next one, and nothing moves until the consumer's data does.
|
|
11
|
+
*
|
|
12
|
+
* No numbered page list. A list of numbers is wrong more often than it is
|
|
13
|
+
* right (it depends on how many pages fit, which depends on the font, the
|
|
14
|
+
* locale and the container), and it is the part consumers most often need to
|
|
15
|
+
* replace with their own. Prev/next plus a position summary covers the
|
|
16
|
+
* default case; the summary is what tells a screen-reader user where they are.
|
|
17
|
+
*/
|
|
18
|
+
export class ChPagination {
|
|
19
|
+
labelId = `ch-pagination-${++paginationIds}`;
|
|
20
|
+
/** The current page, 1-based. Controlled by the consumer. */
|
|
21
|
+
page = 1;
|
|
22
|
+
/** How many rows a page holds. Controlled by the consumer. */
|
|
23
|
+
pageSize = 10;
|
|
24
|
+
/** How many rows exist in total. Zero renders a disabled, empty pager. */
|
|
25
|
+
total = 0;
|
|
26
|
+
/** Accessible name for the navigation landmark. */
|
|
27
|
+
label = 'Pagination';
|
|
28
|
+
/** Size of the controls. */
|
|
29
|
+
size = 'md';
|
|
30
|
+
/** Whether the whole control is disabled. */
|
|
31
|
+
disabled = false;
|
|
32
|
+
/** Emitted when the user asks for another page. The consumer applies it. */
|
|
33
|
+
chPageChange;
|
|
34
|
+
get pageCount() {
|
|
35
|
+
if (this.total <= 0 || this.pageSize <= 0) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
return Math.ceil(this.total / this.pageSize);
|
|
39
|
+
}
|
|
40
|
+
/** How many rows this page shows, which is short on the last page. */
|
|
41
|
+
get rowsOnPage() {
|
|
42
|
+
if (this.pageCount === 0) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
const remaining = this.total - (this.page - 1) * this.pageSize;
|
|
46
|
+
return Math.max(0, Math.min(this.pageSize, remaining));
|
|
47
|
+
}
|
|
48
|
+
get firstRow() {
|
|
49
|
+
return this.rowsOnPage === 0 ? 0 : (this.page - 1) * this.pageSize + 1;
|
|
50
|
+
}
|
|
51
|
+
get lastRow() {
|
|
52
|
+
return this.rowsOnPage === 0 ? 0 : this.firstRow + this.rowsOnPage - 1;
|
|
53
|
+
}
|
|
54
|
+
go(next) {
|
|
55
|
+
if (this.disabled || next < 1 || next > this.pageCount || next === this.page) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.chPageChange.emit({ page: next, pageSize: this.pageSize });
|
|
59
|
+
}
|
|
60
|
+
render() {
|
|
61
|
+
const count = this.pageCount;
|
|
62
|
+
const atStart = this.page <= 1;
|
|
63
|
+
const atEnd = count === 0 || this.page >= count;
|
|
64
|
+
const blocked = this.disabled || count === 0;
|
|
65
|
+
return (h(Host, { key: '82d5cbf478d149a09f17d43113374f0a9fdb626c' }, h("nav", { key: 'd6b712c900e61d03864e3b2f799a881f340b01a9', class: { pager: true, [`pager--${this.size}`]: true }, "aria-label": this.label }, h("button", { key: 'f3a2d877c6af803d8bde467efbc437c36502e7c3', class: "pager__button", type: "button", disabled: blocked || atStart, onClick: () => this.go(this.page - 1), "aria-label": "Previous page" }, h("span", { key: '8d2c3e7d96bc0761fb56318b34a70924c7250939', "aria-hidden": "true" }, "\u2039")), h("p", { key: 'c4eb6fb365ab8f06dadee383be08f0d8fe39f882', class: "pager__summary", id: this.labelId, "aria-live": "polite" }, count === 0 ? 'No results' : `${this.firstRow}–${this.lastRow} of ${this.total}`), h("button", { key: '1ee7a5084c6d937bb1d1b2260b09dd5d190aaf09', class: "pager__button", type: "button", disabled: blocked || atEnd, onClick: () => this.go(this.page + 1), "aria-label": "Next page" }, h("span", { key: '8fbf8209157fe9833a25ed22270580a980d66a1d', "aria-hidden": "true" }, "\u203A")))));
|
|
66
|
+
}
|
|
67
|
+
static get is() { return "ch-pagination"; }
|
|
68
|
+
static get encapsulation() { return "shadow"; }
|
|
69
|
+
static get originalStyleUrls() {
|
|
70
|
+
return {
|
|
71
|
+
"$": ["ch-pagination.css"]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
static get styleUrls() {
|
|
75
|
+
return {
|
|
76
|
+
"$": ["ch-pagination.css"]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
static get properties() {
|
|
80
|
+
return {
|
|
81
|
+
"page": {
|
|
82
|
+
"type": "number",
|
|
83
|
+
"mutable": false,
|
|
84
|
+
"complexType": {
|
|
85
|
+
"original": "number",
|
|
86
|
+
"resolved": "number",
|
|
87
|
+
"references": {}
|
|
88
|
+
},
|
|
89
|
+
"required": false,
|
|
90
|
+
"optional": false,
|
|
91
|
+
"docs": {
|
|
92
|
+
"tags": [],
|
|
93
|
+
"text": "The current page, 1-based. Controlled by the consumer."
|
|
94
|
+
},
|
|
95
|
+
"getter": false,
|
|
96
|
+
"setter": false,
|
|
97
|
+
"reflect": false,
|
|
98
|
+
"attribute": "page",
|
|
99
|
+
"defaultValue": "1"
|
|
100
|
+
},
|
|
101
|
+
"pageSize": {
|
|
102
|
+
"type": "number",
|
|
103
|
+
"mutable": false,
|
|
104
|
+
"complexType": {
|
|
105
|
+
"original": "number",
|
|
106
|
+
"resolved": "number",
|
|
107
|
+
"references": {}
|
|
108
|
+
},
|
|
109
|
+
"required": false,
|
|
110
|
+
"optional": false,
|
|
111
|
+
"docs": {
|
|
112
|
+
"tags": [],
|
|
113
|
+
"text": "How many rows a page holds. Controlled by the consumer."
|
|
114
|
+
},
|
|
115
|
+
"getter": false,
|
|
116
|
+
"setter": false,
|
|
117
|
+
"reflect": false,
|
|
118
|
+
"attribute": "page-size",
|
|
119
|
+
"defaultValue": "10"
|
|
120
|
+
},
|
|
121
|
+
"total": {
|
|
122
|
+
"type": "number",
|
|
123
|
+
"mutable": false,
|
|
124
|
+
"complexType": {
|
|
125
|
+
"original": "number",
|
|
126
|
+
"resolved": "number",
|
|
127
|
+
"references": {}
|
|
128
|
+
},
|
|
129
|
+
"required": false,
|
|
130
|
+
"optional": false,
|
|
131
|
+
"docs": {
|
|
132
|
+
"tags": [],
|
|
133
|
+
"text": "How many rows exist in total. Zero renders a disabled, empty pager."
|
|
134
|
+
},
|
|
135
|
+
"getter": false,
|
|
136
|
+
"setter": false,
|
|
137
|
+
"reflect": false,
|
|
138
|
+
"attribute": "total",
|
|
139
|
+
"defaultValue": "0"
|
|
140
|
+
},
|
|
141
|
+
"label": {
|
|
142
|
+
"type": "string",
|
|
143
|
+
"mutable": false,
|
|
144
|
+
"complexType": {
|
|
145
|
+
"original": "string",
|
|
146
|
+
"resolved": "string",
|
|
147
|
+
"references": {}
|
|
148
|
+
},
|
|
149
|
+
"required": false,
|
|
150
|
+
"optional": false,
|
|
151
|
+
"docs": {
|
|
152
|
+
"tags": [],
|
|
153
|
+
"text": "Accessible name for the navigation landmark."
|
|
154
|
+
},
|
|
155
|
+
"getter": false,
|
|
156
|
+
"setter": false,
|
|
157
|
+
"reflect": false,
|
|
158
|
+
"attribute": "label",
|
|
159
|
+
"defaultValue": "'Pagination'"
|
|
160
|
+
},
|
|
161
|
+
"size": {
|
|
162
|
+
"type": "string",
|
|
163
|
+
"mutable": false,
|
|
164
|
+
"complexType": {
|
|
165
|
+
"original": "ChPaginationSize",
|
|
166
|
+
"resolved": "\"md\" | \"sm\"",
|
|
167
|
+
"references": {
|
|
168
|
+
"ChPaginationSize": {
|
|
169
|
+
"location": "local",
|
|
170
|
+
"path": "/home/runner/work/chucao/chucao/src/components/ch-pagination/ch-pagination.tsx",
|
|
171
|
+
"id": "src/components/ch-pagination/ch-pagination.tsx::ChPaginationSize"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"required": false,
|
|
176
|
+
"optional": false,
|
|
177
|
+
"docs": {
|
|
178
|
+
"tags": [],
|
|
179
|
+
"text": "Size of the controls."
|
|
180
|
+
},
|
|
181
|
+
"getter": false,
|
|
182
|
+
"setter": false,
|
|
183
|
+
"reflect": false,
|
|
184
|
+
"attribute": "size",
|
|
185
|
+
"defaultValue": "'md'"
|
|
186
|
+
},
|
|
187
|
+
"disabled": {
|
|
188
|
+
"type": "boolean",
|
|
189
|
+
"mutable": false,
|
|
190
|
+
"complexType": {
|
|
191
|
+
"original": "boolean",
|
|
192
|
+
"resolved": "boolean",
|
|
193
|
+
"references": {}
|
|
194
|
+
},
|
|
195
|
+
"required": false,
|
|
196
|
+
"optional": false,
|
|
197
|
+
"docs": {
|
|
198
|
+
"tags": [],
|
|
199
|
+
"text": "Whether the whole control is disabled."
|
|
200
|
+
},
|
|
201
|
+
"getter": false,
|
|
202
|
+
"setter": false,
|
|
203
|
+
"reflect": true,
|
|
204
|
+
"attribute": "disabled",
|
|
205
|
+
"defaultValue": "false"
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
static get events() {
|
|
210
|
+
return [{
|
|
211
|
+
"method": "chPageChange",
|
|
212
|
+
"name": "chPageChange",
|
|
213
|
+
"bubbles": true,
|
|
214
|
+
"cancelable": true,
|
|
215
|
+
"composed": true,
|
|
216
|
+
"docs": {
|
|
217
|
+
"tags": [],
|
|
218
|
+
"text": "Emitted when the user asks for another page. The consumer applies it."
|
|
219
|
+
},
|
|
220
|
+
"complexType": {
|
|
221
|
+
"original": "{ page: number; pageSize: number }",
|
|
222
|
+
"resolved": "{ page: number; pageSize: number; }",
|
|
223
|
+
"references": {}
|
|
224
|
+
}
|
|
225
|
+
}];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=ch-pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ch-pagination.js","sourceRoot":"","sources":["../../../../src/components/ch-pagination/ch-pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAInF,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;GAcG;AAMH,MAAM,OAAO,YAAY;IACN,OAAO,GAAG,iBAAiB,EAAE,aAAa,EAAE,CAAC;IAE9D,6DAA6D;IACrD,IA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C,QAAQ,IAAI,IAAI,CAAC,OAAO,OAAO,IAAI,CAAC,KAAK,EAAE,CAC/E;gBACJ,+DAAQ,KAAK,EAAC,eAAe,EAAC,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,OAAO,IAAI,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,gBAAa,WAAW;oBACnI,4EAAkB,MAAM,aAAS,CAC1B,CACL,CACD,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Event, type EventEmitter, Host, Prop, h } from '@stencil/core';\n\nexport type ChPaginationSize = 'sm' | 'md';\n\nlet paginationIds = 0;\n\n/**\n * Controlled pagination for a known total.\n *\n * It holds no page state: `page` and `pageSize` come from the consumer and\n * every action emits `chPageChange` with the page it wants. That matches\n * `ch-table`, so a consumer wiring the two together has one model to reason\n * about — the table shows the rows for `page`, the pagination asks for the\n * next one, and nothing moves until the consumer's data does.\n *\n * No numbered page list. A list of numbers is wrong more often than it is\n * right (it depends on how many pages fit, which depends on the font, the\n * locale and the container), and it is the part consumers most often need to\n * replace with their own. Prev/next plus a position summary covers the\n * default case; the summary is what tells a screen-reader user where they are.\n */\n@Component({\n tag: 'ch-pagination',\n styleUrl: 'ch-pagination.css',\n shadow: true,\n})\nexport class ChPagination {\n private readonly labelId = `ch-pagination-${++paginationIds}`;\n\n /** The current page, 1-based. Controlled by the consumer. */\n @Prop() page = 1;\n\n /** How many rows a page holds. Controlled by the consumer. */\n @Prop() pageSize = 10;\n\n /** How many rows exist in total. Zero renders a disabled, empty pager. */\n @Prop() total = 0;\n\n /** Accessible name for the navigation landmark. */\n @Prop() label = 'Pagination';\n\n /** Size of the controls. */\n @Prop() size: ChPaginationSize = 'md';\n\n /** Whether the whole control is disabled. */\n @Prop({ reflect: true }) disabled = false;\n\n /** Emitted when the user asks for another page. The consumer applies it. */\n @Event() chPageChange: EventEmitter<{ page: number; pageSize: number }>;\n\n private get pageCount(): number {\n if (this.total <= 0 || this.pageSize <= 0) {\n return 0;\n }\n return Math.ceil(this.total / this.pageSize);\n }\n\n /** How many rows this page shows, which is short on the last page. */\n private get rowsOnPage(): number {\n if (this.pageCount === 0) {\n return 0;\n }\n const remaining = this.total - (this.page - 1) * this.pageSize;\n return Math.max(0, Math.min(this.pageSize, remaining));\n }\n\n private get firstRow(): number {\n return this.rowsOnPage === 0 ? 0 : (this.page - 1) * this.pageSize + 1;\n }\n\n private get lastRow(): number {\n return this.rowsOnPage === 0 ? 0 : this.firstRow + this.rowsOnPage - 1;\n }\n\n private go(next: number) {\n if (this.disabled || next < 1 || next > this.pageCount || next === this.page) {\n return;\n }\n this.chPageChange.emit({ page: next, pageSize: this.pageSize });\n }\n\n render() {\n const count = this.pageCount;\n const atStart = this.page <= 1;\n const atEnd = count === 0 || this.page >= count;\n const blocked = this.disabled || count === 0;\n\n return (\n <Host>\n <nav class={{ pager: true, [`pager--${this.size}`]: true }} aria-label={this.label}>\n <button class=\"pager__button\" type=\"button\" disabled={blocked || atStart} onClick={() => this.go(this.page - 1)} aria-label=\"Previous page\">\n <span aria-hidden=\"true\">‹</span>\n </button>\n <p class=\"pager__summary\" id={this.labelId} aria-live=\"polite\">\n {count === 0 ? 'No results' : `${this.firstRow}–${this.lastRow} of ${this.total}`}\n </p>\n <button class=\"pager__button\" type=\"button\" disabled={blocked || atEnd} onClick={() => this.go(this.page + 1)} aria-label=\"Next page\">\n <span aria-hidden=\"true\">›</span>\n </button>\n </nav>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -98,7 +98,7 @@ export class ChRadio {
|
|
|
98
98
|
}
|
|
99
99
|
render() {
|
|
100
100
|
const groupName = this.name || `${this.groupId}-group`;
|
|
101
|
-
return (h(Host, { key: '
|
|
101
|
+
return (h(Host, { key: 'bf7c403e1c7c172b5427d6e41d6740909e7f42f8' }, this.label && (h("span", { key: '4a5391dca354ab46c80238f0f5d8ac43f1024b28', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '75854ae56cf848cbfcbb6a3a36fd831975e41071', 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: '270d6cdf03427427e88d5c6445f6607779c3ee14', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '6091a667601e9ff02f4b245d5a2cebf1e63d4ce0', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
102
102
|
}
|
|
103
103
|
static get is() { return "ch-radio"; }
|
|
104
104
|
static get encapsulation() { return "shadow"; }
|
|
@@ -92,7 +92,7 @@ export class ChSegmentedControl {
|
|
|
92
92
|
}
|
|
93
93
|
render() {
|
|
94
94
|
const groupName = this.name || `${this.groupId}-group`;
|
|
95
|
-
return (h(Host, { key: '
|
|
95
|
+
return (h(Host, { key: '521878f5cc2c183a1ac2c89d2fa4d1b26e58dcce' }, this.label && (h("span", { key: 'd87b35d855bd1185ddff983b7af098dcd867ed3a', class: "group-label", id: this.labelId }, this.label)), h("div", { key: '008d37b8f9c50b007d7975b8cf0ce7ba52c283a1', class: { segmented: true, [`segmented--${this.size}`]: true }, 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", type: "radio", name: groupName, value: option.value, checked: option.value === this.value, disabled: this.disabled || this.formDisabled || option.disabled, onChange: this.handleChange }), h("span", { class: "label-text" }, option.label)))))));
|
|
96
96
|
}
|
|
97
97
|
static get is() { return "ch-segmented-control"; }
|
|
98
98
|
static get encapsulation() { return "shadow"; }
|
|
@@ -99,7 +99,7 @@ export class ChSelect {
|
|
|
99
99
|
return undefined;
|
|
100
100
|
}
|
|
101
101
|
render() {
|
|
102
|
-
return (h(Host, { key: '
|
|
102
|
+
return (h(Host, { key: '21825ec1b83a93617413179ec79ba42ef2e980fe' }, this.label && (h("label", { key: 'e41e1268d92384f93bf492f90c6a727ddd5a05e0', class: "label", htmlFor: this.selectId }, this.label)), h("select", { key: '25160df5f7628bf89d6d7bb1f2736b44d02455d9', id: this.label ? this.selectId : undefined, class: { 'select': true, 'select--invalid': this.invalid }, name: this.name, disabled: this.disabled || this.formDisabled, required: this.required, "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }, this.placeholder && (h("option", { key: '6e6977e6c5d120a2bf28b1b05892ff90ca32e1ff', value: "", disabled: true, hidden: true, selected: !this.value }, this.placeholder)), this.options.map(option => (h("option", { value: option.value, disabled: option.disabled, selected: option.value === this.value }, option.label)))), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: '92cb97df6b5ff80857fa6463d189e366697d6fd5', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '08d3f5deefd5d155c0fd54f06a0f6f5c60db8873', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
103
103
|
}
|
|
104
104
|
static get is() { return "ch-select"; }
|
|
105
105
|
static get encapsulation() { return "shadow"; }
|
|
@@ -47,7 +47,7 @@ export class ChSkeleton {
|
|
|
47
47
|
return { width: this.width, height: this.height };
|
|
48
48
|
}
|
|
49
49
|
render() {
|
|
50
|
-
return (h(Host, { key: '
|
|
50
|
+
return (h(Host, { key: '4bf9bb4d0fdfb1ecff7f0a9606da0c3eaa47aca3', "aria-hidden": "true", class: { 'skeleton': true, [`skeleton--${this.shape}`]: true, 'skeleton--animated': this.animated } }, Array.from({ length: this.items }).map((value, index) => (h("span", { class: "skeleton__item", style: this.sizeStyle, key: index, "data-index": String(value) })))));
|
|
51
51
|
}
|
|
52
52
|
static get is() { return "ch-skeleton"; }
|
|
53
53
|
static get encapsulation() { return "shadow"; }
|
|
@@ -23,7 +23,7 @@ export class ChSpinner {
|
|
|
23
23
|
label;
|
|
24
24
|
render() {
|
|
25
25
|
const labelled = Boolean(this.label);
|
|
26
|
-
return (h(Host, { key: '
|
|
26
|
+
return (h(Host, { key: 'ed67d11ad7efe04c34372852f5c4b81c71bf2327' }, h("span", { key: 'fff47dcd59f6e8881ea6295f5d062f888328a081', class: { spinner: true, [`spinner--${this.size}`]: true }, role: labelled ? 'status' : undefined, "aria-label": labelled ? this.label : undefined, "aria-hidden": labelled ? undefined : 'true' })));
|
|
27
27
|
}
|
|
28
28
|
static get is() { return "ch-spinner"; }
|
|
29
29
|
static get encapsulation() { return "shadow"; }
|
|
@@ -24,7 +24,7 @@ export class ChStack {
|
|
|
24
24
|
return GAPS.has(this.gap) ? this.gap : 'md';
|
|
25
25
|
}
|
|
26
26
|
render() {
|
|
27
|
-
return (h(Host, { key: '
|
|
27
|
+
return (h(Host, { key: '9c781e2f2c953d67442838300c7cd83fb47c19c6', class: { stack: true, [`stack--gap-${this.gapStep}`]: true, [`stack--align-${this.align}`]: true, [`stack--justify-${this.justify}`]: true } }, h("slot", { key: '3907d79b2c5f58a9dccf9b68e34d3fb0878c16a5' })));
|
|
28
28
|
}
|
|
29
29
|
static get is() { return "ch-stack"; }
|
|
30
30
|
static get encapsulation() { return "shadow"; }
|
|
@@ -43,10 +43,10 @@ export class ChStat {
|
|
|
43
43
|
}
|
|
44
44
|
render() {
|
|
45
45
|
const cue = this.toneClass === 'positive' ? '+' : this.toneClass === 'negative' ? '−' : null;
|
|
46
|
-
return (h(Host, { key: '
|
|
46
|
+
return (h(Host, { key: '79553724e7efce617f793913fc4b65301d8e4214', class: "stat" }, h("div", { key: '1d24c5b7fce578242c2464914beddd7c0bc0ac1b', class: "stat__inner" }, h("span", { key: '37bbb5ebf996a2f460d817ffc546bf37100a4c7f', class: "stat__label" }, this.label), h("span", { key: 'a1e5ff57b56f04fcc31b31d04ad6e8fae4ab75e3', class: {
|
|
47
47
|
stat__value: true,
|
|
48
48
|
[`stat__value--${this.toneClass}`]: this.toneClass !== 'default',
|
|
49
|
-
} }, cue && (h("span", { key: '
|
|
49
|
+
} }, cue && (h("span", { key: '9a35c34c366d66f3712f9c22cacefe48e550a08f', class: "stat__cue", "aria-hidden": "true" }, cue)), h("slot", { key: 'cbf547c8ec13a675cd694e39016b7a702fac41a5', name: "value" }, this.value)), this.hint && h("span", { key: 'ceaa61ab32fd4b607fe40f96a4ded7588098c98b', class: "stat__hint" }, this.hint), h("div", { key: '67352638ded6243693a9698105b9d330466ccc3b', class: "stat__footer" }, h("slot", { key: '8d8e59eae68d8d7153a57ec33a8185483e79b8f3', name: "footer" })))));
|
|
50
50
|
}
|
|
51
51
|
static get is() { return "ch-stat"; }
|
|
52
52
|
static get encapsulation() { return "shadow"; }
|
|
@@ -95,7 +95,7 @@ export class ChSwitch {
|
|
|
95
95
|
return undefined;
|
|
96
96
|
}
|
|
97
97
|
render() {
|
|
98
|
-
return (h(Host, { key: '
|
|
98
|
+
return (h(Host, { key: 'f0ad3dab1049febb1e4506c538a938eec237b6ee' }, h("label", { key: '0ec252ff6c58a79c3d1054312f6f92dd03352f69', class: { 'control': true, 'control--disabled': this.disabled || this.formDisabled }, htmlFor: this.switchId }, h("input", { key: 'a2471b09c6e1a026ec6189b3b542edc7147b8759', id: this.switchId, class: { 'input': true, 'input--invalid': this.invalid }, type: "checkbox", role: "switch", name: this.name, value: this.value, checked: this.checked, disabled: this.disabled || this.formDisabled, required: this.required, "aria-checked": this.checked ? 'true' : 'false', "aria-invalid": this.invalid ? 'true' : undefined, "aria-describedby": this.describedBy, onChange: this.handleChange }), h("span", { key: 'dbcf0512d51e71c0072e4d159e23d822a7676da2', class: "track" }, h("span", { key: 'e7ef5934e2c03ba12e320fe963b4904237bf05d5', class: "thumb" })), this.label && h("span", { key: '90e1fc7560f839ec50014648235cc753c955b82a', class: "label-text" }, this.label)), this.hint && !(this.invalid && this.errorMessage) && (h("p", { key: 'c5150070147fcf40364925a5c164ec80d511b411', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: 'c9cc633cd70f53aa62425faf92e760cf8cb816fd', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
99
99
|
}
|
|
100
100
|
static get is() { return "ch-switch"; }
|
|
101
101
|
static get encapsulation() { return "shadow"; }
|
|
@@ -151,7 +151,7 @@ export class ChTable {
|
|
|
151
151
|
const empty = this.emptyState;
|
|
152
152
|
// Before the first measurement the table is rendered as non-empty, so a
|
|
153
153
|
// consumer never sees the empty message flash over real rows.
|
|
154
|
-
return (h(Host, { key: '
|
|
154
|
+
return (h(Host, { key: 'e7957ed09b624ec1fdc599f300d7b1a49668ec41', class: { 'table': true, 'table--empty': empty === 'true' || empty === 'filtered' } }, h("div", { key: 'c2fe932de59ee1c557c7a10bdd5f8704b5ee1dd2', class: "table__scroll", tabIndex: 0, role: "group", "aria-labelledby": this.captionId }, h("table", { key: '9e76c06676ef07c3c7fc46e80e78a7baba6f0c33' }, h("caption", { key: '3842f79c25b143fdb6d410d985e1d456cbdde190', id: this.captionId, class: "caption" }, this.label), h("thead", { key: '1116cf7fed60c9757fac4097332aa2308609cb6b' }, h("tr", { key: 'f8ea8e04ca4bd02a63768c93c6ce1c5b4e307792' }, this.columns.map(column => this.renderHeaderCell(column)))), h("tbody", { key: '2a2c7b18fad74c854cad9164978753ffe168219f' }, h("slot", { key: '514e8c0b56e8beb8c0503723823ce8be7a588af6' })))), (empty === 'true' || empty === 'filtered') && (h("div", { key: 'a64841b511490e24462b89b8007f79c662de6120', class: "table__empty", id: this.emptyId }, h("slot", { key: '32bcbe36421d083883223dadaec7dbd194deab8c', name: "empty" }, h("p", { key: '36a9af8b0e9cbb0dfb96d52d057c910a92fe918e', class: "table__empty-message" }, this.emptyMessage(empty)))))));
|
|
155
155
|
}
|
|
156
156
|
static get is() { return "ch-table"; }
|
|
157
157
|
static get encapsulation() { return "shadow"; }
|
|
@@ -77,7 +77,7 @@ export class ChTabs {
|
|
|
77
77
|
}
|
|
78
78
|
render() {
|
|
79
79
|
const active = this.activeValue;
|
|
80
|
-
return (h(Host, { key: '
|
|
80
|
+
return (h(Host, { key: '596a51404c0d7d87f9988534f65e98135ecfcb75' }, h("div", { key: '6eb8cf1c1a986ce1ebd211806d130c0156bad2f1', class: "tablist", role: "tablist", "aria-label": this.label, onKeyDown: this.handleKeyDown, ref: el => (this.tablistEl = el) }, this.tabs.map(tab => {
|
|
81
81
|
const selected = tab.value === active;
|
|
82
82
|
return (h("button", { key: tab.value, type: "button", class: { 'tab': true, 'tab--active': selected, 'tab--disabled': Boolean(tab.disabled) }, role: "tab", id: this.tabId(tab.value), "data-value": tab.value, "aria-selected": selected ? 'true' : 'false', "aria-controls": this.panelId(tab.value), tabIndex: selected ? FIRST_TAB_INDEX : LAST_TAB_INDEX, disabled: tab.disabled, onClick: () => this.select(tab.value) }, tab.label));
|
|
83
83
|
})), this.tabs.map(tab => (h("div", { key: `${tab.value}-panel`, class: "tabpanel", id: this.panelId(tab.value), role: "tabpanel", "aria-labelledby": this.tabId(tab.value), tabIndex: FIRST_TAB_INDEX, hidden: tab.value !== active }, h("slot", { name: `panel-${tab.value}` }))))));
|
|
@@ -108,7 +108,7 @@ export class ChTextarea {
|
|
|
108
108
|
return undefined;
|
|
109
109
|
}
|
|
110
110
|
render() {
|
|
111
|
-
return (h(Host, { key: '
|
|
111
|
+
return (h(Host, { key: 'd416e809a6e1e3efe416add0008da16a690a611f' }, this.label && (h("label", { key: '777fd65954d8b346dd58ff06fa482e63ebcc3469', class: "label", htmlFor: this.textareaId }, this.label)), h("textarea", { key: '5ec5f626a54f7b94be8064e759553f7324499485', id: this.label ? this.textareaId : undefined, class: { 'textarea': true, 'textarea--invalid': this.invalid }, rows: this.rows, 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: 'dee1dba3eda31566326284fccbdc0f352b14fe8f', class: "hint", id: this.hintId }, this.hint)), this.invalid && this.errorMessage && (h("p", { key: '5e1d47eb86b8ddd5284c3bad620bab11e340034c', class: "error", id: this.errorId, role: "alert" }, this.errorMessage))));
|
|
112
112
|
}
|
|
113
113
|
static get is() { return "ch-textarea"; }
|
|
114
114
|
static get encapsulation() { return "shadow"; }
|
|
@@ -25,7 +25,7 @@ import { Host, h } from "@stencil/core";
|
|
|
25
25
|
*/
|
|
26
26
|
export class ChTimeline {
|
|
27
27
|
render() {
|
|
28
|
-
return (h(Host, { key: '
|
|
28
|
+
return (h(Host, { key: 'f8e1398cd3993e0b4fdfa039f2e09d99321745e0', class: "timeline" }, h("ol", { key: '0341a6f18ed91895bc18b01b4a2d327eed48befc', class: "list" }, h("slot", { key: '90c240cb80a37e844f840d062b7b7e5b97a97c1a' }))));
|
|
29
29
|
}
|
|
30
30
|
static get is() { return "ch-timeline"; }
|
|
31
31
|
static get encapsulation() { return "shadow"; }
|
|
@@ -7,6 +7,17 @@
|
|
|
7
7
|
display: inline-flex;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/* Fixed at the origin of the same containing block the bubble uses. */
|
|
11
|
+
.probe {
|
|
12
|
+
position: fixed;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
width: 1px;
|
|
16
|
+
height: 1px;
|
|
17
|
+
visibility: hidden;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
.bubble {
|
|
11
22
|
position: absolute;
|
|
12
23
|
z-index: var(--z-index-dropdown);
|
|
@@ -30,6 +30,7 @@ export class ChTooltip {
|
|
|
30
30
|
el;
|
|
31
31
|
fallbackId = `ch-tooltip-${++tooltipIds}`;
|
|
32
32
|
bubbleEl;
|
|
33
|
+
probeEl;
|
|
33
34
|
cleanup;
|
|
34
35
|
/**
|
|
35
36
|
* The side the bubble is placed on. It is a preference: when that side has no
|
|
@@ -121,30 +122,46 @@ export class ChTooltip {
|
|
|
121
122
|
* Measures the anchor and the bubble and stores the offset that keeps the
|
|
122
123
|
* bubble inside the viewport. Nothing is measured before the bubble has a
|
|
123
124
|
* box to measure, so the pre-paint render uses plain CSS.
|
|
125
|
+
*
|
|
126
|
+
* A fixed bubble is positioned against the nearest ancestor that establishes
|
|
127
|
+
* a containing block (a `transform`, `filter`, `backdrop-filter`, `contain`
|
|
128
|
+
* or `will-change`), not necessarily the viewport. The probe is fixed at the
|
|
129
|
+
* containing block's origin, so both the anchor and the viewport are
|
|
130
|
+
* converted into that same space before `placeOverlay` does its maths.
|
|
124
131
|
*/
|
|
125
132
|
position() {
|
|
126
133
|
if (typeof window === 'undefined') {
|
|
127
134
|
return;
|
|
128
135
|
}
|
|
129
136
|
const bubble = this.bubbleEl ?? (this.bubbleEl = this.el.shadowRoot?.querySelector('.bubble') ?? undefined);
|
|
130
|
-
|
|
137
|
+
const probe = this.probeEl ?? (this.probeEl = this.el.shadowRoot?.querySelector('.probe') ?? undefined);
|
|
138
|
+
if (!bubble || !probe || bubble.offsetWidth === 0) {
|
|
131
139
|
return;
|
|
132
140
|
}
|
|
133
141
|
const anchorRect = this.slotted('trigger')?.getBoundingClientRect?.();
|
|
134
142
|
if (!anchorRect) {
|
|
135
143
|
return;
|
|
136
144
|
}
|
|
145
|
+
const probeRect = probe.getBoundingClientRect();
|
|
146
|
+
const scaleX = probeRect.width || 1;
|
|
147
|
+
const scaleY = probeRect.height || 1;
|
|
148
|
+
const inContainingBlock = (rect) => ({
|
|
149
|
+
top: (rect.top - probeRect.top) / scaleY,
|
|
150
|
+
left: (rect.left - probeRect.left) / scaleX,
|
|
151
|
+
width: rect.width / scaleX,
|
|
152
|
+
height: rect.height / scaleY,
|
|
153
|
+
});
|
|
137
154
|
const surface = {
|
|
138
155
|
width: bubble.offsetWidth + horizontalMargin(bubble),
|
|
139
156
|
height: bubble.offsetHeight,
|
|
140
157
|
};
|
|
141
158
|
const viewport = window.visualViewport;
|
|
142
159
|
const { placement, top, left } = placeOverlay({
|
|
143
|
-
anchor:
|
|
160
|
+
anchor: inContainingBlock(anchorRect),
|
|
144
161
|
surface,
|
|
145
|
-
viewport: viewport
|
|
162
|
+
viewport: inContainingBlock(viewport
|
|
146
163
|
? { top: viewport.offsetTop, left: viewport.offsetLeft, width: viewport.width, height: viewport.height }
|
|
147
|
-
: { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight },
|
|
164
|
+
: { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight }),
|
|
148
165
|
preferred: this.placement,
|
|
149
166
|
gap: GAP,
|
|
150
167
|
});
|
|
@@ -175,7 +192,7 @@ export class ChTooltip {
|
|
|
175
192
|
};
|
|
176
193
|
render() {
|
|
177
194
|
const { offset } = this;
|
|
178
|
-
return (h(Host, { key: '
|
|
195
|
+
return (h(Host, { key: 'ccc4855053e0c1661f37ef6d40dffc4d0ff8fef3' }, h("span", { key: 'c71b50bd48142031f60017a01e9abbeaad755f83', class: "anchor" }, h("span", { key: 'aa337facc4dd983a5c2b2cf68ef1b3079e911f0b', class: "probe", "aria-hidden": "true", ref: el => (this.probeEl = el) }), h("slot", { key: 'd4c7db781d9cad1b61d0b17071e41ee9619e5129', name: "trigger", onSlotchange: this.associate }), h("span", { key: '8eda03e816c13ba58721a3f2c058d1e812c5630e', ref: el => (this.bubbleEl = el), style: {
|
|
179
196
|
'--ch-tooltip-offset-top': offset ? `${offset.top}px` : null,
|
|
180
197
|
'--ch-tooltip-offset-left': offset ? `${offset.left}px` : null,
|
|
181
198
|
}, class: {
|
|
@@ -183,7 +200,7 @@ export class ChTooltip {
|
|
|
183
200
|
'bubble--positioned': Boolean(this.offset),
|
|
184
201
|
[`bubble--${this.resolvedPlacement ?? this.placement}`]: true,
|
|
185
202
|
'bubble--visible': this.visible,
|
|
186
|
-
} }, h("slot", { key: '
|
|
203
|
+
} }, h("slot", { key: '402e2c295e88586d78974a2169a75afda1380c96', name: "content", onSlotchange: this.associate })))));
|
|
187
204
|
}
|
|
188
205
|
static get is() { return "ch-tooltip"; }
|
|
189
206
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ch-tooltip.js","sourceRoot":"","sources":["../../../../src/components/ch-tooltip/ch-tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE9F,OAAO,EAAE,YAAY,EAA2B,MAAM,qBAAqB,CAAC;AAI5E,IAAI,UAAU,GAAG,CAAC,CAAC;AAEnB,yEAAyE;AACzE,MAAM,GAAG,GAAG,CAAC,CAAC;AAEd;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,MAAM,OAAO,SAAS;IACD,EAAE,CAAc;IAElB,UAAU,GAAG,cAAc,EAAE,UAAU,EAAE,CAAC;IAEnD,QAAQ,CAAe;IAEvB,OAAO,CAAc;IAE7B;;;OAGG;IACK,SAAS,GAAuB,KAAK,CAAC;IAE9C,yEAAyE;IACzE,4EAA4E;IAC5E,wBAAwB;IACf,OAAO,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,SAAS,GAAG,KAAK,CAAC;IAE3B,gFAAgF;IACvE,iBAAiB,CAAsB;IAEhD,8DAA8D;IACtD,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,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;wBAC1C,CAAC,WAAW,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI;wBAC7D,iBAAiB,EAAE,IAAI,CAAC,OAAO;qBAChC;oBAED,6DAAM,IAAI,EAAC,SAAS,EAAC,YAAY,EAAE,IAAI,CAAC,SAAS,GAAS,CACrD,CACF,CACF,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF;AAED,SAAS,gBAAgB,CAAC,EAAe;IACvC,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACpF,CAAC","sourcesContent":["import { Component, Element, forceUpdate, Host, Listen, Prop, State, h } from '@stencil/core';\n\nimport { placeOverlay, type ChOverlayPlacement } from '../../utils/overlay';\n\nexport type ChTooltipPlacement = ChOverlayPlacement;\n\nlet tooltipIds = 0;\n\n/** Space between the trigger and the bubble, matching `--spacing-md`. */\nconst GAP = 8;\n\n/**\n * Short help text shown on hover and on focus.\n *\n * Both the trigger and the text come from the consumer's light DOM through\n * named slots. That is what makes the accessible association work: an\n * `aria-describedby` IDREF only resolves within a single tree, and slotted\n * nodes stay in the document tree even though they render inside the shadow\n * root. Keeping the text in the shadow root instead would need a reference\n * pointing into a shadow tree, which the platform does not allow — element\n * reflection only points outwards, and `referenceTarget` is not available yet.\n *\n * The trigger has to be a natively focusable element (`<button>`, `<a>`,\n * `<input>`). A chucao component such as `ch-button` will not be described,\n * because `aria-*` set on a custom element host does not reach the native\n * element inside it — see the discussion in issue #47.\n *\n * Positioning is measured, not purely CSS: `placement` is the preferred side,\n * and the bubble flips to the opposite side when the preferred one does not\n * fit, then shifts along the other axis to stay inside the viewport. It\n * re-measures on scroll, resize and visual-viewport changes, which is what\n * keeps it correct inside a scrolling modal or drawer and when a mobile\n * keyboard shrinks the visible area.\n */\n@Component({\n tag: 'ch-tooltip',\n styleUrl: 'ch-tooltip.css',\n shadow: true,\n})\nexport class ChTooltip {\n @Element() private el: HTMLElement;\n\n private readonly fallbackId = `ch-tooltip-${++tooltipIds}`;\n\n private bubbleEl?: HTMLElement;\n\n private cleanup?: () => void;\n\n /**\n * The side the bubble is placed on. It is a preference: when that side has no\n * room the bubble flips to the opposite one.\n */\n @Prop() placement: ChTooltipPlacement = 'top';\n\n // Hover and focus are tracked apart so that neither cancels the other: a\n // pointer passing over and away must not hide a tooltip whose trigger still\n // holds keyboard focus.\n @State() hovered = false;\n @State() focused = false;\n @State() dismissed = false;\n\n /** The placement actually used, which may differ from the prop after a flip. */\n @State() resolvedPlacement?: ChTooltipPlacement;\n\n /** Offset applied to the bubble once it has been measured. */\n private offset?: { top: number; left: number };\n\n private get visible() {\n return (this.hovered || this.focused) && !this.dismissed;\n }\n\n componentDidLoad() {\n this.associate();\n }\n\n connectedCallback() {\n this.watchViewport();\n }\n\n disconnectedCallback() {\n this.cleanup?.();\n }\n\n @Listen('mouseenter')\n handleMouseEnter() {\n this.hovered = true;\n this.dismissed = false;\n this.position();\n }\n\n @Listen('mouseleave')\n handleMouseLeave() {\n this.hovered = false;\n }\n\n @Listen('focusin')\n handleFocusIn() {\n this.focused = true;\n this.dismissed = false;\n this.position();\n }\n\n @Listen('focusout')\n handleFocusOut() {\n this.focused = false;\n }\n\n /**\n * Listens on the document because a tooltip opened by hovering leaves focus\n * wherever it was, so a host-scoped handler would never see the key.\n *\n * `preventDefault()` dismisses only the innermost surface: the platform's\n * close request for an open native `<dialog>` is the default action of this\n * same keydown, so cancelling it keeps an enclosing `ch-modal` open. Proven\n * against a real `ch-modal` in `tests/browser/ch-tooltip.browser.spec.ts`.\n */\n @Listen('keydown', { target: 'document' })\n handleKeyDown(event: KeyboardEvent) {\n if (event.key === 'Escape' && this.visible && !event.defaultPrevented) {\n event.preventDefault();\n this.dismissed = true;\n }\n }\n\n /** Cheap guard so scroll frames do not measure while nothing is shown. */\n @Listen('scroll', { target: 'window', capture: true, passive: true })\n handleScroll() {\n if (this.visible && this.offset) {\n this.position();\n }\n }\n\n @Listen('resize', { target: 'window', passive: true })\n handleResize() {\n this.position();\n }\n\n private watchViewport() {\n if (typeof window === 'undefined') {\n return;\n }\n const viewport = window.visualViewport;\n if (!viewport || this.cleanup) {\n return;\n }\n const update = () => this.position();\n viewport.addEventListener('resize', update);\n viewport.addEventListener('scroll', update);\n this.cleanup = () => {\n viewport.removeEventListener('resize', update);\n viewport.removeEventListener('scroll', update);\n };\n }\n\n private slotted(name: string) {\n return Array.from(this.el.children).find(child => child.getAttribute('slot') === name);\n }\n\n /**\n * Measures the anchor and the bubble and stores the offset that keeps the\n * bubble inside the viewport. Nothing is measured before the bubble has a\n * box to measure, so the pre-paint render uses plain CSS.\n */\n private position() {\n if (typeof window === 'undefined') {\n return;\n }\n const bubble = this.bubbleEl ?? (this.bubbleEl = this.el.shadowRoot?.querySelector<HTMLElement>('.bubble') ?? undefined);\n if (!bubble || bubble.offsetWidth === 0) {\n return;\n }\n\n const anchorRect = (this.slotted('trigger') as HTMLElement | undefined)?.getBoundingClientRect?.();\n if (!anchorRect) {\n return;\n }\n\n const surface = {\n width: bubble.offsetWidth + horizontalMargin(bubble),\n height: bubble.offsetHeight,\n };\n const viewport = window.visualViewport;\n\n const { placement, top, left } = placeOverlay({\n anchor: { top: anchorRect.top, left: anchorRect.left, width: anchorRect.width, height: anchorRect.height },\n surface,\n viewport: viewport\n ? { top: viewport.offsetTop, left: viewport.offsetLeft, width: viewport.width, height: viewport.height }\n : { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight },\n preferred: this.placement,\n gap: GAP,\n });\n\n const current = this.offset;\n const unchanged = current?.top === top && current?.left === left && this.resolvedPlacement === placement;\n this.resolvedPlacement = placement;\n this.offset = { top, left };\n if (!unchanged) {\n forceUpdate(this);\n }\n }\n\n /**\n * Points the trigger at the text with `aria-describedby`. Re-run on\n * `slotchange` because a framework re-render can replace the slotted nodes\n * and take the attributes with them.\n */\n private associate = () => {\n const trigger = this.slotted('trigger');\n const content = this.slotted('content');\n if (!trigger || !content) {\n return;\n }\n if (!content.id) {\n content.id = this.fallbackId;\n }\n content.setAttribute('role', 'tooltip');\n trigger.setAttribute('aria-describedby', content.id);\n };\n\n render() {\n const { offset } = this;\n\n return (\n <Host>\n <span class=\"anchor\">\n {/* Pre-measure render uses the preferred side so the bubble never\n jumps from the wrong edge on its first frame. */}\n <slot name=\"trigger\" onSlotchange={this.associate}></slot>\n <span\n ref={el => (this.bubbleEl = el)}\n style={{\n '--ch-tooltip-offset-top': offset ? `${offset.top}px` : null,\n '--ch-tooltip-offset-left': offset ? `${offset.left}px` : null,\n }}\n class={{\n 'bubble': true,\n 'bubble--positioned': Boolean(this.offset),\n [`bubble--${this.resolvedPlacement ?? this.placement}`]: true,\n 'bubble--visible': this.visible,\n }}\n >\n <slot name=\"content\" onSlotchange={this.associate}></slot>\n </span>\n </span>\n </Host>\n );\n }\n}\n\nfunction horizontalMargin(el: HTMLElement) {\n const style = getComputedStyle(el);\n return (parseFloat(style.marginLeft) || 0) + (parseFloat(style.marginRight) || 0);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ch-tooltip.js","sourceRoot":"","sources":["../../../../src/components/ch-tooltip/ch-tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE9F,OAAO,EAAE,YAAY,EAA2B,MAAM,qBAAqB,CAAC;AAI5E,IAAI,UAAU,GAAG,CAAC,CAAC;AAEnB,yEAAyE;AACzE,M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AAC;wBAC1C,CAAC,WAAW,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI;wBAC7D,iBAAiB,EAAE,IAAI,CAAC,OAAO;qBAChC;oBAED,6DAAM,IAAI,EAAC,SAAS,EAAC,YAAY,EAAE,IAAI,CAAC,SAAS,GAAS,CACrD,CACF,CACF,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF;AAED,SAAS,gBAAgB,CAAC,EAAe;IACvC,MAAM,KAAK,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACpF,CAAC","sourcesContent":["import { Component, Element, forceUpdate, Host, Listen, Prop, State, h } from '@stencil/core';\n\nimport { placeOverlay, type ChOverlayPlacement } from '../../utils/overlay';\n\nexport type ChTooltipPlacement = ChOverlayPlacement;\n\nlet tooltipIds = 0;\n\n/** Space between the trigger and the bubble, matching `--spacing-md`. */\nconst GAP = 8;\n\n/**\n * Short help text shown on hover and on focus.\n *\n * Both the trigger and the text come from the consumer's light DOM through\n * named slots. That is what makes the accessible association work: an\n * `aria-describedby` IDREF only resolves within a single tree, and slotted\n * nodes stay in the document tree even though they render inside the shadow\n * root. Keeping the text in the shadow root instead would need a reference\n * pointing into a shadow tree, which the platform does not allow — element\n * reflection only points outwards, and `referenceTarget` is not available yet.\n *\n * The trigger has to be a natively focusable element (`<button>`, `<a>`,\n * `<input>`). A chucao component such as `ch-button` will not be described,\n * because `aria-*` set on a custom element host does not reach the native\n * element inside it — see the discussion in issue #47.\n *\n * Positioning is measured, not purely CSS: `placement` is the preferred side,\n * and the bubble flips to the opposite side when the preferred one does not\n * fit, then shifts along the other axis to stay inside the viewport. It\n * re-measures on scroll, resize and visual-viewport changes, which is what\n * keeps it correct inside a scrolling modal or drawer and when a mobile\n * keyboard shrinks the visible area.\n */\n@Component({\n tag: 'ch-tooltip',\n styleUrl: 'ch-tooltip.css',\n shadow: true,\n})\nexport class ChTooltip {\n @Element() private el: HTMLElement;\n\n private readonly fallbackId = `ch-tooltip-${++tooltipIds}`;\n\n private bubbleEl?: HTMLElement;\n\n private probeEl?: HTMLElement;\n\n private cleanup?: () => void;\n\n /**\n * The side the bubble is placed on. It is a preference: when that side has no\n * room the bubble flips to the opposite one.\n */\n @Prop() placement: ChTooltipPlacement = 'top';\n\n // Hover and focus are tracked apart so that neither cancels the other: a\n // pointer passing over and away must not hide a tooltip whose trigger still\n // holds keyboard focus.\n @State() hovered = false;\n @State() focused = false;\n @State() dismissed = false;\n\n /** The placement actually used, which may differ from the prop after a flip. */\n @State() resolvedPlacement?: ChTooltipPlacement;\n\n /** Offset applied to the bubble once it has been measured. */\n private offset?: { top: number; left: number };\n\n private get visible() {\n return (this.hovered || this.focused) && !this.dismissed;\n }\n\n componentDidLoad() {\n this.associate();\n }\n\n connectedCallback() {\n this.watchViewport();\n }\n\n disconnectedCallback() {\n this.cleanup?.();\n }\n\n @Listen('mouseenter')\n handleMouseEnter() {\n this.hovered = true;\n this.dismissed = false;\n this.position();\n }\n\n @Listen('mouseleave')\n handleMouseLeave() {\n this.hovered = false;\n }\n\n @Listen('focusin')\n handleFocusIn() {\n this.focused = true;\n this.dismissed = false;\n this.position();\n }\n\n @Listen('focusout')\n handleFocusOut() {\n this.focused = false;\n }\n\n /**\n * Listens on the document because a tooltip opened by hovering leaves focus\n * wherever it was, so a host-scoped handler would never see the key.\n *\n * `preventDefault()` dismisses only the innermost surface: the platform's\n * close request for an open native `<dialog>` is the default action of this\n * same keydown, so cancelling it keeps an enclosing `ch-modal` open. Proven\n * against a real `ch-modal` in `tests/browser/ch-tooltip.browser.spec.ts`.\n */\n @Listen('keydown', { target: 'document' })\n handleKeyDown(event: KeyboardEvent) {\n if (event.key === 'Escape' && this.visible && !event.defaultPrevented) {\n event.preventDefault();\n this.dismissed = true;\n }\n }\n\n /** Cheap guard so scroll frames do not measure while nothing is shown. */\n @Listen('scroll', { target: 'window', capture: true, passive: true })\n handleScroll() {\n if (this.visible && this.offset) {\n this.position();\n }\n }\n\n @Listen('resize', { target: 'window', passive: true })\n handleResize() {\n this.position();\n }\n\n private watchViewport() {\n if (typeof window === 'undefined') {\n return;\n }\n const viewport = window.visualViewport;\n if (!viewport || this.cleanup) {\n return;\n }\n const update = () => this.position();\n viewport.addEventListener('resize', update);\n viewport.addEventListener('scroll', update);\n this.cleanup = () => {\n viewport.removeEventListener('resize', update);\n viewport.removeEventListener('scroll', update);\n };\n }\n\n private slotted(name: string) {\n return Array.from(this.el.children).find(child => child.getAttribute('slot') === name);\n }\n\n /**\n * Measures the anchor and the bubble and stores the offset that keeps the\n * bubble inside the viewport. Nothing is measured before the bubble has a\n * box to measure, so the pre-paint render uses plain CSS.\n *\n * A fixed bubble is positioned against the nearest ancestor that establishes\n * a containing block (a `transform`, `filter`, `backdrop-filter`, `contain`\n * or `will-change`), not necessarily the viewport. The probe is fixed at the\n * containing block's origin, so both the anchor and the viewport are\n * converted into that same space before `placeOverlay` does its maths.\n */\n private position() {\n if (typeof window === 'undefined') {\n return;\n }\n const bubble = this.bubbleEl ?? (this.bubbleEl = this.el.shadowRoot?.querySelector<HTMLElement>('.bubble') ?? undefined);\n const probe = this.probeEl ?? (this.probeEl = this.el.shadowRoot?.querySelector<HTMLElement>('.probe') ?? undefined);\n if (!bubble || !probe || bubble.offsetWidth === 0) {\n return;\n }\n\n const anchorRect = (this.slotted('trigger') as HTMLElement | undefined)?.getBoundingClientRect?.();\n if (!anchorRect) {\n return;\n }\n\n const probeRect = probe.getBoundingClientRect();\n const scaleX = probeRect.width || 1;\n const scaleY = probeRect.height || 1;\n const inContainingBlock = (rect: { top: number; left: number; width: number; height: number }) => ({\n top: (rect.top - probeRect.top) / scaleY,\n left: (rect.left - probeRect.left) / scaleX,\n width: rect.width / scaleX,\n height: rect.height / scaleY,\n });\n\n const surface = {\n width: bubble.offsetWidth + horizontalMargin(bubble),\n height: bubble.offsetHeight,\n };\n const viewport = window.visualViewport;\n\n const { placement, top, left } = placeOverlay({\n anchor: inContainingBlock(anchorRect),\n surface,\n viewport: inContainingBlock(\n viewport\n ? { top: viewport.offsetTop, left: viewport.offsetLeft, width: viewport.width, height: viewport.height }\n : { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight },\n ),\n preferred: this.placement,\n gap: GAP,\n });\n\n const current = this.offset;\n const unchanged = current?.top === top && current?.left === left && this.resolvedPlacement === placement;\n this.resolvedPlacement = placement;\n this.offset = { top, left };\n if (!unchanged) {\n forceUpdate(this);\n }\n }\n\n /**\n * Points the trigger at the text with `aria-describedby`. Re-run on\n * `slotchange` because a framework re-render can replace the slotted nodes\n * and take the attributes with them.\n */\n private associate = () => {\n const trigger = this.slotted('trigger');\n const content = this.slotted('content');\n if (!trigger || !content) {\n return;\n }\n if (!content.id) {\n content.id = this.fallbackId;\n }\n content.setAttribute('role', 'tooltip');\n trigger.setAttribute('aria-describedby', content.id);\n };\n\n render() {\n const { offset } = this;\n\n return (\n <Host>\n <span class=\"anchor\">\n <span class=\"probe\" aria-hidden=\"true\" ref={el => (this.probeEl = el)}></span>\n {/* Pre-measure render uses the preferred side so the bubble never\n jumps from the wrong edge on its first frame. */}\n <slot name=\"trigger\" onSlotchange={this.associate}></slot>\n <span\n ref={el => (this.bubbleEl = el)}\n style={{\n '--ch-tooltip-offset-top': offset ? `${offset.top}px` : null,\n '--ch-tooltip-offset-left': offset ? `${offset.left}px` : null,\n }}\n class={{\n 'bubble': true,\n 'bubble--positioned': Boolean(this.offset),\n [`bubble--${this.resolvedPlacement ?? this.placement}`]: true,\n 'bubble--visible': this.visible,\n }}\n >\n <slot name=\"content\" onSlotchange={this.associate}></slot>\n </span>\n </span>\n </Host>\n );\n }\n}\n\nfunction horizontalMargin(el: HTMLElement) {\n const style = getComputedStyle(el);\n return (parseFloat(style.marginLeft) || 0) + (parseFloat(style.marginRight) || 0);\n}\n"]}
|