index.jsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, { useState, useEffect, useMemo } from 'react';
  2. import { Select, Popover, Tag, Button, Dropdown } from '@douyinfe/semi-ui';
  3. const { Option } = Select;
  4. const SelectSection = () => {
  5. useEffect(() => {
  6. console.log('SelectSection mounted');
  7. return () => {
  8. console.log('SelectSection unmounted');
  9. };
  10. }, []);
  11. return (
  12. <Select
  13. defaultValue="abc"
  14. style={{ width: 120 }}
  15. getPopupContainer={() => document.querySelector('#popup-container')}
  16. >
  17. <Option value="abc">抖音</Option>
  18. <Option value="hotsoon">火山</Option>
  19. <Option value="pipixia" disabled>
  20. 皮皮虾
  21. </Option>
  22. <Option value="xigua">西瓜视频</Option>
  23. </Select>
  24. );
  25. };
  26. function Demo() {
  27. const [popupVisible, setPopupVisible] = useState(false);
  28. const [dropdownVisible, setDropdownVisible] = useState(false);
  29. const cachedSelect = useMemo(() => <SelectSection />, []);
  30. return (
  31. <div style={{ margin: 50 }}>
  32. <Popover
  33. visible={popupVisible}
  34. onVisibleChange={v => setPopupVisible(v)}
  35. position={'bottomLeft'}
  36. content={(
  37. <div style={{ padding: 20 }} id={'popup-container'}>
  38. <p>123456</p>
  39. <div>
  40. <Button onClick={() => setPopupVisible(false)}>关闭浮层</Button>
  41. </div>
  42. {cachedSelect}
  43. <div>
  44. <Dropdown
  45. trigger={'click'}
  46. position={'bottomLeft'}
  47. visible={dropdownVisible}
  48. onVisibleChange={v => setDropdownVisible(v)}
  49. getPopupContainer={() => document.querySelector('#popup-container')}
  50. render={(
  51. <Dropdown.Menu>
  52. {[1, 2, 3].map(index => (
  53. <Dropdown.Item key={index} onClick={() => setDropdownVisible(false)}>
  54. Menu Item {index}
  55. </Dropdown.Item>
  56. ))}
  57. </Dropdown.Menu>
  58. )}
  59. >
  60. <Button>Click me</Button>
  61. </Dropdown>
  62. </div>
  63. </div>
  64. )}
  65. trigger="click"
  66. showArrow
  67. >
  68. <Tag>点击此处</Tag>
  69. </Popover>
  70. </div>
  71. );
  72. }
  73. export default Demo;