@boostdev/design-system-components 2.5.1 → 2.7.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/dist/client.cjs +257 -219
- package/dist/client.css +673 -626
- package/dist/client.d.cts +27 -1
- package/dist/client.d.ts +27 -1
- package/dist/client.js +220 -183
- package/dist/index.cjs +257 -219
- package/dist/index.css +673 -626
- package/dist/index.d.cts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +220 -183
- package/dist/web-components/{chunk-N3TN6WCH.js → chunk-GER5UJOF.js} +22 -15
- package/dist/web-components/chunk-QWPACK5L.js +72 -0
- package/dist/web-components/{chunk-YRXCVKHV.js → chunk-RTOS7LLG.js} +9 -7
- package/dist/web-components/{chunk-BX3IPVOB.js → chunk-ZNKEZIYE.js} +20 -16
- package/dist/web-components/index.d.ts +56 -1
- package/dist/web-components/index.js +121 -4
- package/dist/web-components/interaction/bds-button.js +1 -1
- package/dist/web-components/ui/bds-alert.js +1 -1
- package/dist/web-components/ui/bds-badge.js +1 -1
- package/dist/web-components/ui/bds-card.js +1 -1
- package/package.json +3 -2
- package/src/components/interaction/Button/Button.mdx +87 -13
- package/src/components/interaction/Button/Button.module.css +22 -17
- package/src/components/interaction/Toast/Toast.mdx +22 -3
- package/src/components/interaction/Toast/Toast.module.css +13 -10
- package/src/components/interaction/form/FieldGroup/FieldGroup.mdx +113 -0
- package/src/components/interaction/form/FieldGroup/FieldGroup.module.css +96 -0
- package/src/components/interaction/form/FieldGroup/FieldGroup.spec.tsx +196 -0
- package/src/components/interaction/form/FieldGroup/FieldGroup.stories.tsx +99 -0
- package/src/components/interaction/form/FieldGroup/FieldGroup.tsx +64 -0
- package/src/components/interaction/form/FieldGroup/index.ts +2 -0
- package/src/components/interaction/form/atoms/Message.module.css +4 -0
- package/src/components/layout/Card/Card.mdx +20 -8
- package/src/components/layout/Card/Card.module.css +5 -3
- package/src/components/ui/Alert/Alert.mdx +39 -5
- package/src/components/ui/Alert/Alert.module.css +21 -15
- package/src/components/ui/Badge/Badge.mdx +23 -3
- package/src/components/ui/Badge/Badge.module.css +15 -12
- package/src/components/ui/Link/Link.mdx +20 -2
- package/src/components/ui/Link/Link.module.css +12 -8
- package/src/components/ui/NotificationBanner/NotificationBanner.mdx +25 -6
- package/src/components/ui/NotificationBanner/NotificationBanner.module.css +18 -15
- package/src/components/ui/Pagination/Pagination.mdx +22 -9
- package/src/components/ui/Pagination/Pagination.module.css +10 -8
- package/src/components/ui/Tabs/Tabs.mdx +20 -5
- package/src/components/ui/Tabs/Tabs.module.css +8 -5
- package/src/index.ts +2 -0
- package/src/web-components/index.ts +2 -0
- package/src/web-components/interaction/bds-button.ts +22 -15
- package/src/web-components/interaction/form/BdsFieldGroup.mdx +67 -0
- package/src/web-components/interaction/form/BdsFieldGroup.stories.tsx +110 -0
- package/src/web-components/interaction/form/bds-checkbox-group.ts +1 -0
- package/src/web-components/interaction/form/bds-field-group.spec.ts +64 -0
- package/src/web-components/interaction/form/bds-field-group.ts +157 -0
- package/src/web-components/interaction/form/bds-form-input.ts +1 -0
- package/src/web-components/interaction/form/bds-radio-group.ts +1 -0
- package/src/web-components/ui/bds-alert.ts +20 -16
- package/src/web-components/ui/bds-badge.ts +16 -13
- package/src/web-components/ui/bds-card.ts +9 -7
- package/dist/web-components/chunk-OHUTLSIQ.js +0 -69
|
@@ -35,20 +35,35 @@ Organises content into discrete panels accessible via a horizontal tab list.
|
|
|
35
35
|
|
|
36
36
|
## CSS variables
|
|
37
37
|
|
|
38
|
+
The override surface is **layered**. Setting `--tab_color` / `--tab_border-color` on the tablist (or any ancestor) wins in every state — resting, hover, and active. Setting per-state tokens targets only that one state.
|
|
39
|
+
|
|
40
|
+
### Public override tokens (win over per-state defaults)
|
|
38
41
|
|
|
39
42
|
<table>
|
|
40
43
|
<thead>
|
|
41
44
|
<tr><th>Variable</th><th>Default</th><th>Description</th></tr>
|
|
42
45
|
</thead>
|
|
43
46
|
<tbody>
|
|
44
|
-
<tr><td>`--tab_color`</td><td
|
|
45
|
-
<tr><td>`--tab_border-color`</td><td
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
<tr><td>`--tab_color`</td><td>per state</td><td>Tab text colour. Set to theme every state at once.</td></tr>
|
|
48
|
+
<tr><td>`--tab_border-color`</td><td>per state</td><td>Tab block-end border colour.</td></tr>
|
|
49
|
+
</tbody>
|
|
50
|
+
</table>
|
|
51
|
+
|
|
52
|
+
### Per-state overrides
|
|
53
|
+
|
|
54
|
+
<table>
|
|
55
|
+
<thead>
|
|
56
|
+
<tr><th>State</th><th>Text</th><th>Border</th></tr>
|
|
57
|
+
</thead>
|
|
58
|
+
<tbody>
|
|
59
|
+
<tr><td>resting</td><td>(`var(--bds-color_on-bg)`)</td><td>(`transparent`)</td></tr>
|
|
60
|
+
<tr><td>hover</td><td>`--tab_color--hover`</td><td>—</td></tr>
|
|
61
|
+
<tr><td>active</td><td>`--tab_color--active`</td><td>`--tab_border-color--active`</td></tr>
|
|
49
62
|
</tbody>
|
|
50
63
|
</table>
|
|
51
64
|
|
|
65
|
+
Defaults: hover/active text resolves to `--bds-color_interactive_on-bg`; active border to `--bds-color_interactive`.
|
|
66
|
+
|
|
52
67
|
|
|
53
68
|
## Accessibility
|
|
54
69
|
|
|
@@ -18,16 +18,19 @@
|
|
|
18
18
|
font-family: var(--bds-font_family--body);
|
|
19
19
|
font-size: var(--bds-font_size--body);
|
|
20
20
|
font-weight: var(--bds-font_weight--semibold);
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
/* Layered cascade: public overrides (--tab_color, --tab_border-color) win over
|
|
23
|
+
per-state defaults. Active/hover write to the inner --tab_*--state slot. */
|
|
24
|
+
color: var(--tab_color, var(--tab_color--state, var(--bds-color_on-bg)));
|
|
25
|
+
border-block-end: 2px solid var(--tab_border-color, var(--tab_border-color--state, transparent));
|
|
23
26
|
margin-block-end: -1px;
|
|
24
27
|
cursor: pointer;
|
|
25
28
|
transition: var(--bds-animation_transition);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
.tab.--active {
|
|
29
|
-
--tab_color: var(--tab_color--active, var(--bds-color_interactive_on-bg));
|
|
30
|
-
--tab_border-color: var(--tab_border-color--active, var(--bds-color_interactive));
|
|
32
|
+
--tab_color--state: var(--tab_color--active, var(--bds-color_interactive_on-bg));
|
|
33
|
+
--tab_border-color--state: var(--tab_border-color--active, var(--bds-color_interactive));
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
.tab:disabled {
|
|
@@ -43,7 +46,7 @@
|
|
|
43
46
|
|
|
44
47
|
@media (hover: hover) and (pointer: fine) {
|
|
45
48
|
.tab:not(:disabled, .--active):hover {
|
|
46
|
-
--tab_color: var(--tab_color--hover, var(--bds-color_interactive_on-bg));
|
|
49
|
+
--tab_color--state: var(--tab_color--hover, var(--bds-color_interactive_on-bg));
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,8 @@ export { Checkbox } from './components/interaction/form/Checkbox';
|
|
|
48
48
|
export { CheckboxGroup } from './components/interaction/form/CheckboxGroup';
|
|
49
49
|
export type { CheckboxGroupProps } from './components/interaction/form/CheckboxGroup';
|
|
50
50
|
export { Combobox } from './components/interaction/form/Combobox';
|
|
51
|
+
export { FieldGroup } from './components/interaction/form/FieldGroup';
|
|
52
|
+
export type { FieldGroupProps, FieldGroupVariant } from './components/interaction/form/FieldGroup';
|
|
51
53
|
export type { ComboboxOption } from './components/interaction/form/Combobox';
|
|
52
54
|
export { FileInput } from './components/interaction/form/FileInput';
|
|
53
55
|
export { FormInput } from './components/interaction/form/FormInput';
|
|
@@ -68,6 +68,8 @@ export { BdsTable } from './ui/bds-table';
|
|
|
68
68
|
export { BdsPagination } from './ui/bds-pagination';
|
|
69
69
|
export { BdsCheckboxGroup } from './interaction/form/bds-checkbox-group';
|
|
70
70
|
export { BdsRadioGroup } from './interaction/form/bds-radio-group';
|
|
71
|
+
export { BdsFieldGroup } from './interaction/form/bds-field-group';
|
|
72
|
+
export type { FieldGroupVariant as BdsFieldGroupVariant } from './interaction/form/bds-field-group';
|
|
71
73
|
export { BdsFormInput } from './interaction/form/bds-form-input';
|
|
72
74
|
export { BdsCarousel } from './ui/bds-carousel';
|
|
73
75
|
export { BdsCalendar } from './ui/bds-calendar';
|
|
@@ -65,14 +65,20 @@ export class BdsButton extends LitElement {
|
|
|
65
65
|
white-space: nowrap;
|
|
66
66
|
line-height: 1;
|
|
67
67
|
|
|
68
|
+
/* Identity tokens — override --button_color + --button_on-color to re-theme */
|
|
68
69
|
--button_color: var(--bds-color_interactive);
|
|
69
70
|
--button_on-color: var(--bds-color_on-interactive);
|
|
71
|
+
|
|
72
|
+
/* Text-safe variant of --button_color for use on page background (outline text/border) */
|
|
70
73
|
--button_color--on-bg: var(--bds-color_interactive_on-bg);
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
/* Layered cascade: the consumer-facing overrides (--button_bg, --button_text,
|
|
76
|
+
--button_border) are read OUTERMOST so an ancestor-set value always wins
|
|
77
|
+
over variant + hover defaults. Variants and hover write to the inner
|
|
78
|
+
--button_*--variant slot, never to the public tokens. */
|
|
79
|
+
background-color: var(--button_bg, var(--button_bg--variant, var(--button_color)));
|
|
80
|
+
color: var(--button_text, var(--button_text--variant, var(--button_on-color)));
|
|
81
|
+
--bdc_color: var(--button_border, var(--button_border--variant, transparent));
|
|
76
82
|
|
|
77
83
|
box-shadow: inset 0 0 0 var(--bdc-outline_width) var(--bdc_color);
|
|
78
84
|
transition: var(--bds-animation_transition),
|
|
@@ -83,12 +89,13 @@ export class BdsButton extends LitElement {
|
|
|
83
89
|
text-decoration: none;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
/* Variants
|
|
92
|
+
/* Variants — outline-resting overrides (--button_bg--outline, --button_text--outline,
|
|
93
|
+
--button_border--outline) are honored if the consumer sets them. */
|
|
87
94
|
.button.outline,
|
|
88
95
|
.button.ghost /* deprecated — use variant="outline" */ {
|
|
89
|
-
--button_bg:
|
|
90
|
-
--button_text: var(--button_color--on-bg);
|
|
91
|
-
--
|
|
96
|
+
--button_bg--variant: var(--button_bg--outline, transparent);
|
|
97
|
+
--button_text--variant: var(--button_text--outline, var(--button_color--on-bg));
|
|
98
|
+
--button_border--variant: var(--button_border--outline, var(--button_color--on-bg));
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
/* Sizes */
|
|
@@ -174,18 +181,18 @@ export class BdsButton extends LitElement {
|
|
|
174
181
|
|
|
175
182
|
/* Default hover */
|
|
176
183
|
.button.default:hover {
|
|
177
|
-
--button_bg:
|
|
178
|
-
--button_text:
|
|
179
|
-
--
|
|
180
|
-
--
|
|
184
|
+
--button_bg--variant: var(--button_bg--hover, var(--bds-color_bg));
|
|
185
|
+
--button_text--variant: var(--button_text--hover, var(--bds-color_interactive));
|
|
186
|
+
--button_border--variant: var(--button_border--hover, currentcolor);
|
|
187
|
+
--button_pulse-color: var(--button_pulse-color--hover, var(--bds-color_interactive));
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
/* Outline hover */
|
|
184
191
|
.button.outline:hover,
|
|
185
192
|
.button.ghost:hover {
|
|
186
|
-
--button_bg:
|
|
187
|
-
--button_text: var(--button_on-color);
|
|
188
|
-
--
|
|
193
|
+
--button_bg--variant: var(--button_bg--outline-hover, var(--button_color));
|
|
194
|
+
--button_text--variant: var(--button_text--outline-hover, var(--button_on-color));
|
|
195
|
+
--button_border--variant: var(--button_border--outline-hover, transparent);
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
198
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Meta, Canvas } from '@storybook/blocks';
|
|
2
|
+
import * as Stories from './BdsFieldGroup.stories';
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# `<bds-field-group>`
|
|
7
|
+
|
|
8
|
+
Framework-agnostic FieldGroup custom element. Wraps slotted fields in a `<fieldset>` with a styled `<legend>` and lays them out horizontally (with auto-collapse to vertical via CSS container query) or vertically.
|
|
9
|
+
|
|
10
|
+
Mirrors the React `FieldGroup` component — same token surface, same behavior, same auto-derived collapse threshold.
|
|
11
|
+
|
|
12
|
+
## Attributes
|
|
13
|
+
|
|
14
|
+
| Attribute | Values | Default | Description |
|
|
15
|
+
|-----------|--------|---------|-------------|
|
|
16
|
+
| `variant` | `horizontal` \| `vertical` | `horizontal` | Layout direction. |
|
|
17
|
+
| `legend` | string | — | Optional legend text. Falls back to `aria-label` semantics if you set that on the host directly. |
|
|
18
|
+
| `disabled` | boolean | `false` | Forwards to the inner `<fieldset>`; the UA cascades it to descendant form controls (light-DOM children projected through the slot). |
|
|
19
|
+
|
|
20
|
+
## Slots
|
|
21
|
+
|
|
22
|
+
- `(default)` — projected form fields (`<bds-form-input>`, `<bds-select>`, etc.). The component listens for `slotchange` and surfaces the slotted-element count via `--fieldGroup_field-count`, which the auto-derived collapse threshold reads.
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
### Horizontal
|
|
27
|
+
<Canvas of={Stories.Horizontal} />
|
|
28
|
+
|
|
29
|
+
### Vertical
|
|
30
|
+
<Canvas of={Stories.Vertical} />
|
|
31
|
+
|
|
32
|
+
### Horizontal collapses in a narrow container
|
|
33
|
+
<Canvas of={Stories.HorizontalCollapsesInNarrowContainer} />
|
|
34
|
+
|
|
35
|
+
### Without a legend
|
|
36
|
+
<Canvas of={Stories.WithoutLegend} />
|
|
37
|
+
|
|
38
|
+
### Disabled
|
|
39
|
+
<Canvas of={Stories.Disabled} />
|
|
40
|
+
|
|
41
|
+
## CSS variables
|
|
42
|
+
|
|
43
|
+
Same surface as the React component. All public tokens are read with foundation-default fallbacks; consumers can set them on the host (or any ancestor) to theme one or many groups without touching internal classes.
|
|
44
|
+
|
|
45
|
+
### Layout
|
|
46
|
+
|
|
47
|
+
| Variable | Default |
|
|
48
|
+
|----------|---------|
|
|
49
|
+
| `--fieldGroup_gap` | `var(--bds-space_m)` |
|
|
50
|
+
| `--fieldGroup_min-field-width` | `12rem` |
|
|
51
|
+
| `--fieldGroup_collapse-threshold` | `calc(N × min-field-width + (N − 1) × gap)` (computed) |
|
|
52
|
+
|
|
53
|
+
### Legend
|
|
54
|
+
|
|
55
|
+
| Variable | Default |
|
|
56
|
+
|----------|---------|
|
|
57
|
+
| `--fieldGroup_legend-color` | `var(--bds-color_on-bg)` |
|
|
58
|
+
| `--fieldGroup_legend-font-size` | `var(--bds-font_size--heading-3)` |
|
|
59
|
+
| `--fieldGroup_legend-font-weight` | `var(--bds-font_weight--semibold)` |
|
|
60
|
+
| `--fieldGroup_legend-line-height` | `var(--bds-font_line-height--heading)` |
|
|
61
|
+
| `--fieldGroup_legend-padding-block` | `var(--bds-space_xs)` |
|
|
62
|
+
| `--fieldGroup_legend-gap` | `var(--bds-space_m)` |
|
|
63
|
+
| `--fieldGroup_legend-border-block-end` | `1px solid var(--bds-color_bg--subtle)` |
|
|
64
|
+
|
|
65
|
+
## Notes on shadow DOM
|
|
66
|
+
|
|
67
|
+
The component renders its own `<fieldset>` inside the shadow root and projects fields through a `<slot>`. Because slotted elements stay in the host's light DOM, the native `fieldset[disabled]` cascade onto descendants is browser-dependent — modern browsers do propagate disabled to slotted form controls; older ones may not. If you support an older runtime and need a hard guarantee, set `disabled` on each slotted field too.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import '../../index'; // auto-registers all custom elements
|
|
4
|
+
|
|
5
|
+
function BdsFieldGroup({
|
|
6
|
+
legend,
|
|
7
|
+
variant,
|
|
8
|
+
disabled,
|
|
9
|
+
children,
|
|
10
|
+
}: {
|
|
11
|
+
legend?: string;
|
|
12
|
+
variant?: 'horizontal' | 'vertical';
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
}) {
|
|
16
|
+
return React.createElement(
|
|
17
|
+
'bds-field-group',
|
|
18
|
+
{
|
|
19
|
+
legend: legend || undefined,
|
|
20
|
+
variant: variant || undefined,
|
|
21
|
+
disabled: disabled || undefined,
|
|
22
|
+
},
|
|
23
|
+
children,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const meta = {
|
|
28
|
+
title: 'Web Components/Form/FieldGroup',
|
|
29
|
+
component: BdsFieldGroup,
|
|
30
|
+
tags: ['!stable', 'experimental'],
|
|
31
|
+
parameters: {
|
|
32
|
+
layout: 'padded',
|
|
33
|
+
docs: {
|
|
34
|
+
description: {
|
|
35
|
+
component:
|
|
36
|
+
'Framework-agnostic FieldGroup. Wraps slotted fields in a `<fieldset>` ' +
|
|
37
|
+
'and lays them out horizontally with a CSS container query that auto-collapses ' +
|
|
38
|
+
'to a single column when the host is too narrow to fit a complete row at minimum field width.',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
argTypes: {
|
|
43
|
+
variant: { control: 'select', options: ['horizontal', 'vertical'] },
|
|
44
|
+
legend: { control: 'text' },
|
|
45
|
+
disabled: { control: 'boolean' },
|
|
46
|
+
},
|
|
47
|
+
} satisfies Meta<typeof BdsFieldGroup>;
|
|
48
|
+
|
|
49
|
+
export default meta;
|
|
50
|
+
type Story = StoryObj<typeof meta>;
|
|
51
|
+
|
|
52
|
+
const field = (name: string, label: string, type = 'text') =>
|
|
53
|
+
React.createElement('bds-form-input', { name, label, type });
|
|
54
|
+
|
|
55
|
+
export const Horizontal: Story = {
|
|
56
|
+
args: { legend: 'Contact details', variant: 'horizontal' },
|
|
57
|
+
render: args => (
|
|
58
|
+
<BdsFieldGroup {...args}>
|
|
59
|
+
{field('first', 'First name')}
|
|
60
|
+
{field('last', 'Last name')}
|
|
61
|
+
{field('email', 'Email', 'email')}
|
|
62
|
+
</BdsFieldGroup>
|
|
63
|
+
),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const Vertical: Story = {
|
|
67
|
+
args: { legend: 'Contact details', variant: 'vertical' },
|
|
68
|
+
render: args => (
|
|
69
|
+
<BdsFieldGroup {...args}>
|
|
70
|
+
{field('first', 'First name')}
|
|
71
|
+
{field('last', 'Last name')}
|
|
72
|
+
{field('email', 'Email', 'email')}
|
|
73
|
+
</BdsFieldGroup>
|
|
74
|
+
),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const HorizontalCollapsesInNarrowContainer: Story = {
|
|
78
|
+
name: 'Horizontal — collapses in narrow container',
|
|
79
|
+
args: { legend: 'Same fields, narrower parent', variant: 'horizontal' },
|
|
80
|
+
render: args => (
|
|
81
|
+
<div style={{ inlineSize: '20rem', border: '1px dashed currentcolor', padding: '1rem' }}>
|
|
82
|
+
<BdsFieldGroup {...args}>
|
|
83
|
+
{field('first', 'First name')}
|
|
84
|
+
{field('last', 'Last name')}
|
|
85
|
+
{field('email', 'Email', 'email')}
|
|
86
|
+
</BdsFieldGroup>
|
|
87
|
+
</div>
|
|
88
|
+
),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const WithoutLegend: Story = {
|
|
92
|
+
args: { variant: 'horizontal' },
|
|
93
|
+
render: args => (
|
|
94
|
+
<BdsFieldGroup {...args}>
|
|
95
|
+
{field('q', 'Query')}
|
|
96
|
+
{field('from', 'From', 'date')}
|
|
97
|
+
{field('to', 'To', 'date')}
|
|
98
|
+
</BdsFieldGroup>
|
|
99
|
+
),
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const Disabled: Story = {
|
|
103
|
+
args: { legend: 'Disabled section', variant: 'horizontal', disabled: true },
|
|
104
|
+
render: args => (
|
|
105
|
+
<BdsFieldGroup {...args}>
|
|
106
|
+
{field('first', 'First name')}
|
|
107
|
+
{field('last', 'Last name')}
|
|
108
|
+
</BdsFieldGroup>
|
|
109
|
+
),
|
|
110
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsFieldGroup } from './bds-field-group';
|
|
3
|
+
|
|
4
|
+
describe('bds-field-group', () => {
|
|
5
|
+
it('is registered as a custom element', () => {
|
|
6
|
+
expect(customElements.get('bds-field-group')).toBe(BdsFieldGroup);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('renders a fieldset in the shadow DOM', async () => {
|
|
10
|
+
const el = await fixture('<bds-field-group></bds-field-group>');
|
|
11
|
+
expect(el.shadowRoot!.querySelector('fieldset')).not.toBeNull();
|
|
12
|
+
cleanup(el);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders the legend when the legend attribute is set', async () => {
|
|
16
|
+
const el = await fixture('<bds-field-group legend="Contact details"></bds-field-group>');
|
|
17
|
+
const legend = el.shadowRoot!.querySelector('legend');
|
|
18
|
+
expect(legend?.textContent?.trim()).toBe('Contact details');
|
|
19
|
+
cleanup(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('omits the legend element when no legend attribute is set', async () => {
|
|
23
|
+
const el = await fixture('<bds-field-group></bds-field-group>');
|
|
24
|
+
expect(el.shadowRoot!.querySelector('legend')).toBeNull();
|
|
25
|
+
cleanup(el);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('reflects the default horizontal variant onto the host', async () => {
|
|
29
|
+
const el = await fixture('<bds-field-group></bds-field-group>') as BdsFieldGroup;
|
|
30
|
+
expect(el.getAttribute('variant')).toBe('horizontal');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('honors variant="vertical" on the host', async () => {
|
|
34
|
+
const el = await fixture('<bds-field-group variant="vertical"></bds-field-group>') as BdsFieldGroup;
|
|
35
|
+
expect(el.getAttribute('variant')).toBe('vertical');
|
|
36
|
+
cleanup(el);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('forwards the disabled attribute to the inner fieldset', async () => {
|
|
40
|
+
const el = await fixture('<bds-field-group disabled></bds-field-group>');
|
|
41
|
+
const fieldset = el.shadowRoot!.querySelector('fieldset') as HTMLFieldSetElement;
|
|
42
|
+
expect(fieldset.disabled).toBe(true);
|
|
43
|
+
cleanup(el);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('renders a slot for projected fields', async () => {
|
|
47
|
+
const el = await fixture(
|
|
48
|
+
'<bds-field-group><span id="a"></span><span id="b"></span></bds-field-group>',
|
|
49
|
+
);
|
|
50
|
+
expect(el.shadowRoot!.querySelector('slot')).not.toBeNull();
|
|
51
|
+
expect(el.querySelectorAll('span').length).toBe(2);
|
|
52
|
+
cleanup(el);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('exposes the slotted-element count as --fieldGroup_field-count after slotchange', async () => {
|
|
56
|
+
const el = await fixture(
|
|
57
|
+
'<bds-field-group><span></span><span></span><span></span></bds-field-group>',
|
|
58
|
+
) as BdsFieldGroup;
|
|
59
|
+
// slotchange fires synchronously after the initial render; allow a microtask.
|
|
60
|
+
await new Promise(r => requestAnimationFrame(() => r(null)));
|
|
61
|
+
expect(el.style.getPropertyValue('--fieldGroup_field-count')).toBe('3');
|
|
62
|
+
cleanup(el);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { LitElement, css, html, nothing } from 'lit';
|
|
2
|
+
|
|
3
|
+
export type FieldGroupVariant = 'horizontal' | 'vertical';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `<bds-field-group>` — framework-agnostic FieldGroup custom element.
|
|
7
|
+
*
|
|
8
|
+
* Semantically groups related form fields under a single `<fieldset>` and
|
|
9
|
+
* lays them out either horizontally (with a CSS container query that
|
|
10
|
+
* collapses to a vertical stack when the FieldGroup itself is too narrow)
|
|
11
|
+
* or vertically. Mirrors the React `FieldGroup` component.
|
|
12
|
+
*
|
|
13
|
+
* Attributes:
|
|
14
|
+
* variant — "horizontal" (default) | "vertical"
|
|
15
|
+
* legend — optional legend text rendered above the fields
|
|
16
|
+
* disabled — boolean; forwarded to the inner <fieldset>
|
|
17
|
+
*
|
|
18
|
+
* Slots:
|
|
19
|
+
* (default) — form fields (any element). The slotted-element count is
|
|
20
|
+
* measured on each `slotchange` and surfaced via the
|
|
21
|
+
* `--fieldGroup_field-count` custom property, which the auto-derived
|
|
22
|
+
* collapse threshold reads.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* <bds-field-group variant="horizontal" legend="Contact details">
|
|
26
|
+
* <bds-form-input label="First name" name="first"></bds-form-input>
|
|
27
|
+
* <bds-form-input label="Last name" name="last"></bds-form-input>
|
|
28
|
+
* <bds-form-input label="Email" name="email"></bds-form-input>
|
|
29
|
+
* </bds-field-group>
|
|
30
|
+
*/
|
|
31
|
+
export class BdsFieldGroup extends LitElement {
|
|
32
|
+
static styles = css`
|
|
33
|
+
:host {
|
|
34
|
+
display: block;
|
|
35
|
+
|
|
36
|
+
/* Establish an inline-size containment context so the @container rule
|
|
37
|
+
queries the host's own width — independent of the viewport. */
|
|
38
|
+
container-type: inline-size;
|
|
39
|
+
container-name: field-group;
|
|
40
|
+
|
|
41
|
+
/* Auto-derived collapse threshold (mirror of the React component).
|
|
42
|
+
--fieldGroup_field-count is set inline by _onSlotChange; the other
|
|
43
|
+
tokens use foundation-default fallbacks so the calc rebuilds when
|
|
44
|
+
a consumer overrides --fieldGroup_min-field-width or _gap. */
|
|
45
|
+
--fieldGroup_collapse-threshold:
|
|
46
|
+
calc(
|
|
47
|
+
var(--fieldGroup_field-count, 1)
|
|
48
|
+
* var(--fieldGroup_min-field-width, 12rem)
|
|
49
|
+
+ (var(--fieldGroup_field-count, 1) - 1)
|
|
50
|
+
* var(--fieldGroup_gap, var(--bds-space_m))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fieldset {
|
|
55
|
+
border: 0;
|
|
56
|
+
margin: 0;
|
|
57
|
+
padding: 0;
|
|
58
|
+
min-inline-size: 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.legend {
|
|
62
|
+
inline-size: 100%;
|
|
63
|
+
padding-inline: 0;
|
|
64
|
+
|
|
65
|
+
padding-block:
|
|
66
|
+
var(--fieldGroup_legend-padding-block, var(--bds-space_xs));
|
|
67
|
+
margin-block-end:
|
|
68
|
+
var(--fieldGroup_legend-gap, var(--bds-space_m));
|
|
69
|
+
border-block-end:
|
|
70
|
+
var(--fieldGroup_legend-border-block-end, 1px solid var(--bds-color_bg--subtle));
|
|
71
|
+
|
|
72
|
+
color:
|
|
73
|
+
var(--fieldGroup_legend-color, var(--bds-color_on-bg));
|
|
74
|
+
font-family: var(--bds-font_family--body);
|
|
75
|
+
font-size:
|
|
76
|
+
var(--fieldGroup_legend-font-size, var(--bds-font_size--heading-3));
|
|
77
|
+
font-weight:
|
|
78
|
+
var(--fieldGroup_legend-font-weight, var(--bds-font_weight--semibold));
|
|
79
|
+
line-height:
|
|
80
|
+
var(--fieldGroup_legend-line-height, var(--bds-font_line-height--heading));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.fields {
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
gap: var(--fieldGroup_gap, var(--bds-space_m));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:host([variant='horizontal']) .fields {
|
|
90
|
+
flex-flow: row wrap;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
:host([variant='horizontal']) .fields ::slotted(*) {
|
|
94
|
+
flex: 1 1 var(--fieldGroup_min-field-width, 12rem);
|
|
95
|
+
min-inline-size: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Auto-collapse: when the host's inline-size can't fit a complete
|
|
99
|
+
horizontal row, switch to a single-column stack. Threshold scales
|
|
100
|
+
with the actual slotted-element count (see :host calc above). */
|
|
101
|
+
@container field-group (max-inline-size: var(--fieldGroup_collapse-threshold)) {
|
|
102
|
+
:host([variant='horizontal']) .fields {
|
|
103
|
+
flex-direction: column;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
:host([variant='horizontal']) .fields ::slotted(*) {
|
|
107
|
+
flex: 1 1 auto;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
|
|
112
|
+
static properties = {
|
|
113
|
+
variant: { type: String, reflect: true },
|
|
114
|
+
legend: { type: String },
|
|
115
|
+
disabled: { type: Boolean, reflect: true },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare variant: FieldGroupVariant;
|
|
119
|
+
declare legend: string;
|
|
120
|
+
declare disabled: boolean;
|
|
121
|
+
|
|
122
|
+
constructor() {
|
|
123
|
+
super();
|
|
124
|
+
this.variant = 'horizontal';
|
|
125
|
+
this.legend = '';
|
|
126
|
+
this.disabled = false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Arrow-bound for stable identity (unused here but matches the
|
|
130
|
+
// bds-popover / bds-button conventions for handlers attached in render).
|
|
131
|
+
private _onSlotChange = (e: Event) => {
|
|
132
|
+
const slot = e.target as HTMLSlotElement;
|
|
133
|
+
const count = slot.assignedElements().length;
|
|
134
|
+
this.style.setProperty('--fieldGroup_field-count', String(count));
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
render() {
|
|
138
|
+
return html`
|
|
139
|
+
<fieldset ?disabled=${this.disabled}>
|
|
140
|
+
${this.legend
|
|
141
|
+
? html`<legend class="legend">${this.legend}</legend>`
|
|
142
|
+
: nothing}
|
|
143
|
+
<div class="fields">
|
|
144
|
+
<slot @slotchange=${this._onSlotChange}></slot>
|
|
145
|
+
</div>
|
|
146
|
+
</fieldset>
|
|
147
|
+
`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
customElements.define('bds-field-group', BdsFieldGroup);
|
|
152
|
+
|
|
153
|
+
declare global {
|
|
154
|
+
interface HTMLElementTagNameMap {
|
|
155
|
+
'bds-field-group': BdsFieldGroup;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -41,36 +41,40 @@ export class BdsAlert extends LitElement {
|
|
|
41
41
|
gap: var(--bds-space_s);
|
|
42
42
|
padding: var(--bds-space_m);
|
|
43
43
|
border-radius: var(--bds-border_radius--s);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/* Layered cascade: public overrides (--alert_bg, --alert_text, --alert_border)
|
|
45
|
+
are read OUTERMOST so an ancestor-set value always wins over variant
|
|
46
|
+
defaults. Variants write to the inner --alert_*--variant slot. */
|
|
47
|
+
background-color: var(--alert_bg, var(--alert_bg--variant, var(--bds-color_blue--subtle)));
|
|
48
|
+
color: var(--alert_text, var(--alert_text--variant, var(--bds-color_on-blue--subtle)));
|
|
49
|
+
border-inline-start: var(--bds-space_s) solid var(--alert_border, var(--alert_border--variant, var(--bds-color_blue)));
|
|
47
50
|
font-size: var(--bds-font_size--body);
|
|
48
51
|
line-height: var(--bds-font_line-height--body);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
/*
|
|
54
|
+
/* Per-variant resting overrides — consumers can theme per-variant via
|
|
55
|
+
--alert_bg--info / --alert_bg--success / ... */
|
|
52
56
|
: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);
|
|
57
|
+
--alert_bg--variant: var(--alert_bg--info, var(--bds-color_blue--subtle));
|
|
58
|
+
--alert_text--variant: var(--alert_text--info, var(--bds-color_on-blue--subtle));
|
|
59
|
+
--alert_border--variant: var(--alert_border--info, var(--bds-color_blue));
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
: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);
|
|
63
|
+
--alert_bg--variant: var(--alert_bg--success, var(--bds-color_success--subtle));
|
|
64
|
+
--alert_text--variant: var(--alert_text--success, var(--bds-color_on-success--subtle));
|
|
65
|
+
--alert_border--variant: var(--alert_border--success, var(--bds-color_success));
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
: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);
|
|
69
|
+
--alert_bg--variant: var(--alert_bg--warning, var(--bds-color_orange--subtle));
|
|
70
|
+
--alert_text--variant: var(--alert_text--warning, var(--bds-color_on-orange--subtle));
|
|
71
|
+
--alert_border--variant: var(--alert_border--warning, var(--bds-color_warning));
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
: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);
|
|
75
|
+
--alert_bg--variant: var(--alert_bg--error, rgb(from var(--bds-color_error) r g b / 12%));
|
|
76
|
+
--alert_text--variant: var(--alert_text--error, var(--bds-color_on-bg));
|
|
77
|
+
--alert_border--variant: var(--alert_border--error, var(--bds-color_error));
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
/* Icon slot wrapper — hidden unless slot has content */
|