Last active
January 3, 2016 01:59
-
-
Save efleming969/8392841 to your computer and use it in GitHub Desktop.
React radio options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var v = React.DOM | |
var RadioOptions = React.createClass | |
( { render: render | |
, handleClick: handleClick | |
} | |
) | |
var props = | |
{ name: "uniqueName" | |
, options: | |
[ { key: "1", value: "1", label: "one" } | |
, { key: "2", value: "2", label: "two" } | |
] | |
, onOptionChange: onOptionChange | |
} | |
React.renderComponent ( RadioOptions (props) , document.body ) | |
function render () | |
{ | |
var selected = this.props.selected || this.props.options[0].value | |
return v.span ( {}, this.props.options.map ( input.bind(this, selected) ) ) | |
} | |
function input (selected, option) | |
{ | |
return v.span | |
( {} | |
, v.input | |
( { type: "radio" | |
, name: this.props.name | |
, value: option.value | |
, id: this.props.name + "#" + option.value | |
, checked: selected === option.value | |
, onClick: this.handleClick | |
} | |
) | |
, v.label( {} , option.label ) | |
) | |
} | |
function handleClick (event) | |
{ | |
console.log ( event.target.value ) | |
} | |
function onOptionChange (value) | |
{ | |
console.log ( value ) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: react-radio | |
description: React radio options component | |
authors: | |
- Erick Fleming | |
resources: | |
- http://fb.me/react-with-addons-0.8.0.js | |
normalize_css: no | |
wrap: b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment