index.jsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import React from 'react';
  2. import { addDays } from 'date-fns';
  3. import { DatePicker, Typography, Space, InputGroup, Input, InputNumber, Row } from '../../../index';
  4. import RTLWrapper from '../../../configProvider/_story/RTLDirection/RTLWrapper';
  5. const { Title, Text } = Typography;
  6. const dayOffset = 1;
  7. const baseYear = 2019;
  8. const baseDay = 8;
  9. const baseMon = 8;
  10. const presets = [
  11. {
  12. text: 'Today',
  13. start: new Date(),
  14. end: new Date(),
  15. },
  16. {
  17. text: 'Next Day',
  18. start: addDays(new Date(), dayOffset),
  19. end: addDays(new Date(), dayOffset),
  20. },
  21. ];
  22. const baseDate = new Date(baseYear, baseMon, baseDay, 8, 8, 8, 8);
  23. const currentValue = [new Date(baseDate), new Date(baseDate).setDate(baseDay + dayOffset)];
  24. Demo.parameters = {
  25. chromatic: { disableSnapshot: false },
  26. };
  27. export default function Demo(props = {}) {
  28. const style = { width: 240 };
  29. return (
  30. <RTLWrapper>
  31. <Row style={{ marginBottom: 20 }}>
  32. <Title heading={3}>不同尺寸</Title>
  33. <div style={{ marginBottom: 4 }}>
  34. <Space>
  35. <Text>default size</Text>
  36. <DatePicker
  37. onFocus={console.log}
  38. onClear={e => {
  39. console.log('clear', e);
  40. }}
  41. type="dateRange"
  42. style={style}
  43. onChange={console.log}
  44. />
  45. <DatePicker />
  46. </Space>
  47. </div>
  48. <div style={{ marginBottom: 4 }}>
  49. <Space>
  50. <Text>small size</Text>
  51. <DatePicker type="dateRange" size="small" style={style} />
  52. <DatePicker size="small" />
  53. </Space>
  54. </div>
  55. <div style={{ marginBottom: 4 }}>
  56. <Space>
  57. <Text>large size</Text>
  58. <DatePicker type="dateRange" size="large" style={{ width: 280 }} />
  59. <DatePicker size="large" />
  60. </Space>
  61. </div>
  62. </Row>
  63. <Row style={{ marginBottom: 20 }}>
  64. <Title heading={3}>prefix、insetLabel</Title>
  65. <div style={{ marginBottom: 4 }}>
  66. <Space>
  67. <Text>prefix</Text>
  68. <DatePicker prefix="Semi Design" type="dateRange" style={{ width: 340 }} />
  69. </Space>
  70. </div>
  71. <div style={{ marginBottom: 4 }}>
  72. <Space>
  73. <Text>insetLabel</Text>
  74. <DatePicker
  75. insetLabel="放假时间"
  76. type="dateRange"
  77. defaultValue={['2021-06-10', '2021-06-17']}
  78. showClear
  79. style={{ width: 340 }}
  80. />
  81. </Space>
  82. </div>
  83. </Row>
  84. <Row style={{ marginBottom: 20 }}>
  85. <Title heading={3}>dateTimeRange</Title>
  86. <Space>
  87. <DatePicker type="dateTimeRange" showClear needConfirm style={{ width: 360 }} />
  88. <DatePicker
  89. type="dateTimeRange"
  90. defaultValue={currentValue}
  91. placeholder="请选择日期"
  92. style={{ width: 400 }}
  93. />
  94. <DatePicker
  95. type="dateTimeRange"
  96. placeholder={['请选择开始日期', '请选择结束日期']}
  97. style={{ width: 360 }}
  98. />
  99. </Space>
  100. </Row>
  101. <Row style={{ marginBottom: 20 }}>
  102. <Title heading={3}>对比不同校验状态</Title>
  103. <div style={{ marginBottom: 4 }}>
  104. <Space>
  105. <Text>default status</Text>
  106. <DatePicker />
  107. <DatePicker type="dateRange" style={style} />
  108. </Space>
  109. </div>
  110. <div style={{ marginBottom: 4 }}>
  111. <Space>
  112. <Text>warning status</Text>
  113. <DatePicker validateStatus="warning" />
  114. <DatePicker type="dateRange" validateStatus="warning" style={style} />
  115. </Space>
  116. </div>
  117. <div style={{ marginBottom: 4 }}>
  118. <Space>
  119. <Text>error status</Text>
  120. <DatePicker validateStatus="error" />
  121. <DatePicker type="dateRange" validateStatus="error" style={style} />
  122. </Space>
  123. </div>
  124. <div style={{ marginBottom: 4 }}>
  125. <Space>
  126. <Text>disabled status</Text>
  127. <DatePicker disabled />
  128. <DatePicker type="dateRange" disabled style={style} />
  129. </Space>
  130. </div>
  131. </Row>
  132. <Row style={{ marginBottom: 20 }}>
  133. <Title heading={3}>输入框组合</Title>
  134. <div style={{ marginBottom: 4 }}>
  135. <InputGroup>
  136. <Input placeholder="Name" style={{ width: 100 }} />
  137. <DatePicker type="dateRange" placeholder={['入学时间', '离校时间']} style={style} />
  138. <InputNumber placeholder="Score" style={{ width: 140 }} />
  139. </InputGroup>
  140. </div>
  141. <div style={{ marginBottom: 4 }}>
  142. <InputGroup>
  143. <Input placeholder="Name" style={{ width: 100 }} />
  144. <DatePicker type="dateRange" placeholder={['入学时间', '离校时间']} style={style} />
  145. </InputGroup>
  146. </div>
  147. <div style={{ marginBottom: 4 }}>
  148. <InputGroup>
  149. <DatePicker type="dateRange" placeholder={['入学时间', '离校时间']} style={style} />
  150. <Input placeholder="Name" style={{ width: 100 }} />
  151. <InputNumber placeholder="Score" style={{ width: 140 }} />
  152. </InputGroup>
  153. </div>
  154. </Row>
  155. <Row style={{ marginBottom: 20 }}>
  156. <Title heading={3}>带presets</Title>
  157. <div style={{ marginBottom: 4 }}>
  158. <Space>
  159. <DatePicker presets={presets} />
  160. <DatePicker type="dateRange" presets={presets} style={style} />
  161. <DatePicker type="dateTimeRange" presets={presets} style={{ width: 360 }} />
  162. </Space>
  163. </div>
  164. </Row>
  165. </RTLWrapper>
  166. );
  167. }