@gravity-ui/date-components 2.10.1 → 2.10.2

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.
@@ -61,7 +61,7 @@ function Content({ className, state, animation, onAnimationEnd }) {
61
61
  return ((0, jsx_runtime_1.jsxs)("div", { className: b('content', { animation }, className), onAnimationEnd: onAnimationEnd, role: "presentation", children: [state.mode === 'days' && (0, jsx_runtime_1.jsx)(Weekdays, { state: state }), (0, jsx_runtime_1.jsx)(CalendarGridCells, { state: state })] }));
62
62
  }
63
63
  function Weekdays({ state }) {
64
- const weekdays = (0, utils_1.getWeekDays)();
64
+ const weekdays = (0, utils_1.getWeekDays)(state);
65
65
  return ((0, jsx_runtime_1.jsx)("div", { className: b('grid-row'), role: "row", children: weekdays.map((date) => {
66
66
  return ((0, jsx_runtime_1.jsx)("div", { className: b('weekday', { weekend: state.isWeekend(date) }), role: "columnheader", "aria-label": (0, dates_1.formatDateTime)(date, 'dddd', state.timeZone), children: (0, dates_1.formatDateTime)(date, 'dd', state.timeZone) }, date.day()));
67
67
  }) }));
@@ -69,7 +69,7 @@ function Weekdays({ state }) {
69
69
  function CalendarGridCells({ state }) {
70
70
  const rowsInPeriod = state.mode === 'days' ? 6 : 4;
71
71
  const columnsInRow = state.mode === 'days' ? 7 : 3 + (state.mode === 'quarters' ? 1 : 0);
72
- const days = (0, utils_1.getDaysInPeriod)(state.startDate, state.endDate, state.mode);
72
+ const days = (0, utils_1.getDaysInPeriod)(state);
73
73
  return ((0, jsx_runtime_1.jsx)("div", { className: b('grid-rowgroup', { mode: state.mode }), role: "rowgroup", children: [...new Array(rowsInPeriod).keys()].map((rowIndex) => ((0, jsx_runtime_1.jsxs)("div", { className: b('grid-row'), role: "row", children: [state.mode === 'quarters' ? ((0, jsx_runtime_1.jsx)("span", { role: "rowheader", className: b('grid-rowgroup-header'), children: (0, dates_1.formatDateTime)(days[rowIndex * columnsInRow], 'YYYY', state.timeZone) })) : null, days
74
74
  .slice(rowIndex * columnsInRow, (rowIndex + 1) * columnsInRow)
75
75
  .map((date) => {
@@ -1,5 +1,5 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
- import type { CalendarLayout } from './hooks/types';
3
- export declare function getDaysInPeriod(startDate: DateTime, _endDate: DateTime, mode: CalendarLayout): DateTime[];
4
- export declare function getWeekDays(): DateTime[];
2
+ import type { CalendarLayout, CalendarState, RangeCalendarState } from './hooks/types';
3
+ export declare function getDaysInPeriod(state: CalendarState | RangeCalendarState): DateTime[];
4
+ export declare function getWeekDays(state: CalendarState | RangeCalendarState): DateTime[];
5
5
  export declare const calendarLayouts: CalendarLayout[];
@@ -4,29 +4,30 @@ exports.calendarLayouts = void 0;
4
4
  exports.getDaysInPeriod = getDaysInPeriod;
5
5
  exports.getWeekDays = getWeekDays;
6
6
  const date_utils_1 = require("@gravity-ui/date-utils");
7
- function getDaysInPeriod(startDate, _endDate, mode) {
7
+ function getDaysInPeriod(state) {
8
8
  const days = [];
9
- if (mode === 'days') {
9
+ const startDate = (0, date_utils_1.dateTime)({ input: state.startDate, timeZone: state.timeZone });
10
+ if (state.mode === 'days') {
10
11
  const currentDate = startDate.startOf('week');
11
12
  for (let i = 0; i < 42; i++) {
12
13
  days.push(currentDate.add({ days: i }));
13
14
  }
14
15
  }
15
- else if (mode === 'quarters') {
16
+ else if (state.mode === 'quarters') {
16
17
  for (let i = 0; i < 16; i++) {
17
18
  days.push(startDate.add(i, 'quarters'));
18
19
  }
19
20
  }
20
21
  else {
21
22
  for (let i = 0; i < 12; i++) {
22
- days.push(startDate.add({ [mode]: i }));
23
+ days.push(startDate.add({ [state.mode]: i }));
23
24
  }
24
25
  }
25
26
  return days;
26
27
  }
27
- function getWeekDays() {
28
+ function getWeekDays(state) {
28
29
  const weekDays = [];
29
- const weekStart = (0, date_utils_1.dateTime)().startOf('week');
30
+ const weekStart = (0, date_utils_1.dateTime)({ timeZone: state.timeZone }).startOf('week');
30
31
  for (let i = 0; i < 7; i++) {
31
32
  const date = weekStart.add({ days: i });
32
33
  weekDays.push(date);
@@ -55,7 +55,7 @@ function Content({ className, state, animation, onAnimationEnd }) {
55
55
  return (_jsxs("div", { className: b('content', { animation }, className), onAnimationEnd: onAnimationEnd, role: "presentation", children: [state.mode === 'days' && _jsx(Weekdays, { state: state }), _jsx(CalendarGridCells, { state: state })] }));
56
56
  }
57
57
  function Weekdays({ state }) {
58
- const weekdays = getWeekDays();
58
+ const weekdays = getWeekDays(state);
59
59
  return (_jsx("div", { className: b('grid-row'), role: "row", children: weekdays.map((date) => {
60
60
  return (_jsx("div", { className: b('weekday', { weekend: state.isWeekend(date) }), role: "columnheader", "aria-label": formatDateTime(date, 'dddd', state.timeZone), children: formatDateTime(date, 'dd', state.timeZone) }, date.day()));
61
61
  }) }));
@@ -63,7 +63,7 @@ function Weekdays({ state }) {
63
63
  function CalendarGridCells({ state }) {
64
64
  const rowsInPeriod = state.mode === 'days' ? 6 : 4;
65
65
  const columnsInRow = state.mode === 'days' ? 7 : 3 + (state.mode === 'quarters' ? 1 : 0);
66
- const days = getDaysInPeriod(state.startDate, state.endDate, state.mode);
66
+ const days = getDaysInPeriod(state);
67
67
  return (_jsx("div", { className: b('grid-rowgroup', { mode: state.mode }), role: "rowgroup", children: [...new Array(rowsInPeriod).keys()].map((rowIndex) => (_jsxs("div", { className: b('grid-row'), role: "row", children: [state.mode === 'quarters' ? (_jsx("span", { role: "rowheader", className: b('grid-rowgroup-header'), children: formatDateTime(days[rowIndex * columnsInRow], 'YYYY', state.timeZone) })) : null, days
68
68
  .slice(rowIndex * columnsInRow, (rowIndex + 1) * columnsInRow)
69
69
  .map((date) => {
@@ -1,5 +1,5 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
- import type { CalendarLayout } from './hooks/types';
3
- export declare function getDaysInPeriod(startDate: DateTime, _endDate: DateTime, mode: CalendarLayout): DateTime[];
4
- export declare function getWeekDays(): DateTime[];
2
+ import type { CalendarLayout, CalendarState, RangeCalendarState } from './hooks/types';
3
+ export declare function getDaysInPeriod(state: CalendarState | RangeCalendarState): DateTime[];
4
+ export declare function getWeekDays(state: CalendarState | RangeCalendarState): DateTime[];
5
5
  export declare const calendarLayouts: CalendarLayout[];
@@ -1,27 +1,28 @@
1
1
  import { dateTime } from '@gravity-ui/date-utils';
2
- export function getDaysInPeriod(startDate, _endDate, mode) {
2
+ export function getDaysInPeriod(state) {
3
3
  const days = [];
4
- if (mode === 'days') {
4
+ const startDate = dateTime({ input: state.startDate, timeZone: state.timeZone });
5
+ if (state.mode === 'days') {
5
6
  const currentDate = startDate.startOf('week');
6
7
  for (let i = 0; i < 42; i++) {
7
8
  days.push(currentDate.add({ days: i }));
8
9
  }
9
10
  }
10
- else if (mode === 'quarters') {
11
+ else if (state.mode === 'quarters') {
11
12
  for (let i = 0; i < 16; i++) {
12
13
  days.push(startDate.add(i, 'quarters'));
13
14
  }
14
15
  }
15
16
  else {
16
17
  for (let i = 0; i < 12; i++) {
17
- days.push(startDate.add({ [mode]: i }));
18
+ days.push(startDate.add({ [state.mode]: i }));
18
19
  }
19
20
  }
20
21
  return days;
21
22
  }
22
- export function getWeekDays() {
23
+ export function getWeekDays(state) {
23
24
  const weekDays = [];
24
- const weekStart = dateTime().startOf('week');
25
+ const weekStart = dateTime({ timeZone: state.timeZone }).startOf('week');
25
26
  for (let i = 0; i < 7; i++) {
26
27
  const date = weekStart.add({ days: i });
27
28
  weekDays.push(date);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/date-components",
3
- "version": "2.10.1",
3
+ "version": "2.10.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",