@nanahoshi/mona-ui 0.30.0 → 0.32.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 (124) hide show
  1. package/date-range-picker/package.json +4 -0
  2. package/docs/api/button-group.md +1 -0
  3. package/docs/api/calendar.md +3 -2
  4. package/docs/api/color-gradient.md +1 -0
  5. package/docs/api/color-palette.md +1 -0
  6. package/docs/api/color-picker.md +1 -0
  7. package/docs/api/common.md +1 -1
  8. package/docs/api/date-input.md +1 -1
  9. package/docs/api/date-range-picker.md +137 -0
  10. package/docs/api/form-field.md +88 -0
  11. package/docs/api/i18n.md +84 -0
  12. package/docs/api/list.md +1 -1
  13. package/docs/api/locales.md +14 -14
  14. package/docs/api/popup.md +1 -1
  15. package/docs/api/segmented.md +1 -0
  16. package/docs/api/switch.md +1 -0
  17. package/docs/calendar.md +47 -3
  18. package/docs/date-picker.md +1 -1
  19. package/docs/date-range-picker.md +420 -0
  20. package/docs/dropdown-list.md +1 -1
  21. package/docs/form-field.md +425 -0
  22. package/docs/forms.md +13 -4
  23. package/docs/label.md +5 -5
  24. package/docs/numeric-textbox.md +1 -1
  25. package/docs/radio-button.md +2 -1
  26. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +15 -4
  27. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +25 -1
  28. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +171 -59
  29. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +5 -2
  30. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +29 -3
  31. package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +25 -1
  32. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +31 -3
  33. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +15 -4
  34. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +16 -4
  35. package/fesm2022/nanahoshi-mona-ui-date-range-picker.mjs +1331 -0
  36. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +16 -4
  37. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +19 -7
  38. package/fesm2022/nanahoshi-mona-ui-editor.mjs +24 -4
  39. package/fesm2022/nanahoshi-mona-ui-filter.mjs +1 -0
  40. package/fesm2022/nanahoshi-mona-ui-form-field.mjs +666 -0
  41. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +50 -0
  42. package/fesm2022/nanahoshi-mona-ui-i18n.mjs +7 -1
  43. package/fesm2022/nanahoshi-mona-ui-internal.mjs +27 -2
  44. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +50 -0
  45. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +32 -0
  46. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +38 -0
  47. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +38 -0
  48. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +29 -0
  49. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +38 -0
  50. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +29 -0
  51. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +29 -0
  52. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +44 -0
  53. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +38 -0
  54. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +44 -0
  55. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +32 -0
  56. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +29 -0
  57. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +29 -0
  58. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +19 -7
  59. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +14 -5
  60. package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +6 -3
  61. package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +15 -9
  62. package/fesm2022/nanahoshi-mona-ui-rating.mjs +6 -3
  63. package/fesm2022/nanahoshi-mona-ui-segmented.mjs +25 -1
  64. package/fesm2022/nanahoshi-mona-ui-slider.mjs +8 -5
  65. package/fesm2022/nanahoshi-mona-ui-switch.mjs +25 -1
  66. package/fesm2022/nanahoshi-mona-ui-text-box.mjs +6 -3
  67. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +15 -4
  68. package/form-field/package.json +4 -0
  69. package/i18n/catalogs/en-US.messages.json +29 -0
  70. package/llms.txt +5 -1
  71. package/locales/ar-sa/ar-sa.messages.json +29 -0
  72. package/locales/de-de/de-de.messages.json +29 -0
  73. package/locales/es-es/es-es.messages.json +29 -0
  74. package/locales/fr-fr/fr-fr.messages.json +29 -0
  75. package/locales/id-id/id-id.messages.json +29 -0
  76. package/locales/it-it/it-it.messages.json +29 -0
  77. package/locales/ja-jp/ja-jp.messages.json +29 -0
  78. package/locales/ko-kr/ko-kr.messages.json +29 -0
  79. package/locales/pl-pl/pl-pl.messages.json +29 -0
  80. package/locales/pt-br/pt-br.messages.json +29 -0
  81. package/locales/ru-ru/ru-ru.messages.json +29 -0
  82. package/locales/tr-tr/tr-tr.messages.json +29 -0
  83. package/locales/zh-cn/zh-cn.messages.json +29 -0
  84. package/locales/zh-tw/zh-tw.messages.json +29 -0
  85. package/package.json +9 -1
  86. package/types/nanahoshi-mona-ui-auto-complete.d.ts +2 -0
  87. package/types/nanahoshi-mona-ui-button-group.d.ts +11 -0
  88. package/types/nanahoshi-mona-ui-calendar.d.ts +66 -8
  89. package/types/nanahoshi-mona-ui-check-box.d.ts +1 -0
  90. package/types/nanahoshi-mona-ui-color-gradient.d.ts +11 -0
  91. package/types/nanahoshi-mona-ui-color-palette.d.ts +11 -0
  92. package/types/nanahoshi-mona-ui-color-picker.d.ts +11 -0
  93. package/types/nanahoshi-mona-ui-combo-box.d.ts +2 -0
  94. package/types/nanahoshi-mona-ui-date-picker.d.ts +2 -0
  95. package/types/nanahoshi-mona-ui-date-range-picker.d.ts +462 -0
  96. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +2 -0
  97. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +2 -0
  98. package/types/nanahoshi-mona-ui-form-field.d.ts +173 -0
  99. package/types/nanahoshi-mona-ui-i18n.d.ts +68 -0
  100. package/types/nanahoshi-mona-ui-internal.d.ts +39 -4
  101. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +29 -0
  102. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +29 -0
  103. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +29 -0
  104. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +29 -0
  105. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +29 -0
  106. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +29 -0
  107. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +29 -0
  108. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +29 -0
  109. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +29 -0
  110. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +29 -0
  111. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +29 -0
  112. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +29 -0
  113. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +29 -0
  114. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +29 -0
  115. package/types/nanahoshi-mona-ui-multi-select.d.ts +2 -0
  116. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +2 -0
  117. package/types/nanahoshi-mona-ui-otp-input.d.ts +1 -0
  118. package/types/nanahoshi-mona-ui-radio-button.d.ts +2 -0
  119. package/types/nanahoshi-mona-ui-rating.d.ts +1 -0
  120. package/types/nanahoshi-mona-ui-segmented.d.ts +11 -0
  121. package/types/nanahoshi-mona-ui-slider.d.ts +1 -0
  122. package/types/nanahoshi-mona-ui-switch.d.ts +11 -0
  123. package/types/nanahoshi-mona-ui-text-box.d.ts +1 -0
  124. package/types/nanahoshi-mona-ui-time-picker.d.ts +2 -0
@@ -0,0 +1,666 @@
1
+ import { NgTemplateOutlet } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { Component, Directive, TemplateRef, afterRenderEffect, booleanAttribute, computed, contentChild, inject, input, signal, viewChild } from "@angular/core";
4
+ import { FormField } from "@angular/forms/signals";
5
+ import { MonaI18nService, formatGregorianDateToLocaleString, formatNumber } from "@nanahoshi/mona-ui/i18n";
6
+ import { MONA_FORM_FIELD, MONA_LABEL, addAriaReference, createElementControlId, removeAriaReference } from "@nanahoshi/mona-ui/internal";
7
+ import { twMerge } from "tailwind-merge";
8
+ import { cva } from "class-variance-authority";
9
+ var FormFieldErrorTemplateDirective = class FormFieldErrorTemplateDirective {
10
+ static ngTemplateContextGuard(_directive, _context) {
11
+ return true;
12
+ }
13
+ static {
14
+ this.ɵfac = i0.ɵɵngDeclareFactory({
15
+ minVersion: "12.0.0",
16
+ version: "22.2.6",
17
+ ngImport: i0,
18
+ type: FormFieldErrorTemplateDirective,
19
+ deps: [],
20
+ target: i0.ɵɵFactoryTarget.Directive
21
+ });
22
+ }
23
+ static {
24
+ this.ɵdir = i0.ɵɵngDeclareDirective({
25
+ minVersion: "14.0.0",
26
+ version: "22.2.6",
27
+ type: FormFieldErrorTemplateDirective,
28
+ isStandalone: true,
29
+ selector: "ng-template[monaFormFieldErrorTemplate]",
30
+ ngImport: i0
31
+ });
32
+ }
33
+ };
34
+ i0.ɵɵngDeclareClassMetadata({
35
+ minVersion: "12.0.0",
36
+ version: "22.2.6",
37
+ ngImport: i0,
38
+ type: FormFieldErrorTemplateDirective,
39
+ decorators: [{
40
+ type: Directive,
41
+ args: [{ selector: "ng-template[monaFormFieldErrorTemplate]" }]
42
+ }]
43
+ });
44
+ var FormFieldHintTemplateDirective = class FormFieldHintTemplateDirective {
45
+ static {
46
+ this.ɵfac = i0.ɵɵngDeclareFactory({
47
+ minVersion: "12.0.0",
48
+ version: "22.2.6",
49
+ ngImport: i0,
50
+ type: FormFieldHintTemplateDirective,
51
+ deps: [],
52
+ target: i0.ɵɵFactoryTarget.Directive
53
+ });
54
+ }
55
+ static {
56
+ this.ɵdir = i0.ɵɵngDeclareDirective({
57
+ minVersion: "14.0.0",
58
+ version: "22.2.6",
59
+ type: FormFieldHintTemplateDirective,
60
+ isStandalone: true,
61
+ selector: "ng-template[monaFormFieldHintTemplate]",
62
+ ngImport: i0
63
+ });
64
+ }
65
+ };
66
+ i0.ɵɵngDeclareClassMetadata({
67
+ minVersion: "12.0.0",
68
+ version: "22.2.6",
69
+ ngImport: i0,
70
+ type: FormFieldHintTemplateDirective,
71
+ decorators: [{
72
+ type: Directive,
73
+ args: [{ selector: "ng-template[monaFormFieldHintTemplate]" }]
74
+ }]
75
+ });
76
+ var FormFieldLabelTemplateDirective = class FormFieldLabelTemplateDirective {
77
+ static {
78
+ this.ɵfac = i0.ɵɵngDeclareFactory({
79
+ minVersion: "12.0.0",
80
+ version: "22.2.6",
81
+ ngImport: i0,
82
+ type: FormFieldLabelTemplateDirective,
83
+ deps: [],
84
+ target: i0.ɵɵFactoryTarget.Directive
85
+ });
86
+ }
87
+ static {
88
+ this.ɵdir = i0.ɵɵngDeclareDirective({
89
+ minVersion: "14.0.0",
90
+ version: "22.2.6",
91
+ type: FormFieldLabelTemplateDirective,
92
+ isStandalone: true,
93
+ selector: "ng-template[monaFormFieldLabelTemplate]",
94
+ ngImport: i0
95
+ });
96
+ }
97
+ };
98
+ i0.ɵɵngDeclareClassMetadata({
99
+ minVersion: "12.0.0",
100
+ version: "22.2.6",
101
+ ngImport: i0,
102
+ type: FormFieldLabelTemplateDirective,
103
+ decorators: [{
104
+ type: Directive,
105
+ args: [{ selector: "ng-template[monaFormFieldLabelTemplate]" }]
106
+ }]
107
+ });
108
+ function localizeNumber(value, options) {
109
+ return formatNumber(value, "en-US", options);
110
+ }
111
+ const PLURAL_RULES = new Intl.PluralRules("en-US");
112
+ function plural(category, forms) {
113
+ return (forms[category] ?? forms.other)();
114
+ }
115
+ const FORM_FIELD_DEFAULT_MESSAGES = {
116
+ email: "Enter a valid email address.",
117
+ invalid: "Enter a valid value.",
118
+ max: (max) => `The value must be at most ${localizeNumber(max)}.`,
119
+ maxDate: (maxDate) => `The date must be on or before ${maxDate}.`,
120
+ maxLength: (maxLength) => `Enter at most ${plural(PLURAL_RULES.select(maxLength), {
121
+ one: () => `${localizeNumber(maxLength)} character`,
122
+ other: () => `${localizeNumber(maxLength)} characters`
123
+ })}.`,
124
+ min: (min) => `The value must be at least ${localizeNumber(min)}.`,
125
+ minDate: (minDate) => `The date must be on or after ${minDate}.`,
126
+ minLength: (minLength) => `Enter at least ${plural(PLURAL_RULES.select(minLength), {
127
+ one: () => `${localizeNumber(minLength)} character`,
128
+ other: () => `${localizeNumber(minLength)} characters`
129
+ })}.`,
130
+ optional: "Optional",
131
+ pattern: "Enter a value in the expected format.",
132
+ required: "This field is required."
133
+ };
134
+ const formFieldThemeVariants = cva(`
135
+ grid
136
+ min-w-0
137
+ `, {
138
+ variants: { orientation: {
139
+ horizontal: "grid-cols-[var(--mona-form-field-label-width,10rem)_minmax(0,1fr)] gap-x-4",
140
+ vertical: "grid-cols-1"
141
+ } },
142
+ defaultVariants: { orientation: "vertical" }
143
+ });
144
+ const formFieldLabelThemeVariants = cva(`
145
+ inline-flex
146
+ flex-wrap
147
+ items-baseline
148
+ justify-self-start
149
+ text-sm
150
+ font-medium
151
+ leading-snug
152
+ text-foreground
153
+ `, {
154
+ variants: { orientation: {
155
+ horizontal: "col-start-1 row-start-1 self-center",
156
+ vertical: "mb-1.5"
157
+ } },
158
+ defaultVariants: { orientation: "vertical" }
159
+ });
160
+ const formFieldOptionalThemeVariants = cva(`
161
+ ms-1
162
+ text-xs
163
+ font-normal
164
+ text-muted-foreground
165
+ `);
166
+ const formFieldRequiredThemeVariants = cva(`
167
+ ms-0.5
168
+ text-error
169
+ `);
170
+ const formFieldControlThemeVariants = cva(`
171
+ min-w-0
172
+ `, {
173
+ variants: { orientation: {
174
+ horizontal: "col-start-2 row-start-1",
175
+ vertical: ""
176
+ } },
177
+ defaultVariants: { orientation: "vertical" }
178
+ });
179
+ const formFieldHintThemeVariants = cva(`
180
+ mt-1.5
181
+ text-xs
182
+ text-muted-foreground
183
+ `, {
184
+ variants: { orientation: {
185
+ horizontal: "col-start-2",
186
+ vertical: ""
187
+ } },
188
+ defaultVariants: { orientation: "vertical" }
189
+ });
190
+ const formFieldErrorThemeVariants = cva(`
191
+ text-xs
192
+ text-error
193
+ `, {
194
+ variants: { orientation: {
195
+ horizontal: "col-start-2",
196
+ vertical: ""
197
+ } },
198
+ defaultVariants: { orientation: "vertical" }
199
+ });
200
+ const formFieldErrorItemThemeVariants = cva(`
201
+ mt-1.5
202
+ `);
203
+ const numberOf = (error, key) => {
204
+ const value = error[key];
205
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
206
+ };
207
+ const dateOf = (error, key) => {
208
+ const value = error[key];
209
+ return value instanceof Date && !Number.isNaN(value.getTime()) ? value : null;
210
+ };
211
+ function formFieldErrorMessage(error, messages, formatDate) {
212
+ if (error.message) return error.message;
213
+ switch (error.kind) {
214
+ case "email": return messages.email;
215
+ case "max": {
216
+ const max = numberOf(error, "max");
217
+ return max === null ? messages.invalid : messages.max(max);
218
+ }
219
+ case "maxDate": {
220
+ const maxDate = dateOf(error, "maxDate");
221
+ return maxDate === null ? messages.invalid : messages.maxDate(formatDate(maxDate));
222
+ }
223
+ case "maxLength": {
224
+ const maxLength = numberOf(error, "maxLength");
225
+ return maxLength === null ? messages.invalid : messages.maxLength(maxLength);
226
+ }
227
+ case "min": {
228
+ const min = numberOf(error, "min");
229
+ return min === null ? messages.invalid : messages.min(min);
230
+ }
231
+ case "minDate": {
232
+ const minDate = dateOf(error, "minDate");
233
+ return minDate === null ? messages.invalid : messages.minDate(formatDate(minDate));
234
+ }
235
+ case "minLength": {
236
+ const minLength = numberOf(error, "minLength");
237
+ return minLength === null ? messages.invalid : messages.minLength(minLength);
238
+ }
239
+ case "pattern": return messages.pattern;
240
+ case "required": return messages.required;
241
+ default: return messages.invalid;
242
+ }
243
+ }
244
+ const isNativeFormControl = (element) => element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
245
+ var FormFieldComponent = class FormFieldComponent {
246
+ #controls;
247
+ #i18n;
248
+ constructor() {
249
+ this.#controls = signal([], ...ngDevMode ? [{ debugName: "#controls" }] : /* istanbul ignore next */ []);
250
+ this.#i18n = inject(MonaI18nService);
251
+ this.boundField = contentChild(FormField, {
252
+ ...ngDevMode ? { debugName: "boundField" } : /* istanbul ignore next */ {},
253
+ descendants: true
254
+ });
255
+ this.captionId = createElementControlId();
256
+ this.classes = computed(() => twMerge(formFieldThemeVariants({ orientation: this.orientation() }), this.userClass()), ...ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []);
257
+ this.controlClasses = computed(() => formFieldControlThemeVariants({ orientation: this.orientation() }), ...ngDevMode ? [{ debugName: "controlClasses" }] : /* istanbul ignore next */ []);
258
+ this.controlRef = viewChild.required("control", ...ngDevMode ? [{ debugName: "controlRef" }] : /* istanbul ignore next */ []);
259
+ this.describedBy = computed(() => {
260
+ return [this.hintShown() ? this.hintId : null, this.errors().length ? this.errorId : null].filter((id) => id !== null).join(" ") || null;
261
+ }, ...ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []);
262
+ this.errorClasses = computed(() => formFieldErrorThemeVariants({ orientation: this.orientation() }), ...ngDevMode ? [{ debugName: "errorClasses" }] : /* istanbul ignore next */ []);
263
+ this.errorId = createElementControlId();
264
+ this.errorItemClasses = formFieldErrorItemThemeVariants();
265
+ this.errorTemplate = contentChild(FormFieldErrorTemplateDirective, {
266
+ ...ngDevMode ? { debugName: "errorTemplate" } : /* istanbul ignore next */ {},
267
+ read: TemplateRef
268
+ });
269
+ this.errors = computed(() => {
270
+ const shown = [];
271
+ const ownError = this.error();
272
+ if (ownError) shown.push({
273
+ $implicit: ownError,
274
+ error: null,
275
+ message: ownError
276
+ });
277
+ const field = this.boundField();
278
+ if (field?.state().touched()) {
279
+ const messages = this.messages();
280
+ const localeId = this.#i18n.localeId();
281
+ const formatDate = (date) => formatGregorianDateToLocaleString(date, localeId, {
282
+ year: "numeric",
283
+ month: "long",
284
+ day: "numeric"
285
+ });
286
+ for (const error of field.errors()) {
287
+ const message = formFieldErrorMessage(error, messages, formatDate);
288
+ shown.push({
289
+ $implicit: message,
290
+ error,
291
+ message
292
+ });
293
+ }
294
+ }
295
+ return shown;
296
+ }, ...ngDevMode ? [{ debugName: "errors" }] : /* istanbul ignore next */ []);
297
+ this.hintClasses = computed(() => formFieldHintThemeVariants({ orientation: this.orientation() }), ...ngDevMode ? [{ debugName: "hintClasses" }] : /* istanbul ignore next */ []);
298
+ this.hintId = createElementControlId();
299
+ this.hintShown = computed(() => !!this.hint() || !!this.hintTemplate(), ...ngDevMode ? [{ debugName: "hintShown" }] : /* istanbul ignore next */ []);
300
+ this.hintTemplate = contentChild(FormFieldHintTemplateDirective, {
301
+ ...ngDevMode ? { debugName: "hintTemplate" } : /* istanbul ignore next */ {},
302
+ read: TemplateRef
303
+ });
304
+ this.labelClasses = computed(() => formFieldLabelThemeVariants({ orientation: this.orientation() }), ...ngDevMode ? [{ debugName: "labelClasses" }] : /* istanbul ignore next */ []);
305
+ this.labelShown = computed(() => !!this.label() || !!this.labelTemplate(), ...ngDevMode ? [{ debugName: "labelShown" }] : /* istanbul ignore next */ []);
306
+ this.labelTemplate = contentChild(FormFieldLabelTemplateDirective, {
307
+ ...ngDevMode ? { debugName: "labelTemplate" } : /* istanbul ignore next */ {},
308
+ read: TemplateRef
309
+ });
310
+ this.messages = this.#i18n.componentMessages("formField", FORM_FIELD_DEFAULT_MESSAGES);
311
+ this.optionalClasses = formFieldOptionalThemeVariants();
312
+ this.requiredClasses = formFieldRequiredThemeVariants();
313
+ this.requiredShown = computed(() => this.showRequiredMarker() && (this.required() || (this.boundField()?.state().required() ?? false)), ...ngDevMode ? [{ debugName: "requiredShown" }] : /* istanbul ignore next */ []);
314
+ this.error = input("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
315
+ this.fieldContext = {
316
+ describedBy: this.describedBy,
317
+ register: (control) => {
318
+ this.#controls.update((controls) => [...controls, control]);
319
+ return () => this.#controls.update((controls) => controls.filter((registered) => registered !== control));
320
+ }
321
+ };
322
+ this.hint = input("", ...ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []);
323
+ this.label = input("", ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
324
+ this.labelContext = {
325
+ captionId: computed(() => this.labelShown() ? this.captionId : null),
326
+ register: () => () => void 0
327
+ };
328
+ this.optional = input(false, {
329
+ ...ngDevMode ? { debugName: "optional" } : /* istanbul ignore next */ {},
330
+ transform: booleanAttribute
331
+ });
332
+ this.optionalText = input("", ...ngDevMode ? [{ debugName: "optionalText" }] : /* istanbul ignore next */ []);
333
+ this.orientation = input("vertical", ...ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []);
334
+ this.required = input(false, {
335
+ ...ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {},
336
+ transform: booleanAttribute
337
+ });
338
+ this.showRequiredMarker = input(true, {
339
+ ...ngDevMode ? { debugName: "showRequiredMarker" } : /* istanbul ignore next */ {},
340
+ transform: booleanAttribute
341
+ });
342
+ this.userClass = input("", {
343
+ ...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
344
+ alias: "class"
345
+ });
346
+ afterRenderEffect({ write: (onCleanup) => {
347
+ const target = this.#nativeTarget();
348
+ if (!target) return;
349
+ const labelId = this.labelContext.captionId();
350
+ const named = target.hasAttribute("aria-label") || target.hasAttribute("aria-labelledby");
351
+ const labelledBy = labelId && !named ? labelId : null;
352
+ const describedBy = this.describedBy()?.split(" ") ?? [];
353
+ const invalid = this.errors().length > 0 && !target.hasAttribute("aria-invalid");
354
+ if (labelledBy) addAriaReference(target, "aria-labelledby", labelledBy);
355
+ for (const id of describedBy) addAriaReference(target, "aria-describedby", id);
356
+ if (invalid) target.setAttribute("aria-invalid", "true");
357
+ onCleanup(() => {
358
+ if (labelledBy) removeAriaReference(target, "aria-labelledby", labelledBy);
359
+ for (const id of describedBy) removeAriaReference(target, "aria-describedby", id);
360
+ if (invalid) target.removeAttribute("aria-invalid");
361
+ });
362
+ } });
363
+ }
364
+ onLabelClick(event) {
365
+ if (event.defaultPrevented) return;
366
+ const [control] = this.#controls();
367
+ if (control) {
368
+ (control.activate ?? control.focus)();
369
+ return;
370
+ }
371
+ this.#nativeTarget()?.focus();
372
+ }
373
+ #nativeTarget() {
374
+ if (this.#controls().length) return null;
375
+ const bound = this.boundField()?.element;
376
+ if (isNativeFormControl(bound)) return bound;
377
+ const found = this.controlRef().nativeElement.querySelector("input:not([type='hidden']), select, textarea");
378
+ return isNativeFormControl(found) ? found : null;
379
+ }
380
+ static {
381
+ this.ɵfac = i0.ɵɵngDeclareFactory({
382
+ minVersion: "12.0.0",
383
+ version: "22.2.6",
384
+ ngImport: i0,
385
+ type: FormFieldComponent,
386
+ deps: [],
387
+ target: i0.ɵɵFactoryTarget.Component
388
+ });
389
+ }
390
+ static {
391
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
392
+ minVersion: "17.0.0",
393
+ version: "22.2.6",
394
+ type: FormFieldComponent,
395
+ isStandalone: true,
396
+ selector: "mona-form-field",
397
+ inputs: {
398
+ error: {
399
+ classPropertyName: "error",
400
+ publicName: "error",
401
+ isSignal: true,
402
+ isRequired: false,
403
+ transformFunction: null
404
+ },
405
+ hint: {
406
+ classPropertyName: "hint",
407
+ publicName: "hint",
408
+ isSignal: true,
409
+ isRequired: false,
410
+ transformFunction: null
411
+ },
412
+ label: {
413
+ classPropertyName: "label",
414
+ publicName: "label",
415
+ isSignal: true,
416
+ isRequired: false,
417
+ transformFunction: null
418
+ },
419
+ optional: {
420
+ classPropertyName: "optional",
421
+ publicName: "optional",
422
+ isSignal: true,
423
+ isRequired: false,
424
+ transformFunction: null
425
+ },
426
+ optionalText: {
427
+ classPropertyName: "optionalText",
428
+ publicName: "optionalText",
429
+ isSignal: true,
430
+ isRequired: false,
431
+ transformFunction: null
432
+ },
433
+ orientation: {
434
+ classPropertyName: "orientation",
435
+ publicName: "orientation",
436
+ isSignal: true,
437
+ isRequired: false,
438
+ transformFunction: null
439
+ },
440
+ required: {
441
+ classPropertyName: "required",
442
+ publicName: "required",
443
+ isSignal: true,
444
+ isRequired: false,
445
+ transformFunction: null
446
+ },
447
+ showRequiredMarker: {
448
+ classPropertyName: "showRequiredMarker",
449
+ publicName: "showRequiredMarker",
450
+ isSignal: true,
451
+ isRequired: false,
452
+ transformFunction: null
453
+ },
454
+ userClass: {
455
+ classPropertyName: "userClass",
456
+ publicName: "class",
457
+ isSignal: true,
458
+ isRequired: false,
459
+ transformFunction: null
460
+ }
461
+ },
462
+ host: { properties: {
463
+ "attr.data-invalid": "errors().length > 0 || null",
464
+ "attr.data-orientation": "orientation()",
465
+ "attr.data-required": "requiredShown() || null",
466
+ "class": "classes()"
467
+ } },
468
+ providers: [{
469
+ provide: MONA_LABEL,
470
+ useFactory: () => inject(FormFieldComponent).labelContext
471
+ }, {
472
+ provide: MONA_FORM_FIELD,
473
+ useFactory: () => inject(FormFieldComponent).fieldContext
474
+ }],
475
+ queries: [
476
+ {
477
+ propertyName: "boundField",
478
+ first: true,
479
+ predicate: FormField,
480
+ descendants: true,
481
+ isSignal: true
482
+ },
483
+ {
484
+ propertyName: "errorTemplate",
485
+ first: true,
486
+ predicate: FormFieldErrorTemplateDirective,
487
+ descendants: true,
488
+ read: TemplateRef,
489
+ isSignal: true
490
+ },
491
+ {
492
+ propertyName: "hintTemplate",
493
+ first: true,
494
+ predicate: FormFieldHintTemplateDirective,
495
+ descendants: true,
496
+ read: TemplateRef,
497
+ isSignal: true
498
+ },
499
+ {
500
+ propertyName: "labelTemplate",
501
+ first: true,
502
+ predicate: FormFieldLabelTemplateDirective,
503
+ descendants: true,
504
+ read: TemplateRef,
505
+ isSignal: true
506
+ }
507
+ ],
508
+ viewQueries: [{
509
+ propertyName: "controlRef",
510
+ first: true,
511
+ predicate: ["control"],
512
+ descendants: true,
513
+ isSignal: true
514
+ }],
515
+ ngImport: i0,
516
+ template: "@if (labelShown()) {\n <label [id]=\"captionId\" [class]=\"labelClasses()\" (click)=\"onLabelClick($event)\">\n @if (labelTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\"></ng-container>\n } @else {\n <span>{{ label() }}</span>\n }\n @if (optional()) {\n <span [class]=\"optionalClasses\">{{ optionalText() || messages().optional }}</span>\n }\n @if (requiredShown()) {\n <span aria-hidden=\"true\" [class]=\"requiredClasses\">*</span>\n }\n </label>\n}\n<div #control [class]=\"controlClasses()\">\n <ng-content></ng-content>\n</div>\n@if (hintShown()) {\n <div [id]=\"hintId\" [class]=\"hintClasses()\">\n @if (hintTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\"></ng-container>\n } @else {\n {{ hint() }}\n }\n </div>\n}\n<div [id]=\"errorId\" [class]=\"errorClasses()\" aria-live=\"polite\">\n @for (item of errors(); track $index) {\n <div [class]=\"errorItemClasses\">\n @if (errorTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"item\"></ng-container>\n } @else {\n {{ item.message }}\n }\n </div>\n }\n</div>\n",
517
+ dependencies: [{
518
+ kind: "directive",
519
+ type: NgTemplateOutlet,
520
+ selector: "[ngTemplateOutlet]",
521
+ inputs: [
522
+ "ngTemplateOutletContext",
523
+ "ngTemplateOutlet",
524
+ "ngTemplateOutletInjector"
525
+ ]
526
+ }]
527
+ });
528
+ }
529
+ };
530
+ i0.ɵɵngDeclareClassMetadata({
531
+ minVersion: "12.0.0",
532
+ version: "22.2.6",
533
+ ngImport: i0,
534
+ type: FormFieldComponent,
535
+ decorators: [{
536
+ type: Component,
537
+ args: [{
538
+ selector: "mona-form-field",
539
+ imports: [NgTemplateOutlet],
540
+ providers: [{
541
+ provide: MONA_LABEL,
542
+ useFactory: () => inject(FormFieldComponent).labelContext
543
+ }, {
544
+ provide: MONA_FORM_FIELD,
545
+ useFactory: () => inject(FormFieldComponent).fieldContext
546
+ }],
547
+ host: {
548
+ "[attr.data-invalid]": "errors().length > 0 || null",
549
+ "[attr.data-orientation]": "orientation()",
550
+ "[attr.data-required]": "requiredShown() || null",
551
+ "[class]": "classes()"
552
+ },
553
+ template: "@if (labelShown()) {\n <label [id]=\"captionId\" [class]=\"labelClasses()\" (click)=\"onLabelClick($event)\">\n @if (labelTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\"></ng-container>\n } @else {\n <span>{{ label() }}</span>\n }\n @if (optional()) {\n <span [class]=\"optionalClasses\">{{ optionalText() || messages().optional }}</span>\n }\n @if (requiredShown()) {\n <span aria-hidden=\"true\" [class]=\"requiredClasses\">*</span>\n }\n </label>\n}\n<div #control [class]=\"controlClasses()\">\n <ng-content></ng-content>\n</div>\n@if (hintShown()) {\n <div [id]=\"hintId\" [class]=\"hintClasses()\">\n @if (hintTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\"></ng-container>\n } @else {\n {{ hint() }}\n }\n </div>\n}\n<div [id]=\"errorId\" [class]=\"errorClasses()\" aria-live=\"polite\">\n @for (item of errors(); track $index) {\n <div [class]=\"errorItemClasses\">\n @if (errorTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"item\"></ng-container>\n } @else {\n {{ item.message }}\n }\n </div>\n }\n</div>\n"
554
+ }]
555
+ }],
556
+ ctorParameters: () => [],
557
+ propDecorators: {
558
+ boundField: [{
559
+ type: i0.ContentChild,
560
+ args: [i0.forwardRef(() => FormField), {
561
+ descendants: true,
562
+ isSignal: true
563
+ }]
564
+ }],
565
+ controlRef: [{
566
+ type: i0.ViewChild,
567
+ args: ["control", { isSignal: true }]
568
+ }],
569
+ errorTemplate: [{
570
+ type: i0.ContentChild,
571
+ args: [i0.forwardRef(() => FormFieldErrorTemplateDirective), {
572
+ read: TemplateRef,
573
+ isSignal: true
574
+ }]
575
+ }],
576
+ hintTemplate: [{
577
+ type: i0.ContentChild,
578
+ args: [i0.forwardRef(() => FormFieldHintTemplateDirective), {
579
+ read: TemplateRef,
580
+ isSignal: true
581
+ }]
582
+ }],
583
+ labelTemplate: [{
584
+ type: i0.ContentChild,
585
+ args: [i0.forwardRef(() => FormFieldLabelTemplateDirective), {
586
+ read: TemplateRef,
587
+ isSignal: true
588
+ }]
589
+ }],
590
+ error: [{
591
+ type: i0.Input,
592
+ args: [{
593
+ isSignal: true,
594
+ alias: "error",
595
+ required: false
596
+ }]
597
+ }],
598
+ hint: [{
599
+ type: i0.Input,
600
+ args: [{
601
+ isSignal: true,
602
+ alias: "hint",
603
+ required: false
604
+ }]
605
+ }],
606
+ label: [{
607
+ type: i0.Input,
608
+ args: [{
609
+ isSignal: true,
610
+ alias: "label",
611
+ required: false
612
+ }]
613
+ }],
614
+ optional: [{
615
+ type: i0.Input,
616
+ args: [{
617
+ isSignal: true,
618
+ alias: "optional",
619
+ required: false
620
+ }]
621
+ }],
622
+ optionalText: [{
623
+ type: i0.Input,
624
+ args: [{
625
+ isSignal: true,
626
+ alias: "optionalText",
627
+ required: false
628
+ }]
629
+ }],
630
+ orientation: [{
631
+ type: i0.Input,
632
+ args: [{
633
+ isSignal: true,
634
+ alias: "orientation",
635
+ required: false
636
+ }]
637
+ }],
638
+ required: [{
639
+ type: i0.Input,
640
+ args: [{
641
+ isSignal: true,
642
+ alias: "required",
643
+ required: false
644
+ }]
645
+ }],
646
+ showRequiredMarker: [{
647
+ type: i0.Input,
648
+ args: [{
649
+ isSignal: true,
650
+ alias: "showRequiredMarker",
651
+ required: false
652
+ }]
653
+ }],
654
+ userClass: [{
655
+ type: i0.Input,
656
+ args: [{
657
+ isSignal: true,
658
+ alias: "class",
659
+ required: false
660
+ }]
661
+ }]
662
+ }
663
+ });
664
+ export { FormFieldComponent, FormFieldErrorTemplateDirective, FormFieldHintTemplateDirective, FormFieldLabelTemplateDirective };
665
+
666
+ //# sourceMappingURL=nanahoshi-mona-ui-form-field.mjs.map