diff --git a/addon/components/au-select.hbs b/addon/components/au-select.hbs new file mode 100644 index 000000000..83719dde8 --- /dev/null +++ b/addon/components/au-select.hbs @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/addon/components/au-select.js b/addon/components/au-select.js new file mode 100644 index 000000000..be510d2fb --- /dev/null +++ b/addon/components/au-select.js @@ -0,0 +1,21 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; + +const CLEAR_VALUE = 'CLEAR'; +const EMPTY = null; + +export default class AuSelectComponent extends Component { + CLEAR_VALUE = CLEAR_VALUE; + + @action + handleSelectionChange(event) { + let optionIndexOrClear = event.target.value; + let selectedOption = EMPTY; + + if (optionIndexOrClear !== CLEAR_VALUE) { + selectedOption = this.args.options[optionIndexOrClear]; + } + + this.args.onChange?.(selectedOption); + } +} diff --git a/app/components/au-select.js b/app/components/au-select.js new file mode 100644 index 000000000..59ea3e7d4 --- /dev/null +++ b/app/components/au-select.js @@ -0,0 +1 @@ +export { default } from '@appuniversum/ember-appuniversum/components/au-select'; \ No newline at end of file diff --git a/tests/dummy/app/components/sidebar.hbs b/tests/dummy/app/components/sidebar.hbs index 362ec6d95..550cb3dd7 100644 --- a/tests/dummy/app/components/sidebar.hbs +++ b/tests/dummy/app/components/sidebar.hbs @@ -91,6 +91,11 @@ Form: Checkbox +
  • + + Form: Select + +
  • Form: ember power select (draft) diff --git a/tests/dummy/app/controllers/docs/atoms/au-form-select.js b/tests/dummy/app/controllers/docs/atoms/au-form-select.js new file mode 100644 index 000000000..9b61ff5ee --- /dev/null +++ b/tests/dummy/app/controllers/docs/atoms/au-form-select.js @@ -0,0 +1,14 @@ +import Controller from '@ember/controller'; +import { tracked } from '@glimmer/tracking'; + +export default class extends Controller { + @tracked selectedProvince = null; + + provinces = [ + { label: 'Antwerpen' }, + { label: 'Limburg' }, + { label: 'Oost-vlaanderen' }, + { label: 'Vlaams-Brabant' }, + { label: 'West-Vlaanderen' }, + ]; +} diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 2f5915c19..92c24d6e8 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -29,6 +29,7 @@ Router.map(function() { this.route('au-form-textarea'); this.route('au-form-radio'); this.route('au-form-checkbox'); + this.route('au-form-select'); this.route('au-link'); this.route('au-loader'); this.route("au-navigation-link"); diff --git a/tests/dummy/app/templates/docs/atoms/au-form-select.md b/tests/dummy/app/templates/docs/atoms/au-form-select.md new file mode 100644 index 000000000..f409de94d --- /dev/null +++ b/tests/dummy/app/templates/docs/atoms/au-form-select.md @@ -0,0 +1,35 @@ +# Select + +--- + +## Single select + +{{#docs-demo as |demo|}} + {{#demo.example name='au-form-select.hbs'}} + Provincie + + {{province.label}} + +
    + Selected province: {{this.selectedProvince.label}} + {{/demo.example}} + {{demo.snippet 'au-form-select.hbs'}} +{{/docs-demo}} + +## Arguments + +| Argument | Description | Type | Default value | +| ------------- | ----------- | ---- | ------------- | +| `@selected` | The selected option | `string` | - | +| `@options`| List of options that can be selected | 'integer' | 0 | +| `@onChange`| Gets called when the user selects an option with that option as the argument | any | - | +| `@placeholder` | The text that will be shown in the empty option | `string` | - | + + diff --git a/tests/integration/components/au-select-test.js b/tests/integration/components/au-select-test.js new file mode 100644 index 000000000..fe401fe64 --- /dev/null +++ b/tests/integration/components/au-select-test.js @@ -0,0 +1,26 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | au-select', function(hooks) { + setupRenderingTest(hooks); + + test('it renders', async function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + + await render(hbs``); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + + template block text + + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +});