diff --git a/wherehows-web/app/components/radio-button-composer.js b/wherehows-web/app/components/radio-button-composer.js new file mode 100644 index 0000000000..b81125e453 --- /dev/null +++ b/wherehows-web/app/components/radio-button-composer.js @@ -0,0 +1,34 @@ +import Ember from 'ember'; + +const { + Component, + get +} = Ember; + +export default Component.extend({ + tagName: '', + + didReceiveAttrs() { + this._super(...arguments); + const attrs = this.attrs; + + ['name', 'groupValue', 'value'].forEach(attr => { + if (!(attr in attrs)) { + throw new Error( + `Attribute '${attr}' is required to be passed in when instantiating this component.` + ); + } + }); + }, + + actions: { + changed() { + const closureAction = get(this, 'attrs.changed'); + + if (typeof closureAction === 'function') { + return closureAction(...arguments); + } + this.sendAction('changed', ...arguments); + } + } +}); diff --git a/wherehows-web/app/templates/components/radio-button-composer.hbs b/wherehows-web/app/templates/components/radio-button-composer.hbs new file mode 100644 index 0000000000..a9b7fe8c27 --- /dev/null +++ b/wherehows-web/app/templates/components/radio-button-composer.hbs @@ -0,0 +1,11 @@ +{{#radio-button + value=value + groupValue=groupValue + required=required + disabled=disabled + name=name + radioId=radioId + radioClass=radioClass + changed=(action "changed" name)}} + {{yield}} +{{/radio-button}} \ No newline at end of file