import React, {Component, Children} from 'react';
import PropTypes from 'prop-types';

/**
 * 条件容器
 */
class Switch extends Component {
  static propTypes = {
    style: PropTypes.object,
    children: PropTypes.any
  }

  render() {
    const {children, style} = this.props;
    const childrens = Children.map(children, child => child);

    let renderChild = null;

    childrens.some((child) => {
      const is = child.props.is;
      if (is) {
        renderChild = child;
        return true;
      }
    });

    return (
      <div style={style}>
        {renderChild}
      </div>
    );
  }
}

export default Switch;
