Persistence and onSelect handler for the multi-select-dropdown

This commit is contained in:
Michael Lange 2019-01-11 15:41:56 -08:00 committed by Preetha Appan
parent 17ab2c22cc
commit 6160d8af84
No known key found for this signature in database
GPG key ID: 9F7C19990A50EAFC
4 changed files with 36 additions and 3 deletions

View file

@ -0,0 +1,23 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
export default Component.extend({
classNames: ['dropdown'],
options: computed(() => []),
selection: computed(() => []),
onSelect() {},
actions: {
toggle({ key }) {
const newSelection = this.get('selection').slice();
if (newSelection.includes(key)) {
newSelection.removeObject(key);
} else {
newSelection.addObject(key);
}
this.get('onSelect')(newSelection);
},
},
});

View file

@ -25,6 +25,7 @@
.dropdown-trigger-label {
margin-left: 8px;
margin-right: 8px;
}
.ember-power-select-selected-item,

View file

@ -2,7 +2,8 @@
{{multi-select-dropdown
label="Example Dropdown"
options=options
selection=selection}}
selection=selection
onSelect=(action (mut selection))}}
{{/freestyle-usage}}
{{#freestyle-annotation}}
A wrapper around basic-dropdown for creating a list of checkboxes and tracking the state thereof.

View file

@ -1,6 +1,11 @@
{{#basic-dropdown matchTriggerWidth=true as |dd|}}
{{#dd.trigger class="dropdown-trigger"}}
<span class="dropdown-trigger-label">{{label}}</span>
<span class="dropdown-trigger-label">
{{label}}
{{#if selection.length}}
<span class="tag is-light">{{selection.length}}</span>
{{/if}}
</span>
<span class="dropdown-trigger-icon ember-power-select-status-icon"></span>
{{/dd.trigger}}
{{#dd.content class="dropdown-options"}}
@ -8,7 +13,10 @@
{{#each options key="key" as |option|}}
<li class="dropdown-option">
<label>
<input type="checkbox" checked={{includes option.key selection}} />
<input
type="checkbox"
checked={{includes option.key selection}}
onchange={{action "toggle" option}} />
{{option.label}}
</label>
</li>