@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,188 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
export interface SelectOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `<bds-select>` — form-associated Select custom element.
|
|
11
|
+
*
|
|
12
|
+
* Uses a JSON `options` attribute because slotting `<option>` elements into a
|
|
13
|
+
* shadow-DOM `<select>` is not supported cross-browser.
|
|
14
|
+
*
|
|
15
|
+
* Attributes:
|
|
16
|
+
* name — form field name
|
|
17
|
+
* value — currently selected value
|
|
18
|
+
* options — JSON array of `{ value, label, disabled? }` option objects
|
|
19
|
+
* placeholder — placeholder option label (disabled, empty value)
|
|
20
|
+
* required — boolean
|
|
21
|
+
* disabled — boolean
|
|
22
|
+
*
|
|
23
|
+
* Events:
|
|
24
|
+
* change — native change event (forwarded from inner select)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* <bds-select
|
|
28
|
+
* name="country"
|
|
29
|
+
* placeholder="Choose…"
|
|
30
|
+
* options='[{"value":"nl","label":"Netherlands"},{"value":"be","label":"Belgium"}]'
|
|
31
|
+
* ></bds-select>
|
|
32
|
+
*/
|
|
33
|
+
export class BdsSelect extends LitElement {
|
|
34
|
+
static formAssociated = true;
|
|
35
|
+
|
|
36
|
+
static styles = css`
|
|
37
|
+
:host {
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:host([disabled]) {
|
|
42
|
+
opacity: 0.5;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.wrapper {
|
|
47
|
+
position: relative;
|
|
48
|
+
display: block;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.select {
|
|
52
|
+
inline-size: 100%;
|
|
53
|
+
font-family: var(--bds-font_family--body);
|
|
54
|
+
font-size: var(--bds-font_size--body);
|
|
55
|
+
padding: var(--bds-space_s);
|
|
56
|
+
padding-inline-end: var(--bds-space_xl);
|
|
57
|
+
border: none;
|
|
58
|
+
--bdc_color: currentcolor;
|
|
59
|
+
--bdc-outline_radius: var(--bds-border_radius--xs);
|
|
60
|
+
|
|
61
|
+
border-radius: var(--select_radius, var(--bdc-outline_radius));
|
|
62
|
+
box-shadow: inset 0 0 0 var(--bdc-outline_width) var(--bdc_color), var(--select_shadow, var(--bdc-outline_shadow));
|
|
63
|
+
background-color: var(--select_color_bg, var(--bds-color_bg));
|
|
64
|
+
color: var(--select_color, var(--bds-color_on-bg));
|
|
65
|
+
appearance: none;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
transition: --bdc_color var(--bds-animation_transition-duration) var(--bds-animation_easing);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.select:focus {
|
|
71
|
+
--bdc_color: var(--bdc_color--focus);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.select:focus-visible {
|
|
75
|
+
outline: var(--bds-outline_default);
|
|
76
|
+
outline-offset: var(--bds-outline_offset);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.chevron {
|
|
80
|
+
position: absolute;
|
|
81
|
+
inset-inline-end: var(--bds-space_s);
|
|
82
|
+
inset-block-start: 50%;
|
|
83
|
+
transform: translateY(-50%);
|
|
84
|
+
pointer-events: none;
|
|
85
|
+
inline-size: 1rem;
|
|
86
|
+
block-size: 1rem;
|
|
87
|
+
color: var(--select_chevron-color, var(--bds-color_interactive));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.chevron svg {
|
|
91
|
+
inline-size: 100%;
|
|
92
|
+
block-size: 100%;
|
|
93
|
+
}
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
static properties = {
|
|
97
|
+
name: { type: String, reflect: true },
|
|
98
|
+
value: { type: String },
|
|
99
|
+
options: { type: String },
|
|
100
|
+
placeholder: { type: String },
|
|
101
|
+
required: { type: Boolean, reflect: true },
|
|
102
|
+
disabled: { type: Boolean, reflect: true },
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
declare name: string;
|
|
106
|
+
declare value: string;
|
|
107
|
+
declare options: string;
|
|
108
|
+
declare placeholder: string;
|
|
109
|
+
declare required: boolean;
|
|
110
|
+
declare disabled: boolean;
|
|
111
|
+
|
|
112
|
+
private _internals!: ElementInternals;
|
|
113
|
+
|
|
114
|
+
constructor() {
|
|
115
|
+
super();
|
|
116
|
+
this._internals = this.attachInternals();
|
|
117
|
+
this.name = '';
|
|
118
|
+
this.value = '';
|
|
119
|
+
this.options = '[]';
|
|
120
|
+
this.placeholder = '';
|
|
121
|
+
this.required = false;
|
|
122
|
+
this.disabled = false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private get _options(): SelectOption[] {
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(this.options) as SelectOption[];
|
|
128
|
+
} catch {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
updated(changed: Map<string, unknown>) {
|
|
134
|
+
super.updated(changed);
|
|
135
|
+
if (changed.has('value') || changed.has('name')) {
|
|
136
|
+
this._internals.setFormValue?.(this.value || null);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
formResetCallback() {
|
|
141
|
+
this.value = '';
|
|
142
|
+
this._internals.setFormValue?.(null);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private _handleChange(e: Event) {
|
|
146
|
+
this.value = (e.target as HTMLSelectElement).value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
render() {
|
|
150
|
+
const opts = this._options;
|
|
151
|
+
return html`
|
|
152
|
+
<div class="wrapper">
|
|
153
|
+
<select
|
|
154
|
+
class="select"
|
|
155
|
+
name=${this.name}
|
|
156
|
+
.value=${this.value}
|
|
157
|
+
?required=${this.required}
|
|
158
|
+
?disabled=${this.disabled}
|
|
159
|
+
@change=${this._handleChange}
|
|
160
|
+
>
|
|
161
|
+
${this.placeholder ? html`
|
|
162
|
+
<option value="" disabled ?selected=${!this.value}>${this.placeholder}</option>
|
|
163
|
+
` : ''}
|
|
164
|
+
${opts.map(opt => html`
|
|
165
|
+
<option
|
|
166
|
+
value=${opt.value}
|
|
167
|
+
?disabled=${opt.disabled}
|
|
168
|
+
?selected=${opt.value === this.value}
|
|
169
|
+
>${opt.label}</option>
|
|
170
|
+
`)}
|
|
171
|
+
</select>
|
|
172
|
+
<span class="chevron" aria-hidden="true">
|
|
173
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
174
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 9l6 6 6-6" />
|
|
175
|
+
</svg>
|
|
176
|
+
</span>
|
|
177
|
+
</div>
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
customElements.define('bds-select', BdsSelect);
|
|
183
|
+
|
|
184
|
+
declare global {
|
|
185
|
+
interface HTMLElementTagNameMap {
|
|
186
|
+
'bds-select': BdsSelect;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsSlider } from './bds-slider';
|
|
3
|
+
|
|
4
|
+
describe('bds-slider', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-slider')).toBe(BdsSlider);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a range input in shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-slider name="volume"></bds-slider>');
|
|
11
|
+
expect(el.shadowRoot!.querySelector('input[type="range"]')).not.toBeNull();
|
|
12
|
+
cleanup(el);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('applies --slider_fill inline style matching the value percentage', async () => {
|
|
16
|
+
const el = await fixture('<bds-slider name="volume" value="50" min="0" max="100"></bds-slider>');
|
|
17
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
18
|
+
expect(input.style.getPropertyValue('--slider_fill')).toBe('50%');
|
|
19
|
+
cleanup(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('is disabled when disabled attribute is set', async () => {
|
|
23
|
+
const el = await fixture('<bds-slider name="volume" disabled></bds-slider>');
|
|
24
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
25
|
+
expect(input.disabled).toBe(true);
|
|
26
|
+
cleanup(el);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('updates value property on input event', async () => {
|
|
30
|
+
const el = await fixture('<bds-slider name="volume"></bds-slider>') as BdsSlider;
|
|
31
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
32
|
+
input.value = '75';
|
|
33
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
34
|
+
expect(el.value).toBe(75);
|
|
35
|
+
cleanup(el);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('is form-associated', () => {
|
|
39
|
+
expect(BdsSlider.formAssociated).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<bds-slider>` — form-associated Slider / Range Input custom element.
|
|
5
|
+
*
|
|
6
|
+
* Uses a native `<input type="range">` with a CSS fill track driven by
|
|
7
|
+
* the `--slider_fill` custom property.
|
|
8
|
+
*
|
|
9
|
+
* Attributes:
|
|
10
|
+
* name — form field name
|
|
11
|
+
* value — current value (default: 0)
|
|
12
|
+
* min — minimum value (default: 0)
|
|
13
|
+
* max — maximum value (default: 100)
|
|
14
|
+
* step — step increment (default: 1)
|
|
15
|
+
* disabled — boolean
|
|
16
|
+
*
|
|
17
|
+
* Events:
|
|
18
|
+
* input — fired as the user drags
|
|
19
|
+
* change — fired when the user releases
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* <bds-slider name="volume" value="50" min="0" max="100" step="5"></bds-slider>
|
|
23
|
+
*/
|
|
24
|
+
export class BdsSlider extends LitElement {
|
|
25
|
+
static formAssociated = true;
|
|
26
|
+
|
|
27
|
+
static styles = css`
|
|
28
|
+
:host {
|
|
29
|
+
display: block;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
:host([disabled]) {
|
|
33
|
+
opacity: 0.5;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.track-wrapper {
|
|
38
|
+
position: relative;
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.input {
|
|
44
|
+
inline-size: 100%;
|
|
45
|
+
appearance: none;
|
|
46
|
+
block-size: 0.25rem;
|
|
47
|
+
border-radius: 999px;
|
|
48
|
+
background: linear-gradient(
|
|
49
|
+
to right,
|
|
50
|
+
var(--slider_fill-color, var(--bds-color_interactive)) var(--slider_fill, 0%),
|
|
51
|
+
var(--slider_track-color, var(--bds-color_bg--subtle)) var(--slider_fill, 0%)
|
|
52
|
+
);
|
|
53
|
+
outline: none;
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.input::-webkit-slider-thumb {
|
|
58
|
+
appearance: none;
|
|
59
|
+
inline-size: 1.25rem;
|
|
60
|
+
block-size: 1.25rem;
|
|
61
|
+
border-radius: 50%;
|
|
62
|
+
background-color: var(--slider_thumb-color, var(--bds-color_interactive));
|
|
63
|
+
box-shadow: var(--bds-shadow_m);
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
transition: var(--bds-animation_transition);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.input::-moz-range-thumb {
|
|
69
|
+
inline-size: 1.25rem;
|
|
70
|
+
block-size: 1.25rem;
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
border: none;
|
|
73
|
+
background-color: var(--slider_thumb-color, var(--bds-color_interactive));
|
|
74
|
+
box-shadow: var(--bds-shadow_m);
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.input:focus-visible {
|
|
79
|
+
outline: var(--bds-outline_default);
|
|
80
|
+
outline-offset: var(--bds-outline_offset);
|
|
81
|
+
border-radius: 999px;
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
static properties = {
|
|
86
|
+
name: { type: String, reflect: true },
|
|
87
|
+
value: { type: Number },
|
|
88
|
+
min: { type: Number },
|
|
89
|
+
max: { type: Number },
|
|
90
|
+
step: { type: Number },
|
|
91
|
+
disabled: { type: Boolean, reflect: true },
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
declare name: string;
|
|
95
|
+
declare value: number;
|
|
96
|
+
declare min: number;
|
|
97
|
+
declare max: number;
|
|
98
|
+
declare step: number;
|
|
99
|
+
declare disabled: boolean;
|
|
100
|
+
|
|
101
|
+
private _internals!: ElementInternals;
|
|
102
|
+
|
|
103
|
+
constructor() {
|
|
104
|
+
super();
|
|
105
|
+
this._internals = this.attachInternals();
|
|
106
|
+
this.name = '';
|
|
107
|
+
this.value = 0;
|
|
108
|
+
this.min = 0;
|
|
109
|
+
this.max = 100;
|
|
110
|
+
this.step = 1;
|
|
111
|
+
this.disabled = false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
updated(changed: Map<string, unknown>) {
|
|
115
|
+
super.updated(changed);
|
|
116
|
+
if (changed.has('value')) {
|
|
117
|
+
this._internals.setFormValue?.(String(this.value));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
formResetCallback() {
|
|
122
|
+
this.value = 0;
|
|
123
|
+
this._internals.setFormValue?.('0');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private get _fillPct(): number {
|
|
127
|
+
const range = this.max - this.min;
|
|
128
|
+
if (range === 0) return 0;
|
|
129
|
+
return ((this.value - this.min) / range) * 100;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private _handleInput(e: Event) {
|
|
133
|
+
this.value = parseFloat((e.target as HTMLInputElement).value);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
render() {
|
|
137
|
+
return html`
|
|
138
|
+
<div class="track-wrapper">
|
|
139
|
+
<input
|
|
140
|
+
type="range"
|
|
141
|
+
class="input"
|
|
142
|
+
name=${this.name}
|
|
143
|
+
.value=${String(this.value)}
|
|
144
|
+
min=${this.min}
|
|
145
|
+
max=${this.max}
|
|
146
|
+
step=${this.step}
|
|
147
|
+
?disabled=${this.disabled}
|
|
148
|
+
style="--slider_fill: ${this._fillPct}%"
|
|
149
|
+
@input=${this._handleInput}
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
customElements.define('bds-slider', BdsSlider);
|
|
157
|
+
|
|
158
|
+
declare global {
|
|
159
|
+
interface HTMLElementTagNameMap {
|
|
160
|
+
'bds-slider': BdsSlider;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsSwitch } from './bds-switch';
|
|
3
|
+
|
|
4
|
+
describe('bds-switch', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-switch')).toBe(BdsSwitch);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a checkbox input with role="switch"', async () => {
|
|
10
|
+
const el = await fixture('<bds-switch name="notify">Notifications</bds-switch>');
|
|
11
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
12
|
+
expect(input.type).toBe('checkbox');
|
|
13
|
+
expect(input.getAttribute('role')).toBe('switch');
|
|
14
|
+
cleanup(el);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('is off by default', async () => {
|
|
18
|
+
const el = await fixture('<bds-switch name="notify">Notifications</bds-switch>');
|
|
19
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
20
|
+
expect(input.checked).toBe(false);
|
|
21
|
+
cleanup(el);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('is on when checked attribute is set', async () => {
|
|
25
|
+
const el = await fixture('<bds-switch name="notify" checked>Notifications</bds-switch>');
|
|
26
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
27
|
+
expect(input.checked).toBe(true);
|
|
28
|
+
cleanup(el);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('input is disabled when disabled attribute is set', async () => {
|
|
32
|
+
const el = await fixture('<bds-switch name="notify" disabled>Notifications</bds-switch>');
|
|
33
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
34
|
+
expect(input.disabled).toBe(true);
|
|
35
|
+
cleanup(el);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('renders a visual track element', async () => {
|
|
39
|
+
const el = await fixture('<bds-switch name="notify">Notifications</bds-switch>');
|
|
40
|
+
expect(el.shadowRoot!.querySelector('.track')).not.toBeNull();
|
|
41
|
+
cleanup(el);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders slotted label text', async () => {
|
|
45
|
+
const el = await fixture('<bds-switch name="notify">Turn on alerts</bds-switch>');
|
|
46
|
+
expect(el.textContent?.trim()).toBe('Turn on alerts');
|
|
47
|
+
cleanup(el);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('updates checked property on change', async () => {
|
|
51
|
+
const el = await fixture('<bds-switch name="notify">Notifications</bds-switch>') as BdsSwitch;
|
|
52
|
+
const input = el.shadowRoot!.querySelector<HTMLInputElement>('input')!;
|
|
53
|
+
input.checked = true;
|
|
54
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
55
|
+
expect(el.checked).toBe(true);
|
|
56
|
+
cleanup(el);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('is form-associated', () => {
|
|
60
|
+
expect(BdsSwitch.formAssociated).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<bds-switch>` — form-associated Toggle Switch custom element.
|
|
5
|
+
*
|
|
6
|
+
* Visually a toggle switch but semantically equivalent to a checkbox
|
|
7
|
+
* (`role="switch"`). Participates in HTML forms via the Form-Associated
|
|
8
|
+
* Custom Elements API.
|
|
9
|
+
*
|
|
10
|
+
* Attributes:
|
|
11
|
+
* name — form field name
|
|
12
|
+
* value — submitted value when on (default: "on")
|
|
13
|
+
* checked — boolean; whether the switch is on
|
|
14
|
+
* required — boolean
|
|
15
|
+
* disabled — boolean
|
|
16
|
+
*
|
|
17
|
+
* Slots:
|
|
18
|
+
* (default) — label text
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <bds-switch name="notifications" value="enabled">Enable notifications</bds-switch>
|
|
22
|
+
*/
|
|
23
|
+
export class BdsSwitch extends LitElement {
|
|
24
|
+
static formAssociated = true;
|
|
25
|
+
|
|
26
|
+
static styles = css`
|
|
27
|
+
:host {
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: var(--bds-space_xs);
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
font-size: var(--bds-font_size--body);
|
|
33
|
+
font-family: var(--bds-font_family--body);
|
|
34
|
+
color: var(--bds-color_on-bg);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
:host([disabled]) {
|
|
38
|
+
opacity: 0.5;
|
|
39
|
+
cursor: not-allowed;
|
|
40
|
+
pointer-events: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.track {
|
|
44
|
+
position: relative;
|
|
45
|
+
inline-size: 2.75rem;
|
|
46
|
+
block-size: 1.5rem;
|
|
47
|
+
border-radius: 999px;
|
|
48
|
+
background-color: var(--switch_color_bg, var(--bds-color_bg--subtle));
|
|
49
|
+
--bdc_color: currentcolor;
|
|
50
|
+
|
|
51
|
+
box-shadow: inset 0 0 0 var(--bdc-outline_width) var(--bdc_color);
|
|
52
|
+
transition: background-color 0.2s ease;
|
|
53
|
+
flex-shrink: 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.thumb {
|
|
57
|
+
position: absolute;
|
|
58
|
+
inset-block-start: 0.2rem;
|
|
59
|
+
inset-inline-start: 0.2rem;
|
|
60
|
+
inline-size: 1.1rem;
|
|
61
|
+
block-size: 1.1rem;
|
|
62
|
+
border-radius: 50%;
|
|
63
|
+
background-color: var(--switch_thumb_color, var(--bds-color_interactive));
|
|
64
|
+
transition: inset-inline-start 0.2s ease;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.input {
|
|
68
|
+
position: absolute;
|
|
69
|
+
opacity: 0;
|
|
70
|
+
inline-size: 0;
|
|
71
|
+
block-size: 0;
|
|
72
|
+
margin: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.input:checked + .track {
|
|
76
|
+
background-color: var(--switch_color-active, var(--bdc-color_active--subtle));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.input:checked + .track .thumb {
|
|
80
|
+
inset-inline-start: calc(100% - 1.3rem);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.input:focus-visible + .track {
|
|
84
|
+
outline: var(--bds-outline_default);
|
|
85
|
+
outline-offset: var(--bds-outline_offset);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
label {
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
static properties = {
|
|
94
|
+
name: { type: String, reflect: true },
|
|
95
|
+
value: { type: String },
|
|
96
|
+
checked: { type: Boolean, reflect: true },
|
|
97
|
+
required: { type: Boolean, reflect: true },
|
|
98
|
+
disabled: { type: Boolean, reflect: true },
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
declare name: string;
|
|
102
|
+
declare value: string;
|
|
103
|
+
declare checked: boolean;
|
|
104
|
+
declare required: boolean;
|
|
105
|
+
declare disabled: boolean;
|
|
106
|
+
|
|
107
|
+
private _internals!: ElementInternals;
|
|
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.value = 'on';
|
|
115
|
+
this.checked = false;
|
|
116
|
+
this.required = false;
|
|
117
|
+
this.disabled = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updated(changed: Map<string, unknown>) {
|
|
121
|
+
super.updated(changed);
|
|
122
|
+
if (changed.has('checked') || changed.has('value')) {
|
|
123
|
+
this._internals.setFormValue?.(this.checked ? this.value : null);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
formResetCallback() {
|
|
128
|
+
this.checked = false;
|
|
129
|
+
this._internals.setFormValue?.(null);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private _handleChange(e: Event) {
|
|
133
|
+
this.checked = (e.target as HTMLInputElement).checked;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
render() {
|
|
137
|
+
const id = `bds-switch-${this._uid}`;
|
|
138
|
+
return html`
|
|
139
|
+
<input
|
|
140
|
+
id=${id}
|
|
141
|
+
type="checkbox"
|
|
142
|
+
role="switch"
|
|
143
|
+
class="input"
|
|
144
|
+
.checked=${this.checked}
|
|
145
|
+
?required=${this.required}
|
|
146
|
+
?disabled=${this.disabled}
|
|
147
|
+
@change=${this._handleChange}
|
|
148
|
+
/>
|
|
149
|
+
<label for=${id}>
|
|
150
|
+
<span class="track">
|
|
151
|
+
<span class="thumb"></span>
|
|
152
|
+
</span>
|
|
153
|
+
<slot></slot>
|
|
154
|
+
</label>
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
customElements.define('bds-switch', BdsSwitch);
|
|
160
|
+
|
|
161
|
+
declare global {
|
|
162
|
+
interface HTMLElementTagNameMap {
|
|
163
|
+
'bds-switch': BdsSwitch;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsTextarea } from './bds-textarea';
|
|
3
|
+
|
|
4
|
+
describe('bds-textarea', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-textarea')).toBe(BdsTextarea);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a <textarea> element in shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-textarea name="message"></bds-textarea>');
|
|
11
|
+
expect(el.shadowRoot!.querySelector('textarea')).not.toBeNull();
|
|
12
|
+
cleanup(el);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('forwards placeholder attribute to inner textarea', async () => {
|
|
16
|
+
const el = await fixture('<bds-textarea name="message" placeholder="Type here…"></bds-textarea>');
|
|
17
|
+
const textarea = el.shadowRoot!.querySelector<HTMLTextAreaElement>('textarea')!;
|
|
18
|
+
expect(textarea.placeholder).toBe('Type here…');
|
|
19
|
+
cleanup(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('forwards rows attribute to inner textarea', async () => {
|
|
23
|
+
const el = await fixture('<bds-textarea name="message" rows="8"></bds-textarea>');
|
|
24
|
+
const textarea = el.shadowRoot!.querySelector<HTMLTextAreaElement>('textarea')!;
|
|
25
|
+
expect(textarea.rows).toBe(8);
|
|
26
|
+
cleanup(el);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('is disabled when disabled attribute is set', async () => {
|
|
30
|
+
const el = await fixture('<bds-textarea name="message" disabled></bds-textarea>');
|
|
31
|
+
const textarea = el.shadowRoot!.querySelector<HTMLTextAreaElement>('textarea')!;
|
|
32
|
+
expect(textarea.disabled).toBe(true);
|
|
33
|
+
cleanup(el);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('is required when required attribute is set', async () => {
|
|
37
|
+
const el = await fixture('<bds-textarea name="message" required></bds-textarea>');
|
|
38
|
+
const textarea = el.shadowRoot!.querySelector<HTMLTextAreaElement>('textarea')!;
|
|
39
|
+
expect(textarea.required).toBe(true);
|
|
40
|
+
cleanup(el);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('updates value property on input', async () => {
|
|
44
|
+
const el = await fixture('<bds-textarea name="message"></bds-textarea>') as BdsTextarea;
|
|
45
|
+
const textarea = el.shadowRoot!.querySelector<HTMLTextAreaElement>('textarea')!;
|
|
46
|
+
textarea.value = 'Hello world';
|
|
47
|
+
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
48
|
+
expect(el.value).toBe('Hello world');
|
|
49
|
+
cleanup(el);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('is form-associated', () => {
|
|
53
|
+
expect(BdsTextarea.formAssociated).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
});
|