-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toucan-form: Expose all named blocks #156
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
85e9e76
Expose named blocks for textarea
ynotdraw d64d47c
Update test-app/tests/integration/components/toucan-form/form-textare…
ynotdraw 0ac0249
tests: Added additional tests for named blocks
ynotdraw 728fbbf
Merge pull request #149 from CrowdStrike/toucan-form-expose-named-blocks
ynotdraw 84788ef
toucan-form: Input named block support
ynotdraw 5e99d1f
toucan-form: Checkbox named block support
ynotdraw 38834cc
Merge pull request #150 from CrowdStrike/feature-toucan-form-input-bl…
ynotdraw 6065a25
toucan-form: CheckboxGroup named block support
ynotdraw 1455a27
toucan-form: RadioGroup named block support
ynotdraw 36dce87
Merge pull request #151 from CrowdStrike/feature-toucan-form-checkbox…
ynotdraw 647e7c0
Merge pull request #153 from CrowdStrike/feature-toucan-form-checkbox…
ynotdraw 7a6aa3d
Merge pull request #154 from CrowdStrike/feature-toucan-form-radio-gr…
ynotdraw 20d433f
Added changeset
ynotdraw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,38 @@ | ||
--- | ||
'@crowdstrike/ember-toucan-form': patch | ||
--- | ||
|
||
Exposed named blocks from the underlying `toucan-core` components. This allows users to add custom content in `:hint` or `:label` named blocks. You can combine the arguments and named blocks as well! Below are some examples. | ||
|
||
```hbs | ||
<ToucanForm @data={{data}} as |form|> | ||
<form.Textarea @name='comment'> | ||
<:label>Label</:label> | ||
<:hint>Hint</:hint> | ||
</form.Textarea> | ||
</ToucanForm> | ||
``` | ||
|
||
```hbs | ||
<ToucanForm @data={{data}} as |form|> | ||
<form.Textarea @label='Label' @name='comment'> | ||
<:hint>Hint</:hint> | ||
</form.Textarea> | ||
</ToucanForm> | ||
``` | ||
|
||
```hbs | ||
<ToucanForm @data={{data}} as |form|> | ||
<form.Textarea @hint='Hint' @name='comment'> | ||
<:label>Label</:label> | ||
</form.Textarea> | ||
</ToucanForm> | ||
``` | ||
|
||
Or you can continue to use the arguments if you're only working with strings! | ||
|
||
```hbs | ||
<ToucanForm @data={{data}} as |form|> | ||
<form.Textarea @label='Label' @hint='Hint' @name='comment' /> | ||
</ToucanForm> | ||
``` |
95 changes: 81 additions & 14 deletions
95
packages/ember-toucan-form/src/-private/checkbox-field.hbs
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 |
---|---|---|
@@ -1,16 +1,83 @@ | ||
{{! | ||
Regarding Conditionals | ||
|
||
This looks really messy, but Form::Fields::Checkbox exposes named blocks; HOWEVER, | ||
we cannot conditionally render named blocks due to https://github.com/emberjs/rfcs/issues/735. | ||
|
||
We *can* conditionally render components though, based on the blocks and argument combinations | ||
users provide us. This is very brittle, but until https://github.com/emberjs/rfcs/issues/735 | ||
is resolved and a solution is found, this appears to be the only way to truly expose | ||
conditional named blocks. | ||
|
||
--- | ||
|
||
Regarding glint-expect-error | ||
|
||
"@onChange" of the checkbox only expects a boolean typed value, but field.setValue is generic, | ||
accepting anything that DATA[KEY] could be. Similar case with "@isChecked", but there casting to | ||
a boolean is easy. | ||
}} | ||
<@form.Field @name={{@name}} as |field|> | ||
<Form::Fields::Checkbox | ||
@label={{@label}} | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@isChecked={{this.assertBoolean field.value}} | ||
{{! The issue here is that onChange only expects a string typed value, but field.setValue is generic, accepting anything that DATA[KEY] could be. }} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
name={{@name}} | ||
...attributes | ||
/> | ||
{{#if (this.hasOnlyLabelBlock (has-block 'label') (has-block 'hint'))}} | ||
<Form::Fields::Checkbox | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@isChecked={{this.assertBoolean field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
name={{@name}} | ||
...attributes | ||
> | ||
<:label>{{yield to='label'}}</:label> | ||
</Form::Fields::Checkbox> | ||
{{else if (this.hasHintAndLabelBlocks (has-block 'label') (has-block 'hint')) | ||
}} | ||
<Form::Fields::Checkbox | ||
@error={{this.mapErrors field.rawErrors}} | ||
@isChecked={{this.assertBoolean field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
name={{@name}} | ||
...attributes | ||
> | ||
<:label>{{yield to='label'}}</:label> | ||
<:hint>{{yield to='hint'}}</:hint> | ||
</Form::Fields::Checkbox> | ||
{{else if (this.hasLabelArgAndHintBlock @label (has-block 'hint'))}} | ||
<Form::Fields::Checkbox | ||
@label={{@label}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@isChecked={{this.assertBoolean field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
name={{@name}} | ||
...attributes | ||
> | ||
<:hint>{{yield to='hint'}}</:hint> | ||
</Form::Fields::Checkbox> | ||
{{else}} | ||
{{! Argument-only case }} | ||
<Form::Fields::Checkbox | ||
@label={{@label}} | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@isChecked={{this.assertBoolean field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
name={{@name}} | ||
...attributes | ||
/> | ||
{{/if}} | ||
</@form.Field> |
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
110 changes: 93 additions & 17 deletions
110
packages/ember-toucan-form/src/-private/checkbox-group-field.hbs
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 |
---|---|---|
@@ -1,19 +1,95 @@ | ||
{{! | ||
Regarding Conditionals | ||
|
||
This looks really messy, but Form::Fields::CheckboxGroup exposes named blocks; HOWEVER, | ||
we cannot conditionally render named blocks due to https://github.com/emberjs/rfcs/issues/735. | ||
|
||
We *can* conditionally render components though, based on the blocks and argument combinations | ||
users provide us. This is very brittle, but until https://github.com/emberjs/rfcs/issues/735 | ||
is resolved and a solution is found, this appears to be the only way to truly expose | ||
conditional named blocks. | ||
|
||
--- | ||
|
||
Regarding glint-expect-error | ||
|
||
"@onChange" of the checkbox-group only expects an array of strings typed value, but field.setValue is generic, | ||
accepting anything that DATA[KEY] could be. Similar case with "@isChecked", but there casting to | ||
an array of strings is easy. | ||
}} | ||
<@form.Field @name={{@name}} as |field|> | ||
<Form::Fields::CheckboxGroup | ||
@label={{@label}} | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@value={{this.assertArrayOfStrings field.value}} | ||
{{! The issue here is that onChange only expects a string typed value, but field.setValue is generic, accepting anything that DATA[KEY] could be. Similar case with @value, but there casting is easy. }} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
@name={{@name}} | ||
...attributes | ||
as |group| | ||
> | ||
{{yield (hash CheckboxField=group.CheckboxField)}} | ||
</Form::Fields::CheckboxGroup> | ||
{{#if (this.hasOnlyLabelBlock (has-block 'label') (has-block 'hint'))}} | ||
<Form::Fields::CheckboxGroup | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@value={{this.assertArrayOfStrings field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
@name={{@name}} | ||
...attributes | ||
> | ||
<:label>{{yield to='label'}}</:label> | ||
<:default as |group|> | ||
{{yield (hash CheckboxField=group.CheckboxField) to='default'}} | ||
</:default> | ||
</Form::Fields::CheckboxGroup> | ||
{{else if (this.hasHintAndLabelBlocks (has-block 'label') (has-block 'hint')) | ||
}} | ||
<Form::Fields::CheckboxGroup | ||
@error={{this.mapErrors field.rawErrors}} | ||
@value={{this.assertArrayOfStrings field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
@name={{@name}} | ||
...attributes | ||
> | ||
<:label>{{yield to='label'}}</:label> | ||
<:hint>{{yield to='hint'}}</:hint> | ||
<:default as |group|> | ||
{{yield (hash CheckboxField=group.CheckboxField)}} | ||
</:default> | ||
</Form::Fields::CheckboxGroup> | ||
{{else if (this.hasLabelArgAndHintBlock @label (has-block 'hint'))}} | ||
<Form::Fields::CheckboxGroup | ||
@label={{@label}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@value={{this.assertArrayOfStrings field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
@name={{@name}} | ||
...attributes | ||
> | ||
<:hint>{{yield to='hint'}}</:hint> | ||
<:default as |group|> | ||
{{yield (hash CheckboxField=group.CheckboxField)}} | ||
</:default> | ||
</Form::Fields::CheckboxGroup> | ||
{{else}} | ||
{{! Argument-only case }} | ||
<Form::Fields::CheckboxGroup | ||
@label={{@label}} | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@value={{this.assertArrayOfStrings field.value}} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
@name={{@name}} | ||
...attributes | ||
as |group| | ||
> | ||
{{yield (hash CheckboxField=group.CheckboxField)}} | ||
</Form::Fields::CheckboxGroup> | ||
{{/if}} | ||
</@form.Field> |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rendered