UNPKG

@airplane/views

Version:

A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.

37 lines (36 loc) 1.25 kB
import { useReducer, useMemo } from "react"; import { useStateSetters } from "../input/useStateSetters.js"; import { ComponentType, useSyncComponentState } from "../../context/context.js"; import { reducer } from "./reducer.js"; const getUseDatePickerState = (componentType) => (id, options) => { var _a, _b; const initialState = { value: (_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.value, disabled: ((_b = options == null ? void 0 : options.initialState) == null ? void 0 : _b.disabled) ?? false }; const [internalState, dispatch] = useReducer(reducer, { ...initialState, showErrors: false, errors: [] }); const stateSetters = useStateSetters(dispatch, initialState); const state = useMemo(() => ({ ...internalState, ...stateSetters, id, componentType }), [internalState, stateSetters, id]); useSyncComponentState(id, state); return { state, dispatch }; }; const useDatePickerState = getUseDatePickerState(ComponentType.DatePicker); const useDateTimePickerState = getUseDatePickerState(ComponentType.DateTimePicker); export { getUseDatePickerState, useDatePickerState, useDateTimePickerState }; //# sourceMappingURL=useDatePickerState.js.map