@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.
Files changed (50) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +5 -5
  3. package/dist/components/Calendar/Calendar.d.ts +10 -15
  4. package/dist/components/Calendar/Calendar.js +2 -5
  5. package/dist/components/Calendar/utils.js +3 -3
  6. package/dist/constants.d.ts +21 -21
  7. package/dist/constants.js +24 -28
  8. package/dist/helperComponents/CalendarBase/CalendarBase.d.ts +1 -2
  9. package/dist/helperComponents/CalendarBase/CalendarBase.js +6 -6
  10. package/dist/helperComponents/CalendarBase/hooks.d.ts +1 -1
  11. package/dist/helperComponents/CalendarBase/hooks.js +4 -4
  12. package/dist/helperComponents/CalendarBody/CalendarBody.js +4 -4
  13. package/dist/helperComponents/CalendarContext/CalendarContext.d.ts +1 -2
  14. package/dist/helperComponents/CalendarContext/CalendarContext.js +4 -4
  15. package/dist/helperComponents/CalendarNavigation/CalendarNavigation.js +14 -14
  16. package/dist/helperComponents/CalendarNavigation/hooks.js +4 -4
  17. package/dist/helperComponents/CalendarNavigation/utils.d.ts +1 -1
  18. package/dist/helperComponents/CalendarNavigation/utils.js +4 -4
  19. package/dist/helperComponents/ColumnLabels/ColumnLabels.js +2 -2
  20. package/dist/helperComponents/DecadeView/DecadeView.js +2 -2
  21. package/dist/helperComponents/DecadeView/utils.js +2 -2
  22. package/dist/helperComponents/Item/Item.js +2 -2
  23. package/dist/helperComponents/MonthView/MonthView.js +2 -2
  24. package/dist/helperComponents/MonthView/utils.js +2 -2
  25. package/dist/helperComponents/YearView/YearView.js +2 -2
  26. package/dist/helperComponents/YearView/utils.js +2 -2
  27. package/dist/types.d.ts +6 -1
  28. package/dist/utils.d.ts +1 -2
  29. package/dist/utils.js +9 -9
  30. package/package.json +3 -3
  31. package/src/components/Calendar/Calendar.tsx +11 -15
  32. package/src/components/Calendar/utils.ts +3 -3
  33. package/src/constants.ts +24 -24
  34. package/src/helperComponents/CalendarBase/CalendarBase.tsx +7 -7
  35. package/src/helperComponents/CalendarBase/hooks.ts +5 -4
  36. package/src/helperComponents/CalendarBody/CalendarBody.tsx +4 -4
  37. package/src/helperComponents/CalendarContext/CalendarContext.tsx +5 -5
  38. package/src/helperComponents/CalendarNavigation/CalendarNavigation.tsx +14 -14
  39. package/src/helperComponents/CalendarNavigation/hooks.ts +4 -4
  40. package/src/helperComponents/CalendarNavigation/utils.ts +5 -4
  41. package/src/helperComponents/ColumnLabels/ColumnLabels.tsx +2 -2
  42. package/src/helperComponents/DecadeView/DecadeView.tsx +2 -2
  43. package/src/helperComponents/DecadeView/utils.ts +2 -2
  44. package/src/helperComponents/Item/Item.tsx +2 -2
  45. package/src/helperComponents/MonthView/MonthView.tsx +2 -2
  46. package/src/helperComponents/MonthView/utils.ts +2 -2
  47. package/src/helperComponents/YearView/YearView.tsx +2 -2
  48. package/src/helperComponents/YearView/utils.ts +2 -2
  49. package/src/types.ts +11 -1
  50. 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
- **Note:** Version bump only for package @snack-uikit/calendar
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={Calendar.modes.Date}
14
+ mode='date'
15
15
  onChangeValue={(selectedDate: Date) => {
16
16
  // do something
17
17
  }}
18
18
  />
19
19
 
20
20
  <Calendar
21
- mode={Calendar.modes.Range}
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* | enum CalendarMode: `"date"`, `"range"` | - | Режим работы календаря: <br> - `Calendar.modes.Date` - режим выбора даты <br> - `Calendar.modes.Date` - режим выбора периода |
35
- | size | enum Size: `"s"`, `"m"`, `"l"` | Calendar.sizes.M | Размер |
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> - `Calendar.viewMode.Month` отображение месяца, каждая ячейка - 1 день <br> - `Calendar.viewMode.Year` отображение года, каждая ячейка - 1 месяц <br> - `Calendar.viewMode.Decade` отображение декады, каждая ячейка - 1 год <br><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 { CalendarMode, Size, ViewMode } from '../../constants';
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 Calendar.sizes.M
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> - `Calendar.viewMode.Month` отображение месяца, каждая ячейка - 1 день
20
- * <br> - `Calendar.viewMode.Year` отображение года, каждая ячейка - 1 месяц
21
- * <br> - `Calendar.viewMode.Decade` отображение декады, каждая ячейка - 1 год
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> - `Calendar.modes.Date` - режим выбора даты */
50
- mode: CalendarMode.Date;
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> - `Calendar.modes.Date` - режим выбора периода */
60
- mode: CalendarMode.Range;
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 { CalendarMode, Size, ViewMode } from '../../constants';
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 === CalendarMode.Date) {
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 { CalendarMode } from '../../constants';
1
+ import { CALENDAR_MODE } from '../../constants';
2
2
  export const getNormalizedValue = ({ value, mode }) => {
3
3
  if (!value)
4
4
  return value;
5
- if (mode === CalendarMode.Date)
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 === CalendarMode.Date)
12
+ if (mode === CALENDAR_MODE.Date)
13
13
  return [defaultValue, defaultValue];
14
14
  return defaultValue;
15
15
  };
@@ -1,24 +1,24 @@
1
- export declare enum ViewMode {
2
- Month = "month",
3
- Year = "year",
4
- Decade = "decade"
5
- }
6
- export declare enum CalendarMode {
7
- Date = "date",
8
- Range = "range"
9
- }
10
- export declare enum InRangePosition {
11
- Out = "out",
12
- Start = "start",
13
- In = "in",
14
- End = "end",
15
- StartEnd = "start-end"
16
- }
17
- export declare enum Size {
18
- S = "s",
19
- M = "m",
20
- L = "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 var ViewMode;
2
- (function (ViewMode) {
3
- ViewMode["Month"] = "month";
4
- ViewMode["Year"] = "year";
5
- ViewMode["Decade"] = "decade";
6
- })(ViewMode || (ViewMode = {}));
7
- export var CalendarMode;
8
- (function (CalendarMode) {
9
- CalendarMode["Date"] = "date";
10
- CalendarMode["Range"] = "range";
11
- })(CalendarMode || (CalendarMode = {}));
12
- export var InRangePosition;
13
- (function (InRangePosition) {
14
- InRangePosition["Out"] = "out";
15
- InRangePosition["Start"] = "start";
16
- InRangePosition["In"] = "in";
17
- InRangePosition["End"] = "end";
18
- InRangePosition["StartEnd"] = "start-end";
19
- })(InRangePosition || (InRangePosition = {}));
20
- export var Size;
21
- (function (Size) {
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
- [ViewMode.Month]: { rows: 6, columns: 7 },
28
- [ViewMode.Year]: { rows: 4, columns: 3 },
29
- [ViewMode.Decade]: { rows: 4, columns: 3 },
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 '../../constants';
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, Size, ViewMode } from '../../constants';
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
- [Size.S]: styles.calendarSizeS,
27
- [Size.M]: styles.calendarSizeM,
28
- [Size.L]: styles.calendarSizeL,
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 = 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(ViewMode.Month);
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 '../../constants';
1
+ import { ViewMode } from '../../types';
2
2
  export declare function useViewDate(referenceDate: Date, viewMode: ViewMode, viewShift: number): Date;
@@ -1,12 +1,12 @@
1
- import { ViewMode } from '../../constants';
1
+ import { VIEW_MODE } from '../../constants';
2
2
  export function useViewDate(referenceDate, viewMode, viewShift) {
3
3
  switch (viewMode) {
4
- case ViewMode.Decade:
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 ViewMode.Year:
7
+ case VIEW_MODE.Year:
8
8
  return new Date(referenceDate.getFullYear() + viewShift, 1, 1);
9
- case ViewMode.Month:
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 { ViewMode } from '../../constants';
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 ViewMode.Decade:
11
+ case VIEW_MODE.Decade:
12
12
  return _jsx(DecadeView, {});
13
- case ViewMode.Year:
13
+ case VIEW_MODE.Year:
14
14
  return _jsx(YearView, {});
15
- case ViewMode.Month:
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 '../../constants';
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 { CalendarMode, Size, ViewMode } from '../../constants';
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: Size.M,
9
+ size: SIZE.M,
10
10
  today: new Date(),
11
11
  viewDate: new Date(),
12
12
  referenceDate: new Date(),
13
- mode: CalendarMode.Date,
14
- viewMode: ViewMode.Month,
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, Size, ViewMode } from '../../constants';
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
- [ViewMode.Month]: ViewMode.Year,
14
- [ViewMode.Year]: ViewMode.Decade,
15
- [ViewMode.Decade]: ViewMode.Decade,
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
- [Size.S]: _jsx(ChevronUpSVG, { size: 16 }),
20
- [Size.M]: _jsx(ChevronUpSVG, {}),
21
- [Size.L]: _jsx(ChevronUpSVG, {}),
19
+ [SIZE.S]: _jsx(ChevronUpSVG, { size: 16 }),
20
+ [SIZE.M]: _jsx(ChevronUpSVG, {}),
21
+ [SIZE.L]: _jsx(ChevronUpSVG, {}),
22
22
  },
23
23
  DOWN: {
24
- [Size.S]: _jsx(ChevronDownSVG, { size: 16 }),
25
- [Size.M]: _jsx(ChevronDownSVG, {}),
26
- [Size.L]: _jsx(ChevronDownSVG, {}),
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 === ViewMode.Decade;
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 === ViewMode.Year) {
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 !== ViewMode.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)
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 === ViewMode.Month ? 2 : 1;
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 { ViewMode } from '../../constants';
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 ViewMode.Month:
8
+ case VIEW_MODE.Month:
9
9
  const year = viewDate.getFullYear();
10
10
  return `${getMonthName(viewDate, locale)} ${year}`;
11
- case ViewMode.Year:
11
+ case VIEW_MODE.Year:
12
12
  return viewDate.getFullYear().toString();
13
- case ViewMode.Decade:
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 '../../constants';
1
+ import { ViewMode } from '../../types';
2
2
  export declare const getShift: (referenceDate: Date, viewDate: Date, currentViewLevel: ViewMode) => number;
@@ -1,12 +1,12 @@
1
- import { ViewMode } from '../../constants';
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 ViewMode.Month:
5
+ case VIEW_MODE.Month:
6
6
  return getYearShift(referenceDate, viewDate);
7
- case ViewMode.Year:
7
+ case VIEW_MODE.Year:
8
8
  return getDecadeShift(referenceDate, viewDate);
9
- case ViewMode.Decade:
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 { ViewMode } from '../../constants';
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 === ViewMode.Month) {
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 { ViewMode } from '../../constants';
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(ViewMode.Year);
18
+ setViewMode(VIEW_MODE.Year);
19
19
  },
20
20
  onPreselect(date) {
21
21
  if (preselectedRange) {
@@ -1,9 +1,9 @@
1
- import { GRID_SIZE, ViewMode } from '../../constants';
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[ViewMode.Decade];
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, InRangePosition } from '../../constants';
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 !== InRangePosition.Out;
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 { CalendarMode } from '../../constants';
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 === CalendarMode.Range) {
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, ViewMode } from '../../constants';
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[ViewMode.Month];
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, ViewMode } from '../../constants';
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(ViewMode.Month);
19
+ setViewMode(VIEW_MODE.Month);
20
20
  },
21
21
  onPreselect(date) {
22
22
  if (preselectedRange) {