index.jsx 3.5 KB

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