@dxos/react-ui-calendar 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +502 -230
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +16 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +502 -230
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +18 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/Calendar/Calendar.d.ts +41 -18
- package/dist/types/src/components/Calendar/Calendar.d.ts.map +1 -1
- package/dist/types/src/components/Calendar/Calendar.stories.d.ts +6 -10
- package/dist/types/src/components/Calendar/Calendar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Calendar/util.d.ts +11 -0
- package/dist/types/src/components/Calendar/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -3
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -29
- package/src/components/Calendar/Calendar.stories.tsx +34 -40
- package/src/components/Calendar/Calendar.tsx +517 -161
- package/src/components/Calendar/util.ts +19 -1
- package/src/translations.ts +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Day } from 'date-fns';
|
|
5
|
+
import { type Day, differenceInCalendarDays } from 'date-fns';
|
|
6
6
|
|
|
7
7
|
export const getDate = (start: Date, weekNumber: number, dayOfWeek: number, weekStartsOn: Day): Date => {
|
|
8
8
|
const result = new Date(start);
|
|
@@ -12,6 +12,24 @@ export const getDate = (start: Date, weekNumber: number, dayOfWeek: number, week
|
|
|
12
12
|
return result;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Inverse of {@link getDate}: returns the row index for a given date, matching
|
|
17
|
+
* the grid layout (which respects `weekStartsOn`).
|
|
18
|
+
*
|
|
19
|
+
* Uses `differenceInCalendarDays` (DST-safe) — naive ms subtraction silently
|
|
20
|
+
* loses an hour each DST transition, which accumulates over decades and
|
|
21
|
+
* eventually shifts the row boundary by one day. `differenceInWeeks` is also
|
|
22
|
+
* unsuitable because it computes raw 7-day chunks anchored at the start
|
|
23
|
+
* date's weekday rather than the grid's `weekStartsOn` column.
|
|
24
|
+
*/
|
|
25
|
+
export const getRowIndex = (start: Date, date: Date, weekStartsOn: Day): number => {
|
|
26
|
+
const startDayOfWeek = start.getDay();
|
|
27
|
+
const adjustedStartDay = (startDayOfWeek === 0 ? 7 : startDayOfWeek) - weekStartsOn;
|
|
28
|
+
const row0Start = new Date(start);
|
|
29
|
+
row0Start.setDate(start.getDate() - adjustedStartDay);
|
|
30
|
+
return Math.floor(differenceInCalendarDays(date, row0Start) / 7);
|
|
31
|
+
};
|
|
32
|
+
|
|
15
33
|
export const isSameDay = (date1: Date, date2: Date | undefined): boolean => {
|
|
16
34
|
return (
|
|
17
35
|
!!date2 &&
|
package/src/translations.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
export const translationKey = 'react-ui-calendar';
|
|
7
|
+
export const translationKey = '@dxos/react-ui-calendar';
|
|
8
8
|
|
|
9
9
|
export const translations = [
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[translationKey]: {
|
|
13
|
-
'today
|
|
13
|
+
'today.button': 'Today',
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
},
|