Skip to content

Commit

Permalink
chore(addon/components/paper-radio): moves respective logic to their …
Browse files Browse the repository at this point in the history
…different implementations.
  • Loading branch information
matthewhartstonge committed Dec 5, 2024
1 parent 9982aba commit 04fc025
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
1 change: 1 addition & 0 deletions addon/components/paper-radio-base.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{if @warn " md-warn"}}
{{if @accent " md-accent"}}
{{if @primary " md-primary"}}
{{if @secondary " md-secondary"}}
{{if this.focused " md-focused"}}
{{@class}}'
aria-checked={{this.ariaChecked}}
Expand Down
22 changes: 1 addition & 21 deletions addon/components/paper-radio-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,10 @@ export default class PaperRadioBase extends Focusable {
super(owner, args);

this.labelId = `${guidFor(this)}-label`;
this.shouldRegister = this.args.shouldRegister || false;

this.skipProxy = this.args.skipProxy || false;
this.toggle = this.args.toggle || false;

if (this.shouldRegister) {
assert(
'A parent component should be supplied to <PaperRadio> when shouldRegister=true',
this.args.parentComponent
);
this.parent = this.args.parentComponent;
}

assert(
'<PaperRadio> requires an `onChange` action or null for no action.',
this.args.onChange !== undefined
Expand All @@ -72,10 +64,6 @@ export default class PaperRadioBase extends Focusable {
@action didInsertNode(element) {
this.element = element;
this.registerListeners(element);

if (this.shouldRegister) {
this.parent.registerChild(this);
}
}

@action didUpdateNode() {
Expand All @@ -92,10 +80,6 @@ export default class PaperRadioBase extends Focusable {

willDestroy() {
super.willDestroy(...arguments);

if (this.shouldRegister) {
this.parent.unregisterChild(this);
}
}

get value() {
Expand Down Expand Up @@ -130,8 +114,4 @@ export default class PaperRadioBase extends Focusable {
}
}
}

processProxy() {
this.onClick();
}
}
8 changes: 6 additions & 2 deletions addon/components/paper-radio-proxiable.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/**
* @module ember-paper
*/
import PaperRadioBase from './paper-radio-base';
import PaperRadio from './paper-radio';

/**
* @class PaperRadio
* @extends PaperRadioBase
*/
export default class PaperRadioProxiable extends PaperRadioBase {}
export default class PaperRadioProxiable extends PaperRadio {
processProxy() {
this.onClick();
}
}
54 changes: 53 additions & 1 deletion addon/components/paper-radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,61 @@
* @module ember-paper
*/
import PaperRadioBase from './paper-radio-base';
import { action } from '@ember/object';
import { assert } from '@ember/debug';

/**
* @class PaperRadio
* @extends PaperRadioBase
*/
export default class PaperRadio extends PaperRadioBase {}
export default class PaperRadio extends PaperRadioBase {
/**
* The parent this component is bound to.
* @type {PaperRadioGroup|PaperForm|PaperItem|PaperTabs}
*/
parent;
/**
* Marks whether the component should register itself to the supplied parent
* @type {Boolean}
*/
shouldRegister;
/**
* Marks whether the component should skip being proxied.
* @type {Boolean}
*/
skipProxy;

constructor(owner, args) {
super(owner, args);

this.skipProxy = this.args.skipProxy || false;
this.shouldRegister = this.args.shouldRegister || false;
if (this.shouldRegister) {
assert(
'A parent component should be supplied to <PaperRadio> when shouldRegister=true',
this.args.parentComponent
);
this.parent = this.args.parentComponent;
}
}

/**
* Performs any required DOM setup.
* @param element
*/
@action didInsertNode(element) {
super.didInsertNode(element);

if (this.shouldRegister) {
this.parent.registerChild(this);
}
}

willDestroy() {
super.willDestroy(...arguments);

if (this.shouldRegister) {
this.parent.unregisterChild(this);
}
}
}

0 comments on commit 04fc025

Please sign in to comment.