@gntik-ai/blocks 0.9.0 → 0.10.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 +129 -19
- package/dist/index.js +846 -354
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- 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.tsx +43 -10
- package/src/builders/LogViewer/block.meta.ts +14 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +30 -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.tsx +37 -7
- package/src/data-display/DescriptionListCard/block.meta.ts +11 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +22 -0
- package/src/feedback/EmptyStates/EmptyStates.labels.test.tsx +185 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +73 -20
- package/src/feedback/EmptyStates/block.meta.ts +73 -1
- package/src/feedback/EmptyStates/examples/Spanish.tsx +41 -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/FileUploadPanel/FileUploadPanel.test.tsx +22 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +4 -4
- package/src/forms/FileUploadPanel/fixtures.ts +0 -12
- package/src/forms/FileUploadPanel/format-bytes.test.ts +8 -0
- package/src/page-chrome/PageHeader/PageHeader.labels.test.tsx +56 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +19 -4
- package/src/page-chrome/PageHeader/block.meta.ts +8 -1
- package/src/page-chrome/PageHeader/examples/Labels.tsx +16 -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/PaginationFooter/PaginationFooter.i18n.test.tsx +26 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent, 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,
|
|
5
7
|
addDays,
|
|
6
8
|
addMonths,
|
|
7
9
|
dayKey,
|
|
@@ -10,6 +12,7 @@ import {
|
|
|
10
12
|
formatTime,
|
|
11
13
|
formatWeekday,
|
|
12
14
|
monthGrid,
|
|
15
|
+
weekendDays,
|
|
13
16
|
sameDay,
|
|
14
17
|
sameMonth,
|
|
15
18
|
startOfDay,
|
|
@@ -21,6 +24,10 @@ import { sampleEvents, sampleToday } from '../shared/fixtures';
|
|
|
21
24
|
|
|
22
25
|
export interface MonthCalendarProps {
|
|
23
26
|
events?: ScheduleEvent[];
|
|
27
|
+
/** Clock used for event times; defaults to the provider or runtime locale. */
|
|
28
|
+
hourCycle?: HourCycle;
|
|
29
|
+
/** First weekday; defaults to the provider or runtime locale. */
|
|
30
|
+
weekStartsOn?: WeekDay;
|
|
24
31
|
/** The app's "today" (the block never reads the clock). */
|
|
25
32
|
today?: Date;
|
|
26
33
|
/** Month shown first (uncontrolled). Defaults to the month of `today`. */
|
|
@@ -39,16 +46,15 @@ export interface MonthCalendarProps {
|
|
|
39
46
|
className?: string;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
/** Monday-first weekdays (2026-01-05 is a Monday). */
|
|
43
|
-
const WEEK = Array.from({ length: 7 }, (_, i) => new Date(2026, 0, 5 + i));
|
|
44
|
-
|
|
45
49
|
/**
|
|
46
|
-
* Month view of scheduled work: a
|
|
50
|
+
* Month view of scheduled work: a locale-first grid with up to N events per day.
|
|
47
51
|
* Keyboard: arrows move by day/week, Home/End to the week edges, PageUp/PageDown by month,
|
|
48
52
|
* Enter/Space selects.
|
|
49
53
|
*/
|
|
50
54
|
export function MonthCalendar({
|
|
51
55
|
events = sampleEvents,
|
|
56
|
+
hourCycle: hourCycleProp,
|
|
57
|
+
weekStartsOn: weekStartsOnProp,
|
|
52
58
|
today = sampleToday,
|
|
53
59
|
defaultMonth,
|
|
54
60
|
onMonthChange,
|
|
@@ -60,6 +66,8 @@ export function MonthCalendar({
|
|
|
60
66
|
className,
|
|
61
67
|
}: MonthCalendarProps) {
|
|
62
68
|
const { t, locale, dir } = useI18n();
|
|
69
|
+
const clock = useSchedulingClock(hourCycleProp);
|
|
70
|
+
const weekStartsOn = weekStartsOnProp ?? localeWeekStart(clock.locale);
|
|
63
71
|
const titleId = useId();
|
|
64
72
|
const [selected, setSelected] = useState<Date>(() => startOfDay(defaultSelected ?? today));
|
|
65
73
|
const [focused, setFocused] = useState<Date>(() => startOfDay(defaultSelected ?? defaultMonth ?? today));
|
|
@@ -67,7 +75,8 @@ export function MonthCalendar({
|
|
|
67
75
|
const gridRef = useRef<HTMLDivElement>(null);
|
|
68
76
|
const moveFocus = useRef(false);
|
|
69
77
|
const byDay = useMemo(() => groupByDay(events), [events]);
|
|
70
|
-
const weeks = monthGrid(month);
|
|
78
|
+
const weeks = monthGrid(month, weekStartsOn);
|
|
79
|
+
const weekend = weekendDays(clock.locale);
|
|
71
80
|
// The roving tab stop stays inside the visible month.
|
|
72
81
|
const tabStop = sameMonth(focused, month) ? focused : sameMonth(selected, month) ? selected : month;
|
|
73
82
|
|
|
@@ -96,7 +105,7 @@ export function MonthCalendar({
|
|
|
96
105
|
};
|
|
97
106
|
|
|
98
107
|
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>, date: Date) => {
|
|
99
|
-
const weekStart = startOfWeek(date);
|
|
108
|
+
const weekStart = startOfWeek(date, weekStartsOn);
|
|
100
109
|
const map: Record<string, () => Date> = {
|
|
101
110
|
ArrowLeft: () => addDays(date, dir === 'rtl' ? 1 : -1),
|
|
102
111
|
ArrowRight: () => addDays(date, dir === 'rtl' ? -1 : 1),
|
|
@@ -130,7 +139,7 @@ export function MonthCalendar({
|
|
|
130
139
|
/>
|
|
131
140
|
<div ref={gridRef} role="grid" aria-labelledby={titleId}>
|
|
132
141
|
<div role="row" className="grid grid-cols-7 border-b border-border bg-secondary/30">
|
|
133
|
-
{
|
|
142
|
+
{(weeks[0] ?? []).map((day) => (
|
|
134
143
|
<div
|
|
135
144
|
key={day.getDay()}
|
|
136
145
|
role="columnheader"
|
|
@@ -154,6 +163,7 @@ export function MonthCalendar({
|
|
|
154
163
|
<div
|
|
155
164
|
key={key}
|
|
156
165
|
role="gridcell"
|
|
166
|
+
data-weekend={weekend.includes(date.getDay() as WeekDay) ? '' : undefined}
|
|
157
167
|
aria-selected={isSelected}
|
|
158
168
|
className="min-w-0 border-e border-b border-border/70 [&:nth-child(7)]:border-e-0"
|
|
159
169
|
>
|
|
@@ -201,7 +211,7 @@ export function MonthCalendar({
|
|
|
201
211
|
<span className={cn('size-1.5 shrink-0 rounded-full', TONE[kindOf(e, kinds).tone].dot)} />
|
|
202
212
|
<span className="truncate text-[11px] text-foreground/80">{e.title}</span>
|
|
203
213
|
<span className="ms-auto hidden shrink-0 font-mono text-[10px] text-muted-foreground xl:block">
|
|
204
|
-
{formatTime(e.start, locale)}
|
|
214
|
+
{formatTime(e.start, clock.locale, clock.hourCycle)}
|
|
205
215
|
</span>
|
|
206
216
|
</span>
|
|
207
217
|
))}
|
|
@@ -5,6 +5,6 @@ export const meta: BlockMeta = {
|
|
|
5
5
|
family: 'scheduling',
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
|
-
'
|
|
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.',
|
|
9
9
|
uses: ['Button', 'IconButton'],
|
|
10
10
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { MonthCalendar } from '../MonthCalendar';
|
|
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
|
+
<MonthCalendar />
|
|
10
|
+
</I18nProvider>
|
|
11
|
+
<I18nProvider locale="es-ES">
|
|
12
|
+
<MonthCalendar />
|
|
13
|
+
</I18nProvider>
|
|
14
|
+
<I18nProvider locale="en-US">
|
|
15
|
+
<MonthCalendar weekStartsOn={1} hourCycle="h23" />
|
|
16
|
+
</I18nProvider>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
1
2
|
import { render, screen, within } from '@testing-library/react';
|
|
2
3
|
import userEvent from '@testing-library/user-event';
|
|
3
4
|
import { expectNoAxeViolations } from '../../test/a11y';
|
|
@@ -5,7 +6,7 @@ import { WeekCalendar } from './WeekCalendar';
|
|
|
5
6
|
|
|
6
7
|
describe('WeekCalendar', () => {
|
|
7
8
|
it('renders the sample week with its events per day', async () => {
|
|
8
|
-
const { container } = render(<WeekCalendar />);
|
|
9
|
+
const { container } = render(<WeekCalendar weekStartsOn={1} hourCycle="h23" />);
|
|
9
10
|
expect(screen.getByRole('heading', { name: 'Apr 13 – 19, 2026' })).toBeInTheDocument();
|
|
10
11
|
const wednesday = screen.getByRole('list', { name: 'Wednesday, April 15' });
|
|
11
12
|
expect(within(wednesday).getAllByRole('listitem')).toHaveLength(9);
|
|
@@ -16,7 +17,7 @@ describe('WeekCalendar', () => {
|
|
|
16
17
|
const user = userEvent.setup();
|
|
17
18
|
const onEventClick = vi.fn();
|
|
18
19
|
const onWeekChange = vi.fn();
|
|
19
|
-
render(<WeekCalendar onEventClick={onEventClick} onWeekChange={onWeekChange} />);
|
|
20
|
+
render(<WeekCalendar weekStartsOn={1} hourCycle="h23" onEventClick={onEventClick} onWeekChange={onWeekChange} />);
|
|
20
21
|
await user.click(screen.getByRole('button', { name: 'Checkout hotfix, 09:00–10:00, eu-west-1' }));
|
|
21
22
|
expect(onEventClick).toHaveBeenCalledWith(expect.objectContaining({ title: 'Checkout hotfix' }));
|
|
22
23
|
await user.click(screen.getByRole('button', { name: 'Next week' }));
|
|
@@ -25,3 +26,73 @@ describe('WeekCalendar', () => {
|
|
|
25
26
|
await expectNoAxeViolations(document.body);
|
|
26
27
|
});
|
|
27
28
|
});
|
|
29
|
+
|
|
30
|
+
it.each([
|
|
31
|
+
['en-US', undefined, 'Sunday, April 12', 12],
|
|
32
|
+
['es-ES', undefined, 'lunes, 13 de abril', 13],
|
|
33
|
+
['en-US', 1, 'Monday, April 13', 13],
|
|
34
|
+
] as const)(
|
|
35
|
+
'aligns initial week, navigation and Today for %s with override %s',
|
|
36
|
+
async (locale, weekStartsOn, firstLabel, day) => {
|
|
37
|
+
const user = userEvent.setup();
|
|
38
|
+
const onWeekChange = vi.fn();
|
|
39
|
+
render(
|
|
40
|
+
<I18nProvider locale={locale}>
|
|
41
|
+
<WeekCalendar
|
|
42
|
+
events={[]}
|
|
43
|
+
today={new Date(2026, 3, 15)}
|
|
44
|
+
weekStartsOn={weekStartsOn}
|
|
45
|
+
onWeekChange={onWeekChange}
|
|
46
|
+
/>
|
|
47
|
+
</I18nProvider>,
|
|
48
|
+
);
|
|
49
|
+
expect(screen.getAllByRole('list')[0]).toHaveAccessibleName(firstLabel);
|
|
50
|
+
await user.click(screen.getByRole('button', { name: locale === 'es-ES' ? 'Semana siguiente' : 'Next week' }));
|
|
51
|
+
expect(onWeekChange).toHaveBeenLastCalledWith(new Date(2026, 3, day + 7));
|
|
52
|
+
await user.click(screen.getByRole('button', { name: locale === 'es-ES' ? 'Semana anterior' : 'Previous week' }));
|
|
53
|
+
expect(onWeekChange).toHaveBeenLastCalledWith(new Date(2026, 3, day));
|
|
54
|
+
await user.click(screen.getByRole('button', { name: locale === 'es-ES' ? 'Hoy' : 'Today' }));
|
|
55
|
+
expect(onWeekChange).toHaveBeenLastCalledWith(new Date(2026, 3, day));
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
it.each([
|
|
60
|
+
['en-US', undefined, '9:30 AM–10:00 AM', '9 AM'],
|
|
61
|
+
['es-ES', undefined, '09:30–10:00', '09:00'],
|
|
62
|
+
['en-US', 'h23', '09:30–10:00', '09:00'],
|
|
63
|
+
] as const)('formats event names and gutter labels for %s with override %s', (locale, hourCycle, range, hour) => {
|
|
64
|
+
render(
|
|
65
|
+
<I18nProvider locale={locale}>
|
|
66
|
+
<WeekCalendar
|
|
67
|
+
hourCycle={hourCycle}
|
|
68
|
+
onEventClick={() => {}}
|
|
69
|
+
events={[
|
|
70
|
+
{
|
|
71
|
+
id: 'clock',
|
|
72
|
+
title: 'Review',
|
|
73
|
+
kind: 'task',
|
|
74
|
+
start: new Date(2026, 3, 15, 9, 30),
|
|
75
|
+
end: new Date(2026, 3, 15, 10),
|
|
76
|
+
},
|
|
77
|
+
]}
|
|
78
|
+
/>
|
|
79
|
+
</I18nProvider>,
|
|
80
|
+
);
|
|
81
|
+
expect(screen.getByRole('button', { name: `Review, ${range}` })).toBeInTheDocument();
|
|
82
|
+
expect(screen.getByText(hour, { exact: true })).toBeInTheDocument();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('marks Saturday and Sunday day columns only', () => {
|
|
86
|
+
render(
|
|
87
|
+
<I18nProvider locale="en-US">
|
|
88
|
+
<WeekCalendar events={[]} />
|
|
89
|
+
</I18nProvider>,
|
|
90
|
+
);
|
|
91
|
+
const columns = screen.getAllByRole('list');
|
|
92
|
+
expect(columns.filter((column) => column.hasAttribute('data-weekend'))).toHaveLength(2);
|
|
93
|
+
for (const column of columns) {
|
|
94
|
+
expect(column.hasAttribute('data-weekend')).toBe(
|
|
95
|
+
/^(Saturday|Sunday),/.test(column.getAttribute('aria-label') ?? ''),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
@@ -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',
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { I18nProvider, es } from '@gntik-ai/ui';
|
|
3
|
+
import { PaginationFooter } from './PaginationFooter';
|
|
4
|
+
|
|
5
|
+
it('audits every pagination label in Spanish and preserves an explicit noun', () => {
|
|
6
|
+
const { container, rerender } = render(
|
|
7
|
+
<I18nProvider locale="es">
|
|
8
|
+
<PaginationFooter total={20} />
|
|
9
|
+
</I18nProvider>,
|
|
10
|
+
);
|
|
11
|
+
expect(screen.getByText(es['table.rowsPerPage'])).toBeVisible();
|
|
12
|
+
expect(screen.getByRole('combobox', { name: es['table.rowsPerPage'] })).toBeVisible();
|
|
13
|
+
expect(screen.getByRole('navigation', { name: 'Paginación: Filas' })).toBeVisible();
|
|
14
|
+
expect(screen.getByRole('button', { name: es['pagination.previous'] })).toBeVisible();
|
|
15
|
+
expect(screen.getByRole('button', { name: es['pagination.next'] })).toBeVisible();
|
|
16
|
+
expect(screen.getByRole('button', { name: 'Página 1' })).toBeVisible();
|
|
17
|
+
expect(screen.getByRole('button', { name: 'Página 2' })).toBeVisible();
|
|
18
|
+
expect(container.querySelector('[aria-live]')?.textContent).toBe('1–10 de 20');
|
|
19
|
+
expect(container.textContent).not.toContain('{');
|
|
20
|
+
rerender(
|
|
21
|
+
<I18nProvider locale="es">
|
|
22
|
+
<PaginationFooter noun="Caller rows" />
|
|
23
|
+
</I18nProvider>,
|
|
24
|
+
);
|
|
25
|
+
expect(screen.getByRole('navigation', { name: 'Paginación: Caller rows' })).toBeVisible();
|
|
26
|
+
});
|