UNPKG

@flatbiz/antd

Version:
89 lines (85 loc) 3.43 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { _ as _objectWithoutProperties, 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 isSameOrAfter from 'dayjs/plugin/isSameOrAfter.js'; import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js'; 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", "format"]; dayjs.extend(isSameOrBefore); dayjs.extend(isSameOrAfter); /** * TimePicker组件包装 * ``` * 1. value类型为 string * 2. onChange返回类型 string * 3. 默认格式化类型 HH:mm:ss * 4. 其他格式化类型自定义format * 5. 设置disabledTime后,disabledTimeConfig配置将失效 * ``` */ var TimePickerWrapper = function TimePickerWrapper(props) { var onChange = props.onChange, disabledTimeConfig = props.disabledTimeConfig, format = props.format, otherProps = _objectWithoutProperties(props, _excluded); var _ref = disabledTimeConfig || {}, minTime = _ref.minTime, maxTime = _ref.maxTime, disabledHourList = _ref.disabledHourList, disabledMinuteList = _ref.disabledMinuteList, disabledSecondList = _ref.disabledSecondList; var customFormat = format || DayjsTimeTypeEnum.Hms; var onChangeTime = hooks.useCallbackRef(function (time, timeString) { if (time) { onChange === null || onChange === void 0 || onChange(timeString); } else { onChange === null || onChange === void 0 || onChange(undefined); } }); var timePickerValue = useMemo(function () { var value = props.value; if (value) { return dayjs(value, customFormat); } return undefined; }, [customFormat, props.value]); 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); } }; }; var showNow = useMemo(function () { var now = dayjs(); return now.isSameOrAfter(dayjs(minTime || '00:00:00', customFormat)) && now.isSameOrBefore(dayjs(maxTime || '23:59:59', customFormat)); }, [customFormat, maxTime, minTime]); return /*#__PURE__*/jsx(TimePicker, _objectSpread2(_objectSpread2({ showNow: showNow, disabledTime: getDisabledTime }, otherProps), {}, { value: timePickerValue, onChange: onChangeTime, format: customFormat })); }; export { TimePickerWrapper as T }; //# sourceMappingURL=time-picker-wrapper-Dx69Z9kc.js.map