All files / src/timepicker/_example TimeRangePickerExample.jsx

42.86% Statements 6/14
50% Branches 3/6
22.22% Functions 2/9
42.86% Lines 6/14

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 62 63 64        1x   1x           1x                                                                 2x 2x             2x                    
import React from "react";
import moment, { isMoment } from "moment";
import { TimePicker } from "@tencent/tea-component/lib/timepicker";
 
const { RangePicker } = TimePicker;
 
const range = (s, t) =>
  Array(t - s + 1)
    .fill(0)
    .map((_, i) => s + i);
 
export default () => {
  return (
    <>
      <section>
        <RangePicker
          defaultValue={[
            moment("09:30:00", "HH:mm:ss"),
            moment("23:30:00", "HH:mm:ss"),
          ]}
          minuteStep={10}
          secondStep={30}
          onChange={value =>
            console.log(
              value[0].format("HH:mm:ss"),
              value[1].format("HH:mm:ss")
            )
          }
        />
      </section>
      <section>
        <RangePicker
          format="HH:mm"
          range={[moment("09:30", "HH:mm"), moment("23:30", "HH:mm")]}
          onChange={value =>
            console.log(value[0].format("HH:mm"), value[1].format("HH:mm"))
          }
        />
      </section>
      <hr />
      <p>起始相距两小时以上</p>
      <section>
        <RangePicker
          format="HH:mm"
          disabledTime={(time, partial) => {
            const [start] = time;
            Iif (partial === "end" && isMoment(start)) {
              return {
                disabledHours: () => range(0, start.hour() + 1),
                disabledMinutes: hour =>
                  hour - start.hour() <= 2 ? range(0, start.minute() - 1) : [],
              };
            }
            return {};
          }}
          onChange={value =>
            console.log(value[0].format("HH:mm"), value[1].format("HH:mm"))
          }
        />
      </section>
    </>
  );
};