@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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { html, defineElement, classMap } from '@webtides/element-js';
|
|
1
|
+
import { html, defineElement, classMap, spreadAttributes } from '@webtides/element-js';
|
|
2
2
|
import FormField from '../form-field/form-field.js';
|
|
3
|
+
import { shadowNativeTextEntryProperties, textEntryAttributes } from '../../utils/text-entry-attributes.js';
|
|
3
4
|
import style from './textarea-field.style.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -15,10 +16,22 @@ import style from './textarea-field.style.js';
|
|
|
15
16
|
* @property {string} placeholder - Placeholder text shown while the textarea is empty.
|
|
16
17
|
* @property {number} rows - Number of visible text rows. Forwarded to the underlying
|
|
17
18
|
* `<textarea>`'s `rows` attribute.
|
|
19
|
+
* @property {string | null} autocomplete - Passed on to the control as its `autocomplete`
|
|
20
|
+
* attribute (e.g. `'email'`, `'current-password'`, `'one-time-code'`). `null` (the default)
|
|
21
|
+
* leaves the attribute out. The same holds for the five properties below.
|
|
22
|
+
* @property {string | null} inputmode - Passed on as `inputmode`: the on-screen keyboard to show
|
|
23
|
+
* (e.g. `'numeric'`, `'email'`).
|
|
24
|
+
* @property {string | null} enterkeyhint - Passed on as `enterkeyhint`: the label of the enter key
|
|
25
|
+
* on an on-screen keyboard (e.g. `'next'`, `'send'`).
|
|
26
|
+
* @property {string | null} autocapitalize - Passed on as `autocapitalize` (e.g. `'none'`,
|
|
27
|
+
* `'sentences'`).
|
|
28
|
+
* @property {string | null} autocorrect - Passed on as `autocorrect` (`'on'` or `'off'`).
|
|
29
|
+
* @property {boolean | string | null} spellcheck - Passed on as `spellcheck` (`true` or `false`).
|
|
18
30
|
*/
|
|
19
31
|
export default class TextareaField extends FormField {
|
|
20
32
|
constructor(options) {
|
|
21
33
|
super({ shadowRender: false, styles: [style], ...options });
|
|
34
|
+
shadowNativeTextEntryProperties(this);
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
properties() {
|
|
@@ -26,33 +39,74 @@ export default class TextareaField extends FormField {
|
|
|
26
39
|
...super.properties(),
|
|
27
40
|
placeholder: '',
|
|
28
41
|
rows: 3,
|
|
42
|
+
autocomplete: null,
|
|
43
|
+
inputmode: null,
|
|
44
|
+
enterkeyhint: null,
|
|
45
|
+
autocapitalize: null,
|
|
46
|
+
autocorrect: null,
|
|
47
|
+
spellcheck: null,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
watch() {
|
|
52
|
+
const watchers = super.watch();
|
|
53
|
+
return {
|
|
54
|
+
...watchers,
|
|
55
|
+
value: (value, oldValue) => {
|
|
56
|
+
// The text of a textarea is only its default: a value set from outside has to be
|
|
57
|
+
// written to the control as well.
|
|
58
|
+
this._syncControlValue();
|
|
59
|
+
watchers.value(value, oldValue);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
events() {
|
|
65
|
+
const events = super.events();
|
|
66
|
+
return {
|
|
67
|
+
...events,
|
|
68
|
+
'[ref=input]': {
|
|
69
|
+
...events['[ref=input]'],
|
|
70
|
+
// Text arrives without a key going up as well: a paste with the mouse, dictation, a
|
|
71
|
+
// suggestion of an on-screen keyboard, a script that fills the field.
|
|
72
|
+
input: () => this.onChange(),
|
|
73
|
+
},
|
|
29
74
|
};
|
|
30
75
|
}
|
|
31
76
|
|
|
32
77
|
/** @private */
|
|
33
78
|
fieldTemplate() {
|
|
34
79
|
const classes = { 'is-valid': !!this.valid, 'is-invalid': !this.valid };
|
|
80
|
+
// The value has to follow the opening tag on the same line: element-js 1.3.1 only renders an
|
|
81
|
+
// interpolation into a textarea when the content between the tags has no line break. The
|
|
82
|
+
// formatter would put one there, so it must not touch this template.
|
|
83
|
+
// oxfmt-ignore
|
|
35
84
|
return html`
|
|
36
85
|
<textarea
|
|
37
86
|
ref="input"
|
|
38
|
-
id="
|
|
87
|
+
id="${this._idOf('input')}"
|
|
39
88
|
name="${this.name}"
|
|
40
89
|
rows="${this.rows}"
|
|
41
90
|
placeholder="${this.placeholder}"
|
|
42
91
|
?required="${this.required}"
|
|
43
92
|
?disabled="${this.disabled}"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
93
|
+
${spreadAttributes(textEntryAttributes(this))}
|
|
94
|
+
aria-describedby="${this._describedBy()}"
|
|
95
|
+
aria-invalid="${this.valid ? 'false' : 'true'}"
|
|
96
|
+
>${this.value ?? ''}</textarea>
|
|
97
|
+
${
|
|
98
|
+
this.touched
|
|
99
|
+
? html`
|
|
100
|
+
<div class="validity ${classMap(classes)}">
|
|
101
|
+
${
|
|
102
|
+
this.valid
|
|
103
|
+
? html` <span class="valid h-4 w-4">✓</span> `
|
|
104
|
+
: html` <span class="invalid h-4 w-4" data-clear-input>✗</span> `
|
|
105
|
+
}
|
|
106
|
+
</div>
|
|
107
|
+
`
|
|
108
|
+
: ''
|
|
109
|
+
}
|
|
56
110
|
`;
|
|
57
111
|
}
|
|
58
112
|
}
|
|
@@ -41,6 +41,12 @@ import '@webtides/element-library/textarea-field/define';
|
|
|
41
41
|
| `value` | `string` | `null` | The current text content of the textarea field |
|
|
42
42
|
| `placeholder` | `string` | `''` | Placeholder text displayed when the textarea is empty |
|
|
43
43
|
| `rows` | `number` | `3` | The number of visible text rows in the textarea |
|
|
44
|
+
| `autocomplete` | `string` | `null` | Passed on to the control as `autocomplete` (e.g. `email`, `current-password`, `one-time-code`) |
|
|
45
|
+
| `inputmode` | `string` | `null` | Passed on as `inputmode`: the on-screen keyboard to show (e.g. `numeric`, `email`) |
|
|
46
|
+
| `enterkeyhint` | `string` | `null` | Passed on as `enterkeyhint`: the label of the enter key on an on-screen keyboard (e.g. `next`, `send`) |
|
|
47
|
+
| `autocapitalize` | `string` | `null` | Passed on as `autocapitalize` (e.g. `none`, `sentences`) |
|
|
48
|
+
| `autocorrect` | `string` | `null` | Passed on as `autocorrect` (`on` or `off`) |
|
|
49
|
+
| `spellcheck` | `boolean` | `null` | Passed on as `spellcheck` (`true` or `false`) |
|
|
44
50
|
| `required` | `boolean` | `false` | Whether the field is required for form submission |
|
|
45
51
|
| `disabled` | `boolean` | `false` | Whether the field is disabled and cannot be interacted with |
|
|
46
52
|
| `label` | `string` | `''` | Label text displayed above the textarea field |
|
|
@@ -54,20 +60,28 @@ import '@webtides/element-library/textarea-field/define';
|
|
|
54
60
|
|
|
55
61
|
| Name | Parameters | Description |
|
|
56
62
|
| --- | --- | --- |
|
|
57
|
-
| `clearInput()` | None | Clears the textarea content, focuses the field, and resets the touched state |
|
|
63
|
+
| `clearInput()` | None | Clears the textarea content, focuses the field, and resets the touched state. `value` and `valid` follow, and `input-change` reports the empty value |
|
|
58
64
|
| `onFocus()` | None | Internal method called when textarea receives focus, updates validation state |
|
|
59
65
|
| `onBlur()` | None | Internal method called when textarea loses focus, marks field as touched and updates validation |
|
|
60
66
|
| `onChange()` | None | Internal method called when textarea content changes, updates value and validation state |
|
|
61
67
|
|
|
62
68
|
#### Events
|
|
63
69
|
|
|
64
|
-
| Name
|
|
65
|
-
|
|
|
66
|
-
| `input-change` | `value` (string) | Dispatched when the
|
|
70
|
+
| Name | Detail | Description |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `input-change` | `value` (string) | Dispatched when the text changes, however it got in: typed, pasted, dictated. Once more when the field is left after a change. Bubbles up through the DOM |
|
|
67
73
|
|
|
68
74
|
#### CSS Custom Properties
|
|
69
75
|
|
|
70
|
-
This component is headless by default and
|
|
76
|
+
This component is headless by default and shares its layout — and the `--el-*` design tokens it reads — with every field. Skin it by setting those tokens via a theme — see the Storybook _Docs / Theming_ page.
|
|
77
|
+
|
|
78
|
+
The control itself (border, radius, padding, focus ring) is decorated by `styles/native.css`, which you import beside the theme; without it the control keeps the look of the browser.
|
|
79
|
+
|
|
80
|
+
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`. The error message has the danger colour of the theme (`--el-color-danger`); without a theme it has the colour of the text.
|
|
81
|
+
|
|
82
|
+
The mark of a touched field (✓ or ✗) stands beside the textarea, at its top, in `--el-color-success` and `--el-color-danger`. The field is as high with the mark as without it, so nothing below it moves when the field is left: the line of the mark does not add to the height of the row, also where it is higher than a textarea of one row. A textarea that is as wide as the field, as `styles/native.css` makes it, gets narrower by the mark and the gap (`--el-space-2`).
|
|
83
|
+
|
|
84
|
+
On a touch screen (`@media (any-pointer: coarse)`) the textarea is at least `--el-touch-target` high, which matters for `rows="1"`, and the clear cross of an invalid field at least that wide and high. The mark beside the textarea takes that width while the field is valid too, so the textarea keeps its width when the validity changes. Without that token, and on a fine pointer, the sizes stay as they are.
|
|
71
85
|
|
|
72
86
|
#### Slots
|
|
73
87
|
|
|
@@ -75,19 +89,41 @@ _None_ - The component generates its own textarea element internally
|
|
|
75
89
|
|
|
76
90
|
## Accessibility
|
|
77
91
|
|
|
78
|
-
- Includes proper ARIA attributes (`aria-describedby`)
|
|
92
|
+
- Includes proper ARIA attributes (`aria-describedby`, `aria-invalid`)
|
|
79
93
|
- Links labels to textareas via `for` attribute
|
|
80
94
|
- Supports screen reader only labels
|
|
81
95
|
- Visual validity indicators (✓ for valid, × for invalid) appear after field is touched
|
|
82
|
-
-
|
|
96
|
+
- The error message is an alert (`role="alert"`) and part of the `aria-describedby` of the textarea while it is shown: a screen reader announces it when it appears and reads it again when the textarea gets focus
|
|
83
97
|
- Help messages are linked via `aria-describedby`
|
|
84
98
|
|
|
99
|
+
## Keyboard and autofill hints
|
|
100
|
+
|
|
101
|
+
`autocomplete`, `inputmode`, `enterkeyhint`, `autocapitalize`, `autocorrect` and `spellcheck` are passed on to the native control, in server-rendered markup as well. One that is not set is left out on the control.
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<el-textarea-field
|
|
105
|
+
name="note"
|
|
106
|
+
label="Note"
|
|
107
|
+
autocapitalize="sentences"
|
|
108
|
+
enterkeyhint="enter"
|
|
109
|
+
spellcheck="true"
|
|
110
|
+
></el-textarea-field>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Removing one of these attributes later leaves it empty (`autocomplete=""`) on the element and on the control, if it was there when the element started: element-js writes a removed attribute back empty. An empty value has the meaning of the default: on for `spellcheck` and `autocorrect`, the browser's own choice for the other four.
|
|
114
|
+
|
|
115
|
+
## Server rendering
|
|
116
|
+
|
|
117
|
+
The value is rendered as the content of the `<textarea>`. A server-rendered field therefore shows its value before the element has started, and a form submits it without JavaScript.
|
|
118
|
+
|
|
119
|
+
A line break at the very start of the value is missing until the element has started: the HTML parser drops a line break that directly follows `<textarea>`.
|
|
120
|
+
|
|
85
121
|
## Validation
|
|
86
122
|
|
|
87
123
|
The component provides real-time validation feedback:
|
|
88
124
|
|
|
89
|
-
- Validation state updates on focus, blur
|
|
90
|
-
- Visual indicators (checkmark for valid, cross for invalid) appear after the field is touched
|
|
125
|
+
- Validation state updates on focus, on blur and with every change of the text
|
|
126
|
+
- Visual indicators (checkmark for valid, cross for invalid) appear beside the textarea after the field is touched
|
|
91
127
|
- Error messages only display when field is touched and invalid
|
|
92
128
|
- Supports HTML5 validation attributes (required, disabled)
|
|
93
129
|
- Clicking the invalid indicator (×) clears the textarea content
|
|
@@ -1,7 +1,50 @@
|
|
|
1
|
+
import hostStyle from '../../styles/host.style.js';
|
|
2
|
+
import formControlStyle from '../../styles/form-control.style.js';
|
|
3
|
+
|
|
1
4
|
const css = String.raw;
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
const style = css`
|
|
4
7
|
el-textarea-field {
|
|
5
|
-
|
|
8
|
+
/* The mark of a touched field stands beside the first line of the textarea. The shared
|
|
9
|
+
layout would centre it, at a height that changes with the rows of the textarea. */
|
|
10
|
+
.field {
|
|
11
|
+
align-items: flex-start;
|
|
12
|
+
|
|
13
|
+
.validity {
|
|
14
|
+
/* At the top the whole line goes below the mark: it starts where the textarea
|
|
15
|
+
starts, and does not add to the height of the row. */
|
|
16
|
+
margin-block: 0 -1lh;
|
|
17
|
+
|
|
18
|
+
.valid {
|
|
19
|
+
color: var(--el-color-success, green);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.invalid {
|
|
23
|
+
color: var(--el-color-danger, red);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Touch screens: the control and the clear cross are at least --el-touch-target. The mark
|
|
29
|
+
beside the textarea keeps that width in both states, so the textarea does not jump when
|
|
30
|
+
the validity changes. Without the token the sizes stay as they are. */
|
|
31
|
+
@media (any-pointer: coarse) {
|
|
32
|
+
textarea {
|
|
33
|
+
min-height: var(--el-touch-target, auto);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.validity,
|
|
37
|
+
[data-clear-input] {
|
|
38
|
+
display: grid;
|
|
39
|
+
place-items: center;
|
|
40
|
+
min-width: var(--el-touch-target, auto);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[data-clear-input] {
|
|
44
|
+
min-height: var(--el-touch-target, auto);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
6
47
|
}
|
|
7
48
|
`;
|
|
49
|
+
|
|
50
|
+
export default [hostStyle('el-textarea-field'), formControlStyle('el-textarea-field'), style].join('\n');
|
|
@@ -0,0 +1,24 @@
|
|
|
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-toast`: the region of a page where toasts appear. A toast is an `el-notification`; the region gives it its place at an edge of the viewport and puts several of them into a stack. ([#72](https://github.com/webtides/element-library/issues/72))
|
|
20
|
+
- `toast(message, options)`, as a method of the element and as a function of the module: shows a text, a node or an `el-notification` as a toast and returns the notification. A text or a node becomes a notification that can be closed and leaves after five seconds; `variant`, `duration`, `closable` and `closeLabel` change that. The function uses the first `el-toast` of the document and adds one when there is none.
|
|
21
|
+
- `placement` (`top-start`, `top`, `top-end`, `bottom-start`, `bottom`, `bottom-end`), reflected. Start and end follow the reading direction. `--el-toast-inset` is the distance from the edges.
|
|
22
|
+
- `max`: no more than that many toasts show at once. The rest wait in the order they came and are shown when a place is free.
|
|
23
|
+
- While it has toasts the region is a native popover in the top layer, above everything of the page. Without toasts it is not shown. It lets the pointer through beside and between its toasts.
|
|
24
|
+
- The stack is a landmark with the name in `label`. A toast that has left is taken out of the page.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import Notification, { define as defineNotification } from '../notification/notification.js';
|
|
3
|
+
import style from './toast.style.js';
|
|
4
|
+
|
|
5
|
+
/** How long a toast stays, in milliseconds, unless it says otherwise. */
|
|
6
|
+
const DURATION = 5000;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The region of a page where toasts appear: short messages about something that has just
|
|
10
|
+
* happened, which come by themselves and leave by themselves. A toast is an `el-notification`;
|
|
11
|
+
* the region gives it its place at an edge of the viewport, puts several of them into a stack,
|
|
12
|
+
* and lets no more than `max` of them show at once. The rest wait for their turn.
|
|
13
|
+
*
|
|
14
|
+
* `toast()` shows a message, on the element or as the function of the same name that this module
|
|
15
|
+
* exports. The function uses the first `el-toast` of the page and adds one when there is none.
|
|
16
|
+
*
|
|
17
|
+
* While it has toasts the element is a native popover of the platform (`popover="manual"`), which
|
|
18
|
+
* owns the top layer: nothing of the page lies on top of a toast. Without toasts it is not shown.
|
|
19
|
+
*
|
|
20
|
+
* @element el-toast
|
|
21
|
+
*
|
|
22
|
+
* @slot - The toasts, `el-notification` elements. `toast()` puts them here.
|
|
23
|
+
*
|
|
24
|
+
* @csspart base - The stack of the toasts. It is the landmark with the name in `label`.
|
|
25
|
+
*
|
|
26
|
+
* @cssproperty --el-toast-inset - The distance of the stack from the edges of the viewport. Unset,
|
|
27
|
+
* it is `--el-space-4`.
|
|
28
|
+
*
|
|
29
|
+
* @property {'top-start'|'top'|'top-end'|'bottom-start'|'bottom'|'bottom-end'} placement - The
|
|
30
|
+
* edge of the viewport the toasts appear at, and with `-start` or `-end` the corner. Default
|
|
31
|
+
* `'top-end'`. Reflected to the `placement` attribute.
|
|
32
|
+
* @property {number} max - How many toasts show at once. The ones beyond that wait until a place
|
|
33
|
+
* is free. Default `Infinity`: no limit.
|
|
34
|
+
* @property {string} label - The name of the landmark. Default `'Notifications'`.
|
|
35
|
+
*/
|
|
36
|
+
export default class Toast extends TemplateElement {
|
|
37
|
+
constructor() {
|
|
38
|
+
super({
|
|
39
|
+
styles: [style],
|
|
40
|
+
shadowRender: true,
|
|
41
|
+
// The stylesheet selects the host by this attribute.
|
|
42
|
+
propertyOptions: {
|
|
43
|
+
placement: { reflect: true },
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The toasts that wait for a place, in the order they came.
|
|
49
|
+
* @private
|
|
50
|
+
* @type {HTMLElement[]}
|
|
51
|
+
*/
|
|
52
|
+
this._waiting = [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
properties() {
|
|
56
|
+
return {
|
|
57
|
+
placement: 'top-end',
|
|
58
|
+
max: Infinity,
|
|
59
|
+
label: 'Notifications',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
connected() {
|
|
64
|
+
// Toasts that are in the markup of the page, and toasts that came before the region was
|
|
65
|
+
// in the page.
|
|
66
|
+
this._syncTopLayer();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
watch() {
|
|
70
|
+
return {
|
|
71
|
+
max: () => this._showNext(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
events() {
|
|
76
|
+
return {
|
|
77
|
+
// What happens to a toast reaches the stack through the slot the toast is in.
|
|
78
|
+
"[part~='base']": {
|
|
79
|
+
'notification-after-hide': (event) => this._onAfterHide(event),
|
|
80
|
+
// A toast that the page has put in or taken out without `toast()`: the region
|
|
81
|
+
// may have to show or hide itself, and a place may be free.
|
|
82
|
+
slotchange: () => {
|
|
83
|
+
this._syncTopLayer();
|
|
84
|
+
this._showNext();
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Shows a message as a toast. A text, or a node for a message with markup, becomes a
|
|
92
|
+
* notification that can be closed and leaves by itself after five seconds; the options change
|
|
93
|
+
* that. An `el-notification` is shown as it is, with the options on top.
|
|
94
|
+
*
|
|
95
|
+
* A toast beyond `max` waits and is shown when a place is free.
|
|
96
|
+
* @param {string | Node} message - The text, the content, or an `el-notification`.
|
|
97
|
+
* @param {object} [options]
|
|
98
|
+
* @param {'neutral'|'brand'|'success'|'warning'|'danger'} [options.variant] - The variant of
|
|
99
|
+
* the notification.
|
|
100
|
+
* @param {number} [options.duration] - How long the toast stays, in milliseconds. `Infinity`
|
|
101
|
+
* keeps it until it is closed.
|
|
102
|
+
* @param {boolean} [options.closable] - Whether the toast has a close button.
|
|
103
|
+
* @param {string} [options.closeLabel] - The accessible label of the close button.
|
|
104
|
+
* @returns {HTMLElement} The `el-notification`: `hide()` takes it away early, and it fires
|
|
105
|
+
* the events of a notification.
|
|
106
|
+
*/
|
|
107
|
+
toast(message, options = {}) {
|
|
108
|
+
let entry = message;
|
|
109
|
+
if (!(message instanceof Notification)) {
|
|
110
|
+
defineNotification();
|
|
111
|
+
entry = Object.assign(document.createElement('el-notification'), { duration: DURATION, closable: true });
|
|
112
|
+
entry.append(message);
|
|
113
|
+
}
|
|
114
|
+
for (const name of ['variant', 'duration', 'closable', 'closeLabel']) {
|
|
115
|
+
if (options[name] !== undefined) entry[name] = options[name];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this._waiting.push(entry);
|
|
119
|
+
this._showNext();
|
|
120
|
+
return entry;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Shows the toasts that wait, as long as there is a place for them.
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
_showNext() {
|
|
128
|
+
const max = Number(this.max) >= 1 ? Number(this.max) : Infinity;
|
|
129
|
+
while (this._waiting.length > 0 && this.childElementCount < max) {
|
|
130
|
+
const entry = this._waiting.shift();
|
|
131
|
+
this.append(entry);
|
|
132
|
+
this._syncTopLayer({ toFront: true });
|
|
133
|
+
entry.show();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Has the region in the top layer while it has toasts, and out of it without: an empty region
|
|
139
|
+
* is nothing to see and no landmark to stop at.
|
|
140
|
+
*
|
|
141
|
+
* The top layer is a stack: what is opened later lies above. A region that is shown already
|
|
142
|
+
* would have its next toast below a dialog that was opened in the meantime, so a new toast
|
|
143
|
+
* takes the region out and puts it in again, which is on top. Both happen before the browser
|
|
144
|
+
* paints.
|
|
145
|
+
* @private
|
|
146
|
+
* @param {object} [options]
|
|
147
|
+
* @param {boolean} [options.toFront] - Whether a region that is shown comes to the front.
|
|
148
|
+
*/
|
|
149
|
+
_syncTopLayer({ toFront = false } = {}) {
|
|
150
|
+
if (!this.isConnected) return;
|
|
151
|
+
if (!this.hasAttribute('popover')) this.setAttribute('popover', 'manual');
|
|
152
|
+
|
|
153
|
+
const wanted = this.childElementCount > 0;
|
|
154
|
+
const shown = this.matches(':popover-open');
|
|
155
|
+
if (shown && (!wanted || toFront)) this.hidePopover();
|
|
156
|
+
if (wanted && (!shown || toFront)) this.showPopover();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A toast has left: it goes out of the page, and the next one that waits gets its place.
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
_onAfterHide(event) {
|
|
164
|
+
const entry = event.target;
|
|
165
|
+
if (entry.parentElement !== this) return;
|
|
166
|
+
|
|
167
|
+
entry.remove();
|
|
168
|
+
this._syncTopLayer();
|
|
169
|
+
this._showNext();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
template() {
|
|
173
|
+
return html`<div part="base" class="stack" role="region" aria-label="${this.label}"><slot></slot></div>`;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function define() {
|
|
178
|
+
defineElement('el-toast', Toast);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Shows a message as a toast in the region of the page: the first `el-toast` of the document. A
|
|
183
|
+
* page without one gets one at the end of its body, with the defaults. For the arguments see
|
|
184
|
+
* `toast()` of the element.
|
|
185
|
+
* @param {string | Node} message
|
|
186
|
+
* @param {object} [options]
|
|
187
|
+
* @returns {HTMLElement} The `el-notification`.
|
|
188
|
+
*/
|
|
189
|
+
export function toast(message, options = {}) {
|
|
190
|
+
define();
|
|
191
|
+
const region = document.querySelector('el-toast') ?? document.body.appendChild(document.createElement('el-toast'));
|
|
192
|
+
return region.toast(message, options);
|
|
193
|
+
}
|