Card.jsx 926B

12345678910111213141516171819202122232425262728293031323334
  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import classnames from 'classnames'
  4. import CardHeader from './CardHeader.jsx'
  5. import CardBody from './CardBody.jsx'
  6. const Card = props => {
  7. return (
  8. <div className={classnames(props.customClass, 'card')}>
  9. {props.children}
  10. </div>
  11. )
  12. }
  13. export default Card
  14. Card.propTypes = {
  15. // from http://www.mattzabriskie.com/blog/react-validating-children
  16. children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
  17. if (
  18. children.length > 2 ||
  19. children[0].type !== CardHeader ||
  20. children[1].type !== CardBody
  21. // children.some(p => p.type !== CardHeader && p.type !== CardBody)
  22. ) {
  23. return new Error(`PropType Error: children of ${componentName} must be: 1 CardHeader and 1 CardBody.`)
  24. }
  25. }).isRequired,
  26. customClass: PropTypes.string
  27. }
  28. Card.defaultProps = {
  29. customClass: ''
  30. }