@frontile/forms 0.15.0 → 0.16.0-alpha.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 +90 -48
- 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,39 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Usage
|
|
6
|
-
|
|
7
|
-
```hbs template
|
|
8
|
-
<FormRadio
|
|
9
|
-
name="my-radio-input"
|
|
10
|
-
@label="Yes"
|
|
11
|
-
@value={{true}}
|
|
12
|
-
@checked={{this.value}}
|
|
13
|
-
@onChange={{this.setValue}}
|
|
14
|
-
/>
|
|
15
|
-
|
|
16
|
-
<FormRadio
|
|
17
|
-
name="my-radio-input"
|
|
18
|
-
@label="No"
|
|
19
|
-
@value={{false}}
|
|
20
|
-
@checked={{this.value}}
|
|
21
|
-
@onChange={{this.setValue}}
|
|
22
|
-
/>
|
|
23
|
-
|
|
24
|
-
<p class="mt-4">Selected Value: "{{this.value}}"</p>
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
```js component
|
|
28
|
-
import Component from '@glimmer/component';
|
|
29
|
-
import { tracked } from '@glimmer/tracking';
|
|
30
|
-
import { action } from '@ember/object';
|
|
31
|
-
|
|
32
|
-
export default class DemoComponent extends Component {
|
|
33
|
-
@tracked value = '';
|
|
34
|
-
|
|
35
|
-
@action setValue(value) {
|
|
36
|
-
this.value = value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
```
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Usage
|
|
6
|
-
|
|
7
|
-
```hbs template
|
|
8
|
-
<FormRadioGroup
|
|
9
|
-
@label="Grouped radio buttons"
|
|
10
|
-
@value={{this.value}}
|
|
11
|
-
@onChange={{this.setValue}}
|
|
12
|
-
@errors={{this.validationErrors}}
|
|
13
|
-
as |Radio|
|
|
14
|
-
>
|
|
15
|
-
<Radio @value={{true}} @label="Yes" />
|
|
16
|
-
<Radio @value={{false}} @label="No" />
|
|
17
|
-
<Radio @value="maybe" @label="Maybe" />
|
|
18
|
-
</FormRadioGroup>
|
|
19
|
-
|
|
20
|
-
<p class="mt-4">Selected Value: "{{this.value}}"</p>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```js component
|
|
24
|
-
import Component from '@glimmer/component';
|
|
25
|
-
import { tracked } from '@glimmer/tracking';
|
|
26
|
-
import { action } from '@ember/object';
|
|
27
|
-
|
|
28
|
-
export default class DemoComponent extends Component {
|
|
29
|
-
@tracked value = '';
|
|
30
|
-
|
|
31
|
-
get validationErrors() {
|
|
32
|
-
if (this.value === 'maybe') {
|
|
33
|
-
return ['You cannot select maybe as an option'];
|
|
34
|
-
} else {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@action setValue(value) {
|
|
40
|
-
this.value = value;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
```
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
<FormField
|
|
2
|
-
@size={{@size}}
|
|
3
|
-
class={{use-frontile-class "form-radio-group" @size (if @isInline "inline") class=@containerClass}}
|
|
4
|
-
role="radiogroup"
|
|
5
|
-
...attributes
|
|
6
|
-
as |f|
|
|
7
|
-
>
|
|
8
|
-
{{#if @label}}
|
|
9
|
-
<f.Label
|
|
10
|
-
class={{use-frontile-class "form-radio-group" @size (if @isInline "inline") part="label"}}
|
|
11
|
-
>
|
|
12
|
-
{{@label}}
|
|
13
|
-
</f.Label>
|
|
14
|
-
{{/if}}
|
|
15
|
-
|
|
16
|
-
{{#if @hint}}
|
|
17
|
-
<f.Hint
|
|
18
|
-
class={{use-frontile-class "form-radio-group" @size (if @isInline "inline") part="hint"}}
|
|
19
|
-
>
|
|
20
|
-
{{@hint}}
|
|
21
|
-
</f.Hint>
|
|
22
|
-
{{/if}}
|
|
23
|
-
|
|
24
|
-
{{yield (component "form-radio"
|
|
25
|
-
checked=@value
|
|
26
|
-
privateContainerClass=(use-frontile-class "form-radio-group" @size (if @isInline "inline") part="form-radio")
|
|
27
|
-
_parentOnChange=this.handleChange
|
|
28
|
-
size=@size
|
|
29
|
-
name=(concat f.id "-radio-group")
|
|
30
|
-
)
|
|
31
|
-
}}
|
|
32
|
-
|
|
33
|
-
{{#if this.showErrorFeedback}}
|
|
34
|
-
<f.Feedback
|
|
35
|
-
class={{use-frontile-class "form-radio-group" @size (if @isInline "inline") part="feedback"}}
|
|
36
|
-
@errors={{@errors}}
|
|
37
|
-
/>
|
|
38
|
-
{{/if}}
|
|
39
|
-
</FormField>
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
import { tracked } from '@glimmer/tracking';
|
|
4
|
-
import FormRadio from './form-radio';
|
|
5
|
-
|
|
6
|
-
export interface FormRadioGroupArgs {
|
|
7
|
-
value: unknown;
|
|
8
|
-
/** The group label */
|
|
9
|
-
label?: string;
|
|
10
|
-
/** A help text to be displayed */
|
|
11
|
-
hint?: string;
|
|
12
|
-
/** If the form has been submitted, used to force displaying errors */
|
|
13
|
-
hasSubmitted?: boolean;
|
|
14
|
-
/** If has errors */
|
|
15
|
-
hasError?: boolean;
|
|
16
|
-
/** Force displaying errors */
|
|
17
|
-
showError?: boolean;
|
|
18
|
-
/** A list of errors or a single text describing the error */
|
|
19
|
-
errors?: string[] | string;
|
|
20
|
-
/** CSS classes to be added in the container element */
|
|
21
|
-
containerClass?: string;
|
|
22
|
-
/** The size */
|
|
23
|
-
size?: 'sm' | 'lg';
|
|
24
|
-
/** If the Checkbox should be in one line */
|
|
25
|
-
isInline?: boolean;
|
|
26
|
-
|
|
27
|
-
/** Default callback added to the yielded FormRadio component, called when onchange is triggered */
|
|
28
|
-
onChange?: (value: unknown, event: Event) => void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface FormRadioGroupSignature {
|
|
32
|
-
Args: FormRadioGroupArgs;
|
|
33
|
-
Blocks: {
|
|
34
|
-
default: [radio: FormRadio];
|
|
35
|
-
};
|
|
36
|
-
Element: HTMLDivElement;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default class FormRadioGroup extends Component<FormRadioGroupSignature> {
|
|
40
|
-
@tracked shouldShowErrorFeedback = false;
|
|
41
|
-
|
|
42
|
-
get showErrorFeedback(): boolean {
|
|
43
|
-
if (this.args.hasError === false) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
(this.args.showError ||
|
|
49
|
-
this.args.hasSubmitted ||
|
|
50
|
-
this.shouldShowErrorFeedback) &&
|
|
51
|
-
this.args.errors &&
|
|
52
|
-
this.args.errors.length > 0
|
|
53
|
-
) {
|
|
54
|
-
return true;
|
|
55
|
-
} else {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@action handleChange(value: unknown, event: Event): void {
|
|
61
|
-
this.shouldShowErrorFeedback = true;
|
|
62
|
-
|
|
63
|
-
if (typeof this.args.onChange === 'function') {
|
|
64
|
-
this.args.onChange(value, event);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<FormField
|
|
2
|
-
@size={{@size}}
|
|
3
|
-
class={{use-frontile-class
|
|
4
|
-
"form-radio"
|
|
5
|
-
@size
|
|
6
|
-
(if (eq @checked @value) "checked")
|
|
7
|
-
class=(array @containerClass @privateContainerClass)
|
|
8
|
-
}}
|
|
9
|
-
as |f|
|
|
10
|
-
>
|
|
11
|
-
<div class={{use-frontile-class "form-radio" @size part="label-container"}}>
|
|
12
|
-
<div class={{use-frontile-class "form-radio" @size part="input-container"}}>
|
|
13
|
-
{{! Zero-width space character, used to align checkbox properly }}
|
|
14
|
-
|
|
15
|
-
<f.Radio
|
|
16
|
-
@onChange={{this.handleChange}}
|
|
17
|
-
@value={{@value}}
|
|
18
|
-
@checked={{@checked}}
|
|
19
|
-
@name={{@name}}
|
|
20
|
-
class={{use-frontile-class "form-radio" @size part="radio"}}
|
|
21
|
-
aria-describedby={{if @hint f.hintId}}
|
|
22
|
-
...attributes
|
|
23
|
-
/>
|
|
24
|
-
</div>
|
|
25
|
-
|
|
26
|
-
<f.Label class={{use-frontile-class "form-radio" @size part="label"}}>
|
|
27
|
-
{{#if (has-block)}}
|
|
28
|
-
{{yield}}
|
|
29
|
-
{{else}}
|
|
30
|
-
{{@label}}
|
|
31
|
-
{{/if}}
|
|
32
|
-
</f.Label>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
{{#if @hint}}
|
|
36
|
-
<f.Hint class={{use-frontile-class "form-radio" @size part="hint"}}>
|
|
37
|
-
{{@hint}}
|
|
38
|
-
</f.Hint>
|
|
39
|
-
{{/if}}
|
|
40
|
-
</FormField>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
|
|
4
|
-
export interface FormRadioArgs {
|
|
5
|
-
/** The input field label */
|
|
6
|
-
label?: string;
|
|
7
|
-
/** A help text to be displayed */
|
|
8
|
-
hint?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The value to be used in the radio button.
|
|
11
|
-
* You must also pass `onChange` to update its value.
|
|
12
|
-
*/
|
|
13
|
-
value: unknown;
|
|
14
|
-
/**
|
|
15
|
-
* The current checked value.
|
|
16
|
-
* This will be used to compare against the `value` argument,
|
|
17
|
-
* if equal, the radio will me marked as checked.
|
|
18
|
-
*/
|
|
19
|
-
checked: unknown;
|
|
20
|
-
/** The name of the checkbox */
|
|
21
|
-
name?: string;
|
|
22
|
-
/** CSS classes to be added in the container element */
|
|
23
|
-
containerClass?: string;
|
|
24
|
-
/** The size */
|
|
25
|
-
size?: 'sm' | 'lg';
|
|
26
|
-
/** Callback when onchange is triggered */
|
|
27
|
-
onChange: (value: unknown, event: Event) => void;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Internal function for InputRadioGroup
|
|
31
|
-
* @ignore
|
|
32
|
-
**/
|
|
33
|
-
_parentOnChange?: (value: unknown, event: Event) => void;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface FormRadioSignature {
|
|
37
|
-
Args: FormRadioArgs;
|
|
38
|
-
Element: HTMLInputElement;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default class FormRadio extends Component<FormRadioSignature> {
|
|
42
|
-
@action handleChange(value: unknown, event: Event): void {
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
|
|
45
|
-
if (typeof this.args.onChange === 'function') {
|
|
46
|
-
this.args.onChange(value, event);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (typeof this.args._parentOnChange === 'function') {
|
|
50
|
-
this.args._parentOnChange(value, event);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 2
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Multiple Select
|
|
6
|
-
|
|
7
|
-
In example you can select multiple options. To enable multiple select,
|
|
8
|
-
just pass `@isMultiple={{true}}` to the component.
|
|
9
|
-
|
|
10
|
-
```hbs template
|
|
11
|
-
<FormSelect
|
|
12
|
-
@isMultiple={{true}}
|
|
13
|
-
@hint="Select all countries you have lived"
|
|
14
|
-
@errors={{this.countryErrors}}
|
|
15
|
-
@allowClear={{true}}
|
|
16
|
-
@label="Countries"
|
|
17
|
-
@options={{this.countries}}
|
|
18
|
-
@selected={{this.selectedCountries}}
|
|
19
|
-
@onChange={{this.setCountry}}
|
|
20
|
-
as |country|
|
|
21
|
-
>
|
|
22
|
-
{{country}}
|
|
23
|
-
</FormSelect>
|
|
24
|
-
|
|
25
|
-
<p class="mt-4">
|
|
26
|
-
You selected, "{{this.selectedCountries}}"
|
|
27
|
-
</p>
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
```js component
|
|
31
|
-
import Component from '@glimmer/component';
|
|
32
|
-
import { tracked } from '@glimmer/tracking';
|
|
33
|
-
import { action } from '@ember/object';
|
|
34
|
-
|
|
35
|
-
export default class DemoComponent extends Component {
|
|
36
|
-
@tracked selectedCountries;
|
|
37
|
-
|
|
38
|
-
countries = [
|
|
39
|
-
'United States',
|
|
40
|
-
'Spain',
|
|
41
|
-
'Portugal',
|
|
42
|
-
'Russia',
|
|
43
|
-
'Latvia',
|
|
44
|
-
'Brazil',
|
|
45
|
-
'United Kingdom'
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
get countryErrors() {
|
|
49
|
-
if (this.selectedCountries && this.selectedCountries.length > 0) {
|
|
50
|
-
return [];
|
|
51
|
-
} else {
|
|
52
|
-
return ["Countries can't be blank"];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@action setCountry(value) {
|
|
57
|
-
this.selectedCountries = value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Usage
|
|
6
|
-
|
|
7
|
-
Single Select.
|
|
8
|
-
|
|
9
|
-
```hbs template
|
|
10
|
-
<FormSelect
|
|
11
|
-
@hint="Select your country of residence"
|
|
12
|
-
@errors={{this.countryErrors}}
|
|
13
|
-
@allowClear={{true}}
|
|
14
|
-
@label="Country"
|
|
15
|
-
@searchEnabled={{true}}
|
|
16
|
-
@searchField="name"
|
|
17
|
-
@options={{this.countries}}
|
|
18
|
-
@selected={{this.country}}
|
|
19
|
-
@onChange={{this.setCountry}}
|
|
20
|
-
as |country|
|
|
21
|
-
>
|
|
22
|
-
{{country.name}}
|
|
23
|
-
</FormSelect>
|
|
24
|
-
|
|
25
|
-
<p class="mt-4">
|
|
26
|
-
You selected, "{{this.country.name}}"
|
|
27
|
-
</p>
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
```js component
|
|
31
|
-
import Component from '@glimmer/component';
|
|
32
|
-
import { tracked } from '@glimmer/tracking';
|
|
33
|
-
import { action } from '@ember/object';
|
|
34
|
-
|
|
35
|
-
export default class DemoComponent extends Component {
|
|
36
|
-
@tracked country;
|
|
37
|
-
|
|
38
|
-
countries = [
|
|
39
|
-
{ name: 'United States', code: 'US' },
|
|
40
|
-
{ name: 'Spain', code: 'ES' },
|
|
41
|
-
{ name: 'Portugal', code: 'PT', disabled: true },
|
|
42
|
-
{ name: 'Russia', code: 'RU', disabled: true },
|
|
43
|
-
{ name: 'Latvia', code: 'LV' },
|
|
44
|
-
{ name: 'Brazil', code: 'BR' },
|
|
45
|
-
{ name: 'United Kingdom', code: 'GB' }
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
get countryErrors() {
|
|
49
|
-
if (this.country) {
|
|
50
|
-
return [];
|
|
51
|
-
} else {
|
|
52
|
-
return ["Country can't be blank"];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@action setCountry(value) {
|
|
57
|
-
this.country = value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
<FormField
|
|
2
|
-
@size={{@size}}
|
|
3
|
-
class={{use-frontile-class "form-select" @size class=@containerClass}} as |f|
|
|
4
|
-
>
|
|
5
|
-
{{#if @label}}
|
|
6
|
-
<f.Label
|
|
7
|
-
@for={{false}}
|
|
8
|
-
id={{f.id}}
|
|
9
|
-
class={{use-frontile-class "form-select" @size part="label"}}
|
|
10
|
-
>
|
|
11
|
-
{{@label}}
|
|
12
|
-
</f.Label>
|
|
13
|
-
{{/if}}
|
|
14
|
-
|
|
15
|
-
{{#if @hint}}
|
|
16
|
-
<f.Hint class={{use-frontile-class "form-select" @size part="hint"}}>
|
|
17
|
-
{{@hint}}
|
|
18
|
-
</f.Hint>
|
|
19
|
-
{{/if}}
|
|
20
|
-
|
|
21
|
-
{{#let
|
|
22
|
-
(if
|
|
23
|
-
@isMultiple (component "power-select-multiple") (component "power-select")
|
|
24
|
-
) as |Component|
|
|
25
|
-
}}
|
|
26
|
-
<Component
|
|
27
|
-
...attributes
|
|
28
|
-
@onChange={{this.handleChange}}
|
|
29
|
-
@onFocus={{this.handleFocusIn}}
|
|
30
|
-
@onBlur={{this.handleFocusOut}}
|
|
31
|
-
@onOpen={{this.handleOpen}}
|
|
32
|
-
@onClose={{this.handleClose}}
|
|
33
|
-
@ariaDescribedBy="{{if @hint f.hintId}}{{
|
|
34
|
-
if this.showErrorFeedback (concat " " f.feedbackId)
|
|
35
|
-
}}{{if @ariaDescribedBy (concat " " @ariaDescribedBy)}}"
|
|
36
|
-
@ariaLabelledBy="{{if @label f.id}}{{
|
|
37
|
-
if @ariaLabelledBy (concat " " @ariaLabelledBy)
|
|
38
|
-
}}"
|
|
39
|
-
@ariaInvalid={{if this.showErrorFeedback "true"}}
|
|
40
|
-
@triggerClass="{{@triggerClass}} {{
|
|
41
|
-
if @size (concat "ember-power-select-trigger-" @size)
|
|
42
|
-
}} {{use-frontile-class "form-select" @size part="select"}}"
|
|
43
|
-
@highlightOnHover={{@highlightOnHover}}
|
|
44
|
-
@placeholderComponent={{@placeholderComponent}}
|
|
45
|
-
@searchMessage={{@searchMessage}}
|
|
46
|
-
@noMatchesMessage={{@noMatchesMessage}}
|
|
47
|
-
@matchTriggerWidth={{@matchTriggerWidth}}
|
|
48
|
-
@options={{@options}}
|
|
49
|
-
@selected={{@selected}}
|
|
50
|
-
@closeOnSelect={{@closeOnSelect}}
|
|
51
|
-
@defaultHighlighted={{@defaultHighlighted}}
|
|
52
|
-
@searchField={{@searchField}}
|
|
53
|
-
@searchEnabled={{@searchEnabled}}
|
|
54
|
-
@tabindex={{@tabindex}}
|
|
55
|
-
@triggerComponent={{@triggerComponent}}
|
|
56
|
-
@matcher={{@matcher}}
|
|
57
|
-
@initiallyOpened={{@initiallyOpened}}
|
|
58
|
-
@typeAheadOptionMatcher={{@typeAheadOptionMatcher}}
|
|
59
|
-
@buildSelection={{@buildSelection}}
|
|
60
|
-
@search={{@search}}
|
|
61
|
-
@onInput={{@onInput}}
|
|
62
|
-
@onKeydown={{@onKeydown}}
|
|
63
|
-
@scrollTo={{@scrollTo}}
|
|
64
|
-
@registerAPI={{@registerAPI}}
|
|
65
|
-
@horizontalPosition={{@horizontalPosition}}
|
|
66
|
-
@destination={{@destination}}
|
|
67
|
-
@preventScroll={{@preventScroll}}
|
|
68
|
-
@renderInPlace={{@renderInPlace}}
|
|
69
|
-
@verticalPosition={{@verticalPosition}}
|
|
70
|
-
@disabled={{@disabled}}
|
|
71
|
-
@calculatePosition={{@calculatePosition}}
|
|
72
|
-
@eventType={{@eventType}}
|
|
73
|
-
@ariaLabel={{@ariaLabel}}
|
|
74
|
-
@required={{@required}}
|
|
75
|
-
@triggerRole={{@triggerRole}}
|
|
76
|
-
@title={{@title}}
|
|
77
|
-
@triggerId={{@triggerId}}
|
|
78
|
-
@allowClear={{@allowClear}}
|
|
79
|
-
@loadingMessage={{@loadingMessage}}
|
|
80
|
-
@selectedItemComponent={{@selectedItemComponent}}
|
|
81
|
-
@dropdownClass={{@dropdownClass}}
|
|
82
|
-
@beforeOptionsComponent={{@beforeOptionsComponent}}
|
|
83
|
-
@placeholder={{@placeholder}}
|
|
84
|
-
@searchPlaceholder={{@searchPlaceholder}}
|
|
85
|
-
@searchMessageComponent={{@searchMessageComponent}}
|
|
86
|
-
@optionsComponent={{@optionsComponent}}
|
|
87
|
-
@extra={{@extra}}
|
|
88
|
-
@groupComponent={{@groupComponent}}
|
|
89
|
-
@afterOptionsComponent={{@afterOptionsComponent}} as |option term|
|
|
90
|
-
>
|
|
91
|
-
{{yield option term}}
|
|
92
|
-
</Component>
|
|
93
|
-
{{/let}}
|
|
94
|
-
|
|
95
|
-
{{#if this.showErrorFeedback}}
|
|
96
|
-
<f.Feedback
|
|
97
|
-
class={{use-frontile-class "form-select" @size part="feedback"}}
|
|
98
|
-
@errors={{@errors}}
|
|
99
|
-
/>
|
|
100
|
-
{{/if}}
|
|
101
|
-
</FormField>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# FormSelect
|
|
2
|
-
|
|
3
|
-
We use [Ember Power Select](https://github.com/cibernox/ember-power-select/)
|
|
4
|
-
under the hood to deliver the best select experience. Please refer to their
|
|
5
|
-
documentation for further customization.
|
|
6
|
-
|
|
7
|
-
In the example below, we have a label, hint, error validation, search and `allowClear`.
|
|
8
|
-
|
|
9
|
-
## API
|
|
10
|
-
|
|
11
|
-
<ArgsTable @of="FormSelect" />
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { tracked } from '@glimmer/tracking';
|
|
3
|
-
import { action } from '@ember/object';
|
|
4
|
-
import { assert } from '@ember/debug';
|
|
5
|
-
import {
|
|
6
|
-
PowerSelectArgs,
|
|
7
|
-
Select
|
|
8
|
-
} from 'ember-power-select/addon/components/power-select';
|
|
9
|
-
|
|
10
|
-
export interface FormSelectArgs extends PowerSelectArgs {
|
|
11
|
-
/** The input field label */
|
|
12
|
-
label?: string;
|
|
13
|
-
/** A help text to be displayed */
|
|
14
|
-
hint?: string;
|
|
15
|
-
/** If the form has been submitted, used to force displaying errors */
|
|
16
|
-
hasSubmitted?: boolean;
|
|
17
|
-
/** If has errors */
|
|
18
|
-
hasError?: boolean;
|
|
19
|
-
/** Force displaying errors */
|
|
20
|
-
showError?: boolean;
|
|
21
|
-
/** A list of errors or a single text describing the error */
|
|
22
|
-
errors?: string[] | string;
|
|
23
|
-
/** CSS classes to be added in the container element */
|
|
24
|
-
containerClass?: string;
|
|
25
|
-
/** The size */
|
|
26
|
-
size?: 'sm' | 'lg';
|
|
27
|
-
|
|
28
|
-
// Same as onFocus from ember-power-select
|
|
29
|
-
onFocusIn?: (select: Select, event: FocusEvent) => void;
|
|
30
|
-
// Same as onBlur from ember-power-select
|
|
31
|
-
onFocusOut?: (select: Select, event: FocusEvent) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface FormSelectSignature {
|
|
35
|
-
Args: FormSelectArgs;
|
|
36
|
-
Blocks: {
|
|
37
|
-
default: [option: unknown, select: Select];
|
|
38
|
-
};
|
|
39
|
-
Element: HTMLDivElement;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default class FormSelect extends Component<FormSelectSignature> {
|
|
43
|
-
@tracked shouldShowErrorFeedback = false;
|
|
44
|
-
@tracked isOpen = false;
|
|
45
|
-
|
|
46
|
-
constructor(owner: unknown, args: FormSelectArgs) {
|
|
47
|
-
super(owner, args);
|
|
48
|
-
assert(
|
|
49
|
-
'<FormSelect> requires an `@onChange` function',
|
|
50
|
-
this.args.onChange && typeof this.args.onChange === 'function'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get showErrorFeedback(): boolean {
|
|
55
|
-
if (this.args.hasError === false) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
(this.args.showError ||
|
|
61
|
-
this.args.hasSubmitted ||
|
|
62
|
-
this.shouldShowErrorFeedback) &&
|
|
63
|
-
this.args.errors &&
|
|
64
|
-
this.args.errors.length > 0
|
|
65
|
-
) {
|
|
66
|
-
return true;
|
|
67
|
-
} else {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@action handleOpen(select: Select, event: Event): void {
|
|
73
|
-
this.isOpen = true;
|
|
74
|
-
this.shouldShowErrorFeedback = false;
|
|
75
|
-
|
|
76
|
-
if (typeof this.args.onOpen === 'function') {
|
|
77
|
-
this.args.onOpen(select, event);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@action handleClose(select: Select, event: Event): void {
|
|
82
|
-
this.isOpen = false;
|
|
83
|
-
this.shouldShowErrorFeedback = true;
|
|
84
|
-
|
|
85
|
-
if (typeof this.args.onClose === 'function') {
|
|
86
|
-
this.args.onClose(select, event);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@action handleFocusIn(select: Select, event: FocusEvent): void {
|
|
91
|
-
this.shouldShowErrorFeedback = false;
|
|
92
|
-
|
|
93
|
-
if (typeof this.args.onFocusIn === 'function') {
|
|
94
|
-
this.args.onFocusIn(select, event);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ember-power-select argument
|
|
98
|
-
if (typeof this.args.onFocus === 'function') {
|
|
99
|
-
this.args.onFocus(select, event);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@action handleFocusOut(select: Select, event: FocusEvent): void {
|
|
104
|
-
if (!this.isOpen) {
|
|
105
|
-
this.shouldShowErrorFeedback = true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (typeof this.args.onFocusOut === 'function') {
|
|
109
|
-
this.args.onFocusOut(select, event);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ember-power-select argument
|
|
113
|
-
if (typeof this.args.onBlur === 'function') {
|
|
114
|
-
this.args.onBlur(select, event);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@action handleChange(
|
|
119
|
-
selection: unknown,
|
|
120
|
-
select: Select,
|
|
121
|
-
event?: Event
|
|
122
|
-
): void {
|
|
123
|
-
this.shouldShowErrorFeedback = true;
|
|
124
|
-
this.args.onChange(selection, select, event);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
order: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Usage
|
|
6
|
-
|
|
7
|
-
```hbs template
|
|
8
|
-
<FormTextarea
|
|
9
|
-
@label="Text"
|
|
10
|
-
@value={{this.value}}
|
|
11
|
-
@onInput={{this.setValue}}
|
|
12
|
-
@errors={{this.validationErrors}}
|
|
13
|
-
/>
|
|
14
|
-
|
|
15
|
-
<p class="mt-4">
|
|
16
|
-
You typed, "{{this.value}}"
|
|
17
|
-
</p>
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
```js component
|
|
21
|
-
import Component from '@glimmer/component';
|
|
22
|
-
import { tracked } from '@glimmer/tracking';
|
|
23
|
-
import { action } from '@ember/object';
|
|
24
|
-
|
|
25
|
-
export default class DemoComponent extends Component {
|
|
26
|
-
@tracked value = '';
|
|
27
|
-
|
|
28
|
-
get validationErrors() {
|
|
29
|
-
if (/^$/.test(this.value)) {
|
|
30
|
-
return ['Please enter text'];
|
|
31
|
-
} else {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@action setValue(value) {
|
|
37
|
-
this.value = value;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|