@boostdev/design-system-components 1.1.1 → 1.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/AGENTS.md +13 -10
- package/dist/client.cjs +77 -99
- package/dist/client.css +611 -580
- package/dist/client.d.cts +13 -16
- package/dist/client.d.ts +13 -16
- package/dist/client.js +87 -109
- package/dist/index.cjs +77 -99
- package/dist/index.css +611 -580
- package/dist/index.d.cts +13 -16
- package/dist/index.d.ts +13 -16
- package/dist/index.js +87 -109
- package/dist/native/index.cjs +9 -8
- package/dist/native/index.d.cts +1 -1
- package/dist/native/index.d.ts +1 -1
- package/dist/native/index.js +9 -8
- package/dist/web-components/chunk-2QA62WCQ.js +48 -0
- package/dist/web-components/chunk-3REOIRDW.js +246 -0
- package/dist/web-components/chunk-57TRNCWQ.js +93 -0
- package/dist/web-components/chunk-5IPHEONG.js +139 -0
- package/dist/web-components/chunk-5R6IFELV.js +63 -0
- package/dist/web-components/chunk-5TFWOPLH.js +49 -0
- package/dist/web-components/chunk-6I3CFC26.js +89 -0
- package/dist/web-components/chunk-6MH5UWUD.js +226 -0
- package/dist/web-components/chunk-7FMR53BW.js +127 -0
- package/dist/web-components/chunk-AGKJTMJI.js +56 -0
- package/dist/web-components/chunk-AJSXNDAP.js +151 -0
- package/dist/web-components/chunk-BQLZ7I4G.js +56 -0
- package/dist/web-components/chunk-BX3IPVOB.js +167 -0
- package/dist/web-components/chunk-CR5PGUHV.js +109 -0
- package/dist/web-components/chunk-DI46Q2EA.js +278 -0
- package/dist/web-components/chunk-DZRSJGPB.js +53 -0
- package/dist/web-components/chunk-EBJM3VD4.js +107 -0
- package/dist/web-components/chunk-ECW3HHWA.js +185 -0
- package/dist/web-components/chunk-HGBNDR22.js +98 -0
- package/dist/web-components/chunk-HHHRF2PS.js +118 -0
- package/dist/web-components/chunk-ITHLKR7Q.js +105 -0
- package/dist/web-components/chunk-JUKB3BUP.js +186 -0
- package/dist/web-components/chunk-L3XHOMN6.js +111 -0
- package/dist/{web-components.js → web-components/chunk-LGEZYFUU.js} +62 -844
- package/dist/web-components/chunk-LY62SAVN.js +64 -0
- package/dist/web-components/chunk-N6IMUOY4.js +185 -0
- package/dist/web-components/chunk-OHUTLSIQ.js +69 -0
- package/dist/web-components/chunk-OQTRTMAB.js +27 -0
- package/dist/web-components/chunk-PY62FTRW.js +179 -0
- package/dist/web-components/chunk-Q4T5BJT6.js +94 -0
- package/dist/web-components/chunk-QDST57JC.js +119 -0
- package/dist/web-components/chunk-QLZ2362S.js +279 -0
- package/dist/web-components/chunk-QPOKHLMQ.js +45 -0
- package/dist/web-components/chunk-SOQQ7RVJ.js +88 -0
- package/dist/web-components/chunk-T6AETZRP.js +131 -0
- package/dist/web-components/chunk-UFFCKVZE.js +149 -0
- package/dist/web-components/chunk-VMMVWLXL.js +53 -0
- package/dist/web-components/chunk-X3FKVHLK.js +144 -0
- package/dist/web-components/chunk-XNA6WTXG.js +133 -0
- package/dist/web-components/chunk-Y4MAXTMA.js +80 -0
- package/dist/web-components/chunk-YLVTEY23.js +165 -0
- package/dist/web-components/chunk-YRXCVKHV.js +116 -0
- package/dist/web-components/chunk-ZTC6GRP7.js +64 -0
- package/dist/web-components/globals.d.ts +2 -0
- package/dist/web-components/globals.js +1 -0
- package/dist/web-components/index.d.ts +41 -0
- package/dist/web-components/index.js +165 -0
- package/dist/web-components/interaction/bds-accordion-item.d.ts +54 -0
- package/dist/web-components/interaction/bds-accordion-item.js +7 -0
- package/dist/web-components/interaction/bds-accordion.d.ts +50 -0
- package/dist/web-components/interaction/bds-accordion.js +7 -0
- package/dist/web-components/interaction/bds-button.d.ts +100 -0
- package/dist/web-components/interaction/bds-button.js +7 -0
- package/dist/web-components/interaction/bds-collapsible.d.ts +52 -0
- package/dist/web-components/interaction/bds-collapsible.js +7 -0
- package/dist/web-components/interaction/bds-dialog.d.ts +56 -0
- package/dist/web-components/interaction/bds-dialog.js +7 -0
- package/dist/web-components/interaction/bds-drawer.d.ts +64 -0
- package/dist/web-components/interaction/bds-drawer.js +7 -0
- package/dist/web-components/interaction/bds-popover.d.ts +62 -0
- package/dist/web-components/interaction/bds-popover.js +7 -0
- package/dist/web-components/interaction/bds-skip-link.d.ts +36 -0
- package/dist/web-components/interaction/bds-skip-link.js +7 -0
- package/dist/web-components/interaction/bds-tab-panel.d.ts +26 -0
- package/dist/web-components/interaction/bds-tab-panel.js +7 -0
- package/dist/web-components/interaction/bds-tab.d.ts +45 -0
- package/dist/web-components/interaction/bds-tab.js +7 -0
- package/dist/web-components/interaction/bds-tabs.d.ts +46 -0
- package/dist/web-components/interaction/bds-tabs.js +7 -0
- package/dist/web-components/interaction/bds-toast-provider.d.ts +57 -0
- package/dist/web-components/interaction/bds-toast-provider.js +7 -0
- package/dist/web-components/interaction/bds-tooltip.d.ts +50 -0
- package/dist/web-components/interaction/bds-tooltip.js +7 -0
- package/dist/web-components/interaction/form/bds-checkbox.d.ts +70 -0
- package/dist/web-components/interaction/form/bds-checkbox.js +7 -0
- package/dist/web-components/interaction/form/bds-combobox.d.ts +84 -0
- package/dist/web-components/interaction/form/bds-combobox.js +7 -0
- package/dist/web-components/interaction/form/bds-file-input.d.ts +62 -0
- package/dist/web-components/interaction/form/bds-file-input.js +7 -0
- package/dist/web-components/interaction/form/bds-number-input.d.ts +68 -0
- package/dist/web-components/interaction/form/bds-number-input.js +7 -0
- package/dist/web-components/interaction/form/bds-radio.d.ts +68 -0
- package/dist/web-components/interaction/form/bds-radio.js +7 -0
- package/dist/web-components/interaction/form/bds-segmented-control.d.ts +88 -0
- package/dist/web-components/interaction/form/bds-segmented-control.js +7 -0
- package/dist/web-components/interaction/form/bds-select.d.ts +79 -0
- package/dist/web-components/interaction/form/bds-select.js +7 -0
- package/dist/web-components/interaction/form/bds-slider.d.ts +70 -0
- package/dist/web-components/interaction/form/bds-slider.js +7 -0
- package/dist/web-components/interaction/form/bds-switch.d.ts +67 -0
- package/dist/web-components/interaction/form/bds-switch.js +7 -0
- package/dist/web-components/interaction/form/bds-textarea.d.ts +70 -0
- package/dist/web-components/interaction/form/bds-textarea.js +7 -0
- package/dist/web-components/ui/bds-alert.d.ts +66 -0
- package/dist/web-components/ui/bds-alert.js +7 -0
- package/dist/web-components/ui/bds-avatar.d.ts +50 -0
- package/dist/web-components/ui/bds-avatar.js +7 -0
- package/dist/web-components/ui/bds-badge.d.ts +35 -0
- package/dist/web-components/ui/bds-badge.js +7 -0
- package/dist/web-components/ui/bds-breadcrumb.d.ts +35 -0
- package/dist/web-components/ui/bds-breadcrumb.js +7 -0
- package/dist/web-components/ui/bds-card.d.ts +72 -0
- package/dist/web-components/ui/bds-card.js +7 -0
- package/dist/web-components/ui/bds-description-list.d.ts +42 -0
- package/dist/web-components/ui/bds-description-list.js +7 -0
- package/dist/web-components/ui/bds-icon-wrapper.d.ts +39 -0
- package/dist/web-components/ui/bds-icon-wrapper.js +7 -0
- package/dist/web-components/ui/bds-link.d.ts +59 -0
- package/dist/web-components/ui/bds-link.js +7 -0
- package/dist/web-components/ui/bds-loading.d.ts +32 -0
- package/dist/web-components/ui/bds-loading.js +7 -0
- package/dist/web-components/ui/bds-notification-banner.d.ts +61 -0
- package/dist/web-components/ui/bds-notification-banner.js +7 -0
- package/dist/web-components/ui/bds-progress-circle.d.ts +53 -0
- package/dist/web-components/ui/bds-progress-circle.js +7 -0
- package/dist/web-components/ui/bds-progress.d.ts +54 -0
- package/dist/web-components/ui/bds-progress.js +7 -0
- package/dist/web-components/ui/bds-rating.d.ts +36 -0
- package/dist/web-components/ui/bds-rating.js +7 -0
- package/dist/web-components/ui/bds-section-header.d.ts +53 -0
- package/dist/web-components/ui/bds-section-header.js +8 -0
- package/dist/web-components/ui/bds-separator.d.ts +32 -0
- package/dist/web-components/ui/bds-separator.js +7 -0
- package/dist/web-components/ui/bds-skeleton.d.ts +22 -0
- package/dist/web-components/ui/bds-skeleton.js +7 -0
- package/dist/web-components/ui/bds-typography.d.ts +44 -0
- package/dist/web-components/ui/bds-typography.js +8 -0
- package/package.json +170 -5
- package/src/components/interaction/Button/Button.module.css +12 -11
- package/src/components/interaction/Button/Button.native.tsx +10 -9
- package/src/components/interaction/Button/Button.tsx +1 -1
- package/src/components/interaction/Command/Command.module.css +3 -7
- package/src/components/interaction/Dialog/Dialog.module.css +7 -5
- package/src/components/interaction/Drawer/Drawer.module.css +49 -1
- package/src/components/interaction/DropdownMenu/DropdownMenu.module.css +1 -3
- package/src/components/interaction/Popover/Popover.module.css +1 -3
- package/src/components/interaction/form/Checkbox/Checkbox.module.css +1 -3
- package/src/components/interaction/form/Combobox/Combobox.module.css +2 -6
- package/src/components/interaction/form/FormInput/FormInput.module.css +1 -3
- package/src/components/interaction/form/NumberInput/NumberInput.module.css +16 -4
- package/src/components/interaction/form/Radio/Radio.module.css +6 -16
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.mdx +70 -25
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.module.css +55 -33
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.spec.tsx +127 -56
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.stories.tsx +89 -72
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.tsx +40 -62
- package/src/components/interaction/form/SegmentedControl/index.ts +1 -1
- package/src/components/interaction/form/Select/Select.module.css +2 -4
- package/src/components/interaction/form/Switch/Switch.module.css +5 -7
- package/src/components/interaction/form/Switch/Switch.native.spec.tsx +9 -9
- package/src/components/interaction/form/Switch/Switch.native.tsx +2 -2
- package/src/components/interaction/form/Textarea/Textarea.module.css +1 -3
- package/src/components/interaction/form/atoms/InputContainer.stories.tsx +64 -0
- package/src/components/interaction/form/atoms/Label.stories.tsx +33 -0
- package/src/components/interaction/form/atoms/Message.stories.tsx +33 -0
- package/src/components/layout/Card/Card.module.css +1 -3
- package/src/components/ui/Accordion/Accordion.module.css +1 -2
- package/src/components/ui/Alert/Alert.module.css +1 -2
- package/src/components/ui/Calendar/Calendar.module.css +2 -5
- package/src/components/ui/Carousel/Carousel.module.css +1 -3
- package/src/components/ui/NotificationBanner/NotificationBanner.module.css +1 -2
- package/src/components/ui/Pagination/Pagination.module.css +1 -2
- package/src/components/ui/SkipLink/SkipLink.module.css +1 -2
- package/src/components/ui/Table/Table.module.css +1 -2
- package/src/css/bdc.css +16 -11
- package/src/index.ts +1 -1
- package/src/web-components/globals.ts +3 -3
- package/src/web-components/index.ts +47 -0
- package/src/web-components/interaction/BdsAccordion.mdx +51 -0
- package/src/web-components/interaction/BdsAccordion.stories.tsx +85 -0
- package/src/web-components/interaction/BdsCollapsible.mdx +46 -0
- package/src/web-components/interaction/BdsCollapsible.stories.tsx +87 -0
- package/src/web-components/interaction/BdsDialog.mdx +49 -0
- package/src/web-components/interaction/BdsDialog.stories.tsx +75 -0
- package/src/web-components/interaction/BdsDrawer.mdx +50 -0
- package/src/web-components/interaction/BdsDrawer.stories.tsx +66 -0
- package/src/web-components/interaction/BdsSkipLink.mdx +34 -0
- package/src/web-components/interaction/BdsSkipLink.stories.tsx +55 -0
- package/src/web-components/interaction/BdsTabs.mdx +47 -0
- package/src/web-components/interaction/BdsTabs.stories.tsx +80 -0
- package/src/web-components/interaction/BdsTooltip.mdx +38 -0
- package/src/web-components/interaction/BdsTooltip.stories.tsx +68 -0
- package/src/web-components/interaction/bds-accordion-item.spec.ts +75 -0
- package/src/web-components/interaction/bds-accordion-item.ts +181 -0
- package/src/web-components/interaction/bds-accordion.spec.ts +73 -0
- package/src/web-components/interaction/bds-accordion.ts +98 -0
- package/src/web-components/interaction/bds-button.ts +15 -13
- package/src/web-components/interaction/bds-collapsible.spec.ts +56 -0
- package/src/web-components/interaction/bds-collapsible.ts +170 -0
- package/src/web-components/interaction/bds-dialog.spec.ts +119 -0
- package/src/web-components/interaction/bds-dialog.ts +221 -0
- package/src/web-components/interaction/bds-drawer.spec.ts +113 -0
- package/src/web-components/interaction/bds-drawer.ts +315 -0
- package/src/web-components/interaction/bds-skip-link.spec.ts +42 -0
- package/src/web-components/interaction/bds-skip-link.ts +74 -0
- package/src/web-components/interaction/bds-tab-panel.spec.ts +32 -0
- package/src/web-components/interaction/bds-tab-panel.ts +38 -0
- package/src/web-components/interaction/bds-tab.spec.ts +71 -0
- package/src/web-components/interaction/bds-tab.ts +110 -0
- package/src/web-components/interaction/bds-tabs.spec.ts +120 -0
- package/src/web-components/interaction/bds-tabs.ts +152 -0
- package/src/web-components/interaction/bds-tooltip.spec.ts +49 -0
- package/src/web-components/interaction/bds-tooltip.ts +127 -0
- package/src/web-components/interaction/form/BdsCheckbox.mdx +39 -0
- package/src/web-components/interaction/form/BdsCheckbox.stories.tsx +73 -0
- package/src/web-components/interaction/form/BdsCombobox.mdx +52 -0
- package/src/web-components/interaction/form/BdsCombobox.stories.tsx +91 -0
- package/src/web-components/interaction/form/BdsFileInput.mdx +44 -0
- package/src/web-components/interaction/form/BdsFileInput.stories.tsx +84 -0
- package/src/web-components/interaction/form/BdsNumberInput.mdx +41 -0
- package/src/web-components/interaction/form/BdsNumberInput.stories.tsx +90 -0
- package/src/web-components/interaction/form/BdsRadio.mdx +41 -0
- package/src/web-components/interaction/form/BdsRadio.stories.tsx +90 -0
- package/src/web-components/interaction/form/BdsSegmentedControl.mdx +42 -0
- package/src/web-components/interaction/form/BdsSegmentedControl.stories.tsx +92 -0
- package/src/web-components/interaction/form/BdsSelect.mdx +38 -0
- package/src/web-components/interaction/form/BdsSelect.stories.tsx +93 -0
- package/src/web-components/interaction/form/BdsSlider.mdx +49 -0
- package/src/web-components/interaction/form/BdsSlider.stories.tsx +89 -0
- package/src/web-components/interaction/form/BdsSwitch.mdx +39 -0
- package/src/web-components/interaction/form/BdsSwitch.stories.tsx +73 -0
- package/src/web-components/interaction/form/BdsTextarea.mdx +41 -0
- package/src/web-components/interaction/form/BdsTextarea.stories.tsx +79 -0
- package/src/web-components/interaction/form/bds-checkbox.spec.ts +63 -0
- package/src/web-components/interaction/form/bds-checkbox.ts +166 -0
- package/src/web-components/interaction/form/bds-combobox.spec.ts +117 -0
- package/src/web-components/interaction/form/bds-combobox.ts +334 -0
- package/src/web-components/interaction/form/bds-file-input.spec.ts +58 -0
- package/src/web-components/interaction/form/bds-file-input.ts +209 -0
- package/src/web-components/interaction/form/bds-number-input.spec.ts +87 -0
- package/src/web-components/interaction/form/bds-number-input.ts +220 -0
- package/src/web-components/interaction/form/bds-radio.spec.ts +70 -0
- package/src/web-components/interaction/form/bds-radio.ts +151 -0
- package/src/web-components/interaction/form/bds-segmented-control.spec.ts +74 -0
- package/src/web-components/interaction/form/bds-segmented-control.ts +282 -0
- package/src/web-components/interaction/form/bds-select.spec.ts +74 -0
- package/src/web-components/interaction/form/bds-select.ts +188 -0
- package/src/web-components/interaction/form/bds-slider.spec.ts +41 -0
- package/src/web-components/interaction/form/bds-slider.ts +162 -0
- package/src/web-components/interaction/form/bds-switch.spec.ts +62 -0
- package/src/web-components/interaction/form/bds-switch.ts +165 -0
- package/src/web-components/interaction/form/bds-textarea.spec.ts +55 -0
- package/src/web-components/interaction/form/bds-textarea.ts +141 -0
- package/src/web-components/ui/BdsAvatar.mdx +67 -0
- package/src/web-components/ui/BdsAvatar.stories.tsx +62 -0
- package/src/web-components/ui/BdsBreadcrumb.mdx +63 -0
- package/src/web-components/ui/BdsBreadcrumb.stories.tsx +59 -0
- package/src/web-components/ui/BdsCard.mdx +83 -0
- package/src/web-components/ui/BdsCard.stories.tsx +90 -0
- package/src/web-components/ui/BdsDescriptionList.mdx +67 -0
- package/src/web-components/ui/BdsDescriptionList.stories.tsx +79 -0
- package/src/web-components/ui/BdsIconWrapper.mdx +70 -0
- package/src/web-components/ui/BdsIconWrapper.stories.tsx +76 -0
- package/src/web-components/ui/BdsLink.mdx +75 -0
- package/src/web-components/ui/BdsLink.stories.tsx +64 -0
- package/src/web-components/ui/BdsLoading.mdx +62 -0
- package/src/web-components/ui/BdsLoading.stories.tsx +37 -0
- package/src/web-components/ui/BdsNotificationBanner.mdx +90 -0
- package/src/web-components/ui/BdsNotificationBanner.stories.tsx +93 -0
- package/src/web-components/ui/BdsProgress.mdx +63 -0
- package/src/web-components/ui/BdsProgress.stories.tsx +70 -0
- package/src/web-components/ui/BdsProgressCircle.mdx +64 -0
- package/src/web-components/ui/BdsProgressCircle.stories.tsx +69 -0
- package/src/web-components/ui/BdsRating.mdx +61 -0
- package/src/web-components/ui/BdsRating.stories.tsx +39 -0
- package/src/web-components/ui/BdsSectionHeader.mdx +69 -0
- package/src/web-components/ui/BdsSectionHeader.stories.tsx +56 -0
- package/src/web-components/ui/BdsSeparator.mdx +63 -0
- package/src/web-components/ui/BdsSeparator.stories.tsx +47 -0
- package/src/web-components/ui/BdsSkeleton.mdx +67 -0
- package/src/web-components/ui/BdsSkeleton.stories.tsx +50 -0
- package/src/web-components/ui/BdsTypography.mdx +83 -0
- package/src/web-components/ui/BdsTypography.stories.tsx +51 -0
- package/src/web-components/ui/bds-alert.ts +1 -2
- package/src/web-components/ui/bds-avatar.spec.ts +75 -0
- package/src/web-components/ui/bds-avatar.ts +122 -0
- package/src/web-components/ui/bds-breadcrumb.spec.ts +55 -0
- package/src/web-components/ui/bds-breadcrumb.ts +114 -0
- package/src/web-components/ui/bds-card.spec.ts +70 -0
- package/src/web-components/ui/bds-card.ts +154 -0
- package/src/web-components/ui/bds-description-list.spec.ts +36 -0
- package/src/web-components/ui/bds-description-list.ts +79 -0
- package/src/web-components/ui/bds-icon-wrapper.spec.ts +21 -0
- package/src/web-components/ui/bds-icon-wrapper.ts +68 -0
- package/src/web-components/ui/bds-link.spec.ts +72 -0
- package/src/web-components/ui/bds-link.ts +138 -0
- package/src/web-components/ui/bds-loading.spec.ts +38 -0
- package/src/web-components/ui/bds-loading.ts +76 -0
- package/src/web-components/ui/bds-notification-banner.spec.ts +82 -0
- package/src/web-components/ui/bds-notification-banner.ts +184 -0
- package/src/web-components/ui/bds-progress-circle.spec.ts +58 -0
- package/src/web-components/ui/bds-progress-circle.ts +142 -0
- package/src/web-components/ui/bds-progress.spec.ts +66 -0
- package/src/web-components/ui/bds-progress.ts +127 -0
- package/src/web-components/ui/bds-rating.spec.ts +70 -0
- package/src/web-components/ui/bds-rating.ts +80 -0
- package/src/web-components/ui/bds-section-header.spec.ts +57 -0
- package/src/web-components/ui/bds-section-header.ts +96 -0
- package/src/web-components/ui/bds-separator.spec.ts +50 -0
- package/src/web-components/ui/bds-separator.ts +66 -0
- package/src/web-components/ui/bds-skeleton.spec.ts +22 -0
- package/src/web-components/ui/bds-skeleton.ts +55 -0
- package/src/web-components/ui/bds-typography.spec.ts +76 -0
- package/src/web-components/ui/bds-typography.ts +112 -0
- package/dist/web-components.d.ts +0 -304
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<bds-file-input>` — form-associated File Input with drag-and-drop zone.
|
|
5
|
+
*
|
|
6
|
+
* Attributes:
|
|
7
|
+
* name — form field name
|
|
8
|
+
* accept — file types to accept (e.g. "image/*,.pdf")
|
|
9
|
+
* multiple — boolean; allow selecting multiple files
|
|
10
|
+
* disabled — boolean
|
|
11
|
+
*
|
|
12
|
+
* Events:
|
|
13
|
+
* bds-change — fired with `{ detail: FileList }` when files are selected
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <bds-file-input name="avatar" accept="image/*">Upload photo</bds-file-input>
|
|
17
|
+
*/
|
|
18
|
+
export class BdsFileInput extends LitElement {
|
|
19
|
+
static formAssociated = true;
|
|
20
|
+
|
|
21
|
+
static styles = css`
|
|
22
|
+
:host {
|
|
23
|
+
display: block;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host([disabled]) {
|
|
27
|
+
opacity: 0.5;
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.zone {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
gap: var(--bds-space_s);
|
|
37
|
+
padding: var(--bds-space_xl);
|
|
38
|
+
border-radius: var(--bds-border_radius--m);
|
|
39
|
+
border: 2px dashed var(--file-input_border-color, var(--bds-color_bg--subtle));
|
|
40
|
+
background-color: var(--file-input_color_bg, var(--bds-color_bg));
|
|
41
|
+
color: var(--bds-color_on-bg);
|
|
42
|
+
font-family: var(--bds-font_family--body);
|
|
43
|
+
font-size: var(--bds-font_size--body);
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
text-align: center;
|
|
46
|
+
transition: var(--bds-animation_transition);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.zone.--dragging {
|
|
50
|
+
border-color: var(--bds-color_interactive);
|
|
51
|
+
background-color: var(--bds-color_bg--subtle);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.zone-input {
|
|
55
|
+
position: absolute;
|
|
56
|
+
opacity: 0;
|
|
57
|
+
inline-size: 0;
|
|
58
|
+
block-size: 0;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.zone-label {
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
align-items: center;
|
|
66
|
+
gap: var(--bds-space_xs);
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.icon {
|
|
71
|
+
inline-size: 2.5rem;
|
|
72
|
+
block-size: 2.5rem;
|
|
73
|
+
color: var(--bds-color_on-bg--subtle);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.icon svg {
|
|
77
|
+
inline-size: 100%;
|
|
78
|
+
block-size: 100%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.hint {
|
|
82
|
+
font-size: var(--bds-font_size--body--s);
|
|
83
|
+
color: var(--bds-color_on-bg--subtle);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@media (hover: hover) and (pointer: fine) {
|
|
87
|
+
.zone:hover {
|
|
88
|
+
border-color: var(--bds-color_interactive);
|
|
89
|
+
background-color: var(--bds-color_bg--subtle);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
static properties = {
|
|
95
|
+
name: { type: String, reflect: true },
|
|
96
|
+
accept: { type: String },
|
|
97
|
+
multiple: { type: Boolean, reflect: true },
|
|
98
|
+
disabled: { type: Boolean, reflect: true },
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
declare name: string;
|
|
102
|
+
declare accept: string;
|
|
103
|
+
declare multiple: boolean;
|
|
104
|
+
declare disabled: boolean;
|
|
105
|
+
|
|
106
|
+
private _internals!: ElementInternals;
|
|
107
|
+
private _isDragging = false;
|
|
108
|
+
private readonly _uid = Math.random().toString(36).slice(2, 8);
|
|
109
|
+
|
|
110
|
+
constructor() {
|
|
111
|
+
super();
|
|
112
|
+
this._internals = this.attachInternals();
|
|
113
|
+
this.name = '';
|
|
114
|
+
this.accept = '';
|
|
115
|
+
this.multiple = false;
|
|
116
|
+
this.disabled = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
formResetCallback() {
|
|
120
|
+
this._internals.setFormValue?.(null);
|
|
121
|
+
const input = this.shadowRoot?.querySelector<HTMLInputElement>('input');
|
|
122
|
+
if (input) input.value = '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private _handleFiles(files: FileList | null) {
|
|
126
|
+
if (!files || files.length === 0) return;
|
|
127
|
+
const formData = new FormData();
|
|
128
|
+
Array.from(files).forEach(file => formData.append(this.name, file));
|
|
129
|
+
this._internals.setFormValue?.(formData);
|
|
130
|
+
this.dispatchEvent(new CustomEvent('bds-change', {
|
|
131
|
+
bubbles: true,
|
|
132
|
+
composed: true,
|
|
133
|
+
detail: files,
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private _handleInputChange(e: Event) {
|
|
138
|
+
this._handleFiles((e.target as HTMLInputElement).files);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private _handleClick() {
|
|
142
|
+
this.shadowRoot?.querySelector<HTMLInputElement>('input')?.click();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private _handleDragover(e: DragEvent) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
if (!this._isDragging) {
|
|
148
|
+
this._isDragging = true;
|
|
149
|
+
this.requestUpdate();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private _handleDragleave() {
|
|
154
|
+
this._isDragging = false;
|
|
155
|
+
this.requestUpdate();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private _handleDrop(e: DragEvent) {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
this._isDragging = false;
|
|
161
|
+
this.requestUpdate();
|
|
162
|
+
this._handleFiles(e.dataTransfer?.files ?? null);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
render() {
|
|
166
|
+
const id = `bds-file-${this._uid}`;
|
|
167
|
+
return html`
|
|
168
|
+
<input
|
|
169
|
+
id=${id}
|
|
170
|
+
type="file"
|
|
171
|
+
class="zone-input"
|
|
172
|
+
name=${this.name}
|
|
173
|
+
accept=${this.accept}
|
|
174
|
+
?multiple=${this.multiple}
|
|
175
|
+
?disabled=${this.disabled}
|
|
176
|
+
@change=${this._handleInputChange}
|
|
177
|
+
/>
|
|
178
|
+
<div
|
|
179
|
+
class="zone ${this._isDragging ? '--dragging' : ''}"
|
|
180
|
+
role="button"
|
|
181
|
+
tabindex=${this.disabled ? '-1' : '0'}
|
|
182
|
+
aria-label="Upload file"
|
|
183
|
+
@click=${this._handleClick}
|
|
184
|
+
@keydown=${(e: KeyboardEvent) => (e.key === 'Enter' || e.key === ' ') && this._handleClick()}
|
|
185
|
+
@dragover=${this._handleDragover}
|
|
186
|
+
@dragleave=${this._handleDragleave}
|
|
187
|
+
@drop=${this._handleDrop}
|
|
188
|
+
>
|
|
189
|
+
<span class="icon" aria-hidden="true">
|
|
190
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
191
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 16.5V9.75m0 0-3 3m3-3 3 3M6.75 19.5a4.5 4.5 0 01-1.41-8.775 5.25 5.25 0 0110.338-2.329 3 3 0 013.83 3.849A3.75 3.75 0 0118 19.5H6.75z" />
|
|
192
|
+
</svg>
|
|
193
|
+
</span>
|
|
194
|
+
<span class="zone-label">
|
|
195
|
+
<slot>Drag & drop or click to browse</slot>
|
|
196
|
+
</span>
|
|
197
|
+
<span class="hint">${this.accept ? `Accepted: ${this.accept}` : 'Any file type'}</span>
|
|
198
|
+
</div>
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
customElements.define('bds-file-input', BdsFileInput);
|
|
204
|
+
|
|
205
|
+
declare global {
|
|
206
|
+
interface HTMLElementTagNameMap {
|
|
207
|
+
'bds-file-input': BdsFileInput;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsNumberInput } from './bds-number-input';
|
|
3
|
+
|
|
4
|
+
describe('bds-number-input', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-number-input')).toBe(BdsNumberInput);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a number input in shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-number-input name="qty"></bds-number-input>');
|
|
11
|
+
expect(el.shadowRoot!.querySelector('input[type="number"]')).not.toBeNull();
|
|
12
|
+
cleanup(el);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders a decrease button with aria-label="Decrease"', async () => {
|
|
16
|
+
const el = await fixture('<bds-number-input name="qty"></bds-number-input>');
|
|
17
|
+
const btn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Decrease"]');
|
|
18
|
+
expect(btn).not.toBeNull();
|
|
19
|
+
cleanup(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('renders an increase button with aria-label="Increase"', async () => {
|
|
23
|
+
const el = await fixture('<bds-number-input name="qty"></bds-number-input>');
|
|
24
|
+
const btn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Increase"]');
|
|
25
|
+
expect(btn).not.toBeNull();
|
|
26
|
+
cleanup(el);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('increase button increments value by step', async () => {
|
|
30
|
+
const el = await fixture('<bds-number-input name="qty" step="2"></bds-number-input>') as BdsNumberInput;
|
|
31
|
+
const incBtn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Increase"]')!;
|
|
32
|
+
incBtn.click();
|
|
33
|
+
expect(el.value).toBe(2);
|
|
34
|
+
cleanup(el);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('decrease button decrements value by step', async () => {
|
|
38
|
+
const el = await fixture('<bds-number-input name="qty" step="1"></bds-number-input>') as BdsNumberInput;
|
|
39
|
+
el.value = 5;
|
|
40
|
+
await el.updateComplete;
|
|
41
|
+
const decBtn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Decrease"]')!;
|
|
42
|
+
decBtn.click();
|
|
43
|
+
expect(el.value).toBe(4);
|
|
44
|
+
cleanup(el);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('clamps value to max when increasing beyond max', async () => {
|
|
48
|
+
const el = await fixture('<bds-number-input name="qty" max="10"></bds-number-input>') as BdsNumberInput;
|
|
49
|
+
el.value = 10;
|
|
50
|
+
await el.updateComplete;
|
|
51
|
+
const incBtn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Increase"]')!;
|
|
52
|
+
incBtn.click();
|
|
53
|
+
expect(el.value).toBe(10);
|
|
54
|
+
cleanup(el);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('clamps value to min when decreasing below min', async () => {
|
|
58
|
+
const el = await fixture('<bds-number-input name="qty" min="0"></bds-number-input>') as BdsNumberInput;
|
|
59
|
+
el.value = 0;
|
|
60
|
+
await el.updateComplete;
|
|
61
|
+
const decBtn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Decrease"]')!;
|
|
62
|
+
decBtn.click();
|
|
63
|
+
expect(el.value).toBe(0);
|
|
64
|
+
cleanup(el);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('all inputs are disabled when disabled attribute is set', async () => {
|
|
68
|
+
const el = await fixture('<bds-number-input name="qty" disabled></bds-number-input>');
|
|
69
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
70
|
+
expect(input.disabled).toBe(true);
|
|
71
|
+
cleanup(el);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('fires an input event on stepper click', async () => {
|
|
75
|
+
const el = await fixture('<bds-number-input name="qty"></bds-number-input>');
|
|
76
|
+
const handler = vi.fn();
|
|
77
|
+
el.addEventListener('input', handler);
|
|
78
|
+
const incBtn = el.shadowRoot!.querySelector<HTMLButtonElement>('button[aria-label="Increase"]')!;
|
|
79
|
+
incBtn.click();
|
|
80
|
+
expect(handler).toHaveBeenCalledOnce();
|
|
81
|
+
cleanup(el);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('is form-associated', () => {
|
|
85
|
+
expect(BdsNumberInput.formAssociated).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<bds-number-input>` — form-associated Number Input with stepper buttons.
|
|
5
|
+
*
|
|
6
|
+
* Attributes:
|
|
7
|
+
* name — form field name
|
|
8
|
+
* value — current numeric value (default: 0)
|
|
9
|
+
* min — minimum allowed value
|
|
10
|
+
* max — maximum allowed value
|
|
11
|
+
* step — increment/decrement step (default: 1)
|
|
12
|
+
* disabled — boolean
|
|
13
|
+
*
|
|
14
|
+
* Events:
|
|
15
|
+
* input — fired on stepper click and native input
|
|
16
|
+
* change — native change event
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <bds-number-input name="qty" value="1" min="0" max="99" step="1"></bds-number-input>
|
|
20
|
+
*/
|
|
21
|
+
export class BdsNumberInput extends LitElement {
|
|
22
|
+
static formAssociated = true;
|
|
23
|
+
|
|
24
|
+
static styles = css`
|
|
25
|
+
:host {
|
|
26
|
+
display: block;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
:host([disabled]) {
|
|
30
|
+
opacity: 0.5;
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.row {
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.input {
|
|
40
|
+
flex: 1;
|
|
41
|
+
font-family: var(--bds-font_family--body);
|
|
42
|
+
font-size: var(--bds-font_size--body);
|
|
43
|
+
padding: var(--bds-space_s);
|
|
44
|
+
border: none;
|
|
45
|
+
--bdc_color: currentcolor;
|
|
46
|
+
--bdc-outline_radius: var(--bds-border_radius--xs);
|
|
47
|
+
|
|
48
|
+
border-radius: var(--number-input_radius, var(--bdc-outline_radius));
|
|
49
|
+
box-shadow: inset 0 0 0 var(--bdc-outline_width) var(--bdc_color), var(--number-input_shadow, var(--bdc-outline_shadow));
|
|
50
|
+
background-color: var(--number-input_color_bg, var(--bds-color_bg));
|
|
51
|
+
color: var(--number-input_color, var(--bds-color_on-bg));
|
|
52
|
+
text-align: center;
|
|
53
|
+
-moz-appearance: textfield;
|
|
54
|
+
min-inline-size: 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.input::-webkit-inner-spin-button,
|
|
58
|
+
.input::-webkit-outer-spin-button {
|
|
59
|
+
appearance: none;
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.input:focus {
|
|
64
|
+
--bdc_color: var(--bdc_color--focus);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.input:focus-visible {
|
|
68
|
+
outline: var(--bds-outline_default);
|
|
69
|
+
outline-offset: var(--bds-outline_offset);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.stepper {
|
|
73
|
+
all: unset;
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: center;
|
|
77
|
+
margin: 1px;
|
|
78
|
+
inline-size: 2rem;
|
|
79
|
+
block-size: 2rem;
|
|
80
|
+
border-radius: var(--bds-border_radius--xs);
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
flex-shrink: 0;
|
|
83
|
+
color: var(--bds-color_interactive);
|
|
84
|
+
transition: var(--bds-animation_transition);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.stepper:focus-visible {
|
|
88
|
+
outline: var(--bds-outline_default);
|
|
89
|
+
outline-offset: var(--bds-outline_offset);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.stepper:disabled {
|
|
93
|
+
opacity: 0.4;
|
|
94
|
+
cursor: not-allowed;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@media (hover: hover) and (pointer: fine) {
|
|
98
|
+
.stepper:not(:disabled):hover {
|
|
99
|
+
background-color: var(--bds-color_bg--subtle);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.stepper svg {
|
|
104
|
+
inline-size: 1rem;
|
|
105
|
+
block-size: 1rem;
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
static properties = {
|
|
110
|
+
name: { type: String, reflect: true },
|
|
111
|
+
value: { type: Number },
|
|
112
|
+
min: { type: Number },
|
|
113
|
+
max: { type: Number },
|
|
114
|
+
step: { type: Number },
|
|
115
|
+
disabled: { type: Boolean, reflect: true },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare name: string;
|
|
119
|
+
declare value: number;
|
|
120
|
+
declare min: number | undefined;
|
|
121
|
+
declare max: number | undefined;
|
|
122
|
+
declare step: number;
|
|
123
|
+
declare disabled: boolean;
|
|
124
|
+
|
|
125
|
+
private _internals!: ElementInternals;
|
|
126
|
+
|
|
127
|
+
constructor() {
|
|
128
|
+
super();
|
|
129
|
+
this._internals = this.attachInternals();
|
|
130
|
+
this.name = '';
|
|
131
|
+
this.value = 0;
|
|
132
|
+
this.min = undefined;
|
|
133
|
+
this.max = undefined;
|
|
134
|
+
this.step = 1;
|
|
135
|
+
this.disabled = false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
updated(changed: Map<string, unknown>) {
|
|
139
|
+
super.updated(changed);
|
|
140
|
+
if (changed.has('value')) {
|
|
141
|
+
this._internals.setFormValue?.(String(this.value));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
formResetCallback() {
|
|
146
|
+
this.value = 0;
|
|
147
|
+
this._internals.setFormValue?.('0');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private _clamp(v: number): number {
|
|
151
|
+
let result = v;
|
|
152
|
+
if (this.min !== undefined) result = Math.max(this.min, result);
|
|
153
|
+
if (this.max !== undefined) result = Math.min(this.max, result);
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private _adjust(delta: number) {
|
|
158
|
+
const next = this._clamp(this.value + delta);
|
|
159
|
+
this.value = next;
|
|
160
|
+
this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private _handleChange(e: Event) {
|
|
164
|
+
const v = parseFloat((e.target as HTMLInputElement).value);
|
|
165
|
+
this.value = this._clamp(isNaN(v) ? 0 : v);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
render() {
|
|
169
|
+
const atMin = this.min !== undefined && this.value <= this.min;
|
|
170
|
+
const atMax = this.max !== undefined && this.value >= this.max;
|
|
171
|
+
|
|
172
|
+
return html`
|
|
173
|
+
<div class="row">
|
|
174
|
+
<button
|
|
175
|
+
type="button"
|
|
176
|
+
class="stepper"
|
|
177
|
+
aria-label="Decrease"
|
|
178
|
+
tabindex="-1"
|
|
179
|
+
?disabled=${this.disabled || atMin}
|
|
180
|
+
@click=${() => this._adjust(-this.step)}
|
|
181
|
+
>
|
|
182
|
+
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
183
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14" />
|
|
184
|
+
</svg>
|
|
185
|
+
</button>
|
|
186
|
+
<input
|
|
187
|
+
type="number"
|
|
188
|
+
class="input"
|
|
189
|
+
name=${this.name}
|
|
190
|
+
.value=${String(this.value)}
|
|
191
|
+
min=${this.min ?? ''}
|
|
192
|
+
max=${this.max ?? ''}
|
|
193
|
+
step=${this.step}
|
|
194
|
+
?disabled=${this.disabled}
|
|
195
|
+
@change=${this._handleChange}
|
|
196
|
+
/>
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
class="stepper"
|
|
200
|
+
aria-label="Increase"
|
|
201
|
+
tabindex="-1"
|
|
202
|
+
?disabled=${this.disabled || atMax}
|
|
203
|
+
@click=${() => this._adjust(this.step)}
|
|
204
|
+
>
|
|
205
|
+
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
|
206
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 5v14M5 12h14" />
|
|
207
|
+
</svg>
|
|
208
|
+
</button>
|
|
209
|
+
</div>
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
customElements.define('bds-number-input', BdsNumberInput);
|
|
215
|
+
|
|
216
|
+
declare global {
|
|
217
|
+
interface HTMLElementTagNameMap {
|
|
218
|
+
'bds-number-input': BdsNumberInput;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsRadio } from './bds-radio';
|
|
3
|
+
|
|
4
|
+
describe('bds-radio', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-radio')).toBe(BdsRadio);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a radio input in shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-radio name="size" value="m">Medium</bds-radio>');
|
|
11
|
+
expect(el.shadowRoot!.querySelector('input[type="radio"]')).not.toBeNull();
|
|
12
|
+
cleanup(el);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('is not checked by default', async () => {
|
|
16
|
+
const el = await fixture('<bds-radio name="size" value="m">Medium</bds-radio>');
|
|
17
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
18
|
+
expect(input.checked).toBe(false);
|
|
19
|
+
cleanup(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('is checked when checked attribute is set', async () => {
|
|
23
|
+
const el = await fixture('<bds-radio name="size" value="m" checked>Medium</bds-radio>');
|
|
24
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
25
|
+
expect(input.checked).toBe(true);
|
|
26
|
+
cleanup(el);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('input is disabled when disabled attribute is set', async () => {
|
|
30
|
+
const el = await fixture('<bds-radio name="size" value="m" disabled>Medium</bds-radio>');
|
|
31
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
32
|
+
expect(input.disabled).toBe(true);
|
|
33
|
+
cleanup(el);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('input has the correct name and value attributes', async () => {
|
|
37
|
+
const el = await fixture('<bds-radio name="size" value="m">Medium</bds-radio>');
|
|
38
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
39
|
+
expect(input.name).toBe('size');
|
|
40
|
+
expect(input.value).toBe('m');
|
|
41
|
+
cleanup(el);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders a label linked to the input', async () => {
|
|
45
|
+
const el = await fixture('<bds-radio name="size" value="m">Medium</bds-radio>');
|
|
46
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
47
|
+
const label = el.shadowRoot!.querySelector('label')!;
|
|
48
|
+
expect(label.getAttribute('for')).toBe(input.id);
|
|
49
|
+
cleanup(el);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renders slotted label text', async () => {
|
|
53
|
+
const el = await fixture('<bds-radio name="size" value="m">Medium size</bds-radio>');
|
|
54
|
+
expect(el.textContent?.trim()).toBe('Medium size');
|
|
55
|
+
cleanup(el);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('updates checked property on change', async () => {
|
|
59
|
+
const el = await fixture('<bds-radio name="size" value="m">Medium</bds-radio>') as BdsRadio;
|
|
60
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
61
|
+
input.checked = true;
|
|
62
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
63
|
+
expect(el.checked).toBe(true);
|
|
64
|
+
cleanup(el);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('is form-associated', () => {
|
|
68
|
+
expect(BdsRadio.formAssociated).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
});
|