UNPKG

@flatbiz/antd

Version:
128 lines (124 loc) 4.82 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 { DatePicker } from 'antd'; import dayjs from 'dayjs'; import { flatbizDate } from '@flatbiz/utils'; import { D as DayjsDateTypeEnum, g as getDisabledHour, a as getDisabledMinute, b as getDisabledSecond } from './time-CeL7904f.js'; import { jsx } from 'react/jsx-runtime'; var _excluded = ["value", "onChange", "style", "format", "outputNormalize", "inputNormalize"]; /** * DatePicker包装组件 * ``` * 1. value 默认格式为 'YYYY-MM-DD',可以通过 inputNormalize 来进行自定义转换 * 2. onChange返回类型 string,可以通过 outputNormalize 来进行自定义转换 * 3. 默认格式化类型 YYYY-MM-DD; 当showTime===true时,默认格式化类型 DayjsDateTypeEnum.YMDHms;其他格式化类型自定义format * 4. 设置 disabledDate 后,disabledDateConfig配置将失效 * 5. 设置 disabledTime 后,内置的disabledTime逻辑将失效 * ``` */ var DatePickerWrapper = function DatePickerWrapper(props) { var value = props.value, onChange = props.onChange, style = props.style, format = props.format, outputNormalize = props.outputNormalize, inputNormalize = props.inputNormalize, otherProps = _objectWithoutProperties(props, _excluded); var _ref = props.disabledDateConfig || {}, minDate = _ref.minDate, maxDate = _ref.maxDate, disabledHourList = _ref.disabledHourList, disabledMinuteList = _ref.disabledMinuteList, disabledSecondList = _ref.disabledSecondList; var minDateTimeDayInst = minDate ? dayjs(minDate) : undefined; var maxDateTimeDayInst = maxDate ? dayjs(maxDate) : undefined; var customFormat = useMemo(function () { if (format) return format; if (props.showTime) return DayjsDateTypeEnum.YMDHms; return DayjsDateTypeEnum.YMD; }, [props.showTime, format]); var onChangeDate = hooks.useCallbackRef(function (date, dateString) { if (date) { if (outputNormalize) { onChange === null || onChange === void 0 || onChange(outputNormalize(dateString)); } else { onChange === null || onChange === void 0 || onChange(dateString); } } else { onChange === null || onChange === void 0 || onChange(undefined); } }); var getDisabledDate = hooks.useCallbackRef(function (current) { var currentDate = current.format(DayjsDateTypeEnum.YMD); if (!props.disabledDateConfig) { return false; } if (minDateTimeDayInst && maxDateTimeDayInst) { if (!flatbizDate.in(currentDate, minDateTimeDayInst.format(DayjsDateTypeEnum.YMD), maxDateTimeDayInst.format(DayjsDateTypeEnum.YMD))) { return true; } } else if (minDateTimeDayInst) { if (!flatbizDate.gte(currentDate, minDateTimeDayInst.format(DayjsDateTypeEnum.YMD))) { return true; } } else if (maxDateTimeDayInst) { if (!flatbizDate.gte(maxDateTimeDayInst.format(DayjsDateTypeEnum.YMD), currentDate)) { return true; } } return false; }); var datePickerValue = useMemo(function () { if (value) { var valueFt = inputNormalize ? inputNormalize(value) : value; if (valueFt) { return dayjs(flatbizDate.dateNormalize(valueFt)); } } return undefined; }, [value]); var getDisabledTime = hooks.useCallbackRef(function (current) { var options = { minDateTime: minDateTimeDayInst, maxDateTime: maxDateTimeDayInst, disabledHourList: disabledHourList, disabledMinuteList: disabledMinuteList, disabledSecondList: disabledSecondList }; current = current || datePickerValue || dayjs(new Date()); return { disabledHours: function disabledHours() { return getDisabledHour(current, options); }, disabledMinutes: function disabledMinutes() { return getDisabledMinute(current, options); }, disabledSeconds: function disabledSeconds() { return getDisabledSecond(current, options); } }; }); var showTime = useMemo(function () { if (props.showTime) return props.showTime; if (customFormat && customFormat.includes('HH')) { return true; } return false; }, [props.showTime, customFormat]); return /*#__PURE__*/jsx(DatePicker, _objectSpread2(_objectSpread2({ disabledDate: getDisabledDate, disabledTime: getDisabledTime }, otherProps), {}, { showTime: showTime, format: customFormat, style: _objectSpread2({ width: '100%' }, style), value: datePickerValue, onChange: onChangeDate })); }; export { DatePickerWrapper as D }; //# sourceMappingURL=date-picker-wrapper-Cs-HoJ6K.js.map