-
Notifications
You must be signed in to change notification settings - Fork 5
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 #200 from CrowdStrike/add-select-component-tony
Add Combobox component to Toucan Core & Toucan Form
- Loading branch information
Showing
39 changed files
with
3,593 additions
and
30 deletions.
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,61 @@ | ||
--- | ||
'@crowdstrike/ember-toucan-core': patch | ||
'@crowdstrike/ember-toucan-form': patch | ||
--- | ||
|
||
Added a `Combobox` component to both core and form packages. | ||
|
||
If you're using `toucan-core`, the control and field components are exposed: | ||
|
||
```hbs | ||
<Form::Controls::Combobox | ||
@onChange={{this.onChange}} | ||
@options={{this.options}} | ||
@contentClass='z-10' | ||
@selected={{this.selected}} | ||
@optionKey='label' | ||
@noResultsText='No results' | ||
placeholder='Colors' | ||
as |combobox| | ||
> | ||
<combobox.Option> | ||
{{combobox.option.label}} | ||
</combobox.Option> | ||
</Form::Controls::Combobox> | ||
<Form::Fields::Combobox | ||
@contentClass='z-10' | ||
@error={{this.errorMessage}} | ||
@hint='Type "blue" into the field' | ||
@label='Label' | ||
@noResultsText='No results' | ||
@onChange={{this.onChange}} | ||
@optionKey='label' | ||
@options={{this.options}} | ||
@selected={{this.selected}} | ||
placeholder='Colors' | ||
as |combobox| | ||
> | ||
<combobox.Option> | ||
{{combobox.option.label}} | ||
</combobox.Option> | ||
</Form::Fields::Combobox> | ||
``` | ||
|
||
If you're using `toucan-form`, the component is exposed via: | ||
|
||
```hbs | ||
<ToucanForm as |form|> | ||
<form.Combobox | ||
@label='Combobox' | ||
@name='combobox' | ||
@options={{options}} | ||
data-combobox | ||
as |combobox| | ||
> | ||
<combobox.Option data-option>{{combobox.option}}</combobox.Option> | ||
</form.Combobox> | ||
</ToucanForm> | ||
``` | ||
|
||
For more information on using these components, view [the docs](https://ember-toucan-core.pages.dev/docs/components/combobox). |
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,74 @@ | ||
```hbs template | ||
<Form::Fields::Combobox | ||
@contentClass='z-10' | ||
@error={{this.errorMessage}} | ||
@hint='Type "blue" into the field' | ||
@label='Label' | ||
@noResultsText='No results' | ||
@onChange={{this.onChange}} | ||
@optionKey='label' | ||
@options={{this.options}} | ||
@selected={{this.selected}} | ||
placeholder='Colors' | ||
as |combobox| | ||
> | ||
<combobox.Option> | ||
{{combobox.option.label}} | ||
</combobox.Option> | ||
</Form::Fields::Combobox> | ||
``` | ||
|
||
```js component | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export default class extends Component { | ||
@tracked selected; | ||
@tracked errorMessage; | ||
|
||
options = [ | ||
{ | ||
label: 'Blue', | ||
name: 'blue', | ||
}, | ||
{ | ||
label: 'Green', | ||
name: 'green', | ||
}, | ||
{ | ||
label: 'Yellow', | ||
name: 'yellow', | ||
}, | ||
{ | ||
label: 'Orange', | ||
name: 'orange', | ||
}, | ||
{ | ||
label: 'Red', | ||
name: 'red', | ||
}, | ||
{ | ||
label: 'Purple', | ||
name: 'purple', | ||
}, | ||
{ | ||
label: 'Teal', | ||
name: 'teal', | ||
}, | ||
]; | ||
|
||
@action | ||
onChange(option) { | ||
this.selected = option; | ||
console.log(option); | ||
|
||
if (option.label !== 'Blue') { | ||
this.errorMessage = 'Please select "Blue"'; | ||
return; | ||
} | ||
|
||
this.errorMessage = null; | ||
} | ||
} | ||
``` |
Oops, something went wrong.