{"size": 812, "ext": "js", "max_stars_repo_path": "src/reusable/expandable/expandable-children.js", "max_stars_repo_name": "mlibrary/lib.umich.edu", "max_stars_repo_stars_event_min_datetime": "2019-11-20T22:31:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T18:52:51.000Z", "max_issues_repo_path": "src/reusable/expandable/expandable-children.js", "max_issues_repo_name": "mlibrary/lib.umich.edu", "max_issues_repo_issues_event_min_datetime": "2019-07-31T17:57:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-27T03:04:50.000Z", "max_forks_repo_path": "src/reusable/expandable/expandable-children.js", "max_forks_repo_name": "mlibrary/lib.umich.edu", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 32, "max_forks_count": null, "avg_line_length": 21.3684210526, "max_line_length": 68, "alphanum_fraction": 0.6613300493}
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { ExpandableContext } from './expandable'

class ExpandableChildren extends Component {
  componentDidMount() {
    const { context, children, show } = this.props

    if (children.length <= show && !context.disabled) {
      context.disable()
    }
  }

  render() {
    const { context, children, show } = this.props

    return (
      <React.Fragment>
        {context.expanded ? children : children.slice(0, show)}
      </React.Fragment>
    )
  }
}

ExpandableChildren.propTypes = {
  show: PropTypes.number,
}

ExpandableChildren.defaultProps = {
  show: 3,
}

export default props => (
  <ExpandableContext.Consumer>
    {context => <ExpandableChildren {...props} context={context} />}
  </ExpandableContext.Consumer>
)
