index.jsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* eslint-disable max-len */
  2. import React, { useState, useMemo } from 'react';
  3. import { DatePicker, Icon, Typography, Space, Tabs, TabPane } from '../../../index';
  4. import './index.scss';
  5. const { Text } = Typography;
  6. export default function Demo() {
  7. const [activeTab, setActiveTab] = useState('1');
  8. const [date, setDate] = useState();
  9. const uedDisabledDate = currentDate => currentDate && currentDate.getDate() > 10 && currentDate.getDate() < 15;
  10. const testDisabledDate = currentDate => currentDate && currentDate.getDate() > 15 && currentDate.getDate() < 25;
  11. const handleTabChange = tab => {
  12. setActiveTab(tab);
  13. setDate();
  14. };
  15. const handleDateChange = value => {
  16. setDate(value);
  17. };
  18. const disabledDate = useMemo(() => (activeTab === '1' ? uedDisabledDate : testDisabledDate), [activeTab]);
  19. const TopSlot = function (props) {
  20. const { style } = props;
  21. return (
  22. <Tabs size="small" onChange={handleTabChange} activeKey={activeTab} style={{ padding: '12px 20px 0', ...style }}>
  23. <TabPane tab="UED 排期" itemKey="1" />
  24. <TabPane tab="测试排期" itemKey="2" />
  25. </Tabs>
  26. );
  27. };
  28. const BottomSlot = function (props) {
  29. const { style } = props;
  30. return (
  31. <Space style={{ padding: '12px 20px', ...style }}>
  32. <Icon type="bulb" style={{ color: 'rgba(var(--amber-5), 1)' }} />
  33. <Text strong style={{ color: 'var(--color-text-2)' }}>
  34. 定版前请阅读
  35. </Text>
  36. <Text link={{ href: 'https://semi.design/', target: '_blank' }}>发版须知</Text>
  37. </Space>
  38. );
  39. };
  40. const MonthBottomSlot = function (props) {
  41. const { style } = props;
  42. return (
  43. <Space style={{ padding: '12px 20px', ...style }}>
  44. <Icon type="bulb" style={{ color: 'rgba(var(--amber-5), 1)' }} />
  45. <Text strong style={{ color: 'var(--color-text-2)' }}>
  46. 请阅读
  47. </Text>
  48. <Text link={{ href: 'https://semi.design/', target: '_blank' }}>须知</Text>
  49. </Space>
  50. );
  51. };
  52. return (
  53. <div>
  54. <span>topSlot</span>
  55. <DatePicker topSlot={<TopSlot />} disabledDate={disabledDate} value={date} onChange={handleDateChange} />
  56. <br />
  57. <br />
  58. <span>bottomSlot</span>
  59. <DatePicker bottomSlot={<BottomSlot />} />
  60. <br />
  61. <br />
  62. <span>bottomSlot+dateTimeRange</span>
  63. <DatePicker type="dateTimeRange" bottomSlot={<BottomSlot />} style={{ width: 300 }} />
  64. <br />
  65. <br />
  66. <span>topSlot+month</span>
  67. <DatePicker type="month" bottomSlot={<MonthBottomSlot />} />
  68. <br />
  69. <br />
  70. <span>topSlot+bottomSlot+compact</span>
  71. <DatePicker topSlot={<TopSlot style={{ padding: '8px 12px 0' }} />} bottomSlot={<BottomSlot style={{ padding: '8px 12px' }} />} density="compact" />
  72. </div>
  73. );
  74. }