@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
31 lines (30 loc) • 1.64 kB
JavaScript
"use client";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import "core-js/modules/web.dom-collections.iterator.js";
import { useCallback, useRef } from 'react';
export default function usePartialDates() {
const partialDatesRef = useRef({
partialStartDate: null,
partialEndDate: null
});
const setPartialDates = useCallback(partialDates => {
const nonPartialDates = Object.entries(partialDates).reduce((dates, _ref) => {
let [dateKey, dateValue] = _ref;
if (isFullyFilledOut(dateValue)) {
dates[dateKey] = null;
}
return dates;
}, {});
partialDatesRef.current = _objectSpread(_objectSpread(_objectSpread({}, partialDatesRef.current), partialDates), nonPartialDates);
}, []);
return {
partialDatesRef,
setPartialDates
};
}
function isFullyFilledOut(date) {
return /^\d{4}-\d{2}-\d{2}$/.test(date);
}
//# sourceMappingURL=usePartialDates.js.map