From 25c3524ead033164c712cb168384f3b13f996922 Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Fri, 24 Mar 2017 21:41:45 -0700 Subject: [PATCH] Adds radio-button proxy component called radio-button-composer. Ember radio button only passes along radio value to container component, the proxy bind the name of the radio target, effectively providng two arguments, and also ensures the requried components of name, groupValue and value are passed along on instantiation --- .../app/components/radio-button-composer.js | 34 +++++++++++++++++++ .../components/radio-button-composer.hbs | 11 ++++++ 2 files changed, 45 insertions(+) create mode 100644 wherehows-web/app/components/radio-button-composer.js create mode 100644 wherehows-web/app/templates/components/radio-button-composer.hbs 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