UNPKG

fk-react-ui-components

Version:

Step 1 : Create a file in [ Seeds / Plants / Trees ] <br> Step 2 : It should export an Object with component name and story Component [Refer other components] <br> Step 3 : Story Component should return a react component <br> Step 3 : Created file should

36 lines (33 loc) 976 B
import React from 'react'; import classname from 'classnames'; import FormElement from "../FormElement.js"; export class RadioButtonGroup extends FormElement { constructor(props) { super(props); this.state = { ...this.state, selected: props.defaultSelected } this.handleChange = this.handleChange.bind(this); } handleChange(event) { this.setState({ selected: event.target.value }); super.handleChange(event); } render() { return ( <div> { this.props.children.map((Child) => React.cloneElement(Child, { onChange: this.handleChange, name: this.props.name, selected: Child.props.value === this.state.selected, key: Child.props.value })) } </div> ); } }