@frontile/forms 0.17.0-beta.24 → 0.17.0-beta.26
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.
- package/declarations/components/checkbox-group.d.ts +3 -1
- package/declarations/components/checkbox.d.ts +2 -0
- package/declarations/components/field-types.d.ts +14 -0
- package/declarations/components/field.d.ts +85 -0
- package/declarations/components/form-control.d.ts +1 -0
- package/declarations/components/form.d.ts +244 -8
- package/declarations/components/input.d.ts +5 -0
- package/declarations/components/radio-group.d.ts +1 -1
- package/declarations/components/radio.d.ts +2 -0
- package/declarations/components/select.d.ts +228 -13
- package/declarations/components/switch.d.ts +21 -16
- package/declarations/components/textarea.d.ts +2 -0
- package/declarations/index.d.ts +3 -0
- package/declarations/utils/index.d.ts +1 -0
- package/declarations/utils/nested-data.d.ts +44 -0
- package/declarations/utils/standard-validator.d.ts +151 -0
- package/dist/_app_/components/field-types.js +1 -0
- package/dist/_app_/components/field.js +1 -0
- package/dist/components/checkbox-group.js +1 -1
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/checkbox.js +8 -2
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/field-types.js +2 -0
- package/dist/components/field-types.js.map +1 -0
- package/dist/components/field.js +103 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/form-control.js.map +1 -1
- package/dist/components/form.js +12 -29
- package/dist/components/form.js.map +1 -1
- package/dist/components/input.js +8 -2
- package/dist/components/input.js.map +1 -1
- package/dist/components/native-select.js +1 -1
- package/dist/components/radio-group.js +1 -1
- package/dist/components/radio-group.js.map +1 -1
- package/dist/components/radio.js +8 -2
- package/dist/components/radio.js.map +1 -1
- package/dist/components/select.js +165 -20
- package/dist/components/select.js.map +1 -1
- package/dist/components/switch.js +5 -2
- package/dist/components/switch.js.map +1 -1
- package/dist/components/textarea.js +8 -2
- package/dist/components/textarea.js.map +1 -1
- package/dist/form-CVuJDJUq.js +726 -0
- package/dist/form-CVuJDJUq.js.map +1 -0
- package/dist/form-Dzyb1-8B.js +623 -0
- package/dist/form-Dzyb1-8B.js.map +1 -0
- package/dist/index-CeaQc-U7.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime-BPCpkOf1-B5Lbloj7.js +67 -0
- package/dist/runtime-BPCpkOf1-B5Lbloj7.js.map +1 -0
- package/dist/test-support.js +2 -2
- package/dist/test-support.js.map +1 -1
- package/package.json +10 -7
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
/**
|
|
3
|
+
* The issues collection returned by a Standard Schema validation failure.
|
|
4
|
+
*/
|
|
5
|
+
export type Issues = readonly StandardSchemaV1.Issue[];
|
|
6
|
+
/**
|
|
7
|
+
* The return type of a validator function.
|
|
8
|
+
* Resolves to the issues (when validation fails) or undefined
|
|
9
|
+
* (when it succeeds).
|
|
10
|
+
*/
|
|
11
|
+
export type ValidatorReturn = Promise<Issues | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* StandardSchemaV1 issues as either a promise or synchronous. If there are
|
|
14
|
+
* no issues, `undefined` is returned.
|
|
15
|
+
*/
|
|
16
|
+
export type CustomValidatorReturn = ValidatorReturn | Issues | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A custom validator function.
|
|
19
|
+
* If there are errors, they are returned by the validator as
|
|
20
|
+
* StandardSchemaV1 issues. If there are no errors, nothing is returned.
|
|
21
|
+
*/
|
|
22
|
+
export type CustomValidatorFn<Input = unknown> = (input: Input) => CustomValidatorReturn;
|
|
23
|
+
/**
|
|
24
|
+
* Provides convenience methods for validating data using Standard Schema.
|
|
25
|
+
* Also supports custom validator functions that return issues in the
|
|
26
|
+
* Standard Schema format.
|
|
27
|
+
*
|
|
28
|
+
* Most of the time you should use `validateAll` or `validateFieldAll` to
|
|
29
|
+
* validate data. Schema and custom validation are optional arguments
|
|
30
|
+
* to these methods. This is useful because schema and custom validation
|
|
31
|
+
* must both be optional in the form component, which is the primary use
|
|
32
|
+
* case for this class.
|
|
33
|
+
*
|
|
34
|
+
* Note: all methods are static, so you do not need to instantiate
|
|
35
|
+
* this class.
|
|
36
|
+
*
|
|
37
|
+
* @see https://standardschema.dev/
|
|
38
|
+
*/
|
|
39
|
+
declare class StandardValidator {
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Validates data against the provided standard schema.
|
|
43
|
+
* If there are errors, they are returned. Otherwise, nothing is returned.
|
|
44
|
+
* This provides a boolean indication of outcome: if there is a return
|
|
45
|
+
* value, validation failed. Otherwise, validation succeeded.
|
|
46
|
+
* @see https://standardschema.dev/
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const input = …; // your data to validate
|
|
50
|
+
* const schema = …; // your standard schema
|
|
51
|
+
* const issues = await StandardValidator.validate(input, schema);
|
|
52
|
+
*
|
|
53
|
+
* @param input The input to validate.
|
|
54
|
+
* @param schema The standard schema to validate against.
|
|
55
|
+
* @return The issues if validation failed, otherwise undefined.
|
|
56
|
+
*/
|
|
57
|
+
static validate<I, O>(input: I, schema: StandardSchemaV1<I, O>): ValidatorReturn;
|
|
58
|
+
/**
|
|
59
|
+
* Validates a single field within the input data using the provided
|
|
60
|
+
* standard schema. If there are issues related to the specified field,
|
|
61
|
+
* they are returned. Otherwise, nothing is returned.
|
|
62
|
+
*
|
|
63
|
+
* Note: because standard schema does not provide a way to validate
|
|
64
|
+
* individual fields, this method filters the issues returned by the
|
|
65
|
+
* schema validation to find those related to the specified field.
|
|
66
|
+
* @see https://standardschema.dev/
|
|
67
|
+
*
|
|
68
|
+
* @param input The input data to validate.
|
|
69
|
+
* @param fieldName The name of the field to validate.
|
|
70
|
+
* @param schema The standard schema to validate against.
|
|
71
|
+
* @returns The issues related to the specified field if validation failed,
|
|
72
|
+
* otherwise undefined.
|
|
73
|
+
*/
|
|
74
|
+
static validateField<I, O>(input: I, fieldName: string, schema: StandardSchemaV1<I, O>): ValidatorReturn;
|
|
75
|
+
/**
|
|
76
|
+
* Validates input using a custom validator function.
|
|
77
|
+
* If there are errors, they are returned by the validator as
|
|
78
|
+
* StandardSchemaV1 issues. If there are no errors, nothing is returned.
|
|
79
|
+
* @see https://standardschema.dev/
|
|
80
|
+
*
|
|
81
|
+
* @param input The input data to validate.
|
|
82
|
+
* @param customValidator The custom validator function to use.
|
|
83
|
+
* @returns The issues if validation failed, otherwise undefined.
|
|
84
|
+
*/
|
|
85
|
+
static validateCustom<I>(input: I, customValidator: CustomValidatorFn<I>): ValidatorReturn;
|
|
86
|
+
/**
|
|
87
|
+
* Validates a single field within the input data using a custom validator
|
|
88
|
+
* function. If there are issues related to the specified field, they are
|
|
89
|
+
* returned. Otherwise, nothing is returned.
|
|
90
|
+
*
|
|
91
|
+
* Note: because custom validators may return issues for multiple fields,
|
|
92
|
+
* this method filters the issues returned by the custom validator to find
|
|
93
|
+
* those related to the specified field.
|
|
94
|
+
* @see https://standardschema.dev/
|
|
95
|
+
*
|
|
96
|
+
* @param input The input data to validate.
|
|
97
|
+
* @param fieldName The name of the field to validate.
|
|
98
|
+
* @param customValidator The custom validator function to use.
|
|
99
|
+
* @returns The issues related to the specified field if validation failed,
|
|
100
|
+
* otherwise undefined.
|
|
101
|
+
*/
|
|
102
|
+
static validateFieldCustom<I>(input: I, fieldName: string, customValidator: CustomValidatorFn<I>): ValidatorReturn;
|
|
103
|
+
/**
|
|
104
|
+
* Validates input data using both a standard schema and a custom validator
|
|
105
|
+
* function, merging any issues found by either method. If there are issues,
|
|
106
|
+
* they are returned. Otherwise, nothing is returned. This method runs both
|
|
107
|
+
* validations in parallel.
|
|
108
|
+
*
|
|
109
|
+
* Note: `schema` and `customValidator` are both optional. If either the
|
|
110
|
+
* schema or custom validator is not provided, that validation is skipped.
|
|
111
|
+
* @see https://standardschema.dev/
|
|
112
|
+
*
|
|
113
|
+
* @param input The input data to validate.
|
|
114
|
+
* @param schema Optional standard schema to validate against.
|
|
115
|
+
* @param customValidator Optional custom validator function to use.
|
|
116
|
+
* @returns issues if validation failed, otherwise undefined.
|
|
117
|
+
*/
|
|
118
|
+
static validateAll<I, O>(input: I, schema?: StandardSchemaV1<I, O>, customValidator?: CustomValidatorFn<I>): ValidatorReturn;
|
|
119
|
+
/**
|
|
120
|
+
* Validates a single field within the input data using both a standard
|
|
121
|
+
* schema and a custom validator function, merging any issues found by
|
|
122
|
+
* either method. If there are issues related to the specified field,
|
|
123
|
+
* they are returned. Otherwise, nothing is returned. This method runs
|
|
124
|
+
* both validations in parallel.
|
|
125
|
+
*
|
|
126
|
+
* Note: `schema` and `customValidator` are both optional. If either the
|
|
127
|
+
* schema or custom validator is not provided, that validation is skipped.
|
|
128
|
+
* @see https://standardschema.dev/
|
|
129
|
+
*
|
|
130
|
+
* @param input The input data to validate.
|
|
131
|
+
* @param fieldName The name of the field to validate.
|
|
132
|
+
* @param schema Optional standard schema to validate against.
|
|
133
|
+
* @param customValidator Optional custom validator function to use.
|
|
134
|
+
* @returns The issues related to the specified field if validation failed,
|
|
135
|
+
* otherwise undefined.
|
|
136
|
+
*/
|
|
137
|
+
static validateFieldAll<I, O>(input: I, fieldName: string, schema?: StandardSchemaV1<I, O>, customValidator?: CustomValidatorFn<I>): ValidatorReturn;
|
|
138
|
+
/**
|
|
139
|
+
* Filters issues to those related to the specified field name.
|
|
140
|
+
* Supports both simple field names and dotted notation for nested fields.
|
|
141
|
+
*
|
|
142
|
+
* @param issues The issues to filter.
|
|
143
|
+
* @param fieldName The name of the field to filter by (e.g., "email" or
|
|
144
|
+
* "profile.contact.email").
|
|
145
|
+
* @returns The issues related to the specified field, or undefined if
|
|
146
|
+
* there are none.
|
|
147
|
+
*/
|
|
148
|
+
static filterFieldIssues(issues: Issues, fieldName: string): Issues | undefined;
|
|
149
|
+
}
|
|
150
|
+
export { StandardValidator };
|
|
151
|
+
export default StandardValidator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@frontile/forms/components/field-types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@frontile/forms/components/field";
|
|
@@ -15,7 +15,7 @@ class CheckboxGroup extends Component {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
static {
|
|
18
|
-
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} ...attributes as |c|>\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div class={{this.classes.optionsContainer class=@classes.optionsContainer}} data-orientation={{if @orientation @orientation \"vertical\"}}>\n {{yield (component Checkbox name=@name onChange=@onChange size=@size) to=\"default\"}}\n </div>\n </FormControl>\n ", {
|
|
18
|
+
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} ...attributes as |c|>\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div class={{this.classes.optionsContainer class=@classes.optionsContainer}} data-orientation={{if @orientation @orientation \"vertical\"}}>\n {{yield (component Checkbox name=@name onChange=@onChange size=@size isDisabled=@isDisabled) to=\"default\"}}\n </div>\n </FormControl>\n ", {
|
|
19
19
|
strictMode: true,
|
|
20
20
|
scope: () => ({
|
|
21
21
|
FormControl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox-group.js","sources":["../../src/components/checkbox-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { Checkbox, type CheckboxSignature } from './checkbox';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport {\n useStyles,\n type CheckboxGroupVariants,\n type CheckboxGroupSlots,\n type SlotsToClasses\n} from '@frontile/theme';\nimport type { WithBoundArgs } from '@glint/template';\n\ninterface Args extends FormControlSharedArgs {\n name?: string;\n onChange?: CheckboxSignature['Args']['onChange'];\n size?: CheckboxGroupVariants['size'];\n classes?: SlotsToClasses<CheckboxGroupSlots>;\n\n /*\n *\n * @defaultValue 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n}\n\ninterface CheckboxGroupSignature {\n Args: Args;\n Blocks: {\n default: [Checkbox: WithBoundArgs
|
|
1
|
+
{"version":3,"file":"checkbox-group.js","sources":["../../src/components/checkbox-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { Checkbox, type CheckboxSignature } from './checkbox';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport {\n useStyles,\n type CheckboxGroupVariants,\n type CheckboxGroupSlots,\n type SlotsToClasses\n} from '@frontile/theme';\nimport type { WithBoundArgs } from '@glint/template';\n\ninterface Args extends FormControlSharedArgs {\n name?: string;\n onChange?: CheckboxSignature['Args']['onChange'];\n size?: CheckboxGroupVariants['size'];\n classes?: SlotsToClasses<CheckboxGroupSlots>;\n\n /*\n *\n * @defaultValue 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n}\n\ninterface CheckboxGroupSignature {\n Args: Args;\n Blocks: {\n default: [\n Checkbox: WithBoundArgs<\n typeof Checkbox,\n 'name' | 'onChange' | 'isDisabled'\n >\n ];\n };\n Element: HTMLDivElement;\n}\n\nclass CheckboxGroup extends Component<CheckboxGroupSignature> {\n get classes() {\n const { checkboxGroup } = useStyles();\n return checkboxGroup({\n size: this.args.size\n });\n }\n\n <template>\n <FormControl\n @size={{@size}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n @class={{this.classes.base class=@classes.base}}\n ...attributes\n as |c|\n >\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div\n class={{this.classes.optionsContainer class=@classes.optionsContainer}}\n data-orientation={{if @orientation @orientation \"vertical\"}}\n >\n {{yield\n (component\n Checkbox\n name=@name\n onChange=@onChange\n size=@size\n isDisabled=@isDisabled\n )\n to=\"default\"\n }}\n </div>\n </FormControl>\n </template>\n}\n\nexport { CheckboxGroup, type CheckboxGroupSignature };\nexport default CheckboxGroup;\n"],"names":["CheckboxGroup","Component","classes","checkboxGroup","useStyles","size","args","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","Checkbox"],"mappings":";;;;;;;AAqCA,MAAMA,sBAAsBC,SAAA,CAAU;EACpC,IAAIC,OAAAA,GAAU;IACZ,MAAM;AAAEC,MAAAA;KAAe,GAAGC,SAAA,EAAA;AAC1B,IAAA,OAAOD,aAAA,CAAc;AACnBE,MAAAA,IAAA,EAAM,IAAI,CAACC,IAAI,CAACD;AAClB,KAAA,CAAA;AACF,EAAA;AAEA,EAAA;IAAAE,oBAAA,CAAAC,kBAAA,CAAA,8mBAAA,EA8BA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -5,7 +5,7 @@ import { FormControl } from './form-control.js';
|
|
|
5
5
|
import { useStyles } from '@frontile/theme';
|
|
6
6
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
7
7
|
import { setComponentTemplate } from '@ember/component';
|
|
8
|
-
import {
|
|
8
|
+
import { a as decorateMethodV2 } from '../runtime-BPCpkOf1-B5Lbloj7.js';
|
|
9
9
|
|
|
10
10
|
class Checkbox extends Component {
|
|
11
11
|
get isChecked() {
|
|
@@ -21,6 +21,12 @@ class Checkbox extends Component {
|
|
|
21
21
|
static {
|
|
22
22
|
decorateMethodV2(this.prototype, "handleChange", [action]);
|
|
23
23
|
}
|
|
24
|
+
handleBlur() {
|
|
25
|
+
this.args.onBlur?.();
|
|
26
|
+
}
|
|
27
|
+
static {
|
|
28
|
+
decorateMethodV2(this.prototype, "handleBlur", [action]);
|
|
29
|
+
}
|
|
24
30
|
get classes() {
|
|
25
31
|
const {
|
|
26
32
|
checkbox
|
|
@@ -30,7 +36,7 @@ class Checkbox extends Component {
|
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
static {
|
|
33
|
-
setComponentTemplate(precompileTemplate("\n <FormControl @isInvalid={{@isInvalid}} @errors={{@errors}} @size={{@size}} @isRequired={{@isRequired}} @class={{this.classes.base class=@classes.base}} @preventErrorFeedback={{true}} as |c|>\n <input {{on \"change\" this.handleChange}} id={{c.id}} name={{@name}} checked={{this.isChecked}} type=\"checkbox\" class={{this.classes.input class=@classes.input}} data-component=\"checkbox\" aria-invalid={{if c.isInvalid \"true\"}} aria-describedby={{c.describedBy @description c.isInvalid}} ...attributes />\n <div class={{this.classes.labelContainer class=@classes.labelContainer}}>\n {{#if @label}}\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n {{/if}}\n {{#if @description}}\n <c.Description>{{@description}}</c.Description>\n {{/if}}\n {{#if c.isInvalid}}\n <c.Feedback />\n {{/if}}\n </div>\n </FormControl>\n ", {
|
|
39
|
+
setComponentTemplate(precompileTemplate("\n <FormControl @isInvalid={{@isInvalid}} @errors={{@errors}} @size={{@size}} @isRequired={{@isRequired}} @class={{this.classes.base class=@classes.base}} @preventErrorFeedback={{true}} as |c|>\n <input {{on \"change\" this.handleChange}} {{on \"blur\" this.handleBlur}} id={{c.id}} name={{@name}} checked={{this.isChecked}} type=\"checkbox\" disabled={{@isDisabled}} class={{this.classes.input class=@classes.input}} data-component=\"checkbox\" aria-invalid={{if c.isInvalid \"true\"}} aria-describedby={{c.describedBy @description c.isInvalid}} ...attributes />\n <div class={{this.classes.labelContainer class=@classes.labelContainer}}>\n {{#if @label}}\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n {{/if}}\n {{#if @description}}\n <c.Description>{{@description}}</c.Description>\n {{/if}}\n {{#if c.isInvalid}}\n <c.Feedback />\n {{/if}}\n </div>\n </FormControl>\n ", {
|
|
34
40
|
strictMode: true,
|
|
35
41
|
scope: () => ({
|
|
36
42
|
FormControl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","sources":["../../src/components/checkbox.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { action } from '@ember/object';\nimport { on } from '@ember/modifier';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport {\n useStyles,\n type CheckboxVariants,\n type CheckboxSlots,\n type SlotsToClasses\n} from '@frontile/theme';\n\ninterface Args extends FormControlSharedArgs {\n checked?: boolean;\n name?: string;\n size?: CheckboxVariants['size'];\n classes?: SlotsToClasses<CheckboxSlots>;\n\n /*\n * Callback when onchange is triggered\n */\n onChange?: (value: boolean, event: Event) => void;\n}\n\ninterface CheckboxSignature {\n Args: Args;\n Element: HTMLInputElement;\n}\n\nclass Checkbox extends Component<CheckboxSignature> {\n get isChecked(): boolean {\n return !!this.args.checked;\n }\n\n @action handleChange(event: Event): void {\n event.preventDefault();\n\n const value = !this.args.checked;\n\n if (typeof this.args.onChange === 'function') {\n this.args.onChange(value, event);\n }\n }\n\n get classes() {\n const { checkbox } = useStyles();\n return checkbox({\n size: this.args.size\n });\n }\n\n <template>\n <FormControl\n @isInvalid={{@isInvalid}}\n @errors={{@errors}}\n @size={{@size}}\n @isRequired={{@isRequired}}\n @class={{this.classes.base class=@classes.base}}\n @preventErrorFeedback={{true}}\n as |c|\n >\n <input\n {{on \"change\" this.handleChange}}\n id={{c.id}}\n name={{@name}}\n checked={{this.isChecked}}\n type=\"checkbox\"\n class={{this.classes.input class=@classes.input}}\n data-component=\"checkbox\"\n aria-invalid={{if c.isInvalid \"true\"}}\n aria-describedby={{c.describedBy @description c.isInvalid}}\n ...attributes\n />\n <div class={{this.classes.labelContainer class=@classes.labelContainer}}>\n {{#if @label}}\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n {{/if}}\n {{#if @description}}\n <c.Description>{{@description}}</c.Description>\n {{/if}}\n {{#if c.isInvalid}}\n <c.Feedback />\n {{/if}}\n </div>\n </FormControl>\n </template>\n}\n\nexport { Checkbox, type CheckboxSignature };\nexport default Checkbox;\n"],"names":["Checkbox","Component","isChecked","args","checked","handleChange","event","preventDefault","value","onChange","n","prototype","action","classes","checkbox","useStyles","size","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","on"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"checkbox.js","sources":["../../src/components/checkbox.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { action } from '@ember/object';\nimport { on } from '@ember/modifier';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport {\n useStyles,\n type CheckboxVariants,\n type CheckboxSlots,\n type SlotsToClasses\n} from '@frontile/theme';\n\ninterface Args extends FormControlSharedArgs {\n checked?: boolean;\n name?: string;\n size?: CheckboxVariants['size'];\n classes?: SlotsToClasses<CheckboxSlots>;\n\n /*\n * Callback when onchange is triggered\n */\n onChange?: (value: boolean, event: Event) => void;\n\n /*\n * Callback when onblur is triggered\n */\n onBlur?: () => void;\n}\n\ninterface CheckboxSignature {\n Args: Args;\n Element: HTMLInputElement;\n}\n\nclass Checkbox extends Component<CheckboxSignature> {\n get isChecked(): boolean {\n return !!this.args.checked;\n }\n\n @action handleChange(event: Event): void {\n event.preventDefault();\n\n const value = !this.args.checked;\n\n if (typeof this.args.onChange === 'function') {\n this.args.onChange(value, event);\n }\n }\n\n @action handleBlur(): void {\n this.args.onBlur?.();\n }\n\n get classes() {\n const { checkbox } = useStyles();\n return checkbox({\n size: this.args.size\n });\n }\n\n <template>\n <FormControl\n @isInvalid={{@isInvalid}}\n @errors={{@errors}}\n @size={{@size}}\n @isRequired={{@isRequired}}\n @class={{this.classes.base class=@classes.base}}\n @preventErrorFeedback={{true}}\n as |c|\n >\n <input\n {{on \"change\" this.handleChange}}\n {{on \"blur\" this.handleBlur}}\n id={{c.id}}\n name={{@name}}\n checked={{this.isChecked}}\n type=\"checkbox\"\n disabled={{@isDisabled}}\n class={{this.classes.input class=@classes.input}}\n data-component=\"checkbox\"\n aria-invalid={{if c.isInvalid \"true\"}}\n aria-describedby={{c.describedBy @description c.isInvalid}}\n ...attributes\n />\n <div class={{this.classes.labelContainer class=@classes.labelContainer}}>\n {{#if @label}}\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n {{/if}}\n {{#if @description}}\n <c.Description>{{@description}}</c.Description>\n {{/if}}\n {{#if c.isInvalid}}\n <c.Feedback />\n {{/if}}\n </div>\n </FormControl>\n </template>\n}\n\nexport { Checkbox, type CheckboxSignature };\nexport default Checkbox;\n"],"names":["Checkbox","Component","isChecked","args","checked","handleChange","event","preventDefault","value","onChange","n","prototype","action","handleBlur","onBlur","classes","checkbox","useStyles","size","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","on"],"mappings":";;;;;;;;;AAiCA,MAAMA,iBAAiBC,SAAA,CAAU;EAC/B,IAAIC,SAAAA,GAAqB;AACvB,IAAA,OAAO,CAAC,CAAC,IAAI,CAACC,IAAI,CAACC,OAAO;AAC5B,EAAA;EAEQC,YAAAA,CAAaC,KAAY,EAAQ;IACvCA,KAAA,CAAMC,cAAc,EAAA;AAEpB,IAAA,MAAMC,QAAQ,CAAC,IAAI,CAACL,IAAI,CAACC,OAAO;IAEhC,IAAI,OAAO,IAAI,CAACD,IAAI,CAACM,QAAQ,KAAK,UAAA,EAAY;MAC5C,IAAI,CAACN,IAAI,CAACM,QAAQ,CAACD,KAAA,EAAOF,KAAA,CAAA;AAC5B,IAAA;AACF,EAAA;AAAA,EAAA;IAAAI,gBAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,cAAA,EAAA,CARCC,MAAA,CAAA,CAAA;AAAA;AAUOC,EAAAA,UAAAA,GAAmB;AACzB,IAAA,IAAI,CAACV,IAAI,CAACW,MAAM,IAAA;AAClB,EAAA;AAAA,EAAA;IAAAJ,gBAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CAFCC,MAAA,CAAA,CAAA;AAAA;EAID,IAAIG,OAAAA,GAAU;IACZ,MAAM;AAAEC,MAAAA;KAAU,GAAGC,SAAA,EAAA;AACrB,IAAA,OAAOD,QAAA,CAAS;AACdE,MAAAA,IAAA,EAAM,IAAI,CAACf,IAAI,CAACe;AAClB,KAAA,CAAA;AACF,EAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,qgCAAA,EAsCA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { hash } from '@ember/helper';
|
|
3
|
+
import { get, action } from '@ember/object';
|
|
4
|
+
import { debounce } from '@ember/runloop';
|
|
5
|
+
import { Checkbox } from './checkbox.js';
|
|
6
|
+
import { CheckboxGroup } from './checkbox-group.js';
|
|
7
|
+
import { Input } from './input.js';
|
|
8
|
+
import { Radio } from './radio.js';
|
|
9
|
+
import { RadioGroup } from './radio-group.js';
|
|
10
|
+
import { Select } from './select.js';
|
|
11
|
+
import { Switch } from './switch.js';
|
|
12
|
+
import { Textarea } from './textarea.js';
|
|
13
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
14
|
+
import { setComponentTemplate } from '@ember/component';
|
|
15
|
+
import { a as decorateMethodV2 } from '../runtime-BPCpkOf1-B5Lbloj7.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Field is a component wrapper that provides conveniences for form fields.
|
|
19
|
+
* It automatically binds the appropriate form errors by name to yielded
|
|
20
|
+
* components.
|
|
21
|
+
*/
|
|
22
|
+
class Field extends Component {
|
|
23
|
+
/**
|
|
24
|
+
* Returns the validation errors for the field.
|
|
25
|
+
* Supports dotted field names (e.g., 'profile.email').
|
|
26
|
+
*/
|
|
27
|
+
get fieldErrors() {
|
|
28
|
+
return this.args.errors?.[this.args.name];
|
|
29
|
+
}
|
|
30
|
+
/** The events on which validation should run. Defaults to ['change']. */
|
|
31
|
+
get validateOn() {
|
|
32
|
+
return this.args.validateOn ?? ['change'];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the current value for the field from formData.
|
|
36
|
+
* Supports both flat and dotted field names (e.g., 'email' or 'profile.email').
|
|
37
|
+
* Uses Ember's get() which handles both flat keys and dotted paths.
|
|
38
|
+
*/
|
|
39
|
+
get fieldValue() {
|
|
40
|
+
if (!this.args.formData) return undefined;
|
|
41
|
+
// Ember's get() handles both flat keys and dotted paths correctly
|
|
42
|
+
return get(this.args.formData, this.args.name);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validates the field by calling the validateField function passed in args.
|
|
46
|
+
*/
|
|
47
|
+
validateField() {
|
|
48
|
+
this.args.validateField?.(this.args.formData, this.args.name);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates the field on change if change validation is enabled.
|
|
52
|
+
*/
|
|
53
|
+
handleChange() {
|
|
54
|
+
if (this.validateOn?.includes('change')) {
|
|
55
|
+
this.validateField();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validates the field on input if input validation is enabled.
|
|
60
|
+
* Debounces validation to avoid excessive validation calls on every keystroke.
|
|
61
|
+
*/
|
|
62
|
+
static {
|
|
63
|
+
decorateMethodV2(this.prototype, "handleChange", [action]);
|
|
64
|
+
}
|
|
65
|
+
handleInput() {
|
|
66
|
+
if (this.validateOn?.includes('input')) {
|
|
67
|
+
debounce(this, this.validateField, 300);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validates the field on blur if blur validation is enabled.
|
|
72
|
+
*/
|
|
73
|
+
static {
|
|
74
|
+
decorateMethodV2(this.prototype, "handleInput", [action]);
|
|
75
|
+
}
|
|
76
|
+
handleBlur() {
|
|
77
|
+
if (this.validateOn.includes('blur')) {
|
|
78
|
+
this.validateField();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static {
|
|
82
|
+
decorateMethodV2(this.prototype, "handleBlur", [action]);
|
|
83
|
+
}
|
|
84
|
+
static {
|
|
85
|
+
setComponentTemplate(precompileTemplate("\n {{!-- @glint-nocheck component generics (radio, radio-group, select) trigger: type instantiation is excessively deep and possibly infinite --}}\n {{yield (hash Checkbox=(component Checkbox name=@name errors=this.fieldErrors checked=this.fieldValue isDisabled=@disabled onChange=this.handleChange onBlur=this.handleBlur) CheckboxGroup=(component CheckboxGroup name=@name errors=this.fieldErrors isDisabled=@disabled) Input=(component Input name=@name errors=this.fieldErrors value=this.fieldValue isDisabled=@disabled onChange=this.handleChange onInput=this.handleInput onBlur=this.handleBlur) Radio=(component Radio name=@name errors=this.fieldErrors value=this.fieldValue isDisabled=@disabled onChange=this.handleChange onBlur=this.handleBlur) RadioGroup=(component RadioGroup name=@name errors=this.fieldErrors value=this.fieldValue isDisabled=@disabled onChange=this.handleChange) SingleSelect=(component Select name=@name errors=this.fieldErrors selectedKey=this.fieldValue isDisabled=@disabled onBlur=this.handleBlur) MultiSelect=(component Select selectionMode=\"multiple\" name=@name errors=this.fieldErrors selectedKeys=this.fieldValue isDisabled=@disabled onBlur=this.handleBlur) Switch=(component Switch name=@name errors=this.fieldErrors isSelected=this.fieldValue isDisabled=@disabled onChange=this.handleChange onBlur=this.handleBlur) Textarea=(component Textarea name=@name errors=this.fieldErrors value=this.fieldValue isDisabled=@disabled onChange=this.handleChange onInput=this.handleInput onBlur=this.handleBlur)) to=\"default\"}}\n ", {
|
|
86
|
+
strictMode: true,
|
|
87
|
+
scope: () => ({
|
|
88
|
+
hash,
|
|
89
|
+
Checkbox,
|
|
90
|
+
CheckboxGroup,
|
|
91
|
+
Input,
|
|
92
|
+
Radio,
|
|
93
|
+
RadioGroup,
|
|
94
|
+
Select,
|
|
95
|
+
Switch,
|
|
96
|
+
Textarea
|
|
97
|
+
})
|
|
98
|
+
}), this);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { Field, Field as default };
|
|
103
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.js","sources":["../../src/components/field.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { hash } from '@ember/helper';\nimport { action, get } from '@ember/object';\nimport { debounce } from '@ember/runloop';\nimport Checkbox from './checkbox';\nimport CheckboxGroup from './checkbox-group';\nimport Input from './input';\nimport Radio from './radio';\nimport RadioGroup from './radio-group';\nimport Select from './select';\nimport Switch from './switch';\nimport Textarea from './textarea';\n\nimport type { WithBoundArgs } from '@glint/template';\nimport type { FormDataCompiled, FormErrors } from './form';\nimport type { SelectSignature } from './select';\nimport type { WithBoundArgsForSignature } from './field-types';\n\ntype BoundSingleSelect<S = unknown> = WithBoundArgsForSignature<\n SelectSignature<S>,\n 'name' | 'errors' | 'selectedKey' | 'onBlur' | 'isDisabled'\n>;\n\ntype BoundMultiSelect<S = unknown> = WithBoundArgsForSignature<\n SelectSignature<S>,\n 'selectionMode' | 'name' | 'errors' | 'selectedKeys' | 'onBlur' | 'isDisabled'\n>;\n\ninterface FieldSignature<T extends Record<string, unknown> = FormDataCompiled> {\n Element: HTMLElement;\n Args: {\n /** The name of the form field. */\n name: string;\n /** The validation errors for the form, keyed by field name. */\n errors?: FormErrors;\n /** The form data as key/value pairs. */\n formData?: T;\n /** Whether the field should be disabled. */\n disabled?: boolean;\n /** When to run validation. */\n validateOn?: ('change' | 'input' | 'blur')[];\n /** Function to validate a single field by name. */\n validateField?: (data: T, name: string) => Promise<FormErrors | undefined>;\n };\n Blocks: {\n default: [\n {\n Checkbox: WithBoundArgs<\n typeof Checkbox,\n 'name' | 'errors' | 'checked' | 'onChange' | 'onBlur' | 'isDisabled'\n >;\n CheckboxGroup: WithBoundArgs<\n typeof CheckboxGroup,\n 'name' | 'errors' | 'isDisabled'\n >;\n Input: WithBoundArgs<\n typeof Input,\n | 'name'\n | 'errors'\n | 'value'\n | 'onChange'\n | 'onInput'\n | 'onBlur'\n | 'isDisabled'\n >;\n Radio: WithBoundArgs<\n typeof Radio,\n 'name' | 'errors' | 'value' | 'onChange' | 'onBlur' | 'isDisabled'\n >;\n RadioGroup: WithBoundArgs<\n typeof RadioGroup,\n 'name' | 'errors' | 'value' | 'onChange' | 'isDisabled'\n >;\n SingleSelect: BoundSingleSelect;\n MultiSelect: BoundMultiSelect;\n Switch: WithBoundArgs<\n typeof Switch,\n | 'name'\n | 'errors'\n | 'isSelected'\n | 'onChange'\n | 'onBlur'\n | 'isDisabled'\n >;\n Textarea: WithBoundArgs<\n typeof Textarea,\n | 'name'\n | 'errors'\n | 'value'\n | 'onChange'\n | 'onInput'\n | 'onBlur'\n | 'isDisabled'\n >;\n }\n ];\n };\n}\n\n/**\n * Field is a component wrapper that provides conveniences for form fields.\n * It automatically binds the appropriate form errors by name to yielded\n * components.\n */\nclass Field<\n T extends Record<string, unknown> = FormDataCompiled\n> extends Component<FieldSignature<T>> {\n /**\n * Returns the validation errors for the field.\n * Supports dotted field names (e.g., 'profile.email').\n */\n get fieldErrors() {\n return this.args.errors?.[this.args.name];\n }\n\n /** The events on which validation should run. Defaults to ['change']. */\n get validateOn(): ('change' | 'input' | 'blur')[] {\n return this.args.validateOn ?? ['change'];\n }\n\n /**\n * Returns the current value for the field from formData.\n * Supports both flat and dotted field names (e.g., 'email' or 'profile.email').\n * Uses Ember's get() which handles both flat keys and dotted paths.\n */\n get fieldValue() {\n if (!this.args.formData) return undefined;\n\n // Ember's get() handles both flat keys and dotted paths correctly\n return get(this.args.formData, this.args.name);\n }\n\n /**\n * Validates the field by calling the validateField function passed in args.\n */\n validateField() {\n this.args.validateField?.(this.args.formData as T, this.args.name);\n }\n\n /**\n * Validates the field on change if change validation is enabled.\n */\n @action\n handleChange() {\n if (this.validateOn?.includes('change')) {\n this.validateField();\n }\n }\n\n /**\n * Validates the field on input if input validation is enabled.\n * Debounces validation to avoid excessive validation calls on every keystroke.\n */\n @action\n handleInput() {\n if (this.validateOn?.includes('input')) {\n debounce(this, this.validateField, 300);\n }\n }\n\n /**\n * Validates the field on blur if blur validation is enabled.\n */\n @action\n handleBlur() {\n if (this.validateOn.includes('blur')) {\n this.validateField();\n }\n }\n\n <template>\n {{! @glint-nocheck component generics (radio, radio-group, select) trigger: type instantiation is excessively deep and possibly infinite }}\n {{yield\n (hash\n Checkbox=(component\n Checkbox\n name=@name\n errors=this.fieldErrors\n checked=this.fieldValue\n isDisabled=@disabled\n onChange=this.handleChange\n onBlur=this.handleBlur\n )\n CheckboxGroup=(component\n CheckboxGroup name=@name errors=this.fieldErrors isDisabled=@disabled\n )\n Input=(component\n Input\n name=@name\n errors=this.fieldErrors\n value=this.fieldValue\n isDisabled=@disabled\n onChange=this.handleChange\n onInput=this.handleInput\n onBlur=this.handleBlur\n )\n Radio=(component\n Radio\n name=@name\n errors=this.fieldErrors\n value=this.fieldValue\n isDisabled=@disabled\n onChange=this.handleChange\n onBlur=this.handleBlur\n )\n RadioGroup=(component\n RadioGroup\n name=@name\n errors=this.fieldErrors\n value=this.fieldValue\n isDisabled=@disabled\n onChange=this.handleChange\n )\n SingleSelect=(component\n Select\n name=@name\n errors=this.fieldErrors\n selectedKey=this.fieldValue\n isDisabled=@disabled\n onBlur=this.handleBlur\n )\n MultiSelect=(component\n Select\n selectionMode=\"multiple\"\n name=@name\n errors=this.fieldErrors\n selectedKeys=this.fieldValue\n isDisabled=@disabled\n onBlur=this.handleBlur\n )\n Switch=(component\n Switch\n name=@name\n errors=this.fieldErrors\n isSelected=this.fieldValue\n isDisabled=@disabled\n onChange=this.handleChange\n onBlur=this.handleBlur\n )\n Textarea=(component\n Textarea\n name=@name\n errors=this.fieldErrors\n value=this.fieldValue\n isDisabled=@disabled\n onChange=this.handleChange\n onInput=this.handleInput\n onBlur=this.handleBlur\n )\n )\n to=\"default\"\n }}\n </template>\n}\n\nexport { Field, type FieldSignature };\nexport default Field;\n"],"names":["Field","Component","fieldErrors","args","errors","name","validateOn","fieldValue","formData","undefined","get","validateField","handleChange","includes","n","prototype","action","handleInput","debounce","handleBlur","setComponentTemplate","precompileTemplate","strictMode","scope","hash","Checkbox","CheckboxGroup","Input","Radio","RadioGroup","Select","Switch","Textarea"],"mappings":";;;;;;;;;;;;;;;;AAmGA;;;;;AAKA,MAAMA,KAAA,SAEIC,SAAA,CAAyB;AACjC;;;AAGC;EACD,IAAIC,WAAAA,GAAc;IAChB,OAAO,IAAI,CAACC,IAAI,CAACC,MAAM,GAAG,IAAI,CAACD,IAAI,CAACE,IAAI,CAAC;AAC3C,EAAA;AAEA;EACA,IAAIC,UAAAA,GAA8C;IAChD,OAAO,IAAI,CAACH,IAAI,CAACG,UAAU,IAAI,CAAC,QAAA,CAAS;AAC3C,EAAA;AAEA;;;;AAIC;EACD,IAAIC,UAAAA,GAAa;IACf,IAAI,CAAC,IAAI,CAACJ,IAAI,CAACK,QAAQ,EAAE,OAAOC,SAAA;AAEhC;AACA,IAAA,OAAOC,GAAA,CAAI,IAAI,CAACP,IAAI,CAACK,QAAQ,EAAE,IAAI,CAACL,IAAI,CAACE,IAAI,CAAA;AAC/C,EAAA;AAEA;;AAEC;AACDM,EAAAA,aAAAA,GAAgB;AACd,IAAA,IAAI,CAACR,IAAI,CAACQ,aAAa,GAAG,IAAI,CAACR,IAAI,CAACK,QAAQ,EAAO,IAAI,CAACL,IAAI,CAACE,IAAI,CAAA;AACnE,EAAA;AAEA;;AAEC;AAEDO,EAAAA,YAAAA,GAAe;IACb,IAAI,IAAI,CAACN,UAAU,EAAEO,SAAS,QAAA,CAAA,EAAW;MACvC,IAAI,CAACF,aAAa,EAAA;AACpB,IAAA;AACF,EAAA;AAEA;;;AAGC;AAHD,EAAA;IAAAG,gBAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,cAAA,EAAA,CAPCC,MAAA,CAAA,CAAA;AAAA;AAYDC,EAAAA,WAAAA,GAAc;IACZ,IAAI,IAAI,CAACX,UAAU,EAAEO,SAAS,OAAA,CAAA,EAAU;MACtCK,QAAA,CAAS,IAAI,EAAE,IAAI,CAACP,aAAa,EAAE,GAAA,CAAA;AACrC,IAAA;AACF,EAAA;AAEA;;AAEC;AAFD,EAAA;IAAAG,gBAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,aAAA,EAAA,CAPCC,MAAA,CAAA,CAAA;AAAA;AAWDG,EAAAA,UAAAA,GAAa;IACX,IAAI,IAAI,CAACb,UAAU,CAACO,QAAQ,CAAC,MAAA,CAAA,EAAS;MACpC,IAAI,CAACF,aAAa,EAAA;AACpB,IAAA;AACF,EAAA;AAAA,EAAA;IAAAG,gBAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CALCC,MAAA,CAAA,CAAA;AAAA;AAOD,EAAA;IAAAI,oBAAA,CAAAC,kBAAA,CAAA,4hDAAA,EAkFA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,IAAA;QAAAC,QAAA;QAAAC,aAAA;QAAAC,KAAA;QAAAC,KAAA;QAAAC,UAAA;QAAAC,MAAA;QAAAC,MAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-control.js","sources":["../../src/components/form-control.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { guidFor } from '@ember/object/internals';\nimport { hash } from '@ember/helper';\nimport Feedback from './form-feedback';\nimport Description from './form-description';\nimport Label from './label';\nimport type { WithBoundArgs } from '@glint/template';\n\ninterface FormControlSharedArgs {\n label?: string;\n isRequired?: boolean;\n description?: string;\n errors?: string[] | string;\n isInvalid?: boolean;\n}\n\ninterface Args extends FormControlSharedArgs {\n id?: string;\n size?: 'sm' | 'md' | 'lg';\n preventErrorFeedback?: boolean;\n class?: string;\n}\n\ninterface FormControlSignature {\n Args: Args;\n Blocks: {\n default: [\n {\n id: string;\n isInvalid: boolean;\n describedBy: (\n hasDescription?: string | boolean,\n hasFeedback?: string | boolean\n ) => string | undefined;\n Label: WithBoundArgs<typeof Label, 'for' | 'size' | 'isRequired'>;\n Description: WithBoundArgs<typeof Description, 'id' | 'size'>;\n Feedback: WithBoundArgs<\n typeof Feedback,\n 'id' | 'size' | 'messages' | 'intent'\n >;\n }\n ];\n label: [];\n description: [];\n };\n Element: HTMLDivElement;\n}\n\nfunction or(arg1: unknown, arg2: unknown): boolean {\n return !!(arg1 || arg2);\n}\n\nclass FormControl extends Component<FormControlSignature> {\n id = this.args.id || guidFor(this);\n\n get descriptionId(): string {\n return this.id + '-description';\n }\n\n get feedbackId(): string {\n return this.id + '-feedback';\n }\n\n describedBy = (\n hasDescription?: string | boolean,\n hasFeedback?: string | boolean\n ): string | undefined => {\n const ids = [];\n\n if (hasDescription) {\n ids.push(this.descriptionId);\n }\n\n if (hasFeedback) {\n ids.push(this.feedbackId);\n }\n\n if (ids.length > 0) {\n return ids.join(' ');\n }\n };\n\n get isInvalid(): boolean {\n if (\n this.args.isInvalid ||\n (this.args.errors && this.args.errors.length > 0)\n ) {\n return true;\n } else {\n return false;\n }\n }\n\n get showErrorFeedback(): boolean {\n if (!(this.args.preventErrorFeedback === true) && this.isInvalid) {\n return true;\n }\n return false;\n }\n\n <template>\n <div class={{@class}} ...attributes>\n {{#if (or @label (has-block \"label\"))}}\n <Label @for={{this.id}} @isRequired={{@isRequired}} @size={{@size}}>\n {{@label}}\n {{yield to=\"label\"}}\n </Label>\n {{/if}}\n\n {{#if (or @description (has-block \"Description\"))}}\n <Description @id={{this.descriptionId}} @size={{@size}}>\n {{@description}}\n {{yield to=\"description\"}}\n </Description>\n {{/if}}\n\n {{yield\n (hash\n id=this.id\n isInvalid=this.isInvalid\n describedBy=this.describedBy\n Label=(component Label for=this.id size=@size isRequired=@isRequired)\n Description=(component Description id=this.descriptionId size=@size)\n Feedback=(component\n Feedback\n id=this.feedbackId\n size=@size\n messages=@errors\n intent=\"danger\"\n )\n )\n to=\"default\"\n }}\n\n {{#if this.showErrorFeedback}}\n <Feedback\n @id={{this.feedbackId}}\n @size={{@size}}\n @messages={{@errors}}\n @intent=\"danger\"\n />\n {{/if}}\n </div>\n </template>\n}\n\nexport { FormControl, type FormControlSignature, type FormControlSharedArgs };\nexport default FormControl;\n"],"names":["or","arg1","arg2","FormControl","Component","id","args","guidFor","descriptionId","feedbackId","describedBy","hasDescription","hasFeedback","ids","push","length","join","isInvalid","errors","showErrorFeedback","preventErrorFeedback","setComponentTemplate","precompileTemplate","strictMode","scope","Label","Description","hash","Feedback"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"form-control.js","sources":["../../src/components/form-control.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { guidFor } from '@ember/object/internals';\nimport { hash } from '@ember/helper';\nimport Feedback from './form-feedback';\nimport Description from './form-description';\nimport Label from './label';\nimport type { WithBoundArgs } from '@glint/template';\n\ninterface FormControlSharedArgs {\n label?: string;\n isRequired?: boolean;\n description?: string;\n errors?: string[] | string;\n isInvalid?: boolean;\n isDisabled?: boolean;\n}\n\ninterface Args extends FormControlSharedArgs {\n id?: string;\n size?: 'sm' | 'md' | 'lg';\n preventErrorFeedback?: boolean;\n class?: string;\n}\n\ninterface FormControlSignature {\n Args: Args;\n Blocks: {\n default: [\n {\n id: string;\n isInvalid: boolean;\n describedBy: (\n hasDescription?: string | boolean,\n hasFeedback?: string | boolean\n ) => string | undefined;\n Label: WithBoundArgs<typeof Label, 'for' | 'size' | 'isRequired'>;\n Description: WithBoundArgs<typeof Description, 'id' | 'size'>;\n Feedback: WithBoundArgs<\n typeof Feedback,\n 'id' | 'size' | 'messages' | 'intent'\n >;\n }\n ];\n label: [];\n description: [];\n };\n Element: HTMLDivElement;\n}\n\nfunction or(arg1: unknown, arg2: unknown): boolean {\n return !!(arg1 || arg2);\n}\n\nclass FormControl extends Component<FormControlSignature> {\n id = this.args.id || guidFor(this);\n\n get descriptionId(): string {\n return this.id + '-description';\n }\n\n get feedbackId(): string {\n return this.id + '-feedback';\n }\n\n describedBy = (\n hasDescription?: string | boolean,\n hasFeedback?: string | boolean\n ): string | undefined => {\n const ids = [];\n\n if (hasDescription) {\n ids.push(this.descriptionId);\n }\n\n if (hasFeedback) {\n ids.push(this.feedbackId);\n }\n\n if (ids.length > 0) {\n return ids.join(' ');\n }\n };\n\n get isInvalid(): boolean {\n if (\n this.args.isInvalid ||\n (this.args.errors && this.args.errors.length > 0)\n ) {\n return true;\n } else {\n return false;\n }\n }\n\n get showErrorFeedback(): boolean {\n if (!(this.args.preventErrorFeedback === true) && this.isInvalid) {\n return true;\n }\n return false;\n }\n\n <template>\n <div class={{@class}} ...attributes>\n {{#if (or @label (has-block \"label\"))}}\n <Label @for={{this.id}} @isRequired={{@isRequired}} @size={{@size}}>\n {{@label}}\n {{yield to=\"label\"}}\n </Label>\n {{/if}}\n\n {{#if (or @description (has-block \"Description\"))}}\n <Description @id={{this.descriptionId}} @size={{@size}}>\n {{@description}}\n {{yield to=\"description\"}}\n </Description>\n {{/if}}\n\n {{yield\n (hash\n id=this.id\n isInvalid=this.isInvalid\n describedBy=this.describedBy\n Label=(component Label for=this.id size=@size isRequired=@isRequired)\n Description=(component Description id=this.descriptionId size=@size)\n Feedback=(component\n Feedback\n id=this.feedbackId\n size=@size\n messages=@errors\n intent=\"danger\"\n )\n )\n to=\"default\"\n }}\n\n {{#if this.showErrorFeedback}}\n <Feedback\n @id={{this.feedbackId}}\n @size={{@size}}\n @messages={{@errors}}\n @intent=\"danger\"\n />\n {{/if}}\n </div>\n </template>\n}\n\nexport { FormControl, type FormControlSignature, type FormControlSharedArgs };\nexport default FormControl;\n"],"names":["or","arg1","arg2","FormControl","Component","id","args","guidFor","descriptionId","feedbackId","describedBy","hasDescription","hasFeedback","ids","push","length","join","isInvalid","errors","showErrorFeedback","preventErrorFeedback","setComponentTemplate","precompileTemplate","strictMode","scope","Label","Description","hash","Feedback"],"mappings":";;;;;;;;;AAiDA,SAASA,GAAGC,IAAa,EAAEC,IAAa,EAAU;AAChD,EAAA,OAAO,CAAC,EAAED,IAAA,IAAQC,IAAI,CAAA;AACxB;AAEA,MAAMC,oBAAoBC,SAAA,CAAU;EAClCC,EAAA,GAAK,IAAI,CAACC,IAAI,CAACD,EAAE,IAAIE,OAAA,CAAQ,IAAI,CAAA;EAEjC,IAAIC,aAAAA,GAAwB;AAC1B,IAAA,OAAO,IAAI,CAACH,EAAE,GAAG,cAAA;AACnB,EAAA;EAEA,IAAII,UAAAA,GAAqB;AACvB,IAAA,OAAO,IAAI,CAACJ,EAAE,GAAG,WAAA;AACnB,EAAA;AAEAK,EAAAA,WAAA,GAAcA,CACZC,cAAiC,EACjCC,WAA8B,KACX;IACnB,MAAMC,MAAM,EAAE;AAEd,IAAA,IAAIF,cAAA,EAAgB;AAClBE,MAAAA,GAAA,CAAIC,IAAI,CAAC,IAAI,CAACN,aAAa,CAAA;AAC7B,IAAA;AAEA,IAAA,IAAII,WAAA,EAAa;AACfC,MAAAA,GAAA,CAAIC,IAAI,CAAC,IAAI,CAACL,UAAU,CAAA;AAC1B,IAAA;AAEA,IAAA,IAAII,GAAA,CAAIE,MAAM,GAAG,CAAA,EAAG;AAClB,MAAA,OAAOF,GAAA,CAAIG,IAAI,CAAC,GAAA,CAAA;AAClB,IAAA;EACF,CAAA;EAEA,IAAIC,SAAAA,GAAqB;IACvB,IACE,IAAI,CAACX,IAAI,CAACW,SAAS,IAClB,IAAI,CAACX,IAAI,CAACY,MAAM,IAAI,IAAI,CAACZ,IAAI,CAACY,MAAM,CAACH,MAAM,GAAG,CAAC,EAChD;AACA,MAAA,OAAO,IAAA;AACT,IAAA,CAAA,MAAO;AACL,MAAA,OAAO,KAAA;AACT,IAAA;AACF,EAAA;EAEA,IAAII,iBAAAA,GAA6B;AAC/B,IAAA,IAAI,EAAE,IAAI,CAACb,IAAI,CAACc,oBAAoB,KAAK,IAAI,CAAA,IAAK,IAAI,CAACH,SAAS,EAAE;AAChE,MAAA,OAAO,IAAA;AACT,IAAA;AACA,IAAA,OAAO,KAAA;AACT,EAAA;AAEA,EAAA;IAAAI,oBAAA,CAAAC,kBAAA,CAAA,k/BAAA,EA2CA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAxB,EAAA;QAAAyB,KAAA;qBAAAC,eAAA;QAAAC,IAAA;AAAAC,kBAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
package/dist/components/form.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
handleSubmit = event => {
|
|
16
|
-
event.preventDefault();
|
|
17
|
-
this.handleInput(event, 'submit');
|
|
18
|
-
};
|
|
19
|
-
static {
|
|
20
|
-
setComponentTemplate(precompileTemplate("\n <form {{on \"input\" this.handleInput}} {{on \"submit\" this.handleSubmit}} ...attributes>\n {{yield}}\n </form>\n ", {
|
|
21
|
-
strictMode: true,
|
|
22
|
-
scope: () => ({
|
|
23
|
-
on
|
|
24
|
-
})
|
|
25
|
-
}), this);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { Form, Form as default };
|
|
1
|
+
import '@glimmer/component';
|
|
2
|
+
import '@glimmer/tracking';
|
|
3
|
+
import '@ember/object';
|
|
4
|
+
import '@ember/helper';
|
|
5
|
+
import '@ember/modifier';
|
|
6
|
+
import '@frontile/utilities';
|
|
7
|
+
import 'form-data-utils';
|
|
8
|
+
export { F as Form, F as default } from '../form-CVuJDJUq.js';
|
|
9
|
+
import './field.js';
|
|
10
|
+
import '@ember/template-compilation';
|
|
11
|
+
import '@ember/component';
|
|
12
|
+
import '../runtime-BPCpkOf1-B5Lbloj7.js';
|
|
30
13
|
//# sourceMappingURL=form.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","sources":[
|
|
1
|
+
{"version":3,"file":"form.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
package/dist/components/input.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ref } from '@frontile/utilities';
|
|
|
9
9
|
import { CloseButton } from '@frontile/buttons';
|
|
10
10
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
11
11
|
import { setComponentTemplate } from '@ember/component';
|
|
12
|
-
import {
|
|
12
|
+
import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from '../runtime-BPCpkOf1-B5Lbloj7.js';
|
|
13
13
|
|
|
14
14
|
function or(arg1, arg2) {
|
|
15
15
|
return !!(arg1 || arg2);
|
|
@@ -56,6 +56,12 @@ class Input extends Component {
|
|
|
56
56
|
static {
|
|
57
57
|
decorateMethodV2(this.prototype, "handleOnChange", [action]);
|
|
58
58
|
}
|
|
59
|
+
handleOnBlur() {
|
|
60
|
+
this.args.onBlur?.();
|
|
61
|
+
}
|
|
62
|
+
static {
|
|
63
|
+
decorateMethodV2(this.prototype, "handleOnBlur", [action]);
|
|
64
|
+
}
|
|
59
65
|
clearValue() {
|
|
60
66
|
if (this.isControlled) {
|
|
61
67
|
this.args.onChange?.('');
|
|
@@ -84,7 +90,7 @@ class Input extends Component {
|
|
|
84
90
|
});
|
|
85
91
|
}
|
|
86
92
|
static {
|
|
87
|
-
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} as |c|>\n <div class={{this.classes.innerContainer class=@classes.innerContainer}}>\n {{#if (has-block \"startContent\")}}\n <div data-test-id=\"input-start-content\" class={{this.classes.startContent class=@classes.startContent startContentPointerEvents=(if @startContentPointerEvents @startContentPointerEvents \"auto\")}}>\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n <input {{this.inputRef.setup}} {{on \"input\" this.handleOnInput}} {{on \"change\" this.handleOnChange}} id={{c.id}} name={{@name}} value={{this.value}} type={{this.type}} class={{this.classes.input class=@classes.input hasStartContent=(has-block \"startContent\") hasEndContent=(or (has-block \"endContent\") this.isClearable)}} data-component=\"input\" aria-invalid={{if c.isInvalid \"true\"}} aria-describedby={{c.describedBy @description c.isInvalid}} ...attributes />\n {{#if (or (has-block \"endContent\") this.isClearable)}}\n <div data-test-id=\"input-end-content\" class={{this.classes.endContent class=@classes.endContent endContentPointerEvents=(if @endContentPointerEvents @endContentPointerEvents \"auto\")}}>\n {{yield to=\"endContent\"}}\n\n {{#if this.isClearable}}\n <CloseButton @title=\"Clear\" @variant=\"subtle\" @size=\"xs\" data-test-id=\"input-clear-button\" @onPress={{this.clearValue}} />\n {{/if}}\n </div>\n {{/if}}\n </div>\n </FormControl>\n ", {
|
|
93
|
+
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} as |c|>\n <div class={{this.classes.innerContainer class=@classes.innerContainer}}>\n {{#if (has-block \"startContent\")}}\n <div data-test-id=\"input-start-content\" class={{this.classes.startContent class=@classes.startContent startContentPointerEvents=(if @startContentPointerEvents @startContentPointerEvents \"auto\")}}>\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n <input {{this.inputRef.setup}} {{on \"input\" this.handleOnInput}} {{on \"change\" this.handleOnChange}} {{on \"blur\" this.handleOnBlur}} id={{c.id}} name={{@name}} value={{this.value}} type={{this.type}} disabled={{@isDisabled}} class={{this.classes.input class=@classes.input hasStartContent=(has-block \"startContent\") hasEndContent=(or (has-block \"endContent\") this.isClearable)}} data-component=\"input\" aria-invalid={{if c.isInvalid \"true\"}} aria-describedby={{c.describedBy @description c.isInvalid}} ...attributes />\n {{#if (or (has-block \"endContent\") this.isClearable)}}\n <div data-test-id=\"input-end-content\" class={{this.classes.endContent class=@classes.endContent endContentPointerEvents=(if @endContentPointerEvents @endContentPointerEvents \"auto\")}}>\n {{yield to=\"endContent\"}}\n\n {{#if this.isClearable}}\n <CloseButton @title=\"Clear\" @variant=\"subtle\" @size=\"xs\" data-test-id=\"input-clear-button\" @onPress={{this.clearValue}} />\n {{/if}}\n </div>\n {{/if}}\n </div>\n </FormControl>\n ", {
|
|
88
94
|
strictMode: true,
|
|
89
95
|
scope: () => ({
|
|
90
96
|
FormControl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sources":["../../src/components/input.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { on } from '@ember/modifier';\nimport {\n useStyles,\n type InputSlots,\n type InputVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport { triggerFormInputEvent } from '../utils';\nimport { ref } from '@frontile/utilities';\nimport { CloseButton } from '@frontile/buttons';\n\ninterface Args extends FormControlSharedArgs {\n type?: string;\n value?: string;\n name?: string;\n size?: InputVariants['size'];\n classes?: SlotsToClasses<InputSlots>;\n\n /**\n * Whether to include a clear button\n */\n isClearable?: boolean;\n\n /**\n * Controls pointer-events property of startContent.\n * If you want to pass the click event to the input, set it to `none`.\n *\n * @defaultValue 'auto'\n */\n startContentPointerEvents?: 'none' | 'auto';\n\n /**\n * Controls pointer-events property of endContent.\n * If you want to pass the click event to the input, set it to `none`.\n *\n * @defaultValue 'auto'\n */\n endContentPointerEvents?: 'none' | 'auto';\n\n /**\n * Callback when oninput is triggered\n */\n onInput?: (value: string, event?: InputEvent) => void;\n\n /**\n * Callback when onchange is triggered\n */\n onChange?: (value: string, event?: InputEvent) => void;\n}\n\ninterface InputSignature {\n Args: Args;\n Blocks: {\n startContent: [];\n endContent: [];\n };\n Element: HTMLInputElement;\n}\n\nfunction or(arg1: unknown, arg2: unknown): boolean {\n return !!(arg1 || arg2);\n}\n\nclass Input extends Component<InputSignature> {\n @tracked uncontrolledValue: string = this.args.value || '';\n\n inputRef = ref<HTMLInputElement>();\n\n get isControlled() {\n return (\n typeof this.args.onChange === 'function' ||\n typeof this.args.onInput === 'function'\n );\n }\n\n get value(): string | undefined {\n return this.isControlled ? this.args.value : this.uncontrolledValue;\n }\n\n get type(): string {\n if (typeof this.args.type === 'string') {\n return this.args.type;\n }\n return 'text';\n }\n\n @action handleOnInput(event: Event): void {\n const value = (event.target as HTMLInputElement).value;\n\n if (this.isControlled) {\n this.args.onInput?.(value, event as InputEvent);\n } else {\n this.uncontrolledValue = value;\n }\n }\n\n @action handleOnChange(event: Event): void {\n const value = (event.target as HTMLInputElement).value;\n\n if (this.isControlled) {\n this.args.onChange?.(value, event as InputEvent);\n } else {\n this.uncontrolledValue = value;\n }\n }\n\n @action clearValue(): void {\n if (this.isControlled) {\n this.args.onChange?.('');\n this.args.onInput?.('');\n } else {\n this.uncontrolledValue = '';\n }\n\n this.inputRef.current?.focus();\n triggerFormInputEvent(this.inputRef.current);\n }\n\n get isClearable(): boolean {\n if (\n this.args.isClearable === true &&\n this.value !== '' &&\n typeof this.value !== 'undefined'\n ) {\n return true;\n }\n return false;\n }\n\n get classes() {\n const { input } = useStyles();\n return input({\n size: this.args.size\n });\n }\n\n <template>\n <FormControl\n @size={{@size}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n @class={{this.classes.base class=@classes.base}}\n as |c|\n >\n <div class={{this.classes.innerContainer class=@classes.innerContainer}}>\n {{#if (has-block \"startContent\")}}\n <div\n data-test-id=\"input-start-content\"\n class={{this.classes.startContent\n class=@classes.startContent\n startContentPointerEvents=(if\n @startContentPointerEvents @startContentPointerEvents \"auto\"\n )\n }}\n >\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n <input\n {{this.inputRef.setup}}\n {{on \"input\" this.handleOnInput}}\n {{on \"change\" this.handleOnChange}}\n id={{c.id}}\n name={{@name}}\n value={{this.value}}\n type={{this.type}}\n class={{this.classes.input\n class=@classes.input\n hasStartContent=(has-block \"startContent\")\n hasEndContent=(or (has-block \"endContent\") this.isClearable)\n }}\n data-component=\"input\"\n aria-invalid={{if c.isInvalid \"true\"}}\n aria-describedby={{c.describedBy @description c.isInvalid}}\n ...attributes\n />\n {{#if (or (has-block \"endContent\") this.isClearable)}}\n <div\n data-test-id=\"input-end-content\"\n class={{this.classes.endContent\n class=@classes.endContent\n endContentPointerEvents=(if\n @endContentPointerEvents @endContentPointerEvents \"auto\"\n )\n }}\n >\n {{yield to=\"endContent\"}}\n\n {{#if this.isClearable}}\n <CloseButton\n @title=\"Clear\"\n @variant=\"subtle\"\n @size=\"xs\"\n data-test-id=\"input-clear-button\"\n @onPress={{this.clearValue}}\n />\n {{/if}}\n </div>\n {{/if}}\n </div>\n </FormControl>\n </template>\n}\n\nexport { Input, type InputSignature };\nexport default Input;\n"],"names":["or","arg1","arg2","Input","Component","g","prototype","tracked","args","value","i","void 0","inputRef","ref","isControlled","onChange","onInput","uncontrolledValue","type","handleOnInput","event","target","n","action","handleOnChange","clearValue","current","focus","triggerFormInputEvent","isClearable","classes","input","useStyles","size","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","on","CloseButton"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"input.js","sources":["../../src/components/input.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { on } from '@ember/modifier';\nimport {\n useStyles,\n type InputSlots,\n type InputVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport { triggerFormInputEvent } from '../utils';\nimport { ref } from '@frontile/utilities';\nimport { CloseButton } from '@frontile/buttons';\n\ninterface Args extends FormControlSharedArgs {\n type?: string;\n value?: string;\n name?: string;\n size?: InputVariants['size'];\n classes?: SlotsToClasses<InputSlots>;\n\n /**\n * Whether to include a clear button\n */\n isClearable?: boolean;\n\n /**\n * Controls pointer-events property of startContent.\n * If you want to pass the click event to the input, set it to `none`.\n *\n * @defaultValue 'auto'\n */\n startContentPointerEvents?: 'none' | 'auto';\n\n /**\n * Controls pointer-events property of endContent.\n * If you want to pass the click event to the input, set it to `none`.\n *\n * @defaultValue 'auto'\n */\n endContentPointerEvents?: 'none' | 'auto';\n\n /**\n * Callback when oninput is triggered\n */\n onInput?: (value: string, event?: InputEvent) => void;\n\n /**\n * Callback when onchange is triggered\n */\n onChange?: (value: string, event?: InputEvent) => void;\n\n /**\n * Callback when onblur is triggered\n */\n onBlur?: () => void;\n}\n\ninterface InputSignature {\n Args: Args;\n Blocks: {\n startContent: [];\n endContent: [];\n };\n Element: HTMLInputElement;\n}\n\nfunction or(arg1: unknown, arg2: unknown): boolean {\n return !!(arg1 || arg2);\n}\n\nclass Input extends Component<InputSignature> {\n @tracked uncontrolledValue: string = this.args.value || '';\n\n inputRef = ref<HTMLInputElement>();\n\n get isControlled() {\n return (\n typeof this.args.onChange === 'function' ||\n typeof this.args.onInput === 'function'\n );\n }\n\n get value(): string | undefined {\n return this.isControlled ? this.args.value : this.uncontrolledValue;\n }\n\n get type(): string {\n if (typeof this.args.type === 'string') {\n return this.args.type;\n }\n return 'text';\n }\n\n @action handleOnInput(event: Event): void {\n const value = (event.target as HTMLInputElement).value;\n\n if (this.isControlled) {\n this.args.onInput?.(value, event as InputEvent);\n } else {\n this.uncontrolledValue = value;\n }\n }\n\n @action handleOnChange(event: Event): void {\n const value = (event.target as HTMLInputElement).value;\n\n if (this.isControlled) {\n this.args.onChange?.(value, event as InputEvent);\n } else {\n this.uncontrolledValue = value;\n }\n }\n\n @action handleOnBlur(): void {\n this.args.onBlur?.();\n }\n\n @action clearValue(): void {\n if (this.isControlled) {\n this.args.onChange?.('');\n this.args.onInput?.('');\n } else {\n this.uncontrolledValue = '';\n }\n\n this.inputRef.current?.focus();\n triggerFormInputEvent(this.inputRef.current);\n }\n\n get isClearable(): boolean {\n if (\n this.args.isClearable === true &&\n this.value !== '' &&\n typeof this.value !== 'undefined'\n ) {\n return true;\n }\n return false;\n }\n\n get classes() {\n const { input } = useStyles();\n return input({\n size: this.args.size\n });\n }\n\n <template>\n <FormControl\n @size={{@size}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n @class={{this.classes.base class=@classes.base}}\n as |c|\n >\n <div class={{this.classes.innerContainer class=@classes.innerContainer}}>\n {{#if (has-block \"startContent\")}}\n <div\n data-test-id=\"input-start-content\"\n class={{this.classes.startContent\n class=@classes.startContent\n startContentPointerEvents=(if\n @startContentPointerEvents @startContentPointerEvents \"auto\"\n )\n }}\n >\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n <input\n {{this.inputRef.setup}}\n {{on \"input\" this.handleOnInput}}\n {{on \"change\" this.handleOnChange}}\n {{on \"blur\" this.handleOnBlur}}\n id={{c.id}}\n name={{@name}}\n value={{this.value}}\n type={{this.type}}\n disabled={{@isDisabled}}\n class={{this.classes.input\n class=@classes.input\n hasStartContent=(has-block \"startContent\")\n hasEndContent=(or (has-block \"endContent\") this.isClearable)\n }}\n data-component=\"input\"\n aria-invalid={{if c.isInvalid \"true\"}}\n aria-describedby={{c.describedBy @description c.isInvalid}}\n ...attributes\n />\n {{#if (or (has-block \"endContent\") this.isClearable)}}\n <div\n data-test-id=\"input-end-content\"\n class={{this.classes.endContent\n class=@classes.endContent\n endContentPointerEvents=(if\n @endContentPointerEvents @endContentPointerEvents \"auto\"\n )\n }}\n >\n {{yield to=\"endContent\"}}\n\n {{#if this.isClearable}}\n <CloseButton\n @title=\"Clear\"\n @variant=\"subtle\"\n @size=\"xs\"\n data-test-id=\"input-clear-button\"\n @onPress={{this.clearValue}}\n />\n {{/if}}\n </div>\n {{/if}}\n </div>\n </FormControl>\n </template>\n}\n\nexport { Input, type InputSignature };\nexport default Input;\n"],"names":["or","arg1","arg2","Input","Component","g","prototype","tracked","args","value","i","void 0","inputRef","ref","isControlled","onChange","onInput","uncontrolledValue","type","handleOnInput","event","target","n","action","handleOnChange","handleOnBlur","onBlur","clearValue","current","focus","triggerFormInputEvent","isClearable","classes","input","useStyles","size","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","on","CloseButton"],"mappings":";;;;;;;;;;;;;AAoEA,SAASA,GAAGC,IAAa,EAAEC,IAAa,EAAU;AAChD,EAAA,OAAO,CAAC,EAAED,IAAA,IAAQC,IAAI,CAAA;AACxB;AAEA,MAAMC,cAAcC,SAAA,CAAU;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,mBAAA,EAAA,CAC3BC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAoC,IAAI,CAACC,IAAI,CAACC,KAAK,IAAI,EAAA;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,kBAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,EAAAC,MAAA;EAExDC,QAAA,GAAWC,KAAI;EAEf,IAAIC,YAAAA,GAAe;AACjB,IAAA,OACE,OAAO,IAAI,CAACN,IAAI,CAACO,QAAQ,KAAK,UAAA,IAC9B,OAAO,IAAI,CAACP,IAAI,CAACQ,OAAO,KAAK,UAC/B;AACF,EAAA;EAEA,IAAIP,KAAAA,GAA4B;AAC9B,IAAA,OAAO,IAAI,CAACK,YAAY,GAAG,IAAI,CAACN,IAAI,CAACC,KAAK,GAAG,IAAI,CAACQ,iBAAiB;AACrE,EAAA;EAEA,IAAIC,IAAAA,GAAe;IACjB,IAAI,OAAO,IAAI,CAACV,IAAI,CAACU,IAAI,KAAK,QAAA,EAAU;AACtC,MAAA,OAAO,IAAI,CAACV,IAAI,CAACU,IAAI;AACvB,IAAA;AACA,IAAA,OAAO,MAAA;AACT,EAAA;EAEQC,aAAAA,CAAcC,KAAY,EAAQ;AACxC,IAAA,MAAMX,QAASW,KAAA,CAAMC,MAAM,CAAsBZ,KAAK;IAEtD,IAAI,IAAI,CAACK,YAAY,EAAE;MACrB,IAAI,CAACN,IAAI,CAACQ,OAAO,GAAGP,OAAOW,KAAS,CAAA;AACtC,IAAA,CAAA,MAAO;MACL,IAAI,CAACH,iBAAiB,GAAGR,KAAA;AAC3B,IAAA;AACF,EAAA;AAAA,EAAA;IAAAa,gBAAA,CAAA,IAAA,CAAAhB,SAAA,EAAA,eAAA,EAAA,CARCiB,MAAA,CAAA,CAAA;AAAA;EAUOC,cAAAA,CAAeJ,KAAY,EAAQ;AACzC,IAAA,MAAMX,QAASW,KAAA,CAAMC,MAAM,CAAsBZ,KAAK;IAEtD,IAAI,IAAI,CAACK,YAAY,EAAE;MACrB,IAAI,CAACN,IAAI,CAACO,QAAQ,GAAGN,OAAOW,KAAS,CAAA;AACvC,IAAA,CAAA,MAAO;MACL,IAAI,CAACH,iBAAiB,GAAGR,KAAA;AAC3B,IAAA;AACF,EAAA;AAAA,EAAA;IAAAa,gBAAA,CAAA,IAAA,CAAAhB,SAAA,EAAA,gBAAA,EAAA,CARCiB,MAAA,CAAA,CAAA;AAAA;AAUOE,EAAAA,YAAAA,GAAqB;AAC3B,IAAA,IAAI,CAACjB,IAAI,CAACkB,MAAM,IAAA;AAClB,EAAA;AAAA,EAAA;IAAAJ,gBAAA,CAAA,IAAA,CAAAhB,SAAA,EAAA,cAAA,EAAA,CAFCiB,MAAA,CAAA,CAAA;AAAA;AAIOI,EAAAA,UAAAA,GAAmB;IACzB,IAAI,IAAI,CAACb,YAAY,EAAE;AACrB,MAAA,IAAI,CAACN,IAAI,CAACO,QAAQ,GAAG,EAAA,CAAA;AACrB,MAAA,IAAI,CAACP,IAAI,CAACQ,OAAO,GAAG,EAAA,CAAA;AACtB,IAAA,CAAA,MAAO;MACL,IAAI,CAACC,iBAAiB,GAAG,EAAA;AAC3B,IAAA;AAEA,IAAA,IAAI,CAACL,QAAQ,CAACgB,OAAO,EAAEC,KAAA,EAAA;AACvBC,IAAAA,qBAAA,CAAsB,IAAI,CAAClB,QAAQ,CAACgB,OAAO,CAAA;AAC7C,EAAA;AAAA,EAAA;IAAAN,gBAAA,CAAA,IAAA,CAAAhB,SAAA,EAAA,YAAA,EAAA,CAVCiB,MAAA,CAAA,CAAA;AAAA;EAYD,IAAIQ,WAAAA,GAAuB;IACzB,IACE,IAAI,CAACvB,IAAI,CAACuB,WAAW,KAAK,IAAA,IAC1B,IAAI,CAACtB,KAAK,KAAK,EAAA,IACf,OAAO,IAAI,CAACA,KAAK,KAAK,WAAA,EACtB;AACA,MAAA,OAAO,IAAA;AACT,IAAA;AACA,IAAA,OAAO,KAAA;AACT,EAAA;EAEA,IAAIuB,OAAAA,GAAU;IACZ,MAAM;AAAEC,MAAAA;KAAO,GAAGC,SAAA,EAAA;AAClB,IAAA,OAAOD,KAAA,CAAM;AACXE,MAAAA,IAAA,EAAM,IAAI,CAAC3B,IAAI,CAAC2B;AAClB,KAAA,CAAA;AACF,EAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,guDAAA,EAsEA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;QAAAxC,EAAA;QAAAyC,EAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -10,7 +10,7 @@ import { ListManager, keyAndLabelForItem } from '@frontile/collections/utils/lis
|
|
|
10
10
|
import { IconChevronUpDown } from './icons.js';
|
|
11
11
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
12
12
|
import { setComponentTemplate } from '@ember/component';
|
|
13
|
-
import {
|
|
13
|
+
import { a as decorateMethodV2, d as decorateFieldV2, i as initializeDeferredDecorator } from '../runtime-BPCpkOf1-B5Lbloj7.js';
|
|
14
14
|
|
|
15
15
|
class NativeSelect extends Component {
|
|
16
16
|
constructor(owner, args) {
|
|
@@ -15,7 +15,7 @@ class RadioGroup extends Component {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
static {
|
|
18
|
-
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} ...attributes as |c|>\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div class={{this.classes.optionsContainer class=@classes.optionsContainer}} data-orientation={{if @orientation @orientation \"vertical\"}}>\n {{!-- @glint-nocheck: Radio has a type param, glint cannt handle that with WithboundArgs--}}\n {{yield (component Radio name=@name onChange=@onChange size=@size checkedValue=@value)}}\n </div>\n </FormControl>\n ", {
|
|
18
|
+
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} ...attributes as |c|>\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div class={{this.classes.optionsContainer class=@classes.optionsContainer}} data-orientation={{if @orientation @orientation \"vertical\"}}>\n {{!-- @glint-nocheck: Radio has a type param, glint cannt handle that with WithboundArgs--}}\n {{yield (component Radio name=@name onChange=@onChange size=@size checkedValue=@value isDisabled=@isDisabled)}}\n </div>\n </FormControl>\n ", {
|
|
19
19
|
strictMode: true,
|
|
20
20
|
scope: () => ({
|
|
21
21
|
FormControl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio-group.js","sources":["../../src/components/radio-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { Radio, type RadioSignature } from './radio';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport {\n useStyles,\n type RadioGroupSlots,\n type RadioVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport type { WithBoundArgs } from '@glint/template';\n\ninterface Args<T> extends FormControlSharedArgs {\n name?: string;\n value?: T;\n onChange?: RadioSignature<T>['Args']['onChange'];\n size?: RadioVariants['size'];\n classes?: SlotsToClasses<RadioGroupSlots>;\n\n /*\n *\n * @defaultValue 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n}\n\ninterface RadioGroupSignature<T> {\n Args: Args<T>;\n Blocks: {\n default: [\n Radio: WithBoundArgs
|
|
1
|
+
{"version":3,"file":"radio-group.js","sources":["../../src/components/radio-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { Radio, type RadioSignature } from './radio';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport {\n useStyles,\n type RadioGroupSlots,\n type RadioVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport type { WithBoundArgs } from '@glint/template';\n\ninterface Args<T> extends FormControlSharedArgs {\n name?: string;\n value?: T;\n onChange?: RadioSignature<T>['Args']['onChange'];\n size?: RadioVariants['size'];\n classes?: SlotsToClasses<RadioGroupSlots>;\n\n /*\n *\n * @defaultValue 'vertical'\n */\n orientation?: 'horizontal' | 'vertical';\n}\n\ninterface RadioGroupSignature<T> {\n Args: Args<T>;\n Blocks: {\n default: [\n Radio: WithBoundArgs<\n typeof Radio,\n 'name' | 'onChange' | 'checkedValue' | 'isDisabled'\n >\n ];\n };\n Element: HTMLDivElement;\n}\n\nclass RadioGroup<T extends string | number | boolean> extends Component<\n RadioGroupSignature<T>\n> {\n get classes() {\n const { radioGroup } = useStyles();\n return radioGroup({\n size: this.args.size\n });\n }\n\n <template>\n <FormControl\n @size={{@size}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n @class={{this.classes.base class=@classes.base}}\n ...attributes\n as |c|\n >\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div\n class={{this.classes.optionsContainer class=@classes.optionsContainer}}\n data-orientation={{if @orientation @orientation \"vertical\"}}\n >\n {{! @glint-nocheck: Radio has a type param, glint cannt handle that with WithboundArgs}}\n {{yield\n (component\n Radio\n name=@name\n onChange=@onChange\n size=@size\n checkedValue=@value\n isDisabled=@isDisabled\n )\n }}\n </div>\n </FormControl>\n </template>\n}\n\nexport { RadioGroup, type RadioGroupSignature };\nexport default RadioGroup;\n"],"names":["RadioGroup","Component","classes","radioGroup","useStyles","size","args","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","Radio"],"mappings":";;;;;;;AAsCA,MAAMA,UAAA,SAAwDC,SAAA,CACxC;EAEpB,IAAIC,OAAAA,GAAU;IACZ,MAAM;AAAEC,MAAAA;KAAY,GAAGC,SAAA,EAAA;AACvB,IAAA,OAAOD,UAAA,CAAW;AAChBE,MAAAA,IAAA,EAAM,IAAI,CAACC,IAAI,CAACD;AAClB,KAAA,CAAA;AACF,EAAA;AAEA,EAAA;IAAAE,oBAAA,CAAAC,kBAAA,CAAA,stBAAA,EA+BA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|