@frontile/forms 0.15.0 → 0.16.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.
- package/addon-main.js +37 -0
- package/{components → declarations/components}/form-checkbox-group.d.ts +3 -1
- package/declarations/components/form-checkbox-group.d.ts.map +1 -0
- package/{components → declarations/components}/form-checkbox.d.ts +9 -0
- package/declarations/components/form-checkbox.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/checkbox.d.ts +2 -0
- package/declarations/components/form-field/checkbox.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/feedback.d.ts +5 -0
- package/declarations/components/form-field/feedback.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/hint.d.ts +4 -0
- package/declarations/components/form-field/hint.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/input.d.ts +4 -2
- package/declarations/components/form-field/input.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/label.d.ts +4 -0
- package/declarations/components/form-field/label.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/radio.d.ts +3 -1
- package/declarations/components/form-field/radio.d.ts.map +1 -0
- package/{components → declarations/components}/form-field/textarea.d.ts +4 -2
- package/declarations/components/form-field/textarea.d.ts.map +1 -0
- package/declarations/components/form-field.d.ts +38 -0
- package/declarations/components/form-field.d.ts.map +1 -0
- package/{components → declarations/components}/form-input.d.ts +5 -1
- package/declarations/components/form-input.d.ts.map +1 -0
- package/{components → declarations/components}/form-radio-group.d.ts +6 -2
- package/declarations/components/form-radio-group.d.ts.map +1 -0
- package/{components → declarations/components}/form-radio.d.ts +9 -1
- package/declarations/components/form-radio.d.ts.map +1 -0
- package/{components → declarations/components}/form-select.d.ts +6 -2
- package/declarations/components/form-select.d.ts.map +1 -0
- package/{components → declarations/components}/form-textarea.d.ts +5 -1
- package/declarations/components/form-textarea.d.ts.map +1 -0
- package/declarations/template-registry.d.ts +33 -0
- package/declarations/template-registry.d.ts.map +1 -0
- package/dist/_app_/components/form-checkbox-group.js +1 -0
- package/dist/_app_/components/form-checkbox.js +1 -0
- package/dist/_app_/components/form-field/checkbox.js +1 -0
- package/dist/_app_/components/form-field/feedback.js +1 -0
- package/dist/_app_/components/form-field/hint.js +1 -0
- package/dist/_app_/components/form-field/input.js +1 -0
- package/dist/_app_/components/form-field/label.js +1 -0
- package/dist/_app_/components/form-field/radio.js +1 -0
- package/dist/_app_/components/form-field/textarea.js +1 -0
- package/dist/_app_/components/form-field.js +1 -0
- package/dist/_app_/components/form-input.js +1 -0
- package/dist/_app_/components/form-radio-group.js +1 -0
- package/dist/_app_/components/form-radio.js +1 -0
- package/dist/_app_/components/form-select.js +1 -0
- package/dist/_app_/components/form-textarea.js +1 -0
- package/dist/components/form-checkbox-group.js +55 -0
- package/dist/components/form-checkbox-group.js.map +1 -0
- package/dist/components/form-checkbox.js +30 -0
- package/dist/components/form-checkbox.js.map +1 -0
- package/dist/components/form-field/checkbox.js +30 -0
- package/dist/components/form-field/checkbox.js.map +1 -0
- package/dist/components/form-field/feedback.js +29 -0
- package/dist/components/form-field/feedback.js.map +1 -0
- package/dist/components/form-field/hint.js +17 -0
- package/dist/components/form-field/hint.js.map +1 -0
- package/dist/components/form-field/input.js +36 -0
- package/dist/components/form-field/input.js.map +1 -0
- package/dist/components/form-field/label.js +17 -0
- package/dist/components/form-field/label.js.map +1 -0
- package/dist/components/form-field/radio.js +29 -0
- package/dist/components/form-field/radio.js.map +1 -0
- package/dist/components/form-field/textarea.js +30 -0
- package/dist/components/form-field/textarea.js.map +1 -0
- package/dist/components/form-field.js +44 -0
- package/dist/components/form-field.js.map +1 -0
- package/dist/components/form-input.js +64 -0
- package/dist/components/form-input.js.map +1 -0
- package/dist/components/form-radio-group.js +55 -0
- package/dist/components/form-radio-group.js.map +1 -0
- package/dist/components/form-radio.js +34 -0
- package/dist/components/form-radio.js.map +1 -0
- package/dist/components/form-select.js +102 -0
- package/dist/components/form-select.js.map +1 -0
- package/dist/components/form-textarea.js +23 -0
- package/dist/components/form-textarea.js.map +1 -0
- package/dist/template-registry.js +2 -0
- package/dist/template-registry.js.map +1 -0
- package/package.json +91 -49
- package/addon/components/form-checkbox-demo/usage.md +0 -30
- package/addon/components/form-checkbox-group-demo/usage.md +0 -54
- package/addon/components/form-checkbox-group.hbs +0 -38
- package/addon/components/form-checkbox-group.md +0 -5
- package/addon/components/form-checkbox-group.ts +0 -68
- package/addon/components/form-checkbox.hbs +0 -43
- package/addon/components/form-checkbox.md +0 -5
- package/addon/components/form-checkbox.ts +0 -45
- package/addon/components/form-field/checkbox.hbs +0 -10
- package/addon/components/form-field/checkbox.ts +0 -32
- package/addon/components/form-field/feedback.hbs +0 -10
- package/addon/components/form-field/feedback.ts +0 -30
- package/addon/components/form-field/hint.hbs +0 -8
- package/addon/components/form-field/hint.ts +0 -13
- package/addon/components/form-field/index.hbs +0 -20
- package/addon/components/form-field/index.ts +0 -46
- package/addon/components/form-field/input.hbs +0 -10
- package/addon/components/form-field/input.ts +0 -40
- package/addon/components/form-field/label.hbs +0 -8
- package/addon/components/form-field/label.ts +0 -13
- package/addon/components/form-field/radio.hbs +0 -11
- package/addon/components/form-field/radio.ts +0 -31
- package/addon/components/form-field/textarea.hbs +0 -10
- package/addon/components/form-field/textarea.ts +0 -32
- package/addon/components/form-input-demo/hint.md +0 -34
- package/addon/components/form-input-demo/no-label.md +0 -33
- package/addon/components/form-input-demo/simple.md +0 -42
- package/addon/components/form-input-demo/with-button.md +0 -60
- package/addon/components/form-input.hbs +0 -45
- package/addon/components/form-input.md +0 -5
- package/addon/components/form-input.ts +0 -96
- package/addon/components/form-radio-demo/usage.md +0 -39
- package/addon/components/form-radio-group-demo/usage.md +0 -43
- package/addon/components/form-radio-group.hbs +0 -39
- package/addon/components/form-radio-group.md +0 -5
- package/addon/components/form-radio-group.ts +0 -67
- package/addon/components/form-radio.hbs +0 -40
- package/addon/components/form-radio.md +0 -5
- package/addon/components/form-radio.ts +0 -53
- package/addon/components/form-select-demo/multiple.md +0 -60
- package/addon/components/form-select-demo/usage.md +0 -60
- package/addon/components/form-select.hbs +0 -101
- package/addon/components/form-select.md +0 -11
- package/addon/components/form-select.ts +0 -126
- package/addon/components/form-textarea-demo/usage.md +0 -40
- package/addon/components/form-textarea.hbs +0 -44
- package/addon/components/form-textarea.md +0 -5
- package/addon/components/form-textarea.ts +0 -7
- package/app/components/form-checkbox-group.js +0 -1
- package/app/components/form-checkbox.js +0 -1
- package/app/components/form-field/checkbox.js +0 -1
- package/app/components/form-field/feedback.js +0 -1
- package/app/components/form-field/hint.js +0 -1
- package/app/components/form-field/index.js +0 -1
- package/app/components/form-field/input.js +0 -1
- package/app/components/form-field/label.js +0 -1
- package/app/components/form-field/radio.js +0 -1
- package/app/components/form-field/textarea.js +0 -1
- package/app/components/form-input.js +0 -1
- package/app/components/form-radio-group.js +0 -1
- package/app/components/form-radio.js +0 -1
- package/app/components/form-select.js +0 -1
- package/app/components/form-textarea.js +0 -1
- package/components/form-field/index.d.ts +0 -36
- package/config/environment.js +0 -5
- package/index.js +0 -34
- package/tsconfig.json +0 -23
- package/types/dummy/index.d.ts +0 -0
- package/types/ember-get-config.d.ts +0 -3
- package/types/ember-power-select/test-support.d.ts +0 -29
- package/types/global.d.ts +0 -6
- package/types/index.d.ts +0 -1
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
|
|
4
|
-
export interface FormFieldCheckboxArgs {
|
|
5
|
-
checked?: boolean;
|
|
6
|
-
name?: string;
|
|
7
|
-
size?: 'sm' | 'lg';
|
|
8
|
-
|
|
9
|
-
// Callback when onchange is triggered
|
|
10
|
-
onChange?: (value: boolean, event: Event) => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface FormFieldCheckboxSignature {
|
|
14
|
-
Args: FormFieldCheckboxArgs;
|
|
15
|
-
Element: HTMLInputElement;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default class FormFieldCheckbox extends Component<FormFieldCheckboxSignature> {
|
|
19
|
-
get isChecked(): boolean {
|
|
20
|
-
return !!this.args.checked;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@action handleChange(event: Event): void {
|
|
24
|
-
event.preventDefault();
|
|
25
|
-
|
|
26
|
-
const value = !this.args.checked;
|
|
27
|
-
|
|
28
|
-
if (typeof this.args.onChange === 'function') {
|
|
29
|
-
this.args.onChange(value, event);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
|
|
3
|
-
export interface FormFieldFeedbackArgs {
|
|
4
|
-
isError?: boolean;
|
|
5
|
-
errors?: string[] | string;
|
|
6
|
-
size?: 'sm' | 'lg';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface FormFieldFeedbackSignature {
|
|
10
|
-
Args: FormFieldFeedbackArgs;
|
|
11
|
-
Element: HTMLDivElement;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default class FormFieldFeedback extends Component<FormFieldFeedbackSignature> {
|
|
15
|
-
get isError(): boolean {
|
|
16
|
-
return (
|
|
17
|
-
typeof this.args.errors !== 'undefined' || this.args.isError === true
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get errorMessage(): string {
|
|
22
|
-
if (!this.args.errors) return '';
|
|
23
|
-
|
|
24
|
-
if (typeof this.args.errors === 'string') {
|
|
25
|
-
return this.args.errors;
|
|
26
|
-
} else {
|
|
27
|
-
return this.args.errors.join('; ');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
|
|
3
|
-
export interface FormFieldHintArgs {
|
|
4
|
-
id?: string;
|
|
5
|
-
size?: 'sm' | 'lg';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface FormFieldHintSignature {
|
|
9
|
-
Args: FormFieldHintArgs;
|
|
10
|
-
Element: HTMLDivElement;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default class FormFieldHint extends Component<FormFieldHintSignature> {}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<div
|
|
2
|
-
...attributes
|
|
3
|
-
>
|
|
4
|
-
{{yield
|
|
5
|
-
(hash
|
|
6
|
-
id=this.id
|
|
7
|
-
hintId=this.hintId
|
|
8
|
-
feedbackId=this.feedbackId
|
|
9
|
-
|
|
10
|
-
Label=(component "form-field/label" for=this.id size=@size)
|
|
11
|
-
Hint=(component "form-field/hint" id=this.hintId size=@size)
|
|
12
|
-
Feedback=(component "form-field/feedback" id=this.feedbackId size=@size)
|
|
13
|
-
|
|
14
|
-
Input=(component "form-field/input" id=this.id size=@size)
|
|
15
|
-
Textarea=(component "form-field/textarea" id=this.id size=@size)
|
|
16
|
-
Checkbox=(component "form-field/checkbox" id=this.id size=@size)
|
|
17
|
-
Radio=(component "form-field/radio" id=this.id size=@size)
|
|
18
|
-
)
|
|
19
|
-
}}
|
|
20
|
-
</div>
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { guidFor } from '@ember/object/internals';
|
|
3
|
-
import FormFieldCheckbox from './checkbox';
|
|
4
|
-
import FormFieldFeedback from './feedback';
|
|
5
|
-
import FormFieldHint from './hint';
|
|
6
|
-
import FormFieldInput from './input';
|
|
7
|
-
import FormFieldLabel from './label';
|
|
8
|
-
import FormFieldRadio from './radio';
|
|
9
|
-
import FormFieldTextarea from './textarea';
|
|
10
|
-
|
|
11
|
-
export interface FormFieldArgs {
|
|
12
|
-
size?: 'sm' | 'lg';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface FormFieldSignature {
|
|
16
|
-
Args: FormFieldArgs;
|
|
17
|
-
Blocks: {
|
|
18
|
-
default: [
|
|
19
|
-
{
|
|
20
|
-
id: string;
|
|
21
|
-
hintId: string;
|
|
22
|
-
feedbackId: string;
|
|
23
|
-
Label: FormFieldLabel;
|
|
24
|
-
Hint: FormFieldHint;
|
|
25
|
-
Feedback: FormFieldFeedback;
|
|
26
|
-
Input: FormFieldInput;
|
|
27
|
-
Textarea: FormFieldTextarea;
|
|
28
|
-
Checkbox: FormFieldCheckbox;
|
|
29
|
-
Radio: FormFieldRadio;
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
};
|
|
33
|
-
Element: HTMLDivElement;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default class FormField extends Component<FormFieldSignature> {
|
|
37
|
-
id = guidFor(this);
|
|
38
|
-
|
|
39
|
-
get hintId(): string {
|
|
40
|
-
return this.id + '-hint';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get feedbackId(): string {
|
|
44
|
-
return this.id + '-feedback';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
|
|
4
|
-
export interface FormFieldInputArgs {
|
|
5
|
-
id?: string;
|
|
6
|
-
type?: string;
|
|
7
|
-
size?: 'sm' | 'lg';
|
|
8
|
-
|
|
9
|
-
// Callback when oninput is triggered
|
|
10
|
-
onInput?: (value: string, event: InputEvent) => void;
|
|
11
|
-
|
|
12
|
-
// Callback when onchange is triggered
|
|
13
|
-
onChange?: (value: string, event: InputEvent) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface FormFieldInputSignature {
|
|
17
|
-
Args: FormFieldInputArgs;
|
|
18
|
-
Element: HTMLInputElement;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default class FormFieldInput extends Component<FormFieldInputSignature> {
|
|
22
|
-
get type(): string {
|
|
23
|
-
if (typeof this.args.type === 'string') {
|
|
24
|
-
return this.args.type;
|
|
25
|
-
}
|
|
26
|
-
return 'text';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@action handleOnInput(event: InputEvent): void {
|
|
30
|
-
if (typeof this.args.onInput === 'function') {
|
|
31
|
-
this.args.onInput((event.target as HTMLInputElement).value, event);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@action handleOnChange(event: InputEvent): void {
|
|
36
|
-
if (typeof this.args.onChange === 'function') {
|
|
37
|
-
this.args.onChange((event.target as HTMLInputElement).value, event);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
|
|
3
|
-
export interface FormFieldLabelArgs {
|
|
4
|
-
for?: string;
|
|
5
|
-
size?: 'sm' | 'lg';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface FormFieldLabelSignature {
|
|
9
|
-
Args: FormFieldLabelArgs;
|
|
10
|
-
Element: HTMLLabelElement;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default class FormFieldLabel extends Component<FormFieldLabelSignature> {}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
|
|
4
|
-
export interface FormFieldRadioArgs {
|
|
5
|
-
value?: unknown;
|
|
6
|
-
checked?: unknown;
|
|
7
|
-
name?: string;
|
|
8
|
-
size?: 'sm' | 'lg';
|
|
9
|
-
|
|
10
|
-
// Callback when onchange is triggered
|
|
11
|
-
onChange?: (value: unknown, event: Event) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface FormFieldRadioSignature {
|
|
15
|
-
Args: FormFieldRadioArgs;
|
|
16
|
-
Element: HTMLInputElement;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default class FormFieldRadio extends Component<FormFieldRadioSignature> {
|
|
20
|
-
get isChecked(): boolean {
|
|
21
|
-
return this.args.checked === this.args.value;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@action handleChange(event: Event): void {
|
|
25
|
-
event.preventDefault();
|
|
26
|
-
|
|
27
|
-
if (typeof this.args.onChange === 'function') {
|
|
28
|
-
this.args.onChange(this.args.value, event);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
|
|
4
|
-
export interface FormFieldTextareaArgs {
|
|
5
|
-
id?: string;
|
|
6
|
-
size?: 'sm' | 'lg';
|
|
7
|
-
|
|
8
|
-
// Callback when oninput is triggered
|
|
9
|
-
onInput?: (value: string, event: InputEvent) => void;
|
|
10
|
-
|
|
11
|
-
// Callback when onchange is triggered
|
|
12
|
-
onChange?: (value: string, event: InputEvent) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface FormFieldTextareaSignature {
|
|
16
|
-
Args: FormFieldTextareaArgs;
|
|
17
|
-
Element: HTMLTextAreaElement;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default class FormFieldTextarea extends Component<FormFieldTextareaSignature> {
|
|
21
|
-
@action handleOnInput(event: InputEvent): void {
|
|
22
|
-
if (typeof this.args.onInput === 'function') {
|
|
23
|
-
this.args.onInput((event.target as HTMLInputElement).value, event);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@action handleOnChange(event: InputEvent): void {
|
|
28
|
-
if (typeof this.args.onChange === 'function') {
|
|
29
|
-
this.args.onChange((event.target as HTMLInputElement).value, event);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 3
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Input with Hint
|
|
6
|
-
|
|
7
|
-
You can pass `@hint` to the component to add hint content.
|
|
8
|
-
|
|
9
|
-
```hbs template
|
|
10
|
-
<FormInput
|
|
11
|
-
@label="I have Hint"
|
|
12
|
-
@hint="InputText support optional hints"
|
|
13
|
-
@value={{this.value}}
|
|
14
|
-
@onInput={{this.setValue}}
|
|
15
|
-
/>
|
|
16
|
-
|
|
17
|
-
<p class="mt-4">
|
|
18
|
-
You typed, "{{this.value}}"
|
|
19
|
-
</p>
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
```js component
|
|
23
|
-
import Component from '@glimmer/component';
|
|
24
|
-
import { tracked } from '@glimmer/tracking';
|
|
25
|
-
import { action } from '@ember/object';
|
|
26
|
-
|
|
27
|
-
export default class DemoComponent extends Component {
|
|
28
|
-
@tracked value = '';
|
|
29
|
-
|
|
30
|
-
@action setValue(value) {
|
|
31
|
-
this.value = value;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
```
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 2
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# No Label
|
|
6
|
-
|
|
7
|
-
If you don't want the label then simply leave it out of the component tag:
|
|
8
|
-
|
|
9
|
-
```hbs template
|
|
10
|
-
<FormInput
|
|
11
|
-
@value={{this.value}}
|
|
12
|
-
@onInput={{this.setValue}}
|
|
13
|
-
placeholder="I have no label"
|
|
14
|
-
/>
|
|
15
|
-
|
|
16
|
-
<p class="mt-4">
|
|
17
|
-
You typed, "{{this.value}}"
|
|
18
|
-
</p>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
```js component
|
|
22
|
-
import Component from '@glimmer/component';
|
|
23
|
-
import { tracked } from '@glimmer/tracking';
|
|
24
|
-
import { action } from '@ember/object';
|
|
25
|
-
|
|
26
|
-
export default class DemoComponent extends Component {
|
|
27
|
-
@tracked value = '';
|
|
28
|
-
|
|
29
|
-
@action setValue(value) {
|
|
30
|
-
this.value = value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Standard usage
|
|
6
|
-
|
|
7
|
-
The most common use case is a plain text input with validation:
|
|
8
|
-
|
|
9
|
-
```hbs template
|
|
10
|
-
<FormInput
|
|
11
|
-
@label="First Name"
|
|
12
|
-
@value={{this.value}}
|
|
13
|
-
@onInput={{this.setValue}}
|
|
14
|
-
@errors={{this.validationErrors}}
|
|
15
|
-
/>
|
|
16
|
-
|
|
17
|
-
<p class="mt-4">
|
|
18
|
-
You typed, "{{this.value}}"
|
|
19
|
-
</p>
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
```js component
|
|
23
|
-
import Component from '@glimmer/component';
|
|
24
|
-
import { tracked } from '@glimmer/tracking';
|
|
25
|
-
import { action } from '@ember/object';
|
|
26
|
-
|
|
27
|
-
export default class DemoComponent extends Component {
|
|
28
|
-
@tracked value = '';
|
|
29
|
-
|
|
30
|
-
get validationErrors() {
|
|
31
|
-
if (/^$/.test(this.value)) {
|
|
32
|
-
return ['Please enter First Name'];
|
|
33
|
-
} else {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@action setValue(value) {
|
|
39
|
-
this.value = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
```
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 4
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Input with Button
|
|
6
|
-
|
|
7
|
-
This is an example of how to implement an input with a button next to it.
|
|
8
|
-
|
|
9
|
-
```hbs template
|
|
10
|
-
<FormInput
|
|
11
|
-
@value={{this.value}}
|
|
12
|
-
@onInput={{this.setValue}}
|
|
13
|
-
@label="Referral Code"
|
|
14
|
-
@errors={{this.validationErrors}}
|
|
15
|
-
@onChange={{this.validate}}
|
|
16
|
-
placeholder="Input your URL or 6 Digit referral code"
|
|
17
|
-
class="rounded-r-none"
|
|
18
|
-
>
|
|
19
|
-
<button
|
|
20
|
-
type="button"
|
|
21
|
-
{{on "click" this.validate}}
|
|
22
|
-
class="px-4 py-2 border text-gray-100 rounded-r
|
|
23
|
-
{{if this.isValid "bg-green-800 border-green-800 hover:bg-green-700" "bg-teal-600 border-teal-600 hover:bg-teal-700"}}"
|
|
24
|
-
>
|
|
25
|
-
{{#if this.isValid}}
|
|
26
|
-
<span>
|
|
27
|
-
Code Applied
|
|
28
|
-
</span>
|
|
29
|
-
{{else}}
|
|
30
|
-
Apply
|
|
31
|
-
{{/if}}
|
|
32
|
-
</button>
|
|
33
|
-
</FormInput>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
```js component
|
|
37
|
-
import Component from '@glimmer/component';
|
|
38
|
-
import { tracked } from '@glimmer/tracking';
|
|
39
|
-
import { action } from '@ember/object';
|
|
40
|
-
|
|
41
|
-
export default class DemoComponent extends Component {
|
|
42
|
-
@tracked value = '';
|
|
43
|
-
@tracked validationErrors = [];
|
|
44
|
-
@tracked isValid = false;
|
|
45
|
-
|
|
46
|
-
@action setValue(value) {
|
|
47
|
-
this.value = value;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@action validate() {
|
|
51
|
-
if (/^$/.test(this.value)) {
|
|
52
|
-
this.validationErrors = ['Incorrect Code Applied'];
|
|
53
|
-
this.isValid = false;
|
|
54
|
-
} else {
|
|
55
|
-
this.validationErrors = [];
|
|
56
|
-
this.isValid = true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<FormField
|
|
2
|
-
@size={{@size}}
|
|
3
|
-
class={{use-frontile-class "form-input" @size class=@containerClass}}
|
|
4
|
-
as |f|
|
|
5
|
-
>
|
|
6
|
-
{{#if @label}}
|
|
7
|
-
<f.Label
|
|
8
|
-
class={{use-frontile-class "form-input" @size part="label"}}
|
|
9
|
-
>
|
|
10
|
-
{{@label}}
|
|
11
|
-
</f.Label>
|
|
12
|
-
{{/if}}
|
|
13
|
-
|
|
14
|
-
{{#if @hint}}
|
|
15
|
-
<f.Hint
|
|
16
|
-
class={{use-frontile-class "form-input" @size part="hint"}}
|
|
17
|
-
>
|
|
18
|
-
{{@hint}}
|
|
19
|
-
</f.Hint>
|
|
20
|
-
{{/if}}
|
|
21
|
-
|
|
22
|
-
<f.Input
|
|
23
|
-
{{on "focus" this.handleFocusIn}}
|
|
24
|
-
{{on "blur" this.handleFocusOut}}
|
|
25
|
-
|
|
26
|
-
@onInput={{@onInput}}
|
|
27
|
-
@onChange={{@onChange}}
|
|
28
|
-
@value={{@value}}
|
|
29
|
-
@type={{@type}}
|
|
30
|
-
|
|
31
|
-
class={{use-frontile-class "form-input" @size part="input"}}
|
|
32
|
-
aria-invalid={{if this.showErrorFeedback "true"}}
|
|
33
|
-
aria-describedby="{{if @hint f.hintId}}{{if this.showErrorFeedback (concat " " f.feedbackId)}}"
|
|
34
|
-
...attributes
|
|
35
|
-
/>
|
|
36
|
-
|
|
37
|
-
{{yield}}
|
|
38
|
-
|
|
39
|
-
{{#if this.showErrorFeedback}}
|
|
40
|
-
<f.Feedback
|
|
41
|
-
class={{use-frontile-class "form-input" @size part="feedback"}}
|
|
42
|
-
@errors={{@errors}}
|
|
43
|
-
/>
|
|
44
|
-
{{/if}}
|
|
45
|
-
</FormField>
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
import { tracked } from '@glimmer/tracking';
|
|
4
|
-
|
|
5
|
-
export interface FormInputArgs {
|
|
6
|
-
/**
|
|
7
|
-
* The value to be used in the input.
|
|
8
|
-
* You must also pass `onChange` or `onInput` to update its value.
|
|
9
|
-
*/
|
|
10
|
-
value: unknown;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The input type
|
|
14
|
-
* @defaultValue 'text'
|
|
15
|
-
*/
|
|
16
|
-
type?: string;
|
|
17
|
-
|
|
18
|
-
/** The group label */
|
|
19
|
-
label?: string;
|
|
20
|
-
/** A help text to be displayed */
|
|
21
|
-
hint?: string;
|
|
22
|
-
/** If the form has been submitted, used to force displaying errors */
|
|
23
|
-
hasSubmitted?: boolean;
|
|
24
|
-
/** If has errors */
|
|
25
|
-
hasError?: boolean;
|
|
26
|
-
/** Force displaying errors */
|
|
27
|
-
showError?: boolean;
|
|
28
|
-
/** A list of errors or a single text describing the error */
|
|
29
|
-
errors?: string[] | string;
|
|
30
|
-
/** CSS classes to be added in the container element */
|
|
31
|
-
containerClass?: string;
|
|
32
|
-
/** The size */
|
|
33
|
-
size?: 'sm' | 'lg';
|
|
34
|
-
|
|
35
|
-
/** Callback when oninput is triggered */
|
|
36
|
-
onInput?: (value: string, event: InputEvent) => void;
|
|
37
|
-
|
|
38
|
-
/** Callback when onchange is triggered */
|
|
39
|
-
onChange?: (value: string, event: InputEvent) => void;
|
|
40
|
-
|
|
41
|
-
/** Callback when onfocus is triggered */
|
|
42
|
-
onFocusIn?: (event: FocusEvent) => void;
|
|
43
|
-
|
|
44
|
-
/** Callback when onblur is triggered */
|
|
45
|
-
onFocusOut?: (event: FocusEvent) => void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface FormInputBaseSignature {
|
|
49
|
-
Args: FormInputArgs;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface FormInputSignature extends FormInputBaseSignature {
|
|
53
|
-
Element: HTMLInputElement;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class FormInputBase<
|
|
57
|
-
T extends FormInputBaseSignature
|
|
58
|
-
> extends Component<T> {
|
|
59
|
-
@tracked shouldShowErrorFeedback = false;
|
|
60
|
-
|
|
61
|
-
get showErrorFeedback(): boolean {
|
|
62
|
-
if (this.args.hasError === false) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
(this.args.showError ||
|
|
68
|
-
this.args.hasSubmitted ||
|
|
69
|
-
this.shouldShowErrorFeedback) &&
|
|
70
|
-
this.args.errors &&
|
|
71
|
-
this.args.errors.length > 0
|
|
72
|
-
) {
|
|
73
|
-
return true;
|
|
74
|
-
} else {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@action handleFocusIn(event: FocusEvent): void {
|
|
80
|
-
this.shouldShowErrorFeedback = false;
|
|
81
|
-
|
|
82
|
-
if (typeof this.args.onFocusIn === 'function') {
|
|
83
|
-
this.args.onFocusIn(event);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@action handleFocusOut(event: FocusEvent): void {
|
|
88
|
-
this.shouldShowErrorFeedback = true;
|
|
89
|
-
|
|
90
|
-
if (typeof this.args.onFocusOut === 'function') {
|
|
91
|
-
this.args.onFocusOut(event);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export default class FormInput extends FormInputBase<FormInputSignature> {}
|