Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. //@flow
  2. import React, {Component} from 'react';
  3. import PropTypes from 'prop-types'
  4.  
  5. type GroupProps = {
  6. name: string,
  7. children?: Array<React$Element<*>>,
  8. };
  9.  
  10. let groupName;
  11.  
  12. export class RadioGroup extends Component<GroupProps> {
  13. props: GroupProps;
  14. static childContextTypes = {
  15. name: PropTypes.string,
  16. };
  17.  
  18. getChildContext() {
  19. return {name: this.props.name};
  20. }
  21. render() {
  22. let {name, children, ...otherProps} = this.props;
  23. groupName = name;
  24.  
  25. return <div {...otherProps}>{children}</div>;
  26. }
  27. }
  28.  
  29. type ItemProps = {
  30. children?: Array<React$Element<*>>,
  31. };
  32.  
  33. export class RadioItem extends Component<ItemProps> {
  34. props: ItemProps;
  35. static contextTypes = {
  36. name: PropTypes.string,
  37. };
  38. render() {
  39. let {children, ...otherProps} = this.props;
  40. return (
  41. <div {...otherProps}>
  42. <input name={this.context.name} type="radio" />
  43. <span>{children}</span>
  44. </div>
  45. );
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement