import Component from '@ember/component'; import { IDropDownOption } from 'wherehows-web/typings/app/dataset-compliance'; import { get, computed } from '@ember/object'; export default class NachoDropDownOption extends Component { tagName = 'li'; classNames = ['nacho-drop-down__options__option']; classNameBindings = ['isSelected:nacho-drop-down__options__option--selected']; /** * External action invoked when a IDropDownOption instance is selected * @memberof NachoDropDownOption */ onSelect: (option: IDropDownOption) => void; /** * Computed flag indicating if this option is referentially equal to the selectedOption * @type {ComputedProperty} * @memberof NachoDropDownOption */ isSelected = computed('option', 'selectedOption', function(this: NachoDropDownOption): boolean { return get(this, 'selectedOption') === get(this, 'option'); }); /** * References the drop-down option passed in to this * @type {IDropDownOption} * @memberof NachoDropDownOption */ option: IDropDownOption; /** * References the selected drop-down option * @type {IDropDownOption} * @memberof NachoDropDownOption */ selectedOption: IDropDownOption; /** * Invokes the external action onSelect when this component's click event is triggered * @memberof NachoDropDownOption */ click() { this.onSelect(get(this, 'option')); } }