All files / src/datepicker/_example DatePickerRangeExample.jsx

33.33% Statements 2/6
100% Branches 0/0
20% Functions 1/5
33.33% Lines 2/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61        1x     1x                                                                                                          
import React from "react";
import moment from "moment";
import { DatePicker } from "@tencent/tea-component/lib/datepicker";
 
const { RangePicker, MonthPicker } = DatePicker;
 
export default () => {
  return (
    <>
      <section>
        <h3>日期选择 range</h3>
        <DatePicker
          defaultValue={moment("2019-04-01")}
          range={[moment("2019-01-01"), moment("2020-01-11")]}
          onChange={value => console.log(value.format("YYYY/MM/DD"))}
        />
      </section>
      <section>
        <h3>包含时间的日期选择 range</h3>
        <DatePicker
          showTime
          range={[moment("2019-02-02 12:30:00"), moment("2020-02-12 12:30:00")]}
          onChange={value => console.log(value.format())}
        />
      </section>
      <section>
        <h3>月份选择 range</h3>
        <MonthPicker
          defaultValue={moment("2019-04-01")}
          range={[moment("2018-09"), moment("2020-01")]}
          onChange={value => console.log(value.format("YYYY/MM/DD"))}
        />
      </section>
      <section>
        <h3>包含时间的范围选择 range</h3>
        <RangePicker
          range={[
            moment()
              .subtract(6, "d")
              .startOf("d"),
            moment().endOf("d"),
          ]}
          defaultValue={[
            moment()
              .subtract(6, "d")
              .startOf("d"),
            moment().endOf("d"),
          ]}
          showTime={{
            defaultValue: [
              moment("00:00:00", "HH:mm:ss"),
              moment("23:59:59", "HH:mm:ss"),
            ],
          }}
          onChange={value => console.log(value[0].format(), value[1].format())}
        />
      </section>
    </>
  );
};