UNPKG

@mantine/dates

Version:

Calendars, date and time pickers based on Mantine components

36 lines (35 loc) 1.38 kB
"use client"; const require_to_date_string = require("../../utils/to-date-string/to-date-string.cjs"); let react = require("react"); let _mantine_hooks = require("@mantine/hooks"); //#region packages/@mantine/dates/src/hooks/use-uncontrolled-dates/use-uncontrolled-dates.ts const getEmptyValue = (type) => type === "range" ? [null, null] : type === "multiple" ? [] : null; const convertDatesValue = (value, withTime) => { const converter = withTime ? require_to_date_string.toDateTimeString : require_to_date_string.toDateString; return Array.isArray(value) ? value.map(converter) : converter(value); }; function useUncontrolledDates({ type, value, defaultValue, onChange, withTime = false }) { const storedType = (0, react.useRef)(type); const [_value, _setValue, controlled] = (0, _mantine_hooks.useUncontrolled)({ value: convertDatesValue(value, withTime), defaultValue: convertDatesValue(defaultValue, withTime), finalValue: getEmptyValue(type), onChange }); let _finalValue = _value; if (storedType.current !== type) { storedType.current = type; if (value === void 0) { _finalValue = defaultValue !== void 0 ? defaultValue : getEmptyValue(type); _setValue(_finalValue); } } return [ _finalValue, _setValue, controlled ]; } //#endregion exports.useUncontrolledDates = useUncontrolledDates; //# sourceMappingURL=use-uncontrolled-dates.cjs.map