@govtechsg/sgds-web-component 3.0.0-rc.0 → 3.0.0-rc.2
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/Masthead/index.js +1 -1
- package/README.md +5 -5
- package/base/button.js +1 -1
- package/base/form-control-element.d.ts +4 -11
- package/base/form-control-element.js +13 -23
- package/base/form-control-element.js.map +1 -1
- package/components/Accordion/accordion-item.js +1 -1
- package/components/Accordion/index.umd.js +7 -19
- package/components/Accordion/index.umd.js.map +1 -1
- package/components/Accordion/sgds-accordion-item.d.ts +3 -7
- package/components/Accordion/sgds-accordion-item.js +6 -18
- package/components/Accordion/sgds-accordion-item.js.map +1 -1
- package/components/ActionCard/index.umd.js +407 -329
- package/components/ActionCard/index.umd.js.map +1 -1
- package/components/Alert/alert.js +1 -1
- package/components/Alert/index.umd.js +553 -485
- package/components/Alert/index.umd.js.map +1 -1
- package/components/Alert/sgds-alert.d.ts +2 -2
- package/components/Alert/sgds-alert.js +6 -13
- package/components/Alert/sgds-alert.js.map +1 -1
- package/components/Badge/badge.js +1 -1
- package/components/Badge/index.umd.js +9 -10
- package/components/Badge/index.umd.js.map +1 -1
- package/components/Badge/sgds-badge.d.ts +4 -5
- package/components/Badge/sgds-badge.js +6 -7
- package/components/Badge/sgds-badge.js.map +1 -1
- package/components/Button/index.umd.js +8 -81
- package/components/Button/index.umd.js.map +1 -1
- package/components/Button/sgds-button.js +1 -1
- package/components/Button/sgds-button.js.map +1 -1
- package/components/Checkbox/checkbox.js +1 -1
- package/components/Checkbox/index.umd.js +541 -475
- package/components/Checkbox/index.umd.js.map +1 -1
- package/components/Checkbox/sgds-checkbox-group.d.ts +7 -1
- package/components/Checkbox/sgds-checkbox-group.js +15 -4
- package/components/Checkbox/sgds-checkbox-group.js.map +1 -1
- package/components/Checkbox/sgds-checkbox.d.ts +30 -21
- package/components/Checkbox/sgds-checkbox.js +77 -60
- package/components/Checkbox/sgds-checkbox.js.map +1 -1
- package/components/ComboBox/index.umd.js +385 -216
- package/components/ComboBox/index.umd.js.map +1 -1
- package/components/Datepicker/datepicker-input.d.ts +4 -2
- package/components/Datepicker/datepicker-input.js +24 -7
- package/components/Datepicker/datepicker-input.js.map +1 -1
- package/components/Datepicker/index.umd.js +433 -244
- package/components/Datepicker/index.umd.js.map +1 -1
- package/components/Datepicker/sgds-datepicker.d.ts +1 -1
- package/components/Datepicker/sgds-datepicker.js.map +1 -1
- package/components/Drawer/index.umd.js +2 -2
- package/components/Drawer/index.umd.js.map +1 -1
- package/components/Dropdown/index.umd.js +8 -81
- package/components/Dropdown/index.umd.js.map +1 -1
- package/components/FileUpload/file-upload.js +1 -1
- package/components/FileUpload/index.umd.js +579 -272
- package/components/FileUpload/index.umd.js.map +1 -1
- package/components/FileUpload/sgds-file-upload.d.ts +42 -30
- package/components/FileUpload/sgds-file-upload.js +147 -103
- package/components/FileUpload/sgds-file-upload.js.map +1 -1
- package/components/Footer/footer-item.js +6 -0
- package/components/Footer/footer-item.js.map +1 -0
- package/components/Footer/footer.js +1 -1
- package/components/Footer/index.d.ts +2 -0
- package/components/Footer/index.js +2 -0
- package/components/Footer/index.js.map +1 -1
- package/components/Footer/index.umd.js +93 -94
- package/components/Footer/index.umd.js.map +1 -1
- package/components/Footer/sgds-footer-item.d.ts +13 -0
- package/components/Footer/sgds-footer-item.js +27 -0
- package/components/Footer/sgds-footer-item.js.map +1 -0
- package/components/Footer/sgds-footer.d.ts +9 -30
- package/components/Footer/sgds-footer.js +65 -90
- package/components/Footer/sgds-footer.js.map +1 -1
- package/components/Icon/icon.js +6 -0
- package/components/Icon/icon.js.map +1 -0
- package/components/Icon/index.d.ts +6 -0
- package/components/Icon/index.js +4 -0
- package/components/Icon/index.js.map +1 -0
- package/components/Icon/index.umd.js +4389 -0
- package/components/Icon/index.umd.js.map +1 -0
- package/components/Icon/sgds-icon.d.ts +21 -0
- package/components/Icon/sgds-icon.js +64 -0
- package/components/Icon/sgds-icon.js.map +1 -0
- package/components/IconButton/icon-button.js +1 -1
- package/components/IconButton/index.umd.js +6 -9
- package/components/IconButton/index.umd.js.map +1 -1
- package/components/IconButton/sgds-icon-button.d.ts +2 -2
- package/components/IconButton/sgds-icon-button.js +4 -9
- package/components/IconButton/sgds-icon-button.js.map +1 -1
- package/components/Input/index.umd.js +1734 -1376
- package/components/Input/index.umd.js.map +1 -1
- package/components/Input/sgds-input.d.ts +41 -21
- package/components/Input/sgds-input.js +103 -66
- package/components/Input/sgds-input.js.map +1 -1
- package/components/Masthead/index.umd.js +1 -1
- package/components/Masthead/masthead.js +1 -1
- package/components/Modal/index.umd.js +2 -2
- package/components/Modal/index.umd.js.map +1 -1
- package/components/QuantityToggle/index.umd.js +894 -316
- package/components/QuantityToggle/index.umd.js.map +1 -1
- package/components/QuantityToggle/sgds-quantity-toggle.d.ts +42 -15
- package/components/QuantityToggle/sgds-quantity-toggle.js +129 -62
- package/components/QuantityToggle/sgds-quantity-toggle.js.map +1 -1
- package/components/Radio/index.umd.js +516 -203
- package/components/Radio/index.umd.js.map +1 -1
- package/components/Radio/sgds-radio-group.d.ts +38 -27
- package/components/Radio/sgds-radio-group.js +100 -84
- package/components/Radio/sgds-radio-group.js.map +1 -1
- package/components/Radio/sgds-radio.js +1 -1
- package/components/Radio/sgds-radio.js.map +1 -1
- package/components/Stepper/index.umd.js +2 -1
- package/components/Stepper/index.umd.js.map +1 -1
- package/components/Stepper/sgds-stepper.d.ts +1 -0
- package/components/Stepper/sgds-stepper.js +1 -0
- package/components/Stepper/sgds-stepper.js.map +1 -1
- package/components/Stepper/stepper.js +1 -1
- package/components/Switch/index.umd.js +21 -321
- package/components/Switch/index.umd.js.map +1 -1
- package/components/Switch/sgds-switch.js +1 -2
- package/components/Switch/sgds-switch.js.map +1 -1
- package/components/Textarea/index.umd.js +1554 -1336
- package/components/Textarea/index.umd.js.map +1 -1
- package/components/Textarea/sgds-textarea.d.ts +33 -22
- package/components/Textarea/sgds-textarea.js +78 -75
- package/components/Textarea/sgds-textarea.js.map +1 -1
- package/components/Textarea/textarea.js +1 -1
- package/components/Toast/index.umd.js +9 -21
- package/components/Toast/index.umd.js.map +1 -1
- package/components/Toast/sgds-toast.d.ts +2 -1
- package/components/Toast/sgds-toast.js +6 -18
- package/components/Toast/sgds-toast.js.map +1 -1
- package/components/Toast/toast.js +1 -1
- package/components/Tooltip/index.umd.js +14 -14
- package/components/Tooltip/index.umd.js.map +1 -1
- package/components/Tooltip/sgds-tooltip.d.ts +4 -7
- package/components/Tooltip/sgds-tooltip.js +14 -14
- package/components/Tooltip/sgds-tooltip.js.map +1 -1
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/index.js.map +1 -1
- package/components/index.umd.js +1320 -1126
- package/components/index.umd.js.map +1 -1
- package/css/reboot.css +39 -6
- package/css/sgds.css +0 -2
- package/icons/arrow-bar-down.svg +3 -0
- package/icons/arrow-bar-left.svg +3 -0
- package/icons/arrow-bar-right.svg +3 -0
- package/icons/arrow-bar-up.svg +3 -0
- package/icons/arrow-clockwise.svg +3 -0
- package/icons/arrow-down.svg +3 -0
- package/icons/arrow-left.svg +3 -0
- package/icons/arrow-repeat.svg +3 -0
- package/icons/arrow-right.svg +3 -0
- package/icons/arrow-up.svg +3 -0
- package/icons/bank-fill.svg +3 -0
- package/icons/bell-slash.svg +3 -0
- package/icons/bell.svg +3 -0
- package/icons/bi-funnel.svg +3 -0
- package/icons/bookmark-fill.svg +3 -0
- package/icons/bookmark.svg +3 -0
- package/icons/box-arrow-up-right.svg +3 -0
- package/icons/box-seam.svg +3 -0
- package/icons/building.svg +3 -0
- package/icons/calculator.svg +3 -0
- package/icons/calendar-check.svg +4 -0
- package/icons/calendar-x.svg +4 -0
- package/icons/calendar.svg +3 -0
- package/icons/camera.svg +3 -0
- package/icons/chat-left-text.svg +3 -0
- package/icons/check-circle-fill.svg +3 -0
- package/icons/check-circle.svg +3 -0
- package/icons/check.svg +3 -0
- package/icons/chevron-down.svg +3 -0
- package/icons/chevron-left.svg +3 -0
- package/icons/chevron-right.svg +3 -0
- package/icons/chevron-up .svg +3 -0
- package/icons/clock.svg +4 -0
- package/icons/cloud-check.svg +4 -0
- package/icons/cloud-download.svg +3 -0
- package/icons/cloud-upload.svg +3 -0
- package/icons/cloud.svg +3 -0
- package/icons/compass.svg +4 -0
- package/icons/cross.svg +3 -0
- package/icons/cursor-fill.svg +3 -0
- package/icons/cursor.svg +3 -0
- package/icons/dash-circle.svg +3 -0
- package/icons/dash-square.svg +3 -0
- package/icons/dash.svg +3 -0
- package/icons/download.svg +3 -0
- package/icons/exclamation-circle-fill.svg +3 -0
- package/icons/exclamation-circle.svg +4 -0
- package/icons/exclamation-triangle-fill.svg +3 -0
- package/icons/exclamation-triangle.svg +4 -0
- package/icons/exclamation.svg +4 -0
- package/icons/eye-fill.svg +3 -0
- package/icons/eye-slash-fill.svg +4 -0
- package/icons/eye-slash.svg +3 -0
- package/icons/eye.svg +3 -0
- package/icons/facebook.svg +3 -0
- package/icons/file-earmark-text.svg +3 -0
- package/icons/file-pdf.svg +4 -0
- package/icons/file-plus.svg +4 -0
- package/icons/file-text.svg +3 -0
- package/icons/file.svg +3 -0
- package/icons/files.svg +4 -0
- package/icons/folder-check.svg +4 -0
- package/icons/folder-minus.svg +4 -0
- package/icons/folder-plus.svg +4 -0
- package/icons/folder.svg +3 -0
- package/icons/gear.svg +3 -0
- package/icons/geo-alt.svg +4 -0
- package/icons/geo-fill.svg +4 -0
- package/icons/geo.svg +4 -0
- package/icons/google.svg +3 -0
- package/icons/grid-fill.svg +3 -0
- package/icons/hand-thumbs-down.svg +3 -0
- package/icons/hand-thumbs-up.svg +3 -0
- package/icons/hdd.svg +3 -0
- package/icons/house-door.svg +3 -0
- package/icons/house.svg +3 -0
- package/icons/image.svg +3 -0
- package/icons/inbox.svg +3 -0
- package/icons/info-circle-fill.svg +3 -0
- package/icons/info-circle.svg +4 -0
- package/icons/instagram.svg +3 -0
- package/icons/layers.svg +3 -0
- package/icons/layout-text-window-reverse.svg +3 -0
- package/icons/layout-text-window.svg +3 -0
- package/icons/layout.svg +3 -0
- package/icons/link.svg +3 -0
- package/icons/linkedin.svg +3 -0
- package/icons/list.svg +3 -0
- package/icons/lock-fill.svg +3 -0
- package/icons/lock.svg +3 -0
- package/icons/mail.svg +3 -0
- package/icons/map.svg +3 -0
- package/icons/paperclip.svg +3 -0
- package/icons/pencil.svg +3 -0
- package/icons/pending-circle.svg +3 -0
- package/icons/person-dash.svg +3 -0
- package/icons/person-plus.svg +3 -0
- package/icons/person-x.svg +3 -0
- package/icons/person.svg +3 -0
- package/icons/pin-map-fill.svg +3 -0
- package/icons/pin.svg +3 -0
- package/icons/placeholder.svg +3 -0
- package/icons/plus-circle.svg +3 -0
- package/icons/plus-square.svg +3 -0
- package/icons/plus.svg +3 -0
- package/icons/printer.svg +3 -0
- package/icons/question-circle.svg +4 -0
- package/icons/save.svg +3 -0
- package/icons/search.svg +3 -0
- package/icons/share.svg +3 -0
- package/icons/slash-circle.svg +3 -0
- package/icons/sliders.svg +3 -0
- package/icons/speedometer.svg +3 -0
- package/icons/star-fill.svg +3 -0
- package/icons/star.svg +3 -0
- package/icons/stoplights.svg +4 -0
- package/icons/telephone.svg +3 -0
- package/icons/three-dots-vertical.svg +3 -0
- package/icons/three-dots.svg +3 -0
- package/icons/toggle-off.svg +3 -0
- package/icons/toggle-on.svg +3 -0
- package/icons/trash.svg +3 -0
- package/icons/twitter-x.svg +3 -0
- package/icons/unlock.svg +3 -0
- package/icons/upload.svg +3 -0
- package/icons/window-dash.svg +4 -0
- package/icons/window-desktop.svg +4 -0
- package/icons/window-dock.svg +4 -0
- package/icons/window-fullscreen.svg +3 -0
- package/icons/window-plus.svg +4 -0
- package/icons/window-sidebar.svg +3 -0
- package/icons/window-split.svg +3 -0
- package/icons/window-stack.svg +3 -0
- package/icons/window-x.svg +4 -0
- package/icons/window.svg +3 -0
- package/icons/x-circle-fill.svg +3 -0
- package/icons/x-circle.svg +3 -0
- package/icons/youtube.svg +3 -0
- package/icons/zoom-in.svg +3 -0
- package/icons/zoom-out.svg +3 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/index.umd.js +1340 -1121
- package/index.umd.js.map +1 -1
- package/internals/CloseButton/close-button.js +1 -1
- package/internals/CloseButton/sgds-close-button.js +1 -1
- package/internals/CloseButton/sgds-close-button.js.map +1 -1
- package/package.json +1 -1
- package/react/base/button.cjs.js +1 -1
- package/react/base/button.js +1 -1
- package/react/base/form-control-element.cjs.js +13 -23
- package/react/base/form-control-element.cjs.js.map +1 -1
- package/react/base/form-control-element.js +13 -23
- package/react/base/form-control-element.js.map +1 -1
- package/react/checkbox/index.cjs.js +2 -0
- package/react/checkbox/index.cjs.js.map +1 -1
- package/react/checkbox/index.d.ts +2 -0
- package/react/checkbox/index.js +2 -0
- package/react/checkbox/index.js.map +1 -1
- package/react/components/Accordion/accordion-item.cjs.js +1 -1
- package/react/components/Accordion/accordion-item.js +1 -1
- package/react/components/Accordion/sgds-accordion-item.cjs.js +6 -18
- package/react/components/Accordion/sgds-accordion-item.cjs.js.map +1 -1
- package/react/components/Accordion/sgds-accordion-item.js +6 -18
- package/react/components/Accordion/sgds-accordion-item.js.map +1 -1
- package/react/components/Alert/alert.cjs.js +1 -1
- package/react/components/Alert/alert.js +1 -1
- package/react/components/Alert/sgds-alert.cjs.js +5 -12
- package/react/components/Alert/sgds-alert.cjs.js.map +1 -1
- package/react/components/Alert/sgds-alert.js +6 -13
- package/react/components/Alert/sgds-alert.js.map +1 -1
- package/react/components/Badge/badge.cjs.js +1 -1
- package/react/components/Badge/badge.js +1 -1
- package/react/components/Badge/sgds-badge.cjs.js +6 -7
- package/react/components/Badge/sgds-badge.cjs.js.map +1 -1
- package/react/components/Badge/sgds-badge.js +6 -7
- package/react/components/Badge/sgds-badge.js.map +1 -1
- package/react/components/Button/sgds-button.cjs.js +2 -2
- package/react/components/Button/sgds-button.cjs.js.map +1 -1
- package/react/components/Button/sgds-button.js +1 -1
- package/react/components/Button/sgds-button.js.map +1 -1
- package/react/components/Checkbox/checkbox.cjs.js +1 -1
- package/react/components/Checkbox/checkbox.js +1 -1
- package/react/components/Checkbox/sgds-checkbox-group.cjs.js +15 -4
- package/react/components/Checkbox/sgds-checkbox-group.cjs.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox-group.js +15 -4
- package/react/components/Checkbox/sgds-checkbox-group.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox.cjs.js +77 -60
- package/react/components/Checkbox/sgds-checkbox.cjs.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox.js +77 -60
- package/react/components/Checkbox/sgds-checkbox.js.map +1 -1
- package/react/components/Datepicker/datepicker-input.cjs.js +24 -7
- package/react/components/Datepicker/datepicker-input.cjs.js.map +1 -1
- package/react/components/Datepicker/datepicker-input.js +24 -7
- package/react/components/Datepicker/datepicker-input.js.map +1 -1
- package/react/components/Datepicker/sgds-datepicker.cjs.js.map +1 -1
- package/react/components/Datepicker/sgds-datepicker.js.map +1 -1
- package/react/components/FileUpload/file-upload.cjs.js +1 -1
- package/react/components/FileUpload/file-upload.js +1 -1
- package/react/components/FileUpload/sgds-file-upload.cjs.js +145 -101
- package/react/components/FileUpload/sgds-file-upload.cjs.js.map +1 -1
- package/react/components/FileUpload/sgds-file-upload.js +147 -103
- package/react/components/FileUpload/sgds-file-upload.js.map +1 -1
- package/react/components/Footer/footer-item.cjs.js +11 -0
- package/react/components/Footer/footer-item.cjs.js.map +1 -0
- package/react/components/Footer/footer-item.js +7 -0
- package/react/components/Footer/footer-item.js.map +1 -0
- package/react/components/Footer/footer.cjs.js +1 -1
- package/react/components/Footer/footer.js +1 -1
- package/react/components/Footer/sgds-footer-item.cjs.js +33 -0
- package/react/components/Footer/sgds-footer-item.cjs.js.map +1 -0
- package/react/components/Footer/sgds-footer-item.js +28 -0
- package/react/components/Footer/sgds-footer-item.js.map +1 -0
- package/react/components/Footer/sgds-footer.cjs.js +65 -90
- package/react/components/Footer/sgds-footer.cjs.js.map +1 -1
- package/react/components/Footer/sgds-footer.js +65 -90
- package/react/components/Footer/sgds-footer.js.map +1 -1
- package/react/components/Icon/icon.cjs.js +11 -0
- package/react/components/Icon/icon.cjs.js.map +1 -0
- package/react/components/Icon/icon.js +7 -0
- package/react/components/Icon/icon.js.map +1 -0
- package/react/components/Icon/sgds-icon.cjs.js +70 -0
- package/react/components/Icon/sgds-icon.cjs.js.map +1 -0
- package/react/components/Icon/sgds-icon.js +65 -0
- package/react/components/Icon/sgds-icon.js.map +1 -0
- package/react/components/IconButton/icon-button.cjs.js +1 -1
- package/react/components/IconButton/icon-button.js +1 -1
- package/react/components/IconButton/sgds-icon-button.cjs.js +4 -9
- package/react/components/IconButton/sgds-icon-button.cjs.js.map +1 -1
- package/react/components/IconButton/sgds-icon-button.js +4 -9
- package/react/components/IconButton/sgds-icon-button.js.map +1 -1
- package/react/components/Input/sgds-input.cjs.js +101 -64
- package/react/components/Input/sgds-input.cjs.js.map +1 -1
- package/react/components/Input/sgds-input.js +103 -66
- package/react/components/Input/sgds-input.js.map +1 -1
- package/react/components/Masthead/masthead.cjs.js +1 -1
- package/react/components/Masthead/masthead.js +1 -1
- package/react/components/QuantityToggle/sgds-quantity-toggle.cjs.js +128 -61
- package/react/components/QuantityToggle/sgds-quantity-toggle.cjs.js.map +1 -1
- package/react/components/QuantityToggle/sgds-quantity-toggle.js +129 -62
- package/react/components/QuantityToggle/sgds-quantity-toggle.js.map +1 -1
- package/react/components/Radio/sgds-radio-group.cjs.js +99 -83
- package/react/components/Radio/sgds-radio-group.cjs.js.map +1 -1
- package/react/components/Radio/sgds-radio-group.js +100 -84
- package/react/components/Radio/sgds-radio-group.js.map +1 -1
- package/react/components/Radio/sgds-radio.cjs.js +1 -1
- package/react/components/Radio/sgds-radio.cjs.js.map +1 -1
- package/react/components/Radio/sgds-radio.js +1 -1
- package/react/components/Radio/sgds-radio.js.map +1 -1
- package/react/components/Stepper/sgds-stepper.cjs.js +1 -0
- package/react/components/Stepper/sgds-stepper.cjs.js.map +1 -1
- package/react/components/Stepper/sgds-stepper.js +1 -0
- package/react/components/Stepper/sgds-stepper.js.map +1 -1
- package/react/components/Stepper/stepper.cjs.js +1 -1
- package/react/components/Stepper/stepper.js +1 -1
- package/react/components/Switch/sgds-switch.cjs.js +1 -2
- package/react/components/Switch/sgds-switch.cjs.js.map +1 -1
- package/react/components/Switch/sgds-switch.js +1 -2
- package/react/components/Switch/sgds-switch.js.map +1 -1
- package/react/components/Textarea/sgds-textarea.cjs.js +76 -73
- package/react/components/Textarea/sgds-textarea.cjs.js.map +1 -1
- package/react/components/Textarea/sgds-textarea.js +78 -75
- package/react/components/Textarea/sgds-textarea.js.map +1 -1
- package/react/components/Textarea/textarea.cjs.js +1 -1
- package/react/components/Textarea/textarea.js +1 -1
- package/react/components/Toast/sgds-toast.cjs.js +6 -18
- package/react/components/Toast/sgds-toast.cjs.js.map +1 -1
- package/react/components/Toast/sgds-toast.js +6 -18
- package/react/components/Toast/sgds-toast.js.map +1 -1
- package/react/components/Toast/toast.cjs.js +1 -1
- package/react/components/Toast/toast.js +1 -1
- package/react/components/Tooltip/sgds-tooltip.cjs.js +14 -14
- package/react/components/Tooltip/sgds-tooltip.cjs.js.map +1 -1
- package/react/components/Tooltip/sgds-tooltip.js +14 -14
- package/react/components/Tooltip/sgds-tooltip.js.map +1 -1
- package/react/footer-item/index.cjs.js +39 -0
- package/react/footer-item/index.cjs.js.map +1 -0
- package/react/footer-item/index.d.ts +3 -0
- package/react/footer-item/index.js +15 -0
- package/react/footer-item/index.js.map +1 -0
- package/react/icon/index.cjs.js +42 -0
- package/react/icon/index.cjs.js.map +1 -0
- package/react/icon/index.d.ts +6 -0
- package/react/icon/index.js +18 -0
- package/react/icon/index.js.map +1 -0
- package/react/index.cjs.js +64 -60
- package/react/index.cjs.js.map +1 -1
- package/react/index.d.ts +2 -0
- package/react/index.js +2 -0
- package/react/index.js.map +1 -1
- package/react/input/index.cjs.js +3 -1
- package/react/input/index.cjs.js.map +1 -1
- package/react/input/index.d.ts +2 -0
- package/react/input/index.js +3 -1
- package/react/input/index.js.map +1 -1
- package/react/internals/CloseButton/close-button.cjs.js +1 -1
- package/react/internals/CloseButton/close-button.js +1 -1
- package/react/internals/CloseButton/sgds-close-button.cjs.js +1 -1
- package/react/internals/CloseButton/sgds-close-button.cjs.js.map +1 -1
- package/react/internals/CloseButton/sgds-close-button.js +1 -1
- package/react/internals/CloseButton/sgds-close-button.js.map +1 -1
- package/react/styles/form-hint.cjs.js +1 -1
- package/react/styles/form-hint.js +1 -1
- package/react/styles/form-label.cjs.js +1 -1
- package/react/styles/form-label.js +1 -1
- package/react/utils/formSubmitController.cjs.js +64 -0
- package/react/utils/formSubmitController.cjs.js.map +1 -0
- package/react/utils/formSubmitController.js +60 -0
- package/react/utils/formSubmitController.js.map +1 -0
- package/react/utils/inputValidationController.cjs.js +130 -0
- package/react/utils/inputValidationController.cjs.js.map +1 -0
- package/react/utils/inputValidationController.js +126 -0
- package/react/utils/inputValidationController.js.map +1 -0
- package/react/utils/validatorMixin.cjs.js +108 -0
- package/react/utils/validatorMixin.cjs.js.map +1 -0
- package/react/utils/validatorMixin.js +104 -0
- package/react/utils/validatorMixin.js.map +1 -0
- package/styles/form-hint.js +1 -1
- package/styles/form-label.js +1 -1
- package/themes/day.css +1 -1
- package/themes/night.css +3 -2
- package/themes/root.css +2 -0
- package/utils/{form.d.ts → formSubmitController.d.ts} +10 -20
- package/utils/formSubmitController.js +59 -0
- package/utils/formSubmitController.js.map +1 -0
- package/utils/inputValidationController.d.ts +70 -0
- package/utils/inputValidationController.js +125 -0
- package/utils/inputValidationController.js.map +1 -0
- package/utils/validatorMixin.d.ts +24 -0
- package/utils/validatorMixin.js +103 -0
- package/utils/validatorMixin.js.map +1 -0
- package/base/form-check-element.d.ts +0 -50
- package/base/form-check-element.js +0 -169
- package/base/form-check-element.js.map +0 -1
- package/css/body.css +0 -28
- package/css/caption.css +0 -7
- package/css/label.css +0 -28
- package/react/base/form-check-element.cjs.js +0 -175
- package/react/base/form-check-element.cjs.js.map +0 -1
- package/react/base/form-check-element.js +0 -170
- package/react/base/form-check-element.js.map +0 -1
- package/react/utils/form.cjs.js +0 -137
- package/react/utils/form.cjs.js.map +0 -1
- package/react/utils/form.js +0 -133
- package/react/utils/form.js.map +0 -1
- package/utils/form.js +0 -132
- package/utils/form.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A controller to help with form submission
|
|
3
|
+
*/
|
|
4
|
+
class FormSubmitController {
|
|
5
|
+
constructor(host, options) {
|
|
6
|
+
(this.host = host).addController(this);
|
|
7
|
+
this.options = Object.assign({ form: (input) => {
|
|
8
|
+
return input.closest("form");
|
|
9
|
+
} }, options);
|
|
10
|
+
}
|
|
11
|
+
hostConnected() {
|
|
12
|
+
this.form = this.options.form(this.host);
|
|
13
|
+
}
|
|
14
|
+
hostDisconnected() {
|
|
15
|
+
if (this.form) {
|
|
16
|
+
this.form = undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a temporary native HTML button that can participate in form and invoke form submits and reset
|
|
21
|
+
* Button is removed once action is performed
|
|
22
|
+
*/
|
|
23
|
+
doAction(type, invoker) {
|
|
24
|
+
if (this.form) {
|
|
25
|
+
const button = document.createElement("button");
|
|
26
|
+
button.type = type;
|
|
27
|
+
button.style.position = "absolute";
|
|
28
|
+
button.style.width = "0";
|
|
29
|
+
button.style.height = "0";
|
|
30
|
+
button.style.clipPath = "inset(50%)";
|
|
31
|
+
button.style.overflow = "hidden";
|
|
32
|
+
button.style.whiteSpace = "nowrap";
|
|
33
|
+
// Pass form attributes through to the temporary button
|
|
34
|
+
if (invoker) {
|
|
35
|
+
["formaction", "formmethod", "formnovalidate", "formtarget"].forEach(attr => {
|
|
36
|
+
if (invoker.hasAttribute(attr)) {
|
|
37
|
+
button.setAttribute(attr, invoker.getAttribute(attr));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.form.append(button);
|
|
42
|
+
button.click();
|
|
43
|
+
button.remove();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Resets the form, restoring all the control to their default value */
|
|
47
|
+
reset(invoker) {
|
|
48
|
+
this.doAction("reset", invoker);
|
|
49
|
+
}
|
|
50
|
+
/** Submits the form, triggering validation and form data injection. */
|
|
51
|
+
submit(invoker) {
|
|
52
|
+
// Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
|
|
53
|
+
// native submit button into the form, "click" it, then remove it to simulate a standard form submission.
|
|
54
|
+
this.doAction("submit", invoker);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { FormSubmitController };
|
|
59
|
+
//# sourceMappingURL=formSubmitController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formSubmitController.js","sources":["../../src/utils/formSubmitController.ts"],"sourcesContent":["import type SgdsButton from \"../components/Button/sgds-button\";\nimport type { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport SgdsElement from \"../base/sgds-element\";\nimport { SgdsInput } from \"../components\";\n\n/**\n * A controller to help with form submission\n */\nexport class FormSubmitController implements ReactiveController {\n host?: ReactiveControllerHost & Element;\n form?: HTMLFormElement | null;\n options: FormSubmitControllerOptions;\n\n constructor(host: ReactiveControllerHost & Element, options?: Partial<FormSubmitControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input: HTMLInputElement) => {\n return input.closest(\"form\");\n },\n ...options\n };\n }\n\n hostConnected() {\n this.form = this.options.form(this.host);\n }\n\n hostDisconnected() {\n if (this.form) {\n this.form = undefined;\n }\n }\n /**\n * Creates a temporary native HTML button that can participate in form and invoke form submits and reset\n * Button is removed once action is performed\n */\n doAction(type: \"submit\" | \"reset\", invoker?: HTMLInputElement | SgdsButton) {\n if (this.form) {\n const button = document.createElement(\"button\");\n button.type = type;\n button.style.position = \"absolute\";\n button.style.width = \"0\";\n button.style.height = \"0\";\n button.style.clipPath = \"inset(50%)\";\n button.style.overflow = \"hidden\";\n button.style.whiteSpace = \"nowrap\";\n\n // Pass form attributes through to the temporary button\n if (invoker) {\n [\"formaction\", \"formmethod\", \"formnovalidate\", \"formtarget\"].forEach(attr => {\n if (invoker.hasAttribute(attr)) {\n button.setAttribute(attr, invoker.getAttribute(attr));\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(invoker?: HTMLInputElement | SgdsButton) {\n this.doAction(\"reset\", invoker);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(invoker?: HTMLInputElement | SgdsButton) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction(\"submit\", invoker);\n }\n}\n\nexport interface FormSubmitControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: unknown) => HTMLFormElement | null;\n}\n\nexport interface SgdsFormControl extends SgdsElement {\n // Form attributes\n name: string;\n value: unknown;\n disabled?: boolean;\n defaultValue?: unknown;\n defaultChecked?: boolean;\n form?: HTMLFormElement;\n valid?: boolean;\n invalid?: boolean;\n\n // Constraint validation attributes\n pattern?: string;\n min?: number | string | Date;\n max?: number | string | Date;\n step?: number | \"any\";\n required?: boolean;\n minlength?: number;\n maxlength?: number;\n\n input?: HTMLInputElement | SgdsInput;\n}\n"],"names":[],"mappings":"AAKA;;AAEG;MACU,oBAAoB,CAAA;IAK/B,WAAY,CAAA,IAAsC,EAAE,OAA8C,EAAA;QAChG,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,GACV,MAAA,CAAA,MAAA,CAAA,EAAA,IAAI,EAAE,CAAC,KAAuB,KAAI;AAChC,gBAAA,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aA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C,MAAM,CAAC,CAAC;YACzB,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,MAAM,EAAE,CAAC;SACjB;KACF;;AAGD,IAAA,KAAK,CAAC,OAAuC,EAAA;AAC3C,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACjC;;AAGD,IAAA,MAAM,CAAC,OAAuC,EAAA;;;AAG5C,QAAA,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KAClC;AACF;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
+
import { SgdsCheckbox, SgdsInput } from "../components";
|
|
3
|
+
/**
|
|
4
|
+
* SGDS custom form validation methods and behaviours
|
|
5
|
+
*/
|
|
6
|
+
export declare class InputValidationController implements ReactiveController {
|
|
7
|
+
host: ReactiveControllerHost & HTMLElement;
|
|
8
|
+
_internals: ElementInternals;
|
|
9
|
+
validationError: keyof ValidityState;
|
|
10
|
+
options: InputValidationControllerOptions;
|
|
11
|
+
constructor(host: ReactiveControllerHost & HTMLElement, options?: Partial<InputValidationControllerOptions>);
|
|
12
|
+
hostConnected(): void;
|
|
13
|
+
hostDisconnected(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Prevents the native browser error message pop up when reportValidity() called by
|
|
16
|
+
* associated form or the component's reportValidity during constraint validation
|
|
17
|
+
* Sets invalid reactive prop to true
|
|
18
|
+
*/
|
|
19
|
+
handleInvalid(e: Event): void;
|
|
20
|
+
/**
|
|
21
|
+
* Sets invalid to false when invoked and
|
|
22
|
+
* Updates the ValidityState based on new value, but
|
|
23
|
+
* does not update invalid reactive prop
|
|
24
|
+
* @param e
|
|
25
|
+
*/
|
|
26
|
+
handleInput(e: Event): void;
|
|
27
|
+
/**
|
|
28
|
+
* Validate the input's new value after onChange and
|
|
29
|
+
* update invalid reactive prop
|
|
30
|
+
* @param e
|
|
31
|
+
*/
|
|
32
|
+
handleChange(e: Event): void;
|
|
33
|
+
get form(): HTMLFormElement;
|
|
34
|
+
get validity(): ValidityState;
|
|
35
|
+
get validationMessage(): string;
|
|
36
|
+
get willValidate(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Checks the validity and updates the invalid reactive prop of form components
|
|
39
|
+
*/
|
|
40
|
+
updateInvalidState(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Resets the ValidityState of the control
|
|
43
|
+
*/
|
|
44
|
+
resetValidity(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Reports the validity
|
|
47
|
+
*/
|
|
48
|
+
checkValidity(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Reports the validity with a error popup message
|
|
51
|
+
*/
|
|
52
|
+
reportValidity(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Sets the form control value into FormData,
|
|
55
|
+
* making the value of control accessible via FormData
|
|
56
|
+
*/
|
|
57
|
+
setFormValue(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Updates the ValidityState of the input in form component at current state
|
|
60
|
+
*/
|
|
61
|
+
validateInput(input: any): void;
|
|
62
|
+
}
|
|
63
|
+
export interface InputValidationControllerOptions {
|
|
64
|
+
/** A function that sets the value of host invalid reactive prop */
|
|
65
|
+
setInvalid: (host: ReactiveControllerHost & HTMLElement, value: boolean) => void;
|
|
66
|
+
/** A function that gets the value of host value reactive prop */
|
|
67
|
+
value: (host: ReactiveControllerHost & HTMLElement) => unknown;
|
|
68
|
+
/** A function that gets the input control of host value reactive prop */
|
|
69
|
+
input: (host: ReactiveController & HTMLElement) => HTMLInputElement | SgdsInput | SgdsCheckbox;
|
|
70
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SGDS custom form validation methods and behaviours
|
|
3
|
+
*/
|
|
4
|
+
class InputValidationController {
|
|
5
|
+
constructor(host, options) {
|
|
6
|
+
(this.host = host).addController(this);
|
|
7
|
+
this._internals = this.host.attachInternals();
|
|
8
|
+
this.options = Object.assign({ setInvalid: (host, value) => {
|
|
9
|
+
host.invalid = value;
|
|
10
|
+
}, value: (host) => {
|
|
11
|
+
return host.value;
|
|
12
|
+
}, input: (host) => host.input }, options);
|
|
13
|
+
}
|
|
14
|
+
hostConnected() {
|
|
15
|
+
this.host.addEventListener("invalid", e => this.handleInvalid(e));
|
|
16
|
+
}
|
|
17
|
+
hostDisconnected() {
|
|
18
|
+
this.host.removeEventListener("invalid", e => this.handleInvalid(e));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Prevents the native browser error message pop up when reportValidity() called by
|
|
22
|
+
* associated form or the component's reportValidity during constraint validation
|
|
23
|
+
* Sets invalid reactive prop to true
|
|
24
|
+
*/
|
|
25
|
+
handleInvalid(e) {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
this.options.setInvalid(this.host, true);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets invalid to false when invoked and
|
|
31
|
+
* Updates the ValidityState based on new value, but
|
|
32
|
+
* does not update invalid reactive prop
|
|
33
|
+
* @param e
|
|
34
|
+
*/
|
|
35
|
+
handleInput(e) {
|
|
36
|
+
const input = e.target;
|
|
37
|
+
this.options.setInvalid(this.host, false);
|
|
38
|
+
this.validateInput(input);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate the input's new value after onChange and
|
|
42
|
+
* update invalid reactive prop
|
|
43
|
+
* @param e
|
|
44
|
+
*/
|
|
45
|
+
handleChange(e) {
|
|
46
|
+
const input = e.target;
|
|
47
|
+
this.validateInput(input);
|
|
48
|
+
this.options.setInvalid(this.host, !this.checkValidity());
|
|
49
|
+
}
|
|
50
|
+
get form() {
|
|
51
|
+
return this._internals.form;
|
|
52
|
+
}
|
|
53
|
+
get validity() {
|
|
54
|
+
return this._internals.validity;
|
|
55
|
+
}
|
|
56
|
+
get validationMessage() {
|
|
57
|
+
return this._internals.validationMessage;
|
|
58
|
+
}
|
|
59
|
+
get willValidate() {
|
|
60
|
+
return this._internals.willValidate;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks the validity and updates the invalid reactive prop of form components
|
|
64
|
+
*/
|
|
65
|
+
updateInvalidState() {
|
|
66
|
+
this.options.setInvalid(this.host, !this.checkValidity());
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resets the ValidityState of the control
|
|
70
|
+
*/
|
|
71
|
+
resetValidity() {
|
|
72
|
+
return this._internals.setValidity({});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reports the validity
|
|
76
|
+
*/
|
|
77
|
+
checkValidity() {
|
|
78
|
+
return this._internals.checkValidity();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Reports the validity with a error popup message
|
|
82
|
+
*/
|
|
83
|
+
reportValidity() {
|
|
84
|
+
return this._internals.reportValidity();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sets the form control value into FormData,
|
|
88
|
+
* making the value of control accessible via FormData
|
|
89
|
+
*/
|
|
90
|
+
setFormValue() {
|
|
91
|
+
const value = this.options.value(this.host);
|
|
92
|
+
this._internals.setFormValue(value);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Updates the ValidityState of the input in form component at current state
|
|
96
|
+
*/
|
|
97
|
+
validateInput(input) {
|
|
98
|
+
/** When the form control is disabled, its always valid */
|
|
99
|
+
if (this.options.input(this.host).disabled) {
|
|
100
|
+
return this._internals.setValidity({});
|
|
101
|
+
}
|
|
102
|
+
// get the validity of the internal <input>
|
|
103
|
+
const validState = input.validity;
|
|
104
|
+
// if the input is invalid, show the correct error
|
|
105
|
+
if (!validState.valid) {
|
|
106
|
+
// loop through the error reasons
|
|
107
|
+
for (const state in validState) {
|
|
108
|
+
// if there is an error and corresponding attribute holding
|
|
109
|
+
// the message
|
|
110
|
+
if (validState[state]) {
|
|
111
|
+
this.validationError = state.toString();
|
|
112
|
+
// set the validity error reason and the corresponding
|
|
113
|
+
// message
|
|
114
|
+
this._internals.setValidity({ [this.validationError]: true }, input.validationMessage, input);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this._internals.setValidity({});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { InputValidationController };
|
|
125
|
+
//# sourceMappingURL=inputValidationController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputValidationController.js","sources":["../../src/utils/inputValidationController.ts"],"sourcesContent":["import { ReactiveController, ReactiveControllerHost } from \"lit\";\nimport { SgdsFormControl } from \"./formSubmitController\";\nimport { SgdsCheckbox, SgdsInput } from \"../components\";\n\n/**\n * SGDS custom form validation methods and behaviours\n */\nexport class InputValidationController implements ReactiveController {\n host: ReactiveControllerHost & HTMLElement;\n _internals: ElementInternals;\n validationError: keyof ValidityState;\n options: InputValidationControllerOptions;\n\n constructor(host: ReactiveControllerHost & HTMLElement, options?: Partial<InputValidationControllerOptions>) {\n (this.host = host).addController(this);\n this._internals = this.host.attachInternals();\n this.options = {\n setInvalid: (host: SgdsFormControl, value: boolean) => {\n host.invalid = value;\n },\n value: (host: SgdsFormControl) => {\n return host.value;\n },\n input: (host: SgdsFormControl) => host.input,\n ...options\n };\n }\n\n hostConnected(): void {\n this.host.addEventListener(\"invalid\", e => this.handleInvalid(e));\n }\n\n hostDisconnected(): void {\n this.host.removeEventListener(\"invalid\", e => this.handleInvalid(e));\n }\n /**\n * Prevents the native browser error message pop up when reportValidity() called by\n * associated form or the component's reportValidity during constraint validation\n * Sets invalid reactive prop to true\n */\n handleInvalid(e: Event) {\n e.preventDefault();\n this.options.setInvalid(this.host, true);\n }\n\n /**\n * Sets invalid to false when invoked and\n * Updates the ValidityState based on new value, but\n * does not update invalid reactive prop\n * @param e\n */\n handleInput(e: Event) {\n const input = e.target as HTMLInputElement;\n this.options.setInvalid(this.host, false);\n this.validateInput(input);\n }\n /**\n * Validate the input's new value after onChange and\n * update invalid reactive prop\n * @param e\n */\n handleChange(e: Event) {\n const input = e.target as HTMLInputElement;\n this.validateInput(input);\n this.options.setInvalid(this.host, !this.checkValidity());\n }\n\n get form() {\n return this._internals.form;\n }\n\n get validity() {\n return this._internals.validity;\n }\n\n get validationMessage() {\n return this._internals.validationMessage;\n }\n\n get willValidate() {\n return this._internals.willValidate;\n }\n /**\n * Checks the validity and updates the invalid reactive prop of form components\n */\n updateInvalidState() {\n this.options.setInvalid(this.host, !this.checkValidity());\n }\n /**\n * Resets the ValidityState of the control\n */\n resetValidity() {\n return this._internals.setValidity({});\n }\n /**\n * Reports the validity\n */\n checkValidity(): boolean {\n return this._internals.checkValidity();\n }\n /**\n * Reports the validity with a error popup message\n */\n reportValidity(): boolean {\n return this._internals.reportValidity();\n }\n /**\n * Sets the form control value into FormData,\n * making the value of control accessible via FormData\n */\n setFormValue() {\n const value = this.options.value(this.host) as string | FormData | File;\n this._internals.setFormValue(value);\n }\n /**\n * Updates the ValidityState of the input in form component at current state\n */\n validateInput(input) {\n /** When the form control is disabled, its always valid */\n if (this.options.input(this.host).disabled) {\n return this._internals.setValidity({});\n }\n // get the validity of the internal <input>\n const validState = input.validity;\n // if the input is invalid, show the correct error\n if (!validState.valid) {\n // loop through the error reasons\n for (const state in validState) {\n // if there is an error and corresponding attribute holding\n // the message\n if (validState[state]) {\n this.validationError = state.toString() as keyof ValidityState;\n\n // set the validity error reason and the corresponding\n // message\n this._internals.setValidity({ [this.validationError]: true }, input.validationMessage, input);\n }\n }\n } else {\n this._internals.setValidity({});\n }\n }\n}\n\nexport interface InputValidationControllerOptions {\n /** A function that sets the value of host invalid reactive prop */\n setInvalid: (host: ReactiveControllerHost & HTMLElement, value: boolean) => void;\n /** A function that gets the value of host value reactive prop */\n value: (host: ReactiveControllerHost & HTMLElement) => unknown;\n /** A function that gets the input control of host value reactive prop */\n input: (host: ReactiveController & HTMLElement) => HTMLInputElement | SgdsInput | SgdsC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G,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAA6B,CAAC;AACxE,QAAA,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;KACrC;AACD;;AAEG;AACH,IAAA,aAAa,CAAC,KAAK,EAAA;;AAEjB,QAAA,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;SACxC;;AAED,QAAA,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;;AAElC,QAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;;AAErB,YAAA,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;;;AAG9B,gBAAA,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE;AACrB,oBAAA,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,QAAQ,EAAyB,CAAC;;;oBAI/D,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,eAAe,GAAG,IAAI,EAAE,EAAE,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;iBAC/F;aACF;SACF;aAAM;AACL,YAAA,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;SACjC;KACF;AACF;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import { SgdsInput } from "../components";
|
|
3
|
+
import { InputValidationController } from "./inputValidationController";
|
|
4
|
+
type Constructor<T> = new (...args: any[]) => T;
|
|
5
|
+
/**
|
|
6
|
+
* @summary The FormValidationMixin used by the form components
|
|
7
|
+
* @param superClass
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const SgdsFormValidatorMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<ToBeValidatedElementInterface> & T;
|
|
11
|
+
export declare class ToBeValidatedElementInterface {
|
|
12
|
+
inputValidationController: InputValidationController;
|
|
13
|
+
input: HTMLInputElement;
|
|
14
|
+
_mixinHandleChange(e: Event): void;
|
|
15
|
+
_mixinHandleInputChange(e: Event): void;
|
|
16
|
+
_mixinResetValidity(input: HTMLInputElement | SgdsInput): void;
|
|
17
|
+
_mixinValidate(input: HTMLInputElement | SgdsInput): void;
|
|
18
|
+
_mixinSetFormValue(): void;
|
|
19
|
+
_mixinCheckValidity(): boolean;
|
|
20
|
+
_mixinReportValidity(): boolean;
|
|
21
|
+
_mixinGetValidity(): ValidityState;
|
|
22
|
+
_mixinGetValidationMessage(): string;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { queryAsync } from 'lit/decorators.js';
|
|
3
|
+
import { InputValidationController } from './inputValidationController.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @summary The FormValidationMixin used by the form components
|
|
7
|
+
* @param superClass
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
const SgdsFormValidatorMixin = (superClass) => {
|
|
11
|
+
class ToBeValidatedElement extends superClass {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this._isTouched = false;
|
|
15
|
+
}
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
super.connectedCallback();
|
|
18
|
+
this.inputValidationController = new InputValidationController(this);
|
|
19
|
+
}
|
|
20
|
+
async firstUpdated(changedProperties) {
|
|
21
|
+
super.firstUpdated(changedProperties);
|
|
22
|
+
/* Either input or sgds-input. For example, quantity-toggle uses sgds-input */
|
|
23
|
+
this.input =
|
|
24
|
+
this.shadowRoot.querySelector("input") || (await this.sgdsInput) || this.shadowRoot.querySelector("textarea");
|
|
25
|
+
this._mixinValidate(this.input);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Native lifecycle of Form-Associated Custom Element Callbacks
|
|
29
|
+
*/
|
|
30
|
+
formResetCallback() {
|
|
31
|
+
if (this._mixinResetFormControl) {
|
|
32
|
+
this._mixinResetFormControl();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.value = this.defaultValue;
|
|
36
|
+
this._mixinResetValidity(this.input);
|
|
37
|
+
}
|
|
38
|
+
this._mixinSetFormValue();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* Methods use by classes using this mixin
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* OnChange of form component
|
|
46
|
+
* 1. Make value of control accessible via FormData
|
|
47
|
+
* 2. Run change handler
|
|
48
|
+
*/
|
|
49
|
+
_mixinHandleChange(e) {
|
|
50
|
+
this._mixinSetFormValue();
|
|
51
|
+
this.inputValidationController.handleChange(e);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* OnChange of form component
|
|
55
|
+
* 1. Make value of control accessible via FormData
|
|
56
|
+
* 2. Run input handler
|
|
57
|
+
*/
|
|
58
|
+
_mixinHandleInputChange(e) {
|
|
59
|
+
this._mixinSetFormValue();
|
|
60
|
+
this.inputValidationController.handleInput(e);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* During form resetting,
|
|
64
|
+
* 1. ValidityState is reset
|
|
65
|
+
* 2. invalid reactive prop is updated after the reset
|
|
66
|
+
* 3. Revalidates the ValidityState (but do not update invalid prop)
|
|
67
|
+
* to prepare for the next validity check
|
|
68
|
+
* 4. Reset touched state to false for a pristine form
|
|
69
|
+
*/
|
|
70
|
+
_mixinResetValidity(input) {
|
|
71
|
+
this.inputValidationController.resetValidity();
|
|
72
|
+
this.inputValidationController.updateInvalidState();
|
|
73
|
+
this.inputValidationController.validateInput(input);
|
|
74
|
+
this._isTouched ? (this._isTouched = false) : null;
|
|
75
|
+
}
|
|
76
|
+
_mixinValidate(input) {
|
|
77
|
+
this.inputValidationController.validateInput(input);
|
|
78
|
+
}
|
|
79
|
+
_mixinSetFormValue() {
|
|
80
|
+
this.inputValidationController.setFormValue();
|
|
81
|
+
}
|
|
82
|
+
_mixinCheckValidity() {
|
|
83
|
+
return this.inputValidationController.checkValidity();
|
|
84
|
+
}
|
|
85
|
+
_mixinReportValidity() {
|
|
86
|
+
return this.inputValidationController.reportValidity();
|
|
87
|
+
}
|
|
88
|
+
_mixinGetValidity() {
|
|
89
|
+
return this.inputValidationController.validity;
|
|
90
|
+
}
|
|
91
|
+
_mixinGetValidationMessage() {
|
|
92
|
+
return this.inputValidationController.validationMessage;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
ToBeValidatedElement.formAssociated = true;
|
|
96
|
+
__decorate([
|
|
97
|
+
queryAsync("sgds-input")
|
|
98
|
+
], ToBeValidatedElement.prototype, "sgdsInput", void 0);
|
|
99
|
+
return ToBeValidatedElement;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { SgdsFormValidatorMixin };
|
|
103
|
+
//# sourceMappingURL=validatorMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatorMixin.js","sources":["../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n\n connectedCallback(): void {\n super.connectedCallback();\n this.inputValidationController = new InputValidationController(this);\n }\n async firstUpdated(changedProperties) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") || (await this.sgdsInput) || this.shadowRoot.querySelector(\"textarea\");\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset\n * 2. invalid reactive prop is updated after the reset\n * 3. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check\n * 4. Reset touched state to false for a pristine form\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this.inputValidationController.validateInput(input);\n this._isTouched ? (this._isTouched = false) : null;\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue() {\n this.inputValidationController.setFormValue();\n }\n _mixinCheckValidity(): boolean {\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this.inputValidationController.validity;\n }\n _mixinGetValidationMessage(): string {\n return this.inputValidationController.validationMessage;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n}\n"],"names":[],"mappings":";;;;AAQA;;;;AAIG;AACU,MAAA,sBAAsB,GAAG,CAAoC,UAAa,KAAI;IACzF,MAAM,oBAAqB,SAAQ,UAAU,CAAA;AAA7C,QAAA,WAAA,GAAA;;YAIU,IAAU,CAAA,UAAA,GAAG,KAAK,CAAC;SA8F5B;QA3FC,iBAAiB,GAAA;YACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,IAAI,CAAC,yBAAyB,GAAG,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAC;SACtE;QACD,MAAM,YAAY,CAAC,iBAAiB,EAAA;AAClC,YAAA,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;;AAGtC,YAAA,IAAI,CAAC,KAAK;gBACR,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AAChH,YAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;AAED;;AAEG;QACH,iBAAiB,GAAA;AACf,YAAA,IAAI,IAAI,CAAC,sBAAsB,EAAE;gBAC/B,IAAI,CAAC,sBA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AyB,CAAC,cAAc,EAAE,CAAC;SACxD;QACD,iBAAiB,GAAA;AACf,YAAA,OAAO,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC;SAChD;QACD,0BAA0B,GAAA;AACxB,YAAA,OAAO,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,CAAC;SACzD;;IAtFM,oBAAc,CAAA,cAAA,GAAG,IAAH,CAAQ;AAIH,IAAA,UAAA,CAAA;QAAzB,UAAU,CAAC,YAAY,CAAC;AAA+B,KAAA,EAAA,oBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AA+F1D,IAAA,OAAO,oBAAsE,CAAC;AAChF;;;;"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { SgdsFormControl } from "../utils/form";
|
|
2
|
-
import SgdsElement from "./sgds-element";
|
|
3
|
-
export declare class FormCheckElement extends SgdsElement implements SgdsFormControl {
|
|
4
|
-
/**@internal */
|
|
5
|
-
input: HTMLInputElement;
|
|
6
|
-
/**@internal */
|
|
7
|
-
private readonly formSubmitController;
|
|
8
|
-
/** Name of the HTML form control. Submitted with the form as part of a name/value pair. */
|
|
9
|
-
name: string;
|
|
10
|
-
/** For aria-label when there is no appropriate text label visible */
|
|
11
|
-
ariaLabel: string;
|
|
12
|
-
/** Value of the HTML form control. Primarily used to differentiate a list of related checkboxes that have the same name. */
|
|
13
|
-
value: string;
|
|
14
|
-
/** Makes the checkbox a required field. */
|
|
15
|
-
required: boolean;
|
|
16
|
-
/** Draws the checkbox in a checked state. */
|
|
17
|
-
checked: boolean;
|
|
18
|
-
/** Disables the checkbox (so the user can't check / uncheck it). */
|
|
19
|
-
disabled: boolean;
|
|
20
|
-
/** Allows invalidFeedback, invalid and valid styles to be visible with the input */
|
|
21
|
-
hasFeedback: boolean;
|
|
22
|
-
/** Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */
|
|
23
|
-
defaultChecked: boolean;
|
|
24
|
-
/** Marks the checkbox input as invalid. Replace the pseudo :invalid selector for absent in custom elements */
|
|
25
|
-
invalid: boolean;
|
|
26
|
-
/** Marks the checkbox input as indeterminate , with indeterminate logo */
|
|
27
|
-
indeterminate: boolean;
|
|
28
|
-
_handleInvalidChange(): void;
|
|
29
|
-
/** Simulates a click on the checkbox. */
|
|
30
|
-
click(): void;
|
|
31
|
-
/** Sets focus on the checkbox. */
|
|
32
|
-
focus(options?: FocusOptions): void;
|
|
33
|
-
/** Removes focus from the checkbox. */
|
|
34
|
-
blur(): void;
|
|
35
|
-
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
36
|
-
reportValidity(): boolean;
|
|
37
|
-
protected _handleChange(): void;
|
|
38
|
-
protected _handleKeyDown(event: KeyboardEvent): void;
|
|
39
|
-
protected _handleInvalid(e: Event): void;
|
|
40
|
-
/** @internal For Id/For pair of the HTML form control and label. */
|
|
41
|
-
protected _inputId: string;
|
|
42
|
-
/**@internal */
|
|
43
|
-
protected _size: string;
|
|
44
|
-
/** @internal */
|
|
45
|
-
handleDisabledChange(): void;
|
|
46
|
-
/** @internal */
|
|
47
|
-
handleStateChange(): void;
|
|
48
|
-
render(): import("lit-html").TemplateResult<1>;
|
|
49
|
-
}
|
|
50
|
-
export default FormCheckElement;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { html } from 'lit';
|
|
3
|
-
import { query, property } from 'lit/decorators.js';
|
|
4
|
-
import { classMap } from 'lit/directives/class-map.js';
|
|
5
|
-
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
6
|
-
import { defaultValue } from '../utils/defaultvalue.js';
|
|
7
|
-
import { FormSubmitController } from '../utils/form.js';
|
|
8
|
-
import { watch } from '../utils/watch.js';
|
|
9
|
-
import SgdsElement from './sgds-element.js';
|
|
10
|
-
|
|
11
|
-
class FormCheckElement extends SgdsElement {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
/**@internal */
|
|
15
|
-
this.formSubmitController = new FormSubmitController(this, {
|
|
16
|
-
value: (control) => (control.checked ? control.value : undefined),
|
|
17
|
-
defaultValue: (control) => control.defaultChecked,
|
|
18
|
-
setValue: (control, checked) => (control.checked = checked)
|
|
19
|
-
});
|
|
20
|
-
/** For aria-label when there is no appropriate text label visible */
|
|
21
|
-
this.ariaLabel = "checkbox";
|
|
22
|
-
/** Makes the checkbox a required field. */
|
|
23
|
-
this.required = false;
|
|
24
|
-
/** Draws the checkbox in a checked state. */
|
|
25
|
-
this.checked = false;
|
|
26
|
-
/** Disables the checkbox (so the user can't check / uncheck it). */
|
|
27
|
-
this.disabled = false;
|
|
28
|
-
/** Allows invalidFeedback, invalid and valid styles to be visible with the input */
|
|
29
|
-
this.hasFeedback = false;
|
|
30
|
-
/** Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */
|
|
31
|
-
this.defaultChecked = false;
|
|
32
|
-
/** Marks the checkbox input as invalid. Replace the pseudo :invalid selector for absent in custom elements */
|
|
33
|
-
this.invalid = false;
|
|
34
|
-
/** Marks the checkbox input as indeterminate , with indeterminate logo */
|
|
35
|
-
this.indeterminate = false;
|
|
36
|
-
}
|
|
37
|
-
_handleInvalidChange() {
|
|
38
|
-
this.emit("sgds-validity-change", { detail: { invalid: this.invalid } });
|
|
39
|
-
}
|
|
40
|
-
/** Simulates a click on the checkbox. */
|
|
41
|
-
click() {
|
|
42
|
-
this.input.click();
|
|
43
|
-
}
|
|
44
|
-
/** Sets focus on the checkbox. */
|
|
45
|
-
focus(options) {
|
|
46
|
-
this.input.focus(options);
|
|
47
|
-
}
|
|
48
|
-
/** Removes focus from the checkbox. */
|
|
49
|
-
blur() {
|
|
50
|
-
this.input.blur();
|
|
51
|
-
}
|
|
52
|
-
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
53
|
-
reportValidity() {
|
|
54
|
-
if (!this.input.reportValidity()) {
|
|
55
|
-
this.invalid = !this.input.checkValidity();
|
|
56
|
-
}
|
|
57
|
-
return this.input.reportValidity();
|
|
58
|
-
}
|
|
59
|
-
_handleChange() {
|
|
60
|
-
if (this.indeterminate) {
|
|
61
|
-
this.indeterminate = !this.indeterminate;
|
|
62
|
-
}
|
|
63
|
-
this.checked = !this.checked;
|
|
64
|
-
this.value = this.input.value;
|
|
65
|
-
this.emit("sgds-change", { detail: { checked: this.checked, value: this.value } });
|
|
66
|
-
}
|
|
67
|
-
_handleKeyDown(event) {
|
|
68
|
-
const hasModifier = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;
|
|
69
|
-
if (event.key === "Enter" && !hasModifier) {
|
|
70
|
-
this.click();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
_handleInvalid(e) {
|
|
74
|
-
e.preventDefault();
|
|
75
|
-
this.invalid = true;
|
|
76
|
-
}
|
|
77
|
-
/** @internal */
|
|
78
|
-
handleDisabledChange() {
|
|
79
|
-
// Disabled form controls are always valid, so we need to recheck validity when the state changes
|
|
80
|
-
this.input.disabled = this.disabled;
|
|
81
|
-
this.invalid = !this.input.checkValidity();
|
|
82
|
-
}
|
|
83
|
-
/** @internal */
|
|
84
|
-
handleStateChange() {
|
|
85
|
-
this.invalid = !this.input.checkValidity();
|
|
86
|
-
}
|
|
87
|
-
render() {
|
|
88
|
-
return html `
|
|
89
|
-
<div
|
|
90
|
-
class=${classMap({
|
|
91
|
-
"form-check": true
|
|
92
|
-
})}
|
|
93
|
-
>
|
|
94
|
-
<input
|
|
95
|
-
class=${classMap({
|
|
96
|
-
"form-check-input": true,
|
|
97
|
-
"is-invalid": this.hasFeedback && this.invalid,
|
|
98
|
-
md: this._size === "md"
|
|
99
|
-
})}
|
|
100
|
-
type="checkbox"
|
|
101
|
-
id=${this._inputId}
|
|
102
|
-
aria-invalid=${this.invalid ? "true" : "false"}
|
|
103
|
-
name=${ifDefined(this.name)}
|
|
104
|
-
value=${ifDefined(this.value)}
|
|
105
|
-
?checked=${this.checked}
|
|
106
|
-
?indeterminate=${this.indeterminate}
|
|
107
|
-
?disabled=${this.disabled}
|
|
108
|
-
?required=${this.required}
|
|
109
|
-
aria-disabled=${this.disabled ? "true" : "false"}
|
|
110
|
-
aria-checked=${this.checked ? "true" : "false"}
|
|
111
|
-
@change=${this._handleChange}
|
|
112
|
-
@keydown=${this._handleKeyDown}
|
|
113
|
-
@invalid=${(e) => this._handleInvalid(e)}
|
|
114
|
-
/>
|
|
115
|
-
<label for="${this._inputId}" aria-label=${ifDefined(this.ariaLabel)} class="form-check-label"
|
|
116
|
-
><slot></slot
|
|
117
|
-
></label>
|
|
118
|
-
</div>
|
|
119
|
-
`;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
__decorate([
|
|
123
|
-
query('input[type="checkbox"]')
|
|
124
|
-
], FormCheckElement.prototype, "input", void 0);
|
|
125
|
-
__decorate([
|
|
126
|
-
property({ type: String, reflect: true })
|
|
127
|
-
], FormCheckElement.prototype, "name", void 0);
|
|
128
|
-
__decorate([
|
|
129
|
-
property({ type: String, reflect: true })
|
|
130
|
-
], FormCheckElement.prototype, "ariaLabel", void 0);
|
|
131
|
-
__decorate([
|
|
132
|
-
property({ type: String, reflect: true })
|
|
133
|
-
], FormCheckElement.prototype, "value", void 0);
|
|
134
|
-
__decorate([
|
|
135
|
-
property({ type: Boolean, reflect: true })
|
|
136
|
-
], FormCheckElement.prototype, "required", void 0);
|
|
137
|
-
__decorate([
|
|
138
|
-
property({ type: Boolean, reflect: true })
|
|
139
|
-
], FormCheckElement.prototype, "checked", void 0);
|
|
140
|
-
__decorate([
|
|
141
|
-
property({ type: Boolean, reflect: true })
|
|
142
|
-
], FormCheckElement.prototype, "disabled", void 0);
|
|
143
|
-
__decorate([
|
|
144
|
-
property({ type: Boolean, reflect: true })
|
|
145
|
-
], FormCheckElement.prototype, "hasFeedback", void 0);
|
|
146
|
-
__decorate([
|
|
147
|
-
defaultValue("checked")
|
|
148
|
-
], FormCheckElement.prototype, "defaultChecked", void 0);
|
|
149
|
-
__decorate([
|
|
150
|
-
property({ type: Boolean, reflect: true })
|
|
151
|
-
], FormCheckElement.prototype, "invalid", void 0);
|
|
152
|
-
__decorate([
|
|
153
|
-
property({ type: Boolean, reflect: true })
|
|
154
|
-
], FormCheckElement.prototype, "indeterminate", void 0);
|
|
155
|
-
__decorate([
|
|
156
|
-
watch("invalid", { waitUntilFirstUpdate: true })
|
|
157
|
-
], FormCheckElement.prototype, "_handleInvalidChange", null);
|
|
158
|
-
__decorate([
|
|
159
|
-
property({ type: String })
|
|
160
|
-
], FormCheckElement.prototype, "_size", void 0);
|
|
161
|
-
__decorate([
|
|
162
|
-
watch("disabled", { waitUntilFirstUpdate: true })
|
|
163
|
-
], FormCheckElement.prototype, "handleDisabledChange", null);
|
|
164
|
-
__decorate([
|
|
165
|
-
watch("checked", { waitUntilFirstUpdate: true })
|
|
166
|
-
], FormCheckElement.prototype, "handleStateChange", null);
|
|
167
|
-
|
|
168
|
-
export { FormCheckElement, FormCheckElement as default };
|
|
169
|
-
//# sourceMappingURL=form-check-element.js.map
|