@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
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { DataTableProps, DataTableQuery } from '../tables/DataTable/DataTable';
|
|
3
|
+
import type { SortState } from '../tables/DataTable/data-table-utils';
|
|
4
|
+
import type { LoadMoreFooterProps } from '../tables/LoadMoreFooter/LoadMoreFooter';
|
|
5
|
+
|
|
6
|
+
/** One server query. Pages are 1-based; cursor is null for the first cursor page. */
|
|
7
|
+
export interface TableDataParams<F = unknown> {
|
|
8
|
+
page: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
sort: SortState | null;
|
|
11
|
+
filters: F | undefined;
|
|
12
|
+
cursor: string | null;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A numbered page supplies rowCount; a cursor page supplies nextCursor (null means exhausted). */
|
|
17
|
+
export interface TableDataResult<T> {
|
|
18
|
+
rows: T[];
|
|
19
|
+
rowCount?: number;
|
|
20
|
+
nextCursor?: string | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Per-instance server data options. Filters must support JSON.stringify. */
|
|
24
|
+
export interface UseTableDataOptions<T, F = unknown> {
|
|
25
|
+
getRows: (params: TableDataParams<F>) => Promise<TableDataResult<T>>;
|
|
26
|
+
/** Initial numbered page, 1-based (default 1). */
|
|
27
|
+
initialPage?: number;
|
|
28
|
+
/** Rows per request (default 20). */
|
|
29
|
+
initialPageSize?: number;
|
|
30
|
+
/** Initial server order (default null). */
|
|
31
|
+
initialSort?: SortState | null;
|
|
32
|
+
/** Compared by JSON.stringify value, including object key order. */
|
|
33
|
+
filters?: F;
|
|
34
|
+
/** Freshness in milliseconds (30000); zero disables cache reads and writes. */
|
|
35
|
+
cacheTime?: number;
|
|
36
|
+
/** Retain the last resolved page while fetching (default true). */
|
|
37
|
+
keepPreviousData?: boolean;
|
|
38
|
+
/** Foreground polling in milliseconds (zero, the default, disables it). */
|
|
39
|
+
revalidateInterval?: number;
|
|
40
|
+
/** False aborts work and clears loading (default true). */
|
|
41
|
+
enabled?: boolean;
|
|
42
|
+
/** Called once per current non-abort failure; nullish reasons become an Error. */
|
|
43
|
+
onError?: (error: unknown) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type Query<F> = Omit<TableDataParams<F>, 'signal'>;
|
|
47
|
+
type TableProps<T> = Required<
|
|
48
|
+
Pick<
|
|
49
|
+
DataTableProps<T>,
|
|
50
|
+
| 'rows'
|
|
51
|
+
| 'paginationMode'
|
|
52
|
+
| 'rowCount'
|
|
53
|
+
| 'page'
|
|
54
|
+
| 'pageSize'
|
|
55
|
+
| 'onPageChange'
|
|
56
|
+
| 'onPageSizeChange'
|
|
57
|
+
| 'sort'
|
|
58
|
+
| 'onSortChange'
|
|
59
|
+
| 'onQueryChange'
|
|
60
|
+
| 'manualSorting'
|
|
61
|
+
| 'loading'
|
|
62
|
+
| 'filters'
|
|
63
|
+
>
|
|
64
|
+
> & { paginationMode: 'server' };
|
|
65
|
+
interface Snapshot<T> {
|
|
66
|
+
rows: T[];
|
|
67
|
+
rowCount: number;
|
|
68
|
+
nextCursor: string | null | undefined;
|
|
69
|
+
page: number;
|
|
70
|
+
pageSize: number;
|
|
71
|
+
sort: SortState | null;
|
|
72
|
+
isLoading: boolean;
|
|
73
|
+
isFetching: boolean;
|
|
74
|
+
footerLoading: boolean;
|
|
75
|
+
error: unknown;
|
|
76
|
+
lastAppend: { seq: number; count: number };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Data and props for a server DataTable; params describes the requested page, including while old rows remain. */
|
|
80
|
+
export interface UseTableDataResult<T, F = unknown> extends Omit<Snapshot<T>, 'footerLoading'> {
|
|
81
|
+
/** Requested values; the AbortSignal is passed only to getRows. */
|
|
82
|
+
params: Query<F>;
|
|
83
|
+
tableProps: TableProps<T>;
|
|
84
|
+
loadMoreProps: LoadMoreFooterProps;
|
|
85
|
+
hasMore: boolean;
|
|
86
|
+
/** Append the next cursor page; after a failure, retry the query before loading more. */
|
|
87
|
+
loadMore: () => void;
|
|
88
|
+
/** Bypass cache freshness and replace active work; cursor lists restart at the first page. */
|
|
89
|
+
refetch: () => void;
|
|
90
|
+
/** Clear this instance's cache and refetch. */
|
|
91
|
+
invalidate: () => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Map committed table queries to abortable requests. Callback identities do not trigger requests.
|
|
96
|
+
* Spread tableProps into DataTable; use paginated={false} and loadMoreProps for cursor lists.
|
|
97
|
+
* Available from the npm package only (not the copy-install registry).
|
|
98
|
+
*/
|
|
99
|
+
export function useTableData<T, F = unknown>(options: UseTableDataOptions<T, F>): UseTableDataResult<T, F> {
|
|
100
|
+
const { enabled = true } = options;
|
|
101
|
+
const filtersKey = JSON.stringify(options.filters);
|
|
102
|
+
const [request, setRequest] = useState(() => ({
|
|
103
|
+
query: {
|
|
104
|
+
page: options.initialPage ?? 1,
|
|
105
|
+
pageSize: options.initialPageSize ?? 20,
|
|
106
|
+
sort: options.initialSort ?? null,
|
|
107
|
+
filters: options.filters,
|
|
108
|
+
cursor: null as string | null,
|
|
109
|
+
},
|
|
110
|
+
filtersKey,
|
|
111
|
+
revision: 0,
|
|
112
|
+
force: false,
|
|
113
|
+
prefix: [] as T[],
|
|
114
|
+
}));
|
|
115
|
+
// Remember each external filter value, including a return to the initial value.
|
|
116
|
+
// React retries this render before committing effects, so no request starts here.
|
|
117
|
+
if (request.filtersKey !== filtersKey) {
|
|
118
|
+
setRequest({
|
|
119
|
+
...request,
|
|
120
|
+
filtersKey,
|
|
121
|
+
force: false,
|
|
122
|
+
prefix: [],
|
|
123
|
+
revision: request.revision + 1,
|
|
124
|
+
query: { ...request.query, page: 1, cursor: null, filters: options.filters },
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const params: Query<F> = request.query;
|
|
128
|
+
const key = JSON.stringify(params);
|
|
129
|
+
const [snapshot, setSnapshot] = useState<Snapshot<T>>(() => ({
|
|
130
|
+
rows: [],
|
|
131
|
+
rowCount: 0,
|
|
132
|
+
nextCursor: undefined,
|
|
133
|
+
page: params.page,
|
|
134
|
+
pageSize: params.pageSize,
|
|
135
|
+
sort: params.sort,
|
|
136
|
+
isLoading: enabled,
|
|
137
|
+
isFetching: false,
|
|
138
|
+
footerLoading: false,
|
|
139
|
+
error: null,
|
|
140
|
+
lastAppend: { seq: 0, count: 0 },
|
|
141
|
+
}));
|
|
142
|
+
const data = useRef(snapshot);
|
|
143
|
+
const resolved = useRef(snapshot);
|
|
144
|
+
const prefix = request.prefix;
|
|
145
|
+
const latest = useRef({ options, params, key, prefix });
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
latest.current = { options, params, key, prefix };
|
|
148
|
+
});
|
|
149
|
+
const cache = useRef(new Map<string, { value: Snapshot<T>; pageRows: T[]; at: number }>());
|
|
150
|
+
const active = useRef<{ key: string; controller: AbortController } | null>(null);
|
|
151
|
+
const forcedRevision = useRef(-1);
|
|
152
|
+
const mounted = useRef(false);
|
|
153
|
+
const confirmedSort = useRef(params.sort);
|
|
154
|
+
const confirmedKey = useRef<string | null>(null);
|
|
155
|
+
const abortedAppendKey = useRef<string | null>(null);
|
|
156
|
+
const hasData = useRef(false);
|
|
157
|
+
const publish = useCallback((next: Snapshot<T>) => {
|
|
158
|
+
data.current = next;
|
|
159
|
+
setSnapshot(next);
|
|
160
|
+
}, []);
|
|
161
|
+
const abort = useCallback(() => {
|
|
162
|
+
active.current?.controller.abort();
|
|
163
|
+
active.current = null;
|
|
164
|
+
}, []);
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
mounted.current = true;
|
|
167
|
+
return () => {
|
|
168
|
+
mounted.current = false;
|
|
169
|
+
abort();
|
|
170
|
+
};
|
|
171
|
+
}, [abort]);
|
|
172
|
+
const start = useCallback(
|
|
173
|
+
(force = false, background = false) => {
|
|
174
|
+
const { options: current, params: query, key: queryKey, prefix: previousRows } = latest.current;
|
|
175
|
+
if (current.enabled === false) {
|
|
176
|
+
abort();
|
|
177
|
+
publish({
|
|
178
|
+
...resolved.current,
|
|
179
|
+
error: data.current.error,
|
|
180
|
+
isLoading: false,
|
|
181
|
+
isFetching: false,
|
|
182
|
+
footerLoading: false,
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// Poll only a confirmed segment; failed query changes and appends need an explicit retry.
|
|
187
|
+
if (background && queryKey !== confirmedKey.current) return;
|
|
188
|
+
if (!force && active.current?.key === queryKey) return;
|
|
189
|
+
abort();
|
|
190
|
+
abortedAppendKey.current = null;
|
|
191
|
+
const cacheTime = current.cacheTime ?? 30000;
|
|
192
|
+
const cached = cacheTime > 0 ? cache.current.get(queryKey) : undefined;
|
|
193
|
+
// A non-null cursor can also replace an already displayed segment on re-enable.
|
|
194
|
+
const addsSegment = query.cursor !== null && queryKey !== confirmedKey.current;
|
|
195
|
+
if (cached && !force) {
|
|
196
|
+
confirmedSort.current = cached.value.sort;
|
|
197
|
+
confirmedKey.current = queryKey;
|
|
198
|
+
hasData.current = true;
|
|
199
|
+
const appended = query.cursor !== null;
|
|
200
|
+
resolved.current = {
|
|
201
|
+
...cached.value,
|
|
202
|
+
// Cache the segment separately: a first-page refetch can change its prefix.
|
|
203
|
+
rows: appended ? [...previousRows, ...cached.pageRows] : cached.pageRows,
|
|
204
|
+
lastAppend:
|
|
205
|
+
addsSegment && !background
|
|
206
|
+
? { seq: data.current.lastAppend.seq + 1, count: cached.pageRows.length }
|
|
207
|
+
: data.current.lastAppend,
|
|
208
|
+
};
|
|
209
|
+
publish(resolved.current);
|
|
210
|
+
if (Date.now() - cached.at < cacheTime) return;
|
|
211
|
+
}
|
|
212
|
+
const attempt = { key: queryKey, controller: new AbortController() };
|
|
213
|
+
active.current = attempt;
|
|
214
|
+
const keep = query.cursor !== null || background || current.keepPreviousData !== false || Boolean(cached);
|
|
215
|
+
publish({
|
|
216
|
+
...data.current,
|
|
217
|
+
...(keep ? {} : { rows: [], page: query.page, pageSize: query.pageSize }),
|
|
218
|
+
sort: query.sort,
|
|
219
|
+
isLoading: !keep || !hasData.current,
|
|
220
|
+
isFetching: true,
|
|
221
|
+
footerLoading: !background && !(cached && !force),
|
|
222
|
+
});
|
|
223
|
+
const valid = () => mounted.current && active.current === attempt && !attempt.controller.signal.aborted;
|
|
224
|
+
const fail = (error: unknown) => {
|
|
225
|
+
if (!valid()) return;
|
|
226
|
+
active.current = null;
|
|
227
|
+
cache.current.delete(queryKey);
|
|
228
|
+
const aborted = typeof error === 'object' && error !== null && 'name' in error && error.name === 'AbortError';
|
|
229
|
+
if (aborted && query.cursor !== null) abortedAppendKey.current = queryKey;
|
|
230
|
+
const failure = error ?? new Error('Unable to load rows.');
|
|
231
|
+
publish({
|
|
232
|
+
...data.current,
|
|
233
|
+
rows: resolved.current.rows,
|
|
234
|
+
page: resolved.current.page,
|
|
235
|
+
pageSize: resolved.current.pageSize,
|
|
236
|
+
sort: confirmedSort.current,
|
|
237
|
+
isLoading: false,
|
|
238
|
+
isFetching: false,
|
|
239
|
+
footerLoading: false,
|
|
240
|
+
error: aborted ? null : failure,
|
|
241
|
+
});
|
|
242
|
+
if (!aborted) latest.current.options.onError?.(failure);
|
|
243
|
+
};
|
|
244
|
+
try {
|
|
245
|
+
Promise.resolve(current.getRows({ ...query, signal: attempt.controller.signal })).then((result) => {
|
|
246
|
+
if (!valid()) return;
|
|
247
|
+
active.current = null;
|
|
248
|
+
confirmedSort.current = query.sort;
|
|
249
|
+
confirmedKey.current = queryKey;
|
|
250
|
+
hasData.current = true;
|
|
251
|
+
const appended = query.cursor !== null;
|
|
252
|
+
const next = {
|
|
253
|
+
...data.current,
|
|
254
|
+
rows: appended ? [...previousRows, ...result.rows] : result.rows,
|
|
255
|
+
rowCount: result.rowCount ?? data.current.rowCount,
|
|
256
|
+
nextCursor: result.nextCursor,
|
|
257
|
+
page: query.page,
|
|
258
|
+
pageSize: query.pageSize,
|
|
259
|
+
sort: query.sort,
|
|
260
|
+
lastAppend:
|
|
261
|
+
addsSegment && !background && (!cached || force)
|
|
262
|
+
? { seq: data.current.lastAppend.seq + 1, count: result.rows.length }
|
|
263
|
+
: data.current.lastAppend,
|
|
264
|
+
isLoading: false,
|
|
265
|
+
isFetching: false,
|
|
266
|
+
footerLoading: false,
|
|
267
|
+
error: null,
|
|
268
|
+
};
|
|
269
|
+
if (cacheTime > 0) cache.current.set(queryKey, { value: next, pageRows: result.rows, at: Date.now() });
|
|
270
|
+
resolved.current = next;
|
|
271
|
+
publish(next);
|
|
272
|
+
}, fail);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
fail(error);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
[abort, publish],
|
|
278
|
+
);
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
// A forced reload belongs to this query change, not later enabled toggles.
|
|
281
|
+
const force = request.force && forcedRevision.current !== request.revision;
|
|
282
|
+
if (force && enabled) forcedRevision.current = request.revision;
|
|
283
|
+
start(force);
|
|
284
|
+
}, [key, request.revision, request.force, enabled, start]);
|
|
285
|
+
|
|
286
|
+
const interval = options.revalidateInterval ?? 0;
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
if (!enabled || interval <= 0) return;
|
|
289
|
+
const timer = setInterval(() => {
|
|
290
|
+
if (typeof document !== 'undefined' && document.hidden) return;
|
|
291
|
+
if (!active.current) start(true, true);
|
|
292
|
+
}, interval);
|
|
293
|
+
return () => clearInterval(timer);
|
|
294
|
+
}, [enabled, interval, start]);
|
|
295
|
+
|
|
296
|
+
const change = (update: Partial<Query<F>>, force = false, prefix: T[] = []) =>
|
|
297
|
+
setRequest((before) => ({
|
|
298
|
+
...before,
|
|
299
|
+
filtersKey,
|
|
300
|
+
force,
|
|
301
|
+
prefix,
|
|
302
|
+
revision: before.revision + 1,
|
|
303
|
+
query: {
|
|
304
|
+
...(before.filtersKey === filtersKey ? before.query : { ...before.query, page: 1, filters: options.filters }),
|
|
305
|
+
cursor: null,
|
|
306
|
+
...update,
|
|
307
|
+
},
|
|
308
|
+
}));
|
|
309
|
+
const onQueryChange = (query: DataTableQuery) =>
|
|
310
|
+
change({
|
|
311
|
+
page:
|
|
312
|
+
query.cause === 'sort' ||
|
|
313
|
+
(query.cause === 'view' &&
|
|
314
|
+
(JSON.stringify(query.sort) !== JSON.stringify(params.sort) ||
|
|
315
|
+
JSON.stringify(query.filters) !== JSON.stringify(params.filters)))
|
|
316
|
+
? 1
|
|
317
|
+
: query.page,
|
|
318
|
+
pageSize: query.pageSize,
|
|
319
|
+
sort: query.sort,
|
|
320
|
+
...(query.cause === 'view' ? { filters: query.filters as F } : {}),
|
|
321
|
+
});
|
|
322
|
+
const refetch = () => change(params.cursor === null ? {} : { page: 1 }, true);
|
|
323
|
+
const retry = () => change(params, true, prefix);
|
|
324
|
+
const invalidate = () => {
|
|
325
|
+
cache.current.clear();
|
|
326
|
+
refetch();
|
|
327
|
+
};
|
|
328
|
+
const loadMore = () => {
|
|
329
|
+
if (active.current || data.current.error != null || !snapshot.nextCursor || !enabled) return;
|
|
330
|
+
if (key !== confirmedKey.current) {
|
|
331
|
+
// Upstream cancellation is silent, so the ordinary Load more control must retry it.
|
|
332
|
+
if (key === abortedAppendKey.current) retry();
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
change({ page: params.page + 1, cursor: snapshot.nextCursor }, false, snapshot.rows);
|
|
336
|
+
};
|
|
337
|
+
const hasMore = Boolean(snapshot.nextCursor);
|
|
338
|
+
const { footerLoading, ...state } = snapshot;
|
|
339
|
+
return {
|
|
340
|
+
...state,
|
|
341
|
+
params,
|
|
342
|
+
hasMore,
|
|
343
|
+
loadMore,
|
|
344
|
+
refetch,
|
|
345
|
+
invalidate,
|
|
346
|
+
tableProps: {
|
|
347
|
+
rows: snapshot.rows,
|
|
348
|
+
paginationMode: 'server',
|
|
349
|
+
rowCount: snapshot.rowCount,
|
|
350
|
+
page: snapshot.page,
|
|
351
|
+
pageSize: snapshot.pageSize,
|
|
352
|
+
sort: snapshot.sort,
|
|
353
|
+
manualSorting: true,
|
|
354
|
+
loading: snapshot.isLoading,
|
|
355
|
+
filters: params.filters,
|
|
356
|
+
onPageChange: (page) => change({ page }),
|
|
357
|
+
onPageSizeChange: (pageSize) => change({ page: 1, pageSize }),
|
|
358
|
+
onSortChange: (sort) => change({ page: 1, sort }),
|
|
359
|
+
onQueryChange,
|
|
360
|
+
},
|
|
361
|
+
loadMoreProps: {
|
|
362
|
+
onLoadMore: loadMore,
|
|
363
|
+
onRetry: retry,
|
|
364
|
+
error:
|
|
365
|
+
snapshot.error == null
|
|
366
|
+
? ''
|
|
367
|
+
: snapshot.error instanceof Error && snapshot.error.message
|
|
368
|
+
? snapshot.error.message
|
|
369
|
+
: 'Unable to load rows.',
|
|
370
|
+
nextCursor: snapshot.nextCursor,
|
|
371
|
+
hasMore,
|
|
372
|
+
loading: footerLoading,
|
|
373
|
+
loadedCount: snapshot.rows.length,
|
|
374
|
+
lastAppend: snapshot.lastAppend,
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -62,7 +62,7 @@ export interface ComparisonTableProps {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const number = new Intl.NumberFormat('en-US');
|
|
65
|
-
const STICKY = 'sticky start-0 z-
|
|
65
|
+
const STICKY = 'sticky start-0 z-sticky bg-card';
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Feature comparison of plans or options: columns are plans, rows are features grouped by section.
|
|
@@ -128,7 +128,7 @@ export function ComparisonTable({
|
|
|
128
128
|
{(hasTitle || eyebrow || description) && (
|
|
129
129
|
<div className="mx-auto mb-10 max-w-2xl text-center">
|
|
130
130
|
{eyebrow && (
|
|
131
|
-
<p className="font-mono text-[12px] font-semibold tracking-wide text-primary-text
|
|
131
|
+
<p className="font-mono text-[12px] font-semibold tracking-wide text-primary-text label-case">{eyebrow}</p>
|
|
132
132
|
)}
|
|
133
133
|
{hasTitle && (
|
|
134
134
|
<Heading
|
|
@@ -40,7 +40,7 @@ export function FeatureGrid({
|
|
|
40
40
|
{(eyebrow || title || description) && (
|
|
41
41
|
<div className="mx-auto max-w-2xl text-center">
|
|
42
42
|
{eyebrow && (
|
|
43
|
-
<p className="font-mono text-[12px] font-semibold tracking-wide text-primary-text
|
|
43
|
+
<p className="font-mono text-[12px] font-semibold tracking-wide text-primary-text label-case">{eyebrow}</p>
|
|
44
44
|
)}
|
|
45
45
|
{title && (
|
|
46
46
|
<Heading
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentDoc } from '@gntik-ai/ui';
|
|
2
|
+
import { meta } from './block.meta';
|
|
3
|
+
|
|
4
|
+
export const doc: ComponentDoc = {
|
|
5
|
+
name: 'LogoCloud',
|
|
6
|
+
group: 'Display',
|
|
7
|
+
status: 'beta',
|
|
8
|
+
description: meta.description,
|
|
9
|
+
primitive: 'Semantic list with named images and decorative SVG marks',
|
|
10
|
+
pattern: 'Static social proof',
|
|
11
|
+
keyboard: [],
|
|
12
|
+
tokens: ['muted-foreground', 'foreground'],
|
|
13
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { render, screen, within } from '@testing-library/react';
|
|
2
|
+
import { LogoCloud } from './LogoCloud';
|
|
3
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
6
|
+
import Row from './examples/Row';
|
|
7
|
+
import Grid from './examples/Grid';
|
|
8
|
+
import CaptionStart from './examples/CaptionStart';
|
|
9
|
+
import UnderHero from './examples/UnderHero';
|
|
10
|
+
import Custom from './examples/Custom';
|
|
11
|
+
import Empty from './examples/Empty';
|
|
12
|
+
import { sampleLogos } from './fixtures';
|
|
13
|
+
|
|
14
|
+
const logos = ['Acme', 'Example', 'Sample', 'Demo', 'Placeholder', 'Studio'].map((name) => ({
|
|
15
|
+
id: name,
|
|
16
|
+
name,
|
|
17
|
+
mark: (
|
|
18
|
+
<svg viewBox="0 0 80 28" fill="currentColor">
|
|
19
|
+
<path d="M0 0h80v28H0z" />
|
|
20
|
+
</svg>
|
|
21
|
+
),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
describe('LogoCloud', () => {
|
|
25
|
+
describe.each([
|
|
26
|
+
['row', Row],
|
|
27
|
+
['grid', Grid],
|
|
28
|
+
['caption start', CaptionStart],
|
|
29
|
+
['under Hero', UnderHero],
|
|
30
|
+
['custom', Custom],
|
|
31
|
+
['empty', Empty],
|
|
32
|
+
] as const)('%s example', (_name, Example) => {
|
|
33
|
+
it.each(['dark', 'light', 'high_contrast'])('has no axe violations in %s', async (theme) => {
|
|
34
|
+
document.documentElement.className = theme;
|
|
35
|
+
const { container } = render(<Example />);
|
|
36
|
+
await expectNoAxeViolations(container);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('ships six neutral currentColor fixture marks', () => {
|
|
40
|
+
render(<LogoCloud logos={sampleLogos} />);
|
|
41
|
+
expect(screen.getAllByRole('img').map((image) => image.getAttribute('aria-label'))).toEqual([
|
|
42
|
+
'Acme',
|
|
43
|
+
'Example',
|
|
44
|
+
'Sample',
|
|
45
|
+
'Demo',
|
|
46
|
+
'Placeholder',
|
|
47
|
+
'Studio',
|
|
48
|
+
]);
|
|
49
|
+
for (const image of screen.getAllByRole('img'))
|
|
50
|
+
expect(image.querySelector('svg')).toHaveAttribute('fill', 'currentColor');
|
|
51
|
+
});
|
|
52
|
+
it('localizes both default and custom captions in the Spanish example', () => {
|
|
53
|
+
render(<Custom />);
|
|
54
|
+
expect(
|
|
55
|
+
screen.getByRole('list', { name: 'Equipos de empresas de todos los tamaños confían en nosotros' }),
|
|
56
|
+
).toBeInTheDocument();
|
|
57
|
+
expect(screen.getByRole('list', { name: 'Nuestra comunidad' })).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
it('renders no motion or filter utilities and no inline effects or colours', () => {
|
|
60
|
+
const { container } = render(<LogoCloud logos={logos} />);
|
|
61
|
+
for (const element of container.querySelectorAll<HTMLElement>('*')) {
|
|
62
|
+
expect(element.getAttribute('class') ?? '').not.toMatch(
|
|
63
|
+
/animate-|transition-transform|(?:^|\s)(?:filter|blur|mask|backdrop)-?/,
|
|
64
|
+
);
|
|
65
|
+
expect(element.getAttribute('style') ?? '').not.toMatch(/animation|transition|transform|filter|mask|color/i);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
it('contains no fixed colours, palette utilities, theme variants or visual effects', () => {
|
|
69
|
+
const source = readFileSync('src/marketing/LogoCloud/LogoCloud.tsx', 'utf8');
|
|
70
|
+
expect(source).not.toMatch(/#[\da-f]{3,8}\b|(?:rgb|hsl)a?\(|dark:|gradient|glow|shadow/i);
|
|
71
|
+
expect(source).not.toMatch(
|
|
72
|
+
/(?:bg|text|border|fill|stroke)-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d/,
|
|
73
|
+
);
|
|
74
|
+
expect(source).not.toContain('Trusted by teams at companies of every size');
|
|
75
|
+
});
|
|
76
|
+
it('renders nothing for an empty logo array, leaving no dangling caption or ARIA', () => {
|
|
77
|
+
const { container } = render(<LogoCloud logos={[]} />);
|
|
78
|
+
expect(container).toBeEmptyDOMElement();
|
|
79
|
+
});
|
|
80
|
+
it('sizes every mark to 28px by default and accepts a height with automatic width', () => {
|
|
81
|
+
const { rerender } = render(<LogoCloud logos={logos} />);
|
|
82
|
+
for (const image of screen.getAllByRole('img')) expect(image).toHaveStyle({ height: '28px' });
|
|
83
|
+
rerender(<LogoCloud logos={logos} logoHeight={40} />);
|
|
84
|
+
for (const image of screen.getAllByRole('img')) {
|
|
85
|
+
expect(image).toHaveStyle({ height: '40px' });
|
|
86
|
+
expect(image.querySelector('[aria-hidden]')).toHaveClass(
|
|
87
|
+
'[&_svg]:h-full',
|
|
88
|
+
'[&_svg]:w-auto',
|
|
89
|
+
'[&_svg]:max-w-full',
|
|
90
|
+
);
|
|
91
|
+
expect(image.style.color).toBe('');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
it('inherits the muted token and allows foreground overrides on the root and individual items', () => {
|
|
95
|
+
const { container, rerender } = render(<LogoCloud logos={logos} />);
|
|
96
|
+
expect(container.firstElementChild).toHaveClass('text-muted-foreground');
|
|
97
|
+
rerender(
|
|
98
|
+
<LogoCloud
|
|
99
|
+
logos={[{ ...logos[0]!, className: 'text-foreground' }, ...logos.slice(1)]}
|
|
100
|
+
className="text-foreground"
|
|
101
|
+
/>,
|
|
102
|
+
);
|
|
103
|
+
expect(container.firstElementChild).toHaveClass('text-foreground');
|
|
104
|
+
expect(container.firstElementChild).not.toHaveClass('text-muted-foreground');
|
|
105
|
+
expect(screen.getAllByRole('listitem')[0]).toHaveClass('text-foreground');
|
|
106
|
+
for (const image of screen.getAllByRole('img')) expect(image.className).not.toMatch(/text-/);
|
|
107
|
+
});
|
|
108
|
+
it.each([
|
|
109
|
+
[3, 'md:grid-cols-3'],
|
|
110
|
+
[4, 'md:grid-cols-4'],
|
|
111
|
+
[6, 'md:grid-cols-6'],
|
|
112
|
+
] as const)('uses two phone columns and %s desktop columns', (columns, desktopClass) => {
|
|
113
|
+
render(<LogoCloud logos={logos} layout="grid" columns={columns} />);
|
|
114
|
+
expect(screen.getByRole('list')).toHaveClass('grid', 'grid-cols-2', desktopClass);
|
|
115
|
+
});
|
|
116
|
+
it('defaults to a centred wrapping row; columns only affect grid layout', () => {
|
|
117
|
+
const { rerender } = render(<LogoCloud logos={logos} columns={6} />);
|
|
118
|
+
expect(screen.getByRole('list')).toHaveClass('flex', 'flex-wrap', 'justify-center');
|
|
119
|
+
expect(screen.getByRole('list').className).not.toMatch(/grid-cols/);
|
|
120
|
+
rerender(<LogoCloud logos={logos} layout="grid" />);
|
|
121
|
+
expect(screen.getByRole('list')).toHaveClass('md:grid-cols-4');
|
|
122
|
+
});
|
|
123
|
+
it('keeps the caption above by default and places it beside the list only from md when requested', () => {
|
|
124
|
+
const { container, rerender } = render(<LogoCloud logos={logos} />);
|
|
125
|
+
expect(container.firstElementChild).toHaveClass('flex', 'flex-col');
|
|
126
|
+
expect(container.firstElementChild).not.toHaveClass('md:flex-row');
|
|
127
|
+
rerender(<LogoCloud logos={logos} captionPlacement="start" />);
|
|
128
|
+
expect(container.firstElementChild).toHaveClass('flex-col', 'md:flex-row', 'md:items-center');
|
|
129
|
+
expect(screen.getByRole('list').previousElementSibling?.id).toBe(
|
|
130
|
+
screen.getByRole('list').getAttribute('aria-labelledby'),
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
it.each([
|
|
134
|
+
['en', 'Trusted by teams at companies of every size'],
|
|
135
|
+
['es', 'Equipos de empresas de todos los tamaños confían en nosotros'],
|
|
136
|
+
])('names the list with the %s catalog caption by default', (locale, caption) => {
|
|
137
|
+
render(
|
|
138
|
+
<I18nProvider locale={locale}>
|
|
139
|
+
<LogoCloud logos={logos} />
|
|
140
|
+
</I18nProvider>,
|
|
141
|
+
);
|
|
142
|
+
expect(screen.getByRole('list', { name: caption })).toBeInTheDocument();
|
|
143
|
+
});
|
|
144
|
+
it('labels one six-item list with the caption and gives each decorative mark a named image', () => {
|
|
145
|
+
render(<LogoCloud logos={logos} caption={<span>Our community</span>} />);
|
|
146
|
+
const list = screen.getByRole('list', { name: 'Our community' });
|
|
147
|
+
expect(screen.getAllByRole('list')).toHaveLength(1);
|
|
148
|
+
const items = within(list).getAllByRole('listitem');
|
|
149
|
+
expect(items).toHaveLength(6);
|
|
150
|
+
for (const [index, item] of items.entries()) {
|
|
151
|
+
const image = within(item).getByRole('img', { name: logos[index]!.name });
|
|
152
|
+
expect(image.querySelector('[aria-hidden="true"]')).toContainElement(image.querySelector('svg'));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useId, type ReactNode } from 'react';
|
|
2
|
+
import { cn, useI18n } from '@gntik-ai/ui';
|
|
3
|
+
|
|
4
|
+
export interface LogoCloudItem {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
/** Supply a single-colour SVG painted with currentColor. */
|
|
8
|
+
mark: ReactNode;
|
|
9
|
+
/** Optional token colour override for this mark. Otherwise inherits the root colour. */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LogoCloudProps {
|
|
14
|
+
/** Customer marks. Empty arrays render nothing. */
|
|
15
|
+
logos: LogoCloudItem[];
|
|
16
|
+
/** Accessible list name; defaults to the active locale's catalog caption. */
|
|
17
|
+
caption?: ReactNode;
|
|
18
|
+
/** Above at every width, or beside the logos from md. */
|
|
19
|
+
captionPlacement?: 'above' | 'start';
|
|
20
|
+
/** A centred wrapping row (default) or a responsive grid. */
|
|
21
|
+
layout?: 'row' | 'grid';
|
|
22
|
+
/** Desktop column count in grid layout; phones always use two columns. */
|
|
23
|
+
columns?: 3 | 4 | 6;
|
|
24
|
+
/** Mark height in pixels. Width remains automatic and constrained to the available space. */
|
|
25
|
+
logoHeight?: number;
|
|
26
|
+
/** Root utilities; text-foreground overrides the default muted mark colour. */
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const gridColumns = { 3: 'md:grid-cols-3', 4: 'md:grid-cols-4', 6: 'md:grid-cols-6' };
|
|
31
|
+
|
|
32
|
+
/** Static social proof. Marks inherit the root token colour unless an item overrides it. */
|
|
33
|
+
export function LogoCloud({
|
|
34
|
+
logos,
|
|
35
|
+
caption,
|
|
36
|
+
captionPlacement = 'above',
|
|
37
|
+
layout = 'row',
|
|
38
|
+
columns = 4,
|
|
39
|
+
logoHeight = 28,
|
|
40
|
+
className,
|
|
41
|
+
}: LogoCloudProps) {
|
|
42
|
+
const captionId = useId();
|
|
43
|
+
const { t } = useI18n();
|
|
44
|
+
if (logos.length === 0) return null;
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
className={cn(
|
|
48
|
+
'flex min-w-0 flex-col items-center gap-6 px-4 py-10 text-muted-foreground sm:px-6',
|
|
49
|
+
captionPlacement === 'start' && 'md:flex-row md:items-center',
|
|
50
|
+
className,
|
|
51
|
+
)}
|
|
52
|
+
>
|
|
53
|
+
<div
|
|
54
|
+
id={captionId}
|
|
55
|
+
className={cn(
|
|
56
|
+
'min-w-0 text-center text-sm wrap-anywhere',
|
|
57
|
+
captionPlacement === 'start' && 'md:max-w-64 md:shrink-0 md:text-start',
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
{caption ?? t('logoCloud.caption')}
|
|
61
|
+
</div>
|
|
62
|
+
<ul
|
|
63
|
+
aria-labelledby={captionId}
|
|
64
|
+
className={cn(
|
|
65
|
+
'm-0 w-full min-w-0 list-none items-center gap-x-8 gap-y-6 p-0',
|
|
66
|
+
layout === 'grid' ? cn('grid grid-cols-2', gridColumns[columns]) : 'flex flex-wrap justify-center',
|
|
67
|
+
)}
|
|
68
|
+
>
|
|
69
|
+
{logos.map((logo) => (
|
|
70
|
+
<li key={logo.id} className={cn('flex min-w-0 max-w-full justify-center', logo.className)}>
|
|
71
|
+
<div
|
|
72
|
+
role="img"
|
|
73
|
+
aria-label={logo.name}
|
|
74
|
+
className="flex min-w-0 max-w-full justify-center"
|
|
75
|
+
style={{ height: logoHeight }}
|
|
76
|
+
>
|
|
77
|
+
<span
|
|
78
|
+
aria-hidden="true"
|
|
79
|
+
className="inline-flex h-full min-w-0 max-w-full [&_svg]:h-full [&_svg]:w-auto [&_svg]:max-w-full"
|
|
80
|
+
>
|
|
81
|
+
{logo.mark}
|
|
82
|
+
</span>
|
|
83
|
+
</div>
|
|
84
|
+
</li>
|
|
85
|
+
))}
|
|
86
|
+
</ul>
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BlockMeta } from '../../meta';
|
|
2
|
+
|
|
3
|
+
export const meta: BlockMeta = {
|
|
4
|
+
name: 'Logo cloud',
|
|
5
|
+
family: 'marketing',
|
|
6
|
+
status: 'beta',
|
|
7
|
+
description:
|
|
8
|
+
'Static customer marks in a centred wrapping row or responsive grid with a localized caption above or beside the logos. Apps supply single-colour currentColor SVGs. Marks inherit muted-foreground; use the high_contrast theme or text-foreground on the root or an item for thin marks. Empty logo arrays render nothing. No animation, filters or masks.',
|
|
9
|
+
uses: [],
|
|
10
|
+
};
|