@webtides/element-library 0.2.0 → 0.3.1
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/CHANGELOG.md +399 -3
- package/README.md +61 -41
- package/all.js +28 -0
- package/catalog.d.ts +14 -0
- package/catalog.js +55 -27
- package/custom-elements.json +16676 -3457
- package/package.json +35 -28
- package/src/components/accordion/accordion.changelog.md +10 -0
- package/src/components/accordion/accordion.js +10 -7
- package/src/components/accordion/accordion.readme.md +2 -0
- package/src/components/accordion/accordion.style.js +8 -0
- package/src/components/amount-field/amount-field.changelog.md +23 -3
- package/src/components/amount-field/amount-field.js +53 -26
- package/src/components/amount-field/amount-field.readme.md +82 -20
- package/src/components/amount-field/amount-field.style.js +111 -47
- package/src/components/avatar/avatar.changelog.md +23 -0
- package/src/components/avatar/avatar.define.js +3 -0
- package/src/components/avatar/avatar.js +115 -0
- package/src/components/avatar/avatar.readme.md +132 -0
- package/src/components/avatar/avatar.style.js +67 -0
- package/src/components/badge/badge.changelog.md +23 -0
- package/src/components/badge/badge.define.js +3 -0
- package/src/components/badge/badge.js +59 -0
- package/src/components/badge/badge.readme.md +109 -0
- package/src/components/badge/badge.style.js +63 -0
- package/src/components/breadcrumb/breadcrumb.changelog.md +22 -0
- package/src/components/breadcrumb/breadcrumb.define.js +3 -0
- package/src/components/breadcrumb/breadcrumb.js +47 -0
- package/src/components/breadcrumb/breadcrumb.readme.md +108 -0
- package/src/components/breadcrumb/breadcrumb.style.js +20 -0
- package/src/components/breadcrumb-item/breadcrumb-item.changelog.md +23 -0
- package/src/components/breadcrumb-item/breadcrumb-item.define.js +3 -0
- package/src/components/breadcrumb-item/breadcrumb-item.js +82 -0
- package/src/components/breadcrumb-item/breadcrumb-item.readme.md +106 -0
- package/src/components/breadcrumb-item/breadcrumb-item.style.js +92 -0
- package/src/components/button/button.changelog.md +44 -1
- package/src/components/button/button.js +338 -29
- package/src/components/button/button.readme.md +138 -10
- package/src/components/button/button.style.js +99 -120
- package/src/components/button-group/button-group.changelog.md +24 -0
- package/src/components/button-group/button-group.define.js +3 -0
- package/src/components/button-group/button-group.js +53 -0
- package/src/components/button-group/button-group.readme.md +114 -0
- package/src/components/button-group/button-group.style.js +41 -0
- package/src/components/card/card.changelog.md +23 -0
- package/src/components/card/card.define.js +3 -0
- package/src/components/card/card.js +73 -0
- package/src/components/card/card.readme.md +136 -0
- package/src/components/card/card.style.js +99 -0
- package/src/components/carousel/carousel.changelog.md +20 -0
- package/src/components/carousel/carousel.js +89 -40
- package/src/components/carousel/carousel.readme.md +39 -6
- package/src/components/carousel/carousel.style.js +21 -77
- package/src/components/carousel/glide/components/ShadowAnchors.js +3 -1
- package/src/components/carousel/glide/components/ShadowClones.js +21 -24
- package/src/components/carousel/glide/components/ShadowGaps.js +2 -2
- package/src/components/carousel/glide/components/ShadowHtml.js +22 -3
- package/src/components/checkbox-field/checkbox-field.changelog.md +25 -0
- package/src/components/checkbox-field/checkbox-field.js +32 -11
- package/src/components/checkbox-field/checkbox-field.readme.md +17 -4
- package/src/components/checkbox-field/checkbox-field.style.js +15 -3
- package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +25 -0
- package/src/components/checkbox-group-field/checkbox-group-field.define.js +3 -0
- package/src/components/checkbox-group-field/checkbox-group-field.js +217 -0
- package/src/components/checkbox-group-field/checkbox-group-field.readme.md +95 -0
- package/src/components/checkbox-group-field/checkbox-group-field.style.js +62 -0
- package/src/components/color-field/color-field.changelog.md +24 -0
- package/src/components/color-field/color-field.define.js +3 -0
- package/src/components/color-field/color-field.js +184 -0
- package/src/components/color-field/color-field.readme.md +95 -0
- package/src/components/color-field/color-field.style.js +39 -0
- package/src/components/combobox-field/combobox-field.changelog.md +23 -0
- package/src/components/combobox-field/combobox-field.define.js +3 -0
- package/src/components/combobox-field/combobox-field.js +97 -0
- package/src/components/combobox-field/combobox-field.readme.md +93 -0
- package/src/components/combobox-field/combobox-field.style.js +56 -0
- package/src/components/copy-button/copy-button.changelog.md +24 -0
- package/src/components/copy-button/copy-button.define.js +3 -0
- package/src/components/copy-button/copy-button.events.js +4 -0
- package/src/components/copy-button/copy-button.js +237 -0
- package/src/components/copy-button/copy-button.readme.md +134 -0
- package/src/components/copy-button/copy-button.style.js +109 -0
- package/src/components/date-field/date-field.changelog.md +24 -0
- package/src/components/date-field/date-field.define.js +3 -0
- package/src/components/date-field/date-field.js +119 -0
- package/src/components/date-field/date-field.readme.md +110 -0
- package/src/components/date-field/date-field.style.js +53 -0
- package/src/components/dialog/dialog.changelog.md +16 -1
- package/src/components/dialog/dialog.js +252 -57
- package/src/components/dialog/dialog.readme.md +36 -4
- package/src/components/dialog/dialog.style.js +9 -109
- package/src/components/divider/divider.changelog.md +23 -0
- package/src/components/divider/divider.define.js +3 -0
- package/src/components/divider/divider.js +48 -0
- package/src/components/divider/divider.readme.md +101 -0
- package/src/components/divider/divider.style.js +50 -0
- package/src/components/drawer/drawer.changelog.md +25 -0
- package/src/components/drawer/drawer.define.js +3 -0
- package/src/components/drawer/drawer.events.js +8 -0
- package/src/components/drawer/drawer.js +80 -0
- package/src/components/drawer/drawer.readme.md +194 -0
- package/src/components/drawer/drawer.style.js +83 -0
- package/src/components/dropdown/dropdown.js +9 -7
- package/src/components/empty-state/empty-state.changelog.md +22 -0
- package/src/components/empty-state/empty-state.define.js +3 -0
- package/src/components/empty-state/empty-state.js +55 -0
- package/src/components/empty-state/empty-state.readme.md +114 -0
- package/src/components/empty-state/empty-state.style.js +60 -0
- package/src/components/file-field/file-field.changelog.md +24 -0
- package/src/components/file-field/file-field.define.js +3 -0
- package/src/components/file-field/file-field.js +205 -0
- package/src/components/file-field/file-field.readme.md +103 -0
- package/src/components/file-field/file-field.style.js +28 -0
- package/src/components/form-field/form-field.changelog.md +25 -0
- package/src/components/form-field/form-field.js +212 -15
- package/src/components/form-field/form-field.readme.md +82 -18
- package/src/components/form-field/form-field.style.js +6 -24
- package/src/components/input-field/input-field.changelog.md +24 -0
- package/src/components/input-field/input-field.js +82 -6
- package/src/components/input-field/input-field.readme.md +34 -5
- package/src/components/input-field/input-field.style.js +32 -13
- package/src/components/notification/notification.changelog.md +21 -1
- package/src/components/notification/notification.js +80 -74
- package/src/components/notification/notification.readme.md +54 -13
- package/src/components/notification/notification.style.js +37 -22
- package/src/components/otp-field/otp-field.changelog.md +23 -0
- package/src/components/otp-field/otp-field.define.js +3 -0
- package/src/components/otp-field/otp-field.events.js +3 -0
- package/src/components/otp-field/otp-field.js +172 -0
- package/src/components/otp-field/otp-field.readme.md +111 -0
- package/src/components/otp-field/otp-field.style.js +53 -0
- package/src/components/pagination/pagination.changelog.md +30 -0
- package/src/components/pagination/pagination.define.js +3 -0
- package/src/components/pagination/pagination.events.js +3 -0
- package/src/components/pagination/pagination.js +282 -0
- package/src/components/pagination/pagination.readme.md +167 -0
- package/src/components/pagination/pagination.style.js +162 -0
- package/src/components/password-field/password-field.changelog.md +24 -0
- package/src/components/password-field/password-field.js +7 -1
- package/src/components/password-field/password-field.readme.md +15 -6
- package/src/components/password-field/password-field.style.js +36 -13
- package/src/components/popover/popover.changelog.md +24 -0
- package/src/components/popover/popover.define.js +3 -0
- package/src/components/popover/popover.events.js +4 -0
- package/src/components/popover/popover.js +255 -0
- package/src/components/popover/popover.readme.md +132 -0
- package/src/components/popover/popover.style.js +41 -0
- package/src/components/progress-bar/progress-bar.changelog.md +23 -0
- package/src/components/progress-bar/progress-bar.define.js +3 -0
- package/src/components/progress-bar/progress-bar.js +80 -0
- package/src/components/progress-bar/progress-bar.readme.md +110 -0
- package/src/components/progress-bar/progress-bar.style.js +93 -0
- package/src/components/progress-ring/progress-ring.changelog.md +23 -0
- package/src/components/progress-ring/progress-ring.define.js +3 -0
- package/src/components/progress-ring/progress-ring.js +83 -0
- package/src/components/progress-ring/progress-ring.readme.md +115 -0
- package/src/components/progress-ring/progress-ring.style.js +85 -0
- package/src/components/radio-field/radio-field.changelog.md +16 -0
- package/src/components/radio-field/radio-field.js +34 -11
- package/src/components/radio-field/radio-field.readme.md +13 -8
- package/src/components/radio-field/radio-field.style.js +17 -65
- package/src/components/range-field/range-field.changelog.md +24 -0
- package/src/components/range-field/range-field.define.js +3 -0
- package/src/components/range-field/range-field.js +167 -0
- package/src/components/range-field/range-field.readme.md +87 -0
- package/src/components/range-field/range-field.style.js +41 -0
- package/src/components/rating-field/rating-field.changelog.md +24 -0
- package/src/components/rating-field/rating-field.define.js +3 -0
- package/src/components/rating-field/rating-field.js +195 -0
- package/src/components/rating-field/rating-field.readme.md +82 -0
- package/src/components/rating-field/rating-field.style.js +79 -0
- package/src/components/select-field/select-field.changelog.md +17 -0
- package/src/components/select-field/select-field.js +100 -8
- package/src/components/select-field/select-field.readme.md +32 -6
- package/src/components/select-field/select-field.style.js +19 -9
- package/src/components/skeleton/skeleton.changelog.md +22 -0
- package/src/components/skeleton/skeleton.define.js +3 -0
- package/src/components/skeleton/skeleton.js +49 -0
- package/src/components/skeleton/skeleton.readme.md +115 -0
- package/src/components/skeleton/skeleton.style.js +79 -0
- package/src/components/slider/slider.changelog.md +15 -0
- package/src/components/slider/slider.js +37 -5
- package/src/components/slider/slider.readme.md +28 -6
- package/src/components/slider/slider.style.js +7 -71
- package/src/components/spinner/spinner.changelog.md +22 -0
- package/src/components/spinner/spinner.define.js +3 -0
- package/src/components/spinner/spinner.js +48 -0
- package/src/components/spinner/spinner.readme.md +98 -0
- package/src/components/spinner/spinner.style.js +44 -0
- package/src/components/switch-field/switch-field.changelog.md +22 -0
- package/src/components/switch-field/switch-field.js +24 -10
- package/src/components/switch-field/switch-field.readme.md +11 -4
- package/src/components/switch-field/switch-field.style.js +13 -13
- package/src/components/tab-group/tab-group.changelog.md +19 -0
- package/src/components/tab-group/tab-group.js +122 -10
- package/src/components/tab-group/tab-group.readme.md +25 -4
- package/src/components/tab-link/tab-link.changelog.md +16 -0
- package/src/components/tab-link/tab-link.js +51 -8
- package/src/components/tab-link/tab-link.readme.md +14 -8
- package/src/components/tab-link/tab-link.style.js +13 -0
- package/src/components/tab-panel/tab-panel.changelog.md +8 -2
- package/src/components/tab-panel/tab-panel.js +7 -3
- package/src/components/tab-panel/tab-panel.readme.md +7 -5
- package/src/components/tag/tag.changelog.md +24 -0
- package/src/components/tag/tag.define.js +3 -0
- package/src/components/tag/tag.events.js +3 -0
- package/src/components/tag/tag.js +116 -0
- package/src/components/tag/tag.readme.md +119 -0
- package/src/components/tag/tag.style.js +101 -0
- package/src/components/tag-field/tag-field.changelog.md +25 -0
- package/src/components/tag-field/tag-field.define.js +3 -0
- package/src/components/tag-field/tag-field.js +359 -0
- package/src/components/tag-field/tag-field.readme.md +113 -0
- package/src/components/tag-field/tag-field.style.js +62 -0
- package/src/components/textarea-field/textarea-field.changelog.md +28 -4
- package/src/components/textarea-field/textarea-field.js +68 -14
- package/src/components/textarea-field/textarea-field.readme.md +45 -9
- package/src/components/textarea-field/textarea-field.style.js +45 -2
- package/src/components/toast/toast.changelog.md +24 -0
- package/src/components/toast/toast.define.js +3 -0
- package/src/components/toast/toast.js +193 -0
- package/src/components/toast/toast.readme.md +189 -0
- package/src/components/toast/toast.style.js +74 -0
- package/src/components/tooltip/tooltip.changelog.md +24 -0
- package/src/components/tooltip/tooltip.define.js +3 -0
- package/src/components/tooltip/tooltip.events.js +4 -0
- package/src/components/tooltip/tooltip.js +377 -0
- package/src/components/tooltip/tooltip.readme.md +172 -0
- package/src/components/tooltip/tooltip.style.js +107 -0
- package/src/components/transition-classes/transition-classes.js +6 -6
- package/src/styles/appearance.style.js +42 -0
- package/src/styles/arrow.style.js +65 -0
- package/src/styles/choice-group.style.js +94 -0
- package/src/styles/form-control.style.js +79 -0
- package/src/styles/host.style.js +55 -0
- package/src/styles/layers.css +31 -0
- package/src/styles/modal.style.js +146 -0
- package/src/styles/native.css +275 -0
- package/src/styles/size.style.js +48 -0
- package/src/styles/slide-controls.style.js +225 -0
- package/src/styles/utilities.css +30 -0
- package/src/styles/variants.style.js +78 -0
- package/src/themes/default.css +86 -142
- package/src/themes/high-contrast.css +72 -129
- package/src/themes/sketchy.css +95 -175
- package/src/utils/floating.js +71 -0
- package/src/utils/focus.js +18 -0
- package/src/utils/progress.js +25 -0
- package/src/utils/slots.js +21 -0
- package/src/utils/text-entry-attributes.js +51 -0
- package/types/all.d.ts +54 -1
- package/types/index.d.ts +1 -0
- package/types/src/components/accordion/accordion.d.ts +6 -4
- package/types/src/components/accordion/accordion.events.d.ts +3 -3
- package/types/src/components/accordion-group/accordion-group.d.ts +4 -3
- package/types/src/components/amount-field/amount-field.d.ts +30 -16
- package/types/src/components/avatar/avatar.d.ts +57 -0
- package/types/src/components/avatar/avatar.define.d.ts +1 -0
- package/types/src/components/avatar/avatar.style.d.ts +2 -0
- package/types/src/components/badge/badge.d.ts +32 -0
- package/types/src/components/badge/badge.define.d.ts +1 -0
- package/types/src/components/badge/badge.style.d.ts +2 -0
- package/types/src/components/breadcrumb/breadcrumb.d.ts +27 -0
- package/types/src/components/breadcrumb/breadcrumb.define.d.ts +1 -0
- package/types/src/components/breadcrumb/breadcrumb.style.d.ts +2 -0
- package/types/src/components/breadcrumb-item/breadcrumb-item.d.ts +38 -0
- package/types/src/components/breadcrumb-item/breadcrumb-item.define.d.ts +1 -0
- package/types/src/components/breadcrumb-item/breadcrumb-item.style.d.ts +2 -0
- package/types/src/components/button/button.d.ts +158 -14
- package/types/src/components/button-group/button-group.d.ts +28 -0
- package/types/src/components/button-group/button-group.define.d.ts +1 -0
- package/types/src/components/button-group/button-group.style.d.ts +2 -0
- package/types/src/components/card/card.d.ts +40 -0
- package/types/src/components/card/card.define.d.ts +1 -0
- package/types/src/components/card/card.style.d.ts +2 -0
- package/types/src/components/carousel/carousel.d.ts +22 -8
- package/types/src/components/carousel/carousel.events.d.ts +3 -3
- package/types/src/components/carousel/glide/components/ShadowAnchors.d.ts +1 -1
- package/types/src/components/carousel/glide/components/ShadowClones.d.ts +8 -1
- package/types/src/components/carousel/glide/components/ShadowGaps.d.ts +1 -1
- package/types/src/components/carousel/glide/components/ShadowHtml.d.ts +1 -1
- package/types/src/components/carousel/glide/components/glide-html.d.ts +1 -1
- package/types/src/components/checkbox-field/checkbox-field.d.ts +22 -15
- package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +100 -0
- package/types/src/components/checkbox-group-field/checkbox-group-field.define.d.ts +1 -0
- package/types/src/components/checkbox-group-field/checkbox-group-field.style.d.ts +2 -0
- package/types/src/components/color-field/color-field.d.ts +102 -0
- package/types/src/components/color-field/color-field.define.d.ts +1 -0
- package/types/src/components/color-field/color-field.style.d.ts +2 -0
- package/types/src/components/combobox-field/combobox-field.d.ts +84 -0
- package/types/src/components/combobox-field/combobox-field.define.d.ts +1 -0
- package/types/src/components/combobox-field/combobox-field.style.d.ts +2 -0
- package/types/src/components/copy-button/copy-button.d.ts +93 -0
- package/types/src/components/copy-button/copy-button.define.d.ts +1 -0
- package/types/src/components/copy-button/copy-button.events.d.ts +5 -0
- package/types/src/components/copy-button/copy-button.style.d.ts +2 -0
- package/types/src/components/date-field/date-field.d.ts +102 -0
- package/types/src/components/date-field/date-field.define.d.ts +1 -0
- package/types/src/components/date-field/date-field.style.d.ts +2 -0
- package/types/src/components/dialog/dialog.d.ts +101 -19
- package/types/src/components/dialog/dialog.events.d.ts +8 -8
- package/types/src/components/divider/divider.d.ts +27 -0
- package/types/src/components/divider/divider.define.d.ts +1 -0
- package/types/src/components/divider/divider.style.d.ts +2 -0
- package/types/src/components/drawer/drawer.d.ts +70 -0
- package/types/src/components/drawer/drawer.define.d.ts +1 -0
- package/types/src/components/drawer/drawer.events.d.ts +9 -0
- package/types/src/components/drawer/drawer.style.d.ts +2 -0
- package/types/src/components/dropdown/dropdown.d.ts +5 -3
- package/types/src/components/empty-state/empty-state.d.ts +29 -0
- package/types/src/components/empty-state/empty-state.define.d.ts +1 -0
- package/types/src/components/empty-state/empty-state.style.d.ts +2 -0
- package/types/src/components/file-field/file-field.d.ts +115 -0
- package/types/src/components/file-field/file-field.define.d.ts +1 -0
- package/types/src/components/file-field/file-field.style.d.ts +2 -0
- package/types/src/components/form-field/form-field.d.ts +129 -14
- package/types/src/components/form-field/form-field.events.d.ts +4 -4
- package/types/src/components/input-field/input-field.d.ts +52 -5
- package/types/src/components/lazy-src/lazy-src.d.ts +7 -5
- package/types/src/components/lazy-src/lazy-src.events.d.ts +5 -5
- package/types/src/components/notification/notification.d.ts +18 -18
- package/types/src/components/notification/notification.events.d.ts +6 -6
- package/types/src/components/otp-field/otp-field.d.ts +130 -0
- package/types/src/components/otp-field/otp-field.define.d.ts +1 -0
- package/types/src/components/otp-field/otp-field.events.d.ts +4 -0
- package/types/src/components/otp-field/otp-field.style.d.ts +2 -0
- package/types/src/components/pagination/pagination.d.ts +117 -0
- package/types/src/components/pagination/pagination.define.d.ts +1 -0
- package/types/src/components/pagination/pagination.events.d.ts +4 -0
- package/types/src/components/pagination/pagination.style.d.ts +2 -0
- package/types/src/components/password-field/password-field.d.ts +29 -12
- package/types/src/components/popover/popover.d.ts +123 -0
- package/types/src/components/popover/popover.define.d.ts +1 -0
- package/types/src/components/popover/popover.events.d.ts +5 -0
- package/types/src/components/popover/popover.style.d.ts +2 -0
- package/types/src/components/progress-bar/progress-bar.d.ts +35 -0
- package/types/src/components/progress-bar/progress-bar.define.d.ts +1 -0
- package/types/src/components/progress-bar/progress-bar.style.d.ts +2 -0
- package/types/src/components/progress-ring/progress-ring.d.ts +40 -0
- package/types/src/components/progress-ring/progress-ring.define.d.ts +1 -0
- package/types/src/components/progress-ring/progress-ring.style.d.ts +2 -0
- package/types/src/components/radio-field/radio-field.d.ts +21 -9
- package/types/src/components/range-field/range-field.d.ts +94 -0
- package/types/src/components/range-field/range-field.define.d.ts +1 -0
- package/types/src/components/range-field/range-field.style.d.ts +2 -0
- package/types/src/components/rating-field/rating-field.d.ts +96 -0
- package/types/src/components/rating-field/rating-field.define.d.ts +1 -0
- package/types/src/components/rating-field/rating-field.style.d.ts +2 -0
- package/types/src/components/scroll-to/scroll-to.d.ts +3 -2
- package/types/src/components/scroll-to-top/scroll-to-top.d.ts +4 -2
- package/types/src/components/select-field/select-field.d.ts +55 -5
- package/types/src/components/skeleton/skeleton.d.ts +29 -0
- package/types/src/components/skeleton/skeleton.define.d.ts +1 -0
- package/types/src/components/skeleton/skeleton.style.d.ts +2 -0
- package/types/src/components/slider/slider.d.ts +14 -8
- package/types/src/components/slider/slider.events.d.ts +4 -4
- package/types/src/components/spinner/spinner.d.ts +28 -0
- package/types/src/components/spinner/spinner.define.d.ts +1 -0
- package/types/src/components/spinner/spinner.style.d.ts +2 -0
- package/types/src/components/sticky/sticky.d.ts +4 -2
- package/types/src/components/svg-use/svg-use.d.ts +4 -2
- package/types/src/components/switch-field/switch-field.d.ts +17 -15
- package/types/src/components/tab-group/tab-group.d.ts +44 -3
- package/types/src/components/tab-link/tab-link.d.ts +33 -10
- package/types/src/components/tab-panel/tab-panel.d.ts +8 -5
- package/types/src/components/tag/tag.d.ts +53 -0
- package/types/src/components/tag/tag.define.d.ts +1 -0
- package/types/src/components/tag/tag.events.d.ts +4 -0
- package/types/src/components/tag/tag.style.d.ts +2 -0
- package/types/src/components/tag-field/tag-field.d.ts +178 -0
- package/types/src/components/tag-field/tag-field.define.d.ts +1 -0
- package/types/src/components/tag-field/tag-field.style.d.ts +2 -0
- package/types/src/components/textarea-field/textarea-field.d.ts +44 -4
- package/types/src/components/toast/toast.d.ts +110 -0
- package/types/src/components/toast/toast.define.d.ts +1 -0
- package/types/src/components/toast/toast.style.d.ts +2 -0
- package/types/src/components/tooltip/tooltip.d.ts +161 -0
- package/types/src/components/tooltip/tooltip.define.d.ts +1 -0
- package/types/src/components/tooltip/tooltip.events.d.ts +5 -0
- package/types/src/components/tooltip/tooltip.style.d.ts +2 -0
- package/types/src/components/transition-classes/transition-classes.d.ts +9 -8
- package/types/src/styles/appearance.style.d.ts +18 -0
- package/types/src/styles/arrow.style.d.ts +15 -0
- package/types/src/styles/choice-group.style.d.ts +23 -0
- package/types/src/styles/form-control.style.d.ts +26 -0
- package/types/src/styles/host.style.d.ts +24 -0
- package/types/src/styles/modal.style.d.ts +20 -0
- package/types/src/styles/size.style.d.ts +20 -0
- package/types/src/styles/slide-controls.style.d.ts +20 -0
- package/types/src/styles/variants.style.d.ts +32 -0
- package/types/src/utils/body-scroll.d.ts +12 -2
- package/types/src/utils/floating.d.ts +36 -0
- package/types/src/utils/focus.d.ts +16 -0
- package/types/src/utils/progress.d.ts +19 -0
- package/types/src/utils/slots.d.ts +19 -0
- package/types/src/utils/text-entry-attributes.d.ts +18 -0
- package/types/src/utils/transitions.d.ts +2 -2
- package/web-types.json +6590 -1584
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { defineElement } from '@webtides/element-js';
|
|
2
|
+
import InputField from '../input-field/input-field.js';
|
|
3
|
+
import Events from './otp-field.events.js';
|
|
4
|
+
import style from './otp-field.style.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A one-time code: the short code of a second factor that the user gets by SMS, by mail or from an
|
|
8
|
+
* app. Extends `InputField` (and therefore `FormField`), inheriting the label / help / error /
|
|
9
|
+
* validation surface and the look from `styles/native.css`.
|
|
10
|
+
*
|
|
11
|
+
* It is one native `<input>`, not one per digit: the code from an SMS, a paste, a password manager
|
|
12
|
+
* and a screen reader all work on one control. The field sets what such an input needs
|
|
13
|
+
* (`autocomplete`, `inputmode`, a pattern of `length` digits), takes the spaces and the hyphens out
|
|
14
|
+
* of a code that is entered the way a mail shows it, takes no further key once the code is full, and
|
|
15
|
+
* says when the code is complete.
|
|
16
|
+
*
|
|
17
|
+
* @element el-otp-field
|
|
18
|
+
*
|
|
19
|
+
* @fires {CustomEvent<string>} input-change - Fired when the value changes. `detail` is the new
|
|
20
|
+
* value. Bubbles.
|
|
21
|
+
* @fires {CustomEvent<string>} input-complete - Fired when the user has entered a code of full
|
|
22
|
+
* length that is valid: once, and again after the code was changed and completed again. Not
|
|
23
|
+
* fired for a value a script sets. `detail` is the code. Bubbles.
|
|
24
|
+
*
|
|
25
|
+
* @property {number} length - The number of characters of the code. Default `6`.
|
|
26
|
+
* @property {string | false} pattern - Regular expression for the code. `false` (the default) is a
|
|
27
|
+
* pattern of `length` digits. Set one of your own for a code with letters.
|
|
28
|
+
* @property {string | null} autocomplete - Passed on to the control as `autocomplete`. Default
|
|
29
|
+
* `'one-time-code'`: a phone offers the code of an SMS it has just got.
|
|
30
|
+
* @property {string | null} inputmode - Passed on as `inputmode`. Default `'numeric'`: a phone
|
|
31
|
+
* shows the digits. Set `'text'` for a code with letters.
|
|
32
|
+
*/
|
|
33
|
+
export default class OtpField extends InputField {
|
|
34
|
+
/**
|
|
35
|
+
* The complete code the control has, or `null`. What `input-complete` is not fired for again.
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
_completed = null;
|
|
39
|
+
|
|
40
|
+
constructor(options) {
|
|
41
|
+
super({ shadowRender: false, styles: [style], ...options });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
properties() {
|
|
45
|
+
return {
|
|
46
|
+
...super.properties(),
|
|
47
|
+
length: 6,
|
|
48
|
+
autocomplete: 'one-time-code',
|
|
49
|
+
inputmode: 'numeric',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
watch() {
|
|
54
|
+
const watchers = super.watch();
|
|
55
|
+
return {
|
|
56
|
+
...watchers,
|
|
57
|
+
value: (value, oldValue) => {
|
|
58
|
+
watchers.value(value, oldValue);
|
|
59
|
+
// A code from a script is not one the user has entered.
|
|
60
|
+
this._completed = this._completeCode();
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
events() {
|
|
66
|
+
const events = super.events();
|
|
67
|
+
return {
|
|
68
|
+
...events,
|
|
69
|
+
'[ref=input]': {
|
|
70
|
+
...events['[ref=input]'],
|
|
71
|
+
beforeinput: (event) => this._onBeforeInput(event),
|
|
72
|
+
// Not every way into the control presses a key: a paste with the mouse, the code a
|
|
73
|
+
// phone offers from an SMS.
|
|
74
|
+
input: (event) => this._onInput(event),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onChange() {
|
|
80
|
+
super.onChange();
|
|
81
|
+
this._completed = this._completeCode();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A code that is full takes no further key, as an input with `maxlength` does: the character
|
|
86
|
+
* would push the last one of the code out, wherever the caret is. The control has no
|
|
87
|
+
* `maxlength` itself, see `_clean()`. A paste is not held back here, it is cut after it was
|
|
88
|
+
* cleaned.
|
|
89
|
+
* @private
|
|
90
|
+
* @param {InputEvent} event
|
|
91
|
+
*/
|
|
92
|
+
_onBeforeInput(event) {
|
|
93
|
+
if (event.inputType !== 'insertText' || event.isComposing) return;
|
|
94
|
+
|
|
95
|
+
const control = event.target;
|
|
96
|
+
const replaced = control.selectionEnd - control.selectionStart;
|
|
97
|
+
if (control.value.length - replaced >= this._length()) event.preventDefault();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The control has another text. Cleans it, takes it over, and says so when it is a complete
|
|
102
|
+
* code now and was not one before.
|
|
103
|
+
* @private
|
|
104
|
+
* @param {InputEvent} event
|
|
105
|
+
*/
|
|
106
|
+
_onInput(event) {
|
|
107
|
+
const control = this.$refs.input;
|
|
108
|
+
|
|
109
|
+
// A text that is still being composed is left alone, writing it would end the composition.
|
|
110
|
+
if (!event.isComposing) {
|
|
111
|
+
const code = this._clean(control.value);
|
|
112
|
+
if (code !== control.value) control.value = code;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const before = this._completed;
|
|
116
|
+
this.onChange();
|
|
117
|
+
if (this._completed !== null && this._completed !== before) {
|
|
118
|
+
this.dispatch(Events.COMPLETE, this._completed);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A code the way it is entered: without the spaces and the hyphens that a mail or an SMS groups
|
|
124
|
+
* its digits with, and not longer than a code is. Nothing else is taken out: what does not fit
|
|
125
|
+
* the pattern is not valid, and the field says so.
|
|
126
|
+
*
|
|
127
|
+
* This is why the control has no `maxlength`: the browser would cut a pasted `123 456` to
|
|
128
|
+
* `123 45` before the field has taken the space out.
|
|
129
|
+
* @private
|
|
130
|
+
* @param {string} text
|
|
131
|
+
* @returns {string}
|
|
132
|
+
*/
|
|
133
|
+
_clean(text) {
|
|
134
|
+
return String(text ?? '')
|
|
135
|
+
.replace(/[\s-]/g, '')
|
|
136
|
+
.slice(0, this._length());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @private
|
|
141
|
+
* @returns {number} The length of a code: `length`, or 6 where that is no number of characters.
|
|
142
|
+
*/
|
|
143
|
+
_length() {
|
|
144
|
+
const length = Math.floor(Number(this.length));
|
|
145
|
+
return length >= 1 ? length : 6;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The pattern of the page, or one of `length` digits.
|
|
150
|
+
* @private
|
|
151
|
+
* @returns {string}
|
|
152
|
+
*/
|
|
153
|
+
_pattern() {
|
|
154
|
+
return this.pattern || `[0-9]{${this._length()}}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @private
|
|
159
|
+
* @returns {string | null} The text of the control when it is a complete and valid code.
|
|
160
|
+
*/
|
|
161
|
+
_completeCode() {
|
|
162
|
+
const control = this.$refs?.input;
|
|
163
|
+
if (!control || control.value.length !== this._length() || !control.validity.valid) return null;
|
|
164
|
+
return control.value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function define() {
|
|
169
|
+
defineElement('el-otp-field', OtpField);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { Events };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# OtpField
|
|
2
|
+
|
|
3
|
+
`otp-field` takes a one-time code: the short code of a second factor that the user gets by SMS, by mail or from an app. It extends `input-field`, inheriting the label, help text, error message, `required`, the sizes and the touched-state handling.
|
|
4
|
+
|
|
5
|
+
It is one native `<input>`, not one per digit. The code from an SMS, a paste, a password manager and a screen reader all work on one control; with a box per digit each of them has to be rebuilt by hand.
|
|
6
|
+
|
|
7
|
+
It is headless by default: the control keeps the look of the browser. `styles/native.css` gives it the look of the input of `el-input-field`.
|
|
8
|
+
|
|
9
|
+
## How to use
|
|
10
|
+
|
|
11
|
+
#### Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i --save @webtides/element-library
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
#### Use
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import '@webtides/element-library/otp-field/define';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<el-otp-field name="code" label="Code from the SMS" required="true"></el-otp-field>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Without further attributes the control has `autocomplete="one-time-code"`, so a phone offers the code of an SMS it has just got, `inputmode="numeric"`, so it shows the digits, and a pattern of `length` digits.
|
|
28
|
+
|
|
29
|
+
#### What the user enters
|
|
30
|
+
|
|
31
|
+
Spaces and hyphens are taken out of what is typed, pasted or filled in: a mail shows a code as `123 456` or `123-456`, and that is how it is pasted. The code is cut at `length`.
|
|
32
|
+
|
|
33
|
+
A code that is full takes no further key, as an input with `maxlength` does: the character would push the last one of the code out. Nothing else is held back or filtered. A code that does not fit the pattern is not valid, and the field says so with its error message.
|
|
34
|
+
|
|
35
|
+
#### When the code is complete
|
|
36
|
+
|
|
37
|
+
`input-complete` is fired once the user has entered a code of full length that is valid, with the code as its detail. A page can submit the form with it:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
field.addEventListener('input-complete', () => form.requestSubmit());
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
It is fired again after the code was changed and completed again. It is not fired for a value a script sets.
|
|
44
|
+
|
|
45
|
+
#### A code with letters
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<el-otp-field
|
|
49
|
+
name="backup"
|
|
50
|
+
label="Backup code"
|
|
51
|
+
length="8"
|
|
52
|
+
pattern="[A-Za-z0-9]{8}"
|
|
53
|
+
inputmode="text"
|
|
54
|
+
autocomplete="off"
|
|
55
|
+
></el-otp-field>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
#### Properties/Attributes
|
|
61
|
+
|
|
62
|
+
Inherits all of `input-field`'s properties (`name`, `value`, `required`, `disabled`, `label`, `labelScreenReaderOnly`, `errorMessage`, `helpMessage`, `valid`, `touched`, `size`, `placeholder`, `enterkeyhint`, `autocapitalize`, `autocorrect`, `spellcheck`) and changes or adds:
|
|
63
|
+
|
|
64
|
+
| Name | Type | Default | Description |
|
|
65
|
+
| --- | --- | --- | --- |
|
|
66
|
+
| `length` | `number` | `6` | The number of characters of the code. |
|
|
67
|
+
| `pattern` | `string \| false` | `false` | Regular expression for the code. `false` is a pattern of `length` digits. |
|
|
68
|
+
| `autocomplete` | `string \| null` | `'one-time-code'` | Passed on to the control as `autocomplete`. |
|
|
69
|
+
| `inputmode` | `string \| null` | `'numeric'` | Passed on to the control as `inputmode`. `'text'` for a code with letters. |
|
|
70
|
+
|
|
71
|
+
`value` is the code as text, so a code that starts with a zero keeps it.
|
|
72
|
+
|
|
73
|
+
The control has no `maxlength`: the browser would cut a pasted `123 456` before the field has taken the space out. The field does what `maxlength` does itself.
|
|
74
|
+
|
|
75
|
+
#### Events
|
|
76
|
+
|
|
77
|
+
| Name | Detail | Description |
|
|
78
|
+
| --- | --- | --- |
|
|
79
|
+
| `input-change` | `string` (the value) | Fired when the value changes. |
|
|
80
|
+
| `input-complete` | `string` (the code) | Fired when the user has entered a code of full length that is valid. Once for a code, see above. |
|
|
81
|
+
|
|
82
|
+
#### CSS States
|
|
83
|
+
|
|
84
|
+
| Name | Description |
|
|
85
|
+
| --------- | ----------------------------------------------------------------------------- |
|
|
86
|
+
| `touched` | Set once the user has focused and left the control, or the field has a value. |
|
|
87
|
+
| `valid` | Set while the field passes validation. |
|
|
88
|
+
| `invalid` | Set while the field fails validation (the pattern, `required`). |
|
|
89
|
+
|
|
90
|
+
#### CSS Custom Properties
|
|
91
|
+
|
|
92
|
+
Headless by default; the field reads the tokens `el-input-field` reads. With `styles/native.css` the control has the border, the radius, the padding, the colours, the focus ring and the three sizes of the input of `el-input-field`. See the Storybook _Docs / Theming_ page.
|
|
93
|
+
|
|
94
|
+
The field is as wide as its container. A width of its own goes on the element:
|
|
95
|
+
|
|
96
|
+
```css
|
|
97
|
+
el-otp-field {
|
|
98
|
+
max-width: 12rem;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The label, the help message, the control and the error message stack in a column, and the texts have one look in every field: see [Layout](../form-field/form-field.readme.md#layout) in the readme of `form-field`.
|
|
103
|
+
|
|
104
|
+
On a touch screen (`@media (any-pointer: coarse)`) the control and the clear cross are at least `--el-touch-target` high. Without that token, and on a fine pointer, the sizes stay as they are.
|
|
105
|
+
|
|
106
|
+
## Accessibility
|
|
107
|
+
|
|
108
|
+
- One native text input, named by the label (`<label for>`). A screen reader reads the code as one value, and the user moves in it as in any text.
|
|
109
|
+
- The control names the help message in `aria-describedby`, and the error message while that is shown, and says whether it is valid (`aria-invalid`).
|
|
110
|
+
- Say in the label or in the help message how long the code is and where it comes from.
|
|
111
|
+
- A page that submits the form on `input-complete` moves the user on without a key press. Do that only where a wrong code can be entered again.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import hostStyle from '../../styles/host.style.js';
|
|
2
|
+
import formControlStyle from '../../styles/form-control.style.js';
|
|
3
|
+
import sizeStyle from '../../styles/size.style.js';
|
|
4
|
+
|
|
5
|
+
const css = String.raw;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The field has the style of `el-input-field`, under its own tag: a field does not get the
|
|
9
|
+
* stylesheet of the class it extends.
|
|
10
|
+
*/
|
|
11
|
+
const style = css`
|
|
12
|
+
el-otp-field {
|
|
13
|
+
.field {
|
|
14
|
+
.validity {
|
|
15
|
+
.valid {
|
|
16
|
+
color: var(--el-color-success, green);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.invalid {
|
|
20
|
+
color: var(--el-color-danger, red);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Touch screens: the control and the clear cross are at least --el-touch-target, whatever
|
|
26
|
+
the size of the field. The mark beside the input keeps that width in both states, so the
|
|
27
|
+
input does not jump when the validity changes. Without the token the sizes stay as they
|
|
28
|
+
are. */
|
|
29
|
+
@media (any-pointer: coarse) {
|
|
30
|
+
input {
|
|
31
|
+
min-height: max(
|
|
32
|
+
calc(var(--el-control-height, 0px) * var(--_el-size-scale, 1)),
|
|
33
|
+
var(--el-touch-target, 0px)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.validity,
|
|
38
|
+
[data-clear-input] {
|
|
39
|
+
display: grid;
|
|
40
|
+
place-items: center;
|
|
41
|
+
min-width: var(--el-touch-target, auto);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[data-clear-input] {
|
|
45
|
+
min-height: var(--el-touch-target, auto);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
export default [hostStyle('el-otp-field'), formControlStyle('el-otp-field'), sizeStyle('el-otp-field'), style].join(
|
|
52
|
+
'\n',
|
|
53
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this component live here. Versions refer to the parent `@webtides/element-library` release (see root [`CHANGELOG.md`](../../../CHANGELOG.md)); components no longer version independently.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
6
|
+
|
|
7
|
+
<!--
|
|
8
|
+
When your PR touches this component, add an entry under Unreleased and
|
|
9
|
+
mirror it (prefixed with the component name) in root CHANGELOG.md.
|
|
10
|
+
Uncomment headings as needed.
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
## Unreleased
|
|
14
|
+
|
|
15
|
+
## [0.3.0] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- Initial `el-pagination`: the way through a list that is split into pages. A `nav` landmark with a button per page, the current one marked with `aria-current="page"`, and a button for the page before and the page after. ([#80](https://github.com/webtides/element-library/issues/80))
|
|
20
|
+
- `page`, `total` and `per-page` say where in the list the page is; the read-only `pages` is the number of pages. A page that does not exist is shown as the nearest one that does.
|
|
21
|
+
- `siblings` and `boundaries`: how many pages are shown around the current one and at both ends. The pages in between make way for an ellipsis, and the row has the same number of places on every page.
|
|
22
|
+
- `pagination-change` with the new page in `detail.page`, fired when a button has changed the page.
|
|
23
|
+
- The focus follows the page: it is on the button of the page that was chosen, wherever that stands in the new row, and stays on an arrow button until it reaches the end.
|
|
24
|
+
- `size` (`small`, `medium`, `large`), reflected. The buttons are squares of the control height of the size, and at least `--el-touch-target` on a touch screen.
|
|
25
|
+
- `label`, `page-label`, `previous-label` and `next-label` for the names in another language, and the slots `previous-icon` and `next-icon`.
|
|
26
|
+
- With forced colours the current page has the colours of a selection; the arrow heads turn with the reading direction.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- Without a theme the keyboard focus of the current page shows on every page: a ring around it in the text colour of the other buttons, `--el-color-fg` or the text colour of the page. Before, the ring had the colour of the text on the fill of the current page, a white ring on a white page. The ring of the other buttons, and every ring with `--el-color-focus-ring`, is as it was. Where the user forces colours, the ring of the current page has a colour of the system, with a theme as well. ([#160](https://github.com/webtides/element-library/issues/160))
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import style from './pagination.style.js';
|
|
3
|
+
import Events from './pagination.events.js';
|
|
4
|
+
|
|
5
|
+
/** What `perPage` is without a value that can be used. */
|
|
6
|
+
const PER_PAGE = 10;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A whole number that is not negative, from a property that may hold anything.
|
|
10
|
+
* @param {*} value
|
|
11
|
+
* @param {number} fallback - For a value that is no number.
|
|
12
|
+
* @returns {number}
|
|
13
|
+
*/
|
|
14
|
+
function count(value, fallback) {
|
|
15
|
+
const number = Math.floor(Number(value));
|
|
16
|
+
return Number.isFinite(number) ? Math.max(0, number) : fallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A pagination: the way through a list that is split into pages. It shows the current page, the
|
|
21
|
+
* pages around it, the first and the last, and a button for the page before and the page after.
|
|
22
|
+
* The pages in between are left out, and the row keeps its length while the current page moves.
|
|
23
|
+
*
|
|
24
|
+
* The pagination does not load anything. A button sets `page` and fires `pagination-change`, and
|
|
25
|
+
* the page shows the entries that belong to it.
|
|
26
|
+
*
|
|
27
|
+
* @element el-pagination
|
|
28
|
+
*
|
|
29
|
+
* @fires {CustomEvent<{ page: number }>} pagination-change - Fired when a button has changed the
|
|
30
|
+
* page. `detail.page` is the new page. Not fired when `page` is set from a script.
|
|
31
|
+
*
|
|
32
|
+
* @slot previous-icon - The icon of the button for the page before. Unset, an arrow head.
|
|
33
|
+
* @slot next-icon - The icon of the button for the page after. Unset, an arrow head.
|
|
34
|
+
*
|
|
35
|
+
* @csspart base - The `nav` landmark.
|
|
36
|
+
* @csspart list - The row of the buttons.
|
|
37
|
+
* @csspart button - Every button: the pages, the page before and the page after.
|
|
38
|
+
* @csspart page - The button of a page.
|
|
39
|
+
* @csspart current - The button of the current page.
|
|
40
|
+
* @csspart previous - The button for the page before.
|
|
41
|
+
* @csspart next - The button for the page after.
|
|
42
|
+
* @csspart ellipsis - The mark in the place of pages that are left out.
|
|
43
|
+
*
|
|
44
|
+
* @property {number} page - The current page, counted from 1. A page that does not exist is shown
|
|
45
|
+
* as the nearest one that does. Default `1`. Reflected to the `page` attribute.
|
|
46
|
+
* @property {number} total - The number of entries in the whole list. Default `0`.
|
|
47
|
+
* @property {number} perPage - The number of entries on one page. Default `10`.
|
|
48
|
+
* @property {number} siblings - How many pages are shown on each side of the current page.
|
|
49
|
+
* Default `1`.
|
|
50
|
+
* @property {number} boundaries - How many pages are shown at the start and at the end of the
|
|
51
|
+
* row. Default `1`.
|
|
52
|
+
* @property {'small'|'medium'|'large'} size - The size of the buttons. Default `'medium'`.
|
|
53
|
+
* Reflected to the `size` attribute.
|
|
54
|
+
* @property {string} label - The name of the landmark. Two paginations on a page need two names.
|
|
55
|
+
* Default `'Pagination'`.
|
|
56
|
+
* @property {string} pageLabel - The word the button of a page is named with, in front of its
|
|
57
|
+
* number: "Page 3". Default `'Page'`.
|
|
58
|
+
* @property {string} previousLabel - The name of the button for the page before. Default
|
|
59
|
+
* `'Previous page'`.
|
|
60
|
+
* @property {string} nextLabel - The name of the button for the page after. Default
|
|
61
|
+
* `'Next page'`.
|
|
62
|
+
*/
|
|
63
|
+
export default class Pagination extends TemplateElement {
|
|
64
|
+
constructor() {
|
|
65
|
+
super({
|
|
66
|
+
styles: [style],
|
|
67
|
+
shadowRender: true,
|
|
68
|
+
propertyOptions: {
|
|
69
|
+
page: { reflect: true },
|
|
70
|
+
// The shared size module selects the host by this attribute.
|
|
71
|
+
size: { reflect: true },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
properties() {
|
|
77
|
+
return {
|
|
78
|
+
page: 1,
|
|
79
|
+
total: 0,
|
|
80
|
+
perPage: PER_PAGE,
|
|
81
|
+
siblings: 1,
|
|
82
|
+
boundaries: 1,
|
|
83
|
+
size: 'medium',
|
|
84
|
+
label: 'Pagination',
|
|
85
|
+
pageLabel: 'Page',
|
|
86
|
+
previousLabel: 'Previous page',
|
|
87
|
+
nextLabel: 'Next page',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The number of pages: `total` divided by `perPage`, rounded up. A list without entries has one
|
|
93
|
+
* page, an empty one. Read-only.
|
|
94
|
+
* @returns {number}
|
|
95
|
+
*/
|
|
96
|
+
get pages() {
|
|
97
|
+
const perPage = count(this.perPage, PER_PAGE) || PER_PAGE;
|
|
98
|
+
return Math.max(1, Math.ceil(count(this.total, 0) / perPage));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
events() {
|
|
102
|
+
return {
|
|
103
|
+
'[data-page]': {
|
|
104
|
+
click: (event) => this._goTo(Number(event.currentTarget.dataset.page), event.currentTarget),
|
|
105
|
+
},
|
|
106
|
+
// One page back or on from where the pagination is now, not from where it was when the
|
|
107
|
+
// row was rendered: two presses within one frame are two pages.
|
|
108
|
+
'[data-step]': {
|
|
109
|
+
click: (event) =>
|
|
110
|
+
this._goTo(this._currentPage() + Number(event.currentTarget.dataset.step), event.currentTarget),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
afterUpdate() {
|
|
116
|
+
this._restoreFocus();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The page that is shown as the current one: `page`, or the nearest page that exists.
|
|
121
|
+
* @private
|
|
122
|
+
* @returns {number}
|
|
123
|
+
*/
|
|
124
|
+
_currentPage() {
|
|
125
|
+
return Math.min(Math.max(count(this.page, 1), 1), this.pages);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Makes another page the current one, for a button.
|
|
130
|
+
* @private
|
|
131
|
+
* @param {number} page
|
|
132
|
+
* @param {HTMLButtonElement} button - The button that asked for it.
|
|
133
|
+
*/
|
|
134
|
+
_goTo(page, button) {
|
|
135
|
+
// A page that is not there: a second press of an arrow button that reached the end with
|
|
136
|
+
// the first, before the row was rendered again and the button disabled.
|
|
137
|
+
if (page === this._currentPage() || page < 1 || page > this.pages) return;
|
|
138
|
+
|
|
139
|
+
// Where the focus is, when it is on the button at all: a click with the mouse does not
|
|
140
|
+
// put it there in every browser.
|
|
141
|
+
this._focused = this.shadowRoot.activeElement === button ? button : undefined;
|
|
142
|
+
this.page = page;
|
|
143
|
+
this.dispatch(Events.CHANGE, { page });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Keeps the focus where the user expects it after a button has changed the page. The buttons
|
|
148
|
+
* of the pages are rendered anew by their place in the row: the one that was pressed can show
|
|
149
|
+
* another page afterwards, or can be gone for an ellipsis. So the focus goes to the button of
|
|
150
|
+
* the current page. It stays on the button for the page before or after, which can be pressed
|
|
151
|
+
* again, unless that one has reached the end and is disabled now.
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
_restoreFocus() {
|
|
155
|
+
const button = this._focused;
|
|
156
|
+
if (!button) return;
|
|
157
|
+
this._focused = undefined;
|
|
158
|
+
|
|
159
|
+
const stays = !button.matches("[part~='page']") && button.isConnected && !button.disabled;
|
|
160
|
+
const target = stays ? button : this.shadowRoot.querySelector("[aria-current='page']");
|
|
161
|
+
if (this.shadowRoot.activeElement !== target) target?.focus();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The row of the pages: the numbers of the pages that are shown, and `null` in the place of
|
|
166
|
+
* pages that are left out.
|
|
167
|
+
*
|
|
168
|
+
* The row has a fixed number of places: the boundaries at both ends, the current page with its
|
|
169
|
+
* siblings in the middle, and one place between each end and the middle. That place holds an
|
|
170
|
+
* ellipsis, or the page itself when only one page is missing there. Near an end the middle
|
|
171
|
+
* does not shrink but stops, so the row is as long on the first page as on any other.
|
|
172
|
+
* @private
|
|
173
|
+
* @returns {Array<number | null>}
|
|
174
|
+
*/
|
|
175
|
+
_items() {
|
|
176
|
+
const pages = this.pages;
|
|
177
|
+
const siblings = count(this.siblings, 1);
|
|
178
|
+
const boundaries = count(this.boundaries, 1);
|
|
179
|
+
const range = (from, to) => Array.from({ length: Math.max(0, to - from + 1) }, (_, index) => from + index);
|
|
180
|
+
|
|
181
|
+
if (pages <= 2 * boundaries + 2 * siblings + 3) return range(1, pages);
|
|
182
|
+
|
|
183
|
+
const first = boundaries + 2;
|
|
184
|
+
const last = pages - boundaries - 1;
|
|
185
|
+
const from = Math.min(Math.max(this._currentPage() - siblings, first), last - 2 * siblings);
|
|
186
|
+
const to = from + 2 * siblings;
|
|
187
|
+
|
|
188
|
+
return [
|
|
189
|
+
...range(1, boundaries),
|
|
190
|
+
from === first ? first - 1 : null,
|
|
191
|
+
...range(from, to),
|
|
192
|
+
to === last ? last + 1 : null,
|
|
193
|
+
...range(last + 2, pages),
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** @private */
|
|
198
|
+
_pageTemplate(page, current) {
|
|
199
|
+
const isCurrent = page === current;
|
|
200
|
+
return html`
|
|
201
|
+
<li>
|
|
202
|
+
<button
|
|
203
|
+
part="${isCurrent ? 'button page current' : 'button page'}"
|
|
204
|
+
type="button"
|
|
205
|
+
aria-label="${this.pageLabel} ${page}"
|
|
206
|
+
aria-current="${isCurrent ? 'page' : undefined}"
|
|
207
|
+
data-page="${page}"
|
|
208
|
+
>
|
|
209
|
+
${page}
|
|
210
|
+
</button>
|
|
211
|
+
</li>
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
template() {
|
|
216
|
+
const current = this._currentPage();
|
|
217
|
+
|
|
218
|
+
return html`
|
|
219
|
+
<nav part="base" aria-label="${this.label}">
|
|
220
|
+
<ul part="list" role="list">
|
|
221
|
+
<li>
|
|
222
|
+
<button
|
|
223
|
+
part="button previous"
|
|
224
|
+
type="button"
|
|
225
|
+
aria-label="${this.previousLabel}"
|
|
226
|
+
?disabled="${current <= 1}"
|
|
227
|
+
data-step="-1"
|
|
228
|
+
>
|
|
229
|
+
<slot name="previous-icon">
|
|
230
|
+
<svg
|
|
231
|
+
viewBox="0 0 24 24"
|
|
232
|
+
fill="none"
|
|
233
|
+
stroke="currentColor"
|
|
234
|
+
stroke-width="2"
|
|
235
|
+
stroke-linecap="round"
|
|
236
|
+
stroke-linejoin="round"
|
|
237
|
+
aria-hidden="true"
|
|
238
|
+
>
|
|
239
|
+
<polyline points="15 18 9 12 15 6"></polyline>
|
|
240
|
+
</svg>
|
|
241
|
+
</slot>
|
|
242
|
+
</button>
|
|
243
|
+
</li>
|
|
244
|
+
${this._items().map((page) =>
|
|
245
|
+
page === null
|
|
246
|
+
? html`<li part="ellipsis" aria-hidden="true">…</li>`
|
|
247
|
+
: this._pageTemplate(page, current),
|
|
248
|
+
)}
|
|
249
|
+
<li>
|
|
250
|
+
<button
|
|
251
|
+
part="button next"
|
|
252
|
+
type="button"
|
|
253
|
+
aria-label="${this.nextLabel}"
|
|
254
|
+
?disabled="${current >= this.pages}"
|
|
255
|
+
data-step="1"
|
|
256
|
+
>
|
|
257
|
+
<slot name="next-icon">
|
|
258
|
+
<svg
|
|
259
|
+
viewBox="0 0 24 24"
|
|
260
|
+
fill="none"
|
|
261
|
+
stroke="currentColor"
|
|
262
|
+
stroke-width="2"
|
|
263
|
+
stroke-linecap="round"
|
|
264
|
+
stroke-linejoin="round"
|
|
265
|
+
aria-hidden="true"
|
|
266
|
+
>
|
|
267
|
+
<polyline points="9 18 15 12 9 6"></polyline>
|
|
268
|
+
</svg>
|
|
269
|
+
</slot>
|
|
270
|
+
</button>
|
|
271
|
+
</li>
|
|
272
|
+
</ul>
|
|
273
|
+
</nav>
|
|
274
|
+
`;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function define() {
|
|
279
|
+
defineElement('el-pagination', Pagination);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { Events };
|