1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.useFocus = useFocus;
|
4 | const react_1 = require("react");
|
5 | const calculateFocusTarget_js_1 = require("./helpers/calculateFocusTarget.js");
|
6 | const getNextFocus_js_1 = require("./helpers/getNextFocus.js");
|
7 |
|
8 | function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
|
9 | const { autoFocus } = props;
|
10 | const [lastFocused, setLastFocused] = (0, react_1.useState)();
|
11 | const focusTarget = (0, calculateFocusTarget_js_1.calculateFocusTarget)(calendar.days, getModifiers, isSelected || (() => false), lastFocused);
|
12 | const [focusedDay, setFocused] = (0, react_1.useState)(autoFocus ? focusTarget : undefined);
|
13 | const blur = () => {
|
14 | setLastFocused(focusedDay);
|
15 | setFocused(undefined);
|
16 | };
|
17 | const moveFocus = (moveBy, moveDir) => {
|
18 | if (!focusedDay)
|
19 | return;
|
20 | const nextFocus = (0, getNextFocus_js_1.getNextFocus)(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
|
21 | if (!nextFocus)
|
22 | return;
|
23 | calendar.goToDay(nextFocus);
|
24 | setFocused(nextFocus);
|
25 | };
|
26 | const isFocusTarget = (day) => {
|
27 | return Boolean(focusTarget?.isEqualTo(day));
|
28 | };
|
29 | const useFocus = {
|
30 | isFocusTarget,
|
31 | setFocused,
|
32 | focused: focusedDay,
|
33 | blur,
|
34 | moveFocus
|
35 | };
|
36 | return useFocus;
|
37 | }
|
38 |
|
\ | No newline at end of file |