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,224 +1,225 @@
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 { switchStyles, switchCustomFlavorCss } from "../styles/switch.js";
5
6
  export class TySwitch extends TyComponent {
6
- constructor() {
7
- super();
8
- this._customFlavorSheet = null;
9
- this._listenersSetup = false;
10
- this._clickHandler = null;
11
- this._keydownHandler = null;
12
- this._focusHandler = null;
13
- this._blurHandler = null;
14
- const shadow = this.shadowRoot;
15
- ensureStyles(shadow, { css: switchStyles, id: "ty-switch" });
16
- }
17
- onConnect() {
18
- this.setupEventListeners();
19
- this._syncCustomFlavor();
20
- }
21
- onDisconnect() {
22
- this.removeEventListeners();
23
- }
24
- onPropertiesChanged(changes) {
25
- if (changes.some((c) => c.name === "flavor")) {
26
- this._syncCustomFlavor();
27
- }
28
- }
29
- _syncCustomFlavor() {
30
- this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => switchCustomFlavorCss(base));
31
- }
32
- getFormValue() {
33
- return this.checked ? this.value : null;
34
- }
35
- buildClassList() {
36
- const classes = [this.size];
37
- if (this.disabled)
38
- classes.push("disabled");
39
- if (this.required)
40
- classes.push("required");
41
- return classes.join(" ");
42
- }
43
- handleSwitchClick(e) {
44
- if (this.disabled)
45
- return;
46
- if (this.isDuplicateActivationClick())
47
- return;
48
- const newValue = !this.checked;
49
- this.checked = newValue;
50
- setTimeout(() => {
51
- const eventDetail = {
52
- value: newValue,
53
- checked: newValue,
54
- formValue: newValue ? this.value : null,
55
- originalEvent: e,
56
- };
57
- this.dispatchEvent(new CustomEvent("input", { detail: eventDetail, bubbles: true, composed: true }));
58
- this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
59
- }, 0);
60
- }
61
- handleSwitchKeydown(e) {
62
- if (this.disabled)
63
- return;
64
- if (["Space", " ", "Enter"].includes(e.key)) {
65
- e.preventDefault();
66
- e.stopPropagation();
67
- this.handleSwitchClick(e);
68
- }
69
- }
70
- removeEventListeners() {
71
- if (!this._listenersSetup)
72
- return;
73
- if (this._clickHandler) {
74
- this.removeEventListener("click", this._clickHandler);
75
- this._clickHandler = null;
76
- }
77
- const shadow = this.shadowRoot;
78
- if (!shadow)
79
- return;
80
- const el = shadow.querySelector(".switch-container");
81
- if (!el) {
82
- this._listenersSetup = false;
83
- return;
84
- }
85
- if (this._keydownHandler) {
86
- el.removeEventListener("keydown", this._keydownHandler);
87
- this._keydownHandler = null;
88
- }
89
- if (this._focusHandler) {
90
- el.removeEventListener("focus", this._focusHandler);
91
- this._focusHandler = null;
92
- }
93
- if (this._blurHandler) {
94
- el.removeEventListener("blur", this._blurHandler);
95
- this._blurHandler = null;
96
- }
97
- this._listenersSetup = false;
98
- }
99
- setupEventListeners() {
100
- if (this._listenersSetup)
101
- return;
102
- const shadow = this.shadowRoot;
103
- const el = shadow.querySelector(".switch-container");
104
- if (!el)
105
- return;
106
- this._clickHandler = (e) => this.handleSwitchClick(e);
107
- this._keydownHandler = (e) => this.handleSwitchKeydown(e);
108
- this._focusHandler = () => el.classList.add("focused");
109
- this._blurHandler = () => el.classList.remove("focused");
110
- this.addEventListener("click", this._clickHandler);
111
- el.addEventListener("keydown", this._keydownHandler);
112
- el.addEventListener("focus", this._focusHandler);
113
- el.addEventListener("blur", this._blurHandler);
114
- this._listenersSetup = true;
115
- }
116
- render() {
117
- const shadow = this.shadowRoot;
118
- let switchEl = shadow.querySelector(".switch-container");
119
- const classes = this.buildClassList();
120
- if (!switchEl) {
121
- switchEl = document.createElement("div");
122
- switchEl.className = "switch-container " + classes;
123
- switchEl.tabIndex = this.disabled ? -1 : 0;
124
- switchEl.setAttribute("role", "switch");
125
- switchEl.setAttribute("aria-checked", this.checked ? "true" : "false");
126
- switchEl.setAttribute("aria-disabled", this.disabled ? "true" : "false");
127
- switchEl.setAttribute("aria-required", this.required ? "true" : "false");
128
- const track = document.createElement("div");
129
- track.className = "switch-track";
130
- const thumb = document.createElement("div");
131
- thumb.className = "switch-thumb";
132
- track.appendChild(thumb);
133
- switchEl.appendChild(track);
134
- shadow.appendChild(switchEl);
135
- }
136
- else {
137
- switchEl.className = "switch-container " + classes;
138
- switchEl.tabIndex = this.disabled ? -1 : 0;
139
- switchEl.setAttribute("aria-checked", this.checked ? "true" : "false");
140
- switchEl.setAttribute("aria-disabled", this.disabled ? "true" : "false");
141
- switchEl.setAttribute("aria-required", this.required ? "true" : "false");
142
- }
143
- this.setupEventListeners();
144
- this.applyLabelName(switchEl);
145
- this.updateValidity();
146
- }
147
- updateValidity() {
148
- const anchor = this.shadowRoot?.querySelector(".switch-container");
149
- if (this.disabled) {
150
- this._internals.setValidity({});
151
- return;
152
- }
153
- if (this.required && !this.checked) {
154
- this._internals.setValidity({ valueMissing: true }, "Please turn this on", anchor ?? undefined);
155
- }
156
- else {
157
- this._internals.setValidity({});
158
- }
159
- }
160
- get checked() { return this.getProperty("checked"); }
161
- set checked(value) { this.setProperty("checked", value); }
162
- get value() { return this.getProperty("value"); }
163
- set value(val) { this.setProperty("value", val); }
164
- get name() { return this.getProperty("name"); }
165
- set name(val) { this.setProperty("name", val); }
166
- get disabled() { return this.getProperty("disabled"); }
167
- set disabled(value) { this.setProperty("disabled", value); }
168
- get required() { return this.getProperty("required"); }
169
- set required(value) { this.setProperty("required", value); }
170
- get size() { return this.getProperty("size"); }
171
- set size(value) { this.setProperty("size", value); }
172
- get flavor() { return this.getProperty("flavor"); }
173
- set flavor(value) { this.setProperty("flavor", value); }
174
- get form() { return this._internals.form; }
7
+ constructor() {
8
+ super();
9
+ this._customFlavorSheet = null;
10
+ this._listenersSetup = false;
11
+ this._clickHandler = null;
12
+ this._keydownHandler = null;
13
+ this._focusHandler = null;
14
+ this._blurHandler = null;
15
+ const shadow = this.shadowRoot;
16
+ ensureStyles(shadow, { css: switchStyles, id: "ty-switch" });
17
+ }
18
+ onConnect() {
19
+ this.setupEventListeners();
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 }) => switchCustomFlavorCss(base));
32
+ }
33
+ getFormValue() {
34
+ return this.checked ? this.value : null;
35
+ }
36
+ buildClassList() {
37
+ const classes = [this.size];
38
+ if (this.disabled)
39
+ classes.push("disabled");
40
+ if (this.required)
41
+ classes.push("required");
42
+ return classes.join(" ");
43
+ }
44
+ handleSwitchClick(e) {
45
+ if (this.disabled)
46
+ return;
47
+ if (this.isDuplicateActivationClick())
48
+ return;
49
+ const newValue = !this.checked;
50
+ this.checked = newValue;
51
+ setTimeout(() => {
52
+ const eventDetail = {
53
+ value: newValue,
54
+ checked: newValue,
55
+ formValue: newValue ? this.value : null,
56
+ originalEvent: e,
57
+ };
58
+ this.dispatchEvent(new CustomEvent("input", { detail: eventDetail, bubbles: true, composed: true }));
59
+ this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
60
+ }, 0);
61
+ }
62
+ handleSwitchKeydown(e) {
63
+ if (this.disabled)
64
+ return;
65
+ if (["Space", " ", "Enter"].includes(e.key)) {
66
+ e.preventDefault();
67
+ e.stopPropagation();
68
+ this.handleSwitchClick(e);
69
+ }
70
+ }
71
+ removeEventListeners() {
72
+ if (!this._listenersSetup)
73
+ return;
74
+ if (this._clickHandler) {
75
+ this.removeEventListener("click", this._clickHandler);
76
+ this._clickHandler = null;
77
+ }
78
+ const shadow = this.shadowRoot;
79
+ if (!shadow)
80
+ return;
81
+ const el = shadow.querySelector(".switch-container");
82
+ if (!el) {
83
+ this._listenersSetup = false;
84
+ return;
85
+ }
86
+ if (this._keydownHandler) {
87
+ el.removeEventListener("keydown", this._keydownHandler);
88
+ this._keydownHandler = null;
89
+ }
90
+ if (this._focusHandler) {
91
+ el.removeEventListener("focus", this._focusHandler);
92
+ this._focusHandler = null;
93
+ }
94
+ if (this._blurHandler) {
95
+ el.removeEventListener("blur", this._blurHandler);
96
+ this._blurHandler = null;
97
+ }
98
+ this._listenersSetup = false;
99
+ }
100
+ setupEventListeners() {
101
+ if (this._listenersSetup)
102
+ return;
103
+ const shadow = this.shadowRoot;
104
+ const el = shadow.querySelector(".switch-container");
105
+ if (!el)
106
+ return;
107
+ this._clickHandler = (e) => this.handleSwitchClick(e);
108
+ this._keydownHandler = (e) => this.handleSwitchKeydown(e);
109
+ this._focusHandler = () => el.classList.add("focused");
110
+ this._blurHandler = () => el.classList.remove("focused");
111
+ this.addEventListener("click", this._clickHandler);
112
+ el.addEventListener("keydown", this._keydownHandler);
113
+ el.addEventListener("focus", this._focusHandler);
114
+ el.addEventListener("blur", this._blurHandler);
115
+ this._listenersSetup = true;
116
+ }
117
+ render() {
118
+ const shadow = this.shadowRoot;
119
+ let switchEl = shadow.querySelector(".switch-container");
120
+ const classes = this.buildClassList();
121
+ if (!switchEl) {
122
+ switchEl = document.createElement("div");
123
+ switchEl.className = "switch-container " + classes;
124
+ switchEl.tabIndex = this.disabled ? -1 : 0;
125
+ switchEl.setAttribute("role", "switch");
126
+ switchEl.setAttribute("aria-checked", this.checked ? "true" : "false");
127
+ switchEl.setAttribute("aria-disabled", this.disabled ? "true" : "false");
128
+ switchEl.setAttribute("aria-required", this.required ? "true" : "false");
129
+ const track = document.createElement("div");
130
+ track.className = "switch-track";
131
+ const thumb = document.createElement("div");
132
+ thumb.className = "switch-thumb";
133
+ track.appendChild(thumb);
134
+ switchEl.appendChild(track);
135
+ shadow.appendChild(switchEl);
136
+ }
137
+ else {
138
+ switchEl.className = "switch-container " + classes;
139
+ switchEl.tabIndex = this.disabled ? -1 : 0;
140
+ switchEl.setAttribute("aria-checked", this.checked ? "true" : "false");
141
+ switchEl.setAttribute("aria-disabled", this.disabled ? "true" : "false");
142
+ switchEl.setAttribute("aria-required", this.required ? "true" : "false");
143
+ }
144
+ this.setupEventListeners();
145
+ this.applyLabelName(switchEl);
146
+ this.updateValidity();
147
+ }
148
+ updateValidity() {
149
+ const anchor = this.shadowRoot?.querySelector(".switch-container");
150
+ if (this.disabled) {
151
+ this.applyValidity({});
152
+ return;
153
+ }
154
+ if (this.required && !this.checked) {
155
+ this.applyValidity({ valueMissing: true }, "Please turn this on", anchor ?? undefined);
156
+ }
157
+ else {
158
+ this.applyValidity({});
159
+ }
160
+ }
161
+ get checked() { return this.getProperty("checked"); }
162
+ set checked(value) { this.setProperty("checked", value); }
163
+ get value() { return this.getProperty("value"); }
164
+ set value(val) { this.setProperty("value", val); }
165
+ get name() { return this.getProperty("name"); }
166
+ set name(val) { this.setProperty("name", val); }
167
+ get disabled() { return this.getProperty("disabled"); }
168
+ set disabled(value) { this.setProperty("disabled", value); }
169
+ get required() { return this.getProperty("required"); }
170
+ set required(value) { this.setProperty("required", value); }
171
+ get size() { return this.getProperty("size"); }
172
+ set size(value) { this.setProperty("size", value); }
173
+ get flavor() { return this.getProperty("flavor"); }
174
+ set flavor(value) { this.setProperty("flavor", value); }
175
+ get form() { return this._internals.form; }
175
176
  }
176
177
  TySwitch.formAssociated = true;
177
178
  TySwitch.properties = {
178
- checked: {
179
- type: "boolean",
180
- visual: true,
181
- formValue: true,
182
- emitChange: true,
183
- default: false,
184
- },
185
- value: {
186
- type: "string",
187
- default: "on",
188
- },
189
- name: {
190
- type: "string",
191
- default: "",
192
- },
193
- disabled: {
194
- type: "boolean",
195
- visual: true,
196
- default: false,
197
- },
198
- required: {
199
- type: "boolean",
200
- visual: true,
201
- default: false,
202
- },
203
- size: {
204
- type: "string",
205
- visual: true,
206
- default: "md",
207
- validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
208
- coerce: (v) => {
209
- if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
210
- console.warn(`[ty-switch] Invalid size '${v}'. Using 'md'.`);
211
- return "md";
212
- }
213
- return v;
214
- },
215
- },
216
- flavor: {
217
- type: "string",
218
- visual: true,
219
- default: "primary",
220
- },
179
+ checked: {
180
+ type: "boolean",
181
+ visual: true,
182
+ formValue: true,
183
+ emitChange: true,
184
+ default: false,
185
+ },
186
+ value: {
187
+ type: "string",
188
+ default: "on",
189
+ },
190
+ name: {
191
+ type: "string",
192
+ default: "",
193
+ },
194
+ disabled: {
195
+ type: "boolean",
196
+ visual: true,
197
+ default: false,
198
+ },
199
+ required: {
200
+ type: "boolean",
201
+ visual: true,
202
+ default: false,
203
+ },
204
+ size: {
205
+ type: "string",
206
+ visual: true,
207
+ default: DEFAULT_SIZE,
208
+ validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
209
+ coerce: (v) => {
210
+ if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
211
+ console.warn(`[ty-switch] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
212
+ return DEFAULT_SIZE;
213
+ }
214
+ return v;
215
+ },
216
+ },
217
+ flavor: {
218
+ type: "string",
219
+ visual: true,
220
+ default: "primary",
221
+ },
221
222
  };
222
223
  if (!customElements.get("ty-switch")) {
223
- customElements.define("ty-switch", TySwitch);
224
+ customElements.define("ty-switch", TySwitch);
224
225
  }
@@ -3,15 +3,63 @@ export interface TabAttributes {
3
3
  id: string | null;
4
4
  label: string | null;
5
5
  disabled: boolean;
6
+ lazy: boolean;
7
+ }
8
+ /**
9
+ * `ty-tab-load`: a lazy tab with no content was shown. Fired on the ty-tab
10
+ * and doesn't bubble, so a lazy tab nested in another doesn't trigger the
11
+ * outer one's listener. Listen on the tab, or on ty-tabs with capture.
12
+ */
13
+ export interface TabLoadDetail {
14
+ id: string;
15
+ index: number;
6
16
  }
7
17
  export declare class TyTab extends HTMLElement {
8
18
  private _scrollbar;
19
+ private _panelLabel;
20
+ private _shown;
21
+ private _load;
22
+ private _contentObserver;
23
+ private _contentChanged;
9
24
  static get observedAttributes(): string[];
10
25
  constructor();
11
26
  connectedCallback(): void;
27
+ /** Accessible name. Set by ty-tabs, which also knows rich `label-{id}` slots. */
28
+ setPanelLabel(label: string): void;
29
+ /** Set by ty-tabs: a panel that isn't shown is inert. */
30
+ setShown(shown: boolean): void;
12
31
  disconnectedCallback(): void;
13
- attributeChangedCallback(_name: string, _oldValue: string | null, _newValue: string | null): void;
32
+ /**
33
+ * Called by ty-tabs when this tab becomes the shown one — never for the
34
+ * tab shown first, whose content the page is expected to carry. A lazy
35
+ * tab with no content (or whose load failed) asks for it.
36
+ */
37
+ _requestLoad(index: number): void;
38
+ /**
39
+ * Report that loading this tab's content failed: shows `slot="error"`
40
+ * (default "Couldn't load.") with a Retry button. Retry, or showing the
41
+ * tab again, fires `ty-tab-load` once more. Content arriving clears it.
42
+ */
43
+ loadFailed(): void;
44
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
14
45
  private _render;
46
+ /** Lazy tabs track whether they have content; others don't watch. */
47
+ private _watchContent;
48
+ private _hasContent;
49
+ /**
50
+ * `mutated`: content changed under a connected tab. Content that goes away
51
+ * (a morph with the server's empty markup) loads again — right away when
52
+ * this tab is the one shown, otherwise the next time it's shown.
53
+ */
54
+ private _checkContent;
55
+ private _fireLoad;
56
+ /**
57
+ * Placeholder and error, built the first time a tab loads: tabs that never
58
+ * do carry no hidden "Couldn't load / Retry" text.
59
+ */
60
+ private _ensureStatus;
61
+ private _setLoad;
62
+ private _syncPanel;
15
63
  private _setupScrollbar;
16
64
  private _destroyScrollbar;
17
65
  resetScroll(): void;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tab.d.ts","sourceRoot":"","sources":["../../src/components/tab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AASH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AA0DD;;GAEG;AACH,qBAAa,KAAM,SAAQ,WAAW;IACpC,0BAA0B;IAC1B,MAAM,KAAK,kBAAkB,aAE5B;;IAOD,iBAAiB;IAIjB,oBAAoB;IAIpB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAG3F"}