UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2var __importStar = (this && this.__importStar) || function (mod) {
3 if (mod && mod.__esModule) return mod;
4 var result = {};
5 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6 result["default"] = mod;
7 return result;
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10var React = __importStar(require("react"));
11var utils_1 = require("../../_helpers/utils");
12function useViews(views, openTo, onChange) {
13 var _a = React.useState(openTo && utils_1.arrayIncludes(views, openTo) ? openTo : views[0]), openView = _a[0], setOpenView = _a[1];
14 var handleChangeAndOpenNext = React.useCallback(function (date, isFinish) {
15 var nextViewToOpen = views[views.indexOf(openView) + 1];
16 if (isFinish && nextViewToOpen) {
17 // do not close picker if needs to show next view
18 onChange(date, false);
19 setOpenView(nextViewToOpen);
20 return;
21 }
22 onChange(date, Boolean(isFinish));
23 }, [onChange, openView, views]);
24 return { handleChangeAndOpenNext: handleChangeAndOpenNext, openView: openView, setOpenView: setOpenView };
25}
26exports.useViews = useViews;