Calendar日历 - 图1

Calendar 日历

平铺选择

  1. import { Button, Select, Icon, Input, Cell, Calendar } from 'zarm';
  2. class Demo extends React.Component {
  3. constructor(props) {
  4. super(props);
  5. this.state = {
  6. visible: false,
  7. multiple: true,
  8. value: ['2019-10-11', '2019-10-17'],
  9. min: '2019-9-12',
  10. max: '2019-11-11',
  11. dateRender: (date) => {
  12. if (/(0|6)/.test(date.getDay())) {
  13. return (
  14. <div className="custom">
  15. <div className="custom__date">{date.getDate()}</div>
  16. <div className="custom__text">休息</div>
  17. </div>
  18. );
  19. }
  20. return date.getDate();
  21. },
  22. disabledDate: (date) => /(0|6)/.test(date.getDay())
  23. };
  24. }
  25. render() {
  26. const { multiple, min, max, visible } = this.state;
  27. return (
  28. <div>
  29. <div>
  30. <Cell title="multiple">
  31. <Select
  32. visible={visible}
  33. placeholder="multiple"
  34. value={multiple ? 'true' : 'false'}
  35. dataSource={[
  36. {
  37. value: 'false',
  38. label: '单选'
  39. },
  40. {
  41. value: 'true',
  42. label: '双选'
  43. }
  44. ]}
  45. onOk={(selected) => {
  46. this.setState({
  47. multiple: selected[0].value === 'true',
  48. visible: false
  49. });
  50. }}
  51. />
  52. </Cell>
  53. <Cell title="min">
  54. <Input
  55. type="text"
  56. placeholder="请输入日历起始日期"
  57. value={min}
  58. onBlur={e => this.setState({ min: e })}
  59. />
  60. </Cell>
  61. <Cell title="max">
  62. <Input
  63. type="text"
  64. placeholder="请输入日历终止日期"
  65. value={max}
  66. onBlur={e => this.setState({ max: e })}
  67. />
  68. </Cell>
  69. </div>
  70. <div>
  71. <Calendar
  72. {...this.state}
  73. onChange={(value) => {
  74. this.setState({ value });
  75. console.log('onChange', value);
  76. }}
  77. />
  78. </div>
  79. </div>
  80. );
  81. }
  82. }
  83. ReactDOM.render(<Demo />, mountNode);

API

属性类型默认值说明
valueDate | Date[]-
defaultValueDate | Date[]-初始值
minDatenew Date()最小可选日期
maxDatemin + 1 年最大可选日期
multiplebooleanfalse是否双选
dateRender(date?: Date) => void(date) => date.getDate()日期渲染函数
disabledDate(date?: Date) => boolean() => false日期是否禁止选择
onChange(value?: Date[]) => void-日期选择发生变化时触发的回调函数