index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import Button from '../Button';
  4. export default class Select extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = { selecting: false };
  8. }
  9. componentWillMount() {}
  10. componentWillUnmount() {}
  11. open() {
  12. this.setState({ selecting: true });
  13. }
  14. close() {
  15. this.setState({ selecting: false });
  16. }
  17. render() {
  18. const { selecting } = this.state;
  19. const { value, list = [], size = 'small', theme = 'theme' } = this.props;
  20. let index = 0;
  21. for (let i = 0; i < list.length; i += 1) {
  22. if (list[i].key === value) {
  23. index = i;
  24. break;
  25. }
  26. }
  27. const title = list.length > 0 ? list[index].title : '';
  28. return (
  29. <div className="select">
  30. <div hidden={!selecting} className="mask" onClick={() => this.close()} />
  31. <div className="select-warp">
  32. <Button size={size} theme={theme} radius onClick={() => this.open()}>
  33. {title} <i className="right-arrow" />
  34. </Button>
  35. <div className={`select-body ${selecting ? 'select' : ''}`}>
  36. {list.map(item => {
  37. return <div className="select-option">{item.title}</div>;
  38. })}
  39. </div>
  40. </div>
  41. </div>
  42. );
  43. }
  44. }