-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from josemarluedke/feat/forms-v2
New Components for Form Elements
- Loading branch information
Showing
83 changed files
with
6,577 additions
and
10,313 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Component from '@glimmer/component'; | ||
import { Checkbox, type CheckboxSignature } from './checkbox'; | ||
import { FormControl, type FormControlSharedArgs } from './form-control'; | ||
import { | ||
useStyles, | ||
type CheckboxGroupVariants, | ||
type CheckboxGroupSlots, | ||
type SlotsToClasses | ||
} from '@frontile/theme'; | ||
import type { WithBoundArgs } from '@glint/template'; | ||
|
||
interface Args extends FormControlSharedArgs { | ||
name?: string; | ||
onChange?: CheckboxSignature['Args']['onChange']; | ||
size?: CheckboxGroupVariants['size']; | ||
classes?: SlotsToClasses<CheckboxGroupSlots>; | ||
|
||
/* | ||
* | ||
* @defaultValue 'vertical' | ||
*/ | ||
orientation?: 'horizontal' | 'vertical'; | ||
} | ||
|
||
interface CheckboxGroupSignature { | ||
Args: Args; | ||
Blocks: { | ||
default: [Checkbox: WithBoundArgs<typeof Checkbox, 'name' | 'onChange'>]; | ||
}; | ||
Element: HTMLDivElement; | ||
} | ||
|
||
class CheckboxGroup extends Component<CheckboxGroupSignature> { | ||
get classes() { | ||
const { checkboxGroup } = useStyles(); | ||
return checkboxGroup({ | ||
size: this.args.size | ||
}); | ||
} | ||
|
||
<template> | ||
<FormControl | ||
@size={{@size}} | ||
@isRequired={{@isRequired}} | ||
@description={{@description}} | ||
@errors={{@errors}} | ||
@isInvalid={{@isInvalid}} | ||
@class={{this.classes.base class=@classes.base}} | ||
...attributes | ||
as |c| | ||
> | ||
<c.Label @class={{this.classes.label class=@classes.label}}> | ||
{{@label}} | ||
</c.Label> | ||
<div | ||
class={{this.classes.optionsContainer class=@classes.optionsContainer}} | ||
data-orientation={{if @orientation @orientation "vertical"}} | ||
> | ||
{{yield | ||
(component Checkbox name=@name onChange=@onChange size=@size) | ||
to="default" | ||
}} | ||
</div> | ||
</FormControl> | ||
</template> | ||
} | ||
|
||
export { CheckboxGroup, type CheckboxGroupSignature }; | ||
export default CheckboxGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { on } from '@ember/modifier'; | ||
import { FormControl, type FormControlSharedArgs } from './form-control'; | ||
import { | ||
useStyles, | ||
type CheckboxVariants, | ||
type CheckboxSlots, | ||
type SlotsToClasses | ||
} from '@frontile/theme'; | ||
|
||
interface Args extends FormControlSharedArgs { | ||
checked?: boolean; | ||
name?: string; | ||
size?: CheckboxVariants['size']; | ||
classes?: SlotsToClasses<CheckboxSlots>; | ||
|
||
/* | ||
* Callback when onchange is triggered | ||
*/ | ||
onChange?: (value: boolean, event: Event) => void; | ||
} | ||
|
||
interface CheckboxSignature { | ||
Args: Args; | ||
Element: HTMLInputElement; | ||
} | ||
|
||
class Checkbox extends Component<CheckboxSignature> { | ||
get isChecked(): boolean { | ||
return !!this.args.checked; | ||
} | ||
|
||
@action handleChange(event: Event): void { | ||
event.preventDefault(); | ||
|
||
const value = !this.args.checked; | ||
|
||
if (typeof this.args.onChange === 'function') { | ||
this.args.onChange(value, event); | ||
} | ||
} | ||
|
||
get classes() { | ||
const { checkbox } = useStyles(); | ||
return checkbox({ | ||
size: this.args.size | ||
}); | ||
} | ||
|
||
<template> | ||
<FormControl | ||
@isInvalid={{@isInvalid}} | ||
@errors={{@errors}} | ||
@size={{@size}} | ||
@isRequired={{@isRequired}} | ||
@class={{this.classes.base class=@classes.base}} | ||
@preventErrorFeedback={{true}} | ||
as |c| | ||
> | ||
<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 | ||
/> | ||
<div class={{this.classes.labelContainer class=@classes.labelContainer}}> | ||
{{#if @label}} | ||
<c.Label @class={{this.classes.label class=@classes.label}}> | ||
{{@label}} | ||
</c.Label> | ||
{{/if}} | ||
{{#if @description}} | ||
<c.Description>{{@description}}</c.Description> | ||
{{/if}} | ||
{{#if c.isInvalid}} | ||
<c.Feedback /> | ||
{{/if}} | ||
</div> | ||
</FormControl> | ||
</template> | ||
} | ||
|
||
export { Checkbox, type CheckboxSignature }; | ||
export default Checkbox; |
Oops, something went wrong.