UnitGroup.tsx 970 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React, { PureComponent } from 'react';
  2. import { GroupProps } from 'react-select/lib/components/Group';
  3. interface ExtendedGroupProps extends GroupProps<any> {
  4. data: any;
  5. }
  6. interface State {
  7. expanded: boolean;
  8. }
  9. export class UnitGroup extends PureComponent<ExtendedGroupProps, State> {
  10. state = {
  11. expanded: false,
  12. };
  13. onToggleChildren = () => {
  14. this.setState(prevState => ({
  15. expanded: !prevState.expanded,
  16. }));
  17. };
  18. render() {
  19. const { children, label } = this.props;
  20. const { expanded } = this.state;
  21. console.log(children);
  22. return (
  23. <div className="width-18 unit-picker-group" style={{ marginBottom: '5px' }}>
  24. <div className="unit-picker-group-item" onClick={this.onToggleChildren}>
  25. <span style={{ textTransform: 'capitalize' }}>{label}</span>
  26. <i className={`fa ${expanded ? 'fa-minus' : 'fa-plus'}`} />{' '}
  27. </div>
  28. {expanded && children}
  29. </div>
  30. );
  31. }
  32. }