@repobit/dex-system-design 2.5.0 → 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.
Files changed (173) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +2 -1
  3. package/package.json +14 -27
  4. package/schemas/component-manifest.json +226 -33
  5. package/schemas/manifest-omissions.json +23 -0
  6. package/src/components/accordion/accordion-bg.css.js +39 -30
  7. package/src/components/accordion/accordion-bg.js +17 -28
  8. package/src/components/accordion/accordion-bg.stories.js +5 -0
  9. package/src/components/accordion/accordion-panel.js +24 -0
  10. package/src/components/accordion/accordion.css.js +105 -111
  11. package/src/components/accordion/accordion.js +23 -37
  12. package/src/components/accordion/accordion.stories.js +5 -1
  13. package/src/components/anchor/anchor-nav.css.js +131 -53
  14. package/src/components/anchor/anchor-nav.js +276 -201
  15. package/src/components/annotation/annotation.css.js +7 -4
  16. package/src/components/architecture.stories.js +8 -7
  17. package/src/components/audience-card/audience-card.css.js +30 -4
  18. package/src/components/audience-card/audience-card.js +8 -13
  19. package/src/components/awards/awards-flex.css.js +23 -6
  20. package/src/components/awards/awards-flex.js +21 -6
  21. package/src/components/awards/awards-spotlight.css.js +25 -5
  22. package/src/components/awards/awards-spotlight.js +19 -7
  23. package/src/components/awards/awards.css.js +20 -8
  24. package/src/components/awards/awards.js +30 -91
  25. package/src/components/awards/awards.stories.js +5 -5
  26. package/src/components/awards/scroll-slides.js +128 -0
  27. package/src/components/back/back.css.js +2 -0
  28. package/src/components/badge/badge.css.js +15 -0
  29. package/src/components/bento-grid/bento-grid.css.js +105 -11
  30. package/src/components/bento-grid/bento-grid.js +37 -124
  31. package/src/components/bento-grid/bento-grid.stories.js +3 -2
  32. package/src/components/bento-grid/bento-item.css.js +71 -32
  33. package/src/components/bento-grid/bento-item.js +3 -30
  34. package/src/components/blockquote/blockquote.css.js +2 -2
  35. package/src/components/breadcrumb/breadcrumb.css.js +10 -9
  36. package/src/components/breadcrumb/breadcrumb.js +35 -34
  37. package/src/components/button/button.css.js +42 -17
  38. package/src/components/button/button.js +84 -3
  39. package/src/components/button/button.stories.js +17 -0
  40. package/src/components/card-features/card-features.css.js +23 -2
  41. package/src/components/card-features/card-features.js +6 -48
  42. package/src/components/cards/card.css.js +43 -14
  43. package/src/components/cards/card.js +43 -177
  44. package/src/components/cards/card.stories.js +8 -10
  45. package/src/components/carousel/carousel.css.js +101 -70
  46. package/src/components/carousel/carousel.js +107 -71
  47. package/src/components/carousel/carousel.stories.js +18 -16
  48. package/src/components/checkbox/checkbox.css.js +26 -9
  49. package/src/components/checkbox/checkbox.js +73 -39
  50. package/src/components/checkbox/checkbox.stories.js +35 -18
  51. package/src/components/compare/compare.css.js +68 -10
  52. package/src/components/compare/compare.js +40 -103
  53. package/src/components/compare/compare.stories.js +1 -1
  54. package/src/components/compatibility-table/compatibility-table.css.js +70 -37
  55. package/src/components/compatibility-table/compatibility-table.js +47 -40
  56. package/src/components/compatibility-table/compatibility-table.stories.js +78 -1
  57. package/src/components/display/display.css.js +7 -0
  58. package/src/components/dropdown/dropdown.css.js +20 -3
  59. package/src/components/dropdown/dropdown.js +57 -21
  60. package/src/components/dropdown/dropdown.stories.js +31 -9
  61. package/src/components/features/features.css.js +56 -21
  62. package/src/components/features/features.js +7 -117
  63. package/src/components/fieldset/fieldset.stories.js +68 -0
  64. package/src/components/footer/footer-images.js +34 -0
  65. package/src/components/footer/footer-links-group.css.js +10 -10
  66. package/src/components/footer/footer-locale.js +47 -0
  67. package/src/components/footer/footer-lp.js +27 -114
  68. package/src/components/footer/footer-lp.stories.js +2 -2
  69. package/src/components/footer/footer-nav-menu.css.js +2 -2
  70. package/src/components/footer/footer-nav-menu.js +8 -3
  71. package/src/components/footer/footer.css.js +238 -197
  72. package/src/components/footer/footer.js +109 -187
  73. package/src/components/footer/footer.stories.js +14 -4
  74. package/src/components/grid/grid.css.js +64 -5
  75. package/src/components/header/header-code.css.js +20 -11
  76. package/src/components/header/header-code.js +1 -1
  77. package/src/components/header/header.css.js +20 -14
  78. package/src/components/header/header.js +6 -7
  79. package/src/components/header/header.stories.js +29 -24
  80. package/src/components/heading/heading.css.js +11 -0
  81. package/src/components/hero/hero.js +10 -2
  82. package/src/components/highlight/highlight.css.js +30 -6
  83. package/src/components/icons/arrow-icon.js +4 -1
  84. package/src/components/icons/arrow-right-icon.js +5 -1
  85. package/src/components/icons/icon-element.js +18 -0
  86. package/src/components/image/image.js +29 -9
  87. package/src/components/image/image.stories.js +38 -2
  88. package/src/components/input/custom-form.stories.js +38 -7
  89. package/src/components/input/input-clipboard.css.js +15 -1
  90. package/src/components/input/input-clipboard.js +84 -21
  91. package/src/components/input/input.js +27 -7
  92. package/src/components/install-options/install-options.css.js +26 -6
  93. package/src/components/install-options/install-options.js +32 -8
  94. package/src/components/label/label.css.js +1 -1
  95. package/src/components/light-carousel/light-carousel.css.js +100 -48
  96. package/src/components/light-carousel/light-carousel.js +43 -5
  97. package/src/components/link/link.css.js +15 -15
  98. package/src/components/link/link.js +17 -1
  99. package/src/components/link/link.stories.js +20 -7
  100. package/src/components/list/list.css.js +3 -3
  101. package/src/components/logo-marquee/logo-marquee.css.js +12 -1
  102. package/src/components/logo-marquee/logo-marquee.js +33 -8
  103. package/src/components/logo-marquee/logo-marquee.stories.js +10 -4
  104. package/src/components/modal/modal.css.js +74 -40
  105. package/src/components/modal/modal.js +85 -74
  106. package/src/components/modal/modal.stories.js +27 -14
  107. package/src/components/motion-art/motion-art.js +67 -1
  108. package/src/components/page-switcher/page-switcher.css.js +27 -9
  109. package/src/components/page-switcher/page-switcher.js +11 -8
  110. package/src/components/partner-banner/partner-banner.css.js +2 -0
  111. package/src/components/picture/picture.css.js +4 -4
  112. package/src/components/picture/picture.js +13 -3
  113. package/src/components/picture/picture.stories.js +28 -2
  114. package/src/components/post-card/post-card.css.js +18 -3
  115. package/src/components/pricing-cards/adopt-styles.js +16 -0
  116. package/src/components/pricing-cards/new-pricing-card.js +2 -4
  117. package/src/components/pricing-cards/new-pricing-card.stories.js +20 -22
  118. package/src/components/pricing-cards/pricing-card-actions.css.js +8 -12
  119. package/src/components/pricing-cards/pricing-card-actions.js +26 -13
  120. package/src/components/pricing-cards/pricing-card-container.css.js +4 -3
  121. package/src/components/pricing-cards/pricing-card-container.js +10 -4
  122. package/src/components/pricing-cards/pricing-card-header.css.js +5 -4
  123. package/src/components/pricing-cards/pricing-card-header.js +18 -31
  124. package/src/components/pricing-cards/pricing-card-pricing.css.js +84 -61
  125. package/src/components/pricing-cards/pricing-card-pricing.js +38 -24
  126. package/src/components/pricing-cards/pricing-card-show-more.js +8 -3
  127. package/src/components/pricing-cards/pricing-card.css.js +75 -41
  128. package/src/components/pricing-cards/pricing-card.js +356 -308
  129. package/src/components/progress/progress.css.js +58 -13
  130. package/src/components/progress/progress.js +13 -10
  131. package/src/components/progress/progress.stories.js +9 -7
  132. package/src/components/radio/radio-group.css.js +42 -0
  133. package/src/components/radio/radio-group.js +89 -0
  134. package/src/components/radio/radio.css.js +63 -6
  135. package/src/components/radio/radio.js +173 -140
  136. package/src/components/radio/radio.stories.js +99 -44
  137. package/src/components/radio/toggle-radio.js +44 -0
  138. package/src/components/review/review-grid.css.js +5 -1
  139. package/src/components/review/review-grid.js +2 -0
  140. package/src/components/review/review.js +13 -0
  141. package/src/components/shared/announcer.js +37 -0
  142. package/src/components/shared/fill-width.css.js +33 -0
  143. package/src/components/shared/form-control.js +194 -0
  144. package/src/components/shared/form-field.css.js +31 -3
  145. package/src/components/shared/token-scales.js +75 -26
  146. package/src/components/spotlight-section/spotlight-section.js +2 -2
  147. package/src/components/stat/stat-highlight.js +1 -1
  148. package/src/components/stat/stat.css.js +18 -3
  149. package/src/components/switch/switch.css.js +58 -5
  150. package/src/components/switch/switch.js +53 -5
  151. package/src/components/switch/switch.stories.js +30 -8
  152. package/src/components/tab-list/tab-list.css.js +51 -13
  153. package/src/components/tab-list/tab-list.js +7 -2
  154. package/src/components/tab-list/tab-list.stories.js +2 -2
  155. package/src/components/tabs/tabs.css.js +18 -1
  156. package/src/components/tabs/tabs.js +119 -41
  157. package/src/components/terminal/terminal-message.css.js +6 -1
  158. package/src/components/termsOfUse/terms.css.js +4 -2
  159. package/src/components/textarea/textarea.js +22 -7
  160. package/src/components/textarea/textarea.stories.js +12 -9
  161. package/src/components/trust-panel/trust-panel.css.js +13 -3
  162. package/src/components/ultimate-security-demo.stories.js +5 -5
  163. package/src/components/video/video.css.js +5 -0
  164. package/src/components/video/video.js +5 -0
  165. package/src/components/video/video.stories.js +12 -0
  166. package/src/components/video-player/video-player.css.js +20 -8
  167. package/src/components/video-player/video-player.js +74 -20
  168. package/src/components/video-player/video-player.stories.js +17 -3
  169. package/src/tokens/brands.stories.js +1 -1
  170. package/src/tokens/themes/index.js +2 -2
  171. package/src/tokens/typography.stories.js +4 -3
  172. package/src/vendor/motion-art/README.md +4 -1
  173. 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 sharing its `name`, and the
11
- * arrow keys move between them.
29
+ * A single radio. Selecting one clears the others in its group, and the arrow
30
+ * keys move between them.
12
31
  *
13
- * The group behaviour is worked out by finding same-name siblings in the same
14
- * root, because there is no group element yet. That covers exclusivity, arrow
15
- * navigation and the roving tabindex, but it cannot supply role="radiogroup"
16
- * or a group label — those need an owning element, so a screen reader still
17
- * gets no "1 of 4" context. A bd-radio-group is the missing piece.
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
- name : { type: String, reflect: true },
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
- /** Same-name radios in this root, in document order. */
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
- const scope = root instanceof Document || root instanceof ShadowRoot ? root : document;
50
- return [...scope.querySelectorAll(`bd-radio[name="${CSS.escape(this.name)}"]`)];
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
- get _tabbable() {
58
- if (this.disabled) return false;
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.disabled) === this;
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 is a group decision, but each radio renders only when its own
65
- properties change. So when one radio's checked or disabled flips, or one
66
- joins or leaves, the rest have to be told to re-render: clicking radio 3
67
- in a group with nothing selected used to leave radio 1 at tabindex 0
68
- beside it -- two tab stops in one group. The peers' own checked and
69
- disabled do not change, so this does not cascade. */
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 root, so it asks the one it
84
- // was connected in
85
- const root = this._root;
86
- if (this.name && root) {
87
- this._refreshPeers(root.querySelectorAll(`bd-radio[name="${CSS.escape(this.name)}"]`));
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
- this._root = this.isConnected ? this.getRootNode() : this._root;
93
- if (changed.has("checked") || changed.has("disabled") || changed.has("name")) {
94
- this._refreshPeers(this._group);
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
- _select() {
104
- if (this.disabled || this.checked) return;
176
+ formResetCallback() {
177
+ super.formResetCallback();
178
+ this.checked = this._defaults.checked;
179
+ }
105
180
 
106
- // the defining behaviour of a radio, and the part that was missing: the
107
- // rest of the group has to let go
108
- for (const radio of this._group) {
109
- if (radio !== this && radio.checked) radio.checked = false;
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, select it, and focus it. */
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.disabled);
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._select();
129
- next.updateComplete.then(() => {
130
- next.shadowRoot.querySelector(".bd-radio")?.focus();
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
- _handleKeydown(e) {
135
- if (this.disabled) return;
136
-
137
- if (NEXT_KEYS.includes(e.key)) {
138
- e.preventDefault();
139
- this._move(1);
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._move(-1);
143
- } else if (e.key === " ") {
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
- return html`
151
- <div
152
- class="bd-radio"
153
- role="radio"
154
- aria-checked="${this.checked ? "true" : "false"}"
155
- aria-disabled="${this.disabled ? "true" : "false"}"
156
- tabindex="${this._tabbable ? 0 : -1}"
157
- @click=${this._select}
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
- constructor() {
186
- super();
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
- <div
220
- class="bd-radio"
221
- role="checkbox"
222
- aria-checked="${this.checked ? "true" : "false"}"
223
- aria-disabled="${this.disabled ? "true" : "false"}"
224
- tabindex="${this.disabled ? -1 : 0}"
225
- @click=${this._toggle}
226
- @keydown=${this._handleKeydown}
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
- </div>
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
- that share its \`name\`.
13
- - \`<bd-toggle-radio>\` — **deprecated.** It is circular like a radio but
14
- declares \`role="checkbox"\` and toggles independently, so it looks exclusive
15
- and is not. Use \`<bd-checkbox>\` instead.
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 name="plan" value="basic" label="Basic"></bd-radio>
20
- <bd-radio name="plan" value="premium" label="Premium" checked></bd-radio>
21
-
22
- <!-- the label is slotted, so it can carry markup -->
23
- <bd-radio name="plan" value="custom">See the <a href="/plans">plans</a></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
- Radios find their group by \`name\` among their siblings in the same root, so no
28
- wrapper element is needed for the behaviour below.
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 with the same \`name\`. |
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
- ### Still missing: role="radiogroup"
38
- A screen reader gets each radio with its own state but **no group context** — no
39
- "1 of 4", and no group label. That needs an owning element, so a
40
- \`bd-radio-group\` is the missing piece. The behaviour above works without it;
41
- the announcement does not.
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
- ### Not form-associated
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
- - The **whole row is the control**, so clicking the label selects, and the
50
- target clears the 24px WCAG 2.5.8 asks for — a 20px circle cannot on its own.
51
- - \`role="radio"\` with \`aria-checked\` reporting \`true\` or \`false\`, plus
52
- \`aria-disabled\`.
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: 'Form group name for the radio',
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: 'Value emitted in the change event detail',
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, `tabindex="-1"`, `aria-disabled="true"`.' } } }
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
- <fieldset style="border:none; padding:0;">
171
- <legend style="font-weight:600; margin-bottom:12px;">Choose your plan</legend>
172
- <div style="display:flex; flex-direction:column; gap:8px;">
173
- <bd-radio name="plan" value="basic" label="Basic — 1 device" checked></bd-radio>
174
- <bd-radio name="plan" value="standard" label="Standard — 3 devices"></bd-radio>
175
- <bd-radio name="plan" value="premium" label="Premium — 5 devices"></bd-radio>
176
- <bd-radio name="plan" value="unlimited" label="Unlimited devices" disabled></bd-radio>
177
- </div>
178
- </fieldset>
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: 'A group of radio buttons sharing the same `name`. Only one can be selected at a time. Note: mutual exclusivity requires a parent controller — `bd-radio` does not auto-deselect siblings.' } } }
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, Space or Enter to select.</p>
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>