open-vault/ui/app/components/toggle-button.js
Matthew Irish d509588cd2
Ember update (#5386)
Ember update - update ember-cli, ember-data, and ember to 3.4 series
2018-09-25 11:28:26 -05:00

34 lines
951 B
JavaScript

import Component from '@ember/component';
import { set, get, defineProperty, computed } from '@ember/object';
export default Component.extend({
tagName: 'button',
type: 'button',
toggleTarget: null,
toggleAttr: null,
classNameBindings: ['buttonClass'],
attributeBindings: ['type'],
buttonClass: 'has-text-info',
classNames: ['button', 'is-transparent'],
openLabel: 'Hide options',
closedLabel: 'More options',
init() {
this._super(...arguments);
const toggleAttr = this.get('toggleAttr');
defineProperty(
this,
'isOpen',
computed(`toggleTarget.${toggleAttr}`, () => {
const props = this.getProperties('toggleTarget', 'toggleAttr');
return get(props.toggleTarget, props.toggleAttr);
})
);
},
click() {
const target = this.get('toggleTarget');
const attr = this.get('toggleAttr');
const current = get(target, attr);
set(target, attr, !current);
},
});