@snack-uikit/calendar 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/README.md +6 -6
- package/dist/components/Calendar/Calendar.d.ts +10 -15
- package/dist/components/Calendar/Calendar.js +2 -5
- package/dist/components/Calendar/utils.js +3 -3
- package/dist/constants.d.ts +21 -21
- package/dist/constants.js +24 -28
- package/dist/helperComponents/Button/Button.js +1 -1
- package/dist/helperComponents/CalendarBase/CalendarBase.d.ts +1 -2
- package/dist/helperComponents/CalendarBase/CalendarBase.js +8 -8
- package/dist/helperComponents/CalendarBase/hooks.d.ts +1 -1
- package/dist/helperComponents/CalendarBase/hooks.js +4 -4
- package/dist/helperComponents/CalendarBody/CalendarBody.js +4 -4
- package/dist/helperComponents/CalendarContext/CalendarContext.d.ts +1 -2
- package/dist/helperComponents/CalendarContext/CalendarContext.js +4 -4
- package/dist/helperComponents/CalendarNavigation/CalendarNavigation.js +16 -16
- package/dist/helperComponents/CalendarNavigation/hooks.js +4 -4
- package/dist/helperComponents/CalendarNavigation/utils.d.ts +1 -1
- package/dist/helperComponents/CalendarNavigation/utils.js +4 -4
- package/dist/helperComponents/ColumnLabel/ColumnLabel.js +1 -1
- package/dist/helperComponents/ColumnLabels/ColumnLabels.js +3 -3
- package/dist/helperComponents/DecadeView/DecadeView.js +2 -2
- package/dist/helperComponents/DecadeView/utils.js +2 -2
- package/dist/helperComponents/Grid/Grid.js +1 -1
- package/dist/helperComponents/Item/Item.js +3 -3
- package/dist/helperComponents/MonthView/MonthView.js +2 -2
- package/dist/helperComponents/MonthView/utils.js +2 -2
- package/dist/helperComponents/YearView/YearView.js +2 -2
- package/dist/helperComponents/YearView/utils.js +2 -2
- package/dist/types.d.ts +6 -1
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +9 -9
- package/package.json +4 -4
- package/src/components/Calendar/Calendar.tsx +11 -15
- package/src/components/Calendar/utils.ts +3 -3
- package/src/constants.ts +24 -24
- package/src/helperComponents/CalendarBase/CalendarBase.tsx +7 -7
- package/src/helperComponents/CalendarBase/hooks.ts +5 -4
- package/src/helperComponents/CalendarBody/CalendarBody.tsx +4 -4
- package/src/helperComponents/CalendarContext/CalendarContext.tsx +5 -5
- package/src/helperComponents/CalendarNavigation/CalendarNavigation.tsx +14 -14
- package/src/helperComponents/CalendarNavigation/hooks.ts +4 -4
- package/src/helperComponents/CalendarNavigation/utils.ts +5 -4
- package/src/helperComponents/ColumnLabels/ColumnLabels.tsx +2 -2
- package/src/helperComponents/DecadeView/DecadeView.tsx +2 -2
- package/src/helperComponents/DecadeView/utils.ts +2 -2
- package/src/helperComponents/Item/Item.tsx +2 -2
- package/src/helperComponents/MonthView/MonthView.tsx +2 -2
- package/src/helperComponents/MonthView/utils.ts +2 -2
- package/src/helperComponents/YearView/YearView.tsx +2 -2
- package/src/helperComponents/YearView/utils.ts +2 -2
- package/src/types.ts +11 -1
- package/src/utils.ts +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.6.1 (2023-12-14)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/icons@0.19.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/icons/CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# 0.6.0 (2023-12-14)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
* **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## 0.5.1 (2023-12-06)
|
|
7
27
|
|
|
8
28
|
### Only dependencies have been changed
|
|
@@ -134,7 +154,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
134
154
|
|
|
135
155
|
## 0.3.4 (2023-10-06)
|
|
136
156
|
|
|
137
|
-
|
|
157
|
+
### Only dependencies have been changed
|
|
158
|
+
* [@snack-uikit/utils@3.2.0](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/utils/CHANGELOG.md)
|
|
138
159
|
|
|
139
160
|
|
|
140
161
|
|
package/README.md
CHANGED
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
import { Calendar } from '@snack-uikit/calendar';
|
|
12
12
|
|
|
13
13
|
<Calendar
|
|
14
|
-
mode=
|
|
14
|
+
mode='date'
|
|
15
15
|
onChangeValue={(selectedDate: Date) => {
|
|
16
16
|
// do something
|
|
17
17
|
}}
|
|
18
18
|
/>
|
|
19
19
|
|
|
20
20
|
<Calendar
|
|
21
|
-
mode=
|
|
21
|
+
mode='range'
|
|
22
22
|
onChangeValue={(selectedRange: [Date, Date]) => {
|
|
23
23
|
// do something
|
|
24
24
|
}}
|
|
@@ -31,18 +31,18 @@ import { Calendar } from '@snack-uikit/calendar';
|
|
|
31
31
|
### Props
|
|
32
32
|
| name | type | default value | description |
|
|
33
33
|
|------|------|---------------|-------------|
|
|
34
|
-
| mode* |
|
|
35
|
-
| size | enum Size: `"s"`, `"m"`, `"l"` |
|
|
34
|
+
| mode* | "date" \| "range" | - | Режим работы календаря: <br> - `date` - режим выбора даты <br> - `range` - режим выбора периода |
|
|
35
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер |
|
|
36
36
|
| today | `number \| Date` | - | Дата сегодняшнего дня |
|
|
37
37
|
| showHolidays | `boolean` | - | Раскрашивает субботу и воскресенье |
|
|
38
|
-
| buildCellProps | `(date: Date, viewMode: ViewMode) => { isDisabled?: boolean; isHoliday?: boolean };` | - | Колбек установки свойств ячейка календаря. Вызывается на построение каждой ячейки. Принимает два параметра: <br> `Date` - дата ячейки <br> `ViewMode`: <br> - `
|
|
38
|
+
| buildCellProps | `(date: Date, viewMode: ViewMode) => { isDisabled?: boolean; isHoliday?: boolean };` | - | Колбек установки свойств ячейка календаря. Вызывается на построение каждой ячейки. Принимает два параметра: <br> `Date` - дата ячейки <br> `ViewMode`: <br> - `month` отображение месяца, каждая ячейка - 1 день <br> - `year` отображение года, каждая ячейка - 1 месяц <br> - `decade` отображение декады, каждая ячейка - 1 год <br><br> Колбек должен возвращать объект с полями, отвечающими за задизаленность и подкраску ячейки. |
|
|
39
39
|
| className | `string` | - | CSS-класс контейнера |
|
|
40
40
|
| fitToContainer | `boolean` | true | Отключает предустановленный размер, заставляя компонент подстраиваться к размеру контейнра: (width: 100%, height: 100%). |
|
|
41
41
|
| style | `CSSProperties` | - | Объект со стилями на контейнер. |
|
|
42
42
|
| autofocus | `boolean` | - | Автофокус |
|
|
43
43
|
| locale | `Intl.Locale` | Проставляется в соответствие с языком в настройках браузера | Локаль, в соответствие с которой выставляется язык названий и первый день недели |
|
|
44
44
|
| onFocusLeave | `(direction: FocusDirection) => void` | - | Колбек потери фокуса. Вызывается со значением `next`, когда фокус покидает компонент, передвигаясь вперед, по клавише `tab`. Со значением `prev` - по клавише стрелки вверх или `shift + tab`. |
|
|
45
|
-
| navigationStartRef | `
|
|
45
|
+
| navigationStartRef | `RefCallback<HTMLButtonElement>` | - | Ref-callback на первый доступный интерактивный элемент |
|
|
46
46
|
| value | `Date \| Range` | - | Выбранное значение.<br> - в режиме date тип `Date` <br> - в режиме range тип `Range` (`[Date, Date]`) |
|
|
47
47
|
| defaultValue | `Date \| Range` | - | Значение по-умолчанию для uncontrolled.<br> - в режиме date тип `Date` <br> - в режиме range тип `Range` (`[Date, Date]`) |
|
|
48
48
|
| onChangeValue | `((value: Date) => void) \| ((value: Range) => void)` | - | Колбек выбора значения.<br> - в режиме date принимает тип `Date` <br> - в режиме range принимает тип `Range` |
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CSSProperties, RefCallback } from 'react';
|
|
2
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
-
import {
|
|
4
|
-
import { BuildCellPropsFunction, FocusDirection, Range } from '../../types';
|
|
3
|
+
import { CALENDAR_MODE } from '../../constants';
|
|
4
|
+
import { BuildCellPropsFunction, FocusDirection, Range, Size } from '../../types';
|
|
5
5
|
type CommonCalendarProps = {
|
|
6
6
|
/**
|
|
7
7
|
* Размер
|
|
8
|
-
* @default
|
|
8
|
+
* @default m
|
|
9
9
|
*/
|
|
10
10
|
size?: Size;
|
|
11
11
|
/** Дата сегодняшнего дня */
|
|
@@ -16,9 +16,9 @@ type CommonCalendarProps = {
|
|
|
16
16
|
* Колбек установки свойств ячейка календаря. Вызывается на построение каждой ячейки. Принимает два параметра:
|
|
17
17
|
* <br> `Date` - дата ячейки
|
|
18
18
|
* <br> `ViewMode`:
|
|
19
|
-
* <br> - `
|
|
20
|
-
* <br> - `
|
|
21
|
-
* <br> - `
|
|
19
|
+
* <br> - `month` отображение месяца, каждая ячейка - 1 день
|
|
20
|
+
* <br> - `year` отображение года, каждая ячейка - 1 месяц
|
|
21
|
+
* <br> - `decade` отображение декады, каждая ячейка - 1 год
|
|
22
22
|
* <br><br> Колбек должен возвращать объект с полями, отвечающими за задизаленность и подкраску ячейки.
|
|
23
23
|
* @type (date: Date, viewMode: ViewMode) => { isDisabled?: boolean; isHoliday?: boolean };
|
|
24
24
|
*/
|
|
@@ -46,8 +46,8 @@ type CommonCalendarProps = {
|
|
|
46
46
|
navigationStartRef?: RefCallback<HTMLButtonElement>;
|
|
47
47
|
};
|
|
48
48
|
type DateCalendarProps = CommonCalendarProps & {
|
|
49
|
-
/** Режим работы календаря: <br> - `
|
|
50
|
-
mode:
|
|
49
|
+
/** Режим работы календаря: <br> - `date` - режим выбора даты */
|
|
50
|
+
mode: typeof CALENDAR_MODE.Date;
|
|
51
51
|
/** Выбранное значение.<br> - в режиме date тип `Date` */
|
|
52
52
|
value?: Date;
|
|
53
53
|
/** Значение по-умолчанию для uncontrolled.<br> - в режиме date тип `Date` */
|
|
@@ -56,8 +56,8 @@ type DateCalendarProps = CommonCalendarProps & {
|
|
|
56
56
|
onChangeValue?(value: Date): void;
|
|
57
57
|
};
|
|
58
58
|
type RangeCalendarProps = CommonCalendarProps & {
|
|
59
|
-
/** <br> - `
|
|
60
|
-
mode:
|
|
59
|
+
/** <br> - `range` - режим выбора периода */
|
|
60
|
+
mode: typeof CALENDAR_MODE.Range;
|
|
61
61
|
/** <br> - в режиме range тип `Range` (`[Date, Date]`) */
|
|
62
62
|
value?: Range;
|
|
63
63
|
/** <br> - в режиме range тип `Range` (`[Date, Date]`) */
|
|
@@ -67,9 +67,4 @@ type RangeCalendarProps = CommonCalendarProps & {
|
|
|
67
67
|
};
|
|
68
68
|
export type CalendarProps = WithSupportProps<DateCalendarProps | RangeCalendarProps>;
|
|
69
69
|
export declare function Calendar(props: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
70
|
-
export declare namespace Calendar {
|
|
71
|
-
var sizes: typeof Size;
|
|
72
|
-
var modes: typeof CalendarMode;
|
|
73
|
-
var viewMode: typeof ViewMode;
|
|
74
|
-
}
|
|
75
70
|
export {};
|
|
@@ -11,13 +11,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { useCallback } from 'react';
|
|
14
|
-
import {
|
|
14
|
+
import { CALENDAR_MODE } from '../../constants';
|
|
15
15
|
import { CalendarBase } from '../../helperComponents/CalendarBase';
|
|
16
16
|
import { getNormalizedDefaultValue, getNormalizedValue } from './utils';
|
|
17
17
|
export function Calendar(props) {
|
|
18
18
|
const { className, onChangeValue, buildCellProps, mode } = props, rest = __rest(props, ["className", "onChangeValue", "buildCellProps", "mode"]);
|
|
19
19
|
const changeValueHandler = useCallback((value) => {
|
|
20
|
-
if (mode ===
|
|
20
|
+
if (mode === CALENDAR_MODE.Date) {
|
|
21
21
|
const [date] = value;
|
|
22
22
|
onChangeValue === null || onChangeValue === void 0 ? void 0 : onChangeValue(date);
|
|
23
23
|
return;
|
|
@@ -26,6 +26,3 @@ export function Calendar(props) {
|
|
|
26
26
|
}, [onChangeValue, mode]);
|
|
27
27
|
return (_jsx(CalendarBase, Object.assign({}, rest, { mode: mode, className: className, value: getNormalizedValue(props), defaultValue: getNormalizedDefaultValue(props), onChangeValue: changeValueHandler, buildCellProps: buildCellProps })));
|
|
28
28
|
}
|
|
29
|
-
Calendar.sizes = Size;
|
|
30
|
-
Calendar.modes = CalendarMode;
|
|
31
|
-
Calendar.viewMode = ViewMode;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CALENDAR_MODE } from '../../constants';
|
|
2
2
|
export const getNormalizedValue = ({ value, mode }) => {
|
|
3
3
|
if (!value)
|
|
4
4
|
return value;
|
|
5
|
-
if (mode ===
|
|
5
|
+
if (mode === CALENDAR_MODE.Date)
|
|
6
6
|
return [value, value];
|
|
7
7
|
return value;
|
|
8
8
|
};
|
|
9
9
|
export const getNormalizedDefaultValue = ({ defaultValue, mode }) => {
|
|
10
10
|
if (!defaultValue)
|
|
11
11
|
return defaultValue;
|
|
12
|
-
if (mode ===
|
|
12
|
+
if (mode === CALENDAR_MODE.Date)
|
|
13
13
|
return [defaultValue, defaultValue];
|
|
14
14
|
return defaultValue;
|
|
15
15
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
Month
|
|
3
|
-
Year
|
|
4
|
-
Decade
|
|
5
|
-
}
|
|
6
|
-
export declare
|
|
7
|
-
Date
|
|
8
|
-
Range
|
|
9
|
-
}
|
|
10
|
-
export declare
|
|
11
|
-
Out
|
|
12
|
-
Start
|
|
13
|
-
In
|
|
14
|
-
End
|
|
15
|
-
StartEnd
|
|
16
|
-
}
|
|
17
|
-
export declare
|
|
18
|
-
S
|
|
19
|
-
M
|
|
20
|
-
L
|
|
21
|
-
}
|
|
1
|
+
export declare const VIEW_MODE: {
|
|
2
|
+
readonly Month: "month";
|
|
3
|
+
readonly Year: "year";
|
|
4
|
+
readonly Decade: "decade";
|
|
5
|
+
};
|
|
6
|
+
export declare const CALENDAR_MODE: {
|
|
7
|
+
readonly Date: "date";
|
|
8
|
+
readonly Range: "range";
|
|
9
|
+
};
|
|
10
|
+
export declare const IN_RANGE_POSITION: {
|
|
11
|
+
readonly Out: "out";
|
|
12
|
+
readonly Start: "start";
|
|
13
|
+
readonly In: "in";
|
|
14
|
+
readonly End: "end";
|
|
15
|
+
readonly StartEnd: "start-end";
|
|
16
|
+
};
|
|
17
|
+
export declare const SIZE: {
|
|
18
|
+
readonly S: "s";
|
|
19
|
+
readonly M: "m";
|
|
20
|
+
readonly L: "l";
|
|
21
|
+
};
|
|
22
22
|
export declare const GRID_SIZE: {
|
|
23
23
|
readonly month: {
|
|
24
24
|
readonly rows: 6;
|
package/dist/constants.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Size["S"] = "s";
|
|
23
|
-
Size["M"] = "m";
|
|
24
|
-
Size["L"] = "l";
|
|
25
|
-
})(Size || (Size = {}));
|
|
1
|
+
export const VIEW_MODE = {
|
|
2
|
+
Month: 'month',
|
|
3
|
+
Year: 'year',
|
|
4
|
+
Decade: 'decade',
|
|
5
|
+
};
|
|
6
|
+
export const CALENDAR_MODE = {
|
|
7
|
+
Date: 'date',
|
|
8
|
+
Range: 'range',
|
|
9
|
+
};
|
|
10
|
+
export const IN_RANGE_POSITION = {
|
|
11
|
+
Out: 'out',
|
|
12
|
+
Start: 'start',
|
|
13
|
+
In: 'in',
|
|
14
|
+
End: 'end',
|
|
15
|
+
StartEnd: 'start-end',
|
|
16
|
+
};
|
|
17
|
+
export const SIZE = {
|
|
18
|
+
S: 's',
|
|
19
|
+
M: 'm',
|
|
20
|
+
L: 'l',
|
|
21
|
+
};
|
|
26
22
|
export const GRID_SIZE = {
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
23
|
+
[VIEW_MODE.Month]: { rows: 6, columns: 7 },
|
|
24
|
+
[VIEW_MODE.Year]: { rows: 4, columns: 3 },
|
|
25
|
+
[VIEW_MODE.Decade]: { rows: 4, columns: 3 },
|
|
30
26
|
};
|
|
31
27
|
export const AUTOFOCUS = 'autofocus';
|
|
@@ -52,5 +52,5 @@ export function Button(_a) {
|
|
|
52
52
|
useNavigationStartRef && (navigationStartRef === null || navigationStartRef === void 0 ? void 0 : navigationStartRef(buttonRef));
|
|
53
53
|
ref.current = buttonRef;
|
|
54
54
|
}
|
|
55
|
-
}, onKeyDown: onKeyDownHandler, onFocus: () => setFocus(focusName), onBlur: () => setFocus(undefined), disabled: disabled }, extractSupportProps(rest), { children: [label, _jsx("div",
|
|
55
|
+
}, onKeyDown: onKeyDownHandler, onFocus: () => setFocus(focusName), onBlur: () => setFocus(undefined), disabled: disabled }, extractSupportProps(rest), { children: [label, _jsx("div", { className: styles.icon, children: icon })] })));
|
|
56
56
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CSSProperties, RefCallback } from 'react';
|
|
2
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
-
import { CalendarMode, Size } from '../../
|
|
4
|
-
import { BuildCellPropsFunction, FocusDirection, Range } from '../../types';
|
|
3
|
+
import { BuildCellPropsFunction, CalendarMode, FocusDirection, Range, Size } from '../../types';
|
|
5
4
|
export type CalendarBaseProps = WithSupportProps<{
|
|
6
5
|
mode: CalendarMode;
|
|
7
6
|
onChangeValue(value: Range): void;
|
|
@@ -14,7 +14,7 @@ import cn from 'classnames';
|
|
|
14
14
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
15
15
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
16
16
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
17
|
-
import { AUTOFOCUS,
|
|
17
|
+
import { AUTOFOCUS, SIZE, VIEW_MODE } from '../../constants';
|
|
18
18
|
import { getEndOfTheDay, getLocale, getTestIdBuilder, sortDates } from '../../utils';
|
|
19
19
|
import { CalendarBody } from '../CalendarBody';
|
|
20
20
|
import { CalendarContext } from '../CalendarContext';
|
|
@@ -23,13 +23,13 @@ import { ColumnLabels } from '../ColumnLabels';
|
|
|
23
23
|
import { useViewDate } from './hooks';
|
|
24
24
|
import styles from './styles.module.css';
|
|
25
25
|
const CONTAINER_SIZE_MAP = {
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
26
|
+
[SIZE.S]: styles.calendarSizeS,
|
|
27
|
+
[SIZE.M]: styles.calendarSizeM,
|
|
28
|
+
[SIZE.L]: styles.calendarSizeL,
|
|
29
29
|
};
|
|
30
30
|
export function CalendarBase(_a) {
|
|
31
|
-
var { className, mode, size =
|
|
32
|
-
const [viewMode, setViewMode] = useState(
|
|
31
|
+
var { className, mode, size = SIZE.M, autofocus, fitToContainer = true, value: valueProp, defaultValue, onChangeValue, today: todayProp = new Date(), showHolidays = false, style, locale: localeProp, onFocusLeave, buildCellProps, 'data-test-id': testId, navigationStartRef } = _a, rest = __rest(_a, ["className", "mode", "size", "autofocus", "fitToContainer", "value", "defaultValue", "onChangeValue", "today", "showHolidays", "style", "locale", "onFocusLeave", "buildCellProps", 'data-test-id', "navigationStartRef"]);
|
|
32
|
+
const [viewMode, setViewMode] = useState(VIEW_MODE.Month);
|
|
33
33
|
const [viewShift, setViewShift] = useState(0);
|
|
34
34
|
const [value, setValueState] = useUncontrolledProp(valueProp, defaultValue, onChangeValue);
|
|
35
35
|
const today = typeof todayProp === 'number' ? new Date(todayProp) : todayProp;
|
|
@@ -59,7 +59,7 @@ export function CalendarBase(_a) {
|
|
|
59
59
|
const getTestId = useMemo(() => getTestIdBuilder(testId), [testId]);
|
|
60
60
|
const locale = useMemo(() => getLocale(localeProp), [localeProp]);
|
|
61
61
|
const firstNotDisableCell = useRef([0, 0]);
|
|
62
|
-
return (_jsx("div", Object.assign({}, extractSupportProps(rest), { className: cn(styles.calendar, className, CONTAINER_SIZE_MAP[size]), style: style, "data-size": size, "data-fit-to-container": fitToContainer || undefined, "data-test-id": testId
|
|
62
|
+
return (_jsx("div", Object.assign({}, extractSupportProps(rest), { className: cn(styles.calendar, className, CONTAINER_SIZE_MAP[size]), style: style, "data-size": size, "data-fit-to-container": fitToContainer || undefined, "data-test-id": testId, children: _jsxs(CalendarContext.Provider, { value: {
|
|
63
63
|
locale,
|
|
64
64
|
size,
|
|
65
65
|
value,
|
|
@@ -85,5 +85,5 @@ export function CalendarBase(_a) {
|
|
|
85
85
|
onFocusLeave,
|
|
86
86
|
buildCellProps,
|
|
87
87
|
navigationStartRef,
|
|
88
|
-
}
|
|
88
|
+
}, children: [_jsxs("div", { className: styles.header, "data-size": size, children: [_jsx(CalendarNavigation, {}), _jsx(ColumnLabels, {})] }), _jsx("div", { className: styles.body, children: _jsx("div", { className: styles.rows, "data-size": size, children: _jsx(CalendarBody, {}) }) })] }) })));
|
|
89
89
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ViewMode } from '../../
|
|
1
|
+
import { ViewMode } from '../../types';
|
|
2
2
|
export declare function useViewDate(referenceDate: Date, viewMode: ViewMode, viewShift: number): Date;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VIEW_MODE } from '../../constants';
|
|
2
2
|
export function useViewDate(referenceDate, viewMode, viewShift) {
|
|
3
3
|
switch (viewMode) {
|
|
4
|
-
case
|
|
4
|
+
case VIEW_MODE.Decade:
|
|
5
5
|
const decadeFirstYear = Math.floor(referenceDate.getFullYear() / 10) * 10;
|
|
6
6
|
return new Date(decadeFirstYear + viewShift * 10, 1, 1);
|
|
7
|
-
case
|
|
7
|
+
case VIEW_MODE.Year:
|
|
8
8
|
return new Date(referenceDate.getFullYear() + viewShift, 1, 1);
|
|
9
|
-
case
|
|
9
|
+
case VIEW_MODE.Month:
|
|
10
10
|
default:
|
|
11
11
|
return new Date(referenceDate.getFullYear(), referenceDate.getMonth() + viewShift, 1);
|
|
12
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { VIEW_MODE } from '../../constants';
|
|
4
4
|
import { CalendarContext } from '../CalendarContext';
|
|
5
5
|
import { DecadeView } from '../DecadeView';
|
|
6
6
|
import { MonthView } from '../MonthView';
|
|
@@ -8,11 +8,11 @@ import { YearView } from '../YearView';
|
|
|
8
8
|
export function CalendarBody() {
|
|
9
9
|
const { viewMode } = useContext(CalendarContext);
|
|
10
10
|
switch (viewMode) {
|
|
11
|
-
case
|
|
11
|
+
case VIEW_MODE.Decade:
|
|
12
12
|
return _jsx(DecadeView, {});
|
|
13
|
-
case
|
|
13
|
+
case VIEW_MODE.Year:
|
|
14
14
|
return _jsx(YearView, {});
|
|
15
|
-
case
|
|
15
|
+
case VIEW_MODE.Month:
|
|
16
16
|
default:
|
|
17
17
|
return _jsx(MonthView, {});
|
|
18
18
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MutableRefObject, RefCallback } from 'react';
|
|
2
|
-
import { CalendarMode, Size, ViewMode } from '../../
|
|
3
|
-
import { BuildCellPropsFunction, FocusDirection, Range } from '../../types';
|
|
2
|
+
import { BuildCellPropsFunction, CalendarMode, FocusDirection, Range, Size, ViewMode } from '../../types';
|
|
4
3
|
export type CalendarContextType = {
|
|
5
4
|
size: Size;
|
|
6
5
|
/** Дата текущего дня */
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { CALENDAR_MODE, SIZE, VIEW_MODE } from '../../constants';
|
|
3
3
|
import { getLocale } from '../../utils';
|
|
4
4
|
const stub = () => {
|
|
5
5
|
/* it is a stub */
|
|
6
6
|
};
|
|
7
7
|
export const CalendarContext = createContext({
|
|
8
8
|
locale: getLocale(),
|
|
9
|
-
size:
|
|
9
|
+
size: SIZE.M,
|
|
10
10
|
today: new Date(),
|
|
11
11
|
viewDate: new Date(),
|
|
12
12
|
referenceDate: new Date(),
|
|
13
|
-
mode:
|
|
14
|
-
viewMode:
|
|
13
|
+
mode: CALENDAR_MODE.Date,
|
|
14
|
+
viewMode: VIEW_MODE.Month,
|
|
15
15
|
viewShift: 0,
|
|
16
16
|
setFocus: stub,
|
|
17
17
|
setValue: stub,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
|
|
4
|
-
import { GRID_SIZE,
|
|
4
|
+
import { GRID_SIZE, SIZE, VIEW_MODE } from '../../constants';
|
|
5
5
|
import { Button } from '../Button';
|
|
6
6
|
import { CalendarContext } from '../CalendarContext';
|
|
7
7
|
import { stringifyAddress } from '../Item/utils';
|
|
@@ -10,37 +10,37 @@ import { usePeriodName } from './hooks';
|
|
|
10
10
|
import styles from './styles.module.css';
|
|
11
11
|
import { getShift } from './utils';
|
|
12
12
|
const VIEW_MODE_MAP = {
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
13
|
+
[VIEW_MODE.Month]: VIEW_MODE.Year,
|
|
14
|
+
[VIEW_MODE.Year]: VIEW_MODE.Decade,
|
|
15
|
+
[VIEW_MODE.Decade]: VIEW_MODE.Decade,
|
|
16
16
|
};
|
|
17
17
|
const ICONS = {
|
|
18
18
|
UP: {
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
19
|
+
[SIZE.S]: _jsx(ChevronUpSVG, { size: 16 }),
|
|
20
|
+
[SIZE.M]: _jsx(ChevronUpSVG, {}),
|
|
21
|
+
[SIZE.L]: _jsx(ChevronUpSVG, {}),
|
|
22
22
|
},
|
|
23
23
|
DOWN: {
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
24
|
+
[SIZE.S]: _jsx(ChevronDownSVG, { size: 16 }),
|
|
25
|
+
[SIZE.M]: _jsx(ChevronDownSVG, {}),
|
|
26
|
+
[SIZE.L]: _jsx(ChevronDownSVG, {}),
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
export function CalendarNavigation() {
|
|
30
30
|
const { referenceDate, viewDate, viewShift, setViewShift, viewMode, setViewMode, focus, setFocus, getTestId, size, firstNotDisableCell, } = useContext(CalendarContext);
|
|
31
31
|
const periodName = usePeriodName();
|
|
32
|
-
const levelButtonDisabled = viewMode ===
|
|
32
|
+
const levelButtonDisabled = viewMode === VIEW_MODE.Decade;
|
|
33
33
|
const isArrowButtonFocused = focus && [NEXT_PERIOD_BUTTON_FOCUS_NAME, PREV_PERIOD_BUTTON_FOCUS_NAME].includes(focus);
|
|
34
|
-
return (_jsxs("div",
|
|
35
|
-
if (viewMode ===
|
|
34
|
+
return (_jsxs("div", { className: styles.wrapper, children: [_jsx(Button, { disabled: levelButtonDisabled, onClick: () => {
|
|
35
|
+
if (viewMode === VIEW_MODE.Year) {
|
|
36
36
|
setFocus(PREV_PERIOD_BUTTON_FOCUS_NAME);
|
|
37
37
|
}
|
|
38
38
|
setViewShift(getShift(referenceDate, viewDate, viewMode));
|
|
39
39
|
setViewMode(VIEW_MODE_MAP[viewMode]);
|
|
40
|
-
}, label: periodName, "data-test-id": getTestId('period-level'), focusName: LEVEL_BUTTON_FOCUS_NAME, tabIndex: isArrowButtonFocused ? -1 : 0, icon: viewMode !==
|
|
40
|
+
}, label: periodName, "data-test-id": getTestId('period-level'), focusName: LEVEL_BUTTON_FOCUS_NAME, tabIndex: isArrowButtonFocused ? -1 : 0, icon: viewMode !== VIEW_MODE.Decade ? ICONS.DOWN[size] : undefined, onRightArrowKeyDown: () => setFocus(PREV_PERIOD_BUTTON_FOCUS_NAME), onDownArrowKeyDown: () => { var _a; return setFocus(stringifyAddress((_a = firstNotDisableCell === null || firstNotDisableCell === void 0 ? void 0 : firstNotDisableCell.current) !== null && _a !== void 0 ? _a : [0, 0])); }, useNavigationStartRef: true }), _jsxs("div", { children: [_jsx(Button, { onClick: () => setViewShift(viewShift - 1), "data-test-id": getTestId('period-prev'), focusName: PREV_PERIOD_BUTTON_FOCUS_NAME, tabIndex: focus === PREV_PERIOD_BUTTON_FOCUS_NAME || (levelButtonDisabled && focus !== NEXT_PERIOD_BUTTON_FOCUS_NAME)
|
|
41
41
|
? 0
|
|
42
42
|
: -1, icon: ICONS.UP[size], onRightArrowKeyDown: () => setFocus(NEXT_PERIOD_BUTTON_FOCUS_NAME), onLeftArrowKeyDown: () => setFocus(LEVEL_BUTTON_FOCUS_NAME), onDownArrowKeyDown: () => {
|
|
43
|
-
const rightGap = viewMode ===
|
|
43
|
+
const rightGap = viewMode === VIEW_MODE.Month ? 2 : 1;
|
|
44
44
|
setFocus(stringifyAddress([0, GRID_SIZE[viewMode].columns - rightGap]));
|
|
45
|
-
} }), _jsx(Button, { onClick: () => setViewShift(viewShift + 1), "data-test-id": getTestId('period-next'), focusName: NEXT_PERIOD_BUTTON_FOCUS_NAME, tabIndex: focus === NEXT_PERIOD_BUTTON_FOCUS_NAME ? 0 : -1, icon: ICONS.DOWN[size], onLeftArrowKeyDown: () => setFocus(PREV_PERIOD_BUTTON_FOCUS_NAME), onDownArrowKeyDown: () => setFocus(stringifyAddress([0, GRID_SIZE[viewMode].columns - 1])) })] })] }))
|
|
45
|
+
} }), _jsx(Button, { onClick: () => setViewShift(viewShift + 1), "data-test-id": getTestId('period-next'), focusName: NEXT_PERIOD_BUTTON_FOCUS_NAME, tabIndex: focus === NEXT_PERIOD_BUTTON_FOCUS_NAME ? 0 : -1, icon: ICONS.DOWN[size], onLeftArrowKeyDown: () => setFocus(PREV_PERIOD_BUTTON_FOCUS_NAME), onDownArrowKeyDown: () => setFocus(stringifyAddress([0, GRID_SIZE[viewMode].columns - 1])) })] })] }));
|
|
46
46
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { VIEW_MODE } from '../../constants';
|
|
3
3
|
import { getMonthName } from '../../utils';
|
|
4
4
|
import { CalendarContext } from '../CalendarContext';
|
|
5
5
|
export function usePeriodName() {
|
|
6
6
|
const { viewDate, viewMode, locale } = useContext(CalendarContext);
|
|
7
7
|
switch (viewMode) {
|
|
8
|
-
case
|
|
8
|
+
case VIEW_MODE.Month:
|
|
9
9
|
const year = viewDate.getFullYear();
|
|
10
10
|
return `${getMonthName(viewDate, locale)} ${year}`;
|
|
11
|
-
case
|
|
11
|
+
case VIEW_MODE.Year:
|
|
12
12
|
return viewDate.getFullYear().toString();
|
|
13
|
-
case
|
|
13
|
+
case VIEW_MODE.Decade:
|
|
14
14
|
const decadeStart = viewDate.getFullYear();
|
|
15
15
|
return `${decadeStart}-${decadeStart + 9}`;
|
|
16
16
|
default:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ViewMode } from '../../
|
|
1
|
+
import { ViewMode } from '../../types';
|
|
2
2
|
export declare const getShift: (referenceDate: Date, viewDate: Date, currentViewLevel: ViewMode) => number;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VIEW_MODE } from '../../constants';
|
|
2
2
|
import { getDecadeShift, getYearShift } from '../../utils';
|
|
3
3
|
export const getShift = (referenceDate, viewDate, currentViewLevel) => {
|
|
4
4
|
switch (currentViewLevel) {
|
|
5
|
-
case
|
|
5
|
+
case VIEW_MODE.Month:
|
|
6
6
|
return getYearShift(referenceDate, viewDate);
|
|
7
|
-
case
|
|
7
|
+
case VIEW_MODE.Year:
|
|
8
8
|
return getDecadeShift(referenceDate, viewDate);
|
|
9
|
-
case
|
|
9
|
+
case VIEW_MODE.Decade:
|
|
10
10
|
default:
|
|
11
11
|
return 0;
|
|
12
12
|
}
|
|
@@ -5,5 +5,5 @@ import { CalendarContext } from '../CalendarContext';
|
|
|
5
5
|
import styles from './styles.module.css';
|
|
6
6
|
export function ColumnLabel({ label, className }) {
|
|
7
7
|
const { size, getTestId } = useContext(CalendarContext);
|
|
8
|
-
return (_jsx("div",
|
|
8
|
+
return (_jsx("div", { className: cn(styles.wrapper, className), "data-test-id": getTestId('header-item'), "data-size": size, children: label }));
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { useContext, useMemo } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { VIEW_MODE } from '../../constants';
|
|
5
5
|
import { CalendarContext } from '../CalendarContext';
|
|
6
6
|
import { ColumnLabel } from '../ColumnLabel';
|
|
7
7
|
import styles from './styles.module.css';
|
|
@@ -9,8 +9,8 @@ import { getWeekLabels } from './utils';
|
|
|
9
9
|
export function ColumnLabels({ className }) {
|
|
10
10
|
const { viewMode, locale, size } = useContext(CalendarContext);
|
|
11
11
|
const labels = useMemo(() => getWeekLabels(locale), [locale]);
|
|
12
|
-
if (viewMode ===
|
|
13
|
-
return (_jsx("div",
|
|
12
|
+
if (viewMode === VIEW_MODE.Month) {
|
|
13
|
+
return (_jsx("div", { className: cn(styles.row, className), "data-size": size, children: labels.map(label => (_jsx(ColumnLabel, { label: label }, label))) }));
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { VIEW_MODE } from '../../constants';
|
|
4
4
|
import { useGrid } from '../../hooks';
|
|
5
5
|
import { getYearLabel, getYearShift, isTheSameDecade, isTheSameYear } from '../../utils';
|
|
6
6
|
import { CalendarContext } from '../CalendarContext';
|
|
@@ -15,7 +15,7 @@ export function DecadeView() {
|
|
|
15
15
|
getItemLabel: getYearLabel,
|
|
16
16
|
onSelect(date) {
|
|
17
17
|
setViewShift(getYearShift(referenceDate, date));
|
|
18
|
-
setViewMode(
|
|
18
|
+
setViewMode(VIEW_MODE.Year);
|
|
19
19
|
},
|
|
20
20
|
onPreselect(date) {
|
|
21
21
|
if (preselectedRange) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GRID_SIZE,
|
|
1
|
+
import { GRID_SIZE, VIEW_MODE } from '../../constants';
|
|
2
2
|
export const buildDecadeGrid = (date) => {
|
|
3
3
|
const result = [];
|
|
4
4
|
const year = date.getFullYear();
|
|
5
5
|
let shift = -1;
|
|
6
|
-
const { rows, columns } = GRID_SIZE[
|
|
6
|
+
const { rows, columns } = GRID_SIZE[VIEW_MODE.Decade];
|
|
7
7
|
for (let i = 0; i < rows; i++) {
|
|
8
8
|
const row = [];
|
|
9
9
|
for (let j = 0; j < columns; j++) {
|
|
@@ -2,5 +2,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Item } from '../Item';
|
|
3
3
|
import styles from './styles.module.css';
|
|
4
4
|
export function Grid({ grid }) {
|
|
5
|
-
return (_jsx("table",
|
|
5
|
+
return (_jsx("table", { className: styles.grid, border: 0, children: _jsx("tbody", { children: grid.map((row, index) => (_jsx("tr", { children: row.map((cell, index) => (_jsx("td", { children: _jsx(Item, { data: cell, className: styles.item }) }, `${cell.label}_${index}`))) }, index))) }) }));
|
|
6
6
|
}
|