@gntik-ai/blocks 0.11.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 +1501 -1232
- package/dist/index.js +1884 -836
- 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.test.tsx +6 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +4 -1
- package/src/auth/ForgotPasswordForm/block.meta.ts +1 -1
- package/src/auth/ForgotPasswordForm/examples/LargeFields.tsx +6 -0
- package/src/auth/MfaChallenge/MfaChallenge.test.tsx +9 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +5 -2
- package/src/auth/MfaChallenge/block.meta.ts +1 -1
- package/src/auth/MfaChallenge/examples/LargeFields.tsx +6 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.test.tsx +7 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +5 -3
- package/src/auth/ResetPasswordForm/block.meta.ts +1 -1
- package/src/auth/ResetPasswordForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SignInForm/SignInForm.test.tsx +7 -0
- package/src/auth/SignInForm/SignInForm.tsx +5 -1
- package/src/auth/SignInForm/block.meta.ts +1 -1
- package/src/auth/SignInForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SignUpForm/SignUpForm.test.tsx +22 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +7 -1
- package/src/auth/SignUpForm/block.meta.ts +1 -1
- package/src/auth/SignUpForm/examples/LargeFields.tsx +6 -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.tsx +7 -2
- 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.test.tsx +24 -0
- package/src/builders/LogViewer/LogViewer.tsx +67 -20
- package/src/builders/LogViewer/block.meta.ts +2 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +2 -1
- 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.test.tsx +24 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +14 -20
- package/src/data-display/DescriptionListCard/block.meta.ts +2 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +2 -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 +5 -3
- package/src/feedback/EmptyStates/block.meta.ts +1 -1
- package/src/feedback/EmptyStates/examples/HiddenAction.tsx +13 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +13 -15
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.lifecycle.test.tsx +123 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +128 -139
- package/src/forms/CreateApiKeyDialog/block.meta.ts +12 -1
- 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.lifecycle.test.tsx +165 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +267 -69
- package/src/forms/FileUploadPanel/block.meta.ts +5 -1
- package/src/forms/FileUploadPanel/examples/AutoCancel.tsx +38 -0
- package/src/forms/FileUploadPanel/examples/Labels.tsx +1 -1
- 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.test.tsx +11 -0
- package/src/forms/FormSection/FormSection.tsx +20 -22
- package/src/forms/FormSection/block.meta.ts +1 -1
- package/src/forms/FormSection/examples/ContainerPanel.tsx +16 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.lifecycle.test.tsx +80 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +90 -109
- package/src/forms/InviteMembersDialog/block.meta.ts +1 -1
- package/src/forms/ValidationSummary/ValidationSummary.tsx +1 -4
- 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.tsx +4 -4
- 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/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.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.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 +328 -14
- package/src/tables/DataTable/DataTable.test.tsx +85 -1
- package/src/tables/DataTable/DataTable.tsx +108 -14
- package/src/tables/DataTable/block.meta.ts +11 -1
- package/src/tables/DataTable/column-sizing.ts +2 -2
- package/src/tables/DataTable/data-table-props.ts +29 -1
- package/src/tables/DataTable/data-table-row.tsx +2 -2
- package/src/tables/DataTable/data-table-utils.ts +4 -0
- package/src/tables/DataTable/editable-cell.tsx +20 -79
- 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/server-pagination.tsx +47 -40
- package/src/tables/DataTable/export-menu.tsx +58 -0
- package/src/tables/DataTable/header-cell.tsx +1 -1
- package/src/tables/DataTable/labels.ts +7 -0
- package/src/tables/DataTable/resize-handle.tsx +2 -2
- 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 +10 -1
- 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 +5 -5
- package/src/test/without-forced-colors.test.ts +44 -0
- package/src/test/without-forced-colors.ts +14 -0
|
@@ -22,7 +22,7 @@ export default function Labels() {
|
|
|
22
22
|
</Button>
|
|
23
23
|
</div>
|
|
24
24
|
<I18nProvider locale={spanish ? 'es' : 'en'}>
|
|
25
|
-
<FileUploadPanel labels={custom ? labels : undefined} />
|
|
25
|
+
<FileUploadPanel accept=".csv,text/csv" labels={custom ? labels : undefined} />
|
|
26
26
|
</I18nProvider>
|
|
27
27
|
</div>
|
|
28
28
|
);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useState, type FormEvent } from 'react';
|
|
2
|
+
import { Button, Input } from '@gntik-ai/ui';
|
|
3
|
+
import { FileUploadPanel, type UploadItem } from '../FileUploadPanel';
|
|
4
|
+
|
|
5
|
+
/** The form owns the picked File objects and submits them with its other fields. */
|
|
6
|
+
export default function ManualForm() {
|
|
7
|
+
const [files, setFiles] = useState<UploadItem[]>([]);
|
|
8
|
+
const [submitted, setSubmitted] = useState('');
|
|
9
|
+
const submit = (event: FormEvent<HTMLFormElement>) => {
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
const data = new FormData(event.currentTarget);
|
|
12
|
+
for (const item of files) if (item.status === 'pending' && item.file) data.append('files', item.file);
|
|
13
|
+
// Send data with fetch('/api/collections', { method: 'POST', body: data }).
|
|
14
|
+
setSubmitted(
|
|
15
|
+
`${data.get('title')}: ${files
|
|
16
|
+
.filter((item) => item.status === 'pending')
|
|
17
|
+
.map((item) => item.file?.name)
|
|
18
|
+
.join(', ')}`,
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
return (
|
|
22
|
+
<form aria-label="Create collection" onSubmit={submit} className="grid gap-4">
|
|
23
|
+
<label className="grid gap-2 text-sm text-foreground">
|
|
24
|
+
Collection title
|
|
25
|
+
<Input name="title" defaultValue="Documents" required />
|
|
26
|
+
</label>
|
|
27
|
+
<FileUploadPanel files={files} onFilesChange={setFiles} uploadMode="manual" />
|
|
28
|
+
<Button type="submit" disabled={!files.some((item) => item.status === 'pending')}>
|
|
29
|
+
Create collection
|
|
30
|
+
</Button>
|
|
31
|
+
<p role="status" className="text-sm text-muted-foreground">
|
|
32
|
+
{submitted}
|
|
33
|
+
</p>
|
|
34
|
+
</form>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { matchesAccept } from '@gntik-ai/ui';
|
|
2
|
+
|
|
3
|
+
export type UploadStatus = 'pending' | 'uploading' | 'done' | 'error';
|
|
2
4
|
|
|
3
5
|
export interface UploadItem {
|
|
4
6
|
id: string;
|
|
7
|
+
/** Picked source file, absent for previously uploaded items. */
|
|
8
|
+
file?: File;
|
|
5
9
|
name: string;
|
|
6
10
|
/** Size in bytes. */
|
|
7
11
|
size: number;
|
|
@@ -26,29 +30,40 @@ export const uploadItems: UploadItem[] = [
|
|
|
26
30
|
];
|
|
27
31
|
|
|
28
32
|
/** Demo uploader: reports progress in steps and resolves after ~1.5 s. */
|
|
29
|
-
export function simulateUpload(
|
|
30
|
-
|
|
33
|
+
export function simulateUpload(
|
|
34
|
+
_file: File,
|
|
35
|
+
onProgress: (pct: number) => void,
|
|
36
|
+
context?: { signal: AbortSignal; id: string },
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const signal = context?.signal;
|
|
40
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
41
|
+
const abort = () => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
signal?.removeEventListener('abort', abort);
|
|
44
|
+
reject(new DOMException('Aborted', 'AbortError'));
|
|
45
|
+
};
|
|
46
|
+
if (signal?.aborted) {
|
|
47
|
+
abort();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
31
51
|
let pct = 0;
|
|
32
52
|
const step = () => {
|
|
53
|
+
if (signal?.aborted) return;
|
|
33
54
|
pct = Math.min(100, pct + 20);
|
|
34
55
|
onProgress(pct);
|
|
35
|
-
if (
|
|
36
|
-
|
|
56
|
+
if (signal?.aborted) return;
|
|
57
|
+
if (pct >= 100) {
|
|
58
|
+
signal?.removeEventListener('abort', abort);
|
|
59
|
+
resolve();
|
|
60
|
+
} else timer = setTimeout(step, 250);
|
|
37
61
|
};
|
|
38
|
-
setTimeout(step, 250);
|
|
62
|
+
timer = setTimeout(step, 250);
|
|
39
63
|
});
|
|
40
64
|
}
|
|
41
65
|
|
|
42
66
|
/** Matches a file against an `accept` list (".csv", "image/*", "application/pdf"). */
|
|
43
67
|
export function acceptsFile(file: { name: string; type: string }, accept: string | undefined) {
|
|
44
|
-
|
|
45
|
-
const name = file.name.toLowerCase();
|
|
46
|
-
const type = file.type.toLowerCase();
|
|
47
|
-
return accept
|
|
48
|
-
.split(',')
|
|
49
|
-
.map((a) => a.trim().toLowerCase())
|
|
50
|
-
.filter(Boolean)
|
|
51
|
-
.some((a) =>
|
|
52
|
-
a.startsWith('.') ? name.endsWith(a) : a.endsWith('/*') ? type.startsWith(a.slice(0, -1)) : type === a,
|
|
53
|
-
);
|
|
68
|
+
return matchesAccept(file, accept);
|
|
54
69
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { simulateUpload } from './fixtures';
|
|
2
|
+
|
|
3
|
+
it('stops the demo timer and rejects on abort, including an already aborted signal', async () => {
|
|
4
|
+
vi.useFakeTimers();
|
|
5
|
+
try {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const progress = vi.fn();
|
|
8
|
+
const pending = simulateUpload(new File(['x'], 'report.csv'), progress, { signal: controller.signal, id: 'demo' });
|
|
9
|
+
const rejected = expect(pending).rejects.toMatchObject({ name: 'AbortError' });
|
|
10
|
+
await vi.advanceTimersByTimeAsync(250);
|
|
11
|
+
expect(progress).toHaveBeenLastCalledWith(20);
|
|
12
|
+
controller.abort();
|
|
13
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
14
|
+
await rejected;
|
|
15
|
+
await vi.advanceTimersByTimeAsync(2000);
|
|
16
|
+
expect(progress).toHaveBeenCalledTimes(1);
|
|
17
|
+
await expect(
|
|
18
|
+
simulateUpload(new File([], 'empty.csv'), progress, { signal: controller.signal, id: 'aborted' }),
|
|
19
|
+
).rejects.toMatchObject({ name: 'AbortError' });
|
|
20
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
21
|
+
} finally {
|
|
22
|
+
vi.useRealTimers();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -5,6 +5,17 @@ import { expectNoAxeViolations } from '../../test/a11y';
|
|
|
5
5
|
import { FormSection } from './FormSection';
|
|
6
6
|
|
|
7
7
|
describe('FormSection', () => {
|
|
8
|
+
it('keeps section styling, landmark props and the divider outside its layout grid', () => {
|
|
9
|
+
render(<FormSection className="mt-8" divided data-testid="settings" />);
|
|
10
|
+
const section = screen.getByRole('region', { name: 'General' });
|
|
11
|
+
expect(section.tagName).toBe('SECTION');
|
|
12
|
+
expect(section).toHaveAttribute('data-testid', 'settings');
|
|
13
|
+
expect(section).toHaveClass('mt-8', 'border-t');
|
|
14
|
+
expect(section).not.toHaveClass('grid');
|
|
15
|
+
expect(section.firstElementChild).toHaveClass('grid');
|
|
16
|
+
expect(section.firstElementChild).not.toHaveClass('mt-8', 'border-t');
|
|
17
|
+
});
|
|
18
|
+
|
|
8
19
|
it('renders the default section as a named region', async () => {
|
|
9
20
|
const { container } = render(<FormSection />);
|
|
10
21
|
expect(screen.getByRole('region', { name: 'General' })).toBeInTheDocument();
|
|
@@ -25,13 +25,13 @@ export interface FormSectionProps extends Omit<HTMLAttributes<HTMLElement>, 'tit
|
|
|
25
25
|
|
|
26
26
|
function SampleFields() {
|
|
27
27
|
return (
|
|
28
|
-
<div className="grid grid-cols-1 gap-4
|
|
29
|
-
<Field className="
|
|
28
|
+
<div className="grid grid-cols-1 gap-4 @2xl:grid-cols-6">
|
|
29
|
+
<Field className="@2xl:col-span-4">
|
|
30
30
|
<FieldLabel>Project name</FieldLabel>
|
|
31
31
|
<Input defaultValue="billing-dashboard" />
|
|
32
32
|
<FieldDescription>Lowercase letters, numbers and dashes.</FieldDescription>
|
|
33
33
|
</Field>
|
|
34
|
-
<Field className="
|
|
34
|
+
<Field className="@2xl:col-span-6">
|
|
35
35
|
<FieldLabel>Description</FieldLabel>
|
|
36
36
|
<Textarea rows={3} defaultValue="Usage and invoice reporting for every workspace." />
|
|
37
37
|
</Field>
|
|
@@ -41,7 +41,7 @@ function SampleFields() {
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Two-column form section: title and help on the left, fields on the right. Stacks into a
|
|
44
|
-
* single column
|
|
44
|
+
* single column in narrow containers.
|
|
45
45
|
*/
|
|
46
46
|
export function FormSection({
|
|
47
47
|
labels,
|
|
@@ -62,26 +62,24 @@ export function FormSection({
|
|
|
62
62
|
return (
|
|
63
63
|
<section
|
|
64
64
|
aria-labelledby={title != null ? `${id}-title` : undefined}
|
|
65
|
-
className={cn(
|
|
66
|
-
'grid grid-cols-1 gap-x-10 gap-y-5 md:grid-cols-3',
|
|
67
|
-
divided && 'border-t border-border pt-8',
|
|
68
|
-
className,
|
|
69
|
-
)}
|
|
65
|
+
className={cn('@container w-full min-w-0', divided && 'border-t border-border pt-8', className)}
|
|
70
66
|
{...props}
|
|
71
67
|
>
|
|
72
|
-
<div className="
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{title}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
<div className="grid grid-cols-1 gap-x-10 gap-y-5 @2xl:grid-cols-3">
|
|
69
|
+
<div className="min-w-0">
|
|
70
|
+
{title != null && (
|
|
71
|
+
<Heading id={`${id}-title`} className="text-[14px] font-semibold tracking-tight text-foreground">
|
|
72
|
+
{title}
|
|
73
|
+
</Heading>
|
|
74
|
+
)}
|
|
75
|
+
{description != null && (
|
|
76
|
+
<p className="mt-1 text-[13px] leading-6 text-pretty text-muted-foreground">{description}</p>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
<div className="min-w-0 @2xl:col-span-2">
|
|
80
|
+
{children ?? <SampleFields />}
|
|
81
|
+
{actions != null && <div className="mt-6 flex flex-wrap items-center justify-end gap-2.5">{actions}</div>}
|
|
82
|
+
</div>
|
|
85
83
|
</div>
|
|
86
84
|
</section>
|
|
87
85
|
);
|
|
@@ -6,7 +6,7 @@ export const meta: BlockMeta = {
|
|
|
6
6
|
family: 'forms',
|
|
7
7
|
status: 'stable',
|
|
8
8
|
description:
|
|
9
|
-
'Two-column settings section: title and help on the left, fields on the right; stacks
|
|
9
|
+
'Two-column settings section: title and help on the left, fields on the right; stacks in narrow containers. Optional labels?: Partial<FormSectionLabels> overrides built-in copy; explicit props and validation messages win, then labels, then I18nProvider (en/es). No provider preserves English; fixtures and caller content stay unchanged. Interactive preview: /preview.html?kind=block&id=form-section--labels.',
|
|
10
10
|
labels: [
|
|
11
11
|
{ key: 'title', type: 'string', state: 'Default content and accessible names' },
|
|
12
12
|
{ key: 'description', type: 'string', state: 'Default content and accessible names' },
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InspectorLayout } from '@gntik-ai/ui';
|
|
2
|
+
import { FormSection } from '../FormSection';
|
|
3
|
+
|
|
4
|
+
export default function ContainerPanel() {
|
|
5
|
+
return (
|
|
6
|
+
<div data-container-example className="h-[640px] overflow-hidden rounded-lg border border-border">
|
|
7
|
+
<InspectorLayout panelTitle="Properties" dockedQuery="(min-width: 0px)" panel={<FormSection />}>
|
|
8
|
+
<div className="grid gap-6 overflow-auto p-4">
|
|
9
|
+
<div data-container-slot="default" className="flex min-w-0">
|
|
10
|
+
<FormSection />
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</InspectorLayout>
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { InviteMembersDialog } from './InviteMembersDialog';
|
|
5
|
+
|
|
6
|
+
describe('InviteMembersDialog lifecycle', () => {
|
|
7
|
+
it('ignores Escape and a second submit while invitations are being sent', async () => {
|
|
8
|
+
const user = userEvent.setup();
|
|
9
|
+
let release!: () => void;
|
|
10
|
+
const onInvite = vi.fn(() => new Promise<void>((resolve) => (release = resolve)));
|
|
11
|
+
const onOpenChange = vi.fn();
|
|
12
|
+
render(<InviteMembersDialog defaultOpen onInvite={onInvite} onOpenChange={onOpenChange} />);
|
|
13
|
+
await user.type(await screen.findByLabelText(/Email addresses/), 'avery@example.com,');
|
|
14
|
+
await user.click(screen.getByRole('button', { name: 'Send invitation' }));
|
|
15
|
+
expect(screen.getByRole('button', { name: 'Send invitation' })).toHaveAttribute('aria-busy', 'true');
|
|
16
|
+
expect(screen.getByRole('button', { name: 'Cancel' })).toBeDisabled();
|
|
17
|
+
await user.keyboard('{Escape}');
|
|
18
|
+
fireEvent.submit(screen.getByRole('dialog').querySelector('form')!);
|
|
19
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
20
|
+
expect(onInvite).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(onOpenChange).not.toHaveBeenCalled();
|
|
22
|
+
await act(async () => release());
|
|
23
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
24
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('shows a rejection in a titled alert at the top and clears it on the next submit', async () => {
|
|
28
|
+
const user = userEvent.setup();
|
|
29
|
+
const onInvite = vi.fn().mockRejectedValueOnce(new Error('Seat limit reached')).mockResolvedValue(undefined);
|
|
30
|
+
render(<InviteMembersDialog defaultOpen onInvite={onInvite} />);
|
|
31
|
+
await user.type(await screen.findByLabelText(/Email addresses/), 'avery@example.com,');
|
|
32
|
+
await user.click(screen.getByRole('button', { name: 'Send invitation' }));
|
|
33
|
+
const alert = await screen.findByRole('alert');
|
|
34
|
+
expect(alert).toHaveTextContent('Seat limit reached');
|
|
35
|
+
expect(alert.parentElement?.firstElementChild).toBe(alert);
|
|
36
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
37
|
+
await user.click(screen.getByRole('button', { name: 'Send invitation' }));
|
|
38
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('resets the fields after a parent-driven close', async () => {
|
|
42
|
+
const user = userEvent.setup();
|
|
43
|
+
const api: { setOpen: (open: boolean) => void } = { setOpen: () => undefined };
|
|
44
|
+
function Parent() {
|
|
45
|
+
const [open, setOpen] = useState(true);
|
|
46
|
+
api.setOpen = setOpen;
|
|
47
|
+
return <InviteMembersDialog open={open} onOpenChange={setOpen} trigger={null} />;
|
|
48
|
+
}
|
|
49
|
+
render(<Parent />);
|
|
50
|
+
await user.type(await screen.findByLabelText(/Email addresses/), 'avery@example.com,');
|
|
51
|
+
expect(screen.getByRole('list', { name: 'Invited addresses' })).toHaveTextContent('avery@example.com');
|
|
52
|
+
act(() => api.setOpen(false));
|
|
53
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
54
|
+
act(() => api.setOpen(true));
|
|
55
|
+
await screen.findByLabelText(/Email addresses/);
|
|
56
|
+
expect(screen.queryByText('avery@example.com')).not.toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('drops a rejection that arrives after a parent-driven close', async () => {
|
|
60
|
+
const user = userEvent.setup();
|
|
61
|
+
let fail!: (reason: Error) => void;
|
|
62
|
+
const onInvite = vi.fn(() => new Promise<void>((_resolve, reject) => (fail = reject)));
|
|
63
|
+
const api: { setOpen: (open: boolean) => void } = { setOpen: () => undefined };
|
|
64
|
+
function Parent() {
|
|
65
|
+
const [open, setOpen] = useState(true);
|
|
66
|
+
api.setOpen = setOpen;
|
|
67
|
+
return <InviteMembersDialog open={open} onOpenChange={setOpen} onInvite={onInvite} trigger={null} />;
|
|
68
|
+
}
|
|
69
|
+
render(<Parent />);
|
|
70
|
+
await user.type(await screen.findByLabelText(/Email addresses/), 'avery@example.com,');
|
|
71
|
+
await user.click(screen.getByRole('button', { name: 'Send invitation' }));
|
|
72
|
+
act(() => api.setOpen(false));
|
|
73
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
74
|
+
await act(async () => fail(new Error('Stale seat limit')));
|
|
75
|
+
act(() => api.setOpen(true));
|
|
76
|
+
await screen.findByLabelText(/Email addresses/);
|
|
77
|
+
expect(screen.queryByText('Stale seat limit')).not.toBeInTheDocument();
|
|
78
|
+
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -2,19 +2,11 @@ import {
|
|
|
2
2
|
useI18n,
|
|
3
3
|
Alert,
|
|
4
4
|
Button,
|
|
5
|
-
Dialog,
|
|
6
|
-
DialogBody,
|
|
7
|
-
DialogClose,
|
|
8
|
-
DialogContent,
|
|
9
|
-
DialogDescription,
|
|
10
|
-
DialogFooter,
|
|
11
|
-
DialogHeader,
|
|
12
|
-
DialogTitle,
|
|
13
|
-
DialogTrigger,
|
|
14
5
|
Field,
|
|
15
6
|
FieldDescription,
|
|
16
7
|
FieldError,
|
|
17
8
|
FieldLabel,
|
|
9
|
+
FormDialog,
|
|
18
10
|
Select,
|
|
19
11
|
SelectContent,
|
|
20
12
|
SelectItem,
|
|
@@ -23,7 +15,7 @@ import {
|
|
|
23
15
|
TokenInput,
|
|
24
16
|
} from '@gntik-ai/ui';
|
|
25
17
|
import { UserPlus } from '@gntik-ai/icons';
|
|
26
|
-
import { useState, type ReactElement } from 'react';
|
|
18
|
+
import { useEffect, useRef, useState, type ReactElement } from 'react';
|
|
27
19
|
import { EMAIL_RE, memberRoles, type RoleOption } from './fixtures';
|
|
28
20
|
|
|
29
21
|
export type { RoleOption } from './fixtures';
|
|
@@ -77,7 +69,7 @@ export function InviteMembersDialog({
|
|
|
77
69
|
defaultRole = 'member',
|
|
78
70
|
onInvite,
|
|
79
71
|
maxInvites = 20,
|
|
80
|
-
open
|
|
72
|
+
open,
|
|
81
73
|
defaultOpen = false,
|
|
82
74
|
onOpenChange,
|
|
83
75
|
trigger = <Button icon={UserPlus} />,
|
|
@@ -89,14 +81,17 @@ export function InviteMembersDialog({
|
|
|
89
81
|
const description = descriptionProp ?? labels?.description ?? t('inviteMembers.description');
|
|
90
82
|
const emailError = (email: string) =>
|
|
91
83
|
EMAIL_RE.test(email) ? null : (labels?.emailInvalid?.(email) ?? t('inviteMembers.emailInvalid', { email }));
|
|
92
|
-
const [innerOpen, setInnerOpen] = useState(defaultOpen);
|
|
93
84
|
const [emails, setEmails] = useState<string[]>([]);
|
|
94
85
|
const [role, setRole] = useState(defaultRole);
|
|
95
86
|
const [message, setMessage] = useState('');
|
|
96
87
|
const [submitted, setSubmitted] = useState(false);
|
|
97
|
-
const [loading, setLoading] = useState(false);
|
|
98
88
|
const [error, setError] = useState<string | null>(null);
|
|
99
|
-
|
|
89
|
+
|
|
90
|
+
// Bumped whenever an opening ends, so a submit that settles later can't touch a reopened dialog.
|
|
91
|
+
const opening = useRef(0);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
opening.current += 1;
|
|
94
|
+
}, [open]);
|
|
100
95
|
|
|
101
96
|
const invalidCount = emails.filter((e) => emailError(e)).length;
|
|
102
97
|
const emailsProblem =
|
|
@@ -107,112 +102,98 @@ export function InviteMembersDialog({
|
|
|
107
102
|
: null;
|
|
108
103
|
const showEmailError = submitted && emailsProblem != null;
|
|
109
104
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
setError(null);
|
|
118
|
-
}
|
|
119
|
-
setInnerOpen(next);
|
|
120
|
-
onOpenChange?.(next);
|
|
105
|
+
const reset = () => {
|
|
106
|
+
opening.current += 1;
|
|
107
|
+
setEmails([]);
|
|
108
|
+
setRole(defaultRole);
|
|
109
|
+
setMessage('');
|
|
110
|
+
setSubmitted(false);
|
|
111
|
+
setError(null);
|
|
121
112
|
};
|
|
122
113
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
setError(null);
|
|
126
|
-
if (emailsProblem) return;
|
|
127
|
-
setLoading(true);
|
|
114
|
+
const send = async () => {
|
|
115
|
+
const current = opening.current;
|
|
128
116
|
try {
|
|
129
117
|
await onInvite?.({ emails, role, message: message.trim() });
|
|
130
|
-
setLoading(false);
|
|
131
|
-
setOpen(false);
|
|
132
118
|
} catch (e) {
|
|
133
|
-
|
|
134
|
-
|
|
119
|
+
if (current === opening.current) {
|
|
120
|
+
setError(e instanceof Error ? e.message : (labels?.fallbackError ?? t('inviteMembers.fallbackError')));
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
135
123
|
}
|
|
136
124
|
};
|
|
137
125
|
|
|
126
|
+
const submit = () => {
|
|
127
|
+
setSubmitted(true);
|
|
128
|
+
setError(null);
|
|
129
|
+
return emailsProblem ? false : send();
|
|
130
|
+
};
|
|
131
|
+
|
|
138
132
|
const roleLabel = roles.find((r) => r.value === role)?.description;
|
|
139
133
|
|
|
140
134
|
return (
|
|
141
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
135
|
+
<FormDialog
|
|
136
|
+
size="lg"
|
|
137
|
+
title={title}
|
|
138
|
+
description={description}
|
|
139
|
+
trigger={trigger ?? undefined}
|
|
140
|
+
open={open}
|
|
141
|
+
defaultOpen={defaultOpen}
|
|
142
|
+
onOpenChange={onOpenChange}
|
|
143
|
+
onSubmit={submit}
|
|
144
|
+
onClosed={reset}
|
|
145
|
+
cancelLabel={labels?.cancel ?? t('inviteMembers.cancel')}
|
|
146
|
+
submitLabel={
|
|
147
|
+
emails.length > 1
|
|
148
|
+
? (labels?.submitMany?.(emails.length) ?? t('inviteMembers.submitMany', { count: emails.length }))
|
|
149
|
+
: (labels?.submit ?? t('inviteMembers.submit'))
|
|
150
|
+
}
|
|
151
|
+
summary={
|
|
152
|
+
error && (
|
|
153
|
+
<Alert tone="destructive" title={labels?.errorTitle ?? t('inviteMembers.errorTitle')} description={error} />
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
>
|
|
157
|
+
<Field invalid={showEmailError}>
|
|
158
|
+
<FieldLabel required>{labels?.emails ?? t('inviteMembers.emails')}</FieldLabel>
|
|
159
|
+
<TokenInput
|
|
160
|
+
value={emails}
|
|
161
|
+
onValueChange={setEmails}
|
|
162
|
+
validate={emailError}
|
|
163
|
+
maxItems={maxInvites}
|
|
164
|
+
placeholder={labels?.placeholder ?? t('inviteMembers.placeholder')}
|
|
165
|
+
listLabel={labels?.listLabel ?? t('inviteMembers.listLabel')}
|
|
166
|
+
invalid={showEmailError}
|
|
167
|
+
/>
|
|
168
|
+
<FieldError match={showEmailError}>{emailsProblem}</FieldError>
|
|
169
|
+
</Field>
|
|
170
|
+
<Field>
|
|
171
|
+
<FieldLabel>{labels?.role ?? t('inviteMembers.role')}</FieldLabel>
|
|
172
|
+
<Select
|
|
173
|
+
value={role}
|
|
174
|
+
onValueChange={(v) => v != null && setRole(v)}
|
|
175
|
+
items={roles.map(({ value, label }) => ({ value, label }))}
|
|
154
176
|
>
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
<SelectTrigger className="w-full" />
|
|
177
|
-
<SelectContent>
|
|
178
|
-
{roles.map((r) => (
|
|
179
|
-
<SelectItem key={r.value} value={r.value}>
|
|
180
|
-
{r.label}
|
|
181
|
-
</SelectItem>
|
|
182
|
-
))}
|
|
183
|
-
</SelectContent>
|
|
184
|
-
</Select>
|
|
185
|
-
{roleLabel && <FieldDescription>{roleLabel}</FieldDescription>}
|
|
186
|
-
</Field>
|
|
187
|
-
<Field>
|
|
188
|
-
<FieldLabel>{labels?.message ?? t('inviteMembers.message')}</FieldLabel>
|
|
189
|
-
<Textarea
|
|
190
|
-
rows={3}
|
|
191
|
-
value={message}
|
|
192
|
-
onValueChange={setMessage}
|
|
193
|
-
placeholder={labels?.messagePlaceholder ?? t('inviteMembers.messagePlaceholder')}
|
|
194
|
-
/>
|
|
195
|
-
</Field>
|
|
196
|
-
{error && (
|
|
197
|
-
<Alert
|
|
198
|
-
tone="destructive"
|
|
199
|
-
title={labels?.errorTitle ?? t('inviteMembers.errorTitle')}
|
|
200
|
-
description={error}
|
|
201
|
-
/>
|
|
202
|
-
)}
|
|
203
|
-
</DialogBody>
|
|
204
|
-
<DialogFooter>
|
|
205
|
-
<DialogClose render={<Button variant="ghost" disabled={loading} />}>
|
|
206
|
-
{labels?.cancel ?? t('inviteMembers.cancel')}
|
|
207
|
-
</DialogClose>
|
|
208
|
-
<Button type="submit" loading={loading}>
|
|
209
|
-
{emails.length > 1
|
|
210
|
-
? (labels?.submitMany?.(emails.length) ?? t('inviteMembers.submitMany', { count: emails.length }))
|
|
211
|
-
: (labels?.submit ?? t('inviteMembers.submit'))}
|
|
212
|
-
</Button>
|
|
213
|
-
</DialogFooter>
|
|
214
|
-
</form>
|
|
215
|
-
</DialogContent>
|
|
216
|
-
</Dialog>
|
|
177
|
+
<SelectTrigger className="w-full" />
|
|
178
|
+
<SelectContent>
|
|
179
|
+
{roles.map((r) => (
|
|
180
|
+
<SelectItem key={r.value} value={r.value}>
|
|
181
|
+
{r.label}
|
|
182
|
+
</SelectItem>
|
|
183
|
+
))}
|
|
184
|
+
</SelectContent>
|
|
185
|
+
</Select>
|
|
186
|
+
{roleLabel && <FieldDescription>{roleLabel}</FieldDescription>}
|
|
187
|
+
</Field>
|
|
188
|
+
<Field>
|
|
189
|
+
<FieldLabel>{labels?.message ?? t('inviteMembers.message')}</FieldLabel>
|
|
190
|
+
<Textarea
|
|
191
|
+
rows={3}
|
|
192
|
+
value={message}
|
|
193
|
+
onValueChange={setMessage}
|
|
194
|
+
placeholder={labels?.messagePlaceholder ?? t('inviteMembers.messagePlaceholder')}
|
|
195
|
+
/>
|
|
196
|
+
</Field>
|
|
197
|
+
</FormDialog>
|
|
217
198
|
);
|
|
218
199
|
}
|
|
@@ -25,5 +25,5 @@ export const meta: BlockMeta = {
|
|
|
25
25
|
{ key: 'submit', type: 'string', state: 'Default content and accessible names' },
|
|
26
26
|
{ key: 'submitMany', type: '(count: number) => string', state: 'Default content and accessible names' },
|
|
27
27
|
] satisfies Array<{ key: keyof InviteMembersDialogLabels; type: string; state: string }>,
|
|
28
|
-
uses: ['Dialog', 'TokenInput', 'Select', 'Textarea', 'Field', 'Button', 'Alert'],
|
|
28
|
+
uses: ['FormDialog', 'Dialog', 'TokenInput', 'Select', 'Textarea', 'Field', 'Button', 'Alert'],
|
|
29
29
|
};
|
|
@@ -53,10 +53,7 @@ export function ValidationSummary({
|
|
|
53
53
|
role="region"
|
|
54
54
|
tone="destructive"
|
|
55
55
|
title={heading}
|
|
56
|
-
className={cn(
|
|
57
|
-
'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring',
|
|
58
|
-
className,
|
|
59
|
-
)}
|
|
56
|
+
className={cn('focus-ring', className)}
|
|
60
57
|
>
|
|
61
58
|
<ul className="mt-1 list-disc space-y-1 ps-4">
|
|
62
59
|
{errors.map((e) => (
|