@gntik-ai/blocks 0.9.0 → 0.11.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 +426 -55
- package/dist/index.js +2275 -639
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.labels.test.tsx +179 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +59 -24
- package/src/auth/ForgotPasswordForm/block.meta.ts +22 -1
- package/src/auth/ForgotPasswordForm/examples/Labels.tsx +29 -0
- package/src/auth/MfaChallenge/MfaChallenge.labels.test.tsx +139 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +69 -23
- package/src/auth/MfaChallenge/block.meta.ts +29 -1
- package/src/auth/MfaChallenge/examples/Labels.tsx +28 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.labels.test.tsx +104 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +42 -15
- package/src/auth/ResetPasswordForm/block.meta.ts +17 -1
- package/src/auth/ResetPasswordForm/examples/Labels.tsx +28 -0
- package/src/auth/SignInForm/SignInForm.labels.test.tsx +137 -0
- package/src/auth/SignInForm/SignInForm.tsx +43 -16
- package/src/auth/SignInForm/block.meta.ts +22 -1
- package/src/auth/SignInForm/examples/Labels.tsx +29 -0
- package/src/auth/SignUpForm/SignUpForm.labels.test.tsx +217 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +65 -26
- package/src/auth/SignUpForm/block.meta.ts +27 -1
- package/src/auth/SignUpForm/examples/Labels.tsx +29 -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/shared.i18n.test.tsx +71 -0
- package/src/auth/shared.tsx +48 -11
- package/src/billing/CostBreakdown/CostBreakdown.test.tsx +10 -0
- package/src/billing/CostBreakdown/CostBreakdown.tsx +50 -43
- package/src/billing/SpendVsBudget/SpendVsBudget.test.tsx +10 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.tsx +35 -31
- package/src/builders/FlowBuilder/FlowBuilder.test.tsx +237 -2
- package/src/builders/FlowBuilder/FlowBuilder.tsx +101 -29
- package/src/builders/FlowBuilder/block.meta.ts +1 -1
- package/src/builders/FlowBuilder/connections.ts +30 -12
- package/src/builders/FlowBuilder/examples/ControlledGraph.tsx +8 -0
- package/src/builders/FlowBuilder/graph-state.ts +78 -0
- package/src/builders/LogViewer/LogViewer.labels.test.tsx +90 -0
- package/src/builders/LogViewer/LogViewer.levels.test.tsx +49 -0
- package/src/builders/LogViewer/LogViewer.tsx +72 -18
- package/src/builders/LogViewer/LogViewer.wrap.test.tsx +181 -0
- package/src/builders/LogViewer/block.meta.ts +19 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +30 -0
- package/src/builders/LogViewer/examples/Wrap.tsx +62 -0
- package/src/builders/LogViewer/use-wrapped-log-rows.ts +42 -0
- package/src/data-display/ChartCard/ChartCard.locale.test.tsx +15 -0
- package/src/data-display/ChartCard/ChartCard.test.tsx +9 -0
- package/src/data-display/ChartCard/ChartCard.tsx +81 -67
- package/src/data-display/ChartCard/block.meta.ts +1 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.labels.test.tsx +73 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.options.test.tsx +64 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +74 -23
- package/src/data-display/DescriptionListCard/block.meta.ts +11 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +29 -0
- package/src/feedback/EmptyStates/EmptyStates.labels.test.tsx +185 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +101 -30
- package/src/feedback/EmptyStates/NoAccessEmpty.options.test.tsx +38 -0
- package/src/feedback/EmptyStates/block.meta.ts +73 -1
- package/src/feedback/EmptyStates/examples/Spanish.tsx +48 -0
- package/src/feedback/ErrorPanel/ErrorPanel.labels.test.tsx +99 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +38 -9
- package/src/feedback/ErrorPanel/block.meta.ts +19 -1
- package/src/feedback/ErrorPanel/examples/Spanish.tsx +30 -0
- package/src/feedback/InlineCallout/InlineCallout.labels.test.tsx +62 -0
- package/src/feedback/InlineCallout/InlineCallout.tsx +22 -9
- package/src/feedback/InlineCallout/block.meta.ts +9 -1
- package/src/feedback/InlineCallout/examples/Spanish.tsx +19 -0
- package/src/feedback/Skeletons/Skeletons.labels.test.tsx +24 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.labels.test.tsx +115 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +63 -21
- package/src/forms/CreateApiKeyDialog/block.meta.ts +22 -1
- 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.labels.test.tsx +126 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.test.tsx +22 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +85 -22
- package/src/forms/FileUploadPanel/block.meta.ts +22 -1
- package/src/forms/FileUploadPanel/examples/Labels.tsx +29 -0
- package/src/forms/FileUploadPanel/fixtures.ts +0 -12
- package/src/forms/FileUploadPanel/format-bytes.test.ts +8 -0
- package/src/forms/FormSection/FormSection.labels.test.tsx +37 -0
- package/src/forms/FormSection/FormSection.tsx +14 -3
- package/src/forms/FormSection/block.meta.ts +7 -1
- package/src/forms/FormSection/examples/Labels.tsx +27 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.labels.test.tsx +87 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +51 -16
- package/src/forms/InviteMembersDialog/block.meta.ts +20 -1
- 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 +9 -3
- 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/page-chrome/PageHeader/PageHeader.labels.test.tsx +56 -0
- package/src/page-chrome/PageHeader/PageHeader.options.test.tsx +34 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +26 -5
- package/src/page-chrome/PageHeader/block.meta.ts +8 -1
- package/src/page-chrome/PageHeader/examples/Labels.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
- package/src/scheduling/AgendaList/AgendaList.test.tsx +25 -0
- package/src/scheduling/AgendaList/AgendaList.tsx +7 -2
- package/src/scheduling/AgendaList/AgendaListLocale.test.tsx +11 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/Locale.tsx +29 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.test.tsx +111 -1
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +19 -9
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.test.tsx +73 -2
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +26 -12
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/shared/dates.test.ts +75 -0
- package/src/scheduling/shared/dates.ts +46 -22
- package/src/scheduling/shared/useSchedulingClock.ts +13 -0
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +12 -0
- package/src/shell/GlobalSearch/fixtures.ts +2 -2
- package/src/tables/DataTable/DataTable.cross-page-selection.test.tsx +322 -0
- package/src/tables/DataTable/DataTable.labels.test.tsx +74 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +1 -1
- package/src/tables/DataTable/DataTable.single-select.test.tsx +47 -7
- package/src/tables/DataTable/DataTable.test.tsx +55 -0
- package/src/tables/DataTable/DataTable.tsx +134 -67
- package/src/tables/DataTable/block.meta.ts +21 -3
- package/src/tables/DataTable/data-table-props.ts +14 -5
- package/src/tables/DataTable/data-table-row.tsx +7 -3
- package/src/tables/DataTable/data-table-utils.ts +2 -0
- package/src/tables/DataTable/examples/client-selection.tsx +33 -0
- package/src/tables/DataTable/examples/paginated-single-selection.tsx +46 -0
- package/src/tables/DataTable/examples/server-pagination.tsx +55 -15
- package/src/tables/DataTable/labels.ts +4 -0
- 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/PaginationFooter/PaginationFooter.i18n.test.tsx +26 -0
- package/src/test/OptInDefaults.test.tsx +27 -0
- package/src/test/fixtures/opt-in-defaults.json +10 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
|
-
import { cn, useI18n } from '@gntik-ai/ui';
|
|
2
|
+
import { cn, useI18n, localeWeekStart, type WeekDay } from '@gntik-ai/ui';
|
|
3
|
+
import { useSchedulingClock } from '../shared/useSchedulingClock';
|
|
3
4
|
import { CalendarHeader } from '../shared/CalendarHeader';
|
|
4
5
|
import {
|
|
6
|
+
type HourCycle,
|
|
7
|
+
formatHour,
|
|
5
8
|
addDays,
|
|
6
9
|
dayKey,
|
|
7
10
|
formatDay,
|
|
@@ -13,19 +16,24 @@ import {
|
|
|
13
16
|
sameDay,
|
|
14
17
|
startOfWeek,
|
|
15
18
|
weekDays,
|
|
19
|
+
weekendDays,
|
|
16
20
|
} from '../shared/dates';
|
|
17
21
|
import { defaultEventKinds, groupByDay, kindOf, TONE, type EventKind, type ScheduleEvent } from '../shared/events';
|
|
18
22
|
import { sampleEvents, sampleToday } from '../shared/fixtures';
|
|
19
23
|
|
|
20
24
|
export interface WeekCalendarProps {
|
|
21
25
|
events?: ScheduleEvent[];
|
|
26
|
+
/** First weekday; defaults to the provider or runtime locale. */
|
|
27
|
+
weekStartsOn?: WeekDay;
|
|
28
|
+
/** Clock used for events and hour labels; defaults to the provider or runtime locale. */
|
|
29
|
+
hourCycle?: HourCycle;
|
|
22
30
|
/** The app's "today" (the block never reads the clock). */
|
|
23
31
|
today?: Date;
|
|
24
32
|
/** Current time for the "now" line, shown when it falls in the visible week. Defaults to `today`. */
|
|
25
33
|
now?: Date;
|
|
26
34
|
/** A date inside the week shown first (uncontrolled). Defaults to `today`. */
|
|
27
35
|
defaultWeek?: Date;
|
|
28
|
-
/** Called with the
|
|
36
|
+
/** Called with the first day of the newly shown week. */
|
|
29
37
|
onWeekChange?: (weekStart: Date) => void;
|
|
30
38
|
/** Makes events buttons. */
|
|
31
39
|
onEventClick?: (event: ScheduleEvent) => void;
|
|
@@ -41,7 +49,6 @@ export interface WeekCalendarProps {
|
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
const HOURS = Array.from({ length: 24 }, (_, h) => h);
|
|
44
|
-
const pad = (n: number) => String(n).padStart(2, '0');
|
|
45
52
|
|
|
46
53
|
interface Placed {
|
|
47
54
|
event: ScheduleEvent;
|
|
@@ -89,6 +96,8 @@ function layoutDay(list: readonly ScheduleEvent[], hourHeight: number): Placed[]
|
|
|
89
96
|
/** Week view: seven day columns over a scrolling 24-hour time grid, with a "now" line. */
|
|
90
97
|
export function WeekCalendar({
|
|
91
98
|
events = sampleEvents,
|
|
99
|
+
weekStartsOn: weekStartsOnProp,
|
|
100
|
+
hourCycle: hourCycleProp,
|
|
92
101
|
today = sampleToday,
|
|
93
102
|
now,
|
|
94
103
|
defaultWeek,
|
|
@@ -102,11 +111,15 @@ export function WeekCalendar({
|
|
|
102
111
|
className,
|
|
103
112
|
}: WeekCalendarProps) {
|
|
104
113
|
const { t, locale } = useI18n();
|
|
114
|
+
const clock = useSchedulingClock(hourCycleProp);
|
|
115
|
+
const weekStartsOn = weekStartsOnProp ?? localeWeekStart(clock.locale);
|
|
105
116
|
const titleId = useId();
|
|
106
|
-
const [weekStart, setWeekStart] = useState<Date>(() => startOfWeek(defaultWeek ?? today));
|
|
117
|
+
const [weekStart, setWeekStart] = useState<Date>(() => startOfWeek(defaultWeek ?? today, weekStartsOn));
|
|
107
118
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
108
119
|
const byDay = useMemo(() => groupByDay(events), [events]);
|
|
109
|
-
const days = weekDays(weekStart);
|
|
120
|
+
const days = weekDays(weekStart, weekStartsOn);
|
|
121
|
+
const visibleStart = days[0] ?? weekStart;
|
|
122
|
+
const weekend = weekendDays(clock.locale);
|
|
110
123
|
const nowAt = now ?? today;
|
|
111
124
|
const nowVisible = days.some((d) => sameDay(d, nowAt));
|
|
112
125
|
|
|
@@ -126,9 +139,9 @@ export function WeekCalendar({
|
|
|
126
139
|
title={formatWeekRange(days, locale)}
|
|
127
140
|
prevLabel={t('calendar.previousWeek')}
|
|
128
141
|
nextLabel={t('calendar.nextWeek')}
|
|
129
|
-
onPrev={() => show(addDays(
|
|
130
|
-
onNext={() => show(addDays(
|
|
131
|
-
onToday={() => show(startOfWeek(today))}
|
|
142
|
+
onPrev={() => show(addDays(visibleStart, -7))}
|
|
143
|
+
onNext={() => show(addDays(visibleStart, 7))}
|
|
144
|
+
onToday={() => show(startOfWeek(today, weekStartsOn))}
|
|
132
145
|
actions={actions}
|
|
133
146
|
/>
|
|
134
147
|
<div className="overflow-x-auto">
|
|
@@ -173,7 +186,7 @@ export function WeekCalendar({
|
|
|
173
186
|
className="absolute end-2 font-mono text-[10px] text-muted-foreground"
|
|
174
187
|
style={{ top: h * hourHeight - 6 }}
|
|
175
188
|
>
|
|
176
|
-
{
|
|
189
|
+
{formatHour(h, clock.locale, clock.hourCycle)}
|
|
177
190
|
</span>
|
|
178
191
|
))}
|
|
179
192
|
</div>
|
|
@@ -193,20 +206,21 @@ export function WeekCalendar({
|
|
|
193
206
|
return (
|
|
194
207
|
<ul
|
|
195
208
|
key={dayKey(d)}
|
|
209
|
+
data-weekend={weekend.includes(d.getDay() as WeekDay) ? '' : undefined}
|
|
196
210
|
aria-label={formatDay(d, locale)}
|
|
197
211
|
className="relative border-s border-border/70 first:border-s-0"
|
|
198
212
|
>
|
|
199
213
|
{layoutDay(list, hourHeight).map(({ event, top, height: h, lane, lanes }) => {
|
|
200
214
|
const kind = kindOf(event, kinds);
|
|
201
215
|
const tone = TONE[kind.tone];
|
|
202
|
-
const range = formatRange(event.start, event.end, locale);
|
|
216
|
+
const range = formatRange(event.start, event.end, clock.locale, clock.hourCycle);
|
|
203
217
|
const body = (
|
|
204
218
|
<>
|
|
205
219
|
<span className="block truncate text-[11px] leading-tight font-semibold text-foreground">
|
|
206
220
|
{event.title}
|
|
207
221
|
</span>
|
|
208
|
-
<span className="block truncate font-mono text-[10px] text-
|
|
209
|
-
{formatTime(event.start, locale)}
|
|
222
|
+
<span className="block truncate font-mono text-[10px] text-foreground">
|
|
223
|
+
{formatTime(event.start, clock.locale, clock.hourCycle)}
|
|
210
224
|
</span>
|
|
211
225
|
</>
|
|
212
226
|
);
|
|
@@ -5,6 +5,6 @@ export const meta: BlockMeta = {
|
|
|
5
5
|
family: 'scheduling',
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
|
-
'
|
|
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.',
|
|
9
9
|
uses: ['Button', 'IconButton'],
|
|
10
10
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { WeekCalendar } from '../WeekCalendar';
|
|
3
|
+
|
|
4
|
+
/** Compare US defaults, Spanish defaults, and explicit overrides under US English. */
|
|
5
|
+
export default function Locale() {
|
|
6
|
+
return (
|
|
7
|
+
<div className="space-y-6">
|
|
8
|
+
<I18nProvider locale="en-US">
|
|
9
|
+
<WeekCalendar />
|
|
10
|
+
</I18nProvider>
|
|
11
|
+
<I18nProvider locale="es-ES">
|
|
12
|
+
<WeekCalendar />
|
|
13
|
+
</I18nProvider>
|
|
14
|
+
<I18nProvider locale="en-US">
|
|
15
|
+
<WeekCalendar weekStartsOn={1} hourCycle="h23" />
|
|
16
|
+
</I18nProvider>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatWeekRange,
|
|
3
|
+
weekendDays,
|
|
4
|
+
dayKey,
|
|
5
|
+
monthGrid,
|
|
6
|
+
startOfWeek,
|
|
7
|
+
weekDays,
|
|
8
|
+
formatTime,
|
|
9
|
+
formatRange,
|
|
10
|
+
formatHour,
|
|
11
|
+
} from './dates';
|
|
12
|
+
import type { WeekDay } from '@gntik-ai/ui';
|
|
13
|
+
|
|
14
|
+
it.each<[WeekDay, string]>([
|
|
15
|
+
[0, '2026-03-29'],
|
|
16
|
+
[1, '2026-03-30'],
|
|
17
|
+
[6, '2026-03-28'],
|
|
18
|
+
])('starts April weeks on weekday %s', (weekStartsOn, expected) => {
|
|
19
|
+
const april = new Date(2026, 3, 1, 12);
|
|
20
|
+
expect(dayKey(startOfWeek(april, weekStartsOn))).toBe(expected);
|
|
21
|
+
expect(startOfWeek(april, weekStartsOn).getHours()).toBe(0);
|
|
22
|
+
expect(weekDays(april, weekStartsOn)).toHaveLength(7);
|
|
23
|
+
expect(weekDays(april, weekStartsOn)[0]).toEqual(new Date(`${expected}T00:00:00`));
|
|
24
|
+
const grid = monthGrid(april, weekStartsOn);
|
|
25
|
+
expect(grid).toHaveLength(6);
|
|
26
|
+
expect(grid.every((week) => week.length === 7)).toBe(true);
|
|
27
|
+
expect(grid[0]?.[0]).toEqual(new Date(`${expected}T00:00:00`));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it.each([
|
|
31
|
+
['en-US', 'h12', '9:30 AM', '9:30 AM–10:00 AM', '9 AM', '12 PM'],
|
|
32
|
+
['en-US', 'h23', '09:30', '09:30–10:00', '09:00', '12:00'],
|
|
33
|
+
['es-ES', 'h23', '09:30', '09:30–10:00', '09:00', '12:00'],
|
|
34
|
+
['es-ES', 'h12', '9:30 a. m.', '9:30 a. m.–10:00 a. m.', '9 a. m.', '12 p. m.'],
|
|
35
|
+
] as const)('formats time and gutter labels in %s with %s', (locale, cycle, time, range, hour, noon) => {
|
|
36
|
+
const start = new Date(2026, 3, 15, 9, 30);
|
|
37
|
+
expect(formatTime(start, locale, cycle)).toBe(time);
|
|
38
|
+
expect(formatRange(start, new Date(2026, 3, 15, 10), locale, cycle)).toBe(range);
|
|
39
|
+
expect(formatHour(9, locale, cycle)).toBe(hour);
|
|
40
|
+
expect(formatHour(12, locale, cycle)).toBe(noon);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('uses locale weekends and falls back to Saturday and Sunday without Intl week info', () => {
|
|
44
|
+
expect(weekendDays('en-US')).toEqual([6, 0]);
|
|
45
|
+
expect(weekendDays('ar-SA')).toEqual([5, 6]);
|
|
46
|
+
const original = Intl.Locale;
|
|
47
|
+
try {
|
|
48
|
+
vi.stubGlobal('Intl', Object.create(Intl, { Locale: { value: class {} } }));
|
|
49
|
+
expect(weekendDays('en-US')).toEqual([6, 0]);
|
|
50
|
+
} finally {
|
|
51
|
+
vi.unstubAllGlobals();
|
|
52
|
+
expect(Intl.Locale).toBe(original);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('keeps English week labels independent of the host locale', () => {
|
|
57
|
+
const NativeFormatter = Intl.DateTimeFormat;
|
|
58
|
+
try {
|
|
59
|
+
vi.stubGlobal(
|
|
60
|
+
'Intl',
|
|
61
|
+
Object.create(Intl, {
|
|
62
|
+
DateTimeFormat: {
|
|
63
|
+
value: class extends NativeFormatter {
|
|
64
|
+
constructor(locale?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) {
|
|
65
|
+
super(locale ?? 'es-ES', options);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
expect(formatWeekRange(weekDays(new Date(2026, 3, 15), 1), 'en-GB')).toBe('Apr 13 – 19, 2026');
|
|
72
|
+
} finally {
|
|
73
|
+
vi.unstubAllGlobals();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/** Native-Date helpers for the scheduling blocks.
|
|
1
|
+
/** Native-Date helpers for the scheduling blocks. Week starts are caller-supplied. */
|
|
2
|
+
import type { WeekDay } from '@gntik-ai/ui';
|
|
2
3
|
|
|
3
4
|
const pad = (n: number) => String(n).padStart(2, '0');
|
|
4
5
|
|
|
@@ -31,19 +32,19 @@ export function sameMonth(a: Date, b: Date): boolean {
|
|
|
31
32
|
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
export function startOfWeek(d: Date): Date {
|
|
36
|
-
return addDays(startOfDay(d), -((d.getDay() +
|
|
35
|
+
/** First day of the week containing `d`. */
|
|
36
|
+
export function startOfWeek(d: Date, weekStartsOn: WeekDay): Date {
|
|
37
|
+
return addDays(startOfDay(d), -((d.getDay() - weekStartsOn + 7) % 7));
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
export function weekDays(d: Date): Date[] {
|
|
40
|
-
const
|
|
41
|
-
return Array.from({ length: 7 }, (_, i) => addDays(
|
|
40
|
+
export function weekDays(d: Date, weekStartsOn: WeekDay): Date[] {
|
|
41
|
+
const first = startOfWeek(d, weekStartsOn);
|
|
42
|
+
return Array.from({ length: 7 }, (_, i) => addDays(first, i));
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
/** Six
|
|
45
|
-
export function monthGrid(d: Date): Date[][] {
|
|
46
|
-
const start = startOfWeek(startOfMonth(d));
|
|
45
|
+
/** Six weeks covering the month of `d`, starting on `weekStartsOn`. */
|
|
46
|
+
export function monthGrid(d: Date, weekStartsOn: WeekDay): Date[][] {
|
|
47
|
+
const start = startOfWeek(startOfMonth(d), weekStartsOn);
|
|
47
48
|
return Array.from({ length: 6 }, (_, w) => Array.from({ length: 7 }, (_, i) => addDays(start, w * 7 + i)));
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -53,23 +54,33 @@ export function hourOf(d: Date): number {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const cache = new Map<string, Intl.DateTimeFormat>();
|
|
56
|
-
/** Cached Intl formatter;
|
|
57
|
+
/** Cached Intl formatter; an omitted locale uses the runtime locale. */
|
|
57
58
|
const fmt = (locale: string | undefined, opts: Intl.DateTimeFormatOptions) => {
|
|
58
|
-
const key = `${locale ??
|
|
59
|
+
const key = `${locale ?? new Intl.DateTimeFormat().resolvedOptions().locale}|${JSON.stringify(opts)}`;
|
|
59
60
|
let f = cache.get(key);
|
|
60
61
|
if (!f) {
|
|
61
|
-
f = new Intl.DateTimeFormat(locale
|
|
62
|
+
f = new Intl.DateTimeFormat(locale, opts);
|
|
62
63
|
cache.set(key, f);
|
|
63
64
|
}
|
|
64
65
|
return f;
|
|
65
66
|
};
|
|
66
67
|
|
|
67
|
-
/**
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
/** "09:30
|
|
71
|
-
export const
|
|
72
|
-
|
|
68
|
+
/** The clock options accepted by the scheduling blocks. */
|
|
69
|
+
export type HourCycle = 'h12' | 'h23';
|
|
70
|
+
|
|
71
|
+
/** "9:30 AM" or "09:30". */
|
|
72
|
+
export const formatTime = (d: Date, locale: string | undefined, hourCycle: HourCycle) =>
|
|
73
|
+
fmt(locale, { hour: hourCycle === 'h12' ? 'numeric' : '2-digit', minute: '2-digit', hourCycle }).format(d);
|
|
74
|
+
/** "9:30 AM–10:00 AM" or "09:30–10:00". */
|
|
75
|
+
export const formatRange = (start: Date, end: Date, locale: string | undefined, hourCycle: HourCycle) =>
|
|
76
|
+
`${formatTime(start, locale, hourCycle)}–${formatTime(end, locale, hourCycle)}`;
|
|
77
|
+
/** Compact gutter label: "9 AM" or "09:00". */
|
|
78
|
+
export const formatHour = (hour: number, locale: string | undefined, hourCycle: HourCycle) =>
|
|
79
|
+
fmt(locale, {
|
|
80
|
+
hour: hourCycle === 'h12' ? 'numeric' : '2-digit',
|
|
81
|
+
...(hourCycle === 'h23' ? { minute: '2-digit' as const } : {}),
|
|
82
|
+
hourCycle,
|
|
83
|
+
}).format(new Date(2026, 0, 1, hour));
|
|
73
84
|
/** "Wednesday, April 15, 2026". */
|
|
74
85
|
export const formatFullDate = (d: Date, locale?: string) =>
|
|
75
86
|
fmt(locale, { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' }).format(d);
|
|
@@ -91,8 +102,21 @@ export function formatWeekRange(days: readonly Date[], locale?: string): string
|
|
|
91
102
|
if (!first || !last) return '';
|
|
92
103
|
if (locale && !locale.toLowerCase().startsWith('en'))
|
|
93
104
|
return fmt(locale, { month: 'short', day: 'numeric', year: 'numeric' }).formatRange(first, last);
|
|
94
|
-
if (sameMonth(first, last)) return `${formatShort(first)} – ${last.getDate()}, ${last.getFullYear()}`;
|
|
105
|
+
if (sameMonth(first, last)) return `${formatShort(first, 'en-US')} – ${last.getDate()}, ${last.getFullYear()}`;
|
|
95
106
|
if (first.getFullYear() === last.getFullYear())
|
|
96
|
-
return `${formatShort(first)} – ${formatShort(last)}, ${last.getFullYear()}`;
|
|
97
|
-
return `${formatShort(first)}, ${first.getFullYear()} – ${formatShort(last)}, ${last.getFullYear()}`;
|
|
107
|
+
return `${formatShort(first, 'en-US')} – ${formatShort(last, 'en-US')}, ${last.getFullYear()}`;
|
|
108
|
+
return `${formatShort(first, 'en-US')}, ${first.getFullYear()} – ${formatShort(last, 'en-US')}, ${last.getFullYear()}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Internal to blocks: Intl weekdays 1–7 become JS weekdays 0–6. */
|
|
112
|
+
export function weekendDays(locale?: string): WeekDay[] {
|
|
113
|
+
try {
|
|
114
|
+
const loc = new Intl.Locale(locale ?? new Intl.DateTimeFormat().resolvedOptions().locale) as Intl.Locale & {
|
|
115
|
+
getWeekInfo?: () => { weekend: number[] };
|
|
116
|
+
weekInfo?: { weekend: number[] };
|
|
117
|
+
};
|
|
118
|
+
const info = loc.getWeekInfo?.() ?? loc.weekInfo;
|
|
119
|
+
if (info) return info.weekend.map((day) => (day % 7) as WeekDay);
|
|
120
|
+
} catch {}
|
|
121
|
+
return [6, 0];
|
|
98
122
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { localeHourCycle, useOptionalI18n } from '@gntik-ai/ui';
|
|
2
|
+
import type { HourCycle } from './dates';
|
|
3
|
+
|
|
4
|
+
/** Map the existing public numeric clock API to scheduling's Intl options. */
|
|
5
|
+
function resolveHourCycle(locale?: string): HourCycle {
|
|
6
|
+
return localeHourCycle(locale) === 12 ? 'h12' : 'h23';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Undefined outside a provider lets Intl use the runtime locale, as ui Calendar does. */
|
|
10
|
+
export function useSchedulingClock(override?: HourCycle) {
|
|
11
|
+
const locale = useOptionalI18n()?.locale;
|
|
12
|
+
return { locale, hourCycle: override ?? resolveHourCycle(locale) };
|
|
13
|
+
}
|
|
@@ -4,6 +4,18 @@ import { expectNoAxeViolations } from '../../test/a11y';
|
|
|
4
4
|
import { GlobalSearch } from './GlobalSearch';
|
|
5
5
|
|
|
6
6
|
describe('GlobalSearch', () => {
|
|
7
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
8
|
+
|
|
9
|
+
it('shows Ctrl for the Create project shortcut on Linux', async () => {
|
|
10
|
+
vi.stubGlobal('navigator', { platform: 'Linux x86_64' });
|
|
11
|
+
const user = userEvent.setup();
|
|
12
|
+
render(<GlobalSearch />);
|
|
13
|
+
await user.click(screen.getByRole('button', { name: /Search/ }));
|
|
14
|
+
const item = await screen.findByRole('option', { name: /Create project/ });
|
|
15
|
+
expect(within(item).getByText('Ctrl')).toBeInTheDocument();
|
|
16
|
+
expect(within(item).queryByText('⌘')).not.toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
7
19
|
it('renders the trigger with the shortcut hint', async () => {
|
|
8
20
|
const { container } = render(<GlobalSearch />);
|
|
9
21
|
expect(screen.getByRole('button', { name: /Search/ })).toBeInTheDocument();
|
|
@@ -19,7 +19,7 @@ export const globalSearchPages: CommandItem[] = [
|
|
|
19
19
|
{ id: 'page-analytics', label: 'Analytics', icon: BarChart3 },
|
|
20
20
|
{ id: 'page-members', label: 'Members', icon: Users, keywords: ['team', 'people'] },
|
|
21
21
|
{ id: 'page-billing', label: 'Billing', icon: CreditCard, keywords: ['invoices', 'plan'] },
|
|
22
|
-
{ id: 'page-settings', label: 'Settings', icon: Settings, shortcut: ['
|
|
22
|
+
{ id: 'page-settings', label: 'Settings', icon: Settings, shortcut: ['mod', ','] },
|
|
23
23
|
];
|
|
24
24
|
|
|
25
25
|
export const globalSearchRecords: CommandItem[] = [
|
|
@@ -48,7 +48,7 @@ export const globalSearchRecords: CommandItem[] = [
|
|
|
48
48
|
];
|
|
49
49
|
|
|
50
50
|
export const globalSearchActions: CommandItem[] = [
|
|
51
|
-
{ id: 'action-new-project', label: 'Create project', icon: FolderPlus, shortcut: ['
|
|
51
|
+
{ id: 'action-new-project', label: 'Create project', icon: FolderPlus, shortcut: ['mod', 'N'], keywords: ['new'] },
|
|
52
52
|
{
|
|
53
53
|
id: 'action-deploy',
|
|
54
54
|
label: 'Deploy to production',
|