InsetInput.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react';
  2. import { DatePicker, Space, Input, Button, Select } from '@douyinfe/semi-ui';
  3. import { Position } from '@douyinfe/semi-foundation/tooltip/foundation';
  4. import { strings } from '@douyinfe/semi-foundation/tooltip/constants';
  5. import * as dateFns from 'date-fns';
  6. /**
  7. * Test with Chromatic
  8. */
  9. export default function App() {
  10. const spacing = [200, 400];
  11. const [date, setDate] = React.useState();
  12. const [insetInput, setInsetInput] = React.useState(true);
  13. const [position, setPosition] = React.useState('leftTopOver');
  14. const [needConfirm, setNeedConfirm] = React.useState(false);
  15. const [density, setDensity] = React.useState(true);
  16. const props = {
  17. defaultOpen: true,
  18. motion: false,
  19. insetInput,
  20. defaultPickerValue: '2021-12-01',
  21. position,
  22. density: density ? 'compact' : 'default',
  23. autoAdjustOverflow: false,
  24. };
  25. const positionOptionList = strings.POSITION_SET.map((position) => ({
  26. value: position,
  27. label: position,
  28. key: position,
  29. }));
  30. const triggerRender = ({ placeholder }) => {
  31. const format = 'Pp';
  32. const value = (date && dateFns.format(date, format)) || placeholder;
  33. return <Input value={value} readOnly />;
  34. };
  35. const handleDateChange = (date) => {
  36. setDate(date);
  37. };
  38. const handleBtnClick = () => {
  39. setInsetInput(!insetInput);
  40. };
  41. const handleReset = () => {
  42. setInsetInput(true);
  43. setPosition('leftTopOver');
  44. };
  45. const handleToggleNeedConfirm = () => {
  46. setNeedConfirm(!needConfirm);
  47. };
  48. const handleToggleDensity = () => {
  49. setDensity(!density);
  50. };
  51. return (
  52. <div style={{ height: '200vh' }}>
  53. <div style={{ marginBottom: 12 }}>
  54. <Space>
  55. <Button onClick={handleBtnClick}>
  56. {`insetInput=${insetInput}`}
  57. </Button>
  58. <Button onClick={handleToggleNeedConfirm}>
  59. {`needConfirm=${needConfirm}`}
  60. </Button>
  61. <Button onClick={handleToggleDensity}>
  62. {`小尺寸=${density}`}
  63. </Button>
  64. <Select
  65. style={{ width: 200 }}
  66. optionList={positionOptionList}
  67. placeholder='选择position'
  68. value={position}
  69. onChange={setPosition}
  70. showClear
  71. />
  72. <Button onClick={handleReset} theme="solid">reset</Button>
  73. </Space>
  74. </div>
  75. <Space wrap spacing={spacing}>
  76. <DatePicker placeholder='选择单个日期' {...props} />
  77. <DatePicker placeholder='选择月' {...props} type='month' defaultOpen={false} />
  78. <DatePicker placeholder='选择日期时间' {...props} type='dateTime' needConfirm={needConfirm} />
  79. <DatePicker placeholder='选择日期范围' {...props} type='dateRange' />
  80. <DatePicker placeholder='选择日期时间范围' {...props} type='dateTimeRange' needConfirm={needConfirm} />
  81. <DatePicker placeholder='format=Pp' {...props} format='yyyy-MM-dd HH:mm:ss' type='dateTimeRange' />
  82. </Space>
  83. </div>
  84. );
  85. }
  86. App.parameters = {
  87. chromatic: {
  88. disableSnapshot: false,
  89. delay: 3000,
  90. viewports: [1800]
  91. },
  92. };
  93. App.storyName = 'inset input';