@cognite/aura 1.48473.0 → 1.48494.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/dist/components/ui/core/calendar/calendar-header.js +3 -4
- package/dist/components/ui/core/calendar/calendar-header.js.map +1 -1
- package/dist/components/ui/core/calendar/calendar-utils.d.ts +19 -7
- package/dist/components/ui/core/calendar/calendar-utils.js +87 -27
- package/dist/components/ui/core/calendar/calendar-utils.js.map +1 -1
- package/dist/components/ui/core/calendar/calendar.js +2 -2
- package/dist/components/ui/core/calendar/calendar.js.map +1 -1
- package/dist/components/ui/core/calendar/constants.d.ts +1 -0
- package/dist/components/ui/core/calendar/constants.js +1 -0
- package/dist/components/ui/core/calendar/constants.js.map +1 -1
- package/dist/components/ui/core/data-grid/data-grid.utils.js +2 -3
- package/dist/components/ui/core/data-grid/data-grid.utils.js.map +1 -1
- package/dist/components/ui/core/date-time-pickers/date-picker/date-picker.js +3 -1
- package/dist/components/ui/core/date-time-pickers/date-picker/date-picker.js.map +1 -1
- package/dist/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.js +3 -1
- package/dist/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.d.ts +1 -1
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.js +2 -1
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.js.map +1 -1
- package/dist/components/ui/core/date-time-pickers/utils/format-utils.d.ts +11 -2
- package/dist/components/ui/core/date-time-pickers/utils/format-utils.js +28 -3
- package/dist/components/ui/core/date-time-pickers/utils/format-utils.js.map +1 -1
- package/dist/components/ui/core/segmented-control/segmented-control.js +6 -3
- package/dist/components/ui/core/segmented-control/segmented-control.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -4,9 +4,8 @@ import dayjs from "dayjs";
|
|
|
4
4
|
import { cn } from "../../../../lib/utils.js";
|
|
5
5
|
import { Button } from "../button/button.js";
|
|
6
6
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../dropdown-menu/dropdown-menu.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}, (_, i)=>dayjs().month(i).format('MMMM'));
|
|
7
|
+
import { getMonthNames } from "./calendar-utils.js";
|
|
8
|
+
const MONTHS = getMonthNames();
|
|
10
9
|
const YEAR_RANGE_START = dayjs().year() - 50;
|
|
11
10
|
const YEAR_RANGE_END = dayjs().year() + 10;
|
|
12
11
|
const YEARS = Array.from({
|
|
@@ -66,7 +65,7 @@ export const CalendarHeader = ({ displayedMonth, onPrevMonth, onNextMonth, onMon
|
|
|
66
65
|
className: "flex items-center gap-0.5",
|
|
67
66
|
children: [
|
|
68
67
|
/*#__PURE__*/ _jsx(NavigationDropdown, {
|
|
69
|
-
label: displayedMonth.
|
|
68
|
+
label: MONTHS[displayedMonth.month()],
|
|
70
69
|
items: MONTHS.map((name, i)=>({
|
|
71
70
|
value: i,
|
|
72
71
|
label: name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/calendar-header.tsx"],"sourcesContent":["import type { FC } from 'react';\n\nimport {\n IconChevronDown,\n IconChevronLeft,\n IconChevronRight,\n} from '@tabler/icons-react';\nimport type { Dayjs } from 'dayjs';\nimport dayjs from 'dayjs';\n\nimport { cn } from '../../../../lib/utils';\nimport { Button } from '../button/button';\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from '../dropdown-menu/dropdown-menu';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/calendar-header.tsx"],"sourcesContent":["import type { FC } from 'react';\n\nimport {\n IconChevronDown,\n IconChevronLeft,\n IconChevronRight,\n} from '@tabler/icons-react';\nimport type { Dayjs } from 'dayjs';\nimport dayjs from 'dayjs';\n\nimport { cn } from '../../../../lib/utils';\nimport { Button } from '../button/button';\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from '../dropdown-menu/dropdown-menu';\n\nimport { getMonthNames } from './calendar-utils';\n\nconst MONTHS = getMonthNames();\n\nconst YEAR_RANGE_START = dayjs().year() - 50;\nconst YEAR_RANGE_END = dayjs().year() + 10;\nconst YEARS = Array.from(\n { length: YEAR_RANGE_END - YEAR_RANGE_START + 1 },\n (_: unknown, i: number) => YEAR_RANGE_START + i\n);\n\ninterface NavigationDropdownItem {\n value: number;\n label: string;\n}\n\ninterface NavigationDropdownProps {\n label: string;\n items: NavigationDropdownItem[];\n selectedValue: number;\n onSelect: (value: number) => void;\n}\n\n// DropdownMenuItem unmounts on close and remounts on open, so a ref callback on\n// the active item fires exactly when the list opens — scrolling it into view\n// instead of always starting at the top of the (potentially 60-year-long) list.\nconst scrollSelectedItemIntoView = (node: HTMLElement | null) => {\n node?.scrollIntoView?.({ block: 'center', behavior: 'instant' });\n};\n\nconst NavigationDropdown: FC<NavigationDropdownProps> = ({\n label,\n items,\n selectedValue,\n onSelect,\n}) => (\n <DropdownMenu modal={false}>\n <DropdownMenuTrigger\n render={\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className=\"h-7 px-2 gap-1 text-sm font-medium text-secondary-foreground\"\n >\n {label}\n <IconChevronDown className=\"size-4\" />\n </Button>\n }\n />\n <DropdownMenuContent className=\"max-h-60 overflow-y-auto\">\n {items.map(({ value, label: itemLabel }) => (\n <DropdownMenuItem\n key={value}\n ref={value === selectedValue ? scrollSelectedItemIntoView : undefined}\n onClick={() => onSelect(value)}\n >\n {itemLabel}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n);\n\nexport interface CalendarHeaderProps {\n displayedMonth: Dayjs;\n onPrevMonth: () => void;\n onNextMonth: () => void;\n onMonthChange: (month: Dayjs) => void;\n className?: string;\n}\n\nexport const CalendarHeader: FC<CalendarHeaderProps> = ({\n displayedMonth,\n onPrevMonth,\n onNextMonth,\n onMonthChange,\n className,\n}) => {\n return (\n <div\n data-slot=\"calendar-header\"\n className={cn('flex items-center justify-between pt-1 w-full', className)}\n >\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className=\"size-7 rounded-md text-secondary-foreground\"\n onClick={onPrevMonth}\n aria-label=\"Previous month\"\n >\n <IconChevronLeft className=\"size-4\" />\n </Button>\n <div className=\"flex items-center gap-0.5\">\n <NavigationDropdown\n label={MONTHS[displayedMonth.month()]}\n items={MONTHS.map((name, i) => ({ value: i, label: name }))}\n selectedValue={displayedMonth.month()}\n onSelect={(i) => onMonthChange(displayedMonth.date(1).month(i))}\n />\n <NavigationDropdown\n label={displayedMonth.format('YYYY')}\n items={YEARS.map((y) => ({ value: y, label: String(y) }))}\n selectedValue={displayedMonth.year()}\n onSelect={(y) => onMonthChange(displayedMonth.date(1).year(y))}\n />\n </div>\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className=\"size-7 rounded-md text-secondary-foreground\"\n onClick={onNextMonth}\n aria-label=\"Next month\"\n >\n <IconChevronRight className=\"size-4\" />\n </Button>\n </div>\n );\n};\n"],"names":["IconChevronDown","IconChevronLeft","IconChevronRight","dayjs","cn","Button","DropdownMenu","DropdownMenuContent","DropdownMenuItem","DropdownMenuTrigger","getMonthNames","MONTHS","YEAR_RANGE_START","year","YEAR_RANGE_END","YEARS","Array","from","length","_","i","scrollSelectedItemIntoView","node","scrollIntoView","block","behavior","NavigationDropdown","label","items","selectedValue","onSelect","modal","render","variant","size","className","map","value","itemLabel","ref","undefined","onClick","CalendarHeader","displayedMonth","onPrevMonth","onNextMonth","onMonthChange","div","data-slot","aria-label","month","name","date","format","y","String"],"mappings":";AAEA,SACEA,eAAe,EACfC,eAAe,EACfC,gBAAgB,QACX,sBAAsB;AAE7B,OAAOC,WAAW,QAAQ;AAE1B,SAASC,EAAE,QAAQ,2BAAwB;AAC3C,SAASC,MAAM,QAAQ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gBAAIZ,WAAU;;kCACb,KAACT;wBACCC,OAAOhB,MAAM,CAACgC,eAAeO,KAAK,GAAG;wBACrCtB,OAAOjB,OAAOyB,GAAG,CAAC,CAACe,MAAM/B,IAAO,CAAA;gCAAEiB,OAAOjB;gCAAGO,OAAOwB;4BAAK,CAAA;wBACxDtB,eAAec,eAAeO,KAAK;wBACnCpB,UAAU,CAACV,IAAM0B,cAAcH,eAAeS,IAAI,CAAC,GAAGF,KAAK,CAAC9B;;kCAE9D,KAACM;wBACCC,OAAOgB,eAAeU,MAAM,CAAC;wBAC7BzB,OAAOb,MAAMqB,GAAG,CAAC,CAACkB,IAAO,CAAA;gCAAEjB,OAAOiB;gCAAG3B,OAAO4B,OAAOD;4BAAG,CAAA;wBACtDzB,eAAec,eAAe9B,IAAI;wBAClCiB,UAAU,CAACwB,IAAMR,cAAcH,eAAeS,IAAI,CAAC,GAAGvC,IAAI,CAACyC;;;;0BAG/D,KAACjD;gBACC4B,SAAQ;gBACRC,MAAK;gBACLC,WAAU;gBACVM,SAASI;gBACTI,cAAW;0BAEX,cAAA,KAAC/C;oBAAiBiC,WAAU;;;;;AAIpC,EAAE"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { type Dayjs } from "dayjs";
|
|
2
2
|
/**
|
|
3
|
+
* A day cell's aria-label, in the locale's own order.
|
|
4
|
+
* @param locale - Defaults to the browser's own.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getDayLabel(date: Dayjs, locale?: string): string;
|
|
7
|
+
/**
|
|
3
8
|
* Get all days to display in a calendar month grid (including padding days from prev/next months)
|
|
4
9
|
* @param month - The month to display
|
|
5
|
-
* @param locale -
|
|
10
|
+
* @param locale - Defaults to the browser's own.
|
|
6
11
|
*/
|
|
7
12
|
export declare function getCalendarDays(month: Dayjs, locale?: string): Dayjs[];
|
|
8
13
|
/**
|
|
@@ -25,18 +30,25 @@ export declare function isOutsideMonth(date: Dayjs, displayMonth: Dayjs): boolea
|
|
|
25
30
|
export declare function isToday(date: Dayjs, now?: Dayjs): boolean;
|
|
26
31
|
/**
|
|
27
32
|
* Get an array of weekday names (short form)
|
|
28
|
-
* @param locale -
|
|
29
|
-
|
|
33
|
+
* @param locale - Defaults to the browser's own.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getWeekdayNames(locale?: string): string[];
|
|
36
|
+
/**
|
|
37
|
+
* The locale's month names, indexed from 0 for January as dayjs does.
|
|
38
|
+
* @param locale - Defaults to the browser's own.
|
|
30
39
|
*/
|
|
31
|
-
export declare function
|
|
40
|
+
export declare function getMonthNames(locale?: string): string[];
|
|
32
41
|
/**
|
|
33
|
-
* Get the week number
|
|
42
|
+
* Get the week number, counted from the weekday the grid starts on.
|
|
43
|
+
* Week one is the week holding the January day the locale requires.
|
|
44
|
+
* @param locale - Defaults to the browser's own.
|
|
34
45
|
*/
|
|
35
|
-
export declare function getWeekNumber(date: Dayjs): number;
|
|
46
|
+
export declare function getWeekNumber(date: Dayjs, locale?: string): number;
|
|
36
47
|
/**
|
|
37
48
|
* Get all week numbers for days in a calendar month grid
|
|
49
|
+
* @param locale - Defaults to the browser's own.
|
|
38
50
|
*/
|
|
39
|
-
export declare function getWeekNumbers(days: Dayjs[]): number[];
|
|
51
|
+
export declare function getWeekNumbers(days: Dayjs[], locale?: string): number[];
|
|
40
52
|
/**
|
|
41
53
|
* Check if two dates are the same day
|
|
42
54
|
*/
|
|
@@ -1,23 +1,68 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
import isBetween from "dayjs/plugin/isBetween.js";
|
|
3
3
|
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
|
|
4
|
-
import
|
|
5
|
-
import { DAYS_IN_WEEK } from "./constants.js";
|
|
4
|
+
import { DAYS_IN_WEEK, MONTHS_IN_YEAR } from "./constants.js";
|
|
6
5
|
dayjs.extend(isBetween);
|
|
7
6
|
dayjs.extend(isSameOrBefore);
|
|
8
|
-
dayjs.extend(weekOfYear);
|
|
9
7
|
const DATE_RANGE_SEPARATOR = ' – ';
|
|
8
|
+
const INTL_SUNDAY = 7;
|
|
9
|
+
/** Gregorian and ASCII, to match what dayjs prints, since th-TH would read 2567. */ const DAY_LABEL_OPTIONS = {
|
|
10
|
+
calendar: 'gregory',
|
|
11
|
+
numberingSystem: 'latn',
|
|
12
|
+
day: 'numeric',
|
|
13
|
+
month: 'long',
|
|
14
|
+
year: 'numeric'
|
|
15
|
+
};
|
|
16
|
+
const WEEKDAY_OPTIONS = {
|
|
17
|
+
weekday: 'short'
|
|
18
|
+
};
|
|
19
|
+
/** Gregorian, so the names match the months dayjs indexes by. */ const MONTH_OPTIONS = {
|
|
20
|
+
calendar: 'gregory',
|
|
21
|
+
numberingSystem: 'latn',
|
|
22
|
+
month: 'long'
|
|
23
|
+
};
|
|
24
|
+
/** Intl.Locale rejects undefined, so the engine's own tag is resolved first. */ const DEFAULT_LOCALE = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
25
|
+
/** The viewer's formatter is built once. Only the specs pass a locale. */ function formatterFor(options) {
|
|
26
|
+
const forViewer = new Intl.DateTimeFormat(undefined, options);
|
|
27
|
+
return (locale)=>locale === undefined ? forViewer : new Intl.DateTimeFormat(locale, options);
|
|
28
|
+
}
|
|
29
|
+
const dayLabelFormatter = formatterFor(DAY_LABEL_OPTIONS);
|
|
30
|
+
const weekdayFormatter = formatterFor(WEEKDAY_OPTIONS);
|
|
31
|
+
const monthFormatter = formatterFor(MONTH_OPTIONS);
|
|
32
|
+
function readWeekRules(locale) {
|
|
33
|
+
const intlLocale = new Intl.Locale(locale);
|
|
34
|
+
const weekInfo = intlLocale.getWeekInfo?.() ?? intlLocale.weekInfo;
|
|
35
|
+
return {
|
|
36
|
+
weekStart: (weekInfo?.firstDay ?? INTL_SUNDAY) % DAYS_IN_WEEK,
|
|
37
|
+
minimalDays: weekInfo?.minimalDays ?? 1
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const VIEWER_WEEK_RULES = readWeekRules(DEFAULT_LOCALE);
|
|
41
|
+
function getWeekRules(locale) {
|
|
42
|
+
return locale === undefined ? VIEWER_WEEK_RULES : readWeekRules(locale);
|
|
43
|
+
}
|
|
44
|
+
function getWeekStart(locale) {
|
|
45
|
+
return getWeekRules(locale).weekStart;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A day cell's aria-label, in the locale's own order.
|
|
49
|
+
* @param locale - Defaults to the browser's own.
|
|
50
|
+
*/ export function getDayLabel(date, locale) {
|
|
51
|
+
// Intl renders an instant in the viewer's zone, so pass the cell's own date.
|
|
52
|
+
return dayLabelFormatter(locale).format(new Date(date.year(), date.month(), date.date()));
|
|
53
|
+
}
|
|
54
|
+
function startOfGridWeek(date, weekStart) {
|
|
55
|
+
// A zone that skips local midnight would otherwise leave a time of day, making the weeks ragged.
|
|
56
|
+
return date.startOf('day').subtract((date.day() - weekStart + DAYS_IN_WEEK) % DAYS_IN_WEEK, 'day');
|
|
57
|
+
}
|
|
10
58
|
/**
|
|
11
59
|
* Get all days to display in a calendar month grid (including padding days from prev/next months)
|
|
12
60
|
* @param month - The month to display
|
|
13
|
-
* @param locale -
|
|
61
|
+
* @param locale - Defaults to the browser's own.
|
|
14
62
|
*/ export function getCalendarDays(month, locale) {
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const firstDayOfGrid = firstDayOfMonth.startOf('week');
|
|
19
|
-
const lastDayOfMonth = localizedMonth.endOf('month');
|
|
20
|
-
const lastDayOfGrid = lastDayOfMonth.endOf('week');
|
|
63
|
+
const weekStart = getWeekStart(locale);
|
|
64
|
+
const firstDayOfGrid = startOfGridWeek(month.startOf('month'), weekStart);
|
|
65
|
+
const lastDayOfGrid = startOfGridWeek(month.endOf('month'), weekStart).add(DAYS_IN_WEEK - 1, 'day');
|
|
21
66
|
const days = [];
|
|
22
67
|
let currentDay = firstDayOfGrid;
|
|
23
68
|
while(currentDay.isSameOrBefore(lastDayOfGrid, 'day')){
|
|
@@ -61,34 +106,49 @@ const DATE_RANGE_SEPARATOR = ' – ';
|
|
|
61
106
|
}
|
|
62
107
|
/**
|
|
63
108
|
* Get an array of weekday names (short form)
|
|
64
|
-
* @param locale -
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
// Create a localized instance without mutating global state
|
|
69
|
-
const localizedDayjs = locale ? base.locale(locale) : base;
|
|
70
|
-
// Calculate startOfWeek using the localized instance
|
|
71
|
-
const startOfWeek = localizedDayjs.startOf('week');
|
|
109
|
+
* @param locale - Defaults to the browser's own.
|
|
110
|
+
*/ export function getWeekdayNames(locale) {
|
|
111
|
+
const startOfWeek = startOfGridWeek(dayjs(), getWeekStart(locale));
|
|
112
|
+
const formatter = weekdayFormatter(locale);
|
|
72
113
|
return Array.from({
|
|
73
114
|
length: DAYS_IN_WEEK
|
|
74
|
-
}, (_, i)=>
|
|
75
|
-
return startOfWeek.add(i, 'day').format('dd');
|
|
76
|
-
});
|
|
115
|
+
}, (_, i)=>formatter.format(startOfWeek.add(i, 'day').toDate()));
|
|
77
116
|
}
|
|
78
117
|
/**
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
118
|
+
* The locale's month names, indexed from 0 for January as dayjs does.
|
|
119
|
+
* @param locale - Defaults to the browser's own.
|
|
120
|
+
*/ export function getMonthNames(locale) {
|
|
121
|
+
const formatter = monthFormatter(locale);
|
|
122
|
+
// 2000 avoids the 1900s that Date remaps two-digit years into.
|
|
123
|
+
return Array.from({
|
|
124
|
+
length: MONTHS_IN_YEAR
|
|
125
|
+
}, (_, i)=>formatter.format(new Date(2000, i, 1)));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the week number, counted from the weekday the grid starts on.
|
|
129
|
+
* Week one is the week holding the January day the locale requires.
|
|
130
|
+
* @param locale - Defaults to the browser's own.
|
|
131
|
+
*/ export function getWeekNumber(date, locale) {
|
|
132
|
+
const { weekStart, minimalDays } = getWeekRules(locale);
|
|
133
|
+
const weekBegin = startOfGridWeek(date, weekStart);
|
|
134
|
+
const firstWeekOf = (year)=>startOfGridWeek(dayjs(new Date(year, 0, minimalDays)), weekStart);
|
|
135
|
+
// A late December week can belong to the next year, so start a year ahead and walk back.
|
|
136
|
+
let year = weekBegin.year() + 1;
|
|
137
|
+
while(weekBegin.isBefore(firstWeekOf(year), 'day')){
|
|
138
|
+
year -= 1;
|
|
139
|
+
}
|
|
140
|
+
const daysIn = weekBegin.diff(firstWeekOf(year), 'day');
|
|
141
|
+
return Math.round(daysIn / DAYS_IN_WEEK) + 1;
|
|
82
142
|
}
|
|
83
143
|
/**
|
|
84
144
|
* Get all week numbers for days in a calendar month grid
|
|
85
|
-
|
|
145
|
+
* @param locale - Defaults to the browser's own.
|
|
146
|
+
*/ export function getWeekNumbers(days, locale) {
|
|
86
147
|
const weekNumbers = [];
|
|
87
|
-
// Process days in chunks of DAYS_IN_WEEK (one week at a time)
|
|
88
148
|
for(let i = 0; i < days.length; i += DAYS_IN_WEEK){
|
|
89
149
|
const firstDayOfWeek = days[i];
|
|
90
150
|
if (firstDayOfWeek) {
|
|
91
|
-
weekNumbers.push(getWeekNumber(firstDayOfWeek));
|
|
151
|
+
weekNumbers.push(getWeekNumber(firstDayOfWeek, locale));
|
|
92
152
|
}
|
|
93
153
|
}
|
|
94
154
|
return weekNumbers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/calendar-utils.ts"],"sourcesContent":["import dayjs, { type Dayjs } from 'dayjs';\nimport isBetween from 'dayjs/plugin/isBetween.js';\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';\nimport weekOfYear from 'dayjs/plugin/weekOfYear.js';\n\nimport { DAYS_IN_WEEK } from './constants';\n\ndayjs.extend(isBetween);\ndayjs.extend(isSameOrBefore);\ndayjs.extend(weekOfYear);\n\nconst DATE_RANGE_SEPARATOR = ' – ';\n\n/**\n * Get all days to display in a calendar month grid (including padding days from prev/next months)\n * @param month - The month to display\n * @param locale - Optional locale for week start day (e.g., 'en', 'nb', 'de')\n */\nexport function getCalendarDays(month: Dayjs, locale?: string): Dayjs[] {\n // Create a localized instance without mutating global state\n const localizedMonth = locale ? month.locale(locale) : month;\n\n const firstDayOfMonth = localizedMonth.startOf('month');\n const firstDayOfGrid = firstDayOfMonth.startOf('week');\n\n const lastDayOfMonth = localizedMonth.endOf('month');\n const lastDayOfGrid = lastDayOfMonth.endOf('week');\n\n const days: Dayjs[] = [];\n\n let currentDay = firstDayOfGrid;\n\n while (currentDay.isSameOrBefore(lastDayOfGrid, 'day')) {\n days.push(currentDay);\n currentDay = currentDay.add(1, 'day');\n }\n\n return days;\n}\n\n/**\n * Check if a date is within a given range (inclusive)\n * Uses dayjs isBetween plugin with '[]' for inclusive start and end\n * @see https://day.js.org/docs/en/plugin/is-between\n */\nexport function isDateInRange(\n date: Dayjs,\n startDate: Dayjs | null,\n endDate: Dayjs | null\n): boolean {\n if (!startDate || !endDate) {\n return false;\n }\n\n // Validate all dates are valid\n if (!date.isValid() || !startDate.isValid() || !endDate.isValid()) {\n return false;\n }\n\n // If start is after end, the range is invalid\n if (startDate.isAfter(endDate, 'day')) {\n return false;\n }\n\n // 'day' granularity ignores time, '[]' includes both start and end\n return date.isBetween(startDate, endDate, 'day', '[]');\n}\n\n/**\n * Check if a date is outside the current display month\n */\nexport function isOutsideMonth(date: Dayjs, displayMonth: Dayjs): boolean {\n return date.month() !== displayMonth.month();\n}\n\n/**\n * Check if a date is today\n * Note: Uses local timezone. Both the input date and current time are compared\n * using the user's local timezone, which is the expected behavior for calendar UIs.\n * @param date - The date to check\n * @param now - Optional current date for testing (defaults to dayjs())\n */\nexport function isToday(date: Dayjs, now?: Dayjs): boolean {\n return date.isSame(now ?? dayjs(), 'day');\n}\n\n/**\n * Get an array of weekday names (short form)\n * @param locale - Optional locale for localized weekday names (e.g., 'en', 'nb', 'de')\n * @param baseDate - Optional base date for testing (defaults to dayjs())\n */\nexport function getWeekdayNames(locale?: string, baseDate?: Dayjs): string[] {\n const base = baseDate || dayjs();\n\n // Create a localized instance without mutating global state\n const localizedDayjs = locale ? base.locale(locale) : base;\n\n // Calculate startOfWeek using the localized instance\n const startOfWeek = localizedDayjs.startOf('week');\n\n return Array.from({ length: DAYS_IN_WEEK }, (_, i) => {\n return startOfWeek.add(i, 'day').format('dd');\n });\n}\n\n/**\n * Get the week number for a given date\n */\nexport function getWeekNumber(date: Dayjs): number {\n return date.week();\n}\n\n/**\n * Get all week numbers for days in a calendar month grid\n */\nexport function getWeekNumbers(days: Dayjs[]): number[] {\n const weekNumbers: number[] = [];\n\n // Process days in chunks of DAYS_IN_WEEK (one week at a time)\n for (let i = 0; i < days.length; i += DAYS_IN_WEEK) {\n const firstDayOfWeek = days[i];\n if (firstDayOfWeek) {\n weekNumbers.push(getWeekNumber(firstDayOfWeek));\n }\n }\n\n return weekNumbers;\n}\n\n/**\n * Check if two dates are the same day\n */\nexport function isSameDay(date1: Dayjs | null, date2: Dayjs | null): boolean {\n if (!date1 || !date2) {\n return false;\n }\n return date1.isSame(date2, 'day');\n}\n\n/**\n * Format a date range for display\n * When one date is missing, shows the format placeholder for the missing date\n */\nexport function formatDateRange(\n startDate: Dayjs | null,\n endDate: Dayjs | null,\n format: string\n): string {\n if (!startDate && !endDate) {\n return '';\n }\n\n const startStr = startDate?.format(format) ?? format;\n const endStr = endDate?.format(format) ?? format;\n\n return `${startStr}${DATE_RANGE_SEPARATOR}${endStr}`;\n}\n"],"names":["dayjs","isBetween","isSameOrBefore","weekOfYear","DAYS_IN_WEEK","extend","DATE_RANGE_SEPARATOR","getCalendarDays","month","locale","localizedMonth","firstDayOfMonth","startOf","firstDayOfGrid","lastDayOfMonth","endOf","lastDayOfGrid","days","currentDay","push","add","isDateInRange","date","startDate","endDate","isValid","isAfter","isOutsideMonth","displayMonth","isToday","now","isSame","getWeekdayNames","baseDate","base","localizedDayjs","startOfWeek","Array","from","length","_","i","format","getWeekNumber","week","getWeekNumbers","weekNumbers","firstDayO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AO;IACT;IAEA,MAAM4B,WAAW7B,WAAWmB,OAAOA,WAAWA;IAC9C,MAAMW,SAAS7B,SAASkB,OAAOA,WAAWA;IAE1C,OAAO,GAAGU,WAAW9C,uBAAuB+C,QAAQ;AACtD"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/calendar-utils.ts"],"sourcesContent":["import dayjs, { type Dayjs } from 'dayjs';\nimport isBetween from 'dayjs/plugin/isBetween.js';\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';\n\nimport { DAYS_IN_WEEK, MONTHS_IN_YEAR } from './constants';\n\ndayjs.extend(isBetween);\ndayjs.extend(isSameOrBefore);\n\nconst DATE_RANGE_SEPARATOR = ' – ';\n\nconst INTL_SUNDAY = 7;\n\n/** Gregorian and ASCII, to match what dayjs prints, since th-TH would read 2567. */\nconst DAY_LABEL_OPTIONS: Intl.DateTimeFormatOptions = {\n calendar: 'gregory',\n numberingSystem: 'latn',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n};\n\nconst WEEKDAY_OPTIONS: Intl.DateTimeFormatOptions = { weekday: 'short' };\n\n/** Gregorian, so the names match the months dayjs indexes by. */\nconst MONTH_OPTIONS: Intl.DateTimeFormatOptions = {\n calendar: 'gregory',\n numberingSystem: 'latn',\n month: 'long',\n};\n\n/** Intl.WeekInfo omits minimalDays, which the week numbering needs. */\ninterface LocaleWeekInfo {\n readonly firstDay: number;\n readonly minimalDays?: number;\n}\n\n/** TypeScript declares getWeekInfo, V8 ships weekInfo, so both shapes are read. */\ninterface WeekInfoLocale {\n readonly weekInfo?: LocaleWeekInfo;\n readonly getWeekInfo?: () => LocaleWeekInfo;\n}\n\ninterface WeekRules {\n /** Numbered as dayjs does, from 0 for Sunday. */\n weekStart: number;\n /** How many days of January week one must hold, 1 in the US and 4 under ISO. */\n minimalDays: number;\n}\n\n/** Intl.Locale rejects undefined, so the engine's own tag is resolved first. */\nconst DEFAULT_LOCALE = new Intl.DateTimeFormat().resolvedOptions().locale;\n\n/** The viewer's formatter is built once. Only the specs pass a locale. */\nfunction formatterFor(\n options: Intl.DateTimeFormatOptions\n): (locale?: string) => Intl.DateTimeFormat {\n const forViewer = new Intl.DateTimeFormat(undefined, options);\n\n return (locale) =>\n locale === undefined ? forViewer : new Intl.DateTimeFormat(locale, options);\n}\n\nconst dayLabelFormatter = formatterFor(DAY_LABEL_OPTIONS);\nconst weekdayFormatter = formatterFor(WEEKDAY_OPTIONS);\nconst monthFormatter = formatterFor(MONTH_OPTIONS);\n\nfunction readWeekRules(locale: string): WeekRules {\n const intlLocale: WeekInfoLocale = new Intl.Locale(locale);\n const weekInfo = intlLocale.getWeekInfo?.() ?? intlLocale.weekInfo;\n\n return {\n weekStart: (weekInfo?.firstDay ?? INTL_SUNDAY) % DAYS_IN_WEEK,\n minimalDays: weekInfo?.minimalDays ?? 1,\n };\n}\n\nconst VIEWER_WEEK_RULES = readWeekRules(DEFAULT_LOCALE);\n\nfunction getWeekRules(locale?: string): WeekRules {\n return locale === undefined ? VIEWER_WEEK_RULES : readWeekRules(locale);\n}\n\nfunction getWeekStart(locale?: string): number {\n return getWeekRules(locale).weekStart;\n}\n\n/**\n * A day cell's aria-label, in the locale's own order.\n * @param locale - Defaults to the browser's own.\n */\nexport function getDayLabel(date: Dayjs, locale?: string): string {\n // Intl renders an instant in the viewer's zone, so pass the cell's own date.\n return dayLabelFormatter(locale).format(\n new Date(date.year(), date.month(), date.date())\n );\n}\n\nfunction startOfGridWeek(date: Dayjs, weekStart: number): Dayjs {\n // A zone that skips local midnight would otherwise leave a time of day, making the weeks ragged.\n return date\n .startOf('day')\n .subtract((date.day() - weekStart + DAYS_IN_WEEK) % DAYS_IN_WEEK, 'day');\n}\n\n/**\n * Get all days to display in a calendar month grid (including padding days from prev/next months)\n * @param month - The month to display\n * @param locale - Defaults to the browser's own.\n */\nexport function getCalendarDays(month: Dayjs, locale?: string): Dayjs[] {\n const weekStart = getWeekStart(locale);\n const firstDayOfGrid = startOfGridWeek(month.startOf('month'), weekStart);\n const lastDayOfGrid = startOfGridWeek(month.endOf('month'), weekStart).add(\n DAYS_IN_WEEK - 1,\n 'day'\n );\n\n const days: Dayjs[] = [];\n\n let currentDay = firstDayOfGrid;\n\n while (currentDay.isSameOrBefore(lastDayOfGrid, 'day')) {\n days.push(currentDay);\n currentDay = currentDay.add(1, 'day');\n }\n\n return days;\n}\n\n/**\n * Check if a date is within a given range (inclusive)\n * Uses dayjs isBetween plugin with '[]' for inclusive start and end\n * @see https://day.js.org/docs/en/plugin/is-between\n */\nexport function isDateInRange(\n date: Dayjs,\n startDate: Dayjs | null,\n endDate: Dayjs | null\n): boolean {\n if (!startDate || !endDate) {\n return false;\n }\n\n // Validate all dates are valid\n if (!date.isValid() || !startDate.isValid() || !endDate.isValid()) {\n return false;\n }\n\n // If start is after end, the range is invalid\n if (startDate.isAfter(endDate, 'day')) {\n return false;\n }\n\n // 'day' granularity ignores time, '[]' includes both start and end\n return date.isBetween(startDate, endDate, 'day', '[]');\n}\n\n/**\n * Check if a date is outside the current display month\n */\nexport function isOutsideMonth(date: Dayjs, displayMonth: Dayjs): boolean {\n return date.month() !== displayMonth.month();\n}\n\n/**\n * Check if a date is today\n * Note: Uses local timezone. Both the input date and current time are compared\n * using the user's local timezone, which is the expected behavior for calendar UIs.\n * @param date - The date to check\n * @param now - Optional current date for testing (defaults to dayjs())\n */\nexport function isToday(date: Dayjs, now?: Dayjs): boolean {\n return date.isSame(now ?? dayjs(), 'day');\n}\n\n/**\n * Get an array of weekday names (short form)\n * @param locale - Defaults to the browser's own.\n */\nexport function getWeekdayNames(locale?: string): string[] {\n const startOfWeek = startOfGridWeek(dayjs(), getWeekStart(locale));\n const formatter = weekdayFormatter(locale);\n\n return Array.from({ length: DAYS_IN_WEEK }, (_, i) =>\n formatter.format(startOfWeek.add(i, 'day').toDate())\n );\n}\n\n/**\n * The locale's month names, indexed from 0 for January as dayjs does.\n * @param locale - Defaults to the browser's own.\n */\nexport function getMonthNames(locale?: string): string[] {\n const formatter = monthFormatter(locale);\n\n // 2000 avoids the 1900s that Date remaps two-digit years into.\n return Array.from({ length: MONTHS_IN_YEAR }, (_, i) =>\n formatter.format(new Date(2000, i, 1))\n );\n}\n\n/**\n * Get the week number, counted from the weekday the grid starts on.\n * Week one is the week holding the January day the locale requires.\n * @param locale - Defaults to the browser's own.\n */\nexport function getWeekNumber(date: Dayjs, locale?: string): number {\n const { weekStart, minimalDays } = getWeekRules(locale);\n const weekBegin = startOfGridWeek(date, weekStart);\n\n const firstWeekOf = (year: number): Dayjs =>\n startOfGridWeek(dayjs(new Date(year, 0, minimalDays)), weekStart);\n\n // A late December week can belong to the next year, so start a year ahead and walk back.\n let year = weekBegin.year() + 1;\n while (weekBegin.isBefore(firstWeekOf(year), 'day')) {\n year -= 1;\n }\n\n const daysIn = weekBegin.diff(firstWeekOf(year), 'day');\n\n return Math.round(daysIn / DAYS_IN_WEEK) + 1;\n}\n\n/**\n * Get all week numbers for days in a calendar month grid\n * @param locale - Defaults to the browser's own.\n */\nexport function getWeekNumbers(days: Dayjs[], locale?: string): number[] {\n const weekNumbers: number[] = [];\n\n for (let i = 0; i < days.length; i += DAYS_IN_WEEK) {\n const firstDayOfWeek = days[i];\n if (firstDayOfWeek) {\n weekNumbers.push(getWeekNumber(firstDayOfWeek, locale));\n }\n }\n\n return weekNumbers;\n}\n\n/**\n * Check if two dates are the same day\n */\nexport function isSameDay(date1: Dayjs | null, date2: Dayjs | null): boolean {\n if (!date1 || !date2) {\n return false;\n }\n return date1.isSame(date2, 'day');\n}\n\n/**\n * Format a date range for display\n * When one date is missing, shows the format placeholder for the missing date\n */\nexport function formatDateRange(\n startDate: Dayjs | null,\n endDate: Dayjs | null,\n format: string\n): string {\n if (!startDate && !endDate) {\n return '';\n }\n\n const startStr = startDate?.format(format) ?? format;\n const endStr = endDate?.format(format) ?? format;\n\n return `${startStr}${DATE_RANGE_SEPARATOR}${endStr}`;\n}\n"],"names":["dayjs","isBetween","isSameOrBefore","DAYS_IN_WEEK","MONTHS_IN_YEAR","extend","DATE_RANGE_SEPARATOR","INTL_SUNDAY","DAY_LABEL_OPTIONS","calendar","numberingSystem","day","month","year","WEEKDAY_OPTIONS","weekday","MONTH_OPTIONS","DEFAULT_LOCALE","Intl","DateTimeFormat","resolvedOptions","locale","formatterFor","options","forViewer","undefined","dayLabelFormatter","weekdayFormatter","monthFormatter","readWeekRules","intlLocale","Locale","weekInfo","getWeekInfo","weekStart","firstDay","minimalDays","VIEWER_WEEK_RULES","getWeekRules","getWeekStart","getDayLabel","date","format","Date","startOfGridWeek","startOf","subtract","getCalendarDays","firstDayOfGrid","lastDayOfGrid","endOf","add","days","currentDay","push","isDateInRange","startDate","endDate","isValid","isAfter","isOutsideMonth","displayMonth","isToday","now","isSame","getWeekdayNames","startOfWeek","formatter","Array","from","length","_","i","toDate","getMonthNames","getWeekNumber","weekBegin","firstWeekOf","isBefore","daysIn","diff","Math","round","getWeekNumbers","weekNumbers","firstDayOfWeek","isSameDay","date1","date2","formatDateRange","startStr","endStr"],"mappings":"AAAA,OAAOA,WAA2B,QAAQ;AAC1C,OAAOC,eAAe,4BAA4B;AAClD,OAAOC,oBAAoB,iCAAiC;AAE5D,SAASC,YAAY,EAAEC,cAAc,QAAQ,iBAAc;AAE3DJ,MAAMK,MAAM,CAACJ;AACbD,MAAMK,MAAM,CAACH;AAEb,MAAMI,uBAAuB;AAE7B,MAAMC,cAAc;AAEpB,kFAAkF,GAClF,MAAMC,oBAAgD;IACpDC,UAAU;IACVC,iBAAiB;IACjBC,KAAK;IACLC,OAAO;IACPC,MAAM;AACR;AAEA,MAAMC,kBAA8C;IAAEC,SAAS;AAAQ;AAEvE,+DAA+D,GAC/D,MAAMC,gBAA4C;IAChDP,UAAU;IACVC,iBAAiB;IACjBE,OAAO;AACT;AAqBA,8EAA8E,GAC9E,MAAMK,iBAAiB,IAAIC,KAAKC,cAAc,GAAGC,eAAe,GAAGC,MAAM;AAEzE,wEAAwE,GACxE,SAASC,aACP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Aa,CAACC,SAAS;QAC1B,OAAO;IACT;IAEA,MAAMiC,WAAWlC,WAAWd,OAAOA,WAAWA;IAC9C,MAAMiD,SAASlC,SAASf,OAAOA,WAAWA;IAE1C,OAAO,GAAGgD,WAAWpF,uBAAuBqF,QAAQ;AACtD"}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { cn } from "../../../../lib/utils.js";
|
|
4
4
|
import { CalendarHeader } from "./calendar-header.js";
|
|
5
|
-
import { getCalendarDays, getWeekdayNames, getWeekNumbers, isDateInRange, isOutsideMonth, isSameDay, isToday } from "./calendar-utils.js";
|
|
5
|
+
import { getCalendarDays, getDayLabel, getWeekdayNames, getWeekNumbers, isDateInRange, isOutsideMonth, isSameDay, isToday } from "./calendar-utils.js";
|
|
6
6
|
import { DAYS_IN_WEEK } from "./constants.js";
|
|
7
7
|
function getDayCellClass({ isOutsideMonth: outside, isSelected, isToday: today, isRangeStart, isRangeEnd, isInRange, isInHoverRange }) {
|
|
8
8
|
return cn('w-9 h-9 flex items-center justify-center text-sm font-medium cursor-pointer select-none relative transition-colors', 'focus-visible:ring-2 focus-visible:ring-default focus-visible:outline-none', // border-radius for range endpoints
|
|
@@ -81,7 +81,7 @@ export const Calendar = ({ displayedMonth, selectedRange, hoverDate, displayWeek
|
|
|
81
81
|
onMouseLeave: ()=>onDateHover?.(null),
|
|
82
82
|
role: "gridcell",
|
|
83
83
|
tabIndex: 0,
|
|
84
|
-
"aria-label": day
|
|
84
|
+
"aria-label": getDayLabel(day),
|
|
85
85
|
"aria-selected": state.isSelected,
|
|
86
86
|
children: day.date()
|
|
87
87
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/calendar.tsx"],"sourcesContent":["import React, { type FC } from 'react';\n\nimport type { Dayjs } from 'dayjs';\n\nimport { cn } from '../../../../lib/utils';\n\nimport { CalendarHeader } from './calendar-header';\nimport {\n getCalendarDays,\n getWeekdayNames,\n getWeekNumbers,\n isDateInRange,\n isOutsideMonth,\n isSameDay,\n isToday,\n} from './calendar-utils';\nimport { DAYS_IN_WEEK } from './constants';\n\nexport interface CalendarProps {\n displayedMonth: Dayjs;\n selectedRange: [Dayjs | null, Dayjs | null];\n hoverDate: Dayjs | null;\n displayWeekNumber?: boolean;\n onDateClick: (date: Dayjs) => void;\n onMonthChange: (month: Dayjs) => void;\n onDateHover?: (date: Dayjs | null) => void;\n className?: string;\n}\n\ninterface DayCellState {\n isOutsideMonth: boolean;\n isToday: boolean;\n isSelected: boolean;\n isRangeStart: boolean;\n isRangeEnd: boolean;\n isInRange: boolean;\n isInHoverRange: boolean;\n}\n\nfunction getDayCellClass({\n isOutsideMonth: outside,\n isSelected,\n isToday: today,\n isRangeStart,\n isRangeEnd,\n isInRange,\n isInHoverRange,\n}: DayCellState): string {\n return cn(\n 'w-9 h-9 flex items-center justify-center text-sm font-medium cursor-pointer select-none relative transition-colors',\n 'focus-visible:ring-2 focus-visible:ring-default focus-visible:outline-none',\n // border-radius for range endpoints\n isRangeStart && isRangeEnd && 'rounded-lg',\n isRangeStart && !isRangeEnd && 'rounded-l-lg',\n isRangeEnd && !isRangeStart && 'rounded-r-lg',\n // selected endpoints\n isSelected &&\n 'bg-primary-background text-primary-foreground hover:bg-primary-background',\n // hover range preview\n !isSelected &&\n isInHoverRange &&\n 'bg-medium-background-hover text-medium-foreground',\n // committed range middle\n !isSelected &&\n isInRange &&\n !isInHoverRange &&\n 'bg-medium-background-hover text-medium-foreground',\n // default unselected text\n !isSelected &&\n !isInRange &&\n !isInHoverRange &&\n outside &&\n 'text-muted-foreground',\n !isSelected &&\n !isInRange &&\n !isInHoverRange &&\n !outside &&\n 'text-medium-foreground',\n // single-day hover (not already filled by range state)\n !isSelected &&\n !isInRange &&\n !isInHoverRange &&\n 'rounded-lg hover:bg-medium-background-hover hover:text-medium-foreground',\n // today outline\n today && !isSelected && 'border border-default rounded-lg'\n );\n}\n\nexport const Calendar: FC<CalendarProps> = ({\n displayedMonth,\n selectedRange,\n hoverDate,\n displayWeekNumber = false,\n onDateClick,\n onMonthChange,\n onDateHover,\n className,\n}) => {\n const [startDate, endDate] = selectedRange;\n\n const calendarDays = getCalendarDays(displayedMonth);\n const weekdayNames = getWeekdayNames();\n const weekNumbers = displayWeekNumber ? getWeekNumbers(calendarDays) : [];\n\n const handlePrevMonth = () => {\n onMonthChange(displayedMonth.subtract(1, 'month'));\n };\n\n const handleNextMonth = () => {\n onMonthChange(displayedMonth.add(1, 'month'));\n };\n\n const getDayState = (day: Dayjs): DayCellState => {\n const state: DayCellState = {\n isOutsideMonth: isOutsideMonth(day, displayedMonth),\n isToday: isToday(day),\n isSelected: isSameDay(day, startDate) || isSameDay(day, endDate),\n isRangeStart: isSameDay(day, startDate),\n isRangeEnd: isSameDay(day, endDate),\n isInRange: isDateInRange(day, startDate, endDate),\n isInHoverRange: false,\n };\n\n if (hoverDate && startDate && !endDate) {\n const hoverStart = startDate.isBefore(hoverDate) ? startDate : hoverDate;\n const hoverEnd = startDate.isBefore(hoverDate) ? hoverDate : startDate;\n state.isInHoverRange = isDateInRange(day, hoverStart, hoverEnd);\n }\n\n return state;\n };\n\n return (\n <div data-slot=\"calendar\" className={cn('flex flex-col gap-4', className)}>\n <CalendarHeader\n displayedMonth={displayedMonth}\n onPrevMonth={handlePrevMonth}\n onNextMonth={handleNextMonth}\n onMonthChange={onMonthChange}\n />\n\n <div\n className={cn(\n 'grid gap-0',\n displayWeekNumber ? 'grid-cols-calendar-weeks' : 'grid-cols-calendar'\n )}\n >\n {displayWeekNumber && (\n <div className=\"text-xs font-semibold text-muted-foreground text-center py-2 px-1\">\n #\n </div>\n )}\n\n {weekdayNames.map((weekday) => (\n <div\n key={weekday}\n className=\"text-xs font-medium text-muted-foreground text-center py-2 px-1 tracking-tighter\"\n >\n {weekday}\n </div>\n ))}\n\n {calendarDays.map((day, index) => {\n const state = getDayState(day);\n const weekIndex = Math.floor(index / DAYS_IN_WEEK);\n const showWeekNumber =\n displayWeekNumber && index % DAYS_IN_WEEK === 0;\n const dayKey = `day-${day.format('YYYY-MM-DD')}`;\n\n return (\n <React.Fragment key={dayKey}>\n {showWeekNumber && (\n <div className=\"text-xs text-muted-foreground text-center flex items-center justify-center h-9\">\n {weekNumbers[weekIndex]}\n </div>\n )}\n <div\n className={getDayCellClass(state)}\n onClick={() => onDateClick(day)}\n onMouseEnter={() => onDateHover?.(day)}\n onMouseLeave={() => onDateHover?.(null)}\n role=\"gridcell\"\n tabIndex={0}\n aria-label={day
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/calendar.tsx"],"sourcesContent":["import React, { type FC } from 'react';\n\nimport type { Dayjs } from 'dayjs';\n\nimport { cn } from '../../../../lib/utils';\n\nimport { CalendarHeader } from './calendar-header';\nimport {\n getCalendarDays,\n getDayLabel,\n getWeekdayNames,\n getWeekNumbers,\n isDateInRange,\n isOutsideMonth,\n isSameDay,\n isToday,\n} from './calendar-utils';\nimport { DAYS_IN_WEEK } from './constants';\n\nexport interface CalendarProps {\n displayedMonth: Dayjs;\n selectedRange: [Dayjs | null, Dayjs | null];\n hoverDate: Dayjs | null;\n displayWeekNumber?: boolean;\n onDateClick: (date: Dayjs) => void;\n onMonthChange: (month: Dayjs) => void;\n onDateHover?: (date: Dayjs | null) => void;\n className?: string;\n}\n\ninterface DayCellState {\n isOutsideMonth: boolean;\n isToday: boolean;\n isSelected: boolean;\n isRangeStart: boolean;\n isRangeEnd: boolean;\n isInRange: boolean;\n isInHoverRange: boolean;\n}\n\nfunction getDayCellClass({\n isOutsideMonth: outside,\n isSelected,\n isToday: today,\n isRangeStart,\n isRangeEnd,\n isInRange,\n isInHoverRange,\n}: DayCellState): string {\n return cn(\n 'w-9 h-9 flex items-center justify-center text-sm font-medium cursor-pointer select-none relative transition-colors',\n 'focus-visible:ring-2 focus-visible:ring-default focus-visible:outline-none',\n // border-radius for range endpoints\n isRangeStart && isRangeEnd && 'rounded-lg',\n isRangeStart && !isRangeEnd && 'rounded-l-lg',\n isRangeEnd && !isRangeStart && 'rounded-r-lg',\n // selected endpoints\n isSelected &&\n 'bg-primary-background text-primary-foreground hover:bg-primary-background',\n // hover range preview\n !isSelected &&\n isInHoverRange &&\n 'bg-medium-background-hover text-medium-foreground',\n // committed range middle\n !isSelected &&\n isInRange &&\n !isInHoverRange &&\n 'bg-medium-background-hover text-medium-foreground',\n // default unselected text\n !isSelected &&\n !isInRange &&\n !isInHoverRange &&\n outside &&\n 'text-muted-foreground',\n !isSelected &&\n !isInRange &&\n !isInHoverRange &&\n !outside &&\n 'text-medium-foreground',\n // single-day hover (not already filled by range state)\n !isSelected &&\n !isInRange &&\n !isInHoverRange &&\n 'rounded-lg hover:bg-medium-background-hover hover:text-medium-foreground',\n // today outline\n today && !isSelected && 'border border-default rounded-lg'\n );\n}\n\nexport const Calendar: FC<CalendarProps> = ({\n displayedMonth,\n selectedRange,\n hoverDate,\n displayWeekNumber = false,\n onDateClick,\n onMonthChange,\n onDateHover,\n className,\n}) => {\n const [startDate, endDate] = selectedRange;\n\n const calendarDays = getCalendarDays(displayedMonth);\n const weekdayNames = getWeekdayNames();\n const weekNumbers = displayWeekNumber ? getWeekNumbers(calendarDays) : [];\n\n const handlePrevMonth = () => {\n onMonthChange(displayedMonth.subtract(1, 'month'));\n };\n\n const handleNextMonth = () => {\n onMonthChange(displayedMonth.add(1, 'month'));\n };\n\n const getDayState = (day: Dayjs): DayCellState => {\n const state: DayCellState = {\n isOutsideMonth: isOutsideMonth(day, displayedMonth),\n isToday: isToday(day),\n isSelected: isSameDay(day, startDate) || isSameDay(day, endDate),\n isRangeStart: isSameDay(day, startDate),\n isRangeEnd: isSameDay(day, endDate),\n isInRange: isDateInRange(day, startDate, endDate),\n isInHoverRange: false,\n };\n\n if (hoverDate && startDate && !endDate) {\n const hoverStart = startDate.isBefore(hoverDate) ? startDate : hoverDate;\n const hoverEnd = startDate.isBefore(hoverDate) ? hoverDate : startDate;\n state.isInHoverRange = isDateInRange(day, hoverStart, hoverEnd);\n }\n\n return state;\n };\n\n return (\n <div data-slot=\"calendar\" className={cn('flex flex-col gap-4', className)}>\n <CalendarHeader\n displayedMonth={displayedMonth}\n onPrevMonth={handlePrevMonth}\n onNextMonth={handleNextMonth}\n onMonthChange={onMonthChange}\n />\n\n <div\n className={cn(\n 'grid gap-0',\n displayWeekNumber ? 'grid-cols-calendar-weeks' : 'grid-cols-calendar'\n )}\n >\n {displayWeekNumber && (\n <div className=\"text-xs font-semibold text-muted-foreground text-center py-2 px-1\">\n #\n </div>\n )}\n\n {weekdayNames.map((weekday) => (\n <div\n key={weekday}\n className=\"text-xs font-medium text-muted-foreground text-center py-2 px-1 tracking-tighter\"\n >\n {weekday}\n </div>\n ))}\n\n {calendarDays.map((day, index) => {\n const state = getDayState(day);\n const weekIndex = Math.floor(index / DAYS_IN_WEEK);\n const showWeekNumber =\n displayWeekNumber && index % DAYS_IN_WEEK === 0;\n const dayKey = `day-${day.format('YYYY-MM-DD')}`;\n\n return (\n <React.Fragment key={dayKey}>\n {showWeekNumber && (\n <div className=\"text-xs text-muted-foreground text-center flex items-center justify-center h-9\">\n {weekNumbers[weekIndex]}\n </div>\n )}\n <div\n className={getDayCellClass(state)}\n onClick={() => onDateClick(day)}\n onMouseEnter={() => onDateHover?.(day)}\n onMouseLeave={() => onDateHover?.(null)}\n role=\"gridcell\"\n tabIndex={0}\n aria-label={getDayLabel(day)}\n aria-selected={state.isSelected}\n >\n {day.date()}\n </div>\n </React.Fragment>\n );\n })}\n </div>\n </div>\n );\n};\n"],"names":["React","cn","CalendarHeader","getCalendarDays","getDayLabel","getWeekdayNames","getWeekNumbers","isDateInRange","isOutsideMonth","isSameDay","isToday","DAYS_IN_WEEK","getDayCellClass","outside","isSelected","today","isRangeStart","isRangeEnd","isInRange","isInHoverRange","Calendar","displayedMonth","selectedRange","hoverDate","displayWeekNumber","onDateClick","onMonthChange","onDateHover","className","startDate","endDate","calendarDays","weekdayNames","weekNumbers","handlePrevMonth","subtract","handleNextMonth","add","getDayState","day","state","hoverStart","isBefore","hoverEnd","div","data-slot","onPrevMonth","onNextMonth","map","weekday","index","weekIndex","Math","floor","showWeekNumber","dayKey","format","Fragment","onClick","onMouseEnter","onMouseLeave","role","tabIndex","aria-label","aria-selected","date"],"mappings":";AAAA,OAAOA,WAAwB,QAAQ;AAIvC,SAASC,EAAE,QAAQ,2BAAwB;AAE3C,SAASC,cAAc,QAAQ,uBAAoB;AACnD,SACEC,eAAe,EACfC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,SAAS,EACTC,OAAO,QACF,sBAAmB;AAC1B,SAASC,YAAY,QAAQ,iBAAc;AAuB3C,SAASC,gBAAgB,EACvBJ,gBAAgBK,OAAO,EACvBC,UAAU,EACVJ,SAASK,KAAK,EACdC,YAAY,EACZC,UAAU,EACVC,SAAS,EACTC,cAAc,EACD;IACb,OAAOlB,GACL,sHACA,8EACA,oCAAoC;IACpCe,gBAAgBC,cAAc,cAC9BD,gBAAgB,CAACC,cAAc,gBAC/BA,cAAc,CAACD,gBAAgB,gBAC/B,qBAAqB;IACrBF,cACE,6EACF,sBAAsB;IACtB,CAACA,cACCK,kBACA,qDACF,yBAAyB;IACzB,CAACL,cACCI,aACA,CAACC,kBACD,qDACF,0BAA0B;IAC1B,CAACL,cACC,CAACI,aACD,CAACC,kBACDN,WACA,yBACF,CAACC,cACC,CAACI,aACD,CAACC,kBACD,CAACN,WACD,0BACF,uDAAuD;IACvD,CAACC,cACC,CAACI,aACD,CAACC,kBACD,4EACF,gBAAgB;IAChBJ,SAAS,CAACD,cAAc;AAE5B;AAEA,OAAO,MAAMM,WAA8B,CAAC,EAC1CC,cAAc,EACdC,aAAa,EACbC,SAAS,EACTC,oBAAoB,KAAK,EACzBC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,SAAS,EACV;IACC,MAAM,CAACC,WAAWC,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vC;wBACrC,MAAM2C,iBACJ9B,qBAAqB0B,QAAQvC,iBAAiB;wBAChD,MAAM4C,SAAS,CAAC,IAAI,EAAEhB,IAAIiB,MAAM,CAAC,eAAe;wBAEhD,qBACE,MAACxD,MAAMyD,QAAQ;;gCACZH,gCACC,KAACV;oCAAIhB,WAAU;8CACZK,WAAW,CAACkB,UAAU;;8CAG3B,KAACP;oCACChB,WAAWhB,gBAAgB4B;oCAC3BkB,SAAS,IAAMjC,YAAYc;oCAC3BoB,cAAc,IAAMhC,cAAcY;oCAClCqB,cAAc,IAAMjC,cAAc;oCAClCkC,MAAK;oCACLC,UAAU;oCACVC,cAAY3D,YAAYmC;oCACxByB,iBAAexB,MAAM1B,UAAU;8CAE9ByB,IAAI0B,IAAI;;;2BAhBQV;oBAoBzB;;;;;AAIR,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/constants.ts"],"sourcesContent":["export const DAYS_IN_WEEK = 7;\n"],"names":["DAYS_IN_WEEK"],"mappings":"AAAA,OAAO,MAAMA,eAAe,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/calendar/constants.ts"],"sourcesContent":["export const DAYS_IN_WEEK = 7;\nexport const MONTHS_IN_YEAR = 12;\n"],"names":["DAYS_IN_WEEK","MONTHS_IN_YEAR"],"mappings":"AAAA,OAAO,MAAMA,eAAe,EAAE;AAC9B,OAAO,MAAMC,iBAAiB,GAAG"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
-
import { getDateTimeDisplayFormat } from "../date-time-pickers/utils/format-utils.js";
|
|
2
|
+
import { getDateTimeDisplayFormat, getLocaleDateFormat } from "../date-time-pickers/utils/format-utils.js";
|
|
3
3
|
const PINNED_COLUMN_Z_INDEX = 10;
|
|
4
4
|
// Only pulls the year/month/day for the calendar check below, plus whether a `T`
|
|
5
5
|
// time section is present at all — everything inside that section (seconds, offset,
|
|
6
6
|
// shape) is validated by `Date` itself instead of being re-modeled here.
|
|
7
7
|
const ISO_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(T.*)?$/;
|
|
8
|
-
const DATE_DISPLAY_FORMAT = 'DD/MM/YYYY';
|
|
9
8
|
/** Built with a placeholder year (2000) then `setFullYear`, since `Date(year, ...)`
|
|
10
9
|
* remaps any year 0-99 into 1900-1999 (e.g. "0029" → 1929). */ function isRealCalendarDate(year, month, day) {
|
|
11
10
|
const date = new Date(2000, month - 1, day);
|
|
@@ -23,7 +22,7 @@ const DATE_DISPLAY_FORMAT = 'DD/MM/YYYY';
|
|
|
23
22
|
// `Date`'s own ISO 8601 parser rejects a bad time, offset, or shape — the
|
|
24
23
|
// regex above only needs to isolate the date-only vs. datetime distinction.
|
|
25
24
|
if (Number.isNaN(new Date(value).getTime())) return undefined;
|
|
26
|
-
return dayjs(value).format(time ? getDateTimeDisplayFormat() :
|
|
25
|
+
return dayjs(value).format(time ? getDateTimeDisplayFormat() : getLocaleDateFormat());
|
|
27
26
|
}
|
|
28
27
|
function getAriaSort(sortDirection, canSort) {
|
|
29
28
|
if (sortDirection === 'asc') return 'ascending';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid.utils.ts"],"sourcesContent":["import type { ColumnDef } from '@tanstack/react-table';\nimport dayjs from 'dayjs';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid.utils.ts"],"sourcesContent":["import type { ColumnDef } from '@tanstack/react-table';\nimport dayjs from 'dayjs';\n\nimport {\n getDateTimeDisplayFormat,\n getLocaleDateFormat,\n} from '../date-time-pickers/utils/format-utils';\n\nconst PINNED_COLUMN_Z_INDEX = 10;\n\n// Only pulls the year/month/day for the calendar check below, plus whether a `T`\n// time section is present at all — everything inside that section (seconds, offset,\n// shape) is validated by `Date` itself instead of being re-modeled here.\nconst ISO_DATE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})(T.*)?$/;\n\n/** Built with a placeholder year (2000) then `setFullYear`, since `Date(year, ...)`\n * remaps any year 0-99 into 1900-1999 (e.g. \"0029\" → 1929). */\nfunction isRealCalendarDate(year: number, month: number, day: number): boolean {\n const date = new Date(2000, month - 1, day);\n date.setFullYear(year);\n return date.getMonth() === month - 1 && date.getDate() === day;\n}\n\n/**\n * API responses serialize dates as ISO strings; without this, cells would show\n * \"2026-04-11T14:30:00Z\" verbatim.\n */\nfunction formatIsoDateString(value: string): string | undefined {\n const match = ISO_DATE_PATTERN.exec(value);\n if (match === null) return undefined;\n\n const [, year, month, day, time] = match;\n if (!isRealCalendarDate(Number(year), Number(month), Number(day)))\n return undefined;\n // `Date`'s own ISO 8601 parser rejects a bad time, offset, or shape — the\n // regex above only needs to isolate the date-only vs. datetime distinction.\n if (Number.isNaN(new Date(value).getTime())) return undefined;\n\n return dayjs(value).format(\n time ? getDateTimeDisplayFormat() : getLocaleDateFormat()\n );\n}\n\nfunction getAriaSort(\n sortDirection: false | 'asc' | 'desc',\n canSort: boolean\n): 'ascending' | 'descending' | 'none' | undefined {\n if (sortDirection === 'asc') return 'ascending';\n if (sortDirection === 'desc') return 'descending';\n return canSort ? 'none' : undefined;\n}\n\nfunction getTextValue(value: unknown): string | undefined {\n if (value === null || value === undefined) return undefined;\n if (value instanceof Date) return value.toLocaleString();\n if (typeof value === 'string') return formatIsoDateString(value) ?? value;\n if (typeof value === 'object' || typeof value === 'function')\n return undefined;\n return String(value);\n}\n\nfunction isAccessorColumn<TData>(def: ColumnDef<TData>): boolean {\n const hasAccessorKey = 'accessorKey' in def && def.accessorKey !== undefined;\n const hasAccessorFn = 'accessorFn' in def && def.accessorFn !== undefined;\n return hasAccessorKey || hasAccessorFn;\n}\n\nfunction isFromIgnoredCellTarget(target?: EventTarget | null): boolean {\n return target instanceof Element\n ? Boolean(target.closest('[data-row-activation=\"ignore\"]'))\n : false;\n}\n\nfunction isFromExpandToggleTarget(target?: EventTarget | null): boolean {\n return target instanceof Element\n ? Boolean(target.closest('[data-row-expand-toggle=\"true\"]'))\n : false;\n}\n\nexport {\n PINNED_COLUMN_Z_INDEX,\n getAriaSort,\n getTextValue,\n isAccessorColumn,\n isFromExpandToggleTarget,\n isFromIgnoredCellTarget,\n};\n"],"names":["dayjs","getDateTimeDisplayFormat","getLocaleDateFormat","PINNED_COLUMN_Z_INDEX","ISO_DATE_PATTERN","isRealCalendarDate","year","month","day","date","Date","setFullYear","getMonth","getDate","formatIsoDateString","value","match","exec","undefined","time","Number","isNaN","getTime","format","getAriaSort","sortDirection","canSort","getTextValue","toLocaleString","String","isAccessorColumn","def","hasAccessorKey","accessorKey","hasAccessorFn","accessorFn","isFromIgnoredCellTarget","target","Element","Boolean","closest","isFromExpandToggleTarget"],"mappings":"AACA,OAAOA,WAAW,QAAQ;AAE1B,SACEC,wBAAwB,EACxBC,mBAAmB,QACd,6CAA0C;AAEjD,MAAMC,wBAAwB;AAE9B,iFAAiF;AACjF,oFAAoF;AACpF,yEAAyE;AACzE,MAAMC,mBAAmB;AAEzB;8DAC8D,GAC9D,SAASC,mBAAmBC,IAAY,EAAEC,KAAa,EAAEC,GAAW;IAClE,MAAMC,OAAO,IAAIC,KAAK,MAAMH,QAAQ,GAAGC;IACvCC,KAAKE,WAAW,CAACL;IACjB,OAAOG,KAAKG,QAAQ,OAAOL,QAAQ,KAAKE,KAAKI,OAAO,OAAOL;AAC7D;AAEA;;;CAGC,GACD,SAASM,oBAAoBC,KAAa;IACxC,MAAMC,QAAQZ,iBAAiBa,IAAI,CAACF;IACpC,IAAIC,UAAU,MAAM,OAAOE;IAE3B,MAAM,GAAGZ,MAAMC,OAAOC,KAAKW,KAAK,GAAGH;IACnC,IAAI,CAACX,mBAAmBe,OAAOd,OAAOc,OAAOb,QAAQa,OAAOZ,OAC1D,OAAOU;IACT,0EAA0E;IAC1E,4EAA4E;IAC5E,IAAIE,OAAOC,KAAK,CAAC,IAAIX,KAAKK,OAAOO,OAAO,KAAK,OAAOJ;IAEpD,OAAOlB,MAAMe,OAAOQ,MAAM,CACxBJ,OAAOlB,6BAA6BC;AAExC;AAEA,SAASsB,YACPC,aAAqC,EACrCC,OAAgB;IAEhB,IAAID,kBAAkB,OAAO,OAAO;IACpC,IAAIA,kBAAkB,QAAQ,OAAO;IACrC,OAAOC,UAAU,SAASR;AAC5B;AAEA,SAASS,aAAaZ,KAAc;IAClC,IAAIA,UAAU,QAAQA,UAAUG,WAAW,OAAOA;IAClD,IAAIH,iBAAiBL,MAAM,OAAOK,MAAMa,cAAc;IACtD,IAAI,OAAOb,UAAU,UAAU,OAAOD,oBAAoBC,UAAUA;IACpE,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,YAChD,OAAOG;IACT,OAAOW,OAAOd;AAChB;AAEA,SAASe,iBAAwBC,GAAqB;IACpD,MAAMC,iBAAiB,iBAAiBD,OAAOA,IAAIE,WAAW,KAAKf;IACnE,MAAMgB,gBAAgB,gBAAgBH,OAAOA,IAAII,UAAU,KAAKjB;IAChE,OAAOc,kBAAkBE;AAC3B;AAEA,SAASE,wBAAwBC,MAA2B;IAC1D,OAAOA,kBAAkBC,UACrBC,QAAQF,OAAOG,OAAO,CAAC,qCACvB;AACN;AAEA,SAASC,yBAAyBJ,MAA2B;IAC3D,OAAOA,kBAAkBC,UACrBC,QAAQF,OAAOG,OAAO,CAAC,sCACvB;AACN;AAEA,SACErC,qBAAqB,EACrBqB,WAAW,EACXG,YAAY,EACZG,gBAAgB,EAChBW,wBAAwB,EACxBL,uBAAuB,GACvB"}
|
|
@@ -5,7 +5,9 @@ import { Popover, PopoverContent, PopoverTrigger } from "../../popover/popover.j
|
|
|
5
5
|
import { DateTimeInput } from "../shared/date-time-input/date-time-input.js";
|
|
6
6
|
import { ShortcutsPanel } from "../shared/shortcuts-panel/shortcuts-panel.js";
|
|
7
7
|
import { normalizeIn, normalizeOut, normalizeShortcutValue, resolveValueType } from "../utils/date-input.js";
|
|
8
|
+
import { getLocaleDateFormat } from "../utils/format-utils.js";
|
|
8
9
|
import { useDatePicker } from "./use-date-picker.js";
|
|
10
|
+
const DEFAULT_FORMAT = getLocaleDateFormat();
|
|
9
11
|
const toSelectedRange = (date)=>date ? [
|
|
10
12
|
date,
|
|
11
13
|
date
|
|
@@ -13,7 +15,7 @@ const toSelectedRange = (date)=>date ? [
|
|
|
13
15
|
null,
|
|
14
16
|
null
|
|
15
17
|
];
|
|
16
|
-
export function DatePicker({ value, onChange, format =
|
|
18
|
+
export function DatePicker({ value, onChange, format = DEFAULT_FORMAT, placeholder, displayWeekNumber = false, shortcuts, defaultDate, valueType, className }) {
|
|
17
19
|
const resolvedType = resolveValueType(value, defaultDate, valueType);
|
|
18
20
|
const djValue = normalizeIn(value);
|
|
19
21
|
const djDefault = defaultDate != null ? normalizeIn(defaultDate) ?? undefined : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/components/ui/core/date-time-pickers/date-picker/date-picker.tsx"],"sourcesContent":["import type { JSX } from 'react';\n\nimport type { Dayjs } from 'dayjs';\n\nimport { cn } from '../../../../../lib/utils';\nimport { Calendar } from '../../calendar/calendar';\nimport { Popover, PopoverContent, PopoverTrigger } from '../../popover/popover';\nimport { DateTimeInput } from '../shared/date-time-input/date-time-input';\nimport { ShortcutsPanel } from '../shared/shortcuts-panel/shortcuts-panel';\nimport type { ShortcutItem } from '../shared/shortcuts-panel/shortcuts-panel';\nimport {\n type DateInput,\n type DateValueProps,\n normalizeIn,\n normalizeOut,\n normalizeShortcutValue,\n resolveValueType,\n} from '../utils/date-input';\n\nimport { useDatePicker } from './use-date-picker';\n\nexport type { ShortcutItem };\n\nexport interface DatePickerProps<\n T extends DateInput = Dayjs,\n> extends DateValueProps<T> {\n format?: string;\n placeholder?: string;\n displayWeekNumber?: boolean;\n shortcuts?: ShortcutItem[];\n className?: string;\n}\n\nconst toSelectedRange = (date: Dayjs | null): [Dayjs | null, Dayjs | null] =>\n date ? [date, date] : [null, null];\n\nexport function DatePicker<T extends DateInput = Dayjs>({\n value,\n onChange,\n format =
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/components/ui/core/date-time-pickers/date-picker/date-picker.tsx"],"sourcesContent":["import type { JSX } from 'react';\n\nimport type { Dayjs } from 'dayjs';\n\nimport { cn } from '../../../../../lib/utils';\nimport { Calendar } from '../../calendar/calendar';\nimport { Popover, PopoverContent, PopoverTrigger } from '../../popover/popover';\nimport { DateTimeInput } from '../shared/date-time-input/date-time-input';\nimport { ShortcutsPanel } from '../shared/shortcuts-panel/shortcuts-panel';\nimport type { ShortcutItem } from '../shared/shortcuts-panel/shortcuts-panel';\nimport {\n type DateInput,\n type DateValueProps,\n normalizeIn,\n normalizeOut,\n normalizeShortcutValue,\n resolveValueType,\n} from '../utils/date-input';\nimport { getLocaleDateFormat } from '../utils/format-utils';\n\nimport { useDatePicker } from './use-date-picker';\n\nexport type { ShortcutItem };\n\nexport interface DatePickerProps<\n T extends DateInput = Dayjs,\n> extends DateValueProps<T> {\n format?: string;\n placeholder?: string;\n displayWeekNumber?: boolean;\n shortcuts?: ShortcutItem[];\n className?: string;\n}\n\nconst DEFAULT_FORMAT = getLocaleDateFormat();\n\nconst toSelectedRange = (date: Dayjs | null): [Dayjs | null, Dayjs | null] =>\n date ? [date, date] : [null, null];\n\nexport function DatePicker<T extends DateInput = Dayjs>({\n value,\n onChange,\n format = DEFAULT_FORMAT,\n placeholder,\n displayWeekNumber = false,\n shortcuts,\n defaultDate,\n valueType,\n className,\n}: DatePickerProps<T>): JSX.Element {\n const resolvedType = resolveValueType(value, defaultDate, valueType);\n const djValue = normalizeIn(value);\n const djDefault =\n defaultDate != null ? (normalizeIn(defaultDate) ?? undefined) : undefined;\n\n const handleChange = (date: Dayjs | null) => {\n onChange(normalizeOut<T>(date, resolvedType));\n };\n\n const djShortcuts = shortcuts?.map((shortcut) => ({\n ...shortcut,\n getValue: () => normalizeShortcutValue(shortcut.getValue()),\n }));\n\n const {\n isOpen,\n displayedMonth,\n tempDate,\n handleOpenChange,\n handleDateClick,\n handleMonthChange,\n handleApplyShortcut,\n inputRef,\n popoverRef,\n } = useDatePicker({\n value: djValue,\n onChange: handleChange,\n defaultDate: djDefault,\n });\n\n const displayValue = isOpen ? tempDate : djValue;\n\n return (\n <div data-slot=\"date-picker\" className={cn('relative w-full', className)}>\n <Popover open={isOpen} onOpenChange={handleOpenChange}>\n <PopoverTrigger render={<div ref={inputRef} className=\"w-full\" />}>\n <DateTimeInput\n value={displayValue}\n format={format}\n placeholder={placeholder}\n isOpen={isOpen}\n variant=\"date\"\n />\n </PopoverTrigger>\n <PopoverContent\n ref={popoverRef}\n className=\"rounded-xl w-auto p-0\"\n side=\"bottom\"\n align=\"start\"\n >\n <div data-slot=\"date-picker-content\" className=\"flex flex-row\">\n {djShortcuts && djShortcuts.length > 0 && (\n <ShortcutsPanel\n shortcuts={djShortcuts}\n onShortcutClick={handleApplyShortcut}\n />\n )}\n <div className=\"p-3\">\n <Calendar\n displayedMonth={displayedMonth}\n selectedRange={toSelectedRange(tempDate)}\n hoverDate={null}\n displayWeekNumber={displayWeekNumber}\n onDateClick={handleDateClick}\n onMonthChange={handleMonthChange}\n />\n </div>\n </div>\n </PopoverContent>\n </Popover>\n </div>\n );\n}\n"],"names":["cn","Calendar","Popover","PopoverContent","PopoverTrigger","DateTimeInput","ShortcutsPanel","normalizeIn","normalizeOut","normalizeShortcutValue","resolveValueType","getLocaleDateFormat","useDatePicker","DEFAULT_FORMAT","toSelectedRange","date","DatePicker","value","onChange","format","placeholder","displayWeekNumber","shortcuts","defaultDate","valueType","className","resolvedType","djValue","djDefault","undefined","handleChange","djShortcuts","map","shortcut","getValue","isOpen","displayedMonth","tempDate","handleOpenChange","handleDateClick","handleMonthChange","handleApplyShortcut","inputRef","popoverRef","displayValue","div","data-slot","open","onOpenChange","render","ref","variant","side","align","length","onShortcutClick","selectedRange","hoverDate","onDateClick","onMonthChange"],"mappings":";AAIA,SAASA,EAAE,QAA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AACvB;YAAQ6C,MAAMZ;YAAQa,cAAcV;;8BACnC,KAAClC;oBAAe6C,sBAAQ,KAACJ;wBAAIK,KAAKR;wBAAUjB,WAAU;;8BACpD,cAAA,KAACpB;wBACCY,OAAO2B;wBACPzB,QAAQA;wBACRC,aAAaA;wBACbe,QAAQA;wBACRgB,SAAQ;;;8BAGZ,KAAChD;oBACC+C,KAAKP;oBACLlB,WAAU;oBACV2B,MAAK;oBACLC,OAAM;8BAEN,cAAA,MAACR;wBAAIC,aAAU;wBAAsBrB,WAAU;;4BAC5CM,eAAeA,YAAYuB,MAAM,GAAG,mBACnC,KAAChD;gCACCgB,WAAWS;gCACXwB,iBAAiBd;;0CAGrB,KAACI;gCAAIpB,WAAU;0CACb,cAAA,KAACxB;oCACCmC,gBAAgBA;oCAChBoB,eAAe1C,gBAAgBuB;oCAC/BoB,WAAW;oCACXpC,mBAAmBA;oCACnBqC,aAAanB;oCACboB,eAAenB;;;;;;;;;AAQ/B"}
|
|
@@ -5,8 +5,10 @@ import { Popover, PopoverContent, PopoverTrigger } from "../../popover/popover.j
|
|
|
5
5
|
import { DateTimeInput } from "../shared/date-time-input/date-time-input.js";
|
|
6
6
|
import { ShortcutsPanel } from "../shared/shortcuts-panel/shortcuts-panel.js";
|
|
7
7
|
import { normalizeIn, normalizeOutRange, normalizeShortcutValue, resolveValueType } from "../utils/date-input.js";
|
|
8
|
+
import { getLocaleDateFormat } from "../utils/format-utils.js";
|
|
8
9
|
import { useDateRangePicker } from "./use-date-range-picker.js";
|
|
9
|
-
|
|
10
|
+
const DEFAULT_FORMAT = getLocaleDateFormat();
|
|
11
|
+
export function DateRangePicker({ value, onChange, format = DEFAULT_FORMAT, placeholder, displayWeekNumber = false, shortcuts, defaultDate, valueType, className }) {
|
|
10
12
|
const resolvedType = resolveValueType(value[0] ?? value[1], defaultDate, valueType);
|
|
11
13
|
const djValue = [
|
|
12
14
|
normalizeIn(value[0]),
|
package/dist/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.tsx"],"sourcesContent":["import type { JSX } from 'react';\n\nimport type { Dayjs } from 'dayjs';\n\nimport { cn } from '../../../../../lib/utils';\nimport { Calendar } from '../../calendar/calendar';\nimport { Popover, PopoverContent, PopoverTrigger } from '../../popover/popover';\nimport { DateTimeInput } from '../shared/date-time-input/date-time-input';\nimport { ShortcutsPanel } from '../shared/shortcuts-panel/shortcuts-panel';\nimport type { ShortcutItem } from '../shared/shortcuts-panel/shortcuts-panel';\nimport {\n type DateInput,\n type DateRangeValueProps,\n normalizeIn,\n normalizeOutRange,\n normalizeShortcutValue,\n resolveValueType,\n} from '../utils/date-input';\n\nimport { useDateRangePicker } from './use-date-range-picker';\n\nexport type { ShortcutItem };\n\nexport interface DateRangePickerProps<\n T extends DateInput = Dayjs,\n> extends DateRangeValueProps<T> {\n format?: string;\n placeholder?: string;\n displayWeekNumber?: boolean;\n shortcuts?: ShortcutItem[];\n className?: string;\n}\n\nexport function DateRangePicker<T extends DateInput = Dayjs>({\n value,\n onChange,\n format =
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.tsx"],"sourcesContent":["import type { JSX } from 'react';\n\nimport type { Dayjs } from 'dayjs';\n\nimport { cn } from '../../../../../lib/utils';\nimport { Calendar } from '../../calendar/calendar';\nimport { Popover, PopoverContent, PopoverTrigger } from '../../popover/popover';\nimport { DateTimeInput } from '../shared/date-time-input/date-time-input';\nimport { ShortcutsPanel } from '../shared/shortcuts-panel/shortcuts-panel';\nimport type { ShortcutItem } from '../shared/shortcuts-panel/shortcuts-panel';\nimport {\n type DateInput,\n type DateRangeValueProps,\n normalizeIn,\n normalizeOutRange,\n normalizeShortcutValue,\n resolveValueType,\n} from '../utils/date-input';\nimport { getLocaleDateFormat } from '../utils/format-utils';\n\nimport { useDateRangePicker } from './use-date-range-picker';\n\nexport type { ShortcutItem };\n\nconst DEFAULT_FORMAT = getLocaleDateFormat();\n\nexport interface DateRangePickerProps<\n T extends DateInput = Dayjs,\n> extends DateRangeValueProps<T> {\n format?: string;\n placeholder?: string;\n displayWeekNumber?: boolean;\n shortcuts?: ShortcutItem[];\n className?: string;\n}\n\nexport function DateRangePicker<T extends DateInput = Dayjs>({\n value,\n onChange,\n format = DEFAULT_FORMAT,\n placeholder,\n displayWeekNumber = false,\n shortcuts,\n defaultDate,\n valueType,\n className,\n}: DateRangePickerProps<T>): JSX.Element {\n const resolvedType = resolveValueType(\n value[0] ?? value[1],\n defaultDate,\n valueType\n );\n const djValue: [Dayjs | null, Dayjs | null] = [\n normalizeIn(value[0]),\n normalizeIn(value[1]),\n ];\n const djDefault =\n defaultDate != null ? (normalizeIn(defaultDate) ?? undefined) : undefined;\n\n const handleChange = (range: [Dayjs | null, Dayjs | null]) => {\n onChange(normalizeOutRange<T>(range, resolvedType));\n };\n\n const djShortcuts = shortcuts?.map((shortcut) => ({\n ...shortcut,\n getValue: () => normalizeShortcutValue(shortcut.getValue()),\n }));\n\n const {\n isOpen,\n step,\n displayedMonth,\n tempStart,\n tempEnd,\n hoverDate,\n handleOpenChange,\n handleDateClick,\n handleMonthChange,\n handleDateHover,\n handleSetStep,\n handleApplyShortcut,\n inputRef,\n popoverRef,\n } = useDateRangePicker({\n value: djValue,\n onChange: handleChange,\n defaultDate: djDefault,\n });\n\n return (\n <div\n data-slot=\"date-range-picker\"\n className={cn('relative w-full', className)}\n >\n <Popover open={isOpen} onOpenChange={handleOpenChange}>\n <PopoverTrigger render={<div ref={inputRef} className=\"w-full\" />}>\n <DateTimeInput\n value={isOpen ? [tempStart, tempEnd] : djValue}\n format={format}\n placeholder={placeholder}\n isOpen={isOpen}\n variant=\"date\"\n activeRangePart={isOpen ? step : undefined}\n onRangePartClick={isOpen ? handleSetStep : undefined}\n />\n </PopoverTrigger>\n <PopoverContent\n ref={popoverRef}\n className=\"rounded-xl w-auto p-0\"\n side=\"bottom\"\n align=\"start\"\n >\n <div data-slot=\"date-range-picker-content\" className=\"flex flex-row\">\n {djShortcuts && djShortcuts.length > 0 && (\n <ShortcutsPanel\n shortcuts={djShortcuts}\n onShortcutClick={handleApplyShortcut}\n />\n )}\n <div className=\"p-3\">\n <Calendar\n displayedMonth={displayedMonth}\n selectedRange={[tempStart, tempEnd]}\n hoverDate={step === 'end' ? hoverDate : null}\n displayWeekNumber={displayWeekNumber}\n onDateClick={handleDateClick}\n onMonthChange={handleMonthChange}\n onDateHover={handleDateHover}\n />\n </div>\n </div>\n </PopoverContent>\n </Popover>\n </div>\n );\n}\n"],"names":["cn","Calendar","Popover","PopoverContent","PopoverTrigger","DateTimeInput","ShortcutsPanel","normalizeIn","normalizeOutRange","normalizeShortcutValue","resolveValueType","getLocaleDateFormat","useDateRangePicker","DEFAULT_FORMAT","DateRangePicker","value","onChange","format","placeholder","displayWeekNumber","shortcuts","defaultDate","valueType","className","resolvedType","djValue","djDefault","undefined","handleChange","range","djShortcuts","map","shortcut","getValue","isOpen","step","displayedMonth","tempStart","tempEnd","hoverDate","handleOpenChange","handleDateClick","handleMonthChange","handleDateHover","handleSetStep","handleApplyShortcut","inputRef","popoverRef","div","data-slot","open","onOpenChange","render","ref","variant","activeRangePart","onRangePartClick","side","align","length","onShortcutClick","selectedRange","onDateClick","onMonthChange","onDateHover"],"mappings":";AAIA,SAASA,EAAE,QAAQ,8BAA2B;AAC9C,SAASC,QAAQ,QAAQ,6BAA0B;AACnD,SAASC,OAAO,EAAEC,cAAc,EAAEC,cAAc,QAAQ,2BAAwB;AAChF,SAASC,aAAa,QAAQ,+CAA4C;AAC1E,SAASC,cAAc,QAAQ,+CAA4C;AAE3E,SAGEC,WAAW,EACXC,iBAAiB,EACjBC,sBAAsB,EACtBC,gBAAgB,QACX,yBAAsB;AAC7B,SAASC,mBAAmB,QAAQ,2BAAwB;AAE5D,SAASC,kBAAkB,QAAQ,6BAA0B;AAI7D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B,kBAAkBtB,SAASU,gBAAgBjB;;;8BAG/C,KAACxB;oBACCkD,KAAKN;oBACLxB,WAAU;oBACVkC,MAAK;oBACLC,OAAM;8BAEN,cAAA,MAACV;wBAAIC,aAAU;wBAA4B1B,WAAU;;4BAClDO,eAAeA,YAAY6B,MAAM,GAAG,mBACnC,KAACrD;gCACCc,WAAWU;gCACX8B,iBAAiBf;;0CAGrB,KAACG;gCAAIzB,WAAU;0CACb,cAAA,KAACtB;oCACCmC,gBAAgBA;oCAChByB,eAAe;wCAACxB;wCAAWC;qCAAQ;oCACnCC,WAAWJ,SAAS,QAAQI,YAAY;oCACxCpB,mBAAmBA;oCACnB2C,aAAarB;oCACbsB,eAAerB;oCACfsB,aAAarB;;;;;;;;;AAQ7B"}
|
package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { JSX } from "react";
|
|
|
2
2
|
import type { Dayjs } from "dayjs";
|
|
3
3
|
import type { ShortcutItem } from "../shared/shortcuts-panel/shortcuts-panel";
|
|
4
4
|
import { type DateInput, type DateRangeValueProps } from "../utils/date-input";
|
|
5
|
-
import type
|
|
5
|
+
import { type TimeFormat } from "../utils/format-utils";
|
|
6
6
|
export type { ShortcutItem };
|
|
7
7
|
export interface DateTimeRangePickerProps<T extends DateInput = Dayjs> extends DateRangeValueProps<T> {
|
|
8
8
|
format?: string;
|
package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.js
CHANGED
|
@@ -8,6 +8,7 @@ import { DateTimeInput } from "../shared/date-time-input/date-time-input.js";
|
|
|
8
8
|
import { ShortcutsPanel } from "../shared/shortcuts-panel/shortcuts-panel.js";
|
|
9
9
|
import { TimePickerPanel } from "../shared/time-picker-panel/time-picker-panel.js";
|
|
10
10
|
import { normalizeIn, normalizeOutRange, normalizeShortcutValue, resolveValueType } from "../utils/date-input.js";
|
|
11
|
+
import { getDateTimeDisplayFormat } from "../utils/format-utils.js";
|
|
11
12
|
import { convert12HourTo24Hour } from "../utils/time-utils.js";
|
|
12
13
|
import { useDateTimeRangePicker } from "./use-date-time-range-picker.js";
|
|
13
14
|
export function DateTimeRangePicker({ value, onChange, format, placeholder, displayWeekNumber = false, shortcuts, timeFormat = '24h', defaultDate, valueType, className }) {
|
|
@@ -30,7 +31,7 @@ export function DateTimeRangePicker({ value, onChange, format, placeholder, disp
|
|
|
30
31
|
timeFormat,
|
|
31
32
|
defaultDate: djDefault
|
|
32
33
|
});
|
|
33
|
-
const displayFormat =
|
|
34
|
+
const displayFormat = getDateTimeDisplayFormat(timeFormat, format);
|
|
34
35
|
const canProceed = step === 'start' ? tempStart !== null : tempEnd !== null;
|
|
35
36
|
const buttonLabel = step === 'start' ? 'Next' : 'Apply';
|
|
36
37
|
const buttonAction = step === 'start' ? handleNext : handleApply;
|