@snack-uikit/calendar 0.5.0 → 0.6.0
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 +5 -5
- 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/CalendarBase/CalendarBase.d.ts +1 -2
- package/dist/helperComponents/CalendarBase/CalendarBase.js +6 -6
- 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 +14 -14
- 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/ColumnLabels/ColumnLabels.js +2 -2
- package/dist/helperComponents/DecadeView/DecadeView.js +2 -2
- package/dist/helperComponents/DecadeView/utils.js +2 -2
- package/dist/helperComponents/Item/Item.js +2 -2
- 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 +3 -3
- 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.0 (2023-12-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 0.5.1 (2023-12-06)
|
|
18
|
+
|
|
19
|
+
### Only dependencies have been changed
|
|
20
|
+
* [@snack-uikit/utils@3.1.0](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/utils/CHANGELOG.md)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
# 0.5.0 (2023-12-06)
|
|
7
27
|
|
|
8
28
|
|
|
@@ -125,7 +145,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
125
145
|
|
|
126
146
|
## 0.3.4 (2023-10-06)
|
|
127
147
|
|
|
128
|
-
|
|
148
|
+
### Only dependencies have been changed
|
|
149
|
+
* [@snack-uikit/utils@3.2.0](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/utils/CHANGELOG.md)
|
|
129
150
|
|
|
130
151
|
|
|
131
152
|
|
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,11 +31,11 @@ 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` | - | Объект со стилями на контейнер. |
|
|
@@ -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';
|
|
@@ -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;
|
|
@@ -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
34
|
return (_jsxs("div", Object.assign({ className: styles.wrapper }, { children: [_jsx(Button, { disabled: levelButtonDisabled, onClick: () => {
|
|
35
|
-
if (viewMode ===
|
|
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
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
|
}
|
|
@@ -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,7 +9,7 @@ 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 ===
|
|
12
|
+
if (viewMode === VIEW_MODE.Month) {
|
|
13
13
|
return (_jsx("div", Object.assign({ className: cn(styles.row, className), "data-size": size }, { children: labels.map(label => (_jsx(ColumnLabel, { label: label }, label))) })));
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
@@ -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++) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { useContext, useLayoutEffect, useRef } from 'react';
|
|
4
|
-
import { AUTOFOCUS,
|
|
4
|
+
import { AUTOFOCUS, IN_RANGE_POSITION } from '../../constants';
|
|
5
5
|
import { CalendarContext } from '../CalendarContext';
|
|
6
6
|
import { useKeyboardFocus } from './hooks';
|
|
7
7
|
import styles from './styles.module.css';
|
|
@@ -32,7 +32,7 @@ export function Item({ data, className }) {
|
|
|
32
32
|
'data-is-disabled': isDisabled || undefined,
|
|
33
33
|
'data-size': size,
|
|
34
34
|
};
|
|
35
|
-
const isInRange = inRangePosition !==
|
|
35
|
+
const isInRange = inRangePosition !== IN_RANGE_POSITION.Out;
|
|
36
36
|
date.toLocaleString(locale, { weekday: 'short' });
|
|
37
37
|
const handleSelect = (date) => {
|
|
38
38
|
if (!isDisabled && onSelect) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { CALENDAR_MODE } from '../../constants';
|
|
4
4
|
import { useGrid } from '../../hooks';
|
|
5
5
|
import { getDateLabel, isTheSameDate, isTheSameMonth } from '../../utils';
|
|
6
6
|
import { CalendarContext } from '../CalendarContext';
|
|
@@ -14,7 +14,7 @@ export function MonthView() {
|
|
|
14
14
|
isInPeriod: isTheSameMonth,
|
|
15
15
|
getItemLabel: getDateLabel,
|
|
16
16
|
onSelect(date) {
|
|
17
|
-
if (mode ===
|
|
17
|
+
if (mode === CALENDAR_MODE.Range) {
|
|
18
18
|
preselectedRange ? completePreselect(date) : startPreselect(date);
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GRID_SIZE,
|
|
1
|
+
import { GRID_SIZE, VIEW_MODE } from '../../constants';
|
|
2
2
|
import { getStartOfWeek } from '../../utils';
|
|
3
3
|
import { WEEK_STARTS_WITH_MONDAY, WEEK_STARTS_WITH_SUNDAY } from './constants';
|
|
4
4
|
export const buildMonthGrid = (date, locale) => {
|
|
@@ -6,7 +6,7 @@ export const buildMonthGrid = (date, locale) => {
|
|
|
6
6
|
const WEEK = getStartOfWeek(locale) === 0 ? WEEK_STARTS_WITH_SUNDAY : WEEK_STARTS_WITH_MONDAY;
|
|
7
7
|
const startGap = WEEK.indexOf(date.getDay());
|
|
8
8
|
let currentDate = new Date(date.getFullYear(), date.getMonth(), 1 - startGap);
|
|
9
|
-
const { rows } = GRID_SIZE[
|
|
9
|
+
const { rows } = GRID_SIZE[VIEW_MODE.Month];
|
|
10
10
|
for (let i = 0; i < rows; i++) {
|
|
11
11
|
const week = [];
|
|
12
12
|
for (let j = 0; j < WEEK.length; j++) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import { AUTOFOCUS,
|
|
3
|
+
import { AUTOFOCUS, VIEW_MODE } from '../../constants';
|
|
4
4
|
import { useGrid } from '../../hooks';
|
|
5
5
|
import { getMonthName, getMonthShift, isTheSameMonth, isTheSameYear } from '../../utils';
|
|
6
6
|
import { CalendarContext } from '../CalendarContext';
|
|
@@ -16,7 +16,7 @@ export function YearView() {
|
|
|
16
16
|
onSelect(date) {
|
|
17
17
|
setFocus(AUTOFOCUS);
|
|
18
18
|
setViewShift(getMonthShift(referenceDate, date));
|
|
19
|
-
setViewMode(
|
|
19
|
+
setViewMode(VIEW_MODE.Month);
|
|
20
20
|
},
|
|
21
21
|
onPreselect(date) {
|
|
22
22
|
if (preselectedRange) {
|