@boostdev/design-system-components 1.0.2 → 1.1.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 +20 -18
- package/dist/client.cjs +236 -153
- package/dist/client.css +785 -702
- package/dist/client.d.cts +53 -94
- package/dist/client.d.ts +53 -94
- package/dist/client.js +237 -163
- package/dist/index.cjs +236 -153
- package/dist/index.css +785 -702
- package/dist/index.d.cts +53 -94
- package/dist/index.d.ts +53 -94
- package/dist/index.js +237 -163
- package/dist/native/index.cjs +991 -0
- package/dist/native/index.d.cts +208 -0
- package/dist/native/index.d.ts +208 -0
- package/dist/native/index.js +968 -0
- package/dist/web-components.d.ts +303 -0
- package/dist/web-components.js +1968 -0
- package/package.json +29 -7
- package/src/components/interaction/Button/Button.module.css +14 -11
- package/src/components/interaction/Button/Button.native.spec.tsx +35 -0
- package/src/components/interaction/Button/Button.native.stories.tsx +42 -0
- package/src/components/interaction/Button/Button.native.tsx +95 -0
- package/src/components/interaction/Button/Button.stories.tsx +1 -1
- package/src/components/interaction/Button/Button.tsx +2 -2
- package/src/components/interaction/Command/Command.mdx +16 -0
- package/src/components/interaction/Command/Command.module.css +12 -12
- package/src/components/interaction/Command/Command.stories.tsx +1 -1
- package/src/components/interaction/Command/Command.tsx +2 -2
- package/src/components/interaction/Dialog/Dialog.module.css +3 -3
- package/src/components/interaction/Dialog/Dialog.stories.tsx +1 -1
- package/src/components/interaction/Dialog/Dialog.tsx +2 -2
- package/src/components/interaction/Drawer/Drawer.mdx +14 -0
- package/src/components/interaction/Drawer/Drawer.module.css +3 -3
- package/src/components/interaction/Drawer/Drawer.stories.tsx +1 -1
- package/src/components/interaction/Drawer/Drawer.tsx +2 -2
- package/src/components/interaction/DropdownMenu/DropdownMenu.module.css +3 -3
- package/src/components/interaction/DropdownMenu/DropdownMenu.stories.tsx +1 -1
- package/src/components/interaction/DropdownMenu/DropdownMenu.tsx +2 -2
- package/src/components/interaction/Popover/Popover.mdx +17 -0
- package/src/components/interaction/Popover/Popover.module.css +72 -15
- package/src/components/interaction/Popover/Popover.spec.tsx +68 -4
- package/src/components/interaction/Popover/Popover.stories.tsx +1 -1
- package/src/components/interaction/Popover/Popover.tsx +76 -20
- package/src/components/interaction/Rating/Rating.module.css +2 -2
- package/src/components/interaction/Rating/Rating.stories.tsx +1 -1
- package/src/components/interaction/Rating/Rating.tsx +2 -2
- package/src/components/interaction/Toast/Toast.module.css +16 -11
- package/src/components/interaction/Toast/Toast.spec.tsx +21 -0
- package/src/components/interaction/Toast/Toast.stories.tsx +1 -1
- package/src/components/interaction/Toast/Toast.tsx +22 -2
- package/src/components/interaction/form/Checkbox/Checkbox.mdx +2 -2
- package/src/components/interaction/form/Checkbox/Checkbox.module.css +5 -5
- package/src/components/interaction/form/Checkbox/Checkbox.native.spec.tsx +42 -0
- package/src/components/interaction/form/Checkbox/Checkbox.native.stories.tsx +36 -0
- package/src/components/interaction/form/Checkbox/Checkbox.native.tsx +80 -0
- package/src/components/interaction/form/Checkbox/Checkbox.stories.tsx +1 -1
- package/src/components/interaction/form/Checkbox/Checkbox.tsx +2 -2
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.mdx +44 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.module.css +2 -2
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.stories.tsx +1 -1
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.tsx +2 -2
- package/src/components/interaction/form/Combobox/Combobox.mdx +21 -0
- package/src/components/interaction/form/Combobox/Combobox.module.css +8 -8
- package/src/components/interaction/form/Combobox/Combobox.stories.tsx +1 -1
- package/src/components/interaction/form/Combobox/Combobox.tsx +2 -2
- package/src/components/interaction/form/FileInput/FileInput.mdx +14 -0
- package/src/components/interaction/form/FileInput/FileInput.module.css +8 -8
- package/src/components/interaction/form/FileInput/FileInput.stories.tsx +1 -1
- package/src/components/interaction/form/FileInput/FileInput.tsx +2 -2
- package/src/components/interaction/form/FormInput/FormInput.module.css +2 -2
- package/src/components/interaction/form/FormInput/FormInput.stories.tsx +1 -1
- package/src/components/interaction/form/FormInput/FormInput.tsx +2 -2
- package/src/components/interaction/form/NumberInput/NumberInput.mdx +16 -0
- package/src/components/interaction/form/NumberInput/NumberInput.module.css +4 -4
- package/src/components/interaction/form/NumberInput/NumberInput.stories.tsx +1 -1
- package/src/components/interaction/form/NumberInput/NumberInput.tsx +2 -2
- package/src/components/interaction/form/Radio/Radio.mdx +3 -3
- package/src/components/interaction/form/Radio/Radio.module.css +6 -6
- package/src/components/interaction/form/Radio/Radio.native.stories.tsx +46 -0
- package/src/components/interaction/form/Radio/Radio.native.tsx +79 -0
- package/src/components/interaction/form/Radio/Radio.stories.tsx +1 -1
- package/src/components/interaction/form/Radio/Radio.tsx +2 -2
- package/src/components/interaction/form/RadioGroup/RadioGroup.mdx +45 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.module.css +2 -2
- package/src/components/interaction/form/RadioGroup/RadioGroup.stories.tsx +1 -1
- package/src/components/interaction/form/RadioGroup/RadioGroup.tsx +2 -2
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.module.css +5 -5
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.stories.tsx +1 -1
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.tsx +2 -2
- package/src/components/interaction/form/Select/Select.module.css +3 -3
- package/src/components/interaction/form/Select/Select.stories.tsx +1 -1
- package/src/components/interaction/form/Select/Select.tsx +2 -2
- package/src/components/interaction/form/Slider/Slider.mdx +1 -1
- package/src/components/interaction/form/Slider/Slider.module.css +14 -14
- package/src/components/interaction/form/Slider/Slider.stories.tsx +1 -1
- package/src/components/interaction/form/Slider/Slider.tsx +2 -2
- package/src/components/interaction/form/Switch/Switch.mdx +4 -4
- package/src/components/interaction/form/Switch/Switch.module.css +8 -8
- package/src/components/interaction/form/Switch/Switch.native.spec.tsx +60 -0
- package/src/components/interaction/form/Switch/Switch.native.stories.tsx +35 -0
- package/src/components/interaction/form/Switch/Switch.native.tsx +59 -0
- package/src/components/interaction/form/Switch/Switch.stories.tsx +1 -1
- package/src/components/interaction/form/Switch/Switch.tsx +2 -2
- package/src/components/interaction/form/Textarea/Textarea.mdx +17 -0
- package/src/components/interaction/form/Textarea/Textarea.module.css +2 -2
- package/src/components/interaction/form/Textarea/Textarea.stories.tsx +1 -1
- package/src/components/interaction/form/Textarea/Textarea.tsx +2 -2
- package/src/components/interaction/form/atoms/InputContainer.tsx +2 -1
- package/src/components/interaction/form/atoms/Label.module.css +1 -1
- package/src/components/interaction/form/atoms/Label.native.stories.tsx +18 -0
- package/src/components/interaction/form/atoms/Label.native.tsx +29 -0
- package/src/components/interaction/form/atoms/Label.tsx +5 -3
- package/src/components/interaction/form/atoms/Message.native.spec.tsx +30 -0
- package/src/components/interaction/form/atoms/Message.native.stories.tsx +22 -0
- package/src/components/interaction/form/atoms/Message.native.tsx +34 -0
- package/src/components/interaction/form/atoms/Message.tsx +5 -3
- package/src/components/layout/ButtonGroup/ButtonGroup.native.stories.tsx +50 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.native.tsx +34 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.stories.tsx +1 -1
- package/src/components/layout/ButtonGroup/ButtonGroup.tsx +2 -2
- package/src/components/layout/Card/Card.module.css +2 -2
- package/src/components/layout/Card/Card.native.stories.tsx +53 -0
- package/src/components/layout/Card/Card.native.tsx +89 -0
- package/src/components/layout/Card/Card.stories.tsx +1 -1
- package/src/components/layout/Card/Card.tsx +2 -2
- package/src/components/layout/IconWrapper/IconWrapper.mdx +2 -2
- package/src/components/layout/IconWrapper/IconWrapper.module.css +3 -3
- package/src/components/layout/IconWrapper/IconWrapper.native.spec.tsx +39 -0
- package/src/components/layout/IconWrapper/IconWrapper.native.stories.tsx +41 -0
- package/src/components/layout/IconWrapper/IconWrapper.native.tsx +20 -0
- package/src/components/layout/IconWrapper/IconWrapper.stories.tsx +1 -1
- package/src/components/layout/IconWrapper/IconWrapper.tsx +2 -2
- package/src/components/layout/SectionHeader/SectionHeader.mdx +13 -0
- package/src/components/layout/SectionHeader/SectionHeader.module.css +2 -2
- package/src/components/layout/SectionHeader/SectionHeader.native.stories.tsx +38 -0
- package/src/components/layout/SectionHeader/SectionHeader.native.tsx +79 -0
- package/src/components/layout/SectionHeader/SectionHeader.stories.tsx +1 -1
- package/src/components/layout/SectionHeader/SectionHeader.tsx +2 -2
- package/src/components/ui/Accordion/Accordion.mdx +14 -0
- package/src/components/ui/Accordion/Accordion.module.css +5 -5
- package/src/components/ui/Accordion/Accordion.stories.tsx +1 -1
- package/src/components/ui/Accordion/Accordion.tsx +2 -2
- package/src/components/ui/Alert/Alert.module.css +15 -15
- package/src/components/ui/Alert/Alert.native.stories.tsx +43 -0
- package/src/components/ui/Alert/Alert.native.tsx +94 -0
- package/src/components/ui/Alert/Alert.stories.tsx +1 -1
- package/src/components/ui/Alert/Alert.tsx +2 -2
- package/src/components/ui/Avatar/Avatar.module.css +2 -2
- package/src/components/ui/Avatar/Avatar.native.spec.tsx +47 -0
- package/src/components/ui/Avatar/Avatar.native.stories.tsx +34 -0
- package/src/components/ui/Avatar/Avatar.native.tsx +85 -0
- package/src/components/ui/Avatar/Avatar.stories.tsx +1 -1
- package/src/components/ui/Avatar/Avatar.tsx +2 -2
- package/src/components/ui/Badge/Badge.mdx +2 -2
- package/src/components/ui/Badge/Badge.module.css +12 -12
- package/src/components/ui/Badge/Badge.native.stories.tsx +36 -0
- package/src/components/ui/Badge/Badge.native.tsx +50 -0
- package/src/components/ui/Badge/Badge.stories.tsx +1 -1
- package/src/components/ui/Badge/Badge.tsx +2 -2
- package/src/components/ui/Breadcrumb/Breadcrumb.module.css +2 -2
- package/src/components/ui/Breadcrumb/Breadcrumb.stories.tsx +1 -1
- package/src/components/ui/Breadcrumb/Breadcrumb.tsx +2 -2
- package/src/components/ui/Calendar/Calendar.mdx +16 -0
- package/src/components/ui/Calendar/Calendar.module.css +11 -11
- package/src/components/ui/Calendar/Calendar.stories.tsx +1 -1
- package/src/components/ui/Calendar/Calendar.tsx +2 -2
- package/src/components/ui/Carousel/Carousel.module.css +4 -4
- package/src/components/ui/Carousel/Carousel.stories.tsx +1 -1
- package/src/components/ui/Carousel/Carousel.tsx +2 -2
- package/src/components/ui/Collapsible/Collapsible.module.css +6 -6
- package/src/components/ui/Collapsible/Collapsible.stories.tsx +1 -1
- package/src/components/ui/Collapsible/Collapsible.tsx +2 -2
- package/src/components/ui/DescriptionList/DescriptionList.module.css +3 -3
- package/src/components/ui/DescriptionList/DescriptionList.stories.tsx +1 -1
- package/src/components/ui/DescriptionList/DescriptionList.tsx +2 -2
- package/src/components/ui/Link/Link.mdx +14 -0
- package/src/components/ui/Link/Link.module.css +4 -4
- package/src/components/ui/Link/Link.stories.tsx +1 -1
- package/src/components/ui/Link/Link.tsx +2 -2
- package/src/components/ui/Loading/Loading.module.css +2 -2
- package/src/components/ui/Loading/Loading.native.spec.tsx +24 -0
- package/src/components/ui/Loading/Loading.native.stories.tsx +33 -0
- package/src/components/ui/Loading/Loading.native.tsx +29 -0
- package/src/components/ui/Loading/Loading.stories.tsx +1 -1
- package/src/components/ui/Loading/Loading.tsx +2 -2
- package/src/components/ui/NotificationBanner/NotificationBanner.module.css +15 -15
- package/src/components/ui/NotificationBanner/NotificationBanner.native.stories.tsx +39 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.native.tsx +76 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.stories.tsx +1 -1
- package/src/components/ui/NotificationBanner/NotificationBanner.tsx +2 -2
- package/src/components/ui/Pagination/Pagination.module.css +8 -8
- package/src/components/ui/Pagination/Pagination.stories.tsx +1 -1
- package/src/components/ui/Pagination/Pagination.tsx +2 -2
- package/src/components/ui/Progress/Progress.mdx +1 -1
- package/src/components/ui/Progress/Progress.module.css +3 -3
- package/src/components/ui/Progress/Progress.native.stories.tsx +34 -0
- package/src/components/ui/Progress/Progress.native.tsx +84 -0
- package/src/components/ui/Progress/Progress.stories.tsx +1 -1
- package/src/components/ui/Progress/Progress.tsx +2 -2
- package/src/components/ui/ProgressCircle/ProgressCircle.module.css +3 -3
- package/src/components/ui/ProgressCircle/ProgressCircle.stories.tsx +1 -1
- package/src/components/ui/ProgressCircle/ProgressCircle.tsx +2 -2
- package/src/components/ui/Separator/Separator.mdx +14 -0
- package/src/components/ui/Separator/Separator.module.css +1 -1
- package/src/components/ui/Separator/Separator.native.stories.tsx +42 -0
- package/src/components/ui/Separator/Separator.native.tsx +32 -0
- package/src/components/ui/Separator/Separator.stories.tsx +1 -1
- package/src/components/ui/Separator/Separator.tsx +2 -2
- package/src/components/ui/Skeleton/Skeleton.module.css +3 -3
- package/src/components/ui/Skeleton/Skeleton.native.stories.tsx +33 -0
- package/src/components/ui/Skeleton/Skeleton.native.tsx +41 -0
- package/src/components/ui/Skeleton/Skeleton.stories.tsx +1 -1
- package/src/components/ui/Skeleton/Skeleton.tsx +2 -3
- package/src/components/ui/SkipLink/SkipLink.module.css +3 -3
- package/src/components/ui/SkipLink/SkipLink.stories.tsx +1 -1
- package/src/components/ui/SkipLink/SkipLink.tsx +5 -3
- package/src/components/ui/Table/Table.mdx +14 -0
- package/src/components/ui/Table/Table.module.css +11 -11
- package/src/components/ui/Table/Table.stories.tsx +1 -1
- package/src/components/ui/Table/Table.tsx +2 -2
- package/src/components/ui/Tabs/Tabs.module.css +3 -3
- package/src/components/ui/Tabs/Tabs.stories.tsx +1 -1
- package/src/components/ui/Tabs/Tabs.tsx +2 -2
- package/src/components/ui/Tooltip/Tooltip.mdx +14 -0
- package/src/components/ui/Tooltip/Tooltip.module.css +2 -2
- package/src/components/ui/Tooltip/Tooltip.stories.tsx +1 -1
- package/src/components/ui/Tooltip/Tooltip.tsx +2 -2
- package/src/components/ui/Typography/Typography.mdx +13 -0
- package/src/components/ui/Typography/Typography.module.css +1 -1
- package/src/components/ui/Typography/Typography.native.stories.tsx +38 -0
- package/src/components/ui/Typography/Typography.native.tsx +65 -0
- package/src/components/ui/Typography/Typography.stories.tsx +1 -1
- package/src/components/ui/Typography/Typography.tsx +2 -2
- package/src/css/bdc.css +10 -2
- package/src/index.ts +3 -0
- package/src/native/ThemeContext.tsx +28 -0
- package/src/native/tokens.ts +13 -0
- package/src/native.ts +39 -0
- package/src/react-augment.d.ts +13 -0
- package/src/stories/DesignSystem/Borders.mdx +7 -7
- package/src/stories/DesignSystem/Colors.mdx +28 -29
- package/src/stories/DesignSystem/DarkMode.mdx +130 -0
- package/src/stories/DesignSystem/Elevation.mdx +4 -4
- package/src/stories/DesignSystem/Grid.mdx +5 -5
- package/src/stories/DesignSystem/Motion.mdx +2 -2
- package/src/stories/DesignSystem/Overview.mdx +1 -1
- package/src/stories/DesignSystem/Spacing.mdx +3 -3
- package/src/stories/DesignSystem/Typography.mdx +6 -6
- package/src/types.ts +2 -0
- package/src/typings.d.ts +3 -0
- package/src/web-components/globals.ts +61 -0
- package/src/web-components/index.ts +12 -0
- package/src/web-components/interaction/BdsButton.stories.tsx +60 -0
- package/src/web-components/interaction/BdsPopover.stories.tsx +70 -0
- package/src/web-components/interaction/BdsToastProvider.stories.tsx +73 -0
- package/src/web-components/interaction/bds-button.spec.ts +95 -0
- package/src/web-components/interaction/bds-button.ts +293 -0
- package/src/web-components/interaction/bds-popover.spec.ts +126 -0
- package/src/web-components/interaction/bds-popover.ts +217 -0
- package/src/web-components/interaction/bds-toast-provider.spec.ts +122 -0
- package/src/web-components/interaction/bds-toast-provider.ts +211 -0
- package/src/web-components/test/helpers.ts +14 -0
- package/src/web-components/ui/BdsAlert.stories.tsx +60 -0
- package/src/web-components/ui/BdsBadge.stories.tsx +37 -0
- package/src/web-components/ui/bds-alert.spec.ts +109 -0
- package/src/web-components/ui/bds-alert.ts +209 -0
- package/src/web-components/ui/bds-badge.spec.ts +51 -0
- package/src/web-components/ui/bds-badge.ts +88 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { LitElement, css, html, nothing } from 'lit';
|
|
2
|
+
|
|
3
|
+
export type AlertVariant = 'info' | 'success' | 'warning' | 'error';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `<bds-alert>` — framework-agnostic Alert custom element.
|
|
7
|
+
*
|
|
8
|
+
* Attributes:
|
|
9
|
+
* variant — "info" (default) | "success" | "warning" | "error"
|
|
10
|
+
* title — optional heading above the body text
|
|
11
|
+
* dismissible — boolean; shows a dismiss button when present
|
|
12
|
+
*
|
|
13
|
+
* Slots:
|
|
14
|
+
* (default) — alert body content
|
|
15
|
+
* icon — optional icon displayed to the left of the content
|
|
16
|
+
*
|
|
17
|
+
* Events:
|
|
18
|
+
* bds-dismiss — fired (bubbles, composed) when the dismiss button is clicked
|
|
19
|
+
*
|
|
20
|
+
* Accessibility:
|
|
21
|
+
* role="alert" + aria-live="assertive" for error/warning variants,
|
|
22
|
+
* role="status" + aria-live="polite" for info/success variants.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* <bds-alert variant="success" title="Saved!">Your changes have been saved.</bds-alert>
|
|
26
|
+
*
|
|
27
|
+
* <bds-alert variant="error" dismissible>
|
|
28
|
+
* <svg slot="icon">…</svg>
|
|
29
|
+
* Something went wrong.
|
|
30
|
+
* </bds-alert>
|
|
31
|
+
*/
|
|
32
|
+
export class BdsAlert extends LitElement {
|
|
33
|
+
static styles = css`
|
|
34
|
+
:host {
|
|
35
|
+
display: block;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.alert {
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: flex-start;
|
|
41
|
+
gap: var(--bds-space_s);
|
|
42
|
+
padding: var(--bds-space_m);
|
|
43
|
+
border-radius: var(--bds-border_radius--s);
|
|
44
|
+
border-inline-start: var(--bds-space_s) solid var(--alert_border, var(--bds-color_blue));
|
|
45
|
+
background-color: var(--alert_bg, var(--bds-color_blue--subtle));
|
|
46
|
+
color: var(--alert_text, var(--bds-color_on-blue--subtle));
|
|
47
|
+
font-size: var(--bds-font_size--body);
|
|
48
|
+
line-height: var(--bds-font_line-height--body);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Variant colours */
|
|
52
|
+
:host([variant='info']) .alert {
|
|
53
|
+
--alert_bg: var(--bds-color_blue--subtle);
|
|
54
|
+
--alert_text: var(--bds-color_on-blue--subtle);
|
|
55
|
+
--alert_border: var(--bds-color_blue);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
:host([variant='success']) .alert {
|
|
59
|
+
--alert_bg: var(--bds-color_success--subtle);
|
|
60
|
+
--alert_text: var(--bds-color_on-success--subtle);
|
|
61
|
+
--alert_border: var(--bds-color_success);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
:host([variant='warning']) .alert {
|
|
65
|
+
--alert_bg: var(--bds-color_orange--subtle);
|
|
66
|
+
--alert_text: var(--bds-color_on-orange--subtle);
|
|
67
|
+
--alert_border: var(--bds-color_warning);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:host([variant='error']) .alert {
|
|
71
|
+
--alert_bg: rgb(from var(--bds-color_error) r g b / 12%);
|
|
72
|
+
--alert_text: var(--bds-color_on-bg);
|
|
73
|
+
--alert_border: var(--bds-color_error);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Icon slot wrapper — hidden unless slot has content */
|
|
77
|
+
.icon {
|
|
78
|
+
display: none;
|
|
79
|
+
align-items: center;
|
|
80
|
+
flex-shrink: 0;
|
|
81
|
+
margin-block-start: 0.1em;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.icon.has-content {
|
|
85
|
+
display: flex;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* Content area */
|
|
89
|
+
.content {
|
|
90
|
+
flex: 1;
|
|
91
|
+
display: flex;
|
|
92
|
+
flex-direction: column;
|
|
93
|
+
gap: var(--bds-space_xxs);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.title {
|
|
97
|
+
font-weight: var(--bds-font_weight--semibold);
|
|
98
|
+
font-size: var(--bds-font_size--body);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* Dismiss button */
|
|
102
|
+
.dismiss {
|
|
103
|
+
all: unset;
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
flex-shrink: 0;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
color: currentcolor;
|
|
110
|
+
transition: var(--bds-animation_transition);
|
|
111
|
+
border-radius: 50%;
|
|
112
|
+
--bdc_color: currentcolor;
|
|
113
|
+
outline: var(--bdc-outline_width) solid var(--bdc_color);
|
|
114
|
+
outline-offset: var(--bdc-outline_offset);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.dismiss svg {
|
|
118
|
+
width: 1rem;
|
|
119
|
+
height: 1rem;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.dismiss:focus-visible {
|
|
123
|
+
outline: var(--bds-outline_default);
|
|
124
|
+
outline-offset: var(--bds-outline_offset);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@media (hover: hover) and (pointer: fine) {
|
|
128
|
+
.dismiss:hover {
|
|
129
|
+
opacity: 0.7;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
static properties = {
|
|
135
|
+
variant: { type: String, reflect: true },
|
|
136
|
+
title: { type: String },
|
|
137
|
+
dismissible: { type: Boolean, reflect: true },
|
|
138
|
+
_iconFilled: { state: true },
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// `declare` annotates the type without emitting a class field initializer
|
|
142
|
+
// that would shadow Lit's reactive accessors on the prototype.
|
|
143
|
+
declare variant: AlertVariant;
|
|
144
|
+
declare title: string;
|
|
145
|
+
declare dismissible: boolean;
|
|
146
|
+
declare private _iconFilled: boolean;
|
|
147
|
+
|
|
148
|
+
constructor() {
|
|
149
|
+
super();
|
|
150
|
+
this.variant = 'info';
|
|
151
|
+
this.title = '';
|
|
152
|
+
this.dismissible = false;
|
|
153
|
+
this._iconFilled = false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private _onIconSlotChange(e: Event) {
|
|
157
|
+
const slot = e.target as HTMLSlotElement;
|
|
158
|
+
this._iconFilled = slot.assignedNodes({ flatten: true }).length > 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private get _isUrgent() {
|
|
162
|
+
return this.variant === 'error' || this.variant === 'warning';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private _handleDismiss() {
|
|
166
|
+
this.dispatchEvent(new CustomEvent('bds-dismiss', { bubbles: true, composed: true }));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
render() {
|
|
170
|
+
return html`
|
|
171
|
+
<div
|
|
172
|
+
class="alert"
|
|
173
|
+
role=${this._isUrgent ? 'alert' : 'status'}
|
|
174
|
+
aria-live=${this._isUrgent ? 'assertive' : 'polite'}
|
|
175
|
+
aria-atomic="true"
|
|
176
|
+
>
|
|
177
|
+
<span class="icon ${this._iconFilled ? 'has-content' : ''}" aria-hidden="true">
|
|
178
|
+
<slot name="icon" @slotchange=${this._onIconSlotChange}></slot>
|
|
179
|
+
</span>
|
|
180
|
+
<div class="content">
|
|
181
|
+
${this.title ? html`<strong class="title">${this.title}</strong>` : nothing}
|
|
182
|
+
<div><slot></slot></div>
|
|
183
|
+
</div>
|
|
184
|
+
${this.dismissible
|
|
185
|
+
? html`
|
|
186
|
+
<button
|
|
187
|
+
type="button"
|
|
188
|
+
class="dismiss"
|
|
189
|
+
@click=${this._handleDismiss}
|
|
190
|
+
aria-label="Dismiss alert"
|
|
191
|
+
>
|
|
192
|
+
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
193
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M18 6L6 18M6 6l12 12" />
|
|
194
|
+
</svg>
|
|
195
|
+
</button>
|
|
196
|
+
`
|
|
197
|
+
: nothing}
|
|
198
|
+
</div>
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
customElements.define('bds-alert', BdsAlert);
|
|
204
|
+
|
|
205
|
+
declare global {
|
|
206
|
+
interface HTMLElementTagNameMap {
|
|
207
|
+
'bds-alert': BdsAlert;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../test/helpers';
|
|
2
|
+
import { BdsBadge } from './bds-badge';
|
|
3
|
+
|
|
4
|
+
describe('bds-badge', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-badge')).toBe(BdsBadge);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a span.badge in shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-badge>New</bds-badge>');
|
|
11
|
+
const span = el.shadowRoot!.querySelector('.badge');
|
|
12
|
+
expect(span).not.toBeNull();
|
|
13
|
+
cleanup(el);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('defaults to variant="primary"', async () => {
|
|
17
|
+
const el = await fixture('<bds-badge>New</bds-badge>');
|
|
18
|
+
expect(el.getAttribute('variant')).toBe('primary');
|
|
19
|
+
cleanup(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('reflects variant attribute', async () => {
|
|
23
|
+
const el = await fixture('<bds-badge variant="success">OK</bds-badge>');
|
|
24
|
+
expect(el.getAttribute('variant')).toBe('success');
|
|
25
|
+
cleanup(el);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('updates variant property', async () => {
|
|
29
|
+
const el = await fixture('<bds-badge>Label</bds-badge>') as BdsBadge;
|
|
30
|
+
el.variant = 'error';
|
|
31
|
+
await el.updateComplete;
|
|
32
|
+
expect(el.getAttribute('variant')).toBe('error');
|
|
33
|
+
cleanup(el);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('renders slotted text content', async () => {
|
|
37
|
+
const el = await fixture('<bds-badge>Hello</bds-badge>');
|
|
38
|
+
// Slotted content lives in light DOM
|
|
39
|
+
expect(el.textContent?.trim()).toBe('Hello');
|
|
40
|
+
cleanup(el);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('accepts all valid variant values', async () => {
|
|
44
|
+
const variants = ['primary', 'secondary', 'success', 'error', 'warning'] as const;
|
|
45
|
+
for (const variant of variants) {
|
|
46
|
+
const el = await fixture(`<bds-badge variant="${variant}">Label</bds-badge>`);
|
|
47
|
+
expect(el.getAttribute('variant')).toBe(variant);
|
|
48
|
+
cleanup(el);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
export type BadgeVariant = 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `<bds-badge>` — framework-agnostic Badge custom element.
|
|
7
|
+
*
|
|
8
|
+
* Attributes:
|
|
9
|
+
* variant — "primary" (default) | "secondary" | "success" | "error" | "warning"
|
|
10
|
+
*
|
|
11
|
+
* Slots:
|
|
12
|
+
* (default) — badge label text / content
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <bds-badge variant="success">New</bds-badge>
|
|
16
|
+
*/
|
|
17
|
+
export class BdsBadge extends LitElement {
|
|
18
|
+
static styles = css`
|
|
19
|
+
:host {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.badge {
|
|
24
|
+
display: inline-flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
padding: var(--bds-space_xxs) var(--bds-space_xs);
|
|
28
|
+
border-radius: var(--badge_radius, 2em);
|
|
29
|
+
font-size: var(--badge_font-size, var(--bds-font_size--body--s));
|
|
30
|
+
font-weight: var(--bds-font_weight--semibold);
|
|
31
|
+
line-height: 1;
|
|
32
|
+
white-space: nowrap;
|
|
33
|
+
background-color: var(--badge_bg, var(--bds-color_blue));
|
|
34
|
+
color: var(--badge_text, var(--bds-color_on-blue));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Variant overrides */
|
|
38
|
+
:host([variant='primary']) .badge {
|
|
39
|
+
--badge_bg: var(--bds-color_interactive);
|
|
40
|
+
--badge_text: var(--bds-color_on-interactive);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
:host([variant='secondary']) .badge {
|
|
44
|
+
--badge_bg: var(--bds-color_bg);
|
|
45
|
+
--badge_text: var(--bds-color_on-bg);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:host([variant='success']) .badge {
|
|
49
|
+
--badge_bg: var(--bds-color_success);
|
|
50
|
+
--badge_text: var(--bds-color_on-success);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
:host([variant='error']) .badge {
|
|
54
|
+
--badge_bg: var(--bds-color_error);
|
|
55
|
+
--badge_text: var(--bds-color_on-error);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
:host([variant='warning']) .badge {
|
|
59
|
+
--badge_bg: var(--bds-color_warning);
|
|
60
|
+
--badge_text: var(--bds-color_on-warning);
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
static properties = {
|
|
65
|
+
variant: { type: String, reflect: true },
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// `declare` gives TypeScript the type without emitting a class field initializer
|
|
69
|
+
// that would shadow Lit's reactive accessor on the prototype.
|
|
70
|
+
declare variant: BadgeVariant;
|
|
71
|
+
|
|
72
|
+
constructor() {
|
|
73
|
+
super();
|
|
74
|
+
this.variant = 'primary';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
render() {
|
|
78
|
+
return html`<span class="badge"><slot></slot></span>`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
customElements.define('bds-badge', BdsBadge);
|
|
83
|
+
|
|
84
|
+
declare global {
|
|
85
|
+
interface HTMLElementTagNameMap {
|
|
86
|
+
'bds-badge': BdsBadge;
|
|
87
|
+
}
|
|
88
|
+
}
|