tyrell-components 1.0.0-RC14 → 1.0.0-RC16

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 (287) hide show
  1. package/README.md +53 -53
  2. package/css/tyrell-theme.css +32 -4
  3. package/css/tyrell.css +10 -15
  4. package/dist/tyrell-colors-static.css +1 -316
  5. package/dist/tyrell-theme.css +1 -1443
  6. package/dist/tyrell.css +1 -1390
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.d.ts +14 -0
  9. package/lib/base/ty-component.d.ts.map +1 -0
  10. package/lib/base/ty-component.js +223 -196
  11. package/lib/base/ty-component.js.map +1 -0
  12. package/lib/components/button.d.ts +1 -1
  13. package/lib/components/button.d.ts.map +1 -0
  14. package/lib/components/button.js +267 -259
  15. package/lib/components/button.js.map +1 -0
  16. package/lib/components/calendar-month.d.ts +2 -2
  17. package/lib/components/calendar-month.d.ts.map +1 -0
  18. package/lib/components/calendar-month.js +440 -416
  19. package/lib/components/calendar-month.js.map +1 -0
  20. package/lib/components/calendar-navigation.d.ts +11 -0
  21. package/lib/components/calendar-navigation.d.ts.map +1 -0
  22. package/lib/components/calendar-navigation.js +272 -261
  23. package/lib/components/calendar-navigation.js.map +1 -0
  24. package/lib/components/calendar.d.ts +31 -3
  25. package/lib/components/calendar.d.ts.map +1 -0
  26. package/lib/components/calendar.js +785 -603
  27. package/lib/components/calendar.js.map +1 -0
  28. package/lib/components/checkbox.d.ts +1 -1
  29. package/lib/components/checkbox.d.ts.map +1 -0
  30. package/lib/components/checkbox.js +273 -272
  31. package/lib/components/checkbox.js.map +1 -0
  32. package/lib/components/copy.d.ts +1 -1
  33. package/lib/components/copy.d.ts.map +1 -0
  34. package/lib/components/copy.js +287 -278
  35. package/lib/components/copy.js.map +1 -0
  36. package/lib/components/date-picker.d.ts +16 -10
  37. package/lib/components/date-picker.d.ts.map +1 -0
  38. package/lib/components/date-picker.js +1068 -1122
  39. package/lib/components/date-picker.js.map +1 -0
  40. package/lib/components/dropdown.d.ts +403 -0
  41. package/lib/components/dropdown.d.ts.map +1 -0
  42. package/lib/components/dropdown.js +1315 -0
  43. package/lib/components/dropdown.js.map +1 -0
  44. package/lib/components/file-upload.d.ts +4 -0
  45. package/lib/components/file-upload.js +418 -404
  46. package/lib/components/icon.d.ts.map +1 -0
  47. package/lib/components/icon.js +141 -141
  48. package/lib/components/icon.js.map +1 -0
  49. package/lib/components/input.d.ts +1 -1
  50. package/lib/components/input.d.ts.map +1 -0
  51. package/lib/components/input.js +593 -596
  52. package/lib/components/input.js.map +1 -0
  53. package/lib/components/modal.d.ts +2 -8
  54. package/lib/components/modal.d.ts.map +1 -0
  55. package/lib/components/modal.js +309 -319
  56. package/lib/components/modal.js.map +1 -0
  57. package/lib/components/multiselect.d.ts +389 -0
  58. package/lib/components/multiselect.d.ts.map +1 -0
  59. package/lib/components/multiselect.js +1301 -0
  60. package/lib/components/multiselect.js.map +1 -0
  61. package/lib/components/option.d.ts.map +1 -0
  62. package/lib/components/option.js +167 -167
  63. package/lib/components/option.js.map +1 -0
  64. package/lib/components/popup.d.ts.map +1 -0
  65. package/lib/components/popup.js +236 -233
  66. package/lib/components/popup.js.map +1 -0
  67. package/lib/components/radio.d.ts +17 -2
  68. package/lib/components/radio.js +437 -406
  69. package/lib/components/resize-observer.d.ts.map +1 -0
  70. package/lib/components/resize-observer.js +67 -67
  71. package/lib/components/resize-observer.js.map +1 -0
  72. package/lib/components/scroll-container.d.ts +3 -2
  73. package/lib/components/scroll-container.d.ts.map +1 -0
  74. package/lib/components/scroll-container.js +289 -294
  75. package/lib/components/scroll-container.js.map +1 -0
  76. package/lib/components/select.d.ts +85 -18
  77. package/lib/components/select.js +1647 -1529
  78. package/lib/components/selected-tags.d.ts +1 -1
  79. package/lib/components/selected-tags.js +188 -182
  80. package/lib/components/step.d.ts.map +1 -0
  81. package/lib/components/step.js +62 -62
  82. package/lib/components/step.js.map +1 -0
  83. package/lib/components/switch.d.ts +1 -1
  84. package/lib/components/switch.js +214 -213
  85. package/lib/components/tab.d.ts +49 -1
  86. package/lib/components/tab.d.ts.map +1 -0
  87. package/lib/components/tab.js +203 -62
  88. package/lib/components/tab.js.map +1 -0
  89. package/lib/components/tabs.d.ts +15 -2
  90. package/lib/components/tabs.d.ts.map +1 -0
  91. package/lib/components/tabs.js +576 -496
  92. package/lib/components/tabs.js.map +1 -0
  93. package/lib/components/tag.d.ts +5 -8
  94. package/lib/components/tag.d.ts.map +1 -0
  95. package/lib/components/tag.js +235 -235
  96. package/lib/components/tag.js.map +1 -0
  97. package/lib/components/textarea.d.ts +5 -4
  98. package/lib/components/textarea.d.ts.map +1 -0
  99. package/lib/components/textarea.js +458 -456
  100. package/lib/components/textarea.js.map +1 -0
  101. package/lib/components/tooltip.d.ts +4 -3
  102. package/lib/components/tooltip.d.ts.map +1 -0
  103. package/lib/components/tooltip.js +293 -283
  104. package/lib/components/tooltip.js.map +1 -0
  105. package/lib/components/wizard.d.ts +5 -4
  106. package/lib/components/wizard.d.ts.map +1 -0
  107. package/lib/components/wizard.js +359 -395
  108. package/lib/components/wizard.js.map +1 -0
  109. package/lib/icons/fontawesome/brands.d.ts.map +1 -0
  110. package/lib/icons/fontawesome/brands.js.map +1 -0
  111. package/lib/icons/fontawesome/regular.d.ts.map +1 -0
  112. package/lib/icons/fontawesome/regular.js.map +1 -0
  113. package/lib/icons/fontawesome/solid.d.ts.map +1 -0
  114. package/lib/icons/fontawesome/solid.js.map +1 -0
  115. package/lib/icons/heroicons/micro.d.ts.map +1 -0
  116. package/lib/icons/heroicons/micro.js +392 -392
  117. package/lib/icons/heroicons/micro.js.map +1 -0
  118. package/lib/icons/heroicons/mini.d.ts.map +1 -0
  119. package/lib/icons/heroicons/mini.js +382 -382
  120. package/lib/icons/heroicons/mini.js.map +1 -0
  121. package/lib/icons/heroicons/outline.d.ts.map +1 -0
  122. package/lib/icons/heroicons/outline.js +337 -337
  123. package/lib/icons/heroicons/outline.js.map +1 -0
  124. package/lib/icons/heroicons/solid.d.ts.map +1 -0
  125. package/lib/icons/heroicons/solid.js +407 -407
  126. package/lib/icons/heroicons/solid.js.map +1 -0
  127. package/lib/icons/lucide.d.ts.map +1 -0
  128. package/lib/icons/lucide.js +22843 -22843
  129. package/lib/icons/lucide.js.map +1 -0
  130. package/lib/icons/material/filled.d.ts.map +1 -0
  131. package/lib/icons/material/filled.js +9653 -9653
  132. package/lib/icons/material/filled.js.map +1 -0
  133. package/lib/icons/material/outlined.d.ts.map +1 -0
  134. package/lib/icons/material/outlined.js +10271 -10271
  135. package/lib/icons/material/outlined.js.map +1 -0
  136. package/lib/icons/material/round.d.ts.map +1 -0
  137. package/lib/icons/material/round.js +10495 -10495
  138. package/lib/icons/material/round.js.map +1 -0
  139. package/lib/icons/material/sharp.d.ts.map +1 -0
  140. package/lib/icons/material/sharp.js +9905 -9905
  141. package/lib/icons/material/sharp.js.map +1 -0
  142. package/lib/icons/material/two-tone.d.ts.map +1 -0
  143. package/lib/icons/material/two-tone.js +12792 -12792
  144. package/lib/icons/material/two-tone.js.map +1 -0
  145. package/lib/index.d.ts +1 -1
  146. package/lib/index.d.ts.map +1 -0
  147. package/lib/index.js +21 -21
  148. package/lib/index.js.map +1 -0
  149. package/lib/styles/button.d.ts.map +1 -0
  150. package/lib/styles/button.js +200 -302
  151. package/lib/styles/button.js.map +1 -0
  152. package/lib/styles/calendar-month.d.ts +3 -0
  153. package/lib/styles/calendar-month.d.ts.map +1 -0
  154. package/lib/styles/calendar-month.js +141 -185
  155. package/lib/styles/calendar-month.js.map +1 -0
  156. package/lib/styles/calendar-navigation.d.ts +1 -1
  157. package/lib/styles/calendar-navigation.d.ts.map +1 -0
  158. package/lib/styles/calendar-navigation.js +100 -86
  159. package/lib/styles/calendar-navigation.js.map +1 -0
  160. package/lib/styles/calendar.d.ts +3 -2
  161. package/lib/styles/calendar.d.ts.map +1 -0
  162. package/lib/styles/calendar.js +83 -9
  163. package/lib/styles/calendar.js.map +1 -0
  164. package/lib/styles/checkbox.js +62 -77
  165. package/lib/styles/copy.d.ts.map +1 -0
  166. package/lib/styles/copy.js +71 -91
  167. package/lib/styles/copy.js.map +1 -0
  168. package/lib/styles/custom-scrollbar.js +80 -100
  169. package/lib/styles/date-picker.d.ts.map +1 -0
  170. package/lib/styles/date-picker.js +295 -335
  171. package/lib/styles/date-picker.js.map +1 -0
  172. package/lib/styles/dropdown.d.ts +12 -0
  173. package/lib/styles/dropdown.d.ts.map +1 -0
  174. package/lib/styles/dropdown.js +725 -0
  175. package/lib/styles/dropdown.js.map +1 -0
  176. package/lib/styles/field-size.d.ts +6 -0
  177. package/lib/styles/field-size.js +91 -0
  178. package/lib/styles/file-upload.js +139 -169
  179. package/lib/styles/icon.d.ts.map +1 -0
  180. package/lib/styles/icon.js +92 -156
  181. package/lib/styles/icon.js.map +1 -0
  182. package/lib/styles/input.d.ts.map +1 -0
  183. package/lib/styles/input.js +125 -241
  184. package/lib/styles/input.js.map +1 -0
  185. package/lib/styles/modal.d.ts.map +1 -0
  186. package/lib/styles/modal.js +67 -102
  187. package/lib/styles/modal.js.map +1 -0
  188. package/lib/styles/multiselect.d.ts +6 -0
  189. package/lib/styles/multiselect.d.ts.map +1 -0
  190. package/lib/styles/multiselect.js +568 -0
  191. package/lib/styles/multiselect.js.map +1 -0
  192. package/lib/styles/option.d.ts +1 -1
  193. package/lib/styles/option.d.ts.map +1 -0
  194. package/lib/styles/option.js +47 -67
  195. package/lib/styles/option.js.map +1 -0
  196. package/lib/styles/popup.d.ts +1 -1
  197. package/lib/styles/popup.d.ts.map +1 -0
  198. package/lib/styles/popup.js +37 -65
  199. package/lib/styles/popup.js.map +1 -0
  200. package/lib/styles/radio.js +75 -96
  201. package/lib/styles/resize-observer.d.ts.map +1 -0
  202. package/lib/styles/resize-observer.js +2 -5
  203. package/lib/styles/resize-observer.js.map +1 -0
  204. package/lib/styles/scroll-container.d.ts +1 -1
  205. package/lib/styles/scroll-container.d.ts.map +1 -0
  206. package/lib/styles/scroll-container.js +101 -131
  207. package/lib/styles/scroll-container.js.map +1 -0
  208. package/lib/styles/select-base.js +596 -773
  209. package/lib/styles/select.d.ts +1 -1
  210. package/lib/styles/select.js +146 -228
  211. package/lib/styles/step.d.ts +1 -1
  212. package/lib/styles/step.d.ts.map +1 -0
  213. package/lib/styles/step.js +15 -30
  214. package/lib/styles/step.js.map +1 -0
  215. package/lib/styles/switch.js +37 -55
  216. package/lib/styles/tab.d.ts +1 -1
  217. package/lib/styles/tab.d.ts.map +1 -0
  218. package/lib/styles/tab.js +86 -29
  219. package/lib/styles/tab.js.map +1 -0
  220. package/lib/styles/tabs.d.ts +1 -1
  221. package/lib/styles/tabs.d.ts.map +1 -0
  222. package/lib/styles/tabs.js +190 -180
  223. package/lib/styles/tabs.js.map +1 -0
  224. package/lib/styles/tag.d.ts.map +1 -0
  225. package/lib/styles/tag.js +137 -191
  226. package/lib/styles/tag.js.map +1 -0
  227. package/lib/styles/textarea.d.ts +1 -1
  228. package/lib/styles/textarea.d.ts.map +1 -0
  229. package/lib/styles/textarea.js +205 -271
  230. package/lib/styles/textarea.js.map +1 -0
  231. package/lib/styles/tooltip.d.ts.map +1 -0
  232. package/lib/styles/tooltip.js +3 -3
  233. package/lib/styles/tooltip.js.map +1 -0
  234. package/lib/styles/wizard.d.ts +9 -5
  235. package/lib/styles/wizard.d.ts.map +1 -0
  236. package/lib/styles/wizard.js +301 -245
  237. package/lib/styles/wizard.js.map +1 -0
  238. package/lib/types/common.d.ts +4 -2
  239. package/lib/types/common.d.ts.map +1 -0
  240. package/lib/types/common.js +6 -5
  241. package/lib/types/common.js.map +1 -0
  242. package/lib/utils/calendar-utils.d.ts.map +1 -0
  243. package/lib/utils/calendar-utils.js +100 -100
  244. package/lib/utils/calendar-utils.js.map +1 -0
  245. package/lib/utils/custom-scrollbar.js +272 -272
  246. package/lib/utils/flavor-sheet.js +14 -14
  247. package/lib/utils/icon-registry.d.ts.map +1 -0
  248. package/lib/utils/icon-registry.js +127 -127
  249. package/lib/utils/icon-registry.js.map +1 -0
  250. package/lib/utils/loader-registry.js +3 -3
  251. package/lib/utils/locale.d.ts.map +1 -0
  252. package/lib/utils/locale.js +34 -34
  253. package/lib/utils/locale.js.map +1 -0
  254. package/lib/utils/mobile.js +1 -1
  255. package/lib/utils/number-format.d.ts.map +1 -0
  256. package/lib/utils/number-format.js +54 -54
  257. package/lib/utils/number-format.js.map +1 -0
  258. package/lib/utils/parse-boolean.d.ts +39 -0
  259. package/lib/utils/parse-boolean.d.ts.map +1 -0
  260. package/lib/utils/parse-boolean.js +23 -0
  261. package/lib/utils/parse-boolean.js.map +1 -0
  262. package/lib/utils/positioning.d.ts.map +1 -0
  263. package/lib/utils/positioning.js +212 -212
  264. package/lib/utils/positioning.js.map +1 -0
  265. package/lib/utils/property-capture.d.ts.map +1 -0
  266. package/lib/utils/property-capture.js +36 -36
  267. package/lib/utils/property-capture.js.map +1 -0
  268. package/lib/utils/property-manager.d.ts +1 -1
  269. package/lib/utils/property-manager.d.ts.map +1 -0
  270. package/lib/utils/property-manager.js +127 -125
  271. package/lib/utils/property-manager.js.map +1 -0
  272. package/lib/utils/resize-observer.d.ts.map +1 -0
  273. package/lib/utils/resize-observer.js +23 -23
  274. package/lib/utils/resize-observer.js.map +1 -0
  275. package/lib/utils/scroll-lock.d.ts.map +1 -0
  276. package/lib/utils/scroll-lock.js +57 -57
  277. package/lib/utils/scroll-lock.js.map +1 -0
  278. package/lib/utils/styles.d.ts.map +1 -0
  279. package/lib/utils/styles.js +17 -17
  280. package/lib/utils/styles.js.map +1 -0
  281. package/lib/utils/validity.d.ts +26 -0
  282. package/lib/utils/validity.js +53 -0
  283. package/lib/version.d.ts +1 -1
  284. package/lib/version.d.ts.map +1 -0
  285. package/lib/version.js +1 -1
  286. package/lib/version.js.map +1 -0
  287. package/package.json +28 -7
@@ -1,424 +1,455 @@
1
+ import { DEFAULT_SIZE } from "../types/common.js";
1
2
  import { TyComponent } from "../base/ty-component.js";
2
3
  import { ensureStyles } from "../utils/styles.js";
3
4
  import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
4
5
  import { radioStyles, radioCustomFlavorCss } from "../styles/radio.js";
5
6
  import { REQUIRED_ICON_SVG } from "../utils/icons.js";
6
7
  export class TyRadio extends TyComponent {
7
- constructor() {
8
- super();
9
- this._customFlavorSheet = null;
10
- this._listenersSetup = false;
11
- this._clickHandler = null;
12
- this._focusHandler = null;
13
- this._blurHandler = null;
14
- const shadow = this.shadowRoot;
15
- ensureStyles(shadow, { css: radioStyles, id: "ty-radio" });
16
- }
17
- onConnect() {
18
- this.setupEventListeners();
19
- this.dispatchEvent(new CustomEvent("ty-radio-connected", { bubbles: true }));
20
- this._syncCustomFlavor();
21
- }
22
- onDisconnect() {
23
- this.removeEventListeners();
24
- }
25
- onPropertiesChanged(changes) {
26
- if (changes.some((c) => c.name === "flavor")) {
27
- this._syncCustomFlavor();
28
- }
29
- }
30
- _syncCustomFlavor() {
31
- this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => radioCustomFlavorCss(base));
32
- }
33
- buildClassList() {
34
- const classes = [this.size];
35
- if (this.disabled)
36
- classes.push("disabled");
37
- return classes.join(" ");
38
- }
39
- handleClick(e) {
40
- if (this.disabled)
41
- return;
42
- e.stopPropagation();
43
- this.dispatchEvent(new CustomEvent("ty-radio-select", {
44
- detail: { value: this.value },
45
- bubbles: true,
46
- composed: true,
47
- }));
48
- }
49
- removeEventListeners() {
50
- if (!this._listenersSetup)
51
- return;
52
- if (this._clickHandler) {
53
- this.removeEventListener("click", this._clickHandler);
54
- this._clickHandler = null;
55
- }
56
- const el = this.shadowRoot?.querySelector(".radio-container");
57
- if (!el) {
58
- this._listenersSetup = false;
59
- return;
60
- }
61
- if (this._focusHandler) {
62
- el.removeEventListener("focus", this._focusHandler);
63
- this._focusHandler = null;
64
- }
65
- if (this._blurHandler) {
66
- el.removeEventListener("blur", this._blurHandler);
67
- this._blurHandler = null;
68
- }
69
- this._listenersSetup = false;
70
- }
71
- setupEventListeners() {
72
- if (this._listenersSetup)
73
- return;
74
- const el = this.shadowRoot.querySelector(".radio-container");
75
- if (!el)
76
- return;
77
- this._clickHandler = (e) => this.handleClick(e);
78
- this._focusHandler = () => el.classList.add("focused");
79
- this._blurHandler = () => el.classList.remove("focused");
80
- this.addEventListener("click", this._clickHandler);
81
- el.addEventListener("focus", this._focusHandler);
82
- el.addEventListener("blur", this._blurHandler);
83
- this._listenersSetup = true;
84
- }
85
- render() {
86
- const shadow = this.shadowRoot;
87
- let radioEl = shadow.querySelector(".radio-container");
88
- const classes = this.buildClassList();
89
- if (!radioEl) {
90
- radioEl = document.createElement("div");
91
- radioEl.className = "radio-container " + classes;
92
- radioEl.tabIndex = this.disabled ? -1 : 0;
93
- radioEl.setAttribute("role", "radio");
94
- radioEl.setAttribute("aria-checked", String(this.checked));
95
- radioEl.setAttribute("aria-disabled", String(this.disabled));
96
- const circle = document.createElement("div");
97
- circle.className = "radio-circle";
98
- radioEl.appendChild(circle);
99
- shadow.appendChild(radioEl);
100
- }
101
- else {
102
- radioEl.className = "radio-container " + classes;
103
- radioEl.tabIndex = this.disabled ? -1 : 0;
104
- radioEl.setAttribute("aria-checked", String(this.checked));
105
- radioEl.setAttribute("aria-disabled", String(this.disabled));
106
- }
107
- this.setupEventListeners();
108
- this.applyLabelName(radioEl);
109
- }
110
- get value() { return this.getProperty("value"); }
111
- set value(v) { this.setProperty("value", v); }
112
- get checked() { return this.getProperty("checked"); }
113
- set checked(v) { this.setProperty("checked", v); }
114
- get disabled() { return this.getProperty("disabled"); }
115
- set disabled(v) { this.setProperty("disabled", v); }
116
- get size() { return this.getProperty("size"); }
117
- set size(v) { this.setProperty("size", v); }
118
- get flavor() { return this.getProperty("flavor"); }
119
- set flavor(v) { this.setProperty("flavor", v); }
8
+ constructor() {
9
+ super();
10
+ this._customFlavorSheet = null;
11
+ this._listenersSetup = false;
12
+ this._clickHandler = null;
13
+ this._focusHandler = null;
14
+ this._blurHandler = null;
15
+ this._tabStop = true;
16
+ const shadow = this.shadowRoot;
17
+ ensureStyles(shadow, { css: radioStyles, id: "ty-radio" });
18
+ }
19
+ setTabStop(on) {
20
+ this._tabStop = on;
21
+ const el = this.shadowRoot?.querySelector(".radio-container");
22
+ if (el)
23
+ el.tabIndex = this.disabled || !on ? -1 : 0;
24
+ }
25
+ focus(options) {
26
+ const el = this.shadowRoot?.querySelector(".radio-container");
27
+ if (el)
28
+ el.focus(options);
29
+ else
30
+ super.focus(options);
31
+ }
32
+ onConnect() {
33
+ this.setupEventListeners();
34
+ this.dispatchEvent(new CustomEvent("ty-radio-connected", { bubbles: true }));
35
+ this._syncCustomFlavor();
36
+ }
37
+ onDisconnect() {
38
+ this.removeEventListeners();
39
+ }
40
+ onPropertiesChanged(changes) {
41
+ if (changes.some((c) => c.name === "flavor")) {
42
+ this._syncCustomFlavor();
43
+ }
44
+ }
45
+ _syncCustomFlavor() {
46
+ this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => radioCustomFlavorCss(base));
47
+ }
48
+ buildClassList() {
49
+ const classes = [this.size];
50
+ if (this.disabled)
51
+ classes.push("disabled");
52
+ return classes.join(" ");
53
+ }
54
+ handleClick(e) {
55
+ if (this.disabled)
56
+ return;
57
+ e.stopPropagation();
58
+ this.dispatchEvent(new CustomEvent("ty-radio-select", {
59
+ detail: { value: this.value },
60
+ bubbles: true,
61
+ composed: true,
62
+ }));
63
+ }
64
+ removeEventListeners() {
65
+ if (!this._listenersSetup)
66
+ return;
67
+ if (this._clickHandler) {
68
+ this.removeEventListener("click", this._clickHandler);
69
+ this._clickHandler = null;
70
+ }
71
+ const el = this.shadowRoot?.querySelector(".radio-container");
72
+ if (!el) {
73
+ this._listenersSetup = false;
74
+ return;
75
+ }
76
+ if (this._focusHandler) {
77
+ el.removeEventListener("focus", this._focusHandler);
78
+ this._focusHandler = null;
79
+ }
80
+ if (this._blurHandler) {
81
+ el.removeEventListener("blur", this._blurHandler);
82
+ this._blurHandler = null;
83
+ }
84
+ this._listenersSetup = false;
85
+ }
86
+ setupEventListeners() {
87
+ if (this._listenersSetup)
88
+ return;
89
+ const el = this.shadowRoot.querySelector(".radio-container");
90
+ if (!el)
91
+ return;
92
+ this._clickHandler = (e) => this.handleClick(e);
93
+ this._focusHandler = () => el.classList.add("focused");
94
+ this._blurHandler = () => el.classList.remove("focused");
95
+ this.addEventListener("click", this._clickHandler);
96
+ el.addEventListener("focus", this._focusHandler);
97
+ el.addEventListener("blur", this._blurHandler);
98
+ this._listenersSetup = true;
99
+ }
100
+ render() {
101
+ const shadow = this.shadowRoot;
102
+ let radioEl = shadow.querySelector(".radio-container");
103
+ const classes = this.buildClassList();
104
+ if (!radioEl) {
105
+ radioEl = document.createElement("div");
106
+ radioEl.className = "radio-container " + classes;
107
+ radioEl.tabIndex = this.disabled || !this._tabStop ? -1 : 0;
108
+ radioEl.setAttribute("role", "radio");
109
+ radioEl.setAttribute("aria-checked", String(this.checked));
110
+ radioEl.setAttribute("aria-disabled", String(this.disabled));
111
+ const circle = document.createElement("div");
112
+ circle.className = "radio-circle";
113
+ radioEl.appendChild(circle);
114
+ shadow.appendChild(radioEl);
115
+ }
116
+ else {
117
+ radioEl.className = "radio-container " + classes;
118
+ radioEl.tabIndex = this.disabled || !this._tabStop ? -1 : 0;
119
+ radioEl.setAttribute("aria-checked", String(this.checked));
120
+ radioEl.setAttribute("aria-disabled", String(this.disabled));
121
+ }
122
+ this.setupEventListeners();
123
+ this.applyLabelName(radioEl);
124
+ }
125
+ get value() { return this.getProperty("value"); }
126
+ set value(v) { this.setProperty("value", v); }
127
+ get checked() { return this.getProperty("checked"); }
128
+ set checked(v) { this.setProperty("checked", v); }
129
+ get disabled() { return this.getProperty("disabled"); }
130
+ set disabled(v) { this.setProperty("disabled", v); }
131
+ get size() { return this.getProperty("size"); }
132
+ set size(v) { this.setProperty("size", v); }
133
+ get flavor() { return this.getProperty("flavor"); }
134
+ set flavor(v) { this.setProperty("flavor", v); }
120
135
  }
121
136
  TyRadio.properties = {
122
- value: { type: "string", default: "" },
123
- checked: {
124
- type: "boolean",
125
- visual: true,
126
- default: false,
127
- },
128
- disabled: {
129
- type: "boolean",
130
- visual: true,
131
- default: false,
132
- },
133
- size: {
134
- type: "string",
135
- visual: true,
136
- default: "md",
137
- },
138
- flavor: {
139
- type: "string",
140
- visual: true,
141
- default: "primary",
142
- },
137
+ value: { type: "string", default: "" },
138
+ checked: {
139
+ type: "boolean",
140
+ visual: true,
141
+ default: false,
142
+ },
143
+ disabled: {
144
+ type: "boolean",
145
+ visual: true,
146
+ default: false,
147
+ },
148
+ size: {
149
+ type: "string",
150
+ visual: true,
151
+ default: DEFAULT_SIZE,
152
+ },
153
+ flavor: {
154
+ type: "string",
155
+ visual: true,
156
+ default: "primary",
157
+ },
143
158
  };
144
159
  if (!customElements.get("ty-radio")) {
145
- customElements.define("ty-radio", TyRadio);
160
+ customElements.define("ty-radio", TyRadio);
146
161
  }
147
162
  export class TyRadioGroup extends TyComponent {
148
- constructor() {
149
- super();
150
- this._listenersSetup = false;
151
- this._selectHandler = null;
152
- this._keydownHandler = null;
153
- this._connectedHandler = null;
154
- const shadow = this.shadowRoot;
155
- ensureStyles(shadow, { css: radioStyles, id: "ty-radio-group" });
156
- }
157
- onConnect() {
158
- this.setupEventListeners();
159
- queueMicrotask(() => this.syncChildren());
160
- }
161
- onDisconnect() {
162
- this.removeEventListeners();
163
- }
164
- onPropertiesChanged(changes) {
165
- if (changes.some((c) => c.name === "value" || c.name === "size" || c.name === "flavor" || c.name === "disabled")) {
166
- this.syncChildren();
167
- }
168
- }
169
- getFormValue() {
170
- return this.value || null;
171
- }
172
- getRadios() {
173
- return Array.from(this.querySelectorAll("ty-radio"));
174
- }
175
- syncChildren() {
176
- const radios = this.getRadios();
177
- for (const radio of radios) {
178
- radio.checked = radio.value === this.value;
179
- if (this.disabled) {
180
- if (!radio.disabled) {
181
- radio.disabled = true;
182
- radio.dataset.tyGroupDisabled = "";
183
- }
184
- }
185
- else if ("tyGroupDisabled" in radio.dataset) {
186
- radio.disabled = false;
187
- delete radio.dataset.tyGroupDisabled;
188
- }
189
- radio.size = this.size;
190
- radio.flavor = this.flavor;
191
- }
192
- }
193
- handleRadioSelect(e) {
194
- if (this.disabled)
195
- return;
196
- const detail = e.detail;
197
- const newValue = detail?.value;
198
- if (typeof newValue !== "string" || newValue === this.value)
199
- return;
200
- this.value = newValue;
201
- this.syncChildren();
202
- setTimeout(() => {
203
- const eventDetail = {
204
- value: newValue,
205
- formValue: newValue,
206
- originalEvent: e,
207
- };
208
- this.dispatchEvent(new CustomEvent("input", { detail: eventDetail, bubbles: true, composed: true }));
209
- this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
210
- }, 0);
211
- }
212
- handleKeydown(e) {
213
- if (this.disabled)
214
- return;
215
- const radios = this.getRadios().filter((r) => !r.disabled);
216
- if (radios.length === 0)
217
- return;
218
- const active = document.activeElement;
219
- const current = radios.find((r) => r === active || r.contains(active));
220
- let nextIndex = -1;
221
- if (["ArrowDown", "ArrowRight"].includes(e.key)) {
222
- e.preventDefault();
223
- nextIndex = current ? (radios.indexOf(current) + 1) % radios.length : 0;
224
- }
225
- else if (["ArrowUp", "ArrowLeft"].includes(e.key)) {
226
- e.preventDefault();
227
- nextIndex = current
228
- ? (radios.indexOf(current) - 1 + radios.length) % radios.length
229
- : radios.length - 1;
230
- }
231
- else if (["Space", " ", "Enter"].includes(e.key)) {
232
- if (current) {
233
- e.preventDefault();
234
- this.value = current.value;
235
- this.syncChildren();
236
- const eventDetail = {
237
- value: current.value,
238
- formValue: current.value,
239
- originalEvent: e,
240
- };
241
- setTimeout(() => {
242
- this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
243
- }, 0);
244
- }
245
- return;
246
- }
247
- else {
248
- return;
249
- }
250
- const next = radios[nextIndex];
251
- if (next) {
252
- next.focus();
253
- this.value = next.value;
254
- this.syncChildren();
255
- const eventDetail = {
256
- value: next.value,
257
- formValue: next.value,
258
- originalEvent: e,
259
- };
260
- setTimeout(() => {
261
- this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
262
- }, 0);
263
- }
264
- }
265
- removeEventListeners() {
266
- if (!this._listenersSetup)
267
- return;
268
- if (this._selectHandler) {
269
- this.removeEventListener("ty-radio-select", this._selectHandler);
270
- this._selectHandler = null;
271
- }
272
- if (this._keydownHandler) {
273
- this.removeEventListener("keydown", this._keydownHandler);
274
- this._keydownHandler = null;
275
- }
276
- if (this._connectedHandler) {
277
- this.removeEventListener("ty-radio-connected", this._connectedHandler);
278
- this._connectedHandler = null;
279
- }
280
- this._listenersSetup = false;
281
- }
282
- setupEventListeners() {
283
- if (this._listenersSetup)
284
- return;
285
- this._selectHandler = (e) => this.handleRadioSelect(e);
286
- this._keydownHandler = (e) => this.handleKeydown(e);
287
- this._connectedHandler = () => this.syncChildren();
288
- this.addEventListener("ty-radio-select", this._selectHandler);
289
- this.addEventListener("keydown", this._keydownHandler);
290
- this.addEventListener("ty-radio-connected", this._connectedHandler);
291
- this._listenersSetup = true;
292
- }
293
- render() {
294
- const shadow = this.shadowRoot;
295
- let container = shadow.querySelector(".radio-group-container");
296
- if (!container) {
297
- container = document.createElement("div");
298
- container.className = "radio-group-container";
299
- container.setAttribute("role", "radiogroup");
300
- container.setAttribute("aria-disabled", String(this.disabled));
301
- if (this.label) {
302
- const labelEl = document.createElement("div");
303
- labelEl.className = "radio-group-label";
304
- labelEl.textContent = this.label;
305
- if (this.required) {
306
- const req = document.createElement("span");
307
- req.className = "required-icon";
308
- req.innerHTML = REQUIRED_ICON_SVG;
309
- labelEl.appendChild(req);
310
- }
311
- container.appendChild(labelEl);
312
- }
313
- const list = document.createElement("div");
314
- list.className = "radio-group-list " + this.orientation;
315
- const slot = document.createElement("slot");
316
- list.appendChild(slot);
317
- container.appendChild(list);
318
- if (this.error) {
319
- const errorEl = document.createElement("div");
320
- errorEl.className = "radio-group-error";
321
- errorEl.textContent = this.error;
322
- container.appendChild(errorEl);
323
- }
324
- shadow.appendChild(container);
325
- this.setupEventListeners();
326
- }
327
- else {
328
- let labelEl = container.querySelector(".radio-group-label");
329
- if (this.label) {
330
- if (!labelEl) {
331
- labelEl = document.createElement("div");
332
- labelEl.className = "radio-group-label";
333
- container.insertBefore(labelEl, container.firstChild);
334
- }
335
- labelEl.textContent = this.label;
336
- if (this.required && !labelEl.querySelector(".required-icon")) {
337
- const req = document.createElement("span");
338
- req.className = "required-icon";
339
- req.innerHTML = REQUIRED_ICON_SVG;
340
- labelEl.appendChild(req);
341
- }
342
- else if (!this.required) {
343
- labelEl.querySelector(".required-icon")?.remove();
344
- }
345
- }
346
- else if (labelEl) {
347
- labelEl.remove();
348
- }
349
- const list = container.querySelector(".radio-group-list");
350
- if (list)
351
- list.className = "radio-group-list " + this.orientation;
352
- let errorEl = container.querySelector(".radio-group-error");
353
- if (this.error) {
354
- if (!errorEl) {
355
- errorEl = document.createElement("div");
356
- errorEl.className = "radio-group-error";
357
- container.appendChild(errorEl);
358
- }
359
- errorEl.textContent = this.error;
360
- }
361
- else if (errorEl) {
362
- errorEl.remove();
363
- }
364
- container.setAttribute("aria-disabled", String(this.disabled));
365
- }
366
- this.syncChildren();
367
- }
368
- get value() { return this.getProperty("value"); }
369
- set value(v) { this.setProperty("value", v); }
370
- get name() { return this.getProperty("name"); }
371
- set name(v) { this.setProperty("name", v); }
372
- get label() { return this.getProperty("label"); }
373
- set label(v) { this.setProperty("label", v); }
374
- get disabled() { return this.getProperty("disabled"); }
375
- set disabled(v) { this.setProperty("disabled", v); }
376
- get required() { return this.getProperty("required"); }
377
- set required(v) { this.setProperty("required", v); }
378
- get error() { return this.getProperty("error"); }
379
- set error(v) { this.setProperty("error", v); }
380
- get orientation() {
381
- return this.getProperty("orientation");
382
- }
383
- set orientation(v) {
384
- this.setProperty("orientation", v);
385
- }
386
- get size() { return this.getProperty("size"); }
387
- set size(v) { this.setProperty("size", v); }
388
- get flavor() { return this.getProperty("flavor"); }
389
- set flavor(v) { this.setProperty("flavor", v); }
390
- get form() { return this._internals.form; }
163
+ constructor() {
164
+ super();
165
+ this._listenersSetup = false;
166
+ this._selectHandler = null;
167
+ this._keydownHandler = null;
168
+ this._connectedHandler = null;
169
+ const shadow = this.shadowRoot;
170
+ ensureStyles(shadow, { css: radioStyles, id: "ty-radio-group" });
171
+ }
172
+ onConnect() {
173
+ this.setupEventListeners();
174
+ queueMicrotask(() => this.syncChildren());
175
+ }
176
+ onDisconnect() {
177
+ this.removeEventListeners();
178
+ }
179
+ onPropertiesChanged(changes) {
180
+ if (changes.some((c) => c.name === "value" || c.name === "size" || c.name === "flavor" || c.name === "disabled" || c.name === "required")) {
181
+ this.syncChildren();
182
+ }
183
+ }
184
+ getFormValue() {
185
+ return this.value || null;
186
+ }
187
+ getRadios() {
188
+ return Array.from(this.querySelectorAll("ty-radio"))
189
+ .filter((r) => typeof r.setTabStop === "function");
190
+ }
191
+ syncChildren() {
192
+ const radios = this.getRadios();
193
+ for (const radio of radios) {
194
+ radio.checked = radio.value === this.value;
195
+ if (this.disabled) {
196
+ if (!radio.disabled) {
197
+ radio.disabled = true;
198
+ radio.dataset.tyGroupDisabled = "";
199
+ }
200
+ }
201
+ else if ("tyGroupDisabled" in radio.dataset) {
202
+ radio.disabled = false;
203
+ delete radio.dataset.tyGroupDisabled;
204
+ }
205
+ radio.size = this.size;
206
+ radio.flavor = this.flavor;
207
+ }
208
+ const enabled = radios.filter((r) => !r.disabled);
209
+ const stop = enabled.find((r) => r.checked) ?? enabled[0];
210
+ for (const radio of radios)
211
+ radio.setTabStop(radio === stop);
212
+ this.updateValidity();
213
+ }
214
+ updateValidity() {
215
+ if (this.required && !this.disabled && !this.value) {
216
+ const anchor = this.getRadios().find((r) => !r.disabled);
217
+ const target = anchor?.shadowRoot?.querySelector(".radio-container");
218
+ this.applyValidity({ valueMissing: true }, "Please select an option", target ?? undefined);
219
+ }
220
+ else {
221
+ this.applyValidity({});
222
+ }
223
+ }
224
+ handleRadioSelect(e) {
225
+ if (this.disabled)
226
+ return;
227
+ const detail = e.detail;
228
+ const newValue = detail?.value;
229
+ if (typeof newValue !== "string" || newValue === this.value)
230
+ return;
231
+ this.value = newValue;
232
+ this.syncChildren();
233
+ setTimeout(() => {
234
+ const eventDetail = {
235
+ value: newValue,
236
+ formValue: newValue,
237
+ originalEvent: e,
238
+ };
239
+ this.dispatchEvent(new CustomEvent("input", { detail: eventDetail, bubbles: true, composed: true }));
240
+ this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
241
+ }, 0);
242
+ }
243
+ handleKeydown(e) {
244
+ if (this.disabled)
245
+ return;
246
+ const radios = this.getRadios().filter((r) => !r.disabled);
247
+ if (radios.length === 0)
248
+ return;
249
+ const active = document.activeElement;
250
+ const current = radios.find((r) => r === active || r.contains(active));
251
+ let nextIndex = -1;
252
+ if (["ArrowDown", "ArrowRight"].includes(e.key)) {
253
+ e.preventDefault();
254
+ nextIndex = current ? (radios.indexOf(current) + 1) % radios.length : 0;
255
+ }
256
+ else if (["ArrowUp", "ArrowLeft"].includes(e.key)) {
257
+ e.preventDefault();
258
+ nextIndex = current
259
+ ? (radios.indexOf(current) - 1 + radios.length) % radios.length
260
+ : radios.length - 1;
261
+ }
262
+ else if (["Space", " ", "Enter"].includes(e.key)) {
263
+ if (current) {
264
+ e.preventDefault();
265
+ this.value = current.value;
266
+ this.syncChildren();
267
+ const eventDetail = {
268
+ value: current.value,
269
+ formValue: current.value,
270
+ originalEvent: e,
271
+ };
272
+ setTimeout(() => {
273
+ this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
274
+ }, 0);
275
+ }
276
+ return;
277
+ }
278
+ else {
279
+ return;
280
+ }
281
+ const next = radios[nextIndex];
282
+ if (next) {
283
+ next.focus();
284
+ this.value = next.value;
285
+ this.syncChildren();
286
+ const eventDetail = {
287
+ value: next.value,
288
+ formValue: next.value,
289
+ originalEvent: e,
290
+ };
291
+ setTimeout(() => {
292
+ this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
293
+ }, 0);
294
+ }
295
+ }
296
+ removeEventListeners() {
297
+ if (!this._listenersSetup)
298
+ return;
299
+ if (this._selectHandler) {
300
+ this.removeEventListener("ty-radio-select", this._selectHandler);
301
+ this._selectHandler = null;
302
+ }
303
+ if (this._keydownHandler) {
304
+ this.removeEventListener("keydown", this._keydownHandler);
305
+ this._keydownHandler = null;
306
+ }
307
+ if (this._connectedHandler) {
308
+ this.removeEventListener("ty-radio-connected", this._connectedHandler);
309
+ this._connectedHandler = null;
310
+ }
311
+ this._listenersSetup = false;
312
+ }
313
+ setupEventListeners() {
314
+ if (this._listenersSetup)
315
+ return;
316
+ this._selectHandler = (e) => this.handleRadioSelect(e);
317
+ this._keydownHandler = (e) => this.handleKeydown(e);
318
+ this._connectedHandler = () => this.syncChildren();
319
+ this.addEventListener("ty-radio-select", this._selectHandler);
320
+ this.addEventListener("keydown", this._keydownHandler);
321
+ this.addEventListener("ty-radio-connected", this._connectedHandler);
322
+ this._listenersSetup = true;
323
+ }
324
+ render() {
325
+ const shadow = this.shadowRoot;
326
+ let container = shadow.querySelector(".radio-group-container");
327
+ if (!container) {
328
+ container = document.createElement("div");
329
+ container.className = "radio-group-container";
330
+ container.setAttribute("role", "radiogroup");
331
+ container.setAttribute("aria-disabled", String(this.disabled));
332
+ if (this.label) {
333
+ const labelEl = document.createElement("div");
334
+ labelEl.className = "radio-group-label";
335
+ labelEl.textContent = this.label;
336
+ if (this.required) {
337
+ const req = document.createElement("span");
338
+ req.className = "required-icon";
339
+ req.innerHTML = REQUIRED_ICON_SVG;
340
+ labelEl.appendChild(req);
341
+ }
342
+ container.appendChild(labelEl);
343
+ }
344
+ const list = document.createElement("div");
345
+ list.className = "radio-group-list " + this.orientation;
346
+ const slot = document.createElement("slot");
347
+ list.appendChild(slot);
348
+ container.appendChild(list);
349
+ if (this.error) {
350
+ const errorEl = document.createElement("div");
351
+ errorEl.className = "radio-group-error";
352
+ errorEl.textContent = this.error;
353
+ container.appendChild(errorEl);
354
+ }
355
+ shadow.appendChild(container);
356
+ this.setupEventListeners();
357
+ }
358
+ else {
359
+ let labelEl = container.querySelector(".radio-group-label");
360
+ if (this.label) {
361
+ if (!labelEl) {
362
+ labelEl = document.createElement("div");
363
+ labelEl.className = "radio-group-label";
364
+ container.insertBefore(labelEl, container.firstChild);
365
+ }
366
+ labelEl.textContent = this.label;
367
+ if (this.required && !labelEl.querySelector(".required-icon")) {
368
+ const req = document.createElement("span");
369
+ req.className = "required-icon";
370
+ req.innerHTML = REQUIRED_ICON_SVG;
371
+ labelEl.appendChild(req);
372
+ }
373
+ else if (!this.required) {
374
+ labelEl.querySelector(".required-icon")?.remove();
375
+ }
376
+ }
377
+ else if (labelEl) {
378
+ labelEl.remove();
379
+ }
380
+ const list = container.querySelector(".radio-group-list");
381
+ if (list)
382
+ list.className = "radio-group-list " + this.orientation;
383
+ let errorEl = container.querySelector(".radio-group-error");
384
+ if (this.error) {
385
+ if (!errorEl) {
386
+ errorEl = document.createElement("div");
387
+ errorEl.className = "radio-group-error";
388
+ container.appendChild(errorEl);
389
+ }
390
+ errorEl.textContent = this.error;
391
+ }
392
+ else if (errorEl) {
393
+ errorEl.remove();
394
+ }
395
+ container.setAttribute("aria-disabled", String(this.disabled));
396
+ }
397
+ this.syncChildren();
398
+ }
399
+ get value() { return this.getProperty("value"); }
400
+ set value(v) { this.setProperty("value", v); }
401
+ get name() { return this.getProperty("name"); }
402
+ set name(v) { this.setProperty("name", v); }
403
+ get label() { return this.getProperty("label"); }
404
+ set label(v) { this.setProperty("label", v); }
405
+ get disabled() { return this.getProperty("disabled"); }
406
+ set disabled(v) { this.setProperty("disabled", v); }
407
+ get required() { return this.getProperty("required"); }
408
+ set required(v) { this.setProperty("required", v); }
409
+ get error() { return this.getProperty("error"); }
410
+ set error(v) { this.setProperty("error", v); }
411
+ get orientation() {
412
+ return this.getProperty("orientation");
413
+ }
414
+ set orientation(v) {
415
+ this.setProperty("orientation", v);
416
+ }
417
+ get size() { return this.getProperty("size"); }
418
+ set size(v) { this.setProperty("size", v); }
419
+ get flavor() { return this.getProperty("flavor"); }
420
+ set flavor(v) { this.setProperty("flavor", v); }
421
+ get form() { return this._internals.form; }
391
422
  }
392
423
  TyRadioGroup.formAssociated = true;
393
424
  TyRadioGroup.properties = {
394
- value: {
395
- type: "string",
396
- visual: true,
397
- formValue: true,
398
- emitChange: true,
399
- default: "",
400
- },
401
- name: { type: "string", default: "" },
402
- label: { type: "string", visual: true, default: "" },
403
- disabled: { type: "boolean", visual: true, default: false },
404
- required: { type: "boolean", visual: true, default: false },
405
- error: { type: "string", visual: true, default: "" },
406
- orientation: {
407
- type: "string",
408
- visual: true,
409
- default: "vertical",
410
- },
411
- size: {
412
- type: "string",
413
- visual: true,
414
- default: "md",
415
- },
416
- flavor: {
417
- type: "string",
418
- visual: true,
419
- default: "primary",
420
- },
425
+ value: {
426
+ type: "string",
427
+ visual: true,
428
+ formValue: true,
429
+ emitChange: true,
430
+ default: "",
431
+ },
432
+ name: { type: "string", default: "" },
433
+ label: { type: "string", visual: true, default: "" },
434
+ disabled: { type: "boolean", visual: true, default: false },
435
+ required: { type: "boolean", visual: true, default: false },
436
+ error: { type: "string", visual: true, default: "" },
437
+ orientation: {
438
+ type: "string",
439
+ visual: true,
440
+ default: "vertical",
441
+ },
442
+ size: {
443
+ type: "string",
444
+ visual: true,
445
+ default: DEFAULT_SIZE,
446
+ },
447
+ flavor: {
448
+ type: "string",
449
+ visual: true,
450
+ default: "primary",
451
+ },
421
452
  };
422
453
  if (!customElements.get("ty-radio-group")) {
423
- customElements.define("ty-radio-group", TyRadioGroup);
454
+ customElements.define("ty-radio-group", TyRadioGroup);
424
455
  }