@nanahoshi/mona-ui 0.24.10 → 0.25.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 (165) hide show
  1. package/README.md +9 -0
  2. package/chart/README.md +223 -77
  3. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +11 -10
  4. package/fesm2022/nanahoshi-mona-ui-avatar.mjs +37 -20
  5. package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +239 -47
  6. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +184 -31
  7. package/fesm2022/nanahoshi-mona-ui-button.mjs +47 -11
  8. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +17 -13
  9. package/fesm2022/nanahoshi-mona-ui-card.mjs +54 -30
  10. package/fesm2022/nanahoshi-mona-ui-chart.mjs +1909 -666
  11. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +112 -31
  12. package/fesm2022/nanahoshi-mona-ui-chip.mjs +131 -89
  13. package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +59 -19
  14. package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +118 -41
  15. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +243 -212
  16. package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +155 -86
  17. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +161 -131
  18. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +12 -11
  19. package/fesm2022/nanahoshi-mona-ui-common.mjs +18 -1
  20. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +10 -9
  21. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +10 -9
  22. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +2 -2
  23. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +2 -2
  24. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +10 -9
  25. package/fesm2022/nanahoshi-mona-ui-editor.mjs +25 -24
  26. package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +202 -33
  27. package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +31 -10
  28. package/fesm2022/nanahoshi-mona-ui-filter.mjs +1 -1
  29. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs} +2 -2
  30. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs → nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs} +4 -4
  31. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs → nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs} +7 -7
  32. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs} +4 -4
  33. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs} +27 -29
  34. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  35. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +146 -5
  36. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +2 -2
  37. package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +1 -1
  38. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +5 -5
  39. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +7 -7
  40. package/fesm2022/nanahoshi-mona-ui-internal.mjs +183 -47
  41. package/fesm2022/nanahoshi-mona-ui-label.mjs +111 -15
  42. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +1 -1
  43. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +1 -1
  44. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +111 -5
  45. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +103 -5
  46. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +103 -5
  47. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +100 -6
  48. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +90 -5
  49. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +103 -5
  50. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +90 -5
  51. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +90 -5
  52. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +103 -5
  53. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +105 -5
  54. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +103 -5
  55. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +90 -5
  56. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +90 -5
  57. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +2 -2
  58. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +14 -13
  59. package/fesm2022/nanahoshi-mona-ui-notification.mjs +1 -1
  60. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +13 -12
  61. package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +192 -56
  62. package/fesm2022/nanahoshi-mona-ui-pager.mjs +1 -1
  63. package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +3 -1
  64. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +2 -2
  65. package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +60 -29
  66. package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +334 -37
  67. package/fesm2022/nanahoshi-mona-ui-rating.mjs +84 -30
  68. package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +274 -108
  69. package/fesm2022/nanahoshi-mona-ui-segmented.mjs +127 -37
  70. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +2 -2
  71. package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +595 -170
  72. package/fesm2022/nanahoshi-mona-ui-skeleton.mjs +3 -2
  73. package/fesm2022/nanahoshi-mona-ui-slider.mjs +323 -166
  74. package/fesm2022/nanahoshi-mona-ui-spinner.mjs +167 -82
  75. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +3 -3
  76. package/fesm2022/nanahoshi-mona-ui-splitter.mjs +273 -165
  77. package/fesm2022/nanahoshi-mona-ui-stepper.mjs +219 -132
  78. package/fesm2022/nanahoshi-mona-ui-switch.mjs +84 -32
  79. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +337 -116
  80. package/fesm2022/nanahoshi-mona-ui-text-area.mjs +10 -12
  81. package/fesm2022/nanahoshi-mona-ui-text-box.mjs +21 -8
  82. package/fesm2022/nanahoshi-mona-ui-theme.mjs +444 -88
  83. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +10 -9
  84. package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +15 -14
  85. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +17 -3
  86. package/fesm2022/nanahoshi-mona-ui-window.mjs +1 -1
  87. package/i18n/catalogs/en-US.messages.json +90 -5
  88. package/locales/ar-sa/ar-sa.messages.json +90 -5
  89. package/locales/de-de/de-de.messages.json +90 -5
  90. package/locales/es-es/es-es.messages.json +90 -5
  91. package/locales/fr-fr/fr-fr.messages.json +91 -6
  92. package/locales/id-id/id-id.messages.json +90 -5
  93. package/locales/it-it/it-it.messages.json +90 -5
  94. package/locales/ja-jp/ja-jp.messages.json +90 -5
  95. package/locales/ko-kr/ko-kr.messages.json +90 -5
  96. package/locales/pt-br/pt-br.messages.json +90 -5
  97. package/locales/ru-ru/ru-ru.messages.json +90 -5
  98. package/locales/tr-tr/tr-tr.messages.json +90 -5
  99. package/locales/zh-cn/zh-cn.messages.json +90 -5
  100. package/locales/zh-tw/zh-tw.messages.json +90 -5
  101. package/package.json +2 -1
  102. package/styles.css +156 -0
  103. package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -0
  104. package/types/nanahoshi-mona-ui-avatar.d.ts +18 -11
  105. package/types/nanahoshi-mona-ui-breadcrumb.d.ts +62 -14
  106. package/types/nanahoshi-mona-ui-button-group.d.ts +86 -16
  107. package/types/nanahoshi-mona-ui-button.d.ts +26 -3
  108. package/types/nanahoshi-mona-ui-calendar.d.ts +1 -0
  109. package/types/nanahoshi-mona-ui-card.d.ts +22 -6
  110. package/types/nanahoshi-mona-ui-chart.d.ts +519 -527
  111. package/types/nanahoshi-mona-ui-check-box.d.ts +54 -13
  112. package/types/nanahoshi-mona-ui-chip.d.ts +31 -18
  113. package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +21 -5
  114. package/types/nanahoshi-mona-ui-collapsible.d.ts +20 -11
  115. package/types/nanahoshi-mona-ui-color-gradient.d.ts +62 -36
  116. package/types/nanahoshi-mona-ui-color-palette.d.ts +65 -27
  117. package/types/nanahoshi-mona-ui-color-picker.d.ts +64 -23
  118. package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -0
  119. package/types/nanahoshi-mona-ui-common.d.ts +28 -2
  120. package/types/nanahoshi-mona-ui-date-picker.d.ts +1 -0
  121. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +1 -0
  122. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +1 -0
  123. package/types/nanahoshi-mona-ui-editor.d.ts +1 -0
  124. package/types/nanahoshi-mona-ui-expansion-panel.d.ts +51 -7
  125. package/types/nanahoshi-mona-ui-fieldset.d.ts +18 -4
  126. package/types/nanahoshi-mona-ui-grid.d.ts +0 -1
  127. package/types/nanahoshi-mona-ui-i18n.d.ts +130 -3
  128. package/types/nanahoshi-mona-ui-internal.d.ts +95 -14
  129. package/types/nanahoshi-mona-ui-label.d.ts +17 -2
  130. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +85 -0
  131. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +85 -0
  132. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +85 -0
  133. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +85 -0
  134. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +85 -0
  135. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +85 -0
  136. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +85 -0
  137. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +85 -0
  138. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +85 -0
  139. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +85 -0
  140. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +85 -0
  141. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +85 -0
  142. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +85 -0
  143. package/types/nanahoshi-mona-ui-multi-select.d.ts +1 -0
  144. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -0
  145. package/types/nanahoshi-mona-ui-otp-input.d.ts +49 -12
  146. package/types/nanahoshi-mona-ui-placeholder.d.ts +2 -1
  147. package/types/nanahoshi-mona-ui-progress-bar.d.ts +21 -9
  148. package/types/nanahoshi-mona-ui-radio-button.d.ts +165 -20
  149. package/types/nanahoshi-mona-ui-rating.d.ts +21 -6
  150. package/types/nanahoshi-mona-ui-scroll-view.d.ts +59 -27
  151. package/types/nanahoshi-mona-ui-segmented.d.ts +52 -24
  152. package/types/nanahoshi-mona-ui-sidebar.d.ts +104 -41
  153. package/types/nanahoshi-mona-ui-skeleton.d.ts +1 -1
  154. package/types/nanahoshi-mona-ui-slider.d.ts +99 -35
  155. package/types/nanahoshi-mona-ui-spinner.d.ts +9 -5
  156. package/types/nanahoshi-mona-ui-splitter.d.ts +31 -10
  157. package/types/nanahoshi-mona-ui-stepper.d.ts +58 -12
  158. package/types/nanahoshi-mona-ui-switch.d.ts +32 -10
  159. package/types/nanahoshi-mona-ui-tabs.d.ts +75 -20
  160. package/types/nanahoshi-mona-ui-text-area.d.ts +7 -7
  161. package/types/nanahoshi-mona-ui-text-box.d.ts +2 -0
  162. package/types/nanahoshi-mona-ui-theme.d.ts +392 -15
  163. package/types/nanahoshi-mona-ui-time-picker.d.ts +1 -0
  164. package/types/nanahoshi-mona-ui-time-selector.d.ts +1 -0
  165. package/types/nanahoshi-mona-ui-tooltip.d.ts +7 -1
@@ -1,13 +1,16 @@
1
1
  import { NgTemplateOutlet } from '@angular/common';
2
2
  import * as i0 from '@angular/core';
3
- import { Directive, inject, DestroyRef, ElementRef, computed, contentChild, TemplateRef, input, model, output, afterNextRender, Component } from '@angular/core';
3
+ import { Directive, inject, DestroyRef, ElementRef, computed, contentChild, TemplateRef, input, model, booleanAttribute, numberAttribute, output, afterNextRender, Component } from '@angular/core';
4
4
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
5
  import { fromEvent, filter, tap, merge } from 'rxjs';
6
6
  import { twMerge } from 'tailwind-merge';
7
7
  import { cva } from 'class-variance-authority';
8
- import { themeControlSurfaceClasses, themeRaisedSurfaceClasses } from '@nanahoshi/mona-ui/internal';
8
+ import { themeControlSurfaceClasses, themeRaisedSurfaceClasses, injectLabelAssociation, injectEffectiveDisabled } from '@nanahoshi/mona-ui/internal';
9
9
 
10
10
  class SwitchHandleContentTemplateDirective {
11
+ static ngTemplateContextGuard(_directive, _context) {
12
+ return true;
13
+ }
11
14
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SwitchHandleContentTemplateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
12
15
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.6", type: SwitchHandleContentTemplateDirective, isStandalone: true, selector: "ng-template[monaSwitchHandleContentTemplate]", ngImport: i0 }); }
13
16
  }
@@ -45,7 +48,7 @@ const switchThemeVariants = cva(`
45
48
  cursor-pointer select-none
46
49
  ${themeControlSurfaceClasses}
47
50
  border border-input-border
48
- outline-none
51
+ outline-none focus-visible:outline-hidden
49
52
  transition-[background,border-color]
50
53
 
51
54
  data-[disabled='true']:pointer-events-none
@@ -54,8 +57,14 @@ const switchThemeVariants = cva(`
54
57
  data-[disabled='true']:bg-disabled-background
55
58
  data-[disabled='true']:text-disabled-foreground
56
59
 
57
- data-[active='true']:bg-primary
58
- data-[active='true']:text-primary-foreground
60
+ data-[readonly='true']:cursor-default
61
+
62
+ data-[active='true']:bg-[var(--mona-indicator-color,var(--color-primary))]
63
+ data-[active='true']:text-[var(--mona-indicator-foreground,var(--color-primary-foreground))]
64
+ data-[active='true']:not-data-[disabled='true']:forced-color-adjust-none
65
+ data-[active='true']:not-data-[disabled='true']:forced-colors:border-[CanvasText]
66
+ data-[active='true']:not-data-[disabled='true']:forced-colors:bg-[Highlight]
67
+ data-[active='true']:not-data-[disabled='true']:forced-colors:text-[HighlightText]
59
68
  data-[disabled='true']:data-[active='true']:bg-disabled-background
60
69
 
61
70
  focus-visible:border-focus-indicator
@@ -77,19 +86,21 @@ const switchThemeVariants = cva(`
77
86
  size: {
78
87
  large: "h-7.5 w-14 text-base",
79
88
  medium: "h-6.5 w-12 text-sm",
80
- small: "h-5.5 w-10 text-xs"
89
+ small: "h-5.5 w-10 text-xs before:absolute before:inset-x-0 before:-inset-y-px before:content-['']"
81
90
  }
82
91
  }
83
92
  });
84
93
  const switchHandleThemeVariants = cva(`
85
94
  absolute inline-flex items-center justify-center
95
+ forced-color-adjust-auto
86
96
  ${themeRaisedSurfaceClasses} text-foreground
87
97
  border border-border-subtle shadow-(--shadow-control)
88
- outline-none
98
+ outline-none focus-visible:outline-hidden
89
99
  transition-[inset-inline-start,background] duration-(--mona-motion-standard) ease-in-out
90
- data-[active='true']:bg-primary-foreground
91
- group-data-[disabled='true']:border-disabled-border
92
- group-data-[disabled='true']:bg-disabled-background
100
+ data-[active='true']:bg-[var(--mona-indicator-foreground,var(--color-primary-foreground))]
101
+ group-data-[disabled='true']:border-disabled-foreground
102
+ group-data-[disabled='true']:bg-disabled-foreground
103
+ group-data-[disabled='true']:data-[active='true']:bg-disabled-foreground
93
104
  `, {
94
105
  variants: {
95
106
  rounded: {
@@ -125,9 +136,15 @@ const switchLabelThemeVariants = cva(`
125
136
  class SwitchComponent {
126
137
  #destroyRef;
127
138
  #hostElementRef;
139
+ #label;
128
140
  constructor() {
129
141
  this.#destroyRef = inject(DestroyRef);
130
142
  this.#hostElementRef = inject((ElementRef));
143
+ this.#label = injectLabelAssociation({
144
+ activate: () => this.activateFromLabel(),
145
+ ariaLabel: () => this.ariaLabel(),
146
+ ariaLabelledBy: () => this.ariaLabelledBy()
147
+ });
131
148
  this.classes = computed(() => {
132
149
  const rounded = this.rounded();
133
150
  const size = this.size();
@@ -135,6 +152,7 @@ class SwitchComponent {
135
152
  return twMerge(classes, this.userClass());
136
153
  }, /* @ts-ignore */
137
154
  ...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
155
+ this.effectiveDisabled = injectEffectiveDisabled(() => this.disabled());
138
156
  this.handleClasses = computed(() => {
139
157
  const rounded = this.rounded();
140
158
  const size = this.size();
@@ -150,6 +168,7 @@ class SwitchComponent {
150
168
  return twMerge(classes);
151
169
  }, /* @ts-ignore */
152
170
  ...(ngDevMode ? [{ debugName: "labelClasses" }] : /* istanbul ignore next */ []));
171
+ this.labelledBy = this.#label.labelledBy;
153
172
  this.offLabelTemplate = contentChild(SwitchOffLabelTemplateDirective, { ...(ngDevMode ? { debugName: "offLabelTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
154
173
  this.onLabelTemplate = contentChild(SwitchOnLabelTemplateDirective, { ...(ngDevMode ? { debugName: "onLabelTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
155
174
  /**
@@ -173,15 +192,13 @@ class SwitchComponent {
173
192
  * @description Renders the component with reduced visual emphasis and removes pointer interaction.
174
193
  * @default false
175
194
  */
176
- this.disabled = input(false, /* @ts-ignore */
177
- ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
195
+ this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
178
196
  /**
179
- * @description Marks the switch as invalid. When bound to a signal form field via `[field]`,
180
- * this is written by the signal forms `Field` directive.
197
+ * @description Marks the switch as invalid. When bound to a signal form field via `[formField]`, this is written by
198
+ * the `FormField` directive.
181
199
  * @default false
182
200
  */
183
- this.invalid = input(false, /* @ts-ignore */
184
- ...(ngDevMode ? [{ debugName: "invalid" }] : /* istanbul ignore next */ []));
201
+ this.invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
185
202
  /**
186
203
  * @description Label displayed inside the switch track when it is in the off state.
187
204
  * @default ""
@@ -194,12 +211,17 @@ class SwitchComponent {
194
211
  */
195
212
  this.onLabel = input("", /* @ts-ignore */
196
213
  ...(ngDevMode ? [{ debugName: "onLabel" }] : /* istanbul ignore next */ []));
214
+ /**
215
+ * @description Prevents value changes while the control stays focusable and readable. When bound to a signal form
216
+ * field via `[formField]`, this is written by the `FormField` directive.
217
+ * @default false
218
+ */
219
+ this.readonly = input(false, { ...(ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
197
220
  /**
198
221
  * @description Marks the switch as required for form validation.
199
222
  * @default false
200
223
  */
201
- this.required = input(false, /* @ts-ignore */
202
- ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
224
+ this.required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
203
225
  /**
204
226
  * @description Border-radius preset applied to the component.
205
227
  * @default "full"
@@ -212,17 +234,21 @@ class SwitchComponent {
212
234
  */
213
235
  this.size = input("medium", /* @ts-ignore */
214
236
  ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
237
+ /**
238
+ * @description Tab index of the switch while it's enabled.
239
+ * @default 0
240
+ */
241
+ this.tabindex = input(0, { ...(ngDevMode ? { debugName: "tabindex" } : /* istanbul ignore next */ {}), transform: (value) => numberAttribute(value, 0) });
215
242
  /**
216
243
  * @description Emitted when the switch loses focus or its value changes.
217
244
  */
218
245
  this.touch = output();
219
246
  /**
220
- * @description Marks the switch as touched. When bound to a signal form field via `[field]`,
221
- * this is written by the signal forms `Field` directive.
247
+ * @description Marks the switch as touched. When bound to a signal form field via `[formField]`, this is written by
248
+ * the `FormField` directive.
222
249
  * @default false
223
250
  */
224
- this.touched = input(false, /* @ts-ignore */
225
- ...(ngDevMode ? [{ debugName: "touched" }] : /* istanbul ignore next */ []));
251
+ this.touched = input(false, { ...(ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
226
252
  /**
227
253
  * @description Additional CSS classes merged onto the host element via `tailwind-merge`.
228
254
  * @default ""
@@ -232,47 +258,73 @@ class SwitchComponent {
232
258
  read: () => this.#setEventListeners()
233
259
  });
234
260
  }
261
+ /**
262
+ * Toggles the switch when a label for it is clicked, as a native label does for a checkbox.
263
+ * @internal
264
+ */
265
+ activateFromLabel() {
266
+ this.focus();
267
+ this.#toggleState();
268
+ }
269
+ /**
270
+ * @description Moves focus to the switch.
271
+ * @param options Options passed to the native `focus()` call, such as `preventScroll`.
272
+ */
273
+ focus(options) {
274
+ this.#hostElementRef.nativeElement.focus(options);
275
+ }
276
+ /**
277
+ * @internal
278
+ */
279
+ setLabelledBy(id) {
280
+ this.#label.setLabelledBy(id);
281
+ }
235
282
  onBlur() {
236
283
  this.touch.emit();
237
284
  }
238
285
  #setEventListeners() {
239
286
  const host = this.#hostElementRef.nativeElement;
240
287
  const click$ = fromEvent(host, "click");
241
- const keydown$ = fromEvent(host, "keydown").pipe(filter(event => event.key === " " || event.key === "Enter"), tap(event => event.preventDefault()) // Prevent page scroll on Space
242
- );
288
+ const keydown$ = fromEvent(host, "keydown").pipe(
289
+ // Keys pressed on a control inside a handle or label template are that control's.
290
+ filter(event => event.target === host && (event.key === " " || event.key === "Enter")), tap(event => event.preventDefault()), // Prevent page scroll on Space
291
+ filter(event => !event.repeat));
243
292
  merge(click$, keydown$)
244
293
  .pipe(takeUntilDestroyed(this.#destroyRef))
245
294
  .subscribe(() => this.#toggleState());
246
295
  }
247
296
  #toggleState() {
248
- if (this.disabled()) {
297
+ if (this.effectiveDisabled() || this.readonly()) {
249
298
  return;
250
299
  }
251
300
  this.checked.set(!this.checked());
252
301
  this.touch.emit();
253
302
  }
254
303
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SwitchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
255
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: SwitchComponent, isStandalone: true, selector: "mona-switch", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, offLabel: { classPropertyName: "offLabel", publicName: "offLabel", isSignal: true, isRequired: false, transformFunction: null }, onLabel: { classPropertyName: "onLabel", publicName: "onLabel", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", touch: "touch" }, host: { listeners: { "blur": "onBlur()" }, properties: { "attr.role": "'switch'", "attr.aria-checked": "checked()", "attr.aria-disabled": "disabled() || undefined", "attr.aria-label": "ariaLabel()", "attr.aria-labelledby": "ariaLabelledBy()", "attr.tabindex": "disabled() ? -1 : 0", "attr.data-active": "checked()", "attr.data-disabled": "disabled()", "attr.data-invalid": "invalidState() || null", "attr.aria-invalid": "invalidState() ? 'true' : null", "class": "classes()" } }, queries: [{ propertyName: "handleContentTemplate", first: true, predicate: SwitchHandleContentTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "offLabelTemplate", first: true, predicate: SwitchOffLabelTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "onLabelTemplate", first: true, predicate: SwitchOnLabelTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "<span [class]=\"labelClasses()\">\n @if (checked() && !onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ onLabel() }}</span>\n }\n @if (checked() && onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"onLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<span [class]=\"labelClasses()\">\n @if (!checked() && !offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ offLabel() }}</span>\n }\n @if (!checked() && offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"offLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<div [class]=\"handleClasses()\" [attr.data-active]=\"checked()\">\n @if (handleContentTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"handleContentTemplate() ?? null\"\n [ngTemplateOutletContext]=\"{ $implicit: checked() }\"></ng-container>\n }\n</div>\n", styles: [".mona-switch-label-enter{animation:mona-switch-label-fade-in .3s ease-out}.mona-switch-label-leave{animation:mona-switch-label-fade-out .3s ease-out}@keyframes mona-switch-label-fade-in{0%{opacity:0}to{opacity:1}}@keyframes mona-switch-label-fade-out{0%{opacity:1}to{opacity:0}}@media(prefers-reduced-motion:reduce){.mona-switch-label-enter,.mona-switch-label-leave{animation-duration:1ms}}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
304
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: SwitchComponent, isStandalone: true, selector: "mona-switch", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, offLabel: { classPropertyName: "offLabel", publicName: "offLabel", isSignal: true, isRequired: false, transformFunction: null }, onLabel: { classPropertyName: "onLabel", publicName: "onLabel", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", touch: "touch" }, host: { listeners: { "blur": "onBlur()" }, properties: { "attr.role": "'switch'", "attr.aria-checked": "checked()", "attr.aria-disabled": "effectiveDisabled() || undefined", "attr.aria-label": "ariaLabel()", "attr.aria-labelledby": "labelledBy()", "attr.aria-readonly": "readonly() || null", "attr.aria-required": "required() || null", "attr.data-readonly": "readonly() || null", "attr.tabindex": "effectiveDisabled() ? -1 : tabindex()", "attr.data-active": "checked()", "attr.data-disabled": "effectiveDisabled()", "attr.data-invalid": "invalidState() || null", "attr.aria-invalid": "invalidState() ? 'true' : null", "class": "classes()" } }, queries: [{ propertyName: "handleContentTemplate", first: true, predicate: SwitchHandleContentTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "offLabelTemplate", first: true, predicate: SwitchOffLabelTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "onLabelTemplate", first: true, predicate: SwitchOnLabelTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "<span aria-hidden=\"true\" [class]=\"labelClasses()\">\n @if (checked() && !onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ onLabel() }}</span>\n }\n @if (checked() && onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"onLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<span aria-hidden=\"true\" [class]=\"labelClasses()\">\n @if (!checked() && !offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ offLabel() }}</span>\n }\n @if (!checked() && offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"offLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<div [class]=\"handleClasses()\" [attr.data-active]=\"checked()\">\n @if (handleContentTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"handleContentTemplate() ?? null\"\n [ngTemplateOutletContext]=\"{ $implicit: checked() }\"></ng-container>\n }\n</div>\n", styles: [".mona-switch-label-enter{animation:mona-switch-label-fade-in .3s ease-out}.mona-switch-label-leave{animation:mona-switch-label-fade-out .3s ease-out}@keyframes mona-switch-label-fade-in{0%{opacity:0}to{opacity:1}}@keyframes mona-switch-label-fade-out{0%{opacity:1}to{opacity:0}}@media(prefers-reduced-motion:reduce){.mona-switch-label-enter,.mona-switch-label-leave{animation-duration:1ms}}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
256
305
  }
257
306
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SwitchComponent, decorators: [{
258
307
  type: Component,
259
308
  args: [{ selector: "mona-switch", imports: [NgTemplateOutlet], host: {
260
309
  "[attr.role]": "'switch'",
261
310
  "[attr.aria-checked]": "checked()",
262
- "[attr.aria-disabled]": "disabled() || undefined",
311
+ "[attr.aria-disabled]": "effectiveDisabled() || undefined",
263
312
  "[attr.aria-label]": "ariaLabel()",
264
- "[attr.aria-labelledby]": "ariaLabelledBy()",
265
- "[attr.tabindex]": "disabled() ? -1 : 0",
313
+ "[attr.aria-labelledby]": "labelledBy()",
314
+ "[attr.aria-readonly]": "readonly() || null",
315
+ "[attr.aria-required]": "required() || null",
316
+ "[attr.data-readonly]": "readonly() || null",
317
+ "[attr.tabindex]": "effectiveDisabled() ? -1 : tabindex()",
266
318
  "[attr.data-active]": "checked()",
267
- "[attr.data-disabled]": "disabled()",
319
+ "[attr.data-disabled]": "effectiveDisabled()",
268
320
  "[attr.data-invalid]": "invalidState() || null",
269
321
  "[attr.aria-invalid]": "invalidState() ? 'true' : null",
270
322
  "[class]": "classes()",
271
323
  "(blur)": "onBlur()"
272
- }, template: "<span [class]=\"labelClasses()\">\n @if (checked() && !onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ onLabel() }}</span>\n }\n @if (checked() && onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"onLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<span [class]=\"labelClasses()\">\n @if (!checked() && !offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ offLabel() }}</span>\n }\n @if (!checked() && offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"offLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<div [class]=\"handleClasses()\" [attr.data-active]=\"checked()\">\n @if (handleContentTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"handleContentTemplate() ?? null\"\n [ngTemplateOutletContext]=\"{ $implicit: checked() }\"></ng-container>\n }\n</div>\n", styles: [".mona-switch-label-enter{animation:mona-switch-label-fade-in .3s ease-out}.mona-switch-label-leave{animation:mona-switch-label-fade-out .3s ease-out}@keyframes mona-switch-label-fade-in{0%{opacity:0}to{opacity:1}}@keyframes mona-switch-label-fade-out{0%{opacity:1}to{opacity:0}}@media(prefers-reduced-motion:reduce){.mona-switch-label-enter,.mona-switch-label-leave{animation-duration:1ms}}\n"] }]
324
+ }, template: "<span aria-hidden=\"true\" [class]=\"labelClasses()\">\n @if (checked() && !onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ onLabel() }}</span>\n }\n @if (checked() && onLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"onLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<span aria-hidden=\"true\" [class]=\"labelClasses()\">\n @if (!checked() && !offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">{{ offLabel() }}</span>\n }\n @if (!checked() && offLabelTemplate()) {\n <span animate.enter=\"mona-switch-label-enter\" animate.leave=\"mona-switch-label-leave\">\n <ng-container [ngTemplateOutlet]=\"offLabelTemplate() ?? null\"></ng-container>\n </span>\n }\n</span>\n<div [class]=\"handleClasses()\" [attr.data-active]=\"checked()\">\n @if (handleContentTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"handleContentTemplate() ?? null\"\n [ngTemplateOutletContext]=\"{ $implicit: checked() }\"></ng-container>\n }\n</div>\n", styles: [".mona-switch-label-enter{animation:mona-switch-label-fade-in .3s ease-out}.mona-switch-label-leave{animation:mona-switch-label-fade-out .3s ease-out}@keyframes mona-switch-label-fade-in{0%{opacity:0}to{opacity:1}}@keyframes mona-switch-label-fade-out{0%{opacity:1}to{opacity:0}}@media(prefers-reduced-motion:reduce){.mona-switch-label-enter,.mona-switch-label-leave{animation-duration:1ms}}\n"] }]
273
325
  }], ctorParameters: () => [], propDecorators: { handleContentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SwitchHandleContentTemplateDirective), { ...{
274
326
  read: TemplateRef
275
- }, isSignal: true }] }], offLabelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SwitchOffLabelTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], onLabelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SwitchOnLabelTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], checked: [{ type: i0.Input, args: [{ isSignal: true, alias: "checked", required: false }] }, { type: i0.Output, args: ["checkedChange"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], offLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "offLabel", required: false }] }], onLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "onLabel", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], touch: [{ type: i0.Output, args: ["touch"] }], touched: [{ type: i0.Input, args: [{ isSignal: true, alias: "touched", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }] } });
327
+ }, isSignal: true }] }], offLabelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SwitchOffLabelTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], onLabelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SwitchOnLabelTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], checked: [{ type: i0.Input, args: [{ isSignal: true, alias: "checked", required: false }] }, { type: i0.Output, args: ["checkedChange"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], offLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "offLabel", required: false }] }], onLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "onLabel", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], tabindex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabindex", required: false }] }], touch: [{ type: i0.Output, args: ["touch"] }], touched: [{ type: i0.Input, args: [{ isSignal: true, alias: "touched", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }] } });
276
328
 
277
329
  /*
278
330
  * Public API Surface of @nanahoshi/mona-ui/switch