AdminDropdownOption.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. class AdminDropdownOption extends React.PureComponent {
  5. render() {
  6. const menuItem = this.props.options.map((option) => {
  7. return <button key={option} className="dropdown-item" type="button" onClick={() => this.props.onChangeValue(option)}>{option}</button>;
  8. });
  9. return (
  10. <div className="my-0 form-group">
  11. <label>{this.props.label}</label>
  12. <div className="dropdown">
  13. <button className="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  14. {this.props.selectedValue}
  15. </button>
  16. <div className="dropdown-menu" aria-labelledby="dropdownMenuLink">
  17. {menuItem}
  18. </div>
  19. </div>
  20. {this.props.children}
  21. </div>
  22. );
  23. }
  24. }
  25. AdminDropdownOption.propTypes = {
  26. t: PropTypes.func.isRequired, // i18next
  27. selectedValue: PropTypes.number.isRequired,
  28. label: PropTypes.string.isRequired,
  29. onChangeValue: PropTypes.func.isRequired,
  30. options: PropTypes.array.isRequired,
  31. children: PropTypes.object.isRequired,
  32. };
  33. export default withTranslation()(AdminDropdownOption);