index.jsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 MonthBottomSlot = function (props) {
  40. const { style } = props;
  41. return (
  42. <Space style={{ padding: '12px 20px', ...style }}>
  43. <Icon type="bulb" style={{ color: 'rgba(var(--amber-5), 1)' }} />
  44. <Text strong style={{ color: 'var(--color-text-2)' }}>
  45. 请阅读
  46. </Text>
  47. <Text link={{ href: 'https://semi.design/', target: '_blank' }}>须知</Text>
  48. </Space>
  49. );
  50. };
  51. return (
  52. <div>
  53. <span>topSlot</span>
  54. <DatePicker topSlot={<TopSlot />} disabledDate={disabledDate} value={date} onChange={handleDateChange} />
  55. <br />
  56. <br />
  57. <span>bottomSlot</span>
  58. <DatePicker bottomSlot={<BottomSlot />} />
  59. <br />
  60. <br />
  61. <span>bottomSlot+dateTimeRange</span>
  62. <DatePicker type="dateTimeRange" bottomSlot={<BottomSlot />} style={{ width: 300 }} />
  63. <br />
  64. <br />
  65. <span>topSlot+month</span>
  66. <DatePicker type="month" bottomSlot={<MonthBottomSlot />} />
  67. <br />
  68. <br />
  69. <span>topSlot+bottomSlot+compact</span>
  70. <DatePicker topSlot={<TopSlot style={{ padding: '8px 12px 0' }} />} bottomSlot={<BottomSlot style={{ padding: '8px 12px' }} />} density="compact" />
  71. </div>
  72. );
  73. }