@mcp-b/web-components 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/accordion-B1Q3kuP_.d.ts +373 -0
- package/dist/accordion-item-DvPfhpm8.js +307 -0
- package/dist/accordion-item-bPRIahNn.d.ts +63 -0
- package/dist/accordion-zDr-Br4V.js +483 -0
- package/dist/action-bar-CYsjmhwP.d.ts +29 -0
- package/dist/action-bar-CjN_UcnP.js +56 -0
- package/dist/alert-dialog-4CnO3Nb5.d.ts +60 -0
- package/dist/alert-dialog-D25Oi_TS.js +126 -0
- package/dist/avatar-Bje_KpZo.d.ts +141 -0
- package/dist/avatar-CRP0kW3x.js +224 -0
- package/dist/badge-Ct95U4UO.js +301 -0
- package/dist/badge-D1DNQrWn.d.ts +106 -0
- package/dist/breadcrumb-BxZ-nQE5.d.ts +365 -0
- package/dist/breadcrumb-item-BC454oQe.d.ts +59 -0
- package/dist/breadcrumb-item-P5pdq_gE.js +151 -0
- package/dist/breadcrumb-uURhiqWJ.js +384 -0
- package/dist/button-5k_aL_gD.js +802 -0
- package/dist/button-BQofnUt4.d.ts +354 -0
- package/dist/button-group-BydvJTQy.js +197 -0
- package/dist/button-group-COodHeuB.d.ts +155 -0
- package/dist/callout-B8zTf8Go.js +188 -0
- package/dist/callout-DFwPao36.d.ts +103 -0
- package/dist/card-BYDzdMAU.d.ts +177 -0
- package/dist/card-DIg1-X2G.js +332 -0
- package/dist/carousel-Bktu7wrD.js +843 -0
- package/dist/carousel-DQITCtEY.d.ts +423 -0
- package/dist/carousel-item-B5-X31Ha.js +79 -0
- package/dist/carousel-item-BB3jL2tk.d.ts +34 -0
- package/dist/cdn/loader.js +530 -0
- package/dist/checkbox-D6r7PVPj.js +641 -0
- package/dist/checkbox-DoFcDEKB.d.ts +354 -0
- package/dist/checkbox-group-CLvNAO_F.js +201 -0
- package/dist/checkbox-group-Cnh8rAn4.d.ts +152 -0
- package/dist/color-input-Bky89xg_.d.ts +470 -0
- package/dist/color-input-DPIxi9wR.js +894 -0
- package/dist/color-picker-adwOmtRl.js +1240 -0
- package/dist/color-picker-wQw8bPsq.d.ts +360 -0
- package/dist/combobox-B6al50UG.js +1693 -0
- package/dist/combobox-item-D2H1CMxC.d.ts +714 -0
- package/dist/combobox-item-yM6tDrGG.js +225 -0
- package/dist/comparison-B1-nMwmp.d.ts +134 -0
- package/dist/comparison-CyqKrCN-.js +435 -0
- package/dist/components/accordion/accordion.d.ts +2 -0
- package/dist/components/accordion/accordion.js +2 -0
- package/dist/components/accordion-item/accordion-item.d.ts +2 -0
- package/dist/components/accordion-item/accordion-item.js +2 -0
- package/dist/components/action-bar/action-bar.d.ts +2 -0
- package/dist/components/action-bar/action-bar.js +2 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +2 -0
- package/dist/components/alert-dialog/alert-dialog.js +2 -0
- package/dist/components/avatar/avatar.d.ts +2 -0
- package/dist/components/avatar/avatar.js +2 -0
- package/dist/components/badge/badge.d.ts +2 -0
- package/dist/components/badge/badge.js +2 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +2 -0
- package/dist/components/breadcrumb/breadcrumb.js +2 -0
- package/dist/components/breadcrumb-item/breadcrumb-item.d.ts +2 -0
- package/dist/components/breadcrumb-item/breadcrumb-item.js +2 -0
- package/dist/components/button/button.d.ts +2 -0
- package/dist/components/button/button.js +2 -0
- package/dist/components/button-group/button-group.d.ts +2 -0
- package/dist/components/button-group/button-group.js +2 -0
- package/dist/components/callout/callout.d.ts +2 -0
- package/dist/components/callout/callout.js +2 -0
- package/dist/components/card/card.d.ts +2 -0
- package/dist/components/card/card.js +2 -0
- package/dist/components/carousel/carousel.d.ts +2 -0
- package/dist/components/carousel/carousel.js +2 -0
- package/dist/components/carousel-item/carousel-item.d.ts +2 -0
- package/dist/components/carousel-item/carousel-item.js +2 -0
- package/dist/components/checkbox/checkbox.d.ts +2 -0
- package/dist/components/checkbox/checkbox.js +2 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +2 -0
- package/dist/components/checkbox-group/checkbox-group.js +2 -0
- package/dist/components/color-input/color-input.d.ts +2 -0
- package/dist/components/color-input/color-input.js +2 -0
- package/dist/components/color-picker/color-picker.d.ts +2 -0
- package/dist/components/color-picker/color-picker.js +2 -0
- package/dist/components/combobox/combobox.d.ts +2 -0
- package/dist/components/combobox/combobox.js +2 -0
- package/dist/components/combobox-item/combobox-item.d.ts +2 -0
- package/dist/components/combobox-item/combobox-item.js +2 -0
- package/dist/components/comparison/comparison.d.ts +2 -0
- package/dist/components/comparison/comparison.js +2 -0
- package/dist/components/copy/copy.d.ts +2 -0
- package/dist/components/copy/copy.js +291 -0
- package/dist/components/data-table/data-table.d.ts +2 -0
- package/dist/components/data-table/data-table.js +2 -0
- package/dist/components/date/date.d.ts +2 -0
- package/dist/components/date/date.js +2 -0
- package/dist/components/dialog/dialog.d.ts +2 -0
- package/dist/components/dialog/dialog.js +2 -0
- package/dist/components/divider/divider.d.ts +2 -0
- package/dist/components/divider/divider.js +2 -0
- package/dist/components/dropdown/dropdown.d.ts +2 -0
- package/dist/components/dropdown/dropdown.js +2 -0
- package/dist/components/dropdown-item/dropdown-item.d.ts +2 -0
- package/dist/components/dropdown-item/dropdown-item.js +2 -0
- package/dist/components/empty-result/empty-result.d.ts +2 -0
- package/dist/components/empty-result/empty-result.js +2 -0
- package/dist/components/empty-state/empty-state.d.ts +2 -0
- package/dist/components/empty-state/empty-state.js +2 -0
- package/dist/components/expander/expander.d.ts +2 -0
- package/dist/components/expander/expander.js +2 -0
- package/dist/components/field/field.d.ts +2 -0
- package/dist/components/field/field.js +2 -0
- package/dist/components/file-input/file-input.d.ts +2 -0
- package/dist/components/file-input/file-input.js +2 -0
- package/dist/components/filter-bar/filter-bar.d.ts +2 -0
- package/dist/components/filter-bar/filter-bar.js +2 -0
- package/dist/components/form-section/form-section.d.ts +2 -0
- package/dist/components/form-section/form-section.js +2 -0
- package/dist/components/icon/icon.d.ts +2 -0
- package/dist/components/icon/icon.js +2 -0
- package/dist/components/include/include.d.ts +2 -0
- package/dist/components/include/include.js +2 -0
- package/dist/components/index.d.ts +85 -0
- package/dist/components/index.js +86 -0
- package/dist/components/infinite-scroller/infinite-scroller.d.ts +2 -0
- package/dist/components/infinite-scroller/infinite-scroller.js +2 -0
- package/dist/components/intersection-observer/intersection-observer.d.ts +2 -0
- package/dist/components/intersection-observer/intersection-observer.js +2 -0
- package/dist/components/listbox/listbox.d.ts +2 -0
- package/dist/components/listbox/listbox.js +2 -0
- package/dist/components/listbox-item/listbox-item.d.ts +2 -0
- package/dist/components/listbox-item/listbox-item.js +2 -0
- package/dist/components/lorem-ipsum/lorem-ipsum.d.ts +2 -0
- package/dist/components/lorem-ipsum/lorem-ipsum.js +2 -0
- package/dist/components/meter/meter.d.ts +2 -0
- package/dist/components/meter/meter.js +2 -0
- package/dist/components/metric/metric.d.ts +2 -0
- package/dist/components/metric/metric.js +2 -0
- package/dist/components/metric-grid/metric-grid.d.ts +2 -0
- package/dist/components/metric-grid/metric-grid.js +2 -0
- package/dist/components/mutation-observer/mutation-observer.d.ts +2 -0
- package/dist/components/mutation-observer/mutation-observer.js +2 -0
- package/dist/components/navicon/navicon.d.ts +2 -0
- package/dist/components/navicon/navicon.js +2 -0
- package/dist/components/number/number.d.ts +2 -0
- package/dist/components/number/number.js +2 -0
- package/dist/components/number-field/number-field.d.ts +2 -0
- package/dist/components/number-field/number-field.js +2 -0
- package/dist/components/pagination/pagination.d.ts +2 -0
- package/dist/components/pagination/pagination.js +2 -0
- package/dist/components/popover/popover.d.ts +2 -0
- package/dist/components/popover/popover.js +2 -0
- package/dist/components/preview-card/preview-card.d.ts +2 -0
- package/dist/components/preview-card/preview-card.js +2 -0
- package/dist/components/progress/progress.d.ts +2 -0
- package/dist/components/progress/progress.js +2 -0
- package/dist/components/radio/radio.d.ts +2 -0
- package/dist/components/radio/radio.js +2 -0
- package/dist/components/radio-item/radio-item.d.ts +2 -0
- package/dist/components/radio-item/radio-item.js +2 -0
- package/dist/components/random-content/random-content.d.ts +2 -0
- package/dist/components/random-content/random-content.js +2 -0
- package/dist/components/rating/rating.d.ts +2 -0
- package/dist/components/rating/rating.js +2 -0
- package/dist/components/resize-observer/resize-observer.d.ts +2 -0
- package/dist/components/resize-observer/resize-observer.js +2 -0
- package/dist/components/scroll-area/scroll-area.d.ts +2 -0
- package/dist/components/scroll-area/scroll-area.js +2 -0
- package/dist/components/scroller/scroller.d.ts +2 -0
- package/dist/components/scroller/scroller.js +2 -0
- package/dist/components/search-list/search-list.d.ts +2 -0
- package/dist/components/search-list/search-list.js +2 -0
- package/dist/components/select/select.d.ts +2 -0
- package/dist/components/select/select.js +2 -0
- package/dist/components/selection-summary/selection-summary.d.ts +2 -0
- package/dist/components/selection-summary/selection-summary.js +2 -0
- package/dist/components/share/share.d.ts +2 -0
- package/dist/components/share/share.js +2 -0
- package/dist/components/slide-activator/slide-activator.d.ts +2 -0
- package/dist/components/slide-activator/slide-activator.js +2 -0
- package/dist/components/slider/slider.d.ts +2 -0
- package/dist/components/slider/slider.js +2 -0
- package/dist/components/sparkline/sparkline.d.ts +2 -0
- package/dist/components/sparkline/sparkline.js +2 -0
- package/dist/components/spinner/spinner.d.ts +2 -0
- package/dist/components/spinner/spinner.js +2 -0
- package/dist/components/splitter/splitter.d.ts +2 -0
- package/dist/components/splitter/splitter.js +2 -0
- package/dist/components/switch/switch.d.ts +2 -0
- package/dist/components/switch/switch.js +2 -0
- package/dist/components/tab/tab.d.ts +2 -0
- package/dist/components/tab/tab.js +2 -0
- package/dist/components/tab-list/tab-list.d.ts +2 -0
- package/dist/components/tab-list/tab-list.js +2 -0
- package/dist/components/tab-panel/tab-panel.d.ts +2 -0
- package/dist/components/tab-panel/tab-panel.js +2 -0
- package/dist/components/text-area/text-area.d.ts +2 -0
- package/dist/components/text-area/text-area.js +2 -0
- package/dist/components/text-field/text-field.d.ts +2 -0
- package/dist/components/text-field/text-field.js +2 -0
- package/dist/components/text-mask/text-mask.d.ts +2 -0
- package/dist/components/text-mask/text-mask.js +2 -0
- package/dist/components/timed-content/timed-content.d.ts +2 -0
- package/dist/components/timed-content/timed-content.js +2 -0
- package/dist/components/toast/toast.d.ts +2 -0
- package/dist/components/toast/toast.js +2 -0
- package/dist/components/toast-item/toast-item.d.ts +2 -0
- package/dist/components/toast-item/toast-item.js +2 -0
- package/dist/components/toggle-icon/toggle-icon.d.ts +2 -0
- package/dist/components/toggle-icon/toggle-icon.js +2 -0
- package/dist/components/toggle-tag/toggle-tag.d.ts +2 -0
- package/dist/components/toggle-tag/toggle-tag.js +2 -0
- package/dist/components/toolbar/toolbar.d.ts +2 -0
- package/dist/components/toolbar/toolbar.js +2 -0
- package/dist/components/tooltip/tooltip.d.ts +2 -0
- package/dist/components/tooltip/tooltip.js +2 -0
- package/dist/components/transition-group/transition-group.d.ts +2 -0
- package/dist/components/transition-group/transition-group.js +2 -0
- package/dist/components/zoomable-frame/zoomable-frame.d.ts +2 -0
- package/dist/components/zoomable-frame/zoomable-frame.js +2 -0
- package/dist/copy-CvC9vaGw.d.ts +206 -0
- package/dist/copy.styles-DWGvGNTP.js +100 -0
- package/dist/data-table-CITa8DSn.js +247 -0
- package/dist/data-table-DL5RhE0d.d.ts +89 -0
- package/dist/date-CJPmOdi9.js +146 -0
- package/dist/date-DtaTBM71.d.ts +142 -0
- package/dist/decorate-DcF3lt7P.js +9 -0
- package/dist/dialog-Cx46HMaZ.js +983 -0
- package/dist/dialog-N-v0woIy.d.ts +414 -0
- package/dist/divider-9vNsfHW8.js +169 -0
- package/dist/divider-DWuAxcXv.d.ts +79 -0
- package/dist/docs/custom-elements.json +29301 -0
- package/dist/dropdown-BXSKpVX9.js +1123 -0
- package/dist/dropdown-Bo00Vlr5.d.ts +537 -0
- package/dist/dropdown-item-_lIs-Tfd.d.ts +111 -0
- package/dist/dropdown-item-i77cRuN6.js +504 -0
- package/dist/empty-result-B2ln1yFL.js +65 -0
- package/dist/empty-result-B54x_Ab2.d.ts +31 -0
- package/dist/empty-state-BLWjtKUo.js +186 -0
- package/dist/empty-state-SGKjpwp3.d.ts +117 -0
- package/dist/expander-BUev0BmM.d.ts +174 -0
- package/dist/expander-Bwvxj6Oa.js +342 -0
- package/dist/field-BEyS909F.js +163 -0
- package/dist/field-ITx0jVw-.d.ts +69 -0
- package/dist/file-input-BEumLJjg.js +841 -0
- package/dist/file-input-D2D6YC0B.d.ts +378 -0
- package/dist/filter-bar-Bj2QzEn9.d.ts +35 -0
- package/dist/filter-bar-Dcs67aXo.js +66 -0
- package/dist/form-section-BchPetkj.js +83 -0
- package/dist/form-section-xFBTBULQ.d.ts +34 -0
- package/dist/icon-BPVkNsY4.js +165 -0
- package/dist/icon-Ci9CPZJV.d.ts +72 -0
- package/dist/icon-library-D_if7p2h.d.ts +2 -0
- package/dist/include-CQHVVtNs.d.ts +103 -0
- package/dist/include-qNUh_6kT.js +155 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +92 -0
- package/dist/infinite-scroller-BmmtnWNt.js +285 -0
- package/dist/infinite-scroller-CuUEAlB9.d.ts +174 -0
- package/dist/intersection-observer-B6TciOAQ.js +503 -0
- package/dist/intersection-observer-B7nmP7Zz.d.ts +418 -0
- package/dist/listbox-C3XXRWGX.js +1257 -0
- package/dist/listbox-DD4ujIJe.d.ts +682 -0
- package/dist/listbox-item-CwD9s3VY.js +135 -0
- package/dist/listbox-item-DQEJWp4Z.d.ts +53 -0
- package/dist/localize-322EtXNX.d.ts +66 -0
- package/dist/lorem-ipsum-B2x3V-v8.js +198 -0
- package/dist/lorem-ipsum-CR82CSuJ.d.ts +130 -0
- package/dist/meter-BC7uaJWf.d.ts +73 -0
- package/dist/meter-BIDyjwFp.js +155 -0
- package/dist/metric-CjlLq_VA.d.ts +36 -0
- package/dist/metric-DbuOcDp_.js +86 -0
- package/dist/metric-grid-C2Pb0Zl3.js +37 -0
- package/dist/metric-grid-C5Xbb1_0.d.ts +27 -0
- package/dist/mutation-observer-BmrZ-GER.d.ts +326 -0
- package/dist/mutation-observer-DS8EBuOp.js +388 -0
- package/dist/navicon-Dic5Qjzb.d.ts +159 -0
- package/dist/navicon-_yMHY27-.js +486 -0
- package/dist/number-BNtNXNF3.js +162 -0
- package/dist/number-BwbnErlB.d.ts +143 -0
- package/dist/number-field-BQHB7UYo.js +726 -0
- package/dist/number-field-odk4lKXM.d.ts +422 -0
- package/dist/pagination-6z2qcf3U.d.ts +322 -0
- package/dist/pagination-DuKPuzdb.js +679 -0
- package/dist/popover-D0sxTU6o.d.ts +259 -0
- package/dist/popover-DJBrJ0za.js +556 -0
- package/dist/preview-card-C7H1FPfd.js +287 -0
- package/dist/preview-card-DitOCZTD.d.ts +86 -0
- package/dist/progress-Db0_axHQ.d.ts +181 -0
- package/dist/progress-DzVk260j.js +494 -0
- package/dist/radio-BtDG9xJM.js +658 -0
- package/dist/radio-CieMa4zU.d.ts +460 -0
- package/dist/radio-item-DIrUStAX.js +264 -0
- package/dist/radio-item-Xq2U3cMu.d.ts +69 -0
- package/dist/random-content-BhSeJFKz.d.ts +380 -0
- package/dist/random-content-BwiirXdG.js +450 -0
- package/dist/rating-4xNsWumY.d.ts +369 -0
- package/dist/rating-C1BcJDIO.js +722 -0
- package/dist/resize-observer-BseSbVWP.d.ts +187 -0
- package/dist/resize-observer-DcrLhddo.js +236 -0
- package/dist/scroll-area-COc1857S.js +127 -0
- package/dist/scroll-area-CVYDf5qY.d.ts +61 -0
- package/dist/scroller-LYgBVyfY.js +590 -0
- package/dist/scroller-bB2rGs7b.d.ts +374 -0
- package/dist/search-list-Clmrg8EV.js +884 -0
- package/dist/search-list-n0GYO7rh.d.ts +777 -0
- package/dist/select-CkZK2jJn.d.ts +506 -0
- package/dist/select-DLIaRnA4.js +690 -0
- package/dist/selection-summary-BVnNJ8Lw.js +48 -0
- package/dist/selection-summary-DmFkGyZI.d.ts +34 -0
- package/dist/share-DPlqP2dc.d.ts +162 -0
- package/dist/share-bsgXZCl7.js +250 -0
- package/dist/sigvelo.d.ts +5 -0
- package/dist/sigvelo.js +5 -0
- package/dist/sigvelo.loader.d.ts +3 -0
- package/dist/sigvelo.loader.js +102 -0
- package/dist/slide-activator-D7bBz69E.d.ts +429 -0
- package/dist/slide-activator-DlxQt9R9.js +798 -0
- package/dist/slider-B0FVsV1o.d.ts +921 -0
- package/dist/slider-B90Il7x3.js +1744 -0
- package/dist/sparkline-CcpTaJ_Z.js +358 -0
- package/dist/sparkline-DlCIt81-.d.ts +235 -0
- package/dist/spinner-C04Dmc0H.js +188 -0
- package/dist/spinner-CZ19x_dC.d.ts +99 -0
- package/dist/splitter-DBDJAzsp.d.ts +325 -0
- package/dist/splitter-MnD4In9H.js +638 -0
- package/dist/switch-CPaEKbog.js +581 -0
- package/dist/switch-Cief9M59.d.ts +248 -0
- package/dist/tab-BcqYGsuW.d.ts +44 -0
- package/dist/tab-C-FtuNmh.js +102 -0
- package/dist/tab-list-B_Ye_Oj9.js +691 -0
- package/dist/tab-list-DDvS8qHr.d.ts +450 -0
- package/dist/tab-panel-BaBl6eep.js +60 -0
- package/dist/tab-panel-BzSJlSfd.d.ts +38 -0
- package/dist/text-area-B_mjCE9W.d.ts +327 -0
- package/dist/text-area-Czixaz-_.js +556 -0
- package/dist/text-field-BClWMp6q.d.ts +424 -0
- package/dist/text-field-inpJfp0A.js +687 -0
- package/dist/text-mask-CNKVKSFp.d.ts +336 -0
- package/dist/text-mask-DDEurj90.js +370 -0
- package/dist/themes/sigvelo.css +10 -0
- package/dist/themes/utilities.css +9 -0
- package/dist/timed-content-D2mGFamc.d.ts +181 -0
- package/dist/timed-content-pvEP4l5V.js +226 -0
- package/dist/toast-BnZaIg6Z.js +636 -0
- package/dist/toast-cEBVK9NQ.d.ts +487 -0
- package/dist/toast-item-BPpJT6vD.d.ts +159 -0
- package/dist/toast-item-IS8IFUEg.js +372 -0
- package/dist/toggle-icon-4oLDeEt4.js +752 -0
- package/dist/toggle-icon-DlwMMWZL.d.ts +359 -0
- package/dist/toggle-tag-1sfTFJtg.js +434 -0
- package/dist/toggle-tag-IVvMGT4R.d.ts +245 -0
- package/dist/toolbar-CABq0ZL1.d.ts +122 -0
- package/dist/toolbar-CEZ0-F-X.js +196 -0
- package/dist/tooltip-DbyoPFNe.js +521 -0
- package/dist/tooltip-ahFthek8.d.ts +192 -0
- package/dist/transition-group-3hnAnwSd.js +801 -0
- package/dist/transition-group-DD_CjSNC.d.ts +608 -0
- package/dist/translations/en.d.ts +6 -0
- package/dist/translations/en.js +75 -0
- package/dist/translations/es.d.ts +6 -0
- package/dist/translations/es.js +75 -0
- package/dist/types/custom-element-jsx.d.ts +13723 -0
- package/dist/utilities/icon-library.d.ts +3 -0
- package/dist/utilities/icon-library.js +93 -0
- package/dist/utilities/localize.d.ts +2 -0
- package/dist/utilities/localize.js +6 -0
- package/dist/zoomable-frame-Cldvj5sE.js +398 -0
- package/dist/zoomable-frame-r6S6587z.d.ts +162 -0
- package/package.json +83 -0
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
import { Localize } from "./utilities/localize.js";
|
|
2
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
3
|
+
import { css, html } from "lit";
|
|
4
|
+
import { property, query, state } from "lit/decorators.js";
|
|
5
|
+
import hostStyles from "@mcp-b/wc-support/styles/host.styles";
|
|
6
|
+
import { SigveloFormControlElement } from "@mcp-b/wc-support/base/sigvelo-element";
|
|
7
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
8
|
+
import { SigveloBlurEvent, SigveloChangeEvent, SigveloFocusEvent, SigveloInputEvent } from "@mcp-b/wc-support/events/form";
|
|
9
|
+
import formControlStyles from "@mcp-b/wc-support/styles/form-control.styles";
|
|
10
|
+
import { DraggableElement } from "@mcp-b/wc-support/utilities/drag";
|
|
11
|
+
import { clamp } from "@mcp-b/wc-support/utilities/math";
|
|
12
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
13
|
+
//#region src/components/rating/rating.styles.ts
|
|
14
|
+
var rating_styles_default = css`
|
|
15
|
+
:host {
|
|
16
|
+
--active-color: #f59e0b;
|
|
17
|
+
--inactive-color: var(--sigvelo-color-neutral-bg);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#rating {
|
|
21
|
+
display: inline-flex;
|
|
22
|
+
position: relative;
|
|
23
|
+
align-items: center;
|
|
24
|
+
width: fit-content;
|
|
25
|
+
gap: 0.0625em;
|
|
26
|
+
border-radius: var(--sigvelo-radius-md);
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
touch-action: none;
|
|
29
|
+
|
|
30
|
+
&:focus {
|
|
31
|
+
outline: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:focus-visible {
|
|
35
|
+
outline: var(--sigvelo-focus-ring);
|
|
36
|
+
outline-offset: var(--sigvelo-focus-offset);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.disabled {
|
|
40
|
+
cursor: not-allowed;
|
|
41
|
+
opacity: 0.5;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.readonly {
|
|
45
|
+
cursor: default;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Sizes */
|
|
49
|
+
&.xs {
|
|
50
|
+
font-size: calc(var(--sigvelo-control-text-xs) * 1.5);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&.sm {
|
|
54
|
+
font-size: calc(var(--sigvelo-control-text-sm) * 1.5);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&.md {
|
|
58
|
+
font-size: calc(var(--sigvelo-control-text-md) * 1.5);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&.lg {
|
|
62
|
+
font-size: calc(var(--sigvelo-control-text-lg) * 1.5);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&.xl {
|
|
66
|
+
font-size: calc(var(--sigvelo-control-text-xl) * 1.5);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.symbol {
|
|
71
|
+
display: inline-flex;
|
|
72
|
+
position: relative;
|
|
73
|
+
align-items: center;
|
|
74
|
+
transition:
|
|
75
|
+
var(--sigvelo-motion-duration-interaction) color ease,
|
|
76
|
+
var(--sigvelo-motion-duration-interaction) scale ease,
|
|
77
|
+
var(--sigvelo-motion-duration-interaction) translate ease;
|
|
78
|
+
|
|
79
|
+
> :first-child,
|
|
80
|
+
> :last-child {
|
|
81
|
+
transition: inherit;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Selected symbols */
|
|
85
|
+
> :first-child {
|
|
86
|
+
position: absolute;
|
|
87
|
+
top: 0;
|
|
88
|
+
left: 0;
|
|
89
|
+
width: 100%;
|
|
90
|
+
height: 100%;
|
|
91
|
+
color: var(--active-color);
|
|
92
|
+
clip-path: inset(0 calc(100% - var(--clip-percentage)) 0 0);
|
|
93
|
+
|
|
94
|
+
&:dir(rtl) {
|
|
95
|
+
clip-path: inset(0 0 0 calc(100% - var(--clip-percentage)));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* Unselected symbols */
|
|
100
|
+
> :last-child {
|
|
101
|
+
color: var(--inactive-color);
|
|
102
|
+
clip-path: inset(0 0 0 var(--clip-percentage));
|
|
103
|
+
|
|
104
|
+
&:dir(rtl) {
|
|
105
|
+
clip-path: inset(0 var(--clip-percentage) 0 0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#rating:not(.disabled, .readonly) .symbol {
|
|
111
|
+
@media (hover: hover) {
|
|
112
|
+
&:hover {
|
|
113
|
+
scale: 1.2;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&:hover:active {
|
|
117
|
+
translate: 0 var(--sigvelo-motion-distance-xs);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/components/rating/rating.ts
|
|
124
|
+
const nativeFileInput = document.createElement("input");
|
|
125
|
+
nativeFileInput.name = "sigvelo-faux-input";
|
|
126
|
+
nativeFileInput.type = "text";
|
|
127
|
+
nativeFileInput.required = true;
|
|
128
|
+
const VALIDATION_MESSAGE = nativeFileInput.validationMessage;
|
|
129
|
+
/**
|
|
130
|
+
* <sigvelo-rating>
|
|
131
|
+
*
|
|
132
|
+
* @summary Allows users to provide feedback based on their satisfaction with a product or service.
|
|
133
|
+
* @tag sigvelo-rating
|
|
134
|
+
* @documentation https://design-system.sigvelo.com/docs/components/rating
|
|
135
|
+
* @status stable
|
|
136
|
+
* @since 1.0
|
|
137
|
+
*
|
|
138
|
+
* @slot label - The rating's label. For plain-text labels, you can use the `label` attribute instead.
|
|
139
|
+
* @slot description - The rating's description. For plain-text descriptions, you can use the `description` attribute
|
|
140
|
+
* instead.
|
|
141
|
+
*
|
|
142
|
+
* @event sigvelo-blur - Emitted when the rating loses focus. This event does not bubble.
|
|
143
|
+
* @event sigvelo-change - Emitted when the user commits changes to the rating's value.
|
|
144
|
+
* @event sigvelo-focus - Emitted when the rating receives focus. This event does not bubble.
|
|
145
|
+
* @event sigvelo-input - Emitted when the rating receives input.
|
|
146
|
+
*
|
|
147
|
+
* @csspart label - The element that contains the ratings's label.
|
|
148
|
+
* @csspart description - The element that contains the rating's description.
|
|
149
|
+
* @csspart rating - The element that wraps all of the rating's symbols.
|
|
150
|
+
* @csspart symbol - The container that holds the selected and unselected version of each symbol.
|
|
151
|
+
*
|
|
152
|
+
* @cssstate disabled - Applied when the rating is disabled.
|
|
153
|
+
* @cssstate focused - Applied when the rating has focus.
|
|
154
|
+
* @cssstate user-valid - Applied when the rating is valid and the user has sufficiently interacted with it.
|
|
155
|
+
* @cssstate user-invalid - Applied when the rating is invalid and the user has sufficiently interacted with it.
|
|
156
|
+
*
|
|
157
|
+
* @example Default
|
|
158
|
+
* ```html
|
|
159
|
+
* <sigvelo-rating
|
|
160
|
+
* label="Rate my cat"
|
|
161
|
+
* description="Leave her some stars."
|
|
162
|
+
* name="cat"
|
|
163
|
+
* value="4"
|
|
164
|
+
* >
|
|
165
|
+
* </sigvelo-rating>
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example Labels and descriptions
|
|
169
|
+
* You can use the `label` and `description` attributes to provide plain text labels and descriptions for the rating. If you want to provide HTML, use the `label` and `description` slots instead.
|
|
170
|
+
*
|
|
171
|
+
* ```html
|
|
172
|
+
* <sigvelo-rating name="name" label="How would you rate our catnip?">
|
|
173
|
+
* <span slot="description">
|
|
174
|
+
* For details, please <a href="https://example.com/" target="_blank">visit our website</a>.
|
|
175
|
+
* </span>
|
|
176
|
+
* </sigvelo-rating>
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example Providing an initial value
|
|
180
|
+
* Use the `value` attribute to provide an initial value for the rating.
|
|
181
|
+
*
|
|
182
|
+
* ```html
|
|
183
|
+
* <sigvelo-rating
|
|
184
|
+
* name="food"
|
|
185
|
+
* label="Food quality"
|
|
186
|
+
* value="3"
|
|
187
|
+
* ></sigvelo-rating>
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @example Changing the scale
|
|
191
|
+
* Ratings use a scale of 1–5 by default. You can change this by setting the `max` attribute.
|
|
192
|
+
*
|
|
193
|
+
* ```html
|
|
194
|
+
* <sigvelo-rating
|
|
195
|
+
* name="litter"
|
|
196
|
+
* label="Cleanliness of litter box area"
|
|
197
|
+
* max="3"
|
|
198
|
+
* value="3"
|
|
199
|
+
* ></sigvelo-rating>
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @example Fractional values
|
|
203
|
+
* You can enable fractional values by setting the `step` attribute. For example, `0.5` will allow half-star ratings.
|
|
204
|
+
*
|
|
205
|
+
* ```html
|
|
206
|
+
* <sigvelo-rating
|
|
207
|
+
* name="stars"
|
|
208
|
+
* label="Half-stars are fine"
|
|
209
|
+
* step=".5"
|
|
210
|
+
* value="2.5"
|
|
211
|
+
* ></sigvelo-rating>
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @example Changing the size
|
|
215
|
+
* Use the `size` attribute to change the rating's size.
|
|
216
|
+
*
|
|
217
|
+
* ```html
|
|
218
|
+
* <sigvelo-rating size="xs" label="Extra small"></sigvelo-rating><br>
|
|
219
|
+
* <sigvelo-rating size="sm" label="Small"></sigvelo-rating><br>
|
|
220
|
+
* <sigvelo-rating size="md" label="Medium"></sigvelo-rating><br>
|
|
221
|
+
* <sigvelo-rating size="lg" label="Large"></sigvelo-rating><br>
|
|
222
|
+
* <sigvelo-rating size="xl" label="Extra large"></sigvelo-rating>
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @example Using custom symbols
|
|
226
|
+
* To customize the symbols shown, use JavaScript to set the `symbolFormatter` property to a function that returns the HTML for each symbol. The function will receive the `value` and `isSelected` arguments that you can use to customize the symbol based on specific values or whether the symbol is in the selected state.
|
|
227
|
+
*
|
|
228
|
+
* ```html
|
|
229
|
+
* <sigvelo-rating
|
|
230
|
+
* label="Show some love"
|
|
231
|
+
* id="rating__custom-symbols"
|
|
232
|
+
* value="3"
|
|
233
|
+
* style="
|
|
234
|
+
* --active-color: deeppink;
|
|
235
|
+
* --inactive-color: gray;
|
|
236
|
+
* "
|
|
237
|
+
* ></sigvelo-rating>
|
|
238
|
+
*
|
|
239
|
+
* <script>
|
|
240
|
+
* const rating = document.getElementById('rating__custom-symbols');
|
|
241
|
+
*
|
|
242
|
+
* rating.symbolFormatter = (value, isSelected) => {
|
|
243
|
+
* return isSelected ?
|
|
244
|
+
* `<sigvelo-icon family="filled" name="heart"></sigvelo-icon>` :
|
|
245
|
+
* `<sigvelo-icon family="outline" name="heart"></sigvelo-icon>`;
|
|
246
|
+
* }
|
|
247
|
+
* <\/script>
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* ```html
|
|
251
|
+
* <sigvelo-rating
|
|
252
|
+
* label="How satisfied are you?"
|
|
253
|
+
* id="rating__numbers"
|
|
254
|
+
* value="3"
|
|
255
|
+
* style="--active-color: dodgerblue;"
|
|
256
|
+
* ></sigvelo-rating>
|
|
257
|
+
*
|
|
258
|
+
* <script>
|
|
259
|
+
* const rating = document.getElementById('rating__numbers');
|
|
260
|
+
*
|
|
261
|
+
* rating.symbolFormatter = (value, isSelected) => {
|
|
262
|
+
* const family = isSelected ? 'filled' : 'outline';
|
|
263
|
+
* return `<sigvelo-icon family="${family}" name="square-number-${value}"></sigvelo-icon>`
|
|
264
|
+
* }
|
|
265
|
+
* <\/script>
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* ```html
|
|
269
|
+
* <sigvelo-rating
|
|
270
|
+
* label="How satisfied are you?"
|
|
271
|
+
* id="rating__diamonds"
|
|
272
|
+
* value="3"
|
|
273
|
+
* style="--active-color: #2bb7d1;"
|
|
274
|
+
* ></sigvelo-rating>
|
|
275
|
+
*
|
|
276
|
+
* <script>
|
|
277
|
+
* const rating = document.getElementById('rating__diamonds');
|
|
278
|
+
*
|
|
279
|
+
* rating.symbolFormatter = (value, isSelected) => {
|
|
280
|
+
* const family = isSelected ? 'filled' : 'outline';
|
|
281
|
+
* const name = isSelected ? 'diamond' : 'point'
|
|
282
|
+
* return `<sigvelo-icon family="${family}" name="${name}"></sigvelo-icon>`
|
|
283
|
+
* }
|
|
284
|
+
* <\/script>
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* **Warning:** You should only return trusted HTML from the `symbolFormatter()` function, otherwise you may become vulnerable to XSS exploits.
|
|
288
|
+
*
|
|
289
|
+
* @example Readonly ratings
|
|
290
|
+
* Use the `readonly` attribute to make the rating read-only.
|
|
291
|
+
*
|
|
292
|
+
* ```html
|
|
293
|
+
* <sigvelo-rating label="Read-only" value="4" readonly></sigvelo-rating>
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @example Disabling
|
|
297
|
+
* Use the `disabled` attribute to disable the rating.
|
|
298
|
+
*
|
|
299
|
+
* ```html
|
|
300
|
+
* <sigvelo-rating label="Disabled" value="4" disabled></sigvelo-rating>
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @example Validation
|
|
304
|
+
* The `required` attribute can be applied to enable validation using the Constraint Validation API. This will prevent form submission until a non-zero value is selected.
|
|
305
|
+
*
|
|
306
|
+
*
|
|
307
|
+
* ```html
|
|
308
|
+
* <form action="about:blank" method="get" target="_blank">
|
|
309
|
+
* <sigvelo-rating name="required" label="Required" required></sigvelo-rating><br>
|
|
310
|
+
* <sigvelo-button type="submit" color="primary">Submit</sigvelo-button>
|
|
311
|
+
* <sigvelo-button type="reset">Reset</sigvelo-button>
|
|
312
|
+
* </form>
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @example Using custom validation
|
|
316
|
+
* Use the `setCustomValidity()` method to make the rating invalid and show a custom error message on submit. This will override all other validation parameters. To clear the error, remove the attribute or set it to an empty string.
|
|
317
|
+
*
|
|
318
|
+
* ```html
|
|
319
|
+
* <form action="about:blank" method="get" target="_blank" id="rating__custom-validation">
|
|
320
|
+
* <sigvelo-rating
|
|
321
|
+
* name="food"
|
|
322
|
+
* label="Food quality"
|
|
323
|
+
* value="3"
|
|
324
|
+
* ></sigvelo-rating>
|
|
325
|
+
* <br>
|
|
326
|
+
* <sigvelo-button type="submit" color="primary">Submit</sigvelo-button>
|
|
327
|
+
* </form>
|
|
328
|
+
*
|
|
329
|
+
* <script type="module">
|
|
330
|
+
* import { allDefined } from '/dist/sigvelo.js';
|
|
331
|
+
*
|
|
332
|
+
* await allDefined();
|
|
333
|
+
*
|
|
334
|
+
* const form = document.getElementById('rating__custom-validation');
|
|
335
|
+
* const rating = form.querySelector('sigvelo-rating');
|
|
336
|
+
*
|
|
337
|
+
* rating.setCustomValidity('Not so fast, bubba!');
|
|
338
|
+
* <\/script>
|
|
339
|
+
* ```
|
|
340
|
+
*
|
|
341
|
+
* @example Styling validation
|
|
342
|
+
* You can style valid and invalid ratings using the `:valid` and `:invalid` pseudo classes.
|
|
343
|
+
*
|
|
344
|
+
* ```html
|
|
345
|
+
* <form action="about:blank" method="get" target="_blank" class="rating__validation-pseudo">
|
|
346
|
+
* <sigvelo-rating
|
|
347
|
+
* name="food"
|
|
348
|
+
* label="Food quality"
|
|
349
|
+
* description="This field is required."
|
|
350
|
+
* required
|
|
351
|
+
* ></sigvelo-rating>
|
|
352
|
+
* <br>
|
|
353
|
+
* <sigvelo-button type="submit" color="primary">Submit</sigvelo-button>
|
|
354
|
+
* <sigvelo-button type="reset">Reset</sigvelo-button>
|
|
355
|
+
* </form>
|
|
356
|
+
*
|
|
357
|
+
* <style>
|
|
358
|
+
* .rating__validation-pseudo {
|
|
359
|
+
* sigvelo-rating:valid {
|
|
360
|
+
* outline: solid 2px var(--sigvelo-color-success-border);
|
|
361
|
+
* outline-offset: .5rem;
|
|
362
|
+
* }
|
|
363
|
+
*
|
|
364
|
+
* sigvelo-rating:invalid {
|
|
365
|
+
* outline: solid 2px var(--sigvelo-color-danger-border);
|
|
366
|
+
* outline-offset: .5rem;
|
|
367
|
+
* }
|
|
368
|
+
* }
|
|
369
|
+
* </style>
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* However, these selectors will match even before the user has had a chance to fill out the form. More often than not, you'll want to use the `user-valid` and `user-invalid` custom states instead. This way, validation styles are only shown _after_ the user interacts with the form control or when the form is submitted.
|
|
373
|
+
*
|
|
374
|
+
* ```html
|
|
375
|
+
* <form action="about:blank" method="get" target="_blank" class="rating__validation-custom">
|
|
376
|
+
* <sigvelo-rating
|
|
377
|
+
* name="food"
|
|
378
|
+
* label="Food quality"
|
|
379
|
+
* description="This field is required."
|
|
380
|
+
* required
|
|
381
|
+
* ></sigvelo-rating>
|
|
382
|
+
* <br>
|
|
383
|
+
* <sigvelo-button type="submit" color="primary">Submit</sigvelo-button>
|
|
384
|
+
* <sigvelo-button type="reset">Reset</sigvelo-button>
|
|
385
|
+
* </form>
|
|
386
|
+
*
|
|
387
|
+
* <style>
|
|
388
|
+
* .rating__validation-custom {
|
|
389
|
+
* sigvelo-rating:state(user-valid) {
|
|
390
|
+
* outline: solid 2px var(--sigvelo-color-success-border);
|
|
391
|
+
* outline-offset: .5rem;
|
|
392
|
+
* }
|
|
393
|
+
*
|
|
394
|
+
* sigvelo-rating:state(user-invalid) {
|
|
395
|
+
* outline: solid 2px var(--sigvelo-color-danger-border);
|
|
396
|
+
* outline-offset: .5rem;
|
|
397
|
+
* }
|
|
398
|
+
* }
|
|
399
|
+
* </style>
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
var SigveloRating = class extends SigveloFormControlElement {
|
|
403
|
+
constructor(..._args) {
|
|
404
|
+
super(..._args);
|
|
405
|
+
this.didDragOverOthers = false;
|
|
406
|
+
this.localize = new Localize(this);
|
|
407
|
+
this.isInvalid = false;
|
|
408
|
+
this.hadUserInteraction = false;
|
|
409
|
+
this.wasSubmitted = false;
|
|
410
|
+
this.value = 0;
|
|
411
|
+
this.disabled = false;
|
|
412
|
+
this.readonly = false;
|
|
413
|
+
this.size = "md";
|
|
414
|
+
this.required = false;
|
|
415
|
+
this.max = 5;
|
|
416
|
+
this.step = 1;
|
|
417
|
+
this.symbolFormatter = (_, isSelected) => {
|
|
418
|
+
return isSelected ? `<sigvelo-icon library="system" name="star" family="filled"></sigvelo-icon>` : `<sigvelo-icon library="system" name="star" family="outline"></sigvelo-icon>`;
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
static {
|
|
422
|
+
this.formAssociated = true;
|
|
423
|
+
}
|
|
424
|
+
static {
|
|
425
|
+
this.observeSlots = true;
|
|
426
|
+
}
|
|
427
|
+
static {
|
|
428
|
+
this.styles = [
|
|
429
|
+
hostStyles,
|
|
430
|
+
formControlStyles,
|
|
431
|
+
rating_styles_default
|
|
432
|
+
];
|
|
433
|
+
}
|
|
434
|
+
get focusableAnchor() {
|
|
435
|
+
return this.rating;
|
|
436
|
+
}
|
|
437
|
+
connectedCallback() {
|
|
438
|
+
super.connectedCallback();
|
|
439
|
+
this.addEventListener("invalid", this.handleHostInvalid);
|
|
440
|
+
}
|
|
441
|
+
disconnectedCallback() {
|
|
442
|
+
super.disconnectedCallback();
|
|
443
|
+
this.removeEventListener("invalid", this.handleHostInvalid);
|
|
444
|
+
}
|
|
445
|
+
firstUpdated() {
|
|
446
|
+
this.draggableRating = new DraggableElement(this.rating, {
|
|
447
|
+
start: (x) => {
|
|
448
|
+
this.didDragOverOthers = false;
|
|
449
|
+
this.valueWhenDraggingStarted = this.value;
|
|
450
|
+
this.ratingBoundingClientRect = this.rating.getBoundingClientRect();
|
|
451
|
+
this.setValueFromCoordinates(x);
|
|
452
|
+
},
|
|
453
|
+
move: (x) => {
|
|
454
|
+
this.setValueFromCoordinates(x);
|
|
455
|
+
if (this.value !== this.valueWhenDraggingStarted) this.didDragOverOthers = true;
|
|
456
|
+
},
|
|
457
|
+
stop: () => {
|
|
458
|
+
if (this.value !== this.valueWhenDraggingStarted) {
|
|
459
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
460
|
+
this.dispatchEvent(new Event("change", {
|
|
461
|
+
bubbles: true,
|
|
462
|
+
composed: true
|
|
463
|
+
}));
|
|
464
|
+
this.hadUserInteraction = true;
|
|
465
|
+
}
|
|
466
|
+
if (this.value === this.valueWhenDraggingStarted && !this.didDragOverOthers) this.value = 0;
|
|
467
|
+
this.didDragOverOthers = false;
|
|
468
|
+
this.valueWhenDraggingStarted = void 0;
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
updated(changedProperties) {
|
|
473
|
+
this.updateValidity();
|
|
474
|
+
if (changedProperties.has("value")) {
|
|
475
|
+
this.value = clamp(this.value, 0, this.max);
|
|
476
|
+
this.internals.setFormValue(String(this.value));
|
|
477
|
+
}
|
|
478
|
+
if (changedProperties.has("max")) this.value = clamp(this.value, 0, this.max);
|
|
479
|
+
if (changedProperties.has("disabled")) this.customStates.set("disabled", this.disabled);
|
|
480
|
+
if (changedProperties.has("disabled") || changedProperties.has("readonly")) this.draggableRating.toggle(!(this.disabled || this.readonly));
|
|
481
|
+
if (this.hadUserInteraction || this.wasSubmitted) {
|
|
482
|
+
this.customStates.set("user-invalid", this.isInvalid);
|
|
483
|
+
this.customStates.set("user-valid", !this.isInvalid);
|
|
484
|
+
} else {
|
|
485
|
+
this.customStates.set("user-invalid", false);
|
|
486
|
+
this.customStates.set("user-valid", false);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/** @internal Called when a containing fieldset is disabled. */
|
|
490
|
+
formDisabledCallback(isDisabled) {
|
|
491
|
+
this.disabled = isDisabled;
|
|
492
|
+
}
|
|
493
|
+
/** @internal Called when the form is reset. */
|
|
494
|
+
formResetCallback() {
|
|
495
|
+
this.value = parseFloat(this.getAttribute("value") ?? "0");
|
|
496
|
+
this.isInvalid = false;
|
|
497
|
+
this.hadUserInteraction = false;
|
|
498
|
+
this.wasSubmitted = false;
|
|
499
|
+
}
|
|
500
|
+
/** Clamps a number to min/max while ensuring it's a valid step interval. */
|
|
501
|
+
clampAndCeilToStep(value) {
|
|
502
|
+
const stepPrecision = (String(this.step).split(".")[1] || "").replace(/0+$/g, "").length;
|
|
503
|
+
value = Math.ceil(value / this.step) * this.step;
|
|
504
|
+
value = clamp(value, 0, this.max);
|
|
505
|
+
return parseFloat(value.toFixed(stepPrecision));
|
|
506
|
+
}
|
|
507
|
+
handleBlur() {
|
|
508
|
+
this.customStates.set("focused", false);
|
|
509
|
+
this.dispatchEvent(new SigveloBlurEvent());
|
|
510
|
+
}
|
|
511
|
+
handleFocus() {
|
|
512
|
+
this.customStates.set("focused", true);
|
|
513
|
+
this.dispatchEvent(new SigveloFocusEvent());
|
|
514
|
+
}
|
|
515
|
+
handleHostInvalid() {
|
|
516
|
+
this.wasSubmitted = true;
|
|
517
|
+
}
|
|
518
|
+
handleKeyDown(event) {
|
|
519
|
+
const isRtl = this.localize.dir() === "rtl";
|
|
520
|
+
const oldValue = this.value;
|
|
521
|
+
let newValue = this.value;
|
|
522
|
+
if (this.disabled || this.readonly) return;
|
|
523
|
+
if (event.key === "ArrowUp" || event.key === (isRtl ? "ArrowLeft" : "ArrowRight")) {
|
|
524
|
+
event.preventDefault();
|
|
525
|
+
newValue = this.clampAndCeilToStep(newValue + this.step);
|
|
526
|
+
}
|
|
527
|
+
if (event.key === "ArrowDown" || event.key === (isRtl ? "ArrowRight" : "ArrowLeft")) {
|
|
528
|
+
event.preventDefault();
|
|
529
|
+
newValue = this.clampAndCeilToStep(newValue - this.step);
|
|
530
|
+
}
|
|
531
|
+
if (event.key === "Home") {
|
|
532
|
+
event.preventDefault();
|
|
533
|
+
newValue = 0;
|
|
534
|
+
}
|
|
535
|
+
if (event.key === "End") {
|
|
536
|
+
event.preventDefault();
|
|
537
|
+
newValue = this.clampAndCeilToStep(this.max);
|
|
538
|
+
}
|
|
539
|
+
if (event.key === "PageUp") {
|
|
540
|
+
event.preventDefault();
|
|
541
|
+
newValue = this.clampAndCeilToStep(Math.max(newValue + this.max / 10, newValue + this.step));
|
|
542
|
+
}
|
|
543
|
+
if (event.key === "PageDown") {
|
|
544
|
+
event.preventDefault();
|
|
545
|
+
newValue = this.clampAndCeilToStep(Math.min(newValue - this.max / 10, newValue - this.step));
|
|
546
|
+
}
|
|
547
|
+
if (newValue !== oldValue) {
|
|
548
|
+
if (newValue < 0) newValue = 0;
|
|
549
|
+
if (newValue > this.max) newValue = this.max;
|
|
550
|
+
this.value = newValue;
|
|
551
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
552
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
553
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
554
|
+
this.dispatchEvent(new Event("change", {
|
|
555
|
+
bubbles: true,
|
|
556
|
+
composed: true
|
|
557
|
+
}));
|
|
558
|
+
this.hadUserInteraction = true;
|
|
559
|
+
}
|
|
560
|
+
if (event.key === "Enter" && this.internals.form) {
|
|
561
|
+
const submitter = [...this.internals.form.elements].find((el) => {
|
|
562
|
+
return ["button", "input"].includes(el.localName) && el.type === "submit";
|
|
563
|
+
});
|
|
564
|
+
this.internals.form.requestSubmit(submitter);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
handleLabelPointerDown(event) {
|
|
568
|
+
event.preventDefault();
|
|
569
|
+
if (!this.disabled) this.rating.focus();
|
|
570
|
+
}
|
|
571
|
+
setValueFromCoordinates(x) {
|
|
572
|
+
const isRtl = this.localize.dir() === "rtl";
|
|
573
|
+
const oldValue = this.value;
|
|
574
|
+
const { right, left, width } = this.ratingBoundingClientRect;
|
|
575
|
+
const pointerPosition = x;
|
|
576
|
+
const ratingCoords = {
|
|
577
|
+
start: left,
|
|
578
|
+
end: right,
|
|
579
|
+
size: width
|
|
580
|
+
};
|
|
581
|
+
const percentage = (isRtl ? ratingCoords.end - pointerPosition : pointerPosition - ratingCoords.start) / ratingCoords.size;
|
|
582
|
+
this.value = this.clampAndCeilToStep(this.max * percentage);
|
|
583
|
+
if (this.value !== oldValue) {
|
|
584
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
585
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
/** Sets the form control's validity */
|
|
589
|
+
async updateValidity() {
|
|
590
|
+
await this.updateComplete;
|
|
591
|
+
const isValueMissing = this.required && this.value === 0;
|
|
592
|
+
const hasCustomValidity = this.getCustomValidity().length > 0;
|
|
593
|
+
const validationMessage = isValueMissing ? VALIDATION_MESSAGE : this.getCustomValidity();
|
|
594
|
+
const flags = {
|
|
595
|
+
badInput: false,
|
|
596
|
+
customError: hasCustomValidity,
|
|
597
|
+
patternMismatch: false,
|
|
598
|
+
rangeOverflow: false,
|
|
599
|
+
rangeUnderflow: false,
|
|
600
|
+
stepMismatch: false,
|
|
601
|
+
tooLong: false,
|
|
602
|
+
tooShort: false,
|
|
603
|
+
typeMismatch: false,
|
|
604
|
+
valueMissing: isValueMissing
|
|
605
|
+
};
|
|
606
|
+
this.isInvalid = isValueMissing || hasCustomValidity;
|
|
607
|
+
this.internals.setValidity(flags, validationMessage, this.focusableAnchor);
|
|
608
|
+
}
|
|
609
|
+
/** Sets focus to the rating. */
|
|
610
|
+
focus() {
|
|
611
|
+
this.rating.focus();
|
|
612
|
+
}
|
|
613
|
+
/** Removes focus from the rating. */
|
|
614
|
+
blur() {
|
|
615
|
+
this.rating.blur();
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Decreases the rating's value by `step`. This is a programmatic change, so `input` and `change` events will not be
|
|
619
|
+
* emitted when this is called.
|
|
620
|
+
*/
|
|
621
|
+
stepDown() {
|
|
622
|
+
const newValue = this.clampAndCeilToStep(this.value - this.step);
|
|
623
|
+
this.value = newValue;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Increases the rating's value by `step`. This is a programmatic change, so `input` and `change` events will not be
|
|
627
|
+
* emitted when this is called.
|
|
628
|
+
*/
|
|
629
|
+
stepUp() {
|
|
630
|
+
const newValue = this.clampAndCeilToStep(this.value + this.step);
|
|
631
|
+
this.value = newValue;
|
|
632
|
+
}
|
|
633
|
+
render() {
|
|
634
|
+
const hasLabel = this.label || this.slotsWithContent.has("label");
|
|
635
|
+
const hasDescription = this.description || this.slotsWithContent.has("description");
|
|
636
|
+
const symbols = [];
|
|
637
|
+
for (let i = 1; i <= this.max; i += 1) symbols.push([this.symbolFormatter(i, true), this.symbolFormatter(i, false)]);
|
|
638
|
+
return html`
|
|
639
|
+
<label
|
|
640
|
+
id="label"
|
|
641
|
+
part="label"
|
|
642
|
+
class=${classMap({ vh: !hasLabel })}
|
|
643
|
+
for="rating"
|
|
644
|
+
@pointerdown=${this.handleLabelPointerDown}
|
|
645
|
+
>
|
|
646
|
+
<slot name="label">${this.label}</slot>
|
|
647
|
+
</label>
|
|
648
|
+
|
|
649
|
+
<div id="description" part="description" class=${classMap({ vh: !hasDescription })}>
|
|
650
|
+
<slot name="description">${this.description}</slot>
|
|
651
|
+
</div>
|
|
652
|
+
|
|
653
|
+
<div
|
|
654
|
+
id="rating"
|
|
655
|
+
part="rating"
|
|
656
|
+
class=${classMap({
|
|
657
|
+
xs: this.size === "xs",
|
|
658
|
+
sm: this.size === "sm",
|
|
659
|
+
md: this.size === "md",
|
|
660
|
+
lg: this.size === "lg",
|
|
661
|
+
xl: this.size === "xl",
|
|
662
|
+
disabled: this.disabled,
|
|
663
|
+
readonly: this.readonly
|
|
664
|
+
})}
|
|
665
|
+
role="slider"
|
|
666
|
+
aria-labelledby="label"
|
|
667
|
+
aria-describedby="description"
|
|
668
|
+
aria-disabled=${this.disabled ? "true" : "false"}
|
|
669
|
+
aria-readonly=${this.readonly ? "true" : "false"}
|
|
670
|
+
aria-valuemin="0"
|
|
671
|
+
aria-valuenow=${this.value}
|
|
672
|
+
aria-valuetext="${this.localize.term("numberOfTotal", this.value, this.max)}"
|
|
673
|
+
aria-valuemax=${this.max}
|
|
674
|
+
tabindex=${this.disabled || this.readonly ? "-1" : "0"}
|
|
675
|
+
@focus=${this.handleFocus}
|
|
676
|
+
@blur=${this.handleBlur}
|
|
677
|
+
@keydown=${this.handleKeyDown}
|
|
678
|
+
>
|
|
679
|
+
${symbols.map((symbol, index) => {
|
|
680
|
+
return html`
|
|
681
|
+
<span
|
|
682
|
+
part="symbol"
|
|
683
|
+
class="symbol"
|
|
684
|
+
style="--clip-percentage: ${(this.value - index) * 100}%;"
|
|
685
|
+
>
|
|
686
|
+
${unsafeHTML(symbol[0])} ${unsafeHTML(symbol[1])}
|
|
687
|
+
</span>
|
|
688
|
+
`;
|
|
689
|
+
})}
|
|
690
|
+
</div>
|
|
691
|
+
`;
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
__decorate([query("#rating")], SigveloRating.prototype, "rating", void 0);
|
|
695
|
+
__decorate([state()], SigveloRating.prototype, "isInvalid", void 0);
|
|
696
|
+
__decorate([state()], SigveloRating.prototype, "hadUserInteraction", void 0);
|
|
697
|
+
__decorate([state()], SigveloRating.prototype, "wasSubmitted", void 0);
|
|
698
|
+
__decorate([property()], SigveloRating.prototype, "label", void 0);
|
|
699
|
+
__decorate([property()], SigveloRating.prototype, "description", void 0);
|
|
700
|
+
__decorate([property({ reflect: true })], SigveloRating.prototype, "name", void 0);
|
|
701
|
+
__decorate([property({ type: Number })], SigveloRating.prototype, "value", void 0);
|
|
702
|
+
__decorate([property({
|
|
703
|
+
type: Boolean,
|
|
704
|
+
reflect: true
|
|
705
|
+
})], SigveloRating.prototype, "disabled", void 0);
|
|
706
|
+
__decorate([property({
|
|
707
|
+
type: Boolean,
|
|
708
|
+
reflect: true
|
|
709
|
+
})], SigveloRating.prototype, "readonly", void 0);
|
|
710
|
+
__decorate([property({ reflect: true })], SigveloRating.prototype, "size", void 0);
|
|
711
|
+
__decorate([property()], SigveloRating.prototype, "form", void 0);
|
|
712
|
+
__decorate([property({
|
|
713
|
+
type: Boolean,
|
|
714
|
+
reflect: true
|
|
715
|
+
})], SigveloRating.prototype, "required", void 0);
|
|
716
|
+
__decorate([property({ type: Number })], SigveloRating.prototype, "max", void 0);
|
|
717
|
+
__decorate([property({ type: Number })], SigveloRating.prototype, "step", void 0);
|
|
718
|
+
__decorate([property({ type: Boolean })], SigveloRating.prototype, "autofocus", void 0);
|
|
719
|
+
__decorate([property({ attribute: false })], SigveloRating.prototype, "symbolFormatter", void 0);
|
|
720
|
+
customElements.define("sigvelo-rating", SigveloRating);
|
|
721
|
+
//#endregion
|
|
722
|
+
export { SigveloRating as t };
|