@gntik-ai/blocks 0.10.0 → 0.12.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/index.d.ts +1761 -1231
- package/dist/index.js +3280 -1088
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/ai/PromptEditor/PromptEditor.tsx +2 -2
- package/src/ai/PromptEditor/examples/controlled-variables.tsx +1 -1
- package/src/ai/TraceWaterfall/TraceWaterfall.tsx +2 -2
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.labels.test.tsx +179 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.test.tsx +6 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +63 -25
- package/src/auth/ForgotPasswordForm/block.meta.ts +22 -1
- package/src/auth/ForgotPasswordForm/examples/Labels.tsx +29 -0
- package/src/auth/ForgotPasswordForm/examples/LargeFields.tsx +6 -0
- package/src/auth/MfaChallenge/MfaChallenge.labels.test.tsx +139 -0
- package/src/auth/MfaChallenge/MfaChallenge.test.tsx +9 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +74 -25
- package/src/auth/MfaChallenge/block.meta.ts +29 -1
- package/src/auth/MfaChallenge/examples/Labels.tsx +28 -0
- package/src/auth/MfaChallenge/examples/LargeFields.tsx +6 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.labels.test.tsx +104 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.test.tsx +7 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +47 -18
- package/src/auth/ResetPasswordForm/block.meta.ts +17 -1
- package/src/auth/ResetPasswordForm/examples/Labels.tsx +28 -0
- package/src/auth/ResetPasswordForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SignInForm/SignInForm.labels.test.tsx +137 -0
- package/src/auth/SignInForm/SignInForm.test.tsx +7 -0
- package/src/auth/SignInForm/SignInForm.tsx +48 -17
- package/src/auth/SignInForm/block.meta.ts +22 -1
- package/src/auth/SignInForm/examples/Labels.tsx +29 -0
- package/src/auth/SignInForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SignUpForm/SignUpForm.labels.test.tsx +217 -0
- package/src/auth/SignUpForm/SignUpForm.test.tsx +22 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +72 -27
- package/src/auth/SignUpForm/block.meta.ts +27 -1
- package/src/auth/SignUpForm/examples/Labels.tsx +29 -0
- package/src/auth/SignUpForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SsoButtons/SsoButtons.labels.test.tsx +30 -0
- package/src/auth/SsoButtons/SsoButtons.tsx +10 -2
- package/src/auth/SsoButtons/block.meta.ts +8 -1
- package/src/auth/SsoButtons/examples/Labels.tsx +24 -0
- package/src/auth/__snapshots__/field-size.test.tsx.snap +11 -0
- package/src/auth/field-size.test.tsx +21 -0
- package/src/auth/large-examples.test.tsx +30 -0
- package/src/auth/shared.i18n.test.tsx +71 -0
- package/src/auth/shared.tsx +55 -13
- package/src/billing/PaymentMethodCard/PaymentMethodCard.tsx +1 -1
- package/src/billing/PlanCard/PlanCard.baseline.test.tsx +3 -2
- package/src/billing/PlanCard/__snapshots__/PlanCard.baseline.test.tsx.snap +2 -2
- package/src/billing/PlanDefinitionCard/examples/Compact.tsx +1 -4
- package/src/billing/PlanDefinitionCard/examples/Full.tsx +1 -4
- package/src/builders/CodePanel/CodePanel.tsx +2 -2
- package/src/builders/FlowBuilder/FlowBuilder.tsx +4 -19
- package/src/builders/FlowBuilder/parts.tsx +4 -4
- package/src/builders/LogViewer/LogViewer.follow.test.tsx +29 -0
- package/src/builders/LogViewer/LogViewer.levels.test.tsx +49 -0
- package/src/builders/LogViewer/LogViewer.test.tsx +24 -0
- package/src/builders/LogViewer/LogViewer.tsx +96 -28
- package/src/builders/LogViewer/LogViewer.wrap.test.tsx +181 -0
- package/src/builders/LogViewer/block.meta.ts +7 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +2 -1
- package/src/builders/LogViewer/examples/Wrap.tsx +62 -0
- package/src/builders/LogViewer/use-wrapped-log-rows.ts +42 -0
- package/src/data-display/ActivityFeed/ActivityFeed.tsx +1 -1
- package/src/data-display/ChartCard/ChartCard.tsx +2 -2
- package/src/data-display/ChartCard/examples/ContainerPanel.tsx +16 -0
- package/src/data-display/CommentThread/CommentThread.test.tsx +70 -1
- package/src/data-display/CommentThread/CommentThread.tsx +22 -6
- package/src/data-display/CommentThread/block.meta.ts +1 -1
- package/src/data-display/CommentThread/examples/RenderedBody.tsx +20 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.options.test.tsx +64 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.test.tsx +24 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +52 -37
- package/src/data-display/DescriptionListCard/block.meta.ts +2 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +9 -1
- package/src/data-display/KpiRow/KpiRow.doc.ts +14 -0
- package/src/data-display/KpiRow/KpiRow.test.tsx +11 -0
- package/src/data-display/KpiRow/KpiRow.tsx +72 -55
- package/src/data-display/KpiRow/examples/ContainerPanel.tsx +47 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.doc.ts +19 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.test.tsx +13 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.tsx +49 -40
- package/src/data-display/ResourceCardGrid/examples/ContainerPanel.tsx +18 -0
- package/src/data-display/StatusTimeline/StatusTimeline.tsx +1 -1
- package/src/feedback/EmptyStates/EmptyStates.test.tsx +42 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +37 -17
- package/src/feedback/EmptyStates/NoAccessEmpty.options.test.tsx +38 -0
- package/src/feedback/EmptyStates/block.meta.ts +1 -1
- package/src/feedback/EmptyStates/examples/HiddenAction.tsx +13 -0
- package/src/feedback/EmptyStates/examples/Spanish.tsx +7 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +13 -15
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.labels.test.tsx +115 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.lifecycle.test.tsx +123 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +153 -122
- package/src/forms/CreateApiKeyDialog/block.meta.ts +34 -2
- package/src/forms/CreateApiKeyDialog/examples/Labels.tsx +29 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.labels.test.tsx +165 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.tsx +31 -8
- package/src/forms/CredentialDisclosureDialog/SecretCopy.tsx +16 -8
- package/src/forms/CredentialDisclosureDialog/block.meta.ts +19 -1
- package/src/forms/CredentialDisclosureDialog/examples/Labels.tsx +38 -0
- package/src/forms/DangerZone/ConfirmDestructiveDialog.tsx +17 -3
- package/src/forms/DangerZone/DangerZone.labels.test.tsx +87 -0
- package/src/forms/DangerZone/DangerZone.tsx +20 -5
- package/src/forms/DangerZone/block.meta.ts +10 -1
- package/src/forms/DangerZone/examples/Labels.tsx +29 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.labels.test.tsx +52 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.tsx +11 -3
- package/src/forms/DateRangeFilter/block.meta.ts +8 -1
- package/src/forms/DateRangeFilter/examples/Labels.tsx +28 -0
- package/src/forms/DialogWizard/DialogWizard.labels.test.tsx +37 -0
- package/src/forms/DialogWizard/DialogWizard.tsx +13 -2
- package/src/forms/DialogWizard/block.meta.ts +7 -1
- package/src/forms/DialogWizard/examples/Labels.tsx +39 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.controlled.test.tsx +482 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.drag.test.tsx +60 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.labels.test.tsx +126 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.lifecycle.test.tsx +165 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +336 -75
- package/src/forms/FileUploadPanel/block.meta.ts +26 -1
- package/src/forms/FileUploadPanel/examples/AutoCancel.tsx +38 -0
- package/src/forms/FileUploadPanel/examples/Labels.tsx +29 -0
- package/src/forms/FileUploadPanel/examples/ManualForm.tsx +36 -0
- package/src/forms/FileUploadPanel/fixtures.ts +31 -16
- package/src/forms/FileUploadPanel/simulate-upload.test.ts +24 -0
- package/src/forms/FormSection/FormSection.labels.test.tsx +37 -0
- package/src/forms/FormSection/FormSection.test.tsx +11 -0
- package/src/forms/FormSection/FormSection.tsx +34 -25
- package/src/forms/FormSection/block.meta.ts +7 -1
- package/src/forms/FormSection/examples/ContainerPanel.tsx +16 -0
- package/src/forms/FormSection/examples/Labels.tsx +27 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.labels.test.tsx +87 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.lifecycle.test.tsx +80 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +121 -105
- package/src/forms/InviteMembersDialog/block.meta.ts +21 -2
- package/src/forms/InviteMembersDialog/examples/Labels.tsx +28 -0
- package/src/forms/SettingsRow/SettingsRow.labels.test.tsx +33 -0
- package/src/forms/SettingsRow/SettingsRow.tsx +14 -3
- package/src/forms/SettingsRow/block.meta.ts +7 -1
- package/src/forms/SettingsRow/examples/Labels.tsx +27 -0
- package/src/forms/ValidationSummary/ValidationSummary.labels.test.tsx +47 -0
- package/src/forms/ValidationSummary/ValidationSummary.tsx +10 -7
- package/src/forms/ValidationSummary/block.meta.ts +6 -1
- package/src/forms/ValidationSummary/examples/Labels.tsx +24 -0
- package/src/forms/index.ts +5 -1
- package/src/forms/translated-content.tsx +12 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useTableData.integration.test.tsx +89 -0
- package/src/hooks/useTableData.test.tsx +613 -0
- package/src/hooks/useTableData.ts +377 -0
- package/src/index.ts +1 -0
- package/src/marketing/ComparisonTable/ComparisonTable.tsx +2 -2
- package/src/marketing/FeatureGrid/FeatureGrid.tsx +1 -1
- package/src/marketing/LogoCloud/LogoCloud.doc.ts +13 -0
- package/src/marketing/LogoCloud/LogoCloud.test.tsx +155 -0
- package/src/marketing/LogoCloud/LogoCloud.tsx +89 -0
- package/src/marketing/LogoCloud/block.meta.ts +10 -0
- package/src/marketing/LogoCloud/examples/CaptionStart.tsx +6 -0
- package/src/marketing/LogoCloud/examples/Custom.tsx +25 -0
- package/src/marketing/LogoCloud/examples/Empty.tsx +6 -0
- package/src/marketing/LogoCloud/examples/Grid.tsx +13 -0
- package/src/marketing/LogoCloud/examples/Row.tsx +6 -0
- package/src/marketing/LogoCloud/examples/UnderHero.tsx +13 -0
- package/src/marketing/LogoCloud/fixtures.ts +23 -0
- package/src/marketing/PricingTable/PricingTable.tsx +1 -1
- package/src/marketing/SiteFooter/SiteFooter.doc.ts +18 -0
- package/src/marketing/SiteFooter/SiteFooter.test.tsx +236 -0
- package/src/marketing/SiteFooter/SiteFooter.tsx +160 -0
- package/src/marketing/SiteFooter/block.meta.ts +10 -0
- package/src/marketing/SiteFooter/examples/Centered.tsx +15 -0
- package/src/marketing/SiteFooter/examples/Columns.tsx +15 -0
- package/src/marketing/SiteFooter/examples/Custom.tsx +35 -0
- package/src/marketing/SiteFooter/examples/Empty.tsx +6 -0
- package/src/marketing/SiteFooter/examples/Simple.tsx +14 -0
- package/src/marketing/SiteFooter/fixtures.ts +36 -0
- package/src/marketing/index.ts +6 -0
- package/src/page-chrome/PageHeader/EditableTitle.test.tsx +26 -0
- package/src/page-chrome/PageHeader/PageHeader.options.test.tsx +34 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +11 -5
- package/src/page-chrome/PageHeader/block.meta.ts +1 -1
- package/src/page-chrome/PageHeader/examples/ContainerPanel.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/EditableTitle.tsx +23 -0
- package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
- package/src/page-chrome/StickyActionBar/StickyActionBar.tsx +1 -1
- package/src/scheduling/AgendaList/AgendaList.tsx +39 -15
- package/src/scheduling/AgendaList/AgendaListZone.test.tsx +38 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/TimeZone.tsx +28 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +51 -40
- package/src/scheduling/MonthCalendar/MonthCalendarZone.test.tsx +44 -0
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/TimeZone.tsx +28 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +37 -28
- package/src/scheduling/WeekCalendar/WeekCalendarZone.test.tsx +41 -0
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/TimeZone.tsx +28 -0
- package/src/scheduling/shared/CalendarHeader.tsx +26 -1
- package/src/scheduling/shared/dates.ts +102 -58
- package/src/scheduling/shared/events.ts +2 -2
- package/src/shell/AppSidebar/AppSidebar.context.test.tsx +175 -0
- package/src/shell/AppSidebar/AppSidebar.doc.ts +29 -0
- package/src/shell/AppSidebar/AppSidebar.tsx +97 -25
- package/src/shell/AppSidebar/block.meta.ts +1 -1
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +1 -0
- package/src/shell/GlobalSearch/GlobalSearch.tsx +1 -1
- package/src/tables/DataTable/DataTable.cross-page-selection.test.tsx +322 -0
- package/src/tables/DataTable/DataTable.cursor-example.test.tsx +67 -0
- package/src/tables/DataTable/DataTable.export.test.tsx +511 -0
- package/src/tables/DataTable/DataTable.inline-edit-focus.test.tsx +32 -0
- package/src/tables/DataTable/DataTable.labels.test.tsx +74 -0
- package/src/tables/DataTable/DataTable.layout.test.tsx +6 -5
- package/src/tables/DataTable/DataTable.link-actions.test.tsx +18 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +329 -15
- package/src/tables/DataTable/DataTable.single-select.test.tsx +47 -7
- package/src/tables/DataTable/DataTable.test.tsx +140 -1
- package/src/tables/DataTable/DataTable.tsx +241 -80
- package/src/tables/DataTable/block.meta.ts +31 -3
- package/src/tables/DataTable/column-sizing.ts +2 -2
- package/src/tables/DataTable/data-table-props.ts +43 -6
- package/src/tables/DataTable/data-table-row.tsx +9 -5
- package/src/tables/DataTable/data-table-utils.ts +6 -0
- package/src/tables/DataTable/editable-cell.tsx +20 -79
- package/src/tables/DataTable/examples/client-selection.tsx +33 -0
- package/src/tables/DataTable/examples/csv-export.tsx +74 -0
- package/src/tables/DataTable/examples/cursor-load-more.tsx +87 -0
- package/src/tables/DataTable/examples/paginated-single-selection.tsx +46 -0
- package/src/tables/DataTable/examples/server-pagination.tsx +91 -44
- package/src/tables/DataTable/export-menu.tsx +58 -0
- package/src/tables/DataTable/header-cell.tsx +1 -1
- package/src/tables/DataTable/labels.ts +11 -0
- package/src/tables/DataTable/resize-handle.tsx +2 -2
- package/src/tables/DataTable/selection-strip.tsx +31 -0
- package/src/tables/DataTable/single-selection.tsx +0 -7
- package/src/tables/DataTable/use-multiple-selection.ts +86 -0
- package/src/tables/DataTable/use-table-export.ts +117 -0
- package/src/tables/FilterBar/FilterBar.test.tsx +12 -0
- package/src/tables/FilterBar/FilterBar.tsx +5 -7
- package/src/team/ProfileHeader/ProfileHeader.picker.test.tsx +34 -0
- package/src/team/ProfileHeader/ProfileHeader.test.tsx +2 -2
- package/src/team/ProfileHeader/ProfileHeader.tsx +17 -24
- package/src/team/ProfileHeader/block.meta.ts +1 -1
- package/src/test/OptInDefaults.test.tsx +36 -0
- package/src/test/clipboard-fallback.test.tsx +49 -0
- package/src/test/copy-examples.test.tsx +29 -0
- package/src/test/copy-feedback.test.tsx +166 -0
- package/src/test/fixtures/opt-in-defaults.json +10 -0
- package/src/test/without-forced-colors.test.ts +44 -0
- package/src/test/without-forced-colors.ts +14 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from 'react';
|
|
2
|
-
import { cn, useI18n, localeWeekStart, type WeekDay } from '@gntik-ai/ui';
|
|
2
|
+
import { cn, useI18n, zonedParts, localeWeekStart, type WeekDay } from '@gntik-ai/ui';
|
|
3
3
|
import { useSchedulingClock } from '../shared/useSchedulingClock';
|
|
4
4
|
import { CalendarHeader } from '../shared/CalendarHeader';
|
|
5
5
|
import {
|
|
6
6
|
type HourCycle,
|
|
7
|
+
weekday,
|
|
7
8
|
addDays,
|
|
8
9
|
addMonths,
|
|
9
10
|
dayKey,
|
|
@@ -24,6 +25,8 @@ import { sampleEvents, sampleToday } from '../shared/fixtures';
|
|
|
24
25
|
|
|
25
26
|
export interface MonthCalendarProps {
|
|
26
27
|
events?: ScheduleEvent[];
|
|
28
|
+
/** Display time zone; defaults to the I18nProvider zone (system outside a provider). */
|
|
29
|
+
timeZone?: string;
|
|
27
30
|
/** Clock used for event times; defaults to the provider or runtime locale. */
|
|
28
31
|
hourCycle?: HourCycle;
|
|
29
32
|
/** First weekday; defaults to the provider or runtime locale. */
|
|
@@ -53,6 +56,7 @@ export interface MonthCalendarProps {
|
|
|
53
56
|
*/
|
|
54
57
|
export function MonthCalendar({
|
|
55
58
|
events = sampleEvents,
|
|
59
|
+
timeZone: timeZoneProp,
|
|
56
60
|
hourCycle: hourCycleProp,
|
|
57
61
|
weekStartsOn: weekStartsOnProp,
|
|
58
62
|
today = sampleToday,
|
|
@@ -65,56 +69,61 @@ export function MonthCalendar({
|
|
|
65
69
|
actions,
|
|
66
70
|
className,
|
|
67
71
|
}: MonthCalendarProps) {
|
|
68
|
-
const { t, locale, dir } = useI18n();
|
|
72
|
+
const { t, locale, dir, timeZone: providerZone } = useI18n();
|
|
73
|
+
const timeZone = timeZoneProp ?? providerZone;
|
|
69
74
|
const clock = useSchedulingClock(hourCycleProp);
|
|
70
75
|
const weekStartsOn = weekStartsOnProp ?? localeWeekStart(clock.locale);
|
|
71
76
|
const titleId = useId();
|
|
72
|
-
const [selected, setSelected] = useState<Date>(() => startOfDay(defaultSelected ?? today));
|
|
73
|
-
const [focused, setFocused] = useState<Date>(() => startOfDay(defaultSelected ?? defaultMonth ?? today));
|
|
74
|
-
const [month, setMonth] = useState<Date>(() => startOfMonth(defaultMonth ?? defaultSelected ?? today));
|
|
77
|
+
const [selected, setSelected] = useState<Date>(() => startOfDay(defaultSelected ?? today, timeZone));
|
|
78
|
+
const [focused, setFocused] = useState<Date>(() => startOfDay(defaultSelected ?? defaultMonth ?? today, timeZone));
|
|
79
|
+
const [month, setMonth] = useState<Date>(() => startOfMonth(defaultMonth ?? defaultSelected ?? today, timeZone));
|
|
75
80
|
const gridRef = useRef<HTMLDivElement>(null);
|
|
76
81
|
const moveFocus = useRef(false);
|
|
77
|
-
const byDay = useMemo(() => groupByDay(events), [events]);
|
|
78
|
-
const weeks = monthGrid(month, weekStartsOn);
|
|
82
|
+
const byDay = useMemo(() => groupByDay(events, timeZone), [events, timeZone]);
|
|
83
|
+
const weeks = monthGrid(month, weekStartsOn, timeZone);
|
|
79
84
|
const weekend = weekendDays(clock.locale);
|
|
80
85
|
// The roving tab stop stays inside the visible month.
|
|
81
|
-
const tabStop = sameMonth(focused, month
|
|
86
|
+
const tabStop = sameMonth(focused, month, timeZone)
|
|
87
|
+
? focused
|
|
88
|
+
: sameMonth(selected, month, timeZone)
|
|
89
|
+
? selected
|
|
90
|
+
: month;
|
|
82
91
|
|
|
83
92
|
useEffect(() => {
|
|
84
93
|
if (!moveFocus.current) return;
|
|
85
94
|
moveFocus.current = false;
|
|
86
|
-
gridRef.current?.querySelector<HTMLElement>(`[data-date="${dayKey(focused)}"]`)?.focus();
|
|
87
|
-
}, [focused]);
|
|
95
|
+
gridRef.current?.querySelector<HTMLElement>(`[data-date="${dayKey(focused, timeZone)}"]`)?.focus();
|
|
96
|
+
}, [focused, timeZone]);
|
|
88
97
|
|
|
89
98
|
const showMonth = (next: Date) => {
|
|
90
|
-
const first = startOfMonth(next);
|
|
99
|
+
const first = startOfMonth(next, timeZone);
|
|
91
100
|
setMonth(first);
|
|
92
101
|
onMonthChange?.(first);
|
|
93
102
|
};
|
|
94
103
|
|
|
95
104
|
const go = (date: Date) => {
|
|
96
105
|
setFocused(date);
|
|
97
|
-
if (!sameMonth(date, month)) showMonth(date);
|
|
106
|
+
if (!sameMonth(date, month, timeZone)) showMonth(date);
|
|
98
107
|
moveFocus.current = true;
|
|
99
108
|
};
|
|
100
109
|
|
|
101
110
|
const select = (date: Date) => {
|
|
102
111
|
setSelected(date);
|
|
103
112
|
setFocused(date);
|
|
104
|
-
onSelectDate?.(date, byDay.get(dayKey(date)) ?? []);
|
|
113
|
+
onSelectDate?.(date, byDay.get(dayKey(date, timeZone)) ?? []);
|
|
105
114
|
};
|
|
106
115
|
|
|
107
116
|
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>, date: Date) => {
|
|
108
|
-
const weekStart = startOfWeek(date, weekStartsOn);
|
|
117
|
+
const weekStart = startOfWeek(date, weekStartsOn, timeZone);
|
|
109
118
|
const map: Record<string, () => Date> = {
|
|
110
|
-
ArrowLeft: () => addDays(date, dir === 'rtl' ? 1 : -1),
|
|
111
|
-
ArrowRight: () => addDays(date, dir === 'rtl' ? -1 : 1),
|
|
112
|
-
ArrowUp: () => addDays(date, -7),
|
|
113
|
-
ArrowDown: () => addDays(date, 7),
|
|
119
|
+
ArrowLeft: () => addDays(date, dir === 'rtl' ? 1 : -1, timeZone),
|
|
120
|
+
ArrowRight: () => addDays(date, dir === 'rtl' ? -1 : 1, timeZone),
|
|
121
|
+
ArrowUp: () => addDays(date, -7, timeZone),
|
|
122
|
+
ArrowDown: () => addDays(date, 7, timeZone),
|
|
114
123
|
Home: () => weekStart,
|
|
115
|
-
End: () => addDays(weekStart, 6),
|
|
116
|
-
PageUp: () =>
|
|
117
|
-
PageDown: () =>
|
|
124
|
+
End: () => addDays(weekStart, 6, timeZone),
|
|
125
|
+
PageUp: () => addDays(addMonths(date, -1, timeZone), Math.min(zonedParts(date, timeZone).day, 28) - 1, timeZone),
|
|
126
|
+
PageDown: () => addDays(addMonths(date, 1, timeZone), Math.min(zonedParts(date, timeZone).day, 28) - 1, timeZone),
|
|
118
127
|
};
|
|
119
128
|
const next = map[event.key];
|
|
120
129
|
if (!next) return;
|
|
@@ -125,15 +134,17 @@ export function MonthCalendar({
|
|
|
125
134
|
return (
|
|
126
135
|
<div className={cn('overflow-hidden rounded-xl border border-border bg-card', className)}>
|
|
127
136
|
<CalendarHeader
|
|
137
|
+
timeZone={timeZone}
|
|
138
|
+
referenceDate={month}
|
|
128
139
|
titleId={titleId}
|
|
129
|
-
title={formatMonth(month, locale)}
|
|
140
|
+
title={formatMonth(month, locale, timeZone)}
|
|
130
141
|
prevLabel={t('calendar.previousMonth')}
|
|
131
142
|
nextLabel={t('calendar.nextMonth')}
|
|
132
|
-
onPrev={() => showMonth(addMonths(month, -1))}
|
|
133
|
-
onNext={() => showMonth(addMonths(month, 1))}
|
|
143
|
+
onPrev={() => showMonth(addMonths(month, -1, timeZone))}
|
|
144
|
+
onNext={() => showMonth(addMonths(month, 1, timeZone))}
|
|
134
145
|
onToday={() => {
|
|
135
146
|
showMonth(today);
|
|
136
|
-
setFocused(startOfDay(today));
|
|
147
|
+
setFocused(startOfDay(today, timeZone));
|
|
137
148
|
}}
|
|
138
149
|
actions={actions}
|
|
139
150
|
/>
|
|
@@ -141,43 +152,43 @@ export function MonthCalendar({
|
|
|
141
152
|
<div role="row" className="grid grid-cols-7 border-b border-border bg-secondary/30">
|
|
142
153
|
{(weeks[0] ?? []).map((day) => (
|
|
143
154
|
<div
|
|
144
|
-
key={day
|
|
155
|
+
key={weekday(day, timeZone)}
|
|
145
156
|
role="columnheader"
|
|
146
|
-
aria-label={formatWeekday(day, locale, 'long')}
|
|
147
|
-
className="py-2 text-center text-[11px] font-medium tracking-wide text-muted-foreground
|
|
157
|
+
aria-label={formatWeekday(day, locale, 'long', timeZone)}
|
|
158
|
+
className="py-2 text-center text-[11px] font-medium tracking-wide text-muted-foreground label-case"
|
|
148
159
|
>
|
|
149
|
-
{formatWeekday(day, locale)}
|
|
160
|
+
{formatWeekday(day, locale, 'short', timeZone)}
|
|
150
161
|
</div>
|
|
151
162
|
))}
|
|
152
163
|
</div>
|
|
153
164
|
{weeks.map((week) => (
|
|
154
|
-
<div key={dayKey(week[0] ?? month)} role="row" className="grid grid-cols-7">
|
|
165
|
+
<div key={dayKey(week[0] ?? month, timeZone)} role="row" className="grid grid-cols-7">
|
|
155
166
|
{week.map((date) => {
|
|
156
|
-
const key = dayKey(date);
|
|
167
|
+
const key = dayKey(date, timeZone);
|
|
157
168
|
const list = byDay.get(key) ?? [];
|
|
158
|
-
const inMonth = sameMonth(date, month);
|
|
159
|
-
const isToday = sameDay(date, today);
|
|
160
|
-
const isSelected = sameDay(date, selected);
|
|
169
|
+
const inMonth = sameMonth(date, month, timeZone);
|
|
170
|
+
const isToday = sameDay(date, today, timeZone);
|
|
171
|
+
const isSelected = sameDay(date, selected, timeZone);
|
|
161
172
|
const extra = list.length - maxEventsPerDay;
|
|
162
173
|
return (
|
|
163
174
|
<div
|
|
164
175
|
key={key}
|
|
165
176
|
role="gridcell"
|
|
166
|
-
data-weekend={weekend.includes(date
|
|
177
|
+
data-weekend={weekend.includes(weekday(date, timeZone)) ? '' : undefined}
|
|
167
178
|
aria-selected={isSelected}
|
|
168
179
|
className="min-w-0 border-e border-b border-border/70 [&:nth-child(7)]:border-e-0"
|
|
169
180
|
>
|
|
170
181
|
<button
|
|
171
182
|
type="button"
|
|
172
183
|
data-date={key}
|
|
173
|
-
tabIndex={sameDay(date, tabStop) ? 0 : -1}
|
|
174
|
-
aria-label={`${formatFullDate(date, locale)}${list.length ? `, ${t('calendar.events', { count: list.length })}` : ''}`}
|
|
184
|
+
tabIndex={sameDay(date, tabStop, timeZone) ? 0 : -1}
|
|
185
|
+
aria-label={`${formatFullDate(date, locale, timeZone)}${list.length ? `, ${t('calendar.events', { count: list.length })}` : ''}`}
|
|
175
186
|
aria-current={isToday ? 'date' : undefined}
|
|
176
187
|
onClick={() => select(date)}
|
|
177
188
|
onKeyDown={(e) => onKeyDown(e, date)}
|
|
178
189
|
className={cn(
|
|
179
190
|
'flex h-full min-h-14 w-full flex-col items-stretch p-1.5 text-start transition-colors motion-reduce:transition-none sm:min-h-[92px] sm:p-2',
|
|
180
|
-
'hover:bg-accent/30 focus-
|
|
191
|
+
'hover:bg-accent/30 focus-ring-inset',
|
|
181
192
|
inMonth ? 'bg-card' : 'bg-secondary/20',
|
|
182
193
|
)}
|
|
183
194
|
>
|
|
@@ -194,7 +205,7 @@ export function MonthCalendar({
|
|
|
194
205
|
: 'text-muted-foreground',
|
|
195
206
|
)}
|
|
196
207
|
>
|
|
197
|
-
{date.
|
|
208
|
+
{zonedParts(date, timeZone).day}
|
|
198
209
|
</span>
|
|
199
210
|
{isSelected && !isToday && <span aria-hidden className="size-1.5 rounded-full bg-primary" />}
|
|
200
211
|
</span>
|
|
@@ -211,7 +222,7 @@ export function MonthCalendar({
|
|
|
211
222
|
<span className={cn('size-1.5 shrink-0 rounded-full', TONE[kindOf(e, kinds).tone].dot)} />
|
|
212
223
|
<span className="truncate text-[11px] text-foreground/80">{e.title}</span>
|
|
213
224
|
<span className="ms-auto hidden shrink-0 font-mono text-[10px] text-muted-foreground xl:block">
|
|
214
|
-
{formatTime(e.start, clock.locale, clock.hourCycle)}
|
|
225
|
+
{formatTime(e.start, clock.locale, clock.hourCycle, timeZone)}
|
|
215
226
|
</span>
|
|
216
227
|
</span>
|
|
217
228
|
))}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import TimeZoneExample from './examples/TimeZone';
|
|
2
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
3
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
4
|
+
import { render, screen, within } from '@testing-library/react';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
6
|
+
import { MonthCalendar } from './MonthCalendar';
|
|
7
|
+
|
|
8
|
+
const event = {
|
|
9
|
+
id: 'late',
|
|
10
|
+
title: 'Late run',
|
|
11
|
+
start: new Date('2026-04-15T23:30:00Z'),
|
|
12
|
+
end: new Date('2026-04-16T00:00:00Z'),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('MonthCalendar display zone', () => {
|
|
16
|
+
beforeAll(() => vi.stubEnv('TZ', 'Europe/Madrid'));
|
|
17
|
+
afterAll(() => vi.unstubAllEnvs());
|
|
18
|
+
it('buckets UTC events on April 15 on a Madrid machine, and navigates UTC days', async () => {
|
|
19
|
+
const onSelectDate = vi.fn();
|
|
20
|
+
render(
|
|
21
|
+
<I18nProvider locale="en-US" timeZone="Europe/Madrid">
|
|
22
|
+
<MonthCalendar
|
|
23
|
+
timeZone="UTC"
|
|
24
|
+
events={[event]}
|
|
25
|
+
today={new Date('2026-04-15T23:30:00Z')}
|
|
26
|
+
onSelectDate={onSelectDate}
|
|
27
|
+
/>
|
|
28
|
+
</I18nProvider>,
|
|
29
|
+
);
|
|
30
|
+
const day = screen.getByRole('button', { name: 'Wednesday, April 15, 2026, 1 event' });
|
|
31
|
+
expect(within(day).getByText('Late run')).toBeInTheDocument();
|
|
32
|
+
expect(day).toHaveAttribute('aria-current', 'date');
|
|
33
|
+
expect(within(day).getByText('11:30 PM')).toBeInTheDocument();
|
|
34
|
+
expect(screen.getByText('Times in UTC')).toBeInTheDocument();
|
|
35
|
+
day.focus();
|
|
36
|
+
await userEvent.setup().keyboard('{ArrowRight}{Enter}');
|
|
37
|
+
expect(onSelectDate).toHaveBeenCalledWith(new Date('2026-04-16T00:00:00Z'), []);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('has no axe violations in the display-zone example', async () => {
|
|
42
|
+
const { container } = render(<TimeZoneExample />);
|
|
43
|
+
await expectNoAxeViolations(container);
|
|
44
|
+
});
|
|
@@ -5,6 +5,6 @@ export const meta: BlockMeta = {
|
|
|
5
5
|
family: 'scheduling',
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
|
-
'Locale-first month grid of scheduled work with per-day event lines, today/selected states, month navigation and full grid keyboard support. weekStartsOn and hourCycle override provider/runtime defaults; data-weekend marks locale weekends without styling. Locale examples show en-US, es-ES, then en-US with Monday-first and 24-hour overrides.',
|
|
8
|
+
'Locale-first month grid of scheduled work with per-day event lines, today/selected states, month navigation and full grid keyboard support. weekStartsOn and hourCycle override provider/runtime defaults; data-weekend marks locale weekends without styling. timeZone defaults to I18nProvider (system when unset); TimeZone examples demonstrate UTC, an explicit New York override and a Spanish Madrid provider. Use the same zone on server and client. Locale examples show en-US, es-ES, then en-US with Monday-first and 24-hour overrides.',
|
|
9
9
|
uses: ['Button', 'IconButton'],
|
|
10
10
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { MonthCalendar } from '../MonthCalendar';
|
|
3
|
+
|
|
4
|
+
const today = new Date('2026-04-15T13:00:00Z');
|
|
5
|
+
const events = [
|
|
6
|
+
{
|
|
7
|
+
id: 'morning',
|
|
8
|
+
title: 'Morning run',
|
|
9
|
+
start: new Date('2026-04-15T13:00:00Z'),
|
|
10
|
+
end: new Date('2026-04-15T14:00:00Z'),
|
|
11
|
+
},
|
|
12
|
+
{ id: 'late', title: 'Late run', start: new Date('2026-04-15T23:30:00Z'), end: new Date('2026-04-16T00:30:00Z') },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/** UTC provider default, New York prop override, then a Spanish Madrid provider. */
|
|
16
|
+
export default function TimeZone() {
|
|
17
|
+
return (
|
|
18
|
+
<div className="space-y-6">
|
|
19
|
+
<I18nProvider locale="en-US" timeZone="UTC">
|
|
20
|
+
<MonthCalendar today={today} events={events} />
|
|
21
|
+
<MonthCalendar today={today} events={events} timeZone="America/New_York" />
|
|
22
|
+
</I18nProvider>
|
|
23
|
+
<I18nProvider locale="es-ES" timeZone="Europe/Madrid">
|
|
24
|
+
<MonthCalendar today={today} events={events} />
|
|
25
|
+
</I18nProvider>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
|
-
import { cn, useI18n, localeWeekStart, type WeekDay } from '@gntik-ai/ui';
|
|
2
|
+
import { cn, useI18n, zonedParts, localeWeekStart, type WeekDay } from '@gntik-ai/ui';
|
|
3
3
|
import { useSchedulingClock } from '../shared/useSchedulingClock';
|
|
4
4
|
import { CalendarHeader } from '../shared/CalendarHeader';
|
|
5
5
|
import {
|
|
6
6
|
type HourCycle,
|
|
7
|
+
weekday,
|
|
7
8
|
formatHour,
|
|
8
9
|
addDays,
|
|
9
10
|
dayKey,
|
|
@@ -23,6 +24,8 @@ import { sampleEvents, sampleToday } from '../shared/fixtures';
|
|
|
23
24
|
|
|
24
25
|
export interface WeekCalendarProps {
|
|
25
26
|
events?: ScheduleEvent[];
|
|
27
|
+
/** Display time zone; defaults to the I18nProvider zone (system outside a provider). */
|
|
28
|
+
timeZone?: string;
|
|
26
29
|
/** First weekday; defaults to the provider or runtime locale. */
|
|
27
30
|
weekStartsOn?: WeekDay;
|
|
28
31
|
/** Clock used for events and hour labels; defaults to the provider or runtime locale. */
|
|
@@ -59,7 +62,7 @@ interface Placed {
|
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
/** Side-by-side lanes for overlapping events within one day. */
|
|
62
|
-
function layoutDay(list: readonly ScheduleEvent[], hourHeight: number): Placed[] {
|
|
65
|
+
function layoutDay(list: readonly ScheduleEvent[], hourHeight: number, timeZone: string): Placed[] {
|
|
63
66
|
const placed: Placed[] = [];
|
|
64
67
|
let cluster: Placed[] = [];
|
|
65
68
|
let clusterEnd = -1;
|
|
@@ -70,8 +73,8 @@ function layoutDay(list: readonly ScheduleEvent[], hourHeight: number): Placed[]
|
|
|
70
73
|
laneEnds = [];
|
|
71
74
|
};
|
|
72
75
|
for (const event of list) {
|
|
73
|
-
const start = hourOf(event.start);
|
|
74
|
-
const end = Math.max(sameDay(event.start, event.end) ? hourOf(event.end) : 24, start + 0.25);
|
|
76
|
+
const start = hourOf(event.start, timeZone);
|
|
77
|
+
const end = Math.max(sameDay(event.start, event.end, timeZone) ? hourOf(event.end, timeZone) : 24, start + 0.25);
|
|
75
78
|
if (start >= clusterEnd) close();
|
|
76
79
|
let lane = laneEnds.findIndex((e) => e <= start);
|
|
77
80
|
if (lane === -1) {
|
|
@@ -96,6 +99,7 @@ function layoutDay(list: readonly ScheduleEvent[], hourHeight: number): Placed[]
|
|
|
96
99
|
/** Week view: seven day columns over a scrolling 24-hour time grid, with a "now" line. */
|
|
97
100
|
export function WeekCalendar({
|
|
98
101
|
events = sampleEvents,
|
|
102
|
+
timeZone: timeZoneProp,
|
|
99
103
|
weekStartsOn: weekStartsOnProp,
|
|
100
104
|
hourCycle: hourCycleProp,
|
|
101
105
|
today = sampleToday,
|
|
@@ -110,18 +114,19 @@ export function WeekCalendar({
|
|
|
110
114
|
actions,
|
|
111
115
|
className,
|
|
112
116
|
}: WeekCalendarProps) {
|
|
113
|
-
const { t, locale } = useI18n();
|
|
117
|
+
const { t, locale, timeZone: providerZone } = useI18n();
|
|
118
|
+
const timeZone = timeZoneProp ?? providerZone;
|
|
114
119
|
const clock = useSchedulingClock(hourCycleProp);
|
|
115
120
|
const weekStartsOn = weekStartsOnProp ?? localeWeekStart(clock.locale);
|
|
116
121
|
const titleId = useId();
|
|
117
|
-
const [weekStart, setWeekStart] = useState<Date>(() => startOfWeek(defaultWeek ?? today, weekStartsOn));
|
|
122
|
+
const [weekStart, setWeekStart] = useState<Date>(() => startOfWeek(defaultWeek ?? today, weekStartsOn, timeZone));
|
|
118
123
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
119
|
-
const byDay = useMemo(() => groupByDay(events), [events]);
|
|
120
|
-
const days = weekDays(weekStart, weekStartsOn);
|
|
124
|
+
const byDay = useMemo(() => groupByDay(events, timeZone), [events, timeZone]);
|
|
125
|
+
const days = weekDays(weekStart, weekStartsOn, timeZone);
|
|
121
126
|
const visibleStart = days[0] ?? weekStart;
|
|
122
127
|
const weekend = weekendDays(clock.locale);
|
|
123
128
|
const nowAt = now ?? today;
|
|
124
|
-
const nowVisible = days.some((d) => sameDay(d, nowAt));
|
|
129
|
+
const nowVisible = days.some((d) => sameDay(d, nowAt, timeZone));
|
|
125
130
|
|
|
126
131
|
useEffect(() => {
|
|
127
132
|
if (scrollRef.current) scrollRef.current.scrollTop = Math.max(scrollToHour * hourHeight - 8, 0);
|
|
@@ -135,13 +140,15 @@ export function WeekCalendar({
|
|
|
135
140
|
return (
|
|
136
141
|
<div className={cn('overflow-hidden rounded-xl border border-border bg-card', className)}>
|
|
137
142
|
<CalendarHeader
|
|
143
|
+
timeZone={timeZone}
|
|
144
|
+
referenceDate={visibleStart}
|
|
138
145
|
titleId={titleId}
|
|
139
|
-
title={formatWeekRange(days, locale)}
|
|
146
|
+
title={formatWeekRange(days, locale, timeZone)}
|
|
140
147
|
prevLabel={t('calendar.previousWeek')}
|
|
141
148
|
nextLabel={t('calendar.nextWeek')}
|
|
142
|
-
onPrev={() => show(addDays(visibleStart, -7))}
|
|
143
|
-
onNext={() => show(addDays(visibleStart, 7))}
|
|
144
|
-
onToday={() => show(startOfWeek(today, weekStartsOn))}
|
|
149
|
+
onPrev={() => show(addDays(visibleStart, -7, timeZone))}
|
|
150
|
+
onNext={() => show(addDays(visibleStart, 7, timeZone))}
|
|
151
|
+
onToday={() => show(startOfWeek(today, weekStartsOn, timeZone))}
|
|
145
152
|
actions={actions}
|
|
146
153
|
/>
|
|
147
154
|
<div className="overflow-x-auto">
|
|
@@ -150,20 +157,22 @@ export function WeekCalendar({
|
|
|
150
157
|
<div className="w-14 shrink-0 border-e border-border/70" />
|
|
151
158
|
<div className="grid flex-1 grid-cols-7">
|
|
152
159
|
{days.map((d) => {
|
|
153
|
-
const isToday = sameDay(d, today);
|
|
160
|
+
const isToday = sameDay(d, today, timeZone);
|
|
154
161
|
return (
|
|
155
162
|
<div
|
|
156
|
-
key={dayKey(d)}
|
|
163
|
+
key={dayKey(d, timeZone)}
|
|
157
164
|
className="flex flex-col items-center justify-center border-s border-border/70 py-2 first:border-s-0"
|
|
158
165
|
>
|
|
159
|
-
<span className="text-[11px] text-muted-foreground">
|
|
166
|
+
<span className="text-[11px] text-muted-foreground">
|
|
167
|
+
{formatWeekday(d, locale, 'short', timeZone)}
|
|
168
|
+
</span>
|
|
160
169
|
<span
|
|
161
170
|
className={cn(
|
|
162
171
|
'mt-1 inline-flex size-7 items-center justify-center rounded-full text-[13px] tabular-nums',
|
|
163
172
|
isToday ? 'bg-primary font-semibold text-primary-foreground' : 'font-medium text-foreground',
|
|
164
173
|
)}
|
|
165
174
|
>
|
|
166
|
-
{d.
|
|
175
|
+
{zonedParts(d, timeZone).day}
|
|
167
176
|
</span>
|
|
168
177
|
</div>
|
|
169
178
|
);
|
|
@@ -174,8 +183,8 @@ export function WeekCalendar({
|
|
|
174
183
|
ref={scrollRef}
|
|
175
184
|
tabIndex={0}
|
|
176
185
|
role="region"
|
|
177
|
-
aria-labelledby={titleId}
|
|
178
|
-
className="overflow-y-auto focus-
|
|
186
|
+
aria-labelledby={timeZone === 'system' ? titleId : `${titleId} ${titleId}-zone`}
|
|
187
|
+
className="overflow-y-auto focus-ring-inset"
|
|
179
188
|
style={{ maxHeight: height }}
|
|
180
189
|
>
|
|
181
190
|
<div className="relative flex" style={{ height: 24 * hourHeight }}>
|
|
@@ -202,25 +211,25 @@ export function WeekCalendar({
|
|
|
202
211
|
</div>
|
|
203
212
|
<div className="relative grid h-full grid-cols-7">
|
|
204
213
|
{days.map((d) => {
|
|
205
|
-
const list = byDay.get(dayKey(d)) ?? [];
|
|
214
|
+
const list = byDay.get(dayKey(d, timeZone)) ?? [];
|
|
206
215
|
return (
|
|
207
216
|
<ul
|
|
208
|
-
key={dayKey(d)}
|
|
209
|
-
data-weekend={weekend.includes(d
|
|
210
|
-
aria-label={formatDay(d, locale)}
|
|
217
|
+
key={dayKey(d, timeZone)}
|
|
218
|
+
data-weekend={weekend.includes(weekday(d, timeZone)) ? '' : undefined}
|
|
219
|
+
aria-label={formatDay(d, locale, timeZone)}
|
|
211
220
|
className="relative border-s border-border/70 first:border-s-0"
|
|
212
221
|
>
|
|
213
|
-
{layoutDay(list, hourHeight).map(({ event, top, height: h, lane, lanes }) => {
|
|
222
|
+
{layoutDay(list, hourHeight, timeZone).map(({ event, top, height: h, lane, lanes }) => {
|
|
214
223
|
const kind = kindOf(event, kinds);
|
|
215
224
|
const tone = TONE[kind.tone];
|
|
216
|
-
const range = formatRange(event.start, event.end, clock.locale, clock.hourCycle);
|
|
225
|
+
const range = formatRange(event.start, event.end, clock.locale, clock.hourCycle, timeZone);
|
|
217
226
|
const body = (
|
|
218
227
|
<>
|
|
219
228
|
<span className="block truncate text-[11px] leading-tight font-semibold text-foreground">
|
|
220
229
|
{event.title}
|
|
221
230
|
</span>
|
|
222
231
|
<span className="block truncate font-mono text-[10px] text-foreground">
|
|
223
|
-
{formatTime(event.start, clock.locale, clock.hourCycle)}
|
|
232
|
+
{formatTime(event.start, clock.locale, clock.hourCycle, timeZone)}
|
|
224
233
|
</span>
|
|
225
234
|
</>
|
|
226
235
|
);
|
|
@@ -268,8 +277,8 @@ export function WeekCalendar({
|
|
|
268
277
|
{nowVisible && (
|
|
269
278
|
<div
|
|
270
279
|
aria-hidden
|
|
271
|
-
className="pointer-events-none absolute inset-x-0 z-
|
|
272
|
-
style={{ top: hourOf(nowAt) * hourHeight }}
|
|
280
|
+
className="pointer-events-none absolute inset-x-0 z-raised flex items-center"
|
|
281
|
+
style={{ top: hourOf(nowAt, timeZone) * hourHeight }}
|
|
273
282
|
>
|
|
274
283
|
<span className="-ms-1 size-2 shrink-0 rounded-full bg-primary" />
|
|
275
284
|
<span className="h-px flex-1 bg-primary" />
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import TimeZoneExample from './examples/TimeZone';
|
|
2
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
3
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import { WeekCalendar } from './WeekCalendar';
|
|
6
|
+
|
|
7
|
+
it('places events and the now line on the New York clock inherited from the provider', () => {
|
|
8
|
+
vi.stubEnv('TZ', 'Europe/Madrid');
|
|
9
|
+
try {
|
|
10
|
+
render(
|
|
11
|
+
<I18nProvider locale="en-US" timeZone="America/New_York">
|
|
12
|
+
<WeekCalendar
|
|
13
|
+
weekStartsOn={1}
|
|
14
|
+
hourHeight={60}
|
|
15
|
+
today={new Date('2026-04-15T13:00:00Z')}
|
|
16
|
+
now={new Date('2026-04-15T13:30:00Z')}
|
|
17
|
+
events={[
|
|
18
|
+
{
|
|
19
|
+
id: 'ny',
|
|
20
|
+
title: 'Morning run',
|
|
21
|
+
start: new Date('2026-04-15T13:00:00Z'),
|
|
22
|
+
end: new Date('2026-04-15T14:00:00Z'),
|
|
23
|
+
},
|
|
24
|
+
]}
|
|
25
|
+
/>
|
|
26
|
+
</I18nProvider>,
|
|
27
|
+
);
|
|
28
|
+
expect(screen.getByText('Morning run').closest('li')).toHaveStyle({ top: '541px' });
|
|
29
|
+
expect(screen.getByText('Times in America/New_York (EDT)')).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByText('9:00 AM')).toBeInTheDocument();
|
|
31
|
+
expect(screen.getByText('Morning run').closest('ul')).toHaveAccessibleName('Wednesday, April 15');
|
|
32
|
+
expect(screen.getByText('now').parentElement).toHaveStyle({ top: '570px' });
|
|
33
|
+
} finally {
|
|
34
|
+
vi.unstubAllEnvs();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('has no axe violations in the display-zone example', async () => {
|
|
39
|
+
const { container } = render(<TimeZoneExample />);
|
|
40
|
+
await expectNoAxeViolations(container);
|
|
41
|
+
});
|
|
@@ -5,6 +5,6 @@ export const meta: BlockMeta = {
|
|
|
5
5
|
family: 'scheduling',
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
|
-
'Locale-first seven-day time grid with positioned events (overlaps side by side), a now line, week navigation and optional clickable events. weekStartsOn and hourCycle override provider/runtime defaults; data-weekend marks locale weekends without styling. Locale examples show en-US, es-ES, then en-US with Monday-first and 24-hour overrides.',
|
|
8
|
+
'Locale-first seven-day time grid with positioned events (overlaps side by side), a now line, week navigation and optional clickable events. weekStartsOn and hourCycle override provider/runtime defaults; data-weekend marks locale weekends without styling. timeZone defaults to I18nProvider (system when unset); TimeZone examples demonstrate UTC, an explicit New York override and a Spanish Madrid provider. Use the same zone on server and client. Locale examples show en-US, es-ES, then en-US with Monday-first and 24-hour overrides.',
|
|
9
9
|
uses: ['Button', 'IconButton'],
|
|
10
10
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { WeekCalendar } from '../WeekCalendar';
|
|
3
|
+
|
|
4
|
+
const today = new Date('2026-04-15T13:00:00Z');
|
|
5
|
+
const events = [
|
|
6
|
+
{
|
|
7
|
+
id: 'morning',
|
|
8
|
+
title: 'Morning run',
|
|
9
|
+
start: new Date('2026-04-15T13:00:00Z'),
|
|
10
|
+
end: new Date('2026-04-15T14:00:00Z'),
|
|
11
|
+
},
|
|
12
|
+
{ id: 'late', title: 'Late run', start: new Date('2026-04-15T23:30:00Z'), end: new Date('2026-04-16T00:30:00Z') },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/** UTC provider default, New York prop override, then a Spanish Madrid provider. */
|
|
16
|
+
export default function TimeZone() {
|
|
17
|
+
return (
|
|
18
|
+
<div className="space-y-6">
|
|
19
|
+
<I18nProvider locale="en-US" timeZone="UTC">
|
|
20
|
+
<WeekCalendar today={today} events={events} />
|
|
21
|
+
<WeekCalendar today={today} events={events} timeZone="America/New_York" />
|
|
22
|
+
</I18nProvider>
|
|
23
|
+
<I18nProvider locale="es-ES" timeZone="Europe/Madrid">
|
|
24
|
+
<WeekCalendar today={today} events={events} />
|
|
25
|
+
</I18nProvider>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import { Button, IconButton, useI18n } from '@gntik-ai/ui';
|
|
2
|
+
import { Button, IconButton, useI18n, formatTimeZoneLabel } from '@gntik-ai/ui';
|
|
3
3
|
import { ChevronLeft, ChevronRight } from '@gntik-ai/icons';
|
|
4
4
|
|
|
5
5
|
export interface CalendarHeaderProps {
|
|
6
6
|
titleId: string;
|
|
7
|
+
timeZone?: string;
|
|
8
|
+
referenceDate?: Date;
|
|
7
9
|
title: string;
|
|
8
10
|
subtitle?: string;
|
|
9
11
|
prevLabel: string;
|
|
@@ -16,6 +18,8 @@ export interface CalendarHeaderProps {
|
|
|
16
18
|
|
|
17
19
|
/** Title + previous / today / next navigation + caller actions. */
|
|
18
20
|
export function CalendarHeader({
|
|
21
|
+
timeZone = 'system',
|
|
22
|
+
referenceDate,
|
|
19
23
|
titleId,
|
|
20
24
|
title,
|
|
21
25
|
subtitle,
|
|
@@ -37,6 +41,7 @@ export function CalendarHeader({
|
|
|
37
41
|
>
|
|
38
42
|
{title}
|
|
39
43
|
</h3>
|
|
44
|
+
<TimeZoneLabel id={`${titleId}-zone`} timeZone={timeZone} referenceDate={referenceDate} />
|
|
40
45
|
{subtitle && <p className="mt-0.5 truncate font-mono text-[11px] text-muted-foreground">{subtitle}</p>}
|
|
41
46
|
</div>
|
|
42
47
|
<div className="flex shrink-0 items-center gap-2">
|
|
@@ -52,3 +57,23 @@ export function CalendarHeader({
|
|
|
52
57
|
</div>
|
|
53
58
|
);
|
|
54
59
|
}
|
|
60
|
+
|
|
61
|
+
/** Shared, wrapping zone caption for calendar and agenda headers. */
|
|
62
|
+
export function TimeZoneLabel({
|
|
63
|
+
id,
|
|
64
|
+
timeZone,
|
|
65
|
+
referenceDate,
|
|
66
|
+
}: {
|
|
67
|
+
id?: string;
|
|
68
|
+
timeZone: string;
|
|
69
|
+
referenceDate?: Date;
|
|
70
|
+
}) {
|
|
71
|
+
const { t } = useI18n();
|
|
72
|
+
if (timeZone === 'system') return null;
|
|
73
|
+
const zone = timeZone === 'UTC' ? 'UTC' : `${timeZone} (${formatTimeZoneLabel(timeZone, referenceDate, 'en-US')})`;
|
|
74
|
+
return (
|
|
75
|
+
<p id={id} className="mt-0.5 break-words text-[11px] text-muted-foreground">
|
|
76
|
+
{t('scheduling.timeZone', { zone })}
|
|
77
|
+
</p>
|
|
78
|
+
);
|
|
79
|
+
}
|