@solid-design-system/components 1.19.0 → 1.21.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 (134) hide show
  1. package/dist/components/es/accordion-group.js +1 -1
  2. package/dist/components/es/accordion.js +1 -1
  3. package/dist/components/es/brandshape.js +1 -1
  4. package/dist/components/es/button.js +1 -1
  5. package/dist/components/es/carousel.js +2 -2
  6. package/dist/components/es/drawer.js +1 -1
  7. package/dist/components/es/dropdown.js +1 -1
  8. package/dist/components/es/form.js +1 -0
  9. package/dist/components/es/icon.js +3 -3
  10. package/dist/components/es/if-defined.js +2 -2
  11. package/dist/components/es/link.js +1 -1
  12. package/dist/components/es/lit-element.js +4 -4
  13. package/dist/components/es/navigation-item.js +2 -2
  14. package/dist/components/es/popup.js +1 -1
  15. package/dist/components/es/query-assigned-elements.js +6 -0
  16. package/dist/components/es/query.js +7 -2
  17. package/dist/components/es/radio-group.js +1 -0
  18. package/dist/components/es/radio.js +1 -0
  19. package/dist/components/es/solid-components2.js +1 -1
  20. package/dist/components/es/solid-element.js +2 -12
  21. package/dist/components/es/state.js +1 -1
  22. package/dist/components/es/static.js +1 -1
  23. package/dist/components/es/tag.js +1 -1
  24. package/dist/components/es/teaser.js +1 -1
  25. package/dist/components/es/video.js +1 -1
  26. package/dist/components/umd/solid-components.js +18 -18
  27. package/dist/custom-elements.json +1 -1
  28. package/dist/package/_components/button-group/button-group.d.ts +19 -0
  29. package/dist/package/_components/button-group/button-group.js +76 -0
  30. package/dist/package/_components/button-group/button-group.styles.d.ts +2 -0
  31. package/dist/package/_components/button-group/button-group.styles.js +6 -0
  32. package/dist/package/components/button/button.d.ts +4 -0
  33. package/dist/package/components/button/button.js +25 -3
  34. package/dist/package/components/radio/radio.d.ts +27 -0
  35. package/dist/package/components/radio/radio.js +130 -0
  36. package/dist/package/components/radio-group/radio-group.d.ts +52 -0
  37. package/dist/package/components/radio-group/radio-group.js +321 -0
  38. package/dist/package/internal/form.d.ts +7 -1
  39. package/dist/package/internal/form.js +110 -49
  40. package/dist/package/internal/solid-element.d.ts +2 -0
  41. package/dist/package/node_modules/.pnpm/{@shoelace-style_localize@3.1.0 → @shoelace-style_localize@3.1.2}/node_modules/@shoelace-style/localize/dist/index.js +1 -1
  42. package/dist/package/solid-components.d.ts +2 -0
  43. package/dist/package/solid-components.js +12 -8
  44. package/dist/package/styles/tailwind.css.js +1 -1
  45. package/dist/package/translations/en.js +1 -1
  46. package/dist/package/utilities/localize.js +1 -1
  47. package/dist/versioned-components/es/accordion-group.js +1 -1
  48. package/dist/versioned-components/es/accordion.js +1 -1
  49. package/dist/versioned-components/es/badge.js +1 -1
  50. package/dist/versioned-components/es/brandshape.js +1 -1
  51. package/dist/versioned-components/es/button.js +1 -1
  52. package/dist/versioned-components/es/carousel-item.js +1 -1
  53. package/dist/versioned-components/es/carousel.js +3 -3
  54. package/dist/versioned-components/es/divider.js +1 -1
  55. package/dist/versioned-components/es/drawer.js +1 -1
  56. package/dist/versioned-components/es/dropdown.js +1 -1
  57. package/dist/versioned-components/es/form.js +1 -0
  58. package/dist/versioned-components/es/icon.js +3 -3
  59. package/dist/versioned-components/es/if-defined.js +2 -2
  60. package/dist/versioned-components/es/include.js +1 -1
  61. package/dist/versioned-components/es/link.js +1 -1
  62. package/dist/versioned-components/es/lit-element.js +4 -4
  63. package/dist/versioned-components/es/navigation-item.js +2 -2
  64. package/dist/versioned-components/es/popup.js +1 -1
  65. package/dist/versioned-components/es/query-assigned-elements.js +6 -0
  66. package/dist/versioned-components/es/query.js +7 -2
  67. package/dist/versioned-components/es/radio-group.js +1 -0
  68. package/dist/versioned-components/es/radio.js +1 -0
  69. package/dist/versioned-components/es/solid-components2.js +1 -1
  70. package/dist/versioned-components/es/solid-element.js +2 -12
  71. package/dist/versioned-components/es/spinner.js +1 -1
  72. package/dist/versioned-components/es/state.js +1 -1
  73. package/dist/versioned-components/es/static.js +1 -1
  74. package/dist/versioned-components/es/tag.js +1 -1
  75. package/dist/versioned-components/es/teaser.js +1 -1
  76. package/dist/versioned-components/es/video.js +1 -1
  77. package/dist/versioned-package/_components/button-group/button-group.d.ts +19 -0
  78. package/dist/versioned-package/_components/button-group/button-group.js +76 -0
  79. package/dist/versioned-package/_components/button-group/button-group.styles.d.ts +2 -0
  80. package/dist/versioned-package/_components/button-group/button-group.styles.js +6 -0
  81. package/dist/versioned-package/components/accordion/accordion.d.ts +1 -1
  82. package/dist/versioned-package/components/accordion/accordion.js +2 -2
  83. package/dist/versioned-package/components/accordion-group/accordion-group.d.ts +1 -1
  84. package/dist/versioned-package/components/accordion-group/accordion-group.js +3 -3
  85. package/dist/versioned-package/components/badge/badge.d.ts +1 -1
  86. package/dist/versioned-package/components/badge/badge.js +1 -1
  87. package/dist/versioned-package/components/brandshape/brandshape.d.ts +1 -1
  88. package/dist/versioned-package/components/brandshape/brandshape.js +1 -1
  89. package/dist/versioned-package/components/button/button.d.ts +5 -1
  90. package/dist/versioned-package/components/button/button.js +29 -7
  91. package/dist/versioned-package/components/carousel/carousel.d.ts +1 -1
  92. package/dist/versioned-package/components/carousel/carousel.js +6 -6
  93. package/dist/versioned-package/components/carousel-item/carousel-item.d.ts +1 -1
  94. package/dist/versioned-package/components/carousel-item/carousel-item.js +1 -1
  95. package/dist/versioned-package/components/divider/divider.d.ts +1 -1
  96. package/dist/versioned-package/components/divider/divider.js +2 -2
  97. package/dist/versioned-package/components/drawer/drawer.d.ts +1 -1
  98. package/dist/versioned-package/components/drawer/drawer.js +2 -2
  99. package/dist/versioned-package/components/dropdown/dropdown.d.ts +1 -1
  100. package/dist/versioned-package/components/dropdown/dropdown.js +6 -6
  101. package/dist/versioned-package/components/icon/icon.d.ts +1 -1
  102. package/dist/versioned-package/components/icon/icon.js +1 -1
  103. package/dist/versioned-package/components/include/include.d.ts +1 -1
  104. package/dist/versioned-package/components/include/include.js +1 -1
  105. package/dist/versioned-package/components/link/link.d.ts +1 -1
  106. package/dist/versioned-package/components/link/link.js +2 -2
  107. package/dist/versioned-package/components/navigation-item/navigation-item.d.ts +1 -1
  108. package/dist/versioned-package/components/navigation-item/navigation-item.js +3 -3
  109. package/dist/versioned-package/components/popup/popup.d.ts +1 -1
  110. package/dist/versioned-package/components/popup/popup.js +1 -1
  111. package/dist/versioned-package/components/radio/radio.d.ts +27 -0
  112. package/dist/versioned-package/components/radio/radio.js +130 -0
  113. package/dist/versioned-package/components/radio-group/radio-group.d.ts +52 -0
  114. package/dist/versioned-package/components/radio-group/radio-group.js +321 -0
  115. package/dist/versioned-package/components/spinner/spinner.d.ts +1 -1
  116. package/dist/versioned-package/components/spinner/spinner.js +1 -1
  117. package/dist/versioned-package/components/tag/tag.d.ts +1 -1
  118. package/dist/versioned-package/components/tag/tag.js +2 -2
  119. package/dist/versioned-package/components/teaser/teaser.js +1 -1
  120. package/dist/versioned-package/components/video/video.d.ts +1 -1
  121. package/dist/versioned-package/components/video/video.js +2 -2
  122. package/dist/versioned-package/internal/form.d.ts +7 -1
  123. package/dist/versioned-package/internal/form.js +110 -49
  124. package/dist/versioned-package/internal/solid-element.d.ts +2 -0
  125. package/dist/versioned-package/node_modules/.pnpm/{@shoelace-style_localize@3.1.0 → @shoelace-style_localize@3.1.2}/node_modules/@shoelace-style/localize/dist/index.js +1 -1
  126. package/dist/versioned-package/solid-components.d.ts +2 -0
  127. package/dist/versioned-package/solid-components.js +12 -8
  128. package/dist/versioned-package/styles/tailwind.css.js +1 -1
  129. package/dist/versioned-package/translations/en.js +1 -1
  130. package/dist/versioned-package/utilities/localize.js +1 -1
  131. package/dist/versioned-styles/solid-styles.css +1 -1
  132. package/dist/vscode.html-custom-data.json +201 -21
  133. package/dist/web-types.json +910 -122
  134. package/package.json +51 -56
@@ -11,6 +11,6 @@ export default class SdInclude extends SolidElement {
11
11
  }
12
12
  declare global {
13
13
  interface HTMLElementTagNameMap {
14
- 'sd-1-19-0-include': SdInclude;
14
+ 'sd-1-21-0-include': SdInclude;
15
15
  }
16
16
  }
@@ -66,7 +66,7 @@ __decorateClass([
66
66
  watch("src")
67
67
  ], SdInclude.prototype, "handleSrcChange", 1);
68
68
  SdInclude = __decorateClass([
69
- customElement("sd-1-19-0-include")
69
+ customElement("sd-1-21-0-include")
70
70
  ], SdInclude);
71
71
  export {
72
72
  SdInclude as default
@@ -17,6 +17,6 @@ export default class SdLink extends SolidElement {
17
17
  }
18
18
  declare global {
19
19
  interface HTMLElementTagNameMap {
20
- 'sd-1-19-0-link': SdLink;
20
+ 'sd-1-21-0-link': SdLink;
21
21
  }
22
22
  }
@@ -77,7 +77,7 @@ let SdLink = class extends SolidElement {
77
77
  };
78
78
  SdLink.styles = [
79
79
  SolidElement.styles,
80
- css`::slotted(sd-1-19-0-icon){font-size:1.25em;margin-bottom:-.25em}:host([size=sm][standalone]) ::slotted(sd-1-19-0-icon){font-size:1rem}:host([size=lg][standalone]) ::slotted(sd-1-19-0-icon){font-size:1.5rem}`
80
+ css`::slotted(sd-1-21-0-icon){font-size:1.25em;margin-bottom:-.25em}:host([size=sm][standalone]) ::slotted(sd-1-21-0-icon){font-size:1rem}:host([size=lg][standalone]) ::slotted(sd-1-21-0-icon){font-size:1.5rem}`
81
81
  ];
82
82
  __decorateClass([
83
83
  query("a")
@@ -101,7 +101,7 @@ __decorateClass([
101
101
  property()
102
102
  ], SdLink.prototype, "download", 2);
103
103
  SdLink = __decorateClass([
104
- customElement("sd-1-19-0-link")
104
+ customElement("sd-1-21-0-link")
105
105
  ], SdLink);
106
106
  export {
107
107
  SdLink as default
@@ -26,6 +26,6 @@ export default class SdNavigationItem extends SolidElement {
26
26
  }
27
27
  declare global {
28
28
  interface HTMLElementTagNameMap {
29
- 'sd-1-19-0-navigation-item': SdNavigationItem;
29
+ 'sd-1-21-0-navigation-item': SdNavigationItem;
30
30
  }
31
31
  }
@@ -105,10 +105,10 @@ let SdNavigationItem = class extends SolidElement {
105
105
  isAccordion ? "grow" : "w-full",
106
106
  slots["description"] ? "pb-1" : horizontalPaddingBottom,
107
107
  this.calculatePaddingX()
108
- )}">${this.divider && this.vertical ? html`<sd-1-19-0-divider part="divider" class="${cx("w-full transition-all absolute -top-[1px] left-0", this.calculatePaddingX())}"></sd-1-19-0-divider>` : ""} <span class="inline-flex items-center flex-auto"><slot part="content" class="inline"></slot></span>${(this.chevron || slots["children"]) && this.vertical ? html`<sd-1-19-0-icon name="chevron-down" part="chevron" library="system" color="currentColor" class="${cx(
108
+ )}">${this.divider && this.vertical ? html`<sd-1-21-0-divider part="divider" class="${cx("w-full transition-all absolute -top-[1px] left-0", this.calculatePaddingX())}"></sd-1-21-0-divider>` : ""} <span class="inline-flex items-center flex-auto"><slot part="content" class="inline"></slot></span>${(this.chevron || slots["children"]) && this.vertical ? html`<sd-1-21-0-icon name="chevron-down" part="chevron" library="system" color="currentColor" class="${cx(
109
109
  "h-6 w-6 ml-2 transition-all",
110
110
  isAccordion ? this.open ? "rotate-180" : "rotate-0" : "rotate-[270deg]"
111
- )}"></sd-1-19-0-icon>` : ""} </span>${slots["description"] && this.vertical ? html`<slot name="description" part="description" class="${cx(
111
+ )}"></sd-1-21-0-icon>` : ""} </span>${slots["description"] && this.vertical ? html`<slot name="description" part="description" class="${cx(
112
112
  "inline-block text-sm text-left text-black",
113
113
  isAccordion ? "grow" : "w-full",
114
114
  horizontalPaddingBottom,
@@ -159,7 +159,7 @@ __decorateClass([
159
159
  property({ type: Boolean, reflect: true })
160
160
  ], SdNavigationItem.prototype, "open", 2);
161
161
  SdNavigationItem = __decorateClass([
162
- customElement("sd-1-19-0-navigation-item")
162
+ customElement("sd-1-21-0-navigation-item")
163
163
  ], SdNavigationItem);
164
164
  export {
165
165
  SdNavigationItem as default
@@ -37,6 +37,6 @@ export default class SdPopup extends SolidElement {
37
37
  }
38
38
  declare global {
39
39
  interface HTMLElementTagNameMap {
40
- 'sd-1-19-0-popup': SdPopup;
40
+ 'sd-1-21-0-popup': SdPopup;
41
41
  }
42
42
  }
@@ -312,7 +312,7 @@ __decorateClass([
312
312
  property({ attribute: "auto-size-padding", type: Number })
313
313
  ], SdPopup.prototype, "autoSizePadding", 2);
314
314
  SdPopup = __decorateClass([
315
- customElement("sd-1-19-0-popup")
315
+ customElement("sd-1-21-0-popup")
316
316
  ], SdPopup);
317
317
  export {
318
318
  SdPopup as default
@@ -0,0 +1,27 @@
1
+ import '../icon/icon';
2
+ import SolidElement from '../../internal/solid-element';
3
+ export default class SdRadio extends SolidElement {
4
+ checked: boolean;
5
+ protected hasFocus: boolean;
6
+ size: 'lg' | 'sm';
7
+ invalid: boolean;
8
+ disabled: boolean;
9
+ value: string;
10
+ connectedCallback(): void;
11
+ disconnectedCallback(): void;
12
+ private addEventListeners;
13
+ private removeEventListeners;
14
+ private handleBlur;
15
+ private handleClick;
16
+ private handleFocus;
17
+ private setInitialAttributes;
18
+ handleCheckedChange(): void;
19
+ handleDisabledChange(): void;
20
+ render(): import("lit-html").TemplateResult<1>;
21
+ static styles: import("lit").CSSResultGroup[];
22
+ }
23
+ declare global {
24
+ interface HTMLElementTagNameMap {
25
+ 'sd-1-21-0-radio': SdRadio;
26
+ }
27
+ }
@@ -0,0 +1,130 @@
1
+ import "../icon/icon.js";
2
+ import { css, html } from "lit";
3
+ import { customElement } from "../../internal/register-custom-element.js";
4
+ import { state, property } from "lit/decorators.js";
5
+ import { watch } from "../../internal/watch.js";
6
+ import cx from "classix";
7
+ import SolidElement from "../../internal/solid-element.js";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __decorateClass = (decorators, target, key, kind) => {
11
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
12
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
13
+ if (decorator = decorators[i])
14
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
15
+ if (kind && result)
16
+ __defProp(target, key, result);
17
+ return result;
18
+ };
19
+ let SdRadio = class extends SolidElement {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.checked = false;
23
+ this.hasFocus = false;
24
+ this.size = "lg";
25
+ this.invalid = false;
26
+ this.disabled = false;
27
+ }
28
+ connectedCallback() {
29
+ super.connectedCallback();
30
+ this.handleBlur = this.handleBlur.bind(this);
31
+ this.handleClick = this.handleClick.bind(this);
32
+ this.handleFocus = this.handleFocus.bind(this);
33
+ this.setInitialAttributes();
34
+ this.addEventListeners();
35
+ }
36
+ disconnectedCallback() {
37
+ this.removeEventListeners();
38
+ }
39
+ addEventListeners() {
40
+ this.addEventListener("blur", this.handleBlur);
41
+ this.addEventListener("click", this.handleClick);
42
+ this.addEventListener("focus", this.handleFocus);
43
+ }
44
+ removeEventListeners() {
45
+ this.removeEventListener("blur", this.handleBlur);
46
+ this.removeEventListener("click", this.handleClick);
47
+ this.removeEventListener("focus", this.handleFocus);
48
+ }
49
+ handleBlur() {
50
+ this.hasFocus = false;
51
+ this.emit("sd-blur");
52
+ }
53
+ handleClick() {
54
+ if (!this.disabled) {
55
+ this.checked = true;
56
+ }
57
+ }
58
+ handleFocus() {
59
+ this.hasFocus = true;
60
+ this.emit("sd-focus");
61
+ }
62
+ setInitialAttributes() {
63
+ this.setAttribute("role", "radio");
64
+ this.setAttribute("tabindex", "-1");
65
+ this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
66
+ }
67
+ handleCheckedChange() {
68
+ this.setAttribute("aria-checked", this.checked ? "true" : "false");
69
+ this.setAttribute("tabindex", this.checked ? "0" : "-1");
70
+ }
71
+ handleDisabledChange() {
72
+ this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
73
+ }
74
+ render() {
75
+ return html`<span part="base" class="${cx(
76
+ "sd-1-21-0-radio group inline-flex items-start items-center text-base leading-normal text-black cursor-pointer align-middle",
77
+ this.checked && "radio--checked",
78
+ this.disabled && "hover:cursor-not-allowed",
79
+ this.hasFocus && "radio--focused",
80
+ {
81
+ /* sizes, fonts */
82
+ sm: "small-size text-sm",
83
+ lg: "text-base"
84
+ }[this.size]
85
+ )}"><span part="${`${this.checked ? "control--checked" : "control--unchecked"}`}" class="${cx(
86
+ "flex-initial shrink-0 relative inline-flex items-center justify-center border rounded-full bg-white h-4 w-4",
87
+ this.disabled && "border-neutral-500" || this.invalid && "border-error hover:border-error-400 group-hover:border-error-400" || this.checked && "border-accent hover:border-accent-550 group-hover:border-accent-550" || "border-neutral-800 hover:bg-neutral-200 group-hover:bg-neutral-200"
88
+ )}">${this.checked ? html`<span part="checked" class="${cx(
89
+ "rounded-full inline-flex text-white border bg-accent h-2.5 w-2.5",
90
+ this.disabled && "bg-neutral-500" || this.invalid && "bg-error hover:bg-error-400 group-hover:bg-error-400" || this.checked && "bg-accent hover:bg-accent-550 group-hover:bg-accent-550" || "bg-neutral-800"
91
+ )}"></span>` : ""}</span><slot part="label" class="${cx(
92
+ "label ml-2 select-none inline-block",
93
+ this.disabled && "text-neutral-500" || this.invalid && "text-error" || "text-black"
94
+ )}"></slot></span>`;
95
+ }
96
+ };
97
+ SdRadio.styles = [
98
+ SolidElement.styles,
99
+ css`:host{display:block}:host(:focus-visible){outline:0}:host(:focus-visible) [part=control--checked],:host(:focus-visible) [part=control--unchecked]{outline:2px solid #00358e;outline-offset:2px}`
100
+ ];
101
+ __decorateClass([
102
+ state()
103
+ ], SdRadio.prototype, "checked", 2);
104
+ __decorateClass([
105
+ state()
106
+ ], SdRadio.prototype, "hasFocus", 2);
107
+ __decorateClass([
108
+ property({ reflect: true })
109
+ ], SdRadio.prototype, "size", 2);
110
+ __decorateClass([
111
+ property({ type: Boolean, reflect: true })
112
+ ], SdRadio.prototype, "invalid", 2);
113
+ __decorateClass([
114
+ property({ type: Boolean, reflect: true })
115
+ ], SdRadio.prototype, "disabled", 2);
116
+ __decorateClass([
117
+ property()
118
+ ], SdRadio.prototype, "value", 2);
119
+ __decorateClass([
120
+ watch("checked")
121
+ ], SdRadio.prototype, "handleCheckedChange", 1);
122
+ __decorateClass([
123
+ watch("disabled", { waitUntilFirstUpdate: true })
124
+ ], SdRadio.prototype, "handleDisabledChange", 1);
125
+ SdRadio = __decorateClass([
126
+ customElement("sd-1-21-0-radio")
127
+ ], SdRadio);
128
+ export {
129
+ SdRadio as default
130
+ };
@@ -0,0 +1,52 @@
1
+ import { FormControlController } from '../../internal/form';
2
+ import SdButtonGroup from '../../_components/button-group/button-group';
3
+ import SolidElement from '../../internal/solid-element';
4
+ import type { SolidFormControl } from '../../internal/solid-element';
5
+ export default class SdRadioGroup extends SolidElement implements SolidFormControl {
6
+ static dependencies: {
7
+ 'sd-1-21-0-button-group': typeof SdButtonGroup;
8
+ };
9
+ protected readonly formControlController: FormControlController;
10
+ private readonly hasSlotController;
11
+ private customValidityMessage;
12
+ private validationTimeout;
13
+ defaultSlot: HTMLSlotElement;
14
+ validationInput: HTMLInputElement;
15
+ private hasButtonGroup;
16
+ defaultValue: string;
17
+ private invalid;
18
+ private errorText;
19
+ label: string;
20
+ name: string;
21
+ value: string;
22
+ size: 'lg' | 'sm';
23
+ form: string;
24
+ required: boolean;
25
+ orientation: 'horizontal' | 'vertical';
26
+ get validity(): ValidityState;
27
+ get validationMessage(): string;
28
+ connectedCallback(): void;
29
+ firstUpdated(): void;
30
+ private getAllRadios;
31
+ private handleRadioClick;
32
+ private handleKeyDown;
33
+ private handleLabelClick;
34
+ private handleInvalid;
35
+ private syncRadioElements;
36
+ private syncRadios;
37
+ private updateCheckedRadio;
38
+ handleSizeChange(): void;
39
+ handleInvalidChange(): void;
40
+ handleValueChange(): void;
41
+ checkValidity(): boolean;
42
+ getForm(): HTMLFormElement | null;
43
+ reportValidity(): boolean;
44
+ setCustomValidity(message?: string): void;
45
+ render(): import("lit-html").TemplateResult<1>;
46
+ static styles: import("lit").CSSResultGroup[];
47
+ }
48
+ declare global {
49
+ interface HTMLElementTagNameMap {
50
+ 'sd-1-21-0-radio-group': SdRadioGroup;
51
+ }
52
+ }
@@ -0,0 +1,321 @@
1
+ import { css, html } from "lit";
2
+ import { customElement } from "../../internal/register-custom-element.js";
3
+ import { FormControlController, customErrorValidityState, valueMissingValidityState, validValidityState } from "../../internal/form.js";
4
+ import { HasSlotController } from "../../internal/slot.js";
5
+ import { query, state, property } from "lit/decorators.js";
6
+ import { watch } from "../../internal/watch.js";
7
+ import componentStyles from "../../styles/component.styles.js";
8
+ import cx from "classix";
9
+ import SdButtonGroup from "../../_components/button-group/button-group.js";
10
+ import SolidElement from "../../internal/solid-element.js";
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __decorateClass = (decorators, target, key, kind) => {
14
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
15
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
16
+ if (decorator = decorators[i])
17
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
18
+ if (kind && result)
19
+ __defProp(target, key, result);
20
+ return result;
21
+ };
22
+ let SdRadioGroup = class extends SolidElement {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.formControlController = new FormControlController(this);
26
+ this.hasSlotController = new HasSlotController(this, "label", "error-text");
27
+ this.customValidityMessage = "";
28
+ this.hasButtonGroup = false;
29
+ this.defaultValue = "";
30
+ this.invalid = false;
31
+ this.errorText = "";
32
+ this.label = "";
33
+ this.name = "option";
34
+ this.value = "";
35
+ this.size = "lg";
36
+ this.form = "";
37
+ this.required = false;
38
+ this.orientation = "vertical";
39
+ }
40
+ /** Gets the validity state object */
41
+ get validity() {
42
+ const isRequiredAndEmpty = this.required && !this.value;
43
+ const hasCustomValidityMessage = this.customValidityMessage !== "";
44
+ if (hasCustomValidityMessage) {
45
+ this.invalid = true;
46
+ return customErrorValidityState;
47
+ } else if (isRequiredAndEmpty) {
48
+ this.invalid = true;
49
+ return valueMissingValidityState;
50
+ }
51
+ this.invalid = false;
52
+ return validValidityState;
53
+ }
54
+ /** Gets the validation message */
55
+ get validationMessage() {
56
+ const isRequiredAndEmpty = this.required && !this.value;
57
+ const hasCustomValidityMessage = this.customValidityMessage !== "";
58
+ if (hasCustomValidityMessage) {
59
+ console.log("this.customValidityMessage", this.customValidityMessage);
60
+ return this.customValidityMessage;
61
+ } else if (isRequiredAndEmpty) {
62
+ console.log("this.validationInput.validationMessage", this.validationInput);
63
+ return this.validationInput.validationMessage;
64
+ }
65
+ return "";
66
+ }
67
+ connectedCallback() {
68
+ super.connectedCallback();
69
+ this.defaultValue = this.value;
70
+ }
71
+ firstUpdated() {
72
+ this.formControlController.updateValidity();
73
+ }
74
+ getAllRadios() {
75
+ return [...this.querySelectorAll("sd-1-21-0-radio, sd-1-21-0-radio-button")];
76
+ }
77
+ handleRadioClick(event) {
78
+ const target = event.target.closest("sd-1-21-0-radio, sd-1-21-0-radio-button");
79
+ const radios = this.getAllRadios();
80
+ const oldValue = this.value;
81
+ if (target.disabled) {
82
+ return;
83
+ }
84
+ this.value = target.value;
85
+ radios.forEach((radio) => radio.checked = radio === target);
86
+ if (this.value !== oldValue) {
87
+ this.emit("sd-change");
88
+ this.emit("sd-input");
89
+ }
90
+ }
91
+ handleKeyDown(event) {
92
+ if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", " "].includes(event.key)) {
93
+ return;
94
+ }
95
+ const radios = this.getAllRadios().filter((radio) => !radio.disabled);
96
+ const checkedRadio = radios.find((radio) => radio.checked) ?? radios[0];
97
+ const incr = event.key === " " ? 0 : ["ArrowUp", "ArrowLeft"].includes(event.key) ? -1 : 1;
98
+ const oldValue = this.value;
99
+ let index = radios.indexOf(checkedRadio) + incr;
100
+ if (index < 0) {
101
+ index = radios.length - 1;
102
+ }
103
+ if (index > radios.length - 1) {
104
+ index = 0;
105
+ }
106
+ this.getAllRadios().forEach((radio) => {
107
+ radio.checked = false;
108
+ if (!this.hasButtonGroup) {
109
+ radio.tabIndex = -1;
110
+ }
111
+ });
112
+ this.value = radios[index].value;
113
+ radios[index].checked = true;
114
+ if (!this.hasButtonGroup) {
115
+ radios[index].tabIndex = 0;
116
+ radios[index].focus();
117
+ } else {
118
+ radios[index].shadowRoot.querySelector("button").focus();
119
+ }
120
+ if (this.value !== oldValue) {
121
+ this.emit("sd-change");
122
+ this.emit("sd-input");
123
+ }
124
+ event.preventDefault();
125
+ }
126
+ handleLabelClick() {
127
+ const radios = this.getAllRadios();
128
+ const checked = radios.find((radio) => radio.checked);
129
+ const radioToFocus = checked || radios[0];
130
+ if (radioToFocus) {
131
+ radioToFocus.focus();
132
+ }
133
+ }
134
+ handleInvalid(event) {
135
+ this.formControlController.setValidity(false);
136
+ this.formControlController.emitInvalidEvent(event);
137
+ }
138
+ async syncRadioElements() {
139
+ var _a, _b;
140
+ const radios = this.getAllRadios();
141
+ await Promise.all(
142
+ // Sync the checked state and size
143
+ radios.map(async (radio) => {
144
+ await radio.updateComplete;
145
+ radio.checked = radio.value === this.value;
146
+ radio.size = this.size;
147
+ radio.invalid = this.invalid;
148
+ })
149
+ );
150
+ this.hasButtonGroup = radios.some((radio) => radio.tagName.toLowerCase() === "sd-1-21-0-radio-button");
151
+ if (!radios.some((radio) => radio.checked)) {
152
+ if (this.hasButtonGroup) {
153
+ const buttonRadio = (_a = radios[0].shadowRoot) == null ? void 0 : _a.querySelector("button");
154
+ if (buttonRadio) {
155
+ buttonRadio.tabIndex = 0;
156
+ }
157
+ } else {
158
+ radios[0].tabIndex = 0;
159
+ }
160
+ }
161
+ if (this.hasButtonGroup) {
162
+ const buttonGroup = (_b = this.shadowRoot) == null ? void 0 : _b.querySelector("sd-1-21-0-button-group");
163
+ if (buttonGroup) {
164
+ buttonGroup.disableRole = true;
165
+ }
166
+ }
167
+ }
168
+ syncRadios() {
169
+ if (customElements.get("sd-1-21-0-radio") && customElements.get("sd-1-21-0-radio-button")) {
170
+ this.syncRadioElements();
171
+ return;
172
+ }
173
+ if (customElements.get("sd-1-21-0-radio")) {
174
+ this.syncRadioElements();
175
+ } else {
176
+ customElements.whenDefined("sd-1-21-0-radio").then(() => this.syncRadios());
177
+ }
178
+ if (customElements.get("sd-1-21-0-radio-button")) {
179
+ this.syncRadioElements();
180
+ } else {
181
+ customElements.whenDefined("sd-1-21-0-radio-button").then(() => this.syncRadios());
182
+ }
183
+ }
184
+ updateCheckedRadio() {
185
+ const radios = this.getAllRadios();
186
+ radios.forEach((radio) => radio.checked = radio.value === this.value);
187
+ this.formControlController.setValidity(this.validity.valid);
188
+ }
189
+ handleSizeChange() {
190
+ this.syncRadios();
191
+ }
192
+ handleInvalidChange() {
193
+ this.syncRadios();
194
+ }
195
+ handleValueChange() {
196
+ if (this.hasUpdated) {
197
+ this.updateCheckedRadio();
198
+ this.reportValidity();
199
+ }
200
+ }
201
+ /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */
202
+ checkValidity() {
203
+ const isRequiredAndEmpty = this.required && !this.value;
204
+ const hasCustomValidityMessage = this.customValidityMessage !== "";
205
+ if (isRequiredAndEmpty || hasCustomValidityMessage) {
206
+ this.formControlController.emitInvalidEvent();
207
+ return false;
208
+ }
209
+ return true;
210
+ }
211
+ /** Gets the associated form, if one exists. */
212
+ getForm() {
213
+ return this.formControlController.getForm();
214
+ }
215
+ /** Checks for validity and shows the browser's validation message if the control is invalid. */
216
+ // TODO: https://github.com/solid-design-system/solid/issues/501
217
+ reportValidity() {
218
+ const isValid = this.validity.valid;
219
+ this.errorText = this.customValidityMessage || isValid ? "" : this.validationInput.validationMessage;
220
+ this.formControlController.setValidity(isValid);
221
+ this.validationInput.hidden = true;
222
+ clearTimeout(this.validationTimeout);
223
+ if (!isValid) {
224
+ this.validationInput.hidden = false;
225
+ this.validationInput.reportValidity();
226
+ this.validationTimeout = setTimeout(() => this.validationInput.hidden = true, 1e4);
227
+ }
228
+ return isValid;
229
+ }
230
+ /** Sets a custom validation message. Pass an empty string to restore validity. */
231
+ setCustomValidity(message = "") {
232
+ this.customValidityMessage = message;
233
+ this.errorText = message;
234
+ this.validationInput.setCustomValidity(message);
235
+ this.formControlController.updateValidity();
236
+ }
237
+ render() {
238
+ const hasLabelSlot = this.hasSlotController.test("label");
239
+ const hasErrorTextSlot = this.hasSlotController.test("error-text");
240
+ const hasLabel = this.label ? true : !!hasLabelSlot;
241
+ const hasErrorText = this.errorText ? true : !!hasErrorTextSlot;
242
+ const defaultSlot = html`<slot @slotchange="${this.syncRadios}" @click="${this.handleRadioClick}" @keydown="${this.handleKeyDown}"></slot>`;
243
+ return html`<fieldset part="form-control" class="${cx(
244
+ "form-control form-control--radio-group border-0 p-0 m-0",
245
+ hasLabel && "form-control--has-label",
246
+ hasErrorText && "text-error",
247
+ {
248
+ /* sizes, fonts */
249
+ sm: "text-sm",
250
+ lg: "text-base"
251
+ }[this.size]
252
+ )}" role="radiogroup" aria-labelledby="label" aria-errormessage="error-text"><label part="form-control-label" id="label" class="form-control__label mb-2 hidden p-0 font-bold leading-normal text-black" aria-hidden="${!hasLabel}" @click="${this.handleLabelClick}"><slot name="label">${this.label}</slot></label><div part="form-control-input" class="${cx(
253
+ "form-control-input flex",
254
+ this.invalid && "form-control-input--invalid text-error",
255
+ {
256
+ vertical: "form-control-input--vertical flex-col",
257
+ horizontal: "form-control-input--horizontal flex-row"
258
+ }[this.orientation]
259
+ )}"><div class="sr-only"><div id="error-message" aria-live="assertive">${this.errorText}</div><label class="radio-group__validation"><input type="text" class="radio-group__validation-input" ?required="${this.required}" tabindex="-1" hidden @invalid="${this.handleInvalid}"></label></div>${defaultSlot}</div></fieldset>`;
260
+ }
261
+ };
262
+ SdRadioGroup.dependencies = { "sd-1-21-0-button-group": SdButtonGroup };
263
+ SdRadioGroup.styles = [
264
+ componentStyles,
265
+ SolidElement.styles,
266
+ css`:host{display:block}.form-control-input--vertical ::slotted(sd-1-21-0-radio){margin-bottom:8px;display:flex}.form-control-input--vertical ::slotted(sd-1-21-0-radio:last-of-type){margin-bottom:0}.form-control-input--horizontal ::slotted(sd-1-21-0-radio){margin-right:24px}.form-control-input--horizontal ::slotted(sd-1-21-0-radio:last-of-type){margin-right:0}.form-control--has-label .form-control__label{display:flex}:host([required]) .form-control--has-label .form-control__label::after{content:'*';margin-left:2px}`
267
+ ];
268
+ __decorateClass([
269
+ query("slot:not([name])")
270
+ ], SdRadioGroup.prototype, "defaultSlot", 2);
271
+ __decorateClass([
272
+ query(".radio-group__validation-input")
273
+ ], SdRadioGroup.prototype, "validationInput", 2);
274
+ __decorateClass([
275
+ state()
276
+ ], SdRadioGroup.prototype, "hasButtonGroup", 2);
277
+ __decorateClass([
278
+ state()
279
+ ], SdRadioGroup.prototype, "defaultValue", 2);
280
+ __decorateClass([
281
+ state()
282
+ ], SdRadioGroup.prototype, "invalid", 2);
283
+ __decorateClass([
284
+ state()
285
+ ], SdRadioGroup.prototype, "errorText", 2);
286
+ __decorateClass([
287
+ property()
288
+ ], SdRadioGroup.prototype, "label", 2);
289
+ __decorateClass([
290
+ property()
291
+ ], SdRadioGroup.prototype, "name", 2);
292
+ __decorateClass([
293
+ property({ reflect: true })
294
+ ], SdRadioGroup.prototype, "value", 2);
295
+ __decorateClass([
296
+ property({ reflect: true })
297
+ ], SdRadioGroup.prototype, "size", 2);
298
+ __decorateClass([
299
+ property({ reflect: true })
300
+ ], SdRadioGroup.prototype, "form", 2);
301
+ __decorateClass([
302
+ property({ type: Boolean, reflect: true })
303
+ ], SdRadioGroup.prototype, "required", 2);
304
+ __decorateClass([
305
+ property({ reflect: true })
306
+ ], SdRadioGroup.prototype, "orientation", 2);
307
+ __decorateClass([
308
+ watch("size", { waitUntilFirstUpdate: true })
309
+ ], SdRadioGroup.prototype, "handleSizeChange", 1);
310
+ __decorateClass([
311
+ watch("invalid", { waitUntilFirstUpdate: true })
312
+ ], SdRadioGroup.prototype, "handleInvalidChange", 1);
313
+ __decorateClass([
314
+ watch("value")
315
+ ], SdRadioGroup.prototype, "handleValueChange", 1);
316
+ SdRadioGroup = __decorateClass([
317
+ customElement("sd-1-21-0-radio-group")
318
+ ], SdRadioGroup);
319
+ export {
320
+ SdRadioGroup as default
321
+ };
@@ -7,6 +7,6 @@ export default class SdSpinner extends SolidElement {
7
7
  }
8
8
  declare global {
9
9
  interface HTMLElementTagNameMap {
10
- 'sd-1-19-0-spinner': SdSpinner;
10
+ 'sd-1-21-0-spinner': SdSpinner;
11
11
  }
12
12
  }
@@ -40,7 +40,7 @@ __decorateClass([
40
40
  property({ reflect: true })
41
41
  ], SdSpinner.prototype, "color", 2);
42
42
  SdSpinner = __decorateClass([
43
- customElement("sd-1-19-0-spinner")
43
+ customElement("sd-1-21-0-spinner")
44
44
  ], SdSpinner);
45
45
  export {
46
46
  SdSpinner as default
@@ -19,6 +19,6 @@ export default class SdTag extends SolidElement {
19
19
  }
20
20
  declare global {
21
21
  interface HTMLElementTagNameMap {
22
- 'sd-1-19-0-tag': SdTag;
22
+ 'sd-1-21-0-tag': SdTag;
23
23
  }
24
24
  }
@@ -72,7 +72,7 @@ let SdTag = class extends SolidElement {
72
72
  lg: "text-base",
73
73
  sm: "text-[12px]"
74
74
  }[this.size]
75
- )}"><sd-1-19-0-icon library="system" name="close" label="remove"></sd-1-19-0-icon></slot></${tag}>`;
75
+ )}"><sd-1-21-0-icon library="system" name="close" label="remove"></sd-1-21-0-icon></slot></${tag}>`;
76
76
  }
77
77
  };
78
78
  SdTag.styles = [
@@ -104,7 +104,7 @@ __decorateClass([
104
104
  property()
105
105
  ], SdTag.prototype, "download", 2);
106
106
  SdTag = __decorateClass([
107
- customElement("sd-1-19-0-tag")
107
+ customElement("sd-1-21-0-tag")
108
108
  ], SdTag);
109
109
  export {
110
110
  SdTag as default