UNPKG

@flatbiz/antd

Version:
85 lines (81 loc) 3.42 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { _ as _objectWithoutProperties, a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js'; import { hooks } from '@wove/react/hooks'; import { useMemo } from 'react'; import { TimePicker } from 'antd'; import dayjs from 'dayjs'; import { c as DayjsTimeTypeEnum, D as DayjsDateTypeEnum, g as getDisabledHour, a as getDisabledMinute, b as getDisabledSecond } from './time-CeL7904f.js'; import { jsx } from 'react/jsx-runtime'; var _excluded = ["onChange", "disabledTimeConfig"]; // export declare type EventValue<DateType> = DateType | null; // export declare type RangeValue<DateType> = [EventValue<DateType>, EventValue<DateType>] | null; /** * TimePicker组件包装 * ``` * 1. value类型为 [string, string] * 2. onChange返回类型 [string, string] * 3. 默认格式化类型 HH:mm:ss,其他格式化类型自定义format * 4. 设置disabledTime后,disabledTimeConfig配置将失效 * ``` */ var TimeRangePickerWrapper = function TimeRangePickerWrapper(props) { var onChange = props.onChange, disabledTimeConfig = props.disabledTimeConfig, otherProps = _objectWithoutProperties(props, _excluded); var _ref = disabledTimeConfig || {}, minTime = _ref.minTime, maxTime = _ref.maxTime, disabledHourList = _ref.disabledHourList, disabledMinuteList = _ref.disabledMinuteList, disabledSecondList = _ref.disabledSecondList; var format = useMemo(function () { return props.format || DayjsTimeTypeEnum.Hms; }, [props.format]); var onChangeTime = hooks.useCallbackRef(function (date, _ref2) { var _ref3 = _slicedToArray(_ref2, 2), timeStart = _ref3[0], timeEnd = _ref3[1]; if (date) { onChange === null || onChange === void 0 || onChange([timeStart, timeEnd]); } else { onChange === null || onChange === void 0 || onChange(undefined); } }); var timePickerValue = useMemo(function () { var value = props.value; if (value && value.length > 0) { return [value[0] ? dayjs(value[0], format) : value[0], value[1] ? dayjs(value[1], format) : value[1]]; } return undefined; }, [props.value, format]); var getDisabledTime = function getDisabledTime() { var date = dayjs().format(DayjsDateTypeEnum.YMD); var options = { minDateTime: minTime ? dayjs("".concat(date, " ").concat(minTime)) : undefined, maxDateTime: maxTime ? dayjs("".concat(date, " ").concat(maxTime)) : undefined, disabledHourList: disabledHourList, disabledMinuteList: disabledMinuteList, disabledSecondList: disabledSecondList }; return { disabledHours: function disabledHours() { return getDisabledHour(dayjs(), options); }, disabledMinutes: function disabledMinutes(hour) { return getDisabledMinute(dayjs("".concat(date, " ").concat(hour)), options); }, disabledSeconds: function disabledSeconds(hour, minute) { return getDisabledSecond(dayjs("".concat(date, " ").concat(hour, ":").concat(minute)), options); } }; }; return /*#__PURE__*/jsx(TimePicker.RangePicker, _objectSpread2(_objectSpread2({ disabledTime: getDisabledTime }, otherProps), {}, { value: timePickerValue, onChange: onChangeTime, format: format })); }; export { TimeRangePickerWrapper as T }; //# sourceMappingURL=time-range-picker-wrapper-BpQQjbcu.js.map