Last active
January 11, 2019 10:19
-
-
Save kaneel/6f811c9568c3d54f716d01c48d7a12d2 to your computer and use it in GitHub Desktop.
Simple Radio Component that can take any children and wrap it into a Radio choice.
This file contains 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
import * as React from 'react'; | |
import { v4 as uuid } from 'uuid'; | |
import { styled } from '../styled'; | |
export interface IProps { | |
name: string; | |
} | |
const StyledRadio = styled.div` | |
`; | |
const StyledChoice = styled.p` | |
` | |
export default class Radio extends React.Component<IProps, {}> { | |
public render() { | |
const { children, name } = this.props; | |
return ( | |
<StyledRadio> | |
{ | |
React.Children.toArray(children).map( | |
(child: any, key) => { | |
const id = uuid(); | |
return ( | |
<StyledChoice key={key}> | |
<input type="radio" name={name} id={id} value={key} /> | |
<label htmlFor={id}>{child}</label> | |
</StyledChoice> | |
); | |
} | |
) | |
} | |
</StyledRadio> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment