@boostdev/design-system-components 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs +50 -50
- package/dist/client.css +456 -456
- package/dist/client.js +50 -50
- package/dist/index.cjs +50 -50
- package/dist/index.css +456 -456
- package/dist/index.js +50 -50
- package/dist/web-components/chunk-2QA62WCQ.js +48 -0
- package/dist/web-components/chunk-4BX6AWXX.js +146 -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-6T3RKUKG.js +65 -0
- package/dist/web-components/chunk-7FMR53BW.js +127 -0
- package/dist/web-components/chunk-A67LCT7C.js +134 -0
- package/dist/web-components/chunk-AGKJTMJI.js +56 -0
- package/dist/web-components/chunk-BQLZ7I4G.js +56 -0
- package/dist/web-components/chunk-CAPI25CU.js +53 -0
- package/dist/web-components/chunk-CJ5ZOO42.js +229 -0
- package/dist/web-components/chunk-CR5PGUHV.js +109 -0
- package/dist/web-components/chunk-ECW3HHWA.js +185 -0
- package/dist/web-components/chunk-HGBNDR22.js +98 -0
- package/dist/web-components/chunk-IK3PTFZ4.js +133 -0
- package/dist/web-components/chunk-IQGLIQSO.js +188 -0
- package/dist/web-components/chunk-ITHLKR7Q.js +105 -0
- package/dist/web-components/chunk-K5CE6HSB.js +169 -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-LSC4N56Q.js +168 -0
- package/dist/web-components/chunk-LY62SAVN.js +64 -0
- package/dist/web-components/chunk-O4UFI2RX.js +244 -0
- package/dist/web-components/chunk-O7I63SQX.js +124 -0
- package/dist/web-components/chunk-OHUTLSIQ.js +69 -0
- package/dist/web-components/chunk-OQTRTMAB.js +27 -0
- package/dist/web-components/chunk-OTX4COSV.js +187 -0
- package/dist/web-components/chunk-PY62FTRW.js +179 -0
- package/dist/web-components/chunk-Q4T5BJT6.js +94 -0
- package/dist/web-components/chunk-QDRH46TF.js +281 -0
- package/dist/web-components/chunk-QDST57JC.js +119 -0
- package/dist/web-components/chunk-QPOKHLMQ.js +45 -0
- package/dist/web-components/chunk-SOQQ7RVJ.js +88 -0
- package/dist/web-components/chunk-UFFCKVZE.js +149 -0
- package/dist/web-components/chunk-VM3YHGQ2.js +152 -0
- package/dist/web-components/chunk-VMMVWLXL.js +53 -0
- package/dist/web-components/chunk-VSS5ITNE.js +109 -0
- package/dist/web-components/chunk-XIENXR7H.js +118 -0
- package/dist/web-components/chunk-Y4MAXTMA.js +80 -0
- package/dist/web-components/chunk-YLVTEY23.js +165 -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 +71 -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 +169 -4
- package/src/web-components/index.ts +47 -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 +99 -0
- 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 +224 -0
- package/src/web-components/interaction/bds-drawer.spec.ts +113 -0
- package/src/web-components/interaction/bds-drawer.ts +266 -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/bds-checkbox.spec.ts +63 -0
- package/src/web-components/interaction/form/bds-checkbox.ts +168 -0
- package/src/web-components/interaction/form/bds-combobox.spec.ts +117 -0
- package/src/web-components/interaction/form/bds-combobox.ts +336 -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 +221 -0
- package/src/web-components/interaction/form/bds-radio.spec.ts +70 -0
- package/src/web-components/interaction/form/bds-radio.ts +157 -0
- package/src/web-components/interaction/form/bds-segmented-control.spec.ts +74 -0
- package/src/web-components/interaction/form/bds-segmented-control.ts +211 -0
- package/src/web-components/interaction/form/bds-select.spec.ts +74 -0
- package/src/web-components/interaction/form/bds-select.ts +190 -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 +166 -0
- package/src/web-components/interaction/form/bds-textarea.spec.ts +55 -0
- package/src/web-components/interaction/form/bds-textarea.ts +143 -0
- 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 +156 -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 +185 -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,211 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit';
|
|
2
|
+
|
|
3
|
+
export interface SegmentedOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `<bds-segmented-control>` — form-associated Segmented Control custom element.
|
|
11
|
+
*
|
|
12
|
+
* Renders a group of radio buttons styled as a unified segmented control.
|
|
13
|
+
* Passes a JSON `options` attribute because reactive slot content can't be
|
|
14
|
+
* easily converted to radio groups.
|
|
15
|
+
*
|
|
16
|
+
* Attributes:
|
|
17
|
+
* name — form field name (also used for the internal radio group)
|
|
18
|
+
* value — currently selected value
|
|
19
|
+
* options — JSON array of `{ value, label, disabled? }` option objects
|
|
20
|
+
* disabled — boolean; disables all options
|
|
21
|
+
*
|
|
22
|
+
* Events:
|
|
23
|
+
* change — fired when a new segment is selected
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* <bds-segmented-control
|
|
27
|
+
* name="view"
|
|
28
|
+
* value="list"
|
|
29
|
+
* options='[{"value":"list","label":"List"},{"value":"grid","label":"Grid"}]'
|
|
30
|
+
* ></bds-segmented-control>
|
|
31
|
+
*/
|
|
32
|
+
export class BdsSegmentedControl extends LitElement {
|
|
33
|
+
static formAssociated = true;
|
|
34
|
+
|
|
35
|
+
static styles = css`
|
|
36
|
+
:host {
|
|
37
|
+
display: inline-flex;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:host([disabled]) {
|
|
41
|
+
opacity: 0.5;
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.control {
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
position: relative;
|
|
48
|
+
border-radius: var(--bds-border_radius--s);
|
|
49
|
+
background-color: var(--segmented_color_bg, var(--bds-color_bg--subtle));
|
|
50
|
+
padding: 0.25rem;
|
|
51
|
+
gap: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Sliding thumb */
|
|
55
|
+
.thumb {
|
|
56
|
+
position: absolute;
|
|
57
|
+
inset-block: 0.25rem;
|
|
58
|
+
border-radius: calc(var(--bds-border_radius--s) - 2px);
|
|
59
|
+
background-color: var(--segmented_thumb-color, var(--bds-color_bg));
|
|
60
|
+
box-shadow: var(--bds-shadow_m);
|
|
61
|
+
transition: inset-inline-start var(--bds-animation_transition-duration) var(--bds-animation_easing),
|
|
62
|
+
inline-size var(--bds-animation_transition-duration) var(--bds-animation_easing);
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
/* Position set via JS in updated() */
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.radio {
|
|
68
|
+
position: absolute;
|
|
69
|
+
opacity: 0;
|
|
70
|
+
inline-size: 0;
|
|
71
|
+
block-size: 0;
|
|
72
|
+
margin: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.item {
|
|
76
|
+
position: relative;
|
|
77
|
+
display: inline-flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
padding: var(--bds-space_xs) var(--bds-space_m);
|
|
81
|
+
font-size: var(--bds-font_size--body--s);
|
|
82
|
+
font-family: var(--bds-font_family--body);
|
|
83
|
+
font-weight: var(--bds-font_weight--semibold);
|
|
84
|
+
color: var(--segmented_color, var(--bds-color_on-bg));
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
border-radius: calc(var(--bds-border_radius--s) - 2px);
|
|
87
|
+
transition: color var(--bds-animation_transition-duration) var(--bds-animation_easing);
|
|
88
|
+
user-select: none;
|
|
89
|
+
white-space: nowrap;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.item.--active {
|
|
93
|
+
color: var(--segmented_color--active, var(--bds-color_interactive_on-bg));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.item.--disabled {
|
|
97
|
+
opacity: 0.4;
|
|
98
|
+
cursor: not-allowed;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.radio:focus-visible + .item-label {
|
|
102
|
+
outline: var(--bds-outline_default);
|
|
103
|
+
outline-offset: var(--bds-outline_offset);
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
static properties = {
|
|
108
|
+
name: { type: String, reflect: true },
|
|
109
|
+
value: { type: String },
|
|
110
|
+
options: { type: String },
|
|
111
|
+
disabled: { type: Boolean, reflect: true },
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
declare name: string;
|
|
115
|
+
declare value: string;
|
|
116
|
+
declare options: string;
|
|
117
|
+
declare disabled: boolean;
|
|
118
|
+
|
|
119
|
+
private _internals!: ElementInternals;
|
|
120
|
+
private readonly _uid = Math.random().toString(36).slice(2, 8);
|
|
121
|
+
|
|
122
|
+
constructor() {
|
|
123
|
+
super();
|
|
124
|
+
this._internals = this.attachInternals();
|
|
125
|
+
this.name = '';
|
|
126
|
+
this.value = '';
|
|
127
|
+
this.options = '[]';
|
|
128
|
+
this.disabled = false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private get _options(): SegmentedOption[] {
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(this.options) as SegmentedOption[];
|
|
134
|
+
} catch {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
updated(changed: Map<string, unknown>) {
|
|
140
|
+
super.updated(changed);
|
|
141
|
+
if (changed.has('value') || changed.has('options')) {
|
|
142
|
+
this._internals.setFormValue?.(this.value || null);
|
|
143
|
+
this._updateThumb();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private _updateThumb() {
|
|
148
|
+
const opts = this._options;
|
|
149
|
+
const selectedIndex = Math.max(0, opts.findIndex(o => o.value === this.value));
|
|
150
|
+
const items = this.shadowRoot?.querySelectorAll<HTMLElement>('.item');
|
|
151
|
+
const thumb = this.shadowRoot?.querySelector<HTMLElement>('.thumb');
|
|
152
|
+
if (!items || !thumb || items.length === 0) return;
|
|
153
|
+
const item = items[selectedIndex];
|
|
154
|
+
if (!item) return;
|
|
155
|
+
const controlRect = (item.parentElement as HTMLElement).getBoundingClientRect();
|
|
156
|
+
const itemRect = item.getBoundingClientRect();
|
|
157
|
+
thumb.style.insetInlineStart = `${itemRect.left - controlRect.left}px`;
|
|
158
|
+
thumb.style.inlineSize = `${itemRect.width}px`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
formResetCallback() {
|
|
162
|
+
const firstOption = this._options[0];
|
|
163
|
+
this.value = firstOption?.value ?? '';
|
|
164
|
+
this._internals.setFormValue?.(this.value || null);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private _handleChange(optionValue: string) {
|
|
168
|
+
this.value = optionValue;
|
|
169
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
render() {
|
|
173
|
+
const opts = this._options;
|
|
174
|
+
return html`
|
|
175
|
+
<div class="control" role="group">
|
|
176
|
+
<span class="thumb" aria-hidden="true"></span>
|
|
177
|
+
${opts.map((opt, i) => {
|
|
178
|
+
const id = `bds-seg-${this._uid}-${i}`;
|
|
179
|
+
const isActive = opt.value === this.value;
|
|
180
|
+
const isDisabled = this.disabled || opt.disabled;
|
|
181
|
+
return html`
|
|
182
|
+
<label
|
|
183
|
+
class="item ${isActive ? '--active' : ''} ${isDisabled ? '--disabled' : ''}"
|
|
184
|
+
for=${id}
|
|
185
|
+
>
|
|
186
|
+
<input
|
|
187
|
+
id=${id}
|
|
188
|
+
type="radio"
|
|
189
|
+
class="radio"
|
|
190
|
+
name=${this.name || this._uid}
|
|
191
|
+
value=${opt.value}
|
|
192
|
+
.checked=${isActive}
|
|
193
|
+
?disabled=${isDisabled}
|
|
194
|
+
@change=${() => this._handleChange(opt.value)}
|
|
195
|
+
/>
|
|
196
|
+
${opt.label}
|
|
197
|
+
</label>
|
|
198
|
+
`;
|
|
199
|
+
})}
|
|
200
|
+
</div>
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
customElements.define('bds-segmented-control', BdsSegmentedControl);
|
|
206
|
+
|
|
207
|
+
declare global {
|
|
208
|
+
interface HTMLElementTagNameMap {
|
|
209
|
+
'bds-segmented-control': BdsSegmentedControl;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { fixture, cleanup } from '../../test/helpers';
|
|
2
|
+
import { BdsSelect } from './bds-select';
|
|
3
|
+
|
|
4
|
+
const OPTIONS = JSON.stringify([
|
|
5
|
+
{ value: 'nl', label: 'Netherlands' },
|
|
6
|
+
{ value: 'be', label: 'Belgium' },
|
|
7
|
+
{ value: 'de', label: 'Germany', disabled: true },
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
describe('bds-select', () => {
|
|
11
|
+
it('is registered as a custom element', () => {
|
|
12
|
+
expect(customElements.get('bds-select')).toBe(BdsSelect);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders a <select> element in shadow DOM', async () => {
|
|
16
|
+
const el = await fixture(`<bds-select name="country" options='${OPTIONS}'></bds-select>`);
|
|
17
|
+
expect(el.shadowRoot!.querySelector('select')).not.toBeNull();
|
|
18
|
+
cleanup(el);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('renders options from the options attribute', async () => {
|
|
22
|
+
const el = await fixture(`<bds-select name="country" options='${OPTIONS}'></bds-select>`);
|
|
23
|
+
const select = el.shadowRoot!.querySelector('select')!;
|
|
24
|
+
const options = [...select.querySelectorAll('option')];
|
|
25
|
+
expect(options.length).toBe(3);
|
|
26
|
+
expect(options[0].value).toBe('nl');
|
|
27
|
+
expect(options[1].value).toBe('be');
|
|
28
|
+
cleanup(el);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renders a placeholder option when placeholder is set', async () => {
|
|
32
|
+
const el = await fixture(`<bds-select name="country" placeholder="Choose..." options='${OPTIONS}'></bds-select>`);
|
|
33
|
+
const select = el.shadowRoot!.querySelector('select')!;
|
|
34
|
+
const placeholder = select.querySelector<HTMLOptionElement>('option[value=""]');
|
|
35
|
+
expect(placeholder).not.toBeNull();
|
|
36
|
+
expect(placeholder!.textContent?.trim()).toBe('Choose...');
|
|
37
|
+
cleanup(el);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('marks a disabled option as disabled', async () => {
|
|
41
|
+
const el = await fixture(`<bds-select name="country" options='${OPTIONS}'></bds-select>`);
|
|
42
|
+
const select = el.shadowRoot!.querySelector('select')!;
|
|
43
|
+
const deOption = select.querySelector<HTMLOptionElement>('option[value="de"]');
|
|
44
|
+
expect(deOption!.disabled).toBe(true);
|
|
45
|
+
cleanup(el);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('select is disabled when disabled attribute is set', async () => {
|
|
49
|
+
const el = await fixture(`<bds-select name="country" disabled options='${OPTIONS}'></bds-select>`);
|
|
50
|
+
const select = el.shadowRoot!.querySelector<HTMLSelectElement>('select')!;
|
|
51
|
+
expect(select.disabled).toBe(true);
|
|
52
|
+
cleanup(el);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('updates value property on change', async () => {
|
|
56
|
+
const el = await fixture(`<bds-select name="country" options='${OPTIONS}'></bds-select>`) as BdsSelect;
|
|
57
|
+
const select = el.shadowRoot!.querySelector<HTMLSelectElement>('select')!;
|
|
58
|
+
select.value = 'nl';
|
|
59
|
+
select.dispatchEvent(new Event('change', { bubbles: true }));
|
|
60
|
+
expect(el.value).toBe('nl');
|
|
61
|
+
cleanup(el);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('handles invalid JSON options gracefully', async () => {
|
|
65
|
+
const el = await fixture(`<bds-select name="country" options='not-json'></bds-select>`);
|
|
66
|
+
const select = el.shadowRoot!.querySelector('select')!;
|
|
67
|
+
expect([...select.querySelectorAll('option')].length).toBe(0);
|
|
68
|
+
cleanup(el);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('is form-associated', () => {
|
|
72
|
+
expect(BdsSelect.formAssociated).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
outline: var(--bdc-outline_width) solid var(--bdc_color);
|
|
62
|
+
outline-offset: var(--bdc-outline_offset);
|
|
63
|
+
border-radius: var(--select_radius, var(--bdc-outline_radius));
|
|
64
|
+
box-shadow: var(--select_shadow, var(--bdc-outline_shadow));
|
|
65
|
+
background-color: var(--select_color_bg, var(--bds-color_bg));
|
|
66
|
+
color: var(--select_color, var(--bds-color_on-bg));
|
|
67
|
+
appearance: none;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
transition: --bdc_color var(--bds-animation_transition-duration) var(--bds-animation_easing);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.select:focus {
|
|
73
|
+
--bdc_color: var(--bdc_color--focus);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.select:focus-visible {
|
|
77
|
+
outline: var(--bds-outline_default);
|
|
78
|
+
outline-offset: var(--bds-outline_offset);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.chevron {
|
|
82
|
+
position: absolute;
|
|
83
|
+
inset-inline-end: var(--bds-space_s);
|
|
84
|
+
inset-block-start: 50%;
|
|
85
|
+
transform: translateY(-50%);
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
inline-size: 1rem;
|
|
88
|
+
block-size: 1rem;
|
|
89
|
+
color: currentcolor;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.chevron svg {
|
|
93
|
+
inline-size: 100%;
|
|
94
|
+
block-size: 100%;
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
static properties = {
|
|
99
|
+
name: { type: String, reflect: true },
|
|
100
|
+
value: { type: String },
|
|
101
|
+
options: { type: String },
|
|
102
|
+
placeholder: { type: String },
|
|
103
|
+
required: { type: Boolean, reflect: true },
|
|
104
|
+
disabled: { type: Boolean, reflect: true },
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
declare name: string;
|
|
108
|
+
declare value: string;
|
|
109
|
+
declare options: string;
|
|
110
|
+
declare placeholder: string;
|
|
111
|
+
declare required: boolean;
|
|
112
|
+
declare disabled: boolean;
|
|
113
|
+
|
|
114
|
+
private _internals!: ElementInternals;
|
|
115
|
+
|
|
116
|
+
constructor() {
|
|
117
|
+
super();
|
|
118
|
+
this._internals = this.attachInternals();
|
|
119
|
+
this.name = '';
|
|
120
|
+
this.value = '';
|
|
121
|
+
this.options = '[]';
|
|
122
|
+
this.placeholder = '';
|
|
123
|
+
this.required = false;
|
|
124
|
+
this.disabled = false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private get _options(): SelectOption[] {
|
|
128
|
+
try {
|
|
129
|
+
return JSON.parse(this.options) as SelectOption[];
|
|
130
|
+
} catch {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
updated(changed: Map<string, unknown>) {
|
|
136
|
+
super.updated(changed);
|
|
137
|
+
if (changed.has('value') || changed.has('name')) {
|
|
138
|
+
this._internals.setFormValue?.(this.value || null);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
formResetCallback() {
|
|
143
|
+
this.value = '';
|
|
144
|
+
this._internals.setFormValue?.(null);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private _handleChange(e: Event) {
|
|
148
|
+
this.value = (e.target as HTMLSelectElement).value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
render() {
|
|
152
|
+
const opts = this._options;
|
|
153
|
+
return html`
|
|
154
|
+
<div class="wrapper">
|
|
155
|
+
<select
|
|
156
|
+
class="select"
|
|
157
|
+
name=${this.name}
|
|
158
|
+
.value=${this.value}
|
|
159
|
+
?required=${this.required}
|
|
160
|
+
?disabled=${this.disabled}
|
|
161
|
+
@change=${this._handleChange}
|
|
162
|
+
>
|
|
163
|
+
${this.placeholder ? html`
|
|
164
|
+
<option value="" disabled ?selected=${!this.value}>${this.placeholder}</option>
|
|
165
|
+
` : ''}
|
|
166
|
+
${opts.map(opt => html`
|
|
167
|
+
<option
|
|
168
|
+
value=${opt.value}
|
|
169
|
+
?disabled=${opt.disabled}
|
|
170
|
+
?selected=${opt.value === this.value}
|
|
171
|
+
>${opt.label}</option>
|
|
172
|
+
`)}
|
|
173
|
+
</select>
|
|
174
|
+
<span class="chevron" aria-hidden="true">
|
|
175
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
176
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 9l6 6 6-6" />
|
|
177
|
+
</svg>
|
|
178
|
+
</span>
|
|
179
|
+
</div>
|
|
180
|
+
`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
customElements.define('bds-select', BdsSelect);
|
|
185
|
+
|
|
186
|
+
declare global {
|
|
187
|
+
interface HTMLElementTagNameMap {
|
|
188
|
+
'bds-select': BdsSelect;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -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
|
+
}
|