Skip to content

Commit

Permalink
chore(IconToggle): cleaning up prop sync
Browse files Browse the repository at this point in the history
James Friedman committed Mar 15, 2018
1 parent 1a80fa0 commit 8f2c40e
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/IconToggle/index.js
Original file line number Diff line number Diff line change
@@ -6,10 +6,9 @@ import { simpleTag, noop } from '../Base';
import { withRipple } from '../Base/withRipple';
import {
withFoundation,
syncFoundationProp,
addClass,
removeClass,
registerInteractionHandler,
deregisterInteractionHandler
removeClass
} from '../Base/MDCFoundation';

type IconTogglePropsT = {
@@ -42,9 +41,7 @@ export class IconToggle extends withFoundation({
constructor: MDCIconToggle,
adapter: {
addClass: addClass(),
removeClass: removeClass(),
registerInteractionHandler: registerInteractionHandler(),
deregisterInteractionHandler: deregisterInteractionHandler()
removeClass: removeClass()
}
})<IconTogglePropsT, {}> {
static displayName = 'IconToggle';
@@ -55,25 +52,20 @@ export class IconToggle extends withFoundation({
checked: undefined
};

componentDidMount() {
super.componentDidMount();
this.foundation_.toggle(!!this.foundation_.isOn());
}

syncWithProps(nextProps: IconTogglePropsT) {
if (
nextProps.checked !== undefined &&
this.foundation_.isOn() !== nextProps.checked
) {
this.foundation_.toggle(!!nextProps.checked);
}
// checked
syncFoundationProp(
nextProps.checked,
this.on,
() => (this.on = nextProps.checked)
);

if (
nextProps.disabled !== undefined &&
nextProps.disabled !== this.foundation_.isDisabled()
) {
this.foundation_.setDisabled(!!nextProps.disabled);
}
// disabled
syncFoundationProp(
nextProps.disabled,
this.disabled,
() => (this.disabled = nextProps.disabled)
);
}

render() {

0 comments on commit 8f2c40e

Please sign in to comment.