@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,62 +1,77 @@
|
|
|
1
|
-
/** Native-Date helpers for
|
|
2
|
-
import type
|
|
1
|
+
/** Native-Date helpers for scheduling. All optional zones default to the runtime clock. */
|
|
2
|
+
import { fromZonedParts, zonedParts, type WeekDay } from '@gntik-ai/ui';
|
|
3
3
|
|
|
4
4
|
const pad = (n: number) => String(n).padStart(2, '0');
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/** Midnight in the display zone, normalizing calendar arithmetic before DST conversion. */
|
|
7
|
+
function calendarDate(year: number, month: number, day: number, zone = 'system'): Date {
|
|
8
|
+
if (zone === 'system') return new Date(year, month - 1, day);
|
|
9
|
+
const normalized = new Date(0);
|
|
10
|
+
normalized.setUTCFullYear(year, month - 1, day);
|
|
11
|
+
const parts = zonedParts(normalized, 'UTC');
|
|
12
|
+
return fromZonedParts(parts, zone)!;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
export function
|
|
12
|
-
|
|
15
|
+
export function dayKey(d: Date, zone = 'system'): string {
|
|
16
|
+
const p = zonedParts(d, zone);
|
|
17
|
+
return `${p.year}-${pad(p.month)}-${pad(p.day)}`;
|
|
13
18
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return
|
|
19
|
+
export function startOfDay(d: Date, zone = 'system'): Date {
|
|
20
|
+
const p = zonedParts(d, zone);
|
|
21
|
+
return calendarDate(p.year, p.month, p.day, zone);
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
23
|
+
export function addDays(d: Date, n: number, zone = 'system'): Date {
|
|
24
|
+
const p = zonedParts(d, zone);
|
|
25
|
+
return calendarDate(p.year, p.month, p.day + n, zone);
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
27
|
+
export function addMonths(d: Date, n: number, zone = 'system'): Date {
|
|
28
|
+
const p = zonedParts(d, zone);
|
|
29
|
+
return calendarDate(p.year, p.month + n, 1, zone);
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
31
|
+
export function startOfMonth(d: Date, zone = 'system'): Date {
|
|
32
|
+
return addMonths(d, 0, zone);
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
34
|
+
export function sameDay(a: Date, b: Date, zone = 'system'): boolean {
|
|
35
|
+
return dayKey(a, zone) === dayKey(b, zone);
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
37
|
+
export function sameMonth(a: Date, b: Date, zone = 'system'): boolean {
|
|
38
|
+
const p = zonedParts(a, zone),
|
|
39
|
+
q = zonedParts(b, zone);
|
|
40
|
+
return p.year === q.year && p.month === q.month;
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return Array.from({ length: 7 }, (_, i) => addDays(first, i));
|
|
42
|
+
export function weekday(d: Date, zone = 'system'): WeekDay {
|
|
43
|
+
const p = zonedParts(d, zone);
|
|
44
|
+
return new Date(Date.UTC(p.year, p.month - 1, p.day)).getUTCDay() as WeekDay;
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export function monthGrid(d: Date, weekStartsOn: WeekDay): Date[][] {
|
|
47
|
-
const start = startOfWeek(startOfMonth(d), weekStartsOn);
|
|
48
|
-
return Array.from({ length: 6 }, (_, w) => Array.from({ length: 7 }, (_, i) => addDays(start, w * 7 + i)));
|
|
46
|
+
export function startOfWeek(d: Date, weekStartsOn: WeekDay, zone = 'system'): Date {
|
|
47
|
+
return addDays(d, -((weekday(d, zone) - weekStartsOn + 7) % 7), zone);
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
export function weekDays(d: Date, weekStartsOn: WeekDay, zone = 'system'): Date[] {
|
|
50
|
+
const first = startOfWeek(d, weekStartsOn, zone);
|
|
51
|
+
return Array.from({ length: 7 }, (_, i) => addDays(first, i, zone));
|
|
52
|
+
}
|
|
53
|
+
export function monthGrid(d: Date, weekStartsOn: WeekDay, zone = 'system'): Date[][] {
|
|
54
|
+
const start = startOfWeek(startOfMonth(d, zone), weekStartsOn, zone);
|
|
55
|
+
return Array.from({ length: 6 }, (_, w) => Array.from({ length: 7 }, (_, i) => addDays(start, w * 7 + i, zone)));
|
|
56
|
+
}
|
|
57
|
+
export function hourOf(d: Date, zone = 'system'): number {
|
|
58
|
+
const p = zonedParts(d, zone);
|
|
59
|
+
return p.hour + p.minute / 60;
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
const cache = new Map<string, Intl.DateTimeFormat>();
|
|
63
|
+
const runtimeLocales = new WeakMap<typeof Intl.DateTimeFormat, string>();
|
|
64
|
+
function runtimeLocale(): string {
|
|
65
|
+
let locale = runtimeLocales.get(Intl.DateTimeFormat);
|
|
66
|
+
if (!locale) {
|
|
67
|
+
locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
68
|
+
runtimeLocales.set(Intl.DateTimeFormat, locale);
|
|
69
|
+
}
|
|
70
|
+
return locale;
|
|
71
|
+
}
|
|
57
72
|
/** Cached Intl formatter; an omitted locale uses the runtime locale. */
|
|
58
73
|
const fmt = (locale: string | undefined, opts: Intl.DateTimeFormatOptions) => {
|
|
59
|
-
const key = `${locale ??
|
|
74
|
+
const key = `${locale ?? runtimeLocale()}|${JSON.stringify(opts)}`;
|
|
60
75
|
let f = cache.get(key);
|
|
61
76
|
if (!f) {
|
|
62
77
|
f = new Intl.DateTimeFormat(locale, opts);
|
|
@@ -69,11 +84,21 @@ const fmt = (locale: string | undefined, opts: Intl.DateTimeFormatOptions) => {
|
|
|
69
84
|
export type HourCycle = 'h12' | 'h23';
|
|
70
85
|
|
|
71
86
|
/** "9:30 AM" or "09:30". */
|
|
72
|
-
export const formatTime = (d: Date, locale: string | undefined, hourCycle: HourCycle) =>
|
|
73
|
-
fmt(locale, {
|
|
87
|
+
export const formatTime = (d: Date, locale: string | undefined, hourCycle: HourCycle, zone = 'system') =>
|
|
88
|
+
fmt(locale, {
|
|
89
|
+
timeZone: zone === 'system' ? undefined : zone,
|
|
90
|
+
hour: hourCycle === 'h12' ? 'numeric' : '2-digit',
|
|
91
|
+
minute: '2-digit',
|
|
92
|
+
hourCycle,
|
|
93
|
+
}).format(d);
|
|
74
94
|
/** "9:30 AM–10:00 AM" or "09:30–10:00". */
|
|
75
|
-
export const formatRange = (
|
|
76
|
-
|
|
95
|
+
export const formatRange = (
|
|
96
|
+
start: Date,
|
|
97
|
+
end: Date,
|
|
98
|
+
locale: string | undefined,
|
|
99
|
+
hourCycle: HourCycle,
|
|
100
|
+
zone = 'system',
|
|
101
|
+
) => `${formatTime(start, locale, hourCycle, zone)}–${formatTime(end, locale, hourCycle, zone)}`;
|
|
77
102
|
/** Compact gutter label: "9 AM" or "09:00". */
|
|
78
103
|
export const formatHour = (hour: number, locale: string | undefined, hourCycle: HourCycle) =>
|
|
79
104
|
fmt(locale, {
|
|
@@ -82,30 +107,49 @@ export const formatHour = (hour: number, locale: string | undefined, hourCycle:
|
|
|
82
107
|
hourCycle,
|
|
83
108
|
}).format(new Date(2026, 0, 1, hour));
|
|
84
109
|
/** "Wednesday, April 15, 2026". */
|
|
85
|
-
export const formatFullDate = (d: Date, locale?: string) =>
|
|
86
|
-
fmt(locale, {
|
|
110
|
+
export const formatFullDate = (d: Date, locale?: string, zone = 'system') =>
|
|
111
|
+
fmt(locale, {
|
|
112
|
+
timeZone: zone === 'system' ? undefined : zone,
|
|
113
|
+
weekday: 'long',
|
|
114
|
+
month: 'long',
|
|
115
|
+
day: 'numeric',
|
|
116
|
+
year: 'numeric',
|
|
117
|
+
}).format(d);
|
|
87
118
|
/** "Wednesday, April 15". */
|
|
88
|
-
export const formatDay = (d: Date, locale?: string) =>
|
|
89
|
-
fmt(locale, {
|
|
119
|
+
export const formatDay = (d: Date, locale?: string, zone = 'system') =>
|
|
120
|
+
fmt(locale, {
|
|
121
|
+
timeZone: zone === 'system' ? undefined : zone,
|
|
122
|
+
weekday: 'long',
|
|
123
|
+
month: 'long',
|
|
124
|
+
day: 'numeric',
|
|
125
|
+
}).format(d);
|
|
90
126
|
/** "April 2026". */
|
|
91
|
-
export const formatMonth = (d: Date, locale?: string
|
|
127
|
+
export const formatMonth = (d: Date, locale?: string, zone = 'system') =>
|
|
128
|
+
fmt(locale, { timeZone: zone === 'system' ? undefined : zone, month: 'long', year: 'numeric' }).format(d);
|
|
92
129
|
/** "Apr 15". */
|
|
93
|
-
export const formatShort = (d: Date, locale?: string
|
|
130
|
+
export const formatShort = (d: Date, locale?: string, zone = 'system') =>
|
|
131
|
+
fmt(locale, { timeZone: zone === 'system' ? undefined : zone, month: 'short', day: 'numeric' }).format(d);
|
|
94
132
|
/** "Wed". */
|
|
95
|
-
export const formatWeekday = (d: Date, locale?: string, weekday: 'short' | 'long' = 'short') =>
|
|
96
|
-
fmt(locale, { weekday }).format(d);
|
|
133
|
+
export const formatWeekday = (d: Date, locale?: string, weekday: 'short' | 'long' = 'short', zone = 'system') =>
|
|
134
|
+
fmt(locale, { timeZone: zone === 'system' ? undefined : zone, weekday }).format(d);
|
|
97
135
|
|
|
98
136
|
/** "Apr 13 – 19, 2026" (or across months / years). */
|
|
99
|
-
export function formatWeekRange(days: readonly Date[], locale?: string): string {
|
|
137
|
+
export function formatWeekRange(days: readonly Date[], locale?: string, zone = 'system'): string {
|
|
100
138
|
const first = days[0];
|
|
101
139
|
const last = days[days.length - 1];
|
|
102
140
|
if (!first || !last) return '';
|
|
103
141
|
if (locale && !locale.toLowerCase().startsWith('en'))
|
|
104
|
-
return fmt(locale, {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
142
|
+
return fmt(locale, {
|
|
143
|
+
timeZone: zone === 'system' ? undefined : zone,
|
|
144
|
+
month: 'short',
|
|
145
|
+
day: 'numeric',
|
|
146
|
+
year: 'numeric',
|
|
147
|
+
}).formatRange(first, last);
|
|
148
|
+
if (sameMonth(first, last, zone))
|
|
149
|
+
return `${formatShort(first, 'en-US', zone)} – ${zonedParts(last, zone).day}, ${zonedParts(last, zone).year}`;
|
|
150
|
+
if (zonedParts(first, zone).year === zonedParts(last, zone).year)
|
|
151
|
+
return `${formatShort(first, 'en-US', zone)} – ${formatShort(last, 'en-US', zone)}, ${zonedParts(last, zone).year}`;
|
|
152
|
+
return `${formatShort(first, 'en-US', zone)}, ${zonedParts(first, zone).year} – ${formatShort(last, 'en-US', zone)}, ${zonedParts(last, zone).year}`;
|
|
109
153
|
}
|
|
110
154
|
|
|
111
155
|
/** Internal to blocks: Intl weekdays 1–7 become JS weekdays 0–6. */
|
|
@@ -77,10 +77,10 @@ export const TONE: Record<EventTone, { dot: string; soft: string; bar: string; i
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
/** Events grouped by local day key, each day sorted by start. */
|
|
80
|
-
export function groupByDay(events: readonly ScheduleEvent[]): Map<string, ScheduleEvent[]> {
|
|
80
|
+
export function groupByDay(events: readonly ScheduleEvent[], timeZone = 'system'): Map<string, ScheduleEvent[]> {
|
|
81
81
|
const map = new Map<string, ScheduleEvent[]>();
|
|
82
82
|
for (const e of events) {
|
|
83
|
-
const key = dayKey(e.start);
|
|
83
|
+
const key = dayKey(e.start, timeZone);
|
|
84
84
|
const list = map.get(key);
|
|
85
85
|
if (list) list.push(e);
|
|
86
86
|
else map.set(key, [e]);
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { render, screen, within } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { MenuItem } from '@gntik-ai/ui';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
6
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
7
|
+
import { AppSidebar, AppSidebarFooter, AppSidebarHeader, AppSidebarNav } from './AppSidebar';
|
|
8
|
+
|
|
9
|
+
const tenants = [
|
|
10
|
+
{ id: 't1', name: 'One' },
|
|
11
|
+
{ id: 't2', name: 'Two' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
describe('AppSidebar context', () => {
|
|
15
|
+
it('keeps the default header markup byte-identical to 0.11.0, including generated IDs', () => {
|
|
16
|
+
// Captured from the assigned immutable base dbf5a248e551cace019a26c105a8d76f866b2647.
|
|
17
|
+
const html = renderToStaticMarkup(<AppSidebarHeader />);
|
|
18
|
+
expect(createHash('sha256').update(html).digest('hex')).toBe(
|
|
19
|
+
'4aeef719ee282401ef33d640e7e4745d3bfbbb93e81b6e6e15ab2290fad2b2fc',
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
it('forwards context, branding and menu content through the composite sidebar', async () => {
|
|
23
|
+
const onTenantSelect = vi.fn();
|
|
24
|
+
render(
|
|
25
|
+
<AppSidebar
|
|
26
|
+
tenants={tenants}
|
|
27
|
+
currentTenantId="t1"
|
|
28
|
+
onTenantSelect={onTenantSelect}
|
|
29
|
+
tenantLabel="Organization"
|
|
30
|
+
tenantEmptyText="No organizations"
|
|
31
|
+
workspaceLabel="Spaces"
|
|
32
|
+
workspaceEmptyText="No spaces"
|
|
33
|
+
contextRegionLabel="Active context"
|
|
34
|
+
contextBusy
|
|
35
|
+
contextStatus={<span role="status">Syncing</span>}
|
|
36
|
+
brand={<span>Console identity</span>}
|
|
37
|
+
userMenuChildren={<MenuItem>Language</MenuItem>}
|
|
38
|
+
/>,
|
|
39
|
+
);
|
|
40
|
+
const region = screen.getByRole('region', { name: 'Active context' });
|
|
41
|
+
expect(region).toHaveAttribute('aria-busy', 'true');
|
|
42
|
+
expect(within(region).getByRole('status')).toHaveTextContent('Syncing');
|
|
43
|
+
const tenant = within(region).getByRole('combobox', { name: 'Organization' });
|
|
44
|
+
expect(tenant).toHaveTextContent('One');
|
|
45
|
+
expect(within(region).getByRole('button', { name: /Spaces/ })).toBeInTheDocument();
|
|
46
|
+
expect(screen.getByText('Console identity')).toBeInTheDocument();
|
|
47
|
+
await userEvent.click(tenant);
|
|
48
|
+
await userEvent.click(await screen.findByRole('option', { name: 'Two' }));
|
|
49
|
+
expect(onTenantSelect).toHaveBeenCalledWith('t2');
|
|
50
|
+
await userEvent.click(screen.getByRole('button', { name: /Dana Whitfield/ }));
|
|
51
|
+
expect(within(await screen.findByRole('menu')).getByRole('menuitem', { name: 'Language' })).toBeInTheDocument();
|
|
52
|
+
await expectNoAxeViolations();
|
|
53
|
+
});
|
|
54
|
+
it('adds footer menu children alongside items while allowing usage and help to be hidden', async () => {
|
|
55
|
+
render(
|
|
56
|
+
<AppSidebarFooter
|
|
57
|
+
usage={null}
|
|
58
|
+
helpHref=""
|
|
59
|
+
userMenuItems={[{ label: 'Account' }]}
|
|
60
|
+
userMenuChildren={<MenuItem>Language</MenuItem>}
|
|
61
|
+
/>,
|
|
62
|
+
);
|
|
63
|
+
expect(screen.queryByRole('meter')).toBeNull();
|
|
64
|
+
expect(screen.queryByRole('link')).toBeNull();
|
|
65
|
+
await userEvent.click(screen.getByRole('button', { name: /Dana Whitfield/ }));
|
|
66
|
+
const menu = await screen.findByRole('menu');
|
|
67
|
+
expect(within(menu).getByRole('menuitem', { name: 'Language' })).toBeInTheDocument();
|
|
68
|
+
expect(within(menu).getByRole('menuitem', { name: 'Account' })).toBeInTheDocument();
|
|
69
|
+
await expectNoAxeViolations();
|
|
70
|
+
});
|
|
71
|
+
it('replaces the logo with a brand in expanded, logo-only, hidden-context and rail headers', () => {
|
|
72
|
+
const brand = <span>Console identity</span>;
|
|
73
|
+
const { rerender } = render(<AppSidebarHeader brand={brand} />);
|
|
74
|
+
expect(screen.getByText('Console identity')).toBeInTheDocument();
|
|
75
|
+
expect(screen.getByRole('button', { name: /Acme Industries/ })).toBeInTheDocument();
|
|
76
|
+
for (const props of [
|
|
77
|
+
{ workspaces: null },
|
|
78
|
+
{ workspaces: [] },
|
|
79
|
+
{ hideWorkspaceContext: true },
|
|
80
|
+
{ collapsed: true },
|
|
81
|
+
]) {
|
|
82
|
+
rerender(<AppSidebarHeader brand={brand} tenants={tenants} contextRegionLabel="Active context" {...props} />);
|
|
83
|
+
expect(screen.getByText('Console identity')).toBeInTheDocument();
|
|
84
|
+
expect(screen.queryByRole('img')).toBeNull();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
it('opts into a named busy region and hides context in platform-wide and collapsed modes', () => {
|
|
88
|
+
const props = {
|
|
89
|
+
tenants,
|
|
90
|
+
contextRegionLabel: 'Active context',
|
|
91
|
+
contextBusy: true,
|
|
92
|
+
contextStatus: <span role="status">Updating context</span>,
|
|
93
|
+
};
|
|
94
|
+
const { container, rerender } = render(<AppSidebarHeader {...props} />);
|
|
95
|
+
const region = screen.getByRole('region', { name: 'Active context' });
|
|
96
|
+
expect(region).toHaveAttribute('aria-busy', 'true');
|
|
97
|
+
expect(within(region).getByRole('combobox', { name: 'Tenant' })).toBeInTheDocument();
|
|
98
|
+
expect(within(region).getByRole('button', { name: /Acme Industries/ })).toBeInTheDocument();
|
|
99
|
+
expect(within(region).getByRole('status')).toHaveTextContent('Updating context');
|
|
100
|
+
rerender(<AppSidebarHeader {...props} contextRegionLabel={undefined} />);
|
|
101
|
+
expect(container.querySelector('section')).toBeNull();
|
|
102
|
+
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
103
|
+
rerender(<AppSidebarHeader {...props} hideWorkspaceContext />);
|
|
104
|
+
expect(screen.queryByRole('region')).toBeNull();
|
|
105
|
+
expect(screen.queryByRole('combobox')).toBeNull();
|
|
106
|
+
expect(screen.queryByRole('button')).toBeNull();
|
|
107
|
+
expect(screen.queryByRole('status')).toBeNull();
|
|
108
|
+
expect(screen.getByRole('img')).toBeInTheDocument();
|
|
109
|
+
rerender(<AppSidebarHeader {...props} collapsed />);
|
|
110
|
+
expect(screen.queryByRole('region')).toBeNull();
|
|
111
|
+
expect(screen.queryByRole('combobox')).toBeNull();
|
|
112
|
+
expect(screen.queryByRole('status')).toBeNull();
|
|
113
|
+
expect(screen.getByRole('img')).toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
it('passes workspace headings and search empty copy without adding a create entry', async () => {
|
|
116
|
+
const user = userEvent.setup();
|
|
117
|
+
const { rerender } = render(<AppSidebarHeader workspaceLabel="Available spaces" />);
|
|
118
|
+
await user.click(screen.getByRole('button', { name: /Acme Industries/ }));
|
|
119
|
+
expect(await screen.findByRole('group', { name: 'Available spaces' })).toBeInTheDocument();
|
|
120
|
+
expect(screen.queryByRole('menuitem', { name: 'Create workspace' })).toBeNull();
|
|
121
|
+
await user.keyboard('{Escape}');
|
|
122
|
+
rerender(
|
|
123
|
+
<AppSidebarHeader
|
|
124
|
+
workspaceLabel="Available spaces"
|
|
125
|
+
workspaceEmptyText="No matching spaces"
|
|
126
|
+
workspaces={Array.from({ length: 7 }, (_, i) => ({ id: `w${i}`, name: `Space ${i}` }))}
|
|
127
|
+
/>,
|
|
128
|
+
);
|
|
129
|
+
await user.click(screen.getByRole('combobox', { name: /Available spaces/ }));
|
|
130
|
+
expect(await screen.findByRole('listbox', { name: 'Available spaces' })).toBeInTheDocument();
|
|
131
|
+
await user.type(screen.getByRole('combobox', { name: 'Find a workspace' }), 'no match');
|
|
132
|
+
expect(await screen.findByText('No matching spaces')).toBeInTheDocument();
|
|
133
|
+
expect(screen.queryByRole('option', { name: 'Create workspace' })).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
it('omits tenants by default and shows the empty tenant text even without workspaces', () => {
|
|
136
|
+
const { rerender } = render(<AppSidebarHeader />);
|
|
137
|
+
expect(screen.queryByRole('combobox')).toBeNull();
|
|
138
|
+
rerender(
|
|
139
|
+
<AppSidebarHeader tenants={[]} tenantLabel="Organization" tenantEmptyText="No organizations" workspaces={null} />,
|
|
140
|
+
);
|
|
141
|
+
expect(screen.getByRole('combobox', { name: 'Organization' })).toHaveTextContent('No organizations');
|
|
142
|
+
expect(screen.getByRole('img')).toBeInTheDocument();
|
|
143
|
+
});
|
|
144
|
+
it('selects and clears a tenant before workspace and navigation in keyboard order', async () => {
|
|
145
|
+
const user = userEvent.setup();
|
|
146
|
+
const onTenantSelect = vi.fn();
|
|
147
|
+
const { container } = render(
|
|
148
|
+
<>
|
|
149
|
+
<AppSidebarHeader tenants={tenants} currentTenantId="t1" tenantLabel="Tenant" onTenantSelect={onTenantSelect} />
|
|
150
|
+
<AppSidebarNav />
|
|
151
|
+
</>,
|
|
152
|
+
);
|
|
153
|
+
const tenant = screen.getByRole('combobox', { name: 'Tenant' });
|
|
154
|
+
expect(tenant).toHaveTextContent('One');
|
|
155
|
+
expect(container.querySelector('section')).toBeNull();
|
|
156
|
+
await user.tab();
|
|
157
|
+
expect(tenant).toHaveFocus();
|
|
158
|
+
await user.tab();
|
|
159
|
+
expect(screen.getByRole('button', { name: 'Clear Tenant' })).toHaveFocus();
|
|
160
|
+
await user.tab();
|
|
161
|
+
expect(screen.getByRole('button', { name: /Acme Industries/ })).toHaveFocus();
|
|
162
|
+
await user.tab();
|
|
163
|
+
expect(screen.getByRole('link', { name: 'Overview' })).toHaveFocus();
|
|
164
|
+
await user.click(tenant);
|
|
165
|
+
await screen.findByRole('listbox', { name: 'Tenant' });
|
|
166
|
+
await expectNoAxeViolations();
|
|
167
|
+
await user.click(await screen.findByRole('option', { name: 'Two' }));
|
|
168
|
+
expect(onTenantSelect).toHaveBeenCalledWith('t2');
|
|
169
|
+
await user.click(tenant);
|
|
170
|
+
await user.keyboard('{Escape}');
|
|
171
|
+
tenant.focus();
|
|
172
|
+
await user.keyboard('{Delete}');
|
|
173
|
+
expect(onTenantSelect).toHaveBeenLastCalledWith(null);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ComponentDoc } from '@gntik-ai/ui';
|
|
2
|
+
import { meta } from './block.meta';
|
|
3
|
+
|
|
4
|
+
export const doc: ComponentDoc = {
|
|
5
|
+
name: 'AppSidebar',
|
|
6
|
+
group: 'Navigation',
|
|
7
|
+
status: 'beta',
|
|
8
|
+
description:
|
|
9
|
+
`${meta.description} Optional tenants render before the workspace control using the kit Select. ` +
|
|
10
|
+
'tenantLabel and tenantEmptyText customize its name and empty placeholder; clearing reports null. ' +
|
|
11
|
+
'workspaceLabel and workspaceEmptyText customize the workspace popup and search results. ' +
|
|
12
|
+
'hideWorkspaceContext hides both controls, contextStatus and the region, preserving brand or Logo. ' +
|
|
13
|
+
'contextRegionLabel opts into a named section; without it, controls and contextStatus have no extra wrapper. ' +
|
|
14
|
+
'The consumer owns contextBusy and must reset it when loading completes. The collapsed rail hides context; ' +
|
|
15
|
+
'expand the sidebar or open its mobile drawer to switch tenants. brand replaces Logo in either state. ' +
|
|
16
|
+
'userMenuChildren adds popup content alongside userMenuItems; usage=null and helpHref="" hide usage and help. ' +
|
|
17
|
+
'ConsoleShell forwards these props and also shows brand in the mobile topbar. See the five Sidebar shell examples.',
|
|
18
|
+
primitive: 'Select, WorkspaceSwitcher, NavList and UserMenu from @gntik-ai/ui',
|
|
19
|
+
pattern: 'Optional named context region, select-only combobox, navigation and account menu',
|
|
20
|
+
keyboard: [
|
|
21
|
+
['Tab', 'Tenant picker and its clear control, then workspace picker, then navigation'],
|
|
22
|
+
['Enter / Space', 'Open the focused tenant or workspace picker, or account menu'],
|
|
23
|
+
['ArrowDown / ArrowUp', 'Move through the open picker or menu'],
|
|
24
|
+
['Enter', 'Select the highlighted item'],
|
|
25
|
+
['Escape', 'Close the popup and return focus to its trigger'],
|
|
26
|
+
['Delete / Backspace', 'On a selected tenant trigger, clear to the platform-wide context'],
|
|
27
|
+
],
|
|
28
|
+
tokens: ['chrome', 'card', 'border', 'foreground', 'muted-foreground', 'focus-ring'],
|
|
29
|
+
};
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Logo,
|
|
5
5
|
Meter,
|
|
6
6
|
NavList,
|
|
7
|
+
SimpleSelect,
|
|
7
8
|
UserMenu,
|
|
8
9
|
WorkspaceSwitcher,
|
|
9
10
|
cn,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
type UserMenuUser,
|
|
14
15
|
type Workspace,
|
|
15
16
|
} from '@gntik-ai/ui';
|
|
16
|
-
import { useState } from 'react';
|
|
17
|
+
import { useState, type ReactNode } from 'react';
|
|
17
18
|
import {
|
|
18
19
|
appSidebarNavGroups,
|
|
19
20
|
appSidebarUsage,
|
|
@@ -30,6 +31,23 @@ export interface AppSidebarHeaderProps {
|
|
|
30
31
|
currentWorkspaceId?: string;
|
|
31
32
|
onWorkspaceChange?: (workspace: Workspace) => void;
|
|
32
33
|
onCreateWorkspace?: () => void;
|
|
34
|
+
/** Omit to hide the tenant picker. Clearing selects the platform-wide context. */
|
|
35
|
+
tenants?: { id: string; name: string }[];
|
|
36
|
+
currentTenantId?: string | null;
|
|
37
|
+
onTenantSelect?: (id: string | null) => void;
|
|
38
|
+
tenantLabel?: string;
|
|
39
|
+
tenantEmptyText?: string;
|
|
40
|
+
workspaceLabel?: string;
|
|
41
|
+
workspaceEmptyText?: string;
|
|
42
|
+
/** Platform-wide mode: hide all context controls and status. */
|
|
43
|
+
hideWorkspaceContext?: boolean;
|
|
44
|
+
/** Opt into a named section around the controls and status. */
|
|
45
|
+
contextRegionLabel?: string;
|
|
46
|
+
/** Consumer-owned loading state; reset when the context finishes changing. */
|
|
47
|
+
contextBusy?: boolean;
|
|
48
|
+
contextStatus?: ReactNode;
|
|
49
|
+
/** Product-owned identity, rendered in place of the default logo. */
|
|
50
|
+
brand?: ReactNode;
|
|
33
51
|
className?: string;
|
|
34
52
|
}
|
|
35
53
|
|
|
@@ -40,23 +58,79 @@ export function AppSidebarHeader({
|
|
|
40
58
|
currentWorkspaceId,
|
|
41
59
|
onWorkspaceChange,
|
|
42
60
|
onCreateWorkspace,
|
|
61
|
+
tenants,
|
|
62
|
+
currentTenantId,
|
|
63
|
+
onTenantSelect,
|
|
64
|
+
tenantLabel = 'Tenant',
|
|
65
|
+
tenantEmptyText = 'No tenants',
|
|
66
|
+
workspaceLabel,
|
|
67
|
+
workspaceEmptyText,
|
|
68
|
+
hideWorkspaceContext,
|
|
69
|
+
contextRegionLabel,
|
|
70
|
+
contextBusy,
|
|
71
|
+
contextStatus,
|
|
72
|
+
brand,
|
|
43
73
|
className,
|
|
44
74
|
}: AppSidebarHeaderProps) {
|
|
45
75
|
const [current, setCurrent] = useState(currentWorkspaceId ?? workspaces?.[0]?.id ?? '');
|
|
46
76
|
const currentId = currentWorkspaceId ?? current;
|
|
47
|
-
if (collapsed) return <Logo size={26} className={className} />;
|
|
48
|
-
if (
|
|
77
|
+
if (collapsed) return brand ?? <Logo size={26} className={className} />;
|
|
78
|
+
if (hideWorkspaceContext) return brand ?? <Logo size={24} wordmark className={cn('px-1', className)} />;
|
|
79
|
+
// Stack the existing slot parent only for opted-in content, without adding a wrapper.
|
|
80
|
+
const stackParent = '[:has(>_&)]:flex-col [:has(>_&)]:items-stretch [:has(>_&)]:gap-2';
|
|
81
|
+
const workspaceControl =
|
|
82
|
+
!workspaces || workspaces.length === 0 ? (
|
|
83
|
+
brand == null && (
|
|
84
|
+
<Logo size={24} wordmark className={cn('px-1', contextStatus != null && stackParent, className)} />
|
|
85
|
+
)
|
|
86
|
+
) : (
|
|
87
|
+
<WorkspaceSwitcher
|
|
88
|
+
label={workspaceLabel}
|
|
89
|
+
emptyText={workspaceEmptyText}
|
|
90
|
+
className={cn('w-full', (brand != null || contextStatus != null) && stackParent, className)}
|
|
91
|
+
workspaces={workspaces}
|
|
92
|
+
currentId={currentId}
|
|
93
|
+
onCreate={onCreateWorkspace}
|
|
94
|
+
onSelect={(w) => {
|
|
95
|
+
setCurrent(w.id);
|
|
96
|
+
onWorkspaceChange?.(w);
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
// Preserve the original tree path as well as its DOM: Base UI derives IDs from it during SSR.
|
|
101
|
+
if (!tenants && brand == null && !contextRegionLabel && contextStatus == null) return workspaceControl;
|
|
102
|
+
const controls = (
|
|
103
|
+
<>
|
|
104
|
+
{tenants && (
|
|
105
|
+
<SimpleSelect
|
|
106
|
+
items={tenants.map(({ id, name }) => ({ value: id, label: name }))}
|
|
107
|
+
value={currentTenantId}
|
|
108
|
+
onValueChange={(id) => onTenantSelect?.(id)}
|
|
109
|
+
aria-label={tenantLabel}
|
|
110
|
+
placeholder={tenants.length === 0 ? tenantEmptyText : 'Select tenant'}
|
|
111
|
+
clearable
|
|
112
|
+
className="w-full [&+button]:min-h-6 [&+button]:min-w-6 [:has(>_*_>_&)]:flex-col [:has(>_*_>_&)]:items-stretch [:has(>_*_>_&)]:gap-2"
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
{workspaceControl}
|
|
116
|
+
{contextStatus}
|
|
117
|
+
</>
|
|
118
|
+
);
|
|
49
119
|
return (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
120
|
+
<>
|
|
121
|
+
{brand}
|
|
122
|
+
{contextRegionLabel ? (
|
|
123
|
+
<section
|
|
124
|
+
aria-label={contextRegionLabel}
|
|
125
|
+
aria-busy={contextBusy}
|
|
126
|
+
className={cn('flex w-full min-w-0 flex-col gap-2', brand != null && stackParent)}
|
|
127
|
+
>
|
|
128
|
+
{controls}
|
|
129
|
+
</section>
|
|
130
|
+
) : (
|
|
131
|
+
controls
|
|
132
|
+
)}
|
|
133
|
+
</>
|
|
60
134
|
);
|
|
61
135
|
}
|
|
62
136
|
|
|
@@ -101,6 +175,8 @@ export interface AppSidebarFooterProps {
|
|
|
101
175
|
/** Signed-in user; `null` hides the user menu. */
|
|
102
176
|
user?: UserMenuUser | null;
|
|
103
177
|
userMenuItems?: UserMenuEntry[];
|
|
178
|
+
/** Extra content inside the account menu popup, before sign out. */
|
|
179
|
+
userMenuChildren?: ReactNode;
|
|
104
180
|
onSignOut?: () => void;
|
|
105
181
|
className?: string;
|
|
106
182
|
}
|
|
@@ -113,6 +189,7 @@ export function AppSidebarFooter({
|
|
|
113
189
|
helpLabel = 'Help & docs',
|
|
114
190
|
user = appSidebarUser,
|
|
115
191
|
userMenuItems,
|
|
192
|
+
userMenuChildren,
|
|
116
193
|
onSignOut,
|
|
117
194
|
className,
|
|
118
195
|
}: AppSidebarFooterProps) {
|
|
@@ -152,7 +229,9 @@ export function AppSidebarFooter({
|
|
|
152
229
|
onSignOut={onSignOut}
|
|
153
230
|
showName={!collapsed}
|
|
154
231
|
className={collapsed ? undefined : 'w-full justify-start'}
|
|
155
|
-
|
|
232
|
+
>
|
|
233
|
+
{userMenuChildren}
|
|
234
|
+
</UserMenu>
|
|
156
235
|
)}
|
|
157
236
|
</div>
|
|
158
237
|
);
|
|
@@ -174,10 +253,6 @@ export interface AppSidebarProps
|
|
|
174
253
|
*/
|
|
175
254
|
export function AppSidebar({
|
|
176
255
|
collapsed = false,
|
|
177
|
-
workspaces,
|
|
178
|
-
currentWorkspaceId,
|
|
179
|
-
onWorkspaceChange,
|
|
180
|
-
onCreateWorkspace,
|
|
181
256
|
navGroups,
|
|
182
257
|
navLabel,
|
|
183
258
|
currentHref,
|
|
@@ -187,19 +262,15 @@ export function AppSidebar({
|
|
|
187
262
|
helpLabel,
|
|
188
263
|
user,
|
|
189
264
|
userMenuItems,
|
|
265
|
+
userMenuChildren,
|
|
190
266
|
onSignOut,
|
|
191
267
|
className,
|
|
268
|
+
...headerProps
|
|
192
269
|
}: AppSidebarProps) {
|
|
193
270
|
return (
|
|
194
271
|
<div className={cn('flex h-full min-h-0 flex-col bg-chrome', collapsed ? 'w-16' : 'w-[248px]', className)}>
|
|
195
272
|
<div className={cn('flex shrink-0 items-center pt-4 pb-3', collapsed ? 'justify-center px-2' : 'px-3')}>
|
|
196
|
-
<AppSidebarHeader
|
|
197
|
-
collapsed={collapsed}
|
|
198
|
-
workspaces={workspaces}
|
|
199
|
-
currentWorkspaceId={currentWorkspaceId}
|
|
200
|
-
onWorkspaceChange={onWorkspaceChange}
|
|
201
|
-
onCreateWorkspace={onCreateWorkspace}
|
|
202
|
-
/>
|
|
273
|
+
<AppSidebarHeader collapsed={collapsed} {...headerProps} />
|
|
203
274
|
</div>
|
|
204
275
|
<div className={cn('min-h-0 flex-1 overflow-y-auto pt-1 pb-3', collapsed ? 'px-2' : 'px-3')}>
|
|
205
276
|
<AppSidebarNav
|
|
@@ -218,6 +289,7 @@ export function AppSidebar({
|
|
|
218
289
|
helpLabel={helpLabel}
|
|
219
290
|
user={user}
|
|
220
291
|
userMenuItems={userMenuItems}
|
|
292
|
+
userMenuChildren={userMenuChildren}
|
|
221
293
|
onSignOut={onSignOut}
|
|
222
294
|
/>
|
|
223
295
|
</div>
|
|
@@ -6,5 +6,5 @@ export const meta: BlockMeta = {
|
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
8
|
'Application sidebar: workspace switcher (or logo) header, NavList body with icon-rail support, and a footer with plan usage, help link and user menu. Exposes header / nav / footer parts for the SidebarLayout slots.',
|
|
9
|
-
uses: ['WorkspaceSwitcher', 'Logo', 'NavList', 'Meter', 'Link', 'UserMenu'],
|
|
9
|
+
uses: ['SimpleSelect', 'WorkspaceSwitcher', 'Logo', 'NavList', 'Meter', 'Link', 'UserMenu'],
|
|
10
10
|
};
|
|
@@ -23,6 +23,7 @@ describe('GlobalSearch', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('⌘K opens it with recent and grouped results; choosing one reports its group', async () => {
|
|
26
|
+
vi.stubGlobal('navigator', { platform: 'MacIntel' });
|
|
26
27
|
const user = userEvent.setup();
|
|
27
28
|
const onSelect = vi.fn();
|
|
28
29
|
render(<GlobalSearch onSelect={onSelect} />);
|
|
@@ -13,7 +13,7 @@ export interface GlobalSearchProps {
|
|
|
13
13
|
onSelect?: (item: CommandItem, group: GlobalSearchGroup) => void;
|
|
14
14
|
/** Group headings. */
|
|
15
15
|
labels?: Partial<Record<GlobalSearchGroup, string>>;
|
|
16
|
-
/** Registers ⌘K / Ctrl+K. */
|
|
16
|
+
/** Registers ⌘K on macOS/iOS and Ctrl+K on other platforms. */
|
|
17
17
|
shortcut?: boolean;
|
|
18
18
|
open?: boolean;
|
|
19
19
|
defaultOpen?: boolean;
|