@repobit/dex-system-design 2.5.1 → 2.6.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/CHANGELOG.md +84 -0
- package/README.md +2 -1
- package/package.json +14 -27
- package/schemas/component-manifest.json +226 -33
- package/schemas/manifest-omissions.json +23 -0
- package/src/components/accordion/accordion-bg.css.js +39 -30
- package/src/components/accordion/accordion-bg.js +17 -28
- package/src/components/accordion/accordion-bg.stories.js +5 -0
- package/src/components/accordion/accordion-panel.js +24 -0
- package/src/components/accordion/accordion.css.js +105 -111
- package/src/components/accordion/accordion.js +23 -37
- package/src/components/accordion/accordion.stories.js +5 -1
- package/src/components/anchor/anchor-nav.css.js +131 -53
- package/src/components/anchor/anchor-nav.js +276 -201
- package/src/components/annotation/annotation.css.js +7 -4
- package/src/components/architecture.stories.js +8 -7
- package/src/components/audience-card/audience-card.css.js +30 -4
- package/src/components/audience-card/audience-card.js +8 -13
- package/src/components/awards/awards-flex.css.js +23 -6
- package/src/components/awards/awards-flex.js +21 -6
- package/src/components/awards/awards-spotlight.css.js +25 -5
- package/src/components/awards/awards-spotlight.js +19 -7
- package/src/components/awards/awards.css.js +20 -8
- package/src/components/awards/awards.js +30 -91
- package/src/components/awards/awards.stories.js +5 -5
- package/src/components/awards/scroll-slides.js +128 -0
- package/src/components/back/back.css.js +2 -0
- package/src/components/badge/badge.css.js +15 -0
- package/src/components/bento-grid/bento-grid.css.js +105 -11
- package/src/components/bento-grid/bento-grid.js +37 -124
- package/src/components/bento-grid/bento-grid.stories.js +3 -2
- package/src/components/bento-grid/bento-item.css.js +71 -32
- package/src/components/bento-grid/bento-item.js +1 -30
- package/src/components/blockquote/blockquote.css.js +2 -2
- package/src/components/breadcrumb/breadcrumb.css.js +10 -9
- package/src/components/breadcrumb/breadcrumb.js +35 -34
- package/src/components/button/button.css.js +42 -17
- package/src/components/button/button.js +84 -3
- package/src/components/button/button.stories.js +17 -0
- package/src/components/card-features/card-features.css.js +23 -2
- package/src/components/card-features/card-features.js +6 -48
- package/src/components/cards/card.css.js +43 -14
- package/src/components/cards/card.js +43 -177
- package/src/components/cards/card.stories.js +8 -10
- package/src/components/carousel/carousel.css.js +101 -70
- package/src/components/carousel/carousel.js +107 -71
- package/src/components/carousel/carousel.stories.js +18 -16
- package/src/components/checkbox/checkbox.css.js +26 -9
- package/src/components/checkbox/checkbox.js +73 -39
- package/src/components/checkbox/checkbox.stories.js +35 -18
- package/src/components/compare/compare.css.js +68 -10
- package/src/components/compare/compare.js +40 -103
- package/src/components/compare/compare.stories.js +1 -1
- package/src/components/compatibility-table/compatibility-table.css.js +70 -37
- package/src/components/compatibility-table/compatibility-table.js +47 -40
- package/src/components/compatibility-table/compatibility-table.stories.js +78 -1
- package/src/components/display/display.css.js +7 -0
- package/src/components/dropdown/dropdown.css.js +20 -3
- package/src/components/dropdown/dropdown.js +57 -21
- package/src/components/dropdown/dropdown.stories.js +31 -9
- package/src/components/features/features.css.js +56 -21
- package/src/components/features/features.js +7 -117
- package/src/components/fieldset/fieldset.stories.js +68 -0
- package/src/components/footer/footer-images.js +34 -0
- package/src/components/footer/footer-links-group.css.js +10 -10
- package/src/components/footer/footer-locale.js +47 -0
- package/src/components/footer/footer-lp.js +27 -114
- package/src/components/footer/footer-lp.stories.js +2 -2
- package/src/components/footer/footer-nav-menu.css.js +2 -2
- package/src/components/footer/footer-nav-menu.js +8 -3
- package/src/components/footer/footer.css.js +238 -197
- package/src/components/footer/footer.js +109 -187
- package/src/components/footer/footer.stories.js +14 -4
- package/src/components/grid/grid.css.js +64 -5
- package/src/components/header/header-code.css.js +20 -11
- package/src/components/header/header-code.js +1 -1
- package/src/components/header/header.css.js +20 -14
- package/src/components/header/header.js +6 -7
- package/src/components/header/header.stories.js +29 -24
- package/src/components/heading/heading.css.js +11 -0
- package/src/components/hero/hero.js +10 -2
- package/src/components/highlight/highlight.css.js +30 -6
- package/src/components/icons/arrow-icon.js +4 -1
- package/src/components/icons/arrow-right-icon.js +5 -1
- package/src/components/icons/icon-element.js +18 -0
- package/src/components/image/image.js +29 -9
- package/src/components/image/image.stories.js +38 -2
- package/src/components/input/custom-form.stories.js +38 -7
- package/src/components/input/input-clipboard.css.js +15 -1
- package/src/components/input/input-clipboard.js +84 -21
- package/src/components/input/input.js +27 -7
- package/src/components/install-options/install-options.css.js +26 -6
- package/src/components/install-options/install-options.js +32 -8
- package/src/components/label/label.css.js +1 -1
- package/src/components/light-carousel/light-carousel.css.js +100 -48
- package/src/components/light-carousel/light-carousel.js +43 -5
- package/src/components/link/link.css.js +15 -15
- package/src/components/link/link.js +17 -1
- package/src/components/link/link.stories.js +20 -7
- package/src/components/list/list.css.js +3 -3
- package/src/components/logo-marquee/logo-marquee.css.js +12 -1
- package/src/components/logo-marquee/logo-marquee.js +33 -8
- package/src/components/logo-marquee/logo-marquee.stories.js +10 -4
- package/src/components/modal/modal.css.js +74 -40
- package/src/components/modal/modal.js +85 -74
- package/src/components/modal/modal.stories.js +27 -14
- package/src/components/motion-art/motion-art.js +67 -1
- package/src/components/page-switcher/page-switcher.css.js +27 -9
- package/src/components/page-switcher/page-switcher.js +11 -8
- package/src/components/partner-banner/partner-banner.css.js +2 -0
- package/src/components/picture/picture.css.js +4 -4
- package/src/components/picture/picture.js +13 -3
- package/src/components/picture/picture.stories.js +28 -2
- package/src/components/post-card/post-card.css.js +18 -3
- package/src/components/pricing-cards/adopt-styles.js +16 -0
- package/src/components/pricing-cards/new-pricing-card.js +2 -4
- package/src/components/pricing-cards/new-pricing-card.stories.js +20 -22
- package/src/components/pricing-cards/pricing-card-actions.css.js +8 -12
- package/src/components/pricing-cards/pricing-card-actions.js +26 -13
- package/src/components/pricing-cards/pricing-card-container.css.js +4 -3
- package/src/components/pricing-cards/pricing-card-container.js +10 -4
- package/src/components/pricing-cards/pricing-card-header.css.js +5 -4
- package/src/components/pricing-cards/pricing-card-header.js +18 -31
- package/src/components/pricing-cards/pricing-card-pricing.css.js +84 -61
- package/src/components/pricing-cards/pricing-card-pricing.js +38 -24
- package/src/components/pricing-cards/pricing-card-show-more.js +8 -3
- package/src/components/pricing-cards/pricing-card.css.js +75 -41
- package/src/components/pricing-cards/pricing-card.js +356 -308
- package/src/components/progress/progress.css.js +58 -13
- package/src/components/progress/progress.js +13 -10
- package/src/components/progress/progress.stories.js +9 -7
- package/src/components/radio/radio-group.css.js +42 -0
- package/src/components/radio/radio-group.js +89 -0
- package/src/components/radio/radio.css.js +63 -6
- package/src/components/radio/radio.js +173 -140
- package/src/components/radio/radio.stories.js +99 -44
- package/src/components/radio/toggle-radio.js +44 -0
- package/src/components/review/review-grid.css.js +5 -1
- package/src/components/review/review-grid.js +2 -0
- package/src/components/review/review.js +13 -0
- package/src/components/shared/announcer.js +37 -0
- package/src/components/shared/fill-width.css.js +33 -0
- package/src/components/shared/form-control.js +194 -0
- package/src/components/shared/form-field.css.js +31 -3
- package/src/components/shared/token-scales.js +75 -26
- package/src/components/spotlight-section/spotlight-section.js +2 -2
- package/src/components/stat/stat-highlight.js +1 -1
- package/src/components/stat/stat.css.js +18 -3
- package/src/components/switch/switch.css.js +58 -5
- package/src/components/switch/switch.js +53 -5
- package/src/components/switch/switch.stories.js +30 -8
- package/src/components/tab-list/tab-list.css.js +51 -13
- package/src/components/tab-list/tab-list.js +7 -2
- package/src/components/tab-list/tab-list.stories.js +2 -2
- package/src/components/tabs/tabs.css.js +18 -1
- package/src/components/tabs/tabs.js +119 -41
- package/src/components/terminal/terminal-message.css.js +6 -1
- package/src/components/termsOfUse/terms.css.js +4 -2
- package/src/components/textarea/textarea.js +22 -7
- package/src/components/textarea/textarea.stories.js +12 -9
- package/src/components/trust-panel/trust-panel.css.js +13 -3
- package/src/components/ultimate-security-demo.stories.js +5 -5
- package/src/components/video/video.css.js +5 -0
- package/src/components/video/video.js +5 -0
- package/src/components/video/video.stories.js +12 -0
- package/src/components/video-player/video-player.css.js +20 -8
- package/src/components/video-player/video-player.js +74 -20
- package/src/components/video-player/video-player.stories.js +17 -3
- package/src/tokens/brands.stories.js +1 -1
- package/src/tokens/themes/index.js +2 -2
- package/src/tokens/typography.stories.js +4 -3
- package/src/vendor/motion-art/README.md +4 -1
- package/src/components/footer/footer-lp.css.js +0 -159
|
@@ -1,33 +1,57 @@
|
|
|
1
|
-
import { LitElement, html } from "lit";
|
|
1
|
+
import { LitElement, html, nothing } from "lit";
|
|
2
2
|
// Installs the design tokens into document scope; see src/tokens/tokens.js
|
|
3
3
|
import "../../tokens/tokens.js";
|
|
4
4
|
import radioCSS from "./radio.css.js";
|
|
5
|
+
import { FormControl, omitEmpty } from "../shared/form-control.js";
|
|
6
|
+
// bd-toggle-radio has its own module, and this one still registers it, as it
|
|
7
|
+
// always has
|
|
8
|
+
import "./toggle-radio.js";
|
|
5
9
|
|
|
6
10
|
const NEXT_KEYS = ["ArrowDown", "ArrowRight"];
|
|
7
11
|
const PREV_KEYS = ["ArrowUp", "ArrowLeft"];
|
|
8
12
|
|
|
13
|
+
/* A group's radios, in document order; a group nested inside keeps its own.
|
|
14
|
+
Read off the DOM rather than asked of the group, because radios upgrade
|
|
15
|
+
first -- radio-group.js imports this module -- and a group that is not
|
|
16
|
+
upgraded yet has no methods to ask. */
|
|
17
|
+
export const radiosOf = group => [...group.querySelectorAll("bd-radio")]
|
|
18
|
+
.filter(radio => radio.closest("bd-radio-group") === group);
|
|
19
|
+
|
|
20
|
+
/* Same-name radios in `scope` that no bd-radio-group has claimed and that
|
|
21
|
+
belong to `form` -- a native group is the radios with one name AND one form
|
|
22
|
+
owner, so two forms that each ask for a "plan" hold two groups: a choice in
|
|
23
|
+
one neither clears the other nor answers its `required`. A radio not yet
|
|
24
|
+
upgraded has no form to compare; it joins when it upgrades. */
|
|
25
|
+
const byName = (scope, name, form) => [...scope.querySelectorAll(`bd-radio[name="${CSS.escape(name)}"]`)]
|
|
26
|
+
.filter(radio => !radio._owner && (radio.form ?? null) === form);
|
|
27
|
+
|
|
9
28
|
/**
|
|
10
|
-
* A single radio. Selecting one clears the others
|
|
11
|
-
*
|
|
29
|
+
* A single radio. Selecting one clears the others in its group, and the arrow
|
|
30
|
+
* keys move between them.
|
|
12
31
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
32
|
+
* Each radio is a native <input type="radio"> in its own shadow root, and that
|
|
33
|
+
* is exactly what the browser cannot group: a native group is the radios
|
|
34
|
+
* sharing a name in one tree, and every shadow root is a tree of its own. So
|
|
35
|
+
* the group is still worked out here -- exclusivity, the arrow keys, the one
|
|
36
|
+
* tab stop, the position in the set -- over a bd-radio-group's radios, or,
|
|
37
|
+
* without one, the same-name radios in this root, as it always was. The
|
|
38
|
+
* group element is what adds role="radiogroup" and its label; see
|
|
39
|
+
* radio-group.js.
|
|
18
40
|
*/
|
|
19
|
-
class BdRadio extends LitElement {
|
|
41
|
+
class BdRadio extends FormControl(LitElement) {
|
|
20
42
|
static styles = [radioCSS];
|
|
21
43
|
|
|
22
44
|
static properties = {
|
|
23
45
|
/* Reflected because the group is found by it: _group selects same-name
|
|
24
46
|
radios by attribute, so a name set as a property -- radio.name = "plan",
|
|
25
47
|
which is what a framework binding does -- left the radio in no group at
|
|
26
|
-
all, with no exclusivity, no arrow keys and its own tab stop.
|
|
27
|
-
|
|
48
|
+
all, with no exclusivity, no arrow keys and its own tab stop. A form
|
|
49
|
+
reads it off the attribute too. */
|
|
50
|
+
name : { type: String, reflect: true, converter: omitEmpty },
|
|
28
51
|
value : { type: String },
|
|
29
52
|
checked : { type: Boolean, reflect: true },
|
|
30
53
|
disabled: { type: Boolean, reflect: true },
|
|
54
|
+
required: { type: Boolean },
|
|
31
55
|
label : { type: String }
|
|
32
56
|
};
|
|
33
57
|
|
|
@@ -39,75 +63,135 @@ class BdRadio extends LitElement {
|
|
|
39
63
|
// value, so an unselected radio announced no state at all
|
|
40
64
|
this.checked = false;
|
|
41
65
|
this.disabled = false;
|
|
66
|
+
this.required = false;
|
|
42
67
|
this.label = "";
|
|
43
68
|
}
|
|
44
69
|
|
|
45
|
-
|
|
70
|
+
get _control() {
|
|
71
|
+
return this.renderRoot?.querySelector?.("input");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The bd-radio-group this radio belongs to, if any. */
|
|
75
|
+
get _owner() {
|
|
76
|
+
return this.closest("bd-radio-group");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The radios this one excludes, itself included, in document order. */
|
|
46
80
|
get _group() {
|
|
81
|
+
const owner = this._owner;
|
|
82
|
+
if (owner) return radiosOf(owner);
|
|
47
83
|
if (!this.name) return [this];
|
|
84
|
+
/* The tree the radio is in: a document, a shadow root, or -- taken off
|
|
85
|
+
the page -- the fragment or the detached element it went with. It used
|
|
86
|
+
to fall back to the live document there, so a detached radio checked
|
|
87
|
+
from script cleared every same-name radio on the page. */
|
|
48
88
|
const root = this.getRootNode();
|
|
49
|
-
|
|
50
|
-
|
|
89
|
+
return root === this ? [this] : byName(root, this.name, this.form);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get _isDisabled() {
|
|
93
|
+
return this.disabled || this._formDisabled;
|
|
51
94
|
}
|
|
52
95
|
|
|
53
96
|
/**
|
|
54
97
|
* One tab stop per group, as the radiogroup pattern requires: the selected
|
|
55
98
|
* radio, or the first enabled one when nothing is selected yet.
|
|
56
99
|
*/
|
|
57
|
-
|
|
58
|
-
if (this.
|
|
59
|
-
const group = this._group;
|
|
100
|
+
_tabbable(group) {
|
|
101
|
+
if (this._isDisabled) return false;
|
|
60
102
|
if (group.some(r => r.checked)) return this.checked;
|
|
61
|
-
return group.find(r => !r.
|
|
103
|
+
return group.find(r => !r._isDisabled) === this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* `required` on any radio, or on the group element, requires the group:
|
|
107
|
+
one of them has to be selected. */
|
|
108
|
+
_missing(group) {
|
|
109
|
+
const required = this._owner?.required || group.some(r => r.required);
|
|
110
|
+
return required && !group.some(r => r.checked);
|
|
62
111
|
}
|
|
63
112
|
|
|
64
|
-
/* The tab stop
|
|
65
|
-
|
|
66
|
-
joins or leaves, the rest
|
|
67
|
-
in a group with nothing selected used to
|
|
68
|
-
beside it -- two tab stops in one group. The
|
|
69
|
-
|
|
113
|
+
/* The tab stop, the validity and the position in the set are group
|
|
114
|
+
decisions, but each radio renders only when its own properties change.
|
|
115
|
+
So when one radio's state flips, or one joins or leaves, the rest are told
|
|
116
|
+
to re-render: clicking radio 3 in a group with nothing selected used to
|
|
117
|
+
leave radio 1 at tabindex 0 beside it -- two tab stops in one group. The
|
|
118
|
+
peers' own properties do not change, so this does not cascade. */
|
|
70
119
|
_refreshPeers(group) {
|
|
71
120
|
for (const radio of group) {
|
|
72
121
|
if (radio !== this) radio.requestUpdate?.();
|
|
73
122
|
}
|
|
74
123
|
}
|
|
75
124
|
|
|
125
|
+
/** The defining behaviour of a radio: the rest of the group lets go. */
|
|
126
|
+
_exclusive(group = this._group) {
|
|
127
|
+
for (const radio of group) {
|
|
128
|
+
if (radio !== this && radio.checked) radio.checked = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
76
132
|
connectedCallback() {
|
|
77
133
|
super.connectedCallback();
|
|
134
|
+
// what reset returns to, as in bd-checkbox: checked reflects, so the
|
|
135
|
+
// attribute cannot hold the default
|
|
136
|
+
this._defaults ??= { checked: this.checked };
|
|
137
|
+
const owner = this._owner;
|
|
138
|
+
if (owner?.name) this.name = owner.name;
|
|
78
139
|
this._refreshPeers(this._group);
|
|
79
140
|
}
|
|
80
141
|
|
|
81
142
|
disconnectedCallback() {
|
|
82
143
|
super.disconnectedCallback();
|
|
83
|
-
// detached, this radio can no longer find its
|
|
84
|
-
// was
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
144
|
+
// detached, this radio can no longer find its group, so it tells the one
|
|
145
|
+
// it was last rendered in
|
|
146
|
+
this._refreshPeers(this._peers ?? []);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
willUpdate(changed) {
|
|
150
|
+
/* The group, read once an update. The tab stop, the validity, the
|
|
151
|
+
position in the set and the peers to tell all ask it, and each read is
|
|
152
|
+
a scan of the whole root: it was read four times a render, on every
|
|
153
|
+
radio a change re-renders. */
|
|
154
|
+
this._groupNow = this._group;
|
|
155
|
+
/* A radio checked from script clears the rest, as a native one does. Not
|
|
156
|
+
on its first render: what a page wrote is taken as written, so a page
|
|
157
|
+
that renders one name in several places -- pricing cards, each with its
|
|
158
|
+
own "billing" pair -- loads every pair as it always did. */
|
|
159
|
+
if (changed.has("checked") && this.checked && this.hasUpdated) this._exclusive(this._groupNow);
|
|
89
160
|
}
|
|
90
161
|
|
|
91
162
|
updated(changed) {
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// a radio renamed out of a group leaves its old peers to re-decide too
|
|
97
|
-
const oldName = changed.get("name");
|
|
98
|
-
if (oldName && this._root) {
|
|
99
|
-
this._refreshPeers(this._root.querySelectorAll(`bd-radio[name="${CSS.escape(oldName)}"]`));
|
|
163
|
+
const group = this._groupNow;
|
|
164
|
+
if (["checked", "disabled", "name", "required", "_formDisabled"].some(p => changed.has(p))) {
|
|
165
|
+
// a radio renamed out of a group leaves its old peers to re-decide too
|
|
166
|
+
this._refreshPeers(new Set([...(this._peers ?? []), ...group]));
|
|
100
167
|
}
|
|
168
|
+
this._peers = group;
|
|
169
|
+
|
|
170
|
+
this._internals.setFormValue(this.checked ? this.value || "on" : null, String(this.checked));
|
|
171
|
+
// the inner radio carries `required` only while the group is missing a
|
|
172
|
+
// choice, so it is invalid exactly when the group is -- see render()
|
|
173
|
+
this._mirrorValidity(this._control);
|
|
101
174
|
}
|
|
102
175
|
|
|
103
|
-
|
|
104
|
-
|
|
176
|
+
formResetCallback() {
|
|
177
|
+
super.formResetCallback();
|
|
178
|
+
this.checked = this._defaults.checked;
|
|
179
|
+
}
|
|
105
180
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
181
|
+
formStateRestoreCallback(state) {
|
|
182
|
+
this.checked = state === "true";
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// a native radio is selected when its label is clicked, or on el.click()
|
|
186
|
+
_activate() {
|
|
187
|
+
this._control?.click();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* A native radio fires change only when it becomes checked. The rest of the
|
|
191
|
+
group lets go before the event, so a handler reading the group sees one
|
|
192
|
+
selection, not two. */
|
|
193
|
+
_onChange() {
|
|
194
|
+
this._exclusive();
|
|
111
195
|
this.checked = true;
|
|
112
196
|
|
|
113
197
|
this.dispatchEvent(
|
|
@@ -119,118 +203,67 @@ class BdRadio extends LitElement {
|
|
|
119
203
|
);
|
|
120
204
|
}
|
|
121
205
|
|
|
122
|
-
/** Move to the next or previous enabled radio,
|
|
206
|
+
/** Move to the next or previous enabled radio, focus it, and select it. */
|
|
123
207
|
_move(step) {
|
|
124
|
-
const enabled = this._group.filter(r => !r.
|
|
208
|
+
const enabled = this._group.filter(r => !r._isDisabled);
|
|
125
209
|
if (enabled.length < 2) return;
|
|
126
210
|
const from = enabled.indexOf(this);
|
|
127
211
|
const next = enabled[(from + step + enabled.length) % enabled.length];
|
|
128
|
-
next.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
212
|
+
next._control.focus();
|
|
213
|
+
// a click, as the browser sends one when the arrow keys select a radio:
|
|
214
|
+
// it checks the radio and fires input and change on the way
|
|
215
|
+
next._control.click();
|
|
132
216
|
}
|
|
133
217
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
} else if (PREV_KEYS.includes(e.key)) {
|
|
218
|
+
/* The arrow keys are the group's, and the browser's own group here is this
|
|
219
|
+
one radio, so they are handled here. Space is the native radio's own, and
|
|
220
|
+
Enter submits the form, as it does from a native radio (see
|
|
221
|
+
shared/form-control.js). */
|
|
222
|
+
_onKeydown(e) {
|
|
223
|
+
if (e.key === "Enter") {
|
|
141
224
|
e.preventDefault();
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
e.preventDefault();
|
|
145
|
-
this._select();
|
|
225
|
+
this._submitImplicitly();
|
|
226
|
+
return;
|
|
146
227
|
}
|
|
228
|
+
let step = NEXT_KEYS.includes(e.key) ? 1 : PREV_KEYS.includes(e.key) ? -1 : 0;
|
|
229
|
+
if (!step) return;
|
|
230
|
+
// left and right swap on a right-to-left page, as a native group's do
|
|
231
|
+
if (e.key.endsWith("Left") || e.key.endsWith("Right")) step *= this.matches(":dir(rtl)") ? -1 : 1;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
this._move(step);
|
|
147
234
|
}
|
|
148
235
|
|
|
149
236
|
render() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
@keydown=${this._handleKeydown}
|
|
159
|
-
>
|
|
160
|
-
<span class="box" part="box"><span class="dot"></span></span>
|
|
161
|
-
<span class="label" part="label"><slot>${this.label}</slot></span>
|
|
162
|
-
</div>
|
|
163
|
-
`;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Toggles independently despite looking like a radio, which is why it declares
|
|
169
|
-
* role="checkbox". It duplicates bd-checkbox with a circular skin, and a round
|
|
170
|
-
* control that does not behave exclusively misleads people — it should be
|
|
171
|
-
* retired in favour of bd-checkbox. Kept working here because it is a
|
|
172
|
-
* published element with stories against it.
|
|
173
|
-
*/
|
|
174
|
-
class BdToggleRadio extends LitElement {
|
|
175
|
-
static styles = [radioCSS];
|
|
176
|
-
|
|
177
|
-
static properties = {
|
|
178
|
-
name : { type: String },
|
|
179
|
-
value : { type: String },
|
|
180
|
-
checked : { type: Boolean, reflect: true },
|
|
181
|
-
disabled: { type: Boolean, reflect: true },
|
|
182
|
-
label : { type: String }
|
|
183
|
-
};
|
|
237
|
+
const group = this._groupNow;
|
|
238
|
+
/* The inner radio is required while the group has no choice, and only
|
|
239
|
+
then. It supplies the browser's own message for an empty required
|
|
240
|
+
group; marked required for good, an unselected radio beside the
|
|
241
|
+
selected one would be invalid on its own and could be announced so.
|
|
242
|
+
It needs a name for that: a radio without one is in no group, and the
|
|
243
|
+
browser never finds it missing. Any name does -- it is the only radio
|
|
244
|
+
in this root, and the host is what a form reads.
|
|
184
245
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.name = "";
|
|
188
|
-
this.value = "";
|
|
189
|
-
this.checked = false;
|
|
190
|
-
this.disabled = false;
|
|
191
|
-
this.label = "";
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
_toggle() {
|
|
195
|
-
if (this.disabled) return;
|
|
196
|
-
this.checked = !this.checked;
|
|
197
|
-
|
|
198
|
-
this.dispatchEvent(
|
|
199
|
-
// name was declared and read by nothing; it is carried here, as
|
|
200
|
-
// bd-radio carries it, so a handler can tell which control changed
|
|
201
|
-
new CustomEvent("change", {
|
|
202
|
-
detail : { checked: this.checked, value: this.checked ? this.value : null, name: this.name },
|
|
203
|
-
bubbles : true,
|
|
204
|
-
composed: true
|
|
205
|
-
})
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
_handleKeydown(e) {
|
|
210
|
-
if (this.disabled) return;
|
|
211
|
-
if (e.key === " " || e.key === "Enter") {
|
|
212
|
-
e.preventDefault();
|
|
213
|
-
this._toggle();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
render() {
|
|
246
|
+
Its position in the set is stated, because the browser counts each
|
|
247
|
+
shadow root's radios alone and would announce every radio as 1 of 1. */
|
|
218
248
|
return html`
|
|
219
|
-
<
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
249
|
+
<label class="bd-radio">
|
|
250
|
+
<input
|
|
251
|
+
type="radio"
|
|
252
|
+
name="choice"
|
|
253
|
+
.checked=${this.checked}
|
|
254
|
+
?disabled=${this._isDisabled}
|
|
255
|
+
?required=${this._missing(group)}
|
|
256
|
+
tabindex=${this._tabbable(group) ? 0 : -1}
|
|
257
|
+
aria-posinset=${group.length > 1 ? group.indexOf(this) + 1 : nothing}
|
|
258
|
+
aria-setsize=${group.length > 1 ? group.length : nothing}
|
|
259
|
+
@change=${this._onChange}
|
|
260
|
+
@keydown=${this._onKeydown}
|
|
261
|
+
/>
|
|
228
262
|
<span class="box" part="box"><span class="dot"></span></span>
|
|
229
263
|
<span class="label" part="label"><slot>${this.label}</slot></span>
|
|
230
|
-
</
|
|
264
|
+
</label>
|
|
231
265
|
`;
|
|
232
266
|
}
|
|
233
267
|
}
|
|
234
268
|
|
|
235
|
-
customElements.define("bd-toggle-radio", BdToggleRadio);
|
|
236
269
|
customElements.define("bd-radio", BdRadio);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html } from 'lit';
|
|
2
2
|
import './radio.js';
|
|
3
|
+
import './radio-group.js';
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
title : 'Atoms/Radio',
|
|
@@ -9,47 +10,74 @@ export default {
|
|
|
9
10
|
description: {
|
|
10
11
|
component: `
|
|
11
12
|
- \`<bd-radio>\` — one choice from a group. Selecting one clears the others
|
|
12
|
-
|
|
13
|
-
- \`<bd-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
in its group.
|
|
14
|
+
- \`<bd-radio-group>\` — the group: \`role="radiogroup"\`, its label, its
|
|
15
|
+
\`name\` and \`required\`. Import \`@repobit/dex-system-design/radio-group\`.
|
|
16
|
+
- \`<bd-toggle-radio>\` — **deprecated.** It is circular like a radio but is a
|
|
17
|
+
native checkbox underneath and toggles independently, so it looks exclusive
|
|
18
|
+
and is not. Use \`<bd-checkbox>\` instead. Space toggles it and Enter submits
|
|
19
|
+
its form, as on \`bd-checkbox\`; it is form-associated like its siblings.
|
|
16
20
|
|
|
17
21
|
### Usage
|
|
18
22
|
\`\`\`html
|
|
19
|
-
<bd-radio
|
|
20
|
-
<bd-radio
|
|
21
|
-
|
|
22
|
-
<!-- the label is slotted, so it can carry markup -->
|
|
23
|
-
<bd-radio
|
|
23
|
+
<bd-radio-group label="Plan" name="plan" required>
|
|
24
|
+
<bd-radio value="basic" label="Basic"></bd-radio>
|
|
25
|
+
<bd-radio value="premium" label="Premium" checked></bd-radio>
|
|
26
|
+
<!-- the label is slotted, so it can carry markup -->
|
|
27
|
+
<bd-radio value="custom">See the <a href="/plans">plans</a></bd-radio>
|
|
28
|
+
</bd-radio-group>
|
|
29
|
+
|
|
30
|
+
<!-- without a group element, radios group by name, as before -->
|
|
31
|
+
<bd-radio name="billing" value="monthly" label="Monthly"></bd-radio>
|
|
32
|
+
<bd-radio name="billing" value="yearly" label="Yearly" checked></bd-radio>
|
|
24
33
|
\`\`\`
|
|
25
34
|
|
|
26
35
|
### Group behaviour
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
A radio's group is its \`<bd-radio-group>\`, or, without one, the radios that
|
|
37
|
+
share its \`name\` in the same root. Either way:
|
|
29
38
|
|
|
30
39
|
| | |
|
|
31
40
|
|---|---|
|
|
32
|
-
| Exclusivity | Selecting one clears every other radio
|
|
41
|
+
| Exclusivity | Selecting one clears every other radio in the group — by click, by key, or by setting \`checked\` from script, as a native radio does. The \`checked\` a radio is first rendered with is kept as written. |
|
|
33
42
|
| Arrow keys | Up and Left move to the previous option, Down and Right to the next, wrapping at both ends and skipping disabled ones. Moving selects, as it does natively. |
|
|
34
43
|
| Tab | **One stop for the whole group**, on the selected radio, or the first enabled one when nothing is selected. |
|
|
35
|
-
| Space | Selects the focused radio. Re-selecting the current one does nothing. |
|
|
44
|
+
| Space | Selects the focused radio, natively. Re-selecting the current one does nothing. |
|
|
45
|
+
|
|
46
|
+
The browser cannot do this part itself: each radio is a native
|
|
47
|
+
\`<input type="radio">\` in its own shadow root, and a native group is the
|
|
48
|
+
radios sharing a name **in one tree**. So the group is still worked out by the
|
|
49
|
+
radios, and each states its place in the set — the browser would announce
|
|
50
|
+
every one as "1 of 1".
|
|
51
|
+
|
|
52
|
+
### The group element
|
|
53
|
+
\`<bd-radio-group>\` renders \`role="radiogroup"\` named by its \`label\`, so a
|
|
54
|
+
screen reader hears the question with the options, and \`aria-required\` when
|
|
55
|
+
it is \`required\`. It gives every radio inside its \`name\`, and scopes them:
|
|
56
|
+
they exclude each other and nothing else, whatever else on the page shares the
|
|
57
|
+
name. Its \`value\` reads and sets the selected radio's, as
|
|
58
|
+
\`RadioNodeList.value\` does. The options stack; lay them out in a row with
|
|
59
|
+
\`bd-radio-group::part(options)\`.
|
|
60
|
+
|
|
61
|
+
### In a form
|
|
62
|
+
\`bd-radio\` is **form-associated**, so a \`<form>\` sees the group as it would
|
|
63
|
+
native radios.
|
|
36
64
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
the
|
|
65
|
+
| | |
|
|
66
|
+
|---|---|
|
|
67
|
+
| Submit | The selected radio's \`name=value\` (\`on\` with no \`value\`); the others send nothing. |
|
|
68
|
+
| Reset | Back to the selection the radios joined the page with. |
|
|
69
|
+
| \`required\` | On any radio, or on the group element: the submit is blocked until one is selected, with the browser's own message. |
|
|
70
|
+
| \`<fieldset disabled>\` | Disables the radios and leaves them out of the submit, without touching their \`disabled\`. |
|
|
42
71
|
|
|
43
|
-
|
|
44
|
-
\`name\` groups the radios and is carried on the \`change\` event, but this
|
|
45
|
-
element does **not** participate in form submission — a \`<form>\` containing it
|
|
46
|
-
yields no \`FormData\` entry, because there is no native input behind it.
|
|
72
|
+
**Fieldset → In a form** shows every control together.
|
|
47
73
|
|
|
48
74
|
### Accessibility
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
- A **native radio** is the control, clipped out of sight under the drawn
|
|
76
|
+
circle, so the browser supplies the role, the checked and disabled states,
|
|
77
|
+
and Space.
|
|
78
|
+
- The **whole row is the control**, a \`<label>\`, so clicking the label
|
|
79
|
+
selects, and the target clears the 24px WCAG 2.5.8 asks for — a 20px circle
|
|
80
|
+
cannot on its own.
|
|
53
81
|
- The focus ring appears on keyboard navigation only, via \`:focus-visible\`, and
|
|
54
82
|
is inset evenly on all four sides.
|
|
55
83
|
|
|
@@ -82,12 +110,12 @@ Two deviations from the design, both deliberate:
|
|
|
82
110
|
},
|
|
83
111
|
name: {
|
|
84
112
|
control : 'text',
|
|
85
|
-
description: '
|
|
113
|
+
description: 'Groups the radios outside a bd-radio-group, and is the name the selected one submits under in a form',
|
|
86
114
|
table : { type: { summary: 'string' }, defaultValue: { summary: '' }, category: 'Form' }
|
|
87
115
|
},
|
|
88
116
|
value: {
|
|
89
117
|
control : 'text',
|
|
90
|
-
description: '
|
|
118
|
+
description: 'Submitted with a form when selected, and emitted in the change event detail',
|
|
91
119
|
table : { type: { summary: 'string' }, defaultValue: { summary: '' }, category: 'Form' }
|
|
92
120
|
},
|
|
93
121
|
checked: {
|
|
@@ -99,6 +127,11 @@ Two deviations from the design, both deliberate:
|
|
|
99
127
|
control : 'boolean',
|
|
100
128
|
description: 'Disables interaction and applies disabled styles',
|
|
101
129
|
table : { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, category: 'State' }
|
|
130
|
+
},
|
|
131
|
+
required: {
|
|
132
|
+
control : 'boolean',
|
|
133
|
+
description: 'In a form, blocks the submit until one radio of the group is selected',
|
|
134
|
+
table : { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, category: 'State' }
|
|
102
135
|
}
|
|
103
136
|
}
|
|
104
137
|
};
|
|
@@ -129,25 +162,25 @@ const renderToggle = (args) => html`
|
|
|
129
162
|
|
|
130
163
|
export const RadioDefault = {
|
|
131
164
|
name : 'Radio — Default (Unchecked)',
|
|
132
|
-
render : () => html`<bd-radio name="plan" value="basic" label="Basic Plan"></bd-radio>`,
|
|
165
|
+
render : () => html`<bd-radio name="plan-default" value="basic" label="Basic Plan"></bd-radio>`,
|
|
133
166
|
parameters: { docs: { description: { story: 'Default unchecked radio button.' } } }
|
|
134
167
|
};
|
|
135
168
|
|
|
136
169
|
export const RadioChecked = {
|
|
137
170
|
name : 'Radio — Checked',
|
|
138
|
-
render : () => html`<bd-radio name="plan" value="premium" label="Premium Plan" checked></bd-radio>`,
|
|
171
|
+
render : () => html`<bd-radio name="plan-checked" value="premium" label="Premium Plan" checked></bd-radio>`,
|
|
139
172
|
parameters: { docs: { description: { story: 'Radio pre-selected via the `checked` attribute.' } } }
|
|
140
173
|
};
|
|
141
174
|
|
|
142
175
|
export const RadioDisabled = {
|
|
143
176
|
name : 'Radio — Disabled (Unchecked)',
|
|
144
|
-
render : () => html`<bd-radio name="plan" value="enterprise" label="Enterprise (unavailable)" disabled></bd-radio>`,
|
|
145
|
-
parameters: { docs: { description: { story: 'Disabled radio — not interactable,
|
|
177
|
+
render : () => html`<bd-radio name="plan-disabled" value="enterprise" label="Enterprise (unavailable)" disabled></bd-radio>`,
|
|
178
|
+
parameters: { docs: { description: { story: 'Disabled radio — not interactable, out of the tab order, announced as disabled.' } } }
|
|
146
179
|
};
|
|
147
180
|
|
|
148
181
|
export const RadioDisabledChecked = {
|
|
149
182
|
name : 'Radio — Disabled (Checked)',
|
|
150
|
-
render : () => html`<bd-radio name="plan" value="locked" label="Locked selection" checked disabled></bd-radio>`,
|
|
183
|
+
render : () => html`<bd-radio name="plan-locked" value="locked" label="Locked selection" checked disabled></bd-radio>`,
|
|
151
184
|
parameters: { docs: { description: { story: 'Disabled radio in the checked/selected state — locked selection.' } } }
|
|
152
185
|
};
|
|
153
186
|
|
|
@@ -167,23 +200,45 @@ export const RadioAllStates = {
|
|
|
167
200
|
export const RadioGroup = {
|
|
168
201
|
name : 'Radio — Group (Single Select)',
|
|
169
202
|
render: () => html`
|
|
170
|
-
<
|
|
171
|
-
<
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
203
|
+
<bd-radio-group label="Choose your plan" name="plan">
|
|
204
|
+
<bd-radio value="basic" label="Basic — 1 device" checked></bd-radio>
|
|
205
|
+
<bd-radio value="standard" label="Standard — 3 devices"></bd-radio>
|
|
206
|
+
<bd-radio value="premium" label="Premium — 5 devices"></bd-radio>
|
|
207
|
+
<bd-radio value="unlimited" label="Unlimited devices" disabled></bd-radio>
|
|
208
|
+
</bd-radio-group>
|
|
209
|
+
`,
|
|
210
|
+
parameters: { docs: { description: { story: 'A `bd-radio-group`: a radiogroup named by its label, which gives its radios their name. Only one can be selected at a time, and the arrow keys move the selection.' } } }
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const RadioGroupRequired = {
|
|
214
|
+
name : 'Radio — Group, required',
|
|
215
|
+
render: () => html`
|
|
216
|
+
<bd-radio-group label="How often should we bill you?" name="billing" required>
|
|
217
|
+
<bd-radio value="monthly" label="Monthly"></bd-radio>
|
|
218
|
+
<bd-radio value="yearly" label="Yearly"></bd-radio>
|
|
219
|
+
</bd-radio-group>
|
|
220
|
+
`,
|
|
221
|
+
parameters: { docs: { description: { story: 'A required group: the label carries the required mark and the group announces `aria-required`. In a form, the submit is blocked until one is chosen.' } } }
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export const RadioGroupInline = {
|
|
225
|
+
name : 'Radio — Group in a row',
|
|
226
|
+
render: () => html`
|
|
227
|
+
<style>
|
|
228
|
+
.billing-row::part(options) { flex-direction: row; gap: var(--spacing-24); }
|
|
229
|
+
</style>
|
|
230
|
+
<bd-radio-group class="billing-row" label="Billing" name="billing-row">
|
|
231
|
+
<bd-radio value="monthly" label="Monthly"></bd-radio>
|
|
232
|
+
<bd-radio value="yearly" label="Yearly" checked></bd-radio>
|
|
233
|
+
</bd-radio-group>
|
|
179
234
|
`,
|
|
180
|
-
parameters: { docs: { description: { story: '
|
|
235
|
+
parameters: { docs: { description: { story: 'The options stack by default; `::part(options)` lays them out in a row.' } } }
|
|
181
236
|
};
|
|
182
237
|
|
|
183
238
|
export const RadioKeyboard = {
|
|
184
239
|
name : 'Radio — Keyboard Navigation',
|
|
185
240
|
render: () => html`
|
|
186
|
-
<p style="font-size:14px; margin-bottom:8px;">Tab to focus,
|
|
241
|
+
<p style="font-size:14px; margin-bottom:8px;">Tab to focus, the arrow keys to move the selection, Space to select.</p>
|
|
187
242
|
<div style="display:flex; flex-direction:column; gap:8px;">
|
|
188
243
|
<bd-radio name="kb" value="a" label="Option A"></bd-radio>
|
|
189
244
|
<bd-radio name="kb" value="b" label="Option B"></bd-radio>
|