Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Last active May 17, 2016 06:53
Show Gist options
  • Save jrwebdev/67a5c6a0f0fdcd824714f0db26721d87 to your computer and use it in GitHub Desktop.
Save jrwebdev/67a5c6a0f0fdcd824714f0db26721d87 to your computer and use it in GitHub Desktop.
ngReact Toggle Component
const module = angular.module('toggle', ['react']);
const Toggle = (props) => (
<div onClick={() => props.onToggle(!props.value)}>
<span className={props.value ? 'selected' : ''}>
{props.trueLabel || 'Yes'}
</span>
<span className={!props.value ? 'selected' : ''}>
{props.falseLabel || 'No'}
</span>
</div>
);
Toggle.propTypes = {
value: React.PropTypes.bool,
trueLabel: React.PropTypes.string,
falseLabel: React.PropTypes.string,
onToggle: React.PropTypes.func
};
module.directive('toggle', ['reactDirective', function (reactDirective) {
return reactDirective(Toggle);
}]);
<toggle value="value"
true-label="trueLabel"
false-label="falseLabel"
on-toggle="::onToggle">
</toggle>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment