@gntik-ai/blocks 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +138 -21
- package/dist/index.js +897 -376
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/billing/CostBreakdown/CostBreakdown.test.tsx +10 -0
- package/src/billing/CostBreakdown/CostBreakdown.tsx +50 -43
- package/src/billing/SpendVsBudget/SpendVsBudget.test.tsx +10 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.tsx +35 -31
- package/src/builders/FlowBuilder/FlowBuilder.test.tsx +237 -2
- package/src/builders/FlowBuilder/FlowBuilder.tsx +101 -29
- package/src/builders/FlowBuilder/block.meta.ts +1 -1
- package/src/builders/FlowBuilder/connections.ts +30 -12
- package/src/builders/FlowBuilder/examples/ControlledGraph.tsx +8 -0
- package/src/builders/FlowBuilder/graph-state.ts +78 -0
- package/src/builders/LogViewer/LogViewer.labels.test.tsx +90 -0
- package/src/builders/LogViewer/LogViewer.test.tsx +11 -0
- package/src/builders/LogViewer/LogViewer.tsx +70 -31
- package/src/builders/LogViewer/block.meta.ts +14 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +30 -0
- package/src/data-display/ChartCard/ChartCard.locale.test.tsx +15 -0
- package/src/data-display/ChartCard/ChartCard.test.tsx +9 -0
- package/src/data-display/ChartCard/ChartCard.tsx +81 -67
- package/src/data-display/ChartCard/block.meta.ts +1 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.labels.test.tsx +73 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +37 -7
- package/src/data-display/DescriptionListCard/block.meta.ts +11 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +22 -0
- package/src/feedback/EmptyStates/EmptyStates.labels.test.tsx +185 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +73 -20
- package/src/feedback/EmptyStates/block.meta.ts +73 -1
- package/src/feedback/EmptyStates/examples/Spanish.tsx +41 -0
- package/src/feedback/ErrorPanel/ErrorPanel.labels.test.tsx +99 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +38 -9
- package/src/feedback/ErrorPanel/block.meta.ts +19 -1
- package/src/feedback/ErrorPanel/examples/Spanish.tsx +30 -0
- package/src/feedback/InlineCallout/InlineCallout.labels.test.tsx +62 -0
- package/src/feedback/InlineCallout/InlineCallout.tsx +22 -9
- package/src/feedback/InlineCallout/block.meta.ts +9 -1
- package/src/feedback/InlineCallout/examples/Spanish.tsx +19 -0
- package/src/feedback/Skeletons/Skeletons.labels.test.tsx +24 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.test.tsx +22 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +4 -4
- package/src/forms/FileUploadPanel/fixtures.ts +0 -12
- package/src/forms/FileUploadPanel/format-bytes.test.ts +8 -0
- package/src/page-chrome/PageHeader/PageHeader.labels.test.tsx +56 -0
- package/src/page-chrome/PageHeader/PageHeader.test.tsx +18 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +21 -4
- package/src/page-chrome/PageHeader/block.meta.ts +8 -1
- package/src/page-chrome/PageHeader/examples/Labels.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
- package/src/scheduling/AgendaList/AgendaList.test.tsx +25 -0
- package/src/scheduling/AgendaList/AgendaList.tsx +7 -2
- package/src/scheduling/AgendaList/AgendaListLocale.test.tsx +11 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/Locale.tsx +29 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.test.tsx +111 -1
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +19 -9
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.test.tsx +73 -2
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +26 -12
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/shared/dates.test.ts +75 -0
- package/src/scheduling/shared/dates.ts +46 -22
- package/src/scheduling/shared/useSchedulingClock.ts +13 -0
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +12 -0
- package/src/shell/GlobalSearch/fixtures.ts +2 -2
- package/src/tables/DataTable/DataTable.labels.test.tsx +2 -0
- package/src/tables/DataTable/DataTable.locale.test.tsx +153 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +1 -1
- package/src/tables/DataTable/DataTable.test.tsx +16 -0
- package/src/tables/DataTable/block.meta.ts +2 -0
- package/src/tables/DataTable/data-table-row.tsx +18 -2
- package/src/tables/DataTable/data-table-utils.ts +18 -4
- package/src/tables/DataTable/labels.ts +2 -0
- package/src/tables/PaginationFooter/PaginationFooter.i18n.test.tsx +26 -0
|
@@ -4,7 +4,23 @@ import { Button, Collapsible, CollapsiblePanel, CollapsibleTrigger, IconButton,
|
|
|
4
4
|
import { useId, useRef, useState, type ReactNode } from 'react';
|
|
5
5
|
import type { FeedbackAction } from '../types';
|
|
6
6
|
|
|
7
|
+
export interface ErrorPanelLabels {
|
|
8
|
+
title: string;
|
|
9
|
+
message: string;
|
|
10
|
+
support: string;
|
|
11
|
+
retry: string;
|
|
12
|
+
retrying: string;
|
|
13
|
+
retryingStatus: string;
|
|
14
|
+
requestId: string;
|
|
15
|
+
copyRequestId: string;
|
|
16
|
+
copied: string;
|
|
17
|
+
requestIdCopied: string;
|
|
18
|
+
details: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
export interface ErrorPanelProps {
|
|
22
|
+
/** Per-key copy overrides; explicit props take precedence, then labels, then the active catalog. */
|
|
23
|
+
labels?: Partial<ErrorPanelLabels>;
|
|
8
24
|
icon?: LucideIcon;
|
|
9
25
|
title?: ReactNode;
|
|
10
26
|
/** Human summary of what failed and what to do. */
|
|
@@ -31,21 +47,28 @@ export interface ErrorPanelProps {
|
|
|
31
47
|
/** Error summary for a failed load or action: what happened, request id, retry and technical details. */
|
|
32
48
|
export function ErrorPanel({
|
|
33
49
|
icon: Icon = ServerCrash,
|
|
34
|
-
title
|
|
35
|
-
|
|
50
|
+
title: titleProp,
|
|
51
|
+
labels,
|
|
52
|
+
message: messageProp,
|
|
36
53
|
code = 503,
|
|
37
54
|
requestId = 'req_8f2c41d07a9b',
|
|
38
55
|
details = 'GET /v1/projects/acme-web/deployments\n503 Service Unavailable\nupstream timed out after 30000 ms (pool: api-eu-west-1)',
|
|
39
56
|
onRetry,
|
|
40
57
|
retrying,
|
|
41
58
|
retryLabel: retryLabelProp,
|
|
42
|
-
secondaryAction
|
|
59
|
+
secondaryAction: secondaryActionProp,
|
|
43
60
|
titleAs: Heading = 'h3',
|
|
44
61
|
className,
|
|
45
62
|
announce = true,
|
|
46
63
|
}: ErrorPanelProps) {
|
|
47
64
|
const { t } = useI18n();
|
|
48
|
-
const
|
|
65
|
+
const title = titleProp === undefined ? (labels?.title ?? t('error.title')) : titleProp;
|
|
66
|
+
const message = messageProp === undefined ? (labels?.message ?? t('error.message')) : messageProp;
|
|
67
|
+
const secondaryAction =
|
|
68
|
+
secondaryActionProp === undefined
|
|
69
|
+
? { label: labels?.support ?? t('error.support'), variant: 'ghost' as const }
|
|
70
|
+
: secondaryActionProp;
|
|
71
|
+
const retryLabel = retryLabelProp ?? labels?.retry ?? t('error.retry');
|
|
49
72
|
const id = useId();
|
|
50
73
|
const [innerRetrying, setInnerRetrying] = useState(false);
|
|
51
74
|
const [copied, setCopied] = useState(false);
|
|
@@ -97,13 +120,15 @@ export function ErrorPanel({
|
|
|
97
120
|
{message != null && <p className="mt-1.5 max-w-xl text-[13px] leading-6 text-muted-foreground">{message}</p>}
|
|
98
121
|
{requestId && (
|
|
99
122
|
<div className="mt-3 flex items-center gap-1.5 text-[12px] text-muted-foreground">
|
|
100
|
-
<span>{t('error.requestId')}</span>
|
|
123
|
+
<span>{labels?.requestId ?? t('error.requestId')}</span>
|
|
101
124
|
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-[11.5px] text-foreground">
|
|
102
125
|
{requestId}
|
|
103
126
|
</code>
|
|
104
127
|
<IconButton
|
|
105
128
|
icon={copied ? Check : Copy}
|
|
106
|
-
label={
|
|
129
|
+
label={
|
|
130
|
+
copied ? (labels?.copied ?? t('common.copied')) : (labels?.copyRequestId ?? t('error.copyRequestId'))
|
|
131
|
+
}
|
|
107
132
|
size="sm"
|
|
108
133
|
variant="ghost"
|
|
109
134
|
className="size-7"
|
|
@@ -114,7 +139,7 @@ export function ErrorPanel({
|
|
|
114
139
|
<div className="mt-4 flex flex-wrap items-center gap-2">
|
|
115
140
|
{onRetry && (
|
|
116
141
|
<Button variant="secondary" size="sm" icon={RotateCw} loading={busy} onClick={() => void retry()}>
|
|
117
|
-
{busy ? t('error.retrying') : retryLabel}
|
|
142
|
+
{busy ? (labels?.retrying ?? t('error.retrying')) : retryLabel}
|
|
118
143
|
</Button>
|
|
119
144
|
)}
|
|
120
145
|
{secondaryAction && (
|
|
@@ -131,7 +156,7 @@ export function ErrorPanel({
|
|
|
131
156
|
</div>
|
|
132
157
|
{details && (
|
|
133
158
|
<Collapsible className="mt-4">
|
|
134
|
-
<CollapsibleTrigger className="text-[12.5px]">{t('error.details')}</CollapsibleTrigger>
|
|
159
|
+
<CollapsibleTrigger className="text-[12.5px]">{labels?.details ?? t('error.details')}</CollapsibleTrigger>
|
|
135
160
|
<CollapsiblePanel>
|
|
136
161
|
<pre className="mt-2 max-h-60 overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-[11.5px] leading-5 whitespace-pre-wrap text-foreground">
|
|
137
162
|
{details}
|
|
@@ -141,7 +166,11 @@ export function ErrorPanel({
|
|
|
141
166
|
)}
|
|
142
167
|
{announce && (
|
|
143
168
|
<p role="status" className="sr-only">
|
|
144
|
-
{busy
|
|
169
|
+
{busy
|
|
170
|
+
? (labels?.retryingStatus ?? t('error.retryingStatus'))
|
|
171
|
+
: copied
|
|
172
|
+
? (labels?.requestIdCopied ?? t('error.requestIdCopied'))
|
|
173
|
+
: ''}
|
|
145
174
|
</p>
|
|
146
175
|
)}
|
|
147
176
|
</div>
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { ErrorPanelLabels } from './ErrorPanel';
|
|
2
3
|
|
|
3
4
|
export const meta: BlockMeta = {
|
|
4
5
|
name: 'Error panel',
|
|
5
6
|
family: 'feedback',
|
|
6
7
|
status: 'beta',
|
|
7
8
|
description:
|
|
8
|
-
'Error summary with status code, copyable request id, retry with loading state and a technical-details disclosure.',
|
|
9
|
+
'Error summary with status code, copyable request id, retry with loading state and a technical-details disclosure. Optional labels?: Partial<ErrorPanelLabels> overrides each built-in label. Explicit content props win over labels, then I18nProvider (en/es); no provider keeps English. Imported fixtures and machine data stay unchanged. See the Catalog labels live preview.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'title', type: 'string', state: 'Panel heading; explicit title prop wins, including null' },
|
|
12
|
+
{ key: 'message', type: 'string', state: 'Summary; explicit message prop wins, including null' },
|
|
13
|
+
{
|
|
14
|
+
key: 'support',
|
|
15
|
+
type: 'string',
|
|
16
|
+
state: 'Default secondary action; explicit secondaryAction wins, including null',
|
|
17
|
+
},
|
|
18
|
+
{ key: 'retry', type: 'string', state: 'Retry button; retryLabel prop wins' },
|
|
19
|
+
{ key: 'retrying', type: 'string', state: 'Busy retry button' },
|
|
20
|
+
{ key: 'retryingStatus', type: 'string', state: 'Busy status announcement' },
|
|
21
|
+
{ key: 'requestId', type: 'string', state: 'Request ID caption' },
|
|
22
|
+
{ key: 'copyRequestId', type: 'string', state: 'Copy request ID button' },
|
|
23
|
+
{ key: 'copied', type: 'string', state: 'Copy button after copying' },
|
|
24
|
+
{ key: 'requestIdCopied', type: 'string', state: 'Copied status announcement' },
|
|
25
|
+
{ key: 'details', type: 'string', state: 'Technical details disclosure' },
|
|
26
|
+
] satisfies Array<{ key: keyof ErrorPanelLabels; type: string; state: string }>,
|
|
9
27
|
uses: ['Button', 'IconButton', 'Collapsible'],
|
|
10
28
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { I18nProvider, Stack } from '@gntik-ai/ui';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { ErrorPanel } from '../ErrorPanel';
|
|
4
|
+
export default function Spanish() {
|
|
5
|
+
const [retrying, setRetrying] = useState(false);
|
|
6
|
+
return (
|
|
7
|
+
<I18nProvider locale="es">
|
|
8
|
+
<Stack gap={6}>
|
|
9
|
+
<ErrorPanel onRetry={() => {}} />
|
|
10
|
+
<ErrorPanel
|
|
11
|
+
retrying={retrying}
|
|
12
|
+
onRetry={() => setRetrying(true)}
|
|
13
|
+
labels={{
|
|
14
|
+
title: 'Resource unavailable',
|
|
15
|
+
message: 'Please try again.',
|
|
16
|
+
support: 'Get help',
|
|
17
|
+
retry: 'Try loading',
|
|
18
|
+
retrying: 'Loading…',
|
|
19
|
+
retryingStatus: 'Loading resource',
|
|
20
|
+
requestId: 'Reference',
|
|
21
|
+
copyRequestId: 'Copy reference',
|
|
22
|
+
copied: 'Reference copied',
|
|
23
|
+
requestIdCopied: 'Reference copied to clipboard',
|
|
24
|
+
details: 'Show diagnostics',
|
|
25
|
+
}}
|
|
26
|
+
/>
|
|
27
|
+
</Stack>
|
|
28
|
+
</I18nProvider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { I18nProvider, es } from '@gntik-ai/ui';
|
|
3
|
+
import { InlineCallout, type InlineCalloutLabels } from './InlineCallout';
|
|
4
|
+
|
|
5
|
+
it('localizes built-in callout content and action labels, leaving the href unchanged', () => {
|
|
6
|
+
render(
|
|
7
|
+
<I18nProvider locale="es">
|
|
8
|
+
<InlineCallout />
|
|
9
|
+
</I18nProvider>,
|
|
10
|
+
);
|
|
11
|
+
expect(screen.getByText(es['callout.title'])).toHaveTextContent('Has usado el 92% de tus minutos de compilación');
|
|
12
|
+
expect(screen.getByText(es['callout.description'])).toBeVisible();
|
|
13
|
+
expect(screen.getByRole('button', { name: es['callout.upgrade'] })).toBeVisible();
|
|
14
|
+
expect(screen.getByRole('link', { name: es['callout.viewUsage'] })).toHaveAttribute('href', '#usage');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('preserves English, merges overrides per key and respects explicit content and actions', () => {
|
|
18
|
+
const { rerender } = render(<InlineCallout />);
|
|
19
|
+
expect(screen.getByText('You have used 92% of your build minutes')).toBeVisible();
|
|
20
|
+
expect(
|
|
21
|
+
screen.getByText(
|
|
22
|
+
'Builds will queue once the monthly limit is reached. Upgrade the plan or reduce concurrent builds.',
|
|
23
|
+
),
|
|
24
|
+
).toBeVisible();
|
|
25
|
+
expect(screen.getByRole('button', { name: 'Upgrade plan' })).toBeVisible();
|
|
26
|
+
expect(screen.getByRole('link', { name: 'View usage' })).toBeVisible();
|
|
27
|
+
const labels: InlineCalloutLabels = {
|
|
28
|
+
title: 'Title override',
|
|
29
|
+
description: 'Description override',
|
|
30
|
+
upgrade: 'Upgrade override',
|
|
31
|
+
viewUsage: 'Usage override',
|
|
32
|
+
};
|
|
33
|
+
rerender(
|
|
34
|
+
<I18nProvider locale="es">
|
|
35
|
+
<InlineCallout labels={labels} />
|
|
36
|
+
</I18nProvider>,
|
|
37
|
+
);
|
|
38
|
+
expect(screen.getByText(labels.title)).toBeVisible();
|
|
39
|
+
expect(screen.getByText(labels.description)).toBeVisible();
|
|
40
|
+
expect(screen.getByRole('button', { name: labels.upgrade })).toBeVisible();
|
|
41
|
+
expect(screen.getByRole('link', { name: labels.viewUsage })).toBeVisible();
|
|
42
|
+
rerender(
|
|
43
|
+
<I18nProvider locale="es">
|
|
44
|
+
<InlineCallout labels={{ title: 'Only title' }} />
|
|
45
|
+
</I18nProvider>,
|
|
46
|
+
);
|
|
47
|
+
expect(screen.getByText('Only title')).toBeVisible();
|
|
48
|
+
expect(screen.getByText(es['callout.description'])).toBeVisible();
|
|
49
|
+
expect(screen.getByRole('button', { name: es['callout.upgrade'] })).toBeVisible();
|
|
50
|
+
expect(screen.getByRole('link', { name: es['callout.viewUsage'] })).toBeVisible();
|
|
51
|
+
rerender(
|
|
52
|
+
<InlineCallout
|
|
53
|
+
labels={labels}
|
|
54
|
+
title="Explicit title"
|
|
55
|
+
description="Explicit description"
|
|
56
|
+
actions={[{ label: 'Explicit action', href: '#explicit' }]}
|
|
57
|
+
/>,
|
|
58
|
+
);
|
|
59
|
+
expect(screen.getByText('Explicit title')).toBeVisible();
|
|
60
|
+
expect(screen.getByText('Explicit description')).toBeVisible();
|
|
61
|
+
expect(screen.getByRole('link', { name: 'Explicit action' })).toHaveAttribute('href', '#explicit');
|
|
62
|
+
});
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { Alert, Button, Link, type AlertTone } from '@gntik-ai/ui';
|
|
1
|
+
import { Alert, Button, Link, useI18n, type AlertTone } from '@gntik-ai/ui';
|
|
2
2
|
import type { LucideIcon } from '@gntik-ai/icons';
|
|
3
3
|
import { useState, type ReactNode } from 'react';
|
|
4
4
|
import type { FeedbackAction } from '../types';
|
|
5
5
|
|
|
6
|
+
export interface InlineCalloutLabels {
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
upgrade: string;
|
|
10
|
+
viewUsage: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
export interface InlineCalloutProps {
|
|
14
|
+
/** Per-key copy overrides; explicit props take precedence, then labels, then the active catalog. */
|
|
15
|
+
labels?: Partial<InlineCalloutLabels>;
|
|
7
16
|
tone?: AlertTone;
|
|
8
17
|
title?: ReactNode;
|
|
9
18
|
description?: ReactNode;
|
|
@@ -18,23 +27,27 @@ export interface InlineCalloutProps {
|
|
|
18
27
|
className?: string;
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
const inlineCalloutDefaultActions: FeedbackAction[] = [
|
|
22
|
-
{ label: 'Upgrade plan', variant: 'secondary' },
|
|
23
|
-
{ label: 'View usage', href: '#usage' },
|
|
24
|
-
];
|
|
25
|
-
|
|
26
30
|
/** In-content callout built on Alert: tone, title, body and a row of actions. */
|
|
27
31
|
export function InlineCallout({
|
|
28
32
|
tone = 'warning',
|
|
29
|
-
title
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
title: titleProp,
|
|
34
|
+
labels,
|
|
35
|
+
description: descriptionProp,
|
|
36
|
+
actions: actionsProp,
|
|
32
37
|
icon,
|
|
33
38
|
dismissible = false,
|
|
34
39
|
open,
|
|
35
40
|
onDismiss,
|
|
36
41
|
className,
|
|
37
42
|
}: InlineCalloutProps) {
|
|
43
|
+
const { t } = useI18n();
|
|
44
|
+
const title = titleProp === undefined ? (labels?.title ?? t('callout.title')) : titleProp;
|
|
45
|
+
const description =
|
|
46
|
+
descriptionProp === undefined ? (labels?.description ?? t('callout.description')) : descriptionProp;
|
|
47
|
+
const actions: FeedbackAction[] = actionsProp ?? [
|
|
48
|
+
{ label: labels?.upgrade ?? t('callout.upgrade'), variant: 'secondary' },
|
|
49
|
+
{ label: labels?.viewUsage ?? t('callout.viewUsage'), href: '#usage' },
|
|
50
|
+
];
|
|
38
51
|
const [dismissed, setDismissed] = useState(false);
|
|
39
52
|
if (!(open ?? !dismissed)) return null;
|
|
40
53
|
return (
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { InlineCalloutLabels } from './InlineCallout';
|
|
2
3
|
|
|
3
4
|
export const meta: BlockMeta = {
|
|
4
5
|
name: 'Inline callout',
|
|
5
6
|
family: 'feedback',
|
|
6
7
|
status: 'beta',
|
|
7
|
-
description:
|
|
8
|
+
description:
|
|
9
|
+
'Alert-based in-content callout with a tone, title, body, action buttons or links and optional dismiss. Optional labels?: Partial<InlineCalloutLabels> overrides each built-in label. Explicit content props win over labels, then I18nProvider (en/es); no provider keeps English. Imported fixtures and machine data stay unchanged. See the Catalog labels live preview.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'title', type: 'string', state: 'Callout title; explicit title prop wins, including null' },
|
|
12
|
+
{ key: 'description', type: 'string', state: 'Callout body; explicit description prop wins, including null' },
|
|
13
|
+
{ key: 'upgrade', type: 'string', state: 'Default primary action; explicit actions win' },
|
|
14
|
+
{ key: 'viewUsage', type: 'string', state: 'Default usage link; explicit actions win' },
|
|
15
|
+
] satisfies Array<{ key: keyof InlineCalloutLabels; type: string; state: string }>,
|
|
8
16
|
uses: ['Alert', 'Button', 'Link'],
|
|
9
17
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { I18nProvider, Stack } from '@gntik-ai/ui';
|
|
2
|
+
import { InlineCallout } from '../InlineCallout';
|
|
3
|
+
export default function Spanish() {
|
|
4
|
+
return (
|
|
5
|
+
<I18nProvider locale="es">
|
|
6
|
+
<Stack gap={6}>
|
|
7
|
+
<InlineCallout />
|
|
8
|
+
<InlineCallout
|
|
9
|
+
labels={{
|
|
10
|
+
title: 'Build usage',
|
|
11
|
+
description: 'Review your current allowance.',
|
|
12
|
+
upgrade: 'Change plan',
|
|
13
|
+
viewUsage: 'Open usage',
|
|
14
|
+
}}
|
|
15
|
+
/>
|
|
16
|
+
</Stack>
|
|
17
|
+
</I18nProvider>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { I18nProvider, es } from '@gntik-ai/ui';
|
|
3
|
+
import { ListSkeleton, PageSkeleton, TableSkeleton } from './Skeletons';
|
|
4
|
+
|
|
5
|
+
it.each([
|
|
6
|
+
[TableSkeleton, 'loading.table', 'Loading table'],
|
|
7
|
+
[ListSkeleton, 'loading.list', 'Loading list'],
|
|
8
|
+
[PageSkeleton, 'loading.page', 'Loading page'],
|
|
9
|
+
] as const)('audits catalog and explicit loading labels for %s', (Skeleton, key, english) => {
|
|
10
|
+
const { rerender } = render(<Skeleton />);
|
|
11
|
+
expect(screen.getByRole('status').textContent).toBe(english);
|
|
12
|
+
rerender(
|
|
13
|
+
<I18nProvider locale="es">
|
|
14
|
+
<Skeleton />
|
|
15
|
+
</I18nProvider>,
|
|
16
|
+
);
|
|
17
|
+
expect(screen.getByRole('status').textContent).toBe(es[key]);
|
|
18
|
+
rerender(
|
|
19
|
+
<I18nProvider locale="es">
|
|
20
|
+
<Skeleton label="Caller loading text" />
|
|
21
|
+
</I18nProvider>,
|
|
22
|
+
);
|
|
23
|
+
expect(screen.getByRole('status').textContent).toBe('Caller loading text');
|
|
24
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
1
2
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
|
2
3
|
import userEvent from '@testing-library/user-event';
|
|
3
4
|
import { expectNoAxeViolations } from '../../test/a11y';
|
|
@@ -5,6 +6,26 @@ import { FileUploadPanel } from './FileUploadPanel';
|
|
|
5
6
|
import { acceptsFile } from './fixtures';
|
|
6
7
|
|
|
7
8
|
describe('FileUploadPanel', () => {
|
|
9
|
+
it('shows decimal default limits and provider-localized file sizes', () => {
|
|
10
|
+
render(
|
|
11
|
+
<I18nProvider locale="es">
|
|
12
|
+
<FileUploadPanel defaultFiles={[{ id: 'es', name: 'report.pdf', size: 1536, progress: 100, status: 'done' }]} />
|
|
13
|
+
</I18nProvider>,
|
|
14
|
+
);
|
|
15
|
+
expect(screen.getByText(/25 MB/)).toBeInTheDocument();
|
|
16
|
+
expect(screen.getByText(/1,5 kB/)).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('rejects files above the decimal default limit', () => {
|
|
20
|
+
const onUpload = vi.fn(() => Promise.resolve());
|
|
21
|
+
const { container } = render(<FileUploadPanel defaultFiles={[]} onUpload={onUpload} />);
|
|
22
|
+
const input = container.querySelector('input[type="file"]') as HTMLInputElement;
|
|
23
|
+
const big = new File([new Uint8Array(25_000_001)], 'big.pdf', { type: 'application/pdf' });
|
|
24
|
+
fireEvent.change(input, { target: { files: [big] } });
|
|
25
|
+
expect(screen.getByText(/Exceeds the 25 MB limit/)).toBeInTheDocument();
|
|
26
|
+
expect(onUpload).not.toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
8
29
|
it('renders the default list', async () => {
|
|
9
30
|
const { container } = render(<FileUploadPanel />);
|
|
10
31
|
expect(screen.getByRole('group', { name: 'Upload files' })).toBeInTheDocument();
|
|
@@ -27,7 +48,7 @@ describe('FileUploadPanel', () => {
|
|
|
27
48
|
fireEvent.change(input, { target: { files: [ok, big, bad] } });
|
|
28
49
|
expect(onUpload).toHaveBeenCalledOnce();
|
|
29
50
|
expect(screen.getByRole('progressbar', { name: 'Uploading report.csv' })).toBeInTheDocument();
|
|
30
|
-
expect(screen.getByText(/Exceeds the
|
|
51
|
+
expect(screen.getByText(/Exceeds the 1 kB limit/)).toBeInTheDocument();
|
|
31
52
|
expect(screen.getByText(/File type not accepted/)).toBeInTheDocument();
|
|
32
53
|
await act(async () => finish());
|
|
33
54
|
expect(screen.getByText(/^3 B · uploaded$/)).toBeInTheDocument();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Button, IconButton, Progress, cn, useI18n } from '@gntik-ai/ui';
|
|
2
2
|
import { CircleAlert, FileText, RotateCcw, Upload, X } from '@gntik-ai/icons';
|
|
3
3
|
import { useId, useRef, useState, type DragEvent } from 'react';
|
|
4
|
-
import { acceptsFile,
|
|
4
|
+
import { acceptsFile, simulateUpload, uploadItems, type UploadItem } from './fixtures';
|
|
5
5
|
|
|
6
6
|
export type { UploadItem, UploadStatus } from './fixtures';
|
|
7
7
|
|
|
@@ -33,7 +33,7 @@ const nextId = () => `upload-${++uid}`;
|
|
|
33
33
|
*/
|
|
34
34
|
export function FileUploadPanel({
|
|
35
35
|
accept = '.csv,.json,.jsonl,.yaml,.pdf',
|
|
36
|
-
maxSize =
|
|
36
|
+
maxSize = 25_000_000,
|
|
37
37
|
multiple = true,
|
|
38
38
|
defaultFiles = uploadItems,
|
|
39
39
|
onUpload = simulateUpload,
|
|
@@ -43,7 +43,7 @@ export function FileUploadPanel({
|
|
|
43
43
|
disabled = false,
|
|
44
44
|
className,
|
|
45
45
|
}: FileUploadPanelProps) {
|
|
46
|
-
const { t } = useI18n();
|
|
46
|
+
const { t, formatBytes } = useI18n();
|
|
47
47
|
const label = labelProp ?? t('upload.label');
|
|
48
48
|
const id = useId();
|
|
49
49
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
@@ -196,7 +196,7 @@ export function FileUploadPanel({
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
function FileRow({ item, onRemove, onRetry }: { item: UploadItem; onRemove: () => void; onRetry?: () => void }) {
|
|
199
|
-
const { t } = useI18n();
|
|
199
|
+
const { t, formatBytes } = useI18n();
|
|
200
200
|
const err = item.status === 'error';
|
|
201
201
|
const done = item.status === 'done';
|
|
202
202
|
return (
|
|
@@ -39,18 +39,6 @@ export function simulateUpload(_file: File, onProgress: (pct: number) => void):
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function formatBytes(bytes: number) {
|
|
43
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
44
|
-
const units = ['KB', 'MB', 'GB', 'TB'];
|
|
45
|
-
let v = bytes / 1024;
|
|
46
|
-
let i = 0;
|
|
47
|
-
while (v >= 1024 && i < units.length - 1) {
|
|
48
|
-
v /= 1024;
|
|
49
|
-
i++;
|
|
50
|
-
}
|
|
51
|
-
return `${v >= 10 ? Math.round(v) : v.toFixed(1)} ${units[i]}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
42
|
/** Matches a file against an `accept` list (".csv", "image/*", "application/pdf"). */
|
|
55
43
|
export function acceptsFile(file: { name: string; type: string }, accept: string | undefined) {
|
|
56
44
|
if (!accept) return true;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { chartFmt } from '@gntik-ai/charts';
|
|
2
|
+
import { formatBytes } from '@gntik-ai/ui';
|
|
3
|
+
|
|
4
|
+
describe('byte formatter parity', () => {
|
|
5
|
+
it.each([0, 512, 999, 1536, 999_999, 1_840_000, 2_540_000_000])('agrees with chart sizes for %s bytes', (size) => {
|
|
6
|
+
expect(formatBytes(size, 'en')).toBe(chartFmt.bytes(size));
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { I18nProvider, es } from '@gntik-ai/ui';
|
|
3
|
+
import { PageHeader, type PageHeaderLabels } from './PageHeader';
|
|
4
|
+
import { pageHeaderMeta, pageHeaderTabs, pageHeaderActions } from './fixtures';
|
|
5
|
+
|
|
6
|
+
it('translates built-in header labels and leaves fixtures untouched', () => {
|
|
7
|
+
render(
|
|
8
|
+
<I18nProvider locale="es">
|
|
9
|
+
<PageHeader />
|
|
10
|
+
</I18nProvider>,
|
|
11
|
+
);
|
|
12
|
+
expect(screen.getByRole('heading', { name: es['pageHeader.title'] })).toHaveTextContent('Despliegues');
|
|
13
|
+
expect(screen.getByText(es['pageHeader.description'])).toBeVisible();
|
|
14
|
+
expect(screen.getByRole('button', { name: es['pageHeader.moreActions'] })).toBeVisible();
|
|
15
|
+
expect(screen.getByRole('tablist', { name: es['pageHeader.sections'] })).toBeVisible();
|
|
16
|
+
for (const item of pageHeaderMeta) expect(screen.getByText(String(item.value))).toBeVisible();
|
|
17
|
+
for (const tab of pageHeaderTabs) expect(screen.getByRole('tab', { name: new RegExp(tab.label) })).toBeVisible();
|
|
18
|
+
for (const action of pageHeaderActions)
|
|
19
|
+
expect(screen.getAllByRole('button', { name: action.label })[0]).toBeVisible();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('preserves English and merges each override below explicit title and description props', () => {
|
|
23
|
+
const { rerender } = render(<PageHeader />);
|
|
24
|
+
expect(screen.getByRole('heading', { name: 'Deployments' })).toBeVisible();
|
|
25
|
+
expect(screen.getByText('Every build and release of this project across its environments.')).toBeVisible();
|
|
26
|
+
expect(screen.getByRole('button', { name: 'More actions' })).toBeVisible();
|
|
27
|
+
expect(screen.getByRole('tablist', { name: 'Page sections' })).toBeVisible();
|
|
28
|
+
const labels: PageHeaderLabels = {
|
|
29
|
+
title: 'Custom title',
|
|
30
|
+
description: 'Custom description',
|
|
31
|
+
moreActions: 'Custom actions',
|
|
32
|
+
sections: 'Custom sections',
|
|
33
|
+
};
|
|
34
|
+
const view = (overrides: Partial<PageHeaderLabels>, explicit = false) => (
|
|
35
|
+
<I18nProvider locale="es">
|
|
36
|
+
<PageHeader
|
|
37
|
+
labels={overrides}
|
|
38
|
+
title={explicit ? 'Explicit title' : undefined}
|
|
39
|
+
description={explicit ? 'Explicit description' : undefined}
|
|
40
|
+
/>
|
|
41
|
+
</I18nProvider>
|
|
42
|
+
);
|
|
43
|
+
rerender(view(labels));
|
|
44
|
+
expect(screen.getByRole('heading', { name: labels.title })).toBeVisible();
|
|
45
|
+
expect(screen.getByText(labels.description)).toBeVisible();
|
|
46
|
+
expect(screen.getByRole('button', { name: labels.moreActions })).toBeVisible();
|
|
47
|
+
expect(screen.getByRole('tablist', { name: labels.sections })).toBeVisible();
|
|
48
|
+
rerender(view(labels, true));
|
|
49
|
+
expect(screen.getByRole('heading', { name: 'Explicit title' })).toBeVisible();
|
|
50
|
+
expect(screen.getByText('Explicit description')).toBeVisible();
|
|
51
|
+
rerender(view({ moreActions: '' }));
|
|
52
|
+
expect(screen.getByRole('heading', { name: es['pageHeader.title'] })).toBeVisible();
|
|
53
|
+
expect(screen.getByText(es['pageHeader.description'])).toBeVisible();
|
|
54
|
+
expect(screen.getByRole('tablist', { name: es['pageHeader.sections'] })).toBeVisible();
|
|
55
|
+
expect(screen.getByRole('button', { name: '' })).toBeVisible();
|
|
56
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Spanish from './examples/Spanish';
|
|
2
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
1
3
|
import { render, screen } from '@testing-library/react';
|
|
2
4
|
import userEvent from '@testing-library/user-event';
|
|
3
5
|
import { createRef } from 'react';
|
|
@@ -34,6 +36,15 @@ describe('PageHeader', () => {
|
|
|
34
36
|
expect(screen.getByRole('heading', { level: 1 })).not.toHaveAttribute('tabindex');
|
|
35
37
|
});
|
|
36
38
|
|
|
39
|
+
it('names the tablist from the active Spanish catalog', () => {
|
|
40
|
+
render(
|
|
41
|
+
<I18nProvider locale="es">
|
|
42
|
+
<PageHeader />
|
|
43
|
+
</I18nProvider>,
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByRole('tablist', { name: 'Secciones de la página' })).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
|
|
37
48
|
it('renders the default header', async () => {
|
|
38
49
|
const { container } = render(<PageHeader />);
|
|
39
50
|
expect(screen.getByRole('heading', { level: 1, name: 'Deployments' })).toBeInTheDocument();
|
|
@@ -66,3 +77,10 @@ describe('PageHeader', () => {
|
|
|
66
77
|
expect(onTabChange).toHaveBeenCalledWith('domains');
|
|
67
78
|
});
|
|
68
79
|
});
|
|
80
|
+
|
|
81
|
+
it.each(['dark', 'light', 'high_contrast'])('Spanish PageHeader example is axe clean (%s)', async (theme) => {
|
|
82
|
+
document.documentElement.className = theme === 'light' ? '' : theme;
|
|
83
|
+
const { container } = render(<Spanish />);
|
|
84
|
+
expect(screen.getByRole('tablist', { name: 'Secciones de la página' })).toBeInTheDocument();
|
|
85
|
+
await expectNoAxeViolations(container);
|
|
86
|
+
});
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
TabsList,
|
|
8
8
|
TabsTab,
|
|
9
9
|
cn,
|
|
10
|
+
useI18n,
|
|
10
11
|
type BreadcrumbItem,
|
|
11
12
|
type StatusDefinition,
|
|
12
13
|
} from '@gntik-ai/ui';
|
|
@@ -30,7 +31,16 @@ export interface PageHeaderTab {
|
|
|
30
31
|
count?: number;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
export interface PageHeaderLabels {
|
|
35
|
+
title: string;
|
|
36
|
+
description: string;
|
|
37
|
+
moreActions: string;
|
|
38
|
+
sections: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
export interface PageHeaderProps {
|
|
42
|
+
/** Per-key copy overrides; explicit props take precedence, then labels, then the active catalog. */
|
|
43
|
+
labels?: Partial<PageHeaderLabels>;
|
|
34
44
|
/** Root element. Use 'div' where the layout already has a banner (e.g. StackedLayout's pageHeader slot). */
|
|
35
45
|
as?: 'header' | 'div';
|
|
36
46
|
/** Location trail above the title; `null` hides it. */
|
|
@@ -61,9 +71,10 @@ export interface PageHeaderProps {
|
|
|
61
71
|
export function PageHeader({
|
|
62
72
|
as: Root = 'header',
|
|
63
73
|
breadcrumbs = pageHeaderBreadcrumbs,
|
|
64
|
-
title
|
|
74
|
+
title: titleProp,
|
|
75
|
+
labels,
|
|
65
76
|
titleRef,
|
|
66
|
-
description
|
|
77
|
+
description: descriptionProp,
|
|
67
78
|
status = 'active',
|
|
68
79
|
statuses,
|
|
69
80
|
meta = pageHeaderMeta,
|
|
@@ -74,6 +85,10 @@ export function PageHeader({
|
|
|
74
85
|
onTabChange,
|
|
75
86
|
className,
|
|
76
87
|
}: PageHeaderProps) {
|
|
88
|
+
const { t } = useI18n();
|
|
89
|
+
const title = titleProp === undefined ? (labels?.title ?? t('pageHeader.title')) : titleProp;
|
|
90
|
+
const description =
|
|
91
|
+
descriptionProp === undefined ? (labels?.description ?? t('pageHeader.description')) : descriptionProp;
|
|
77
92
|
const explicitPrimary = actions.findIndex((a) => a.variant === 'primary');
|
|
78
93
|
const primaryIndex = explicitPrimary >= 0 ? explicitPrimary : actions.length - 1;
|
|
79
94
|
const primary = actions[primaryIndex];
|
|
@@ -125,7 +140,9 @@ export function PageHeader({
|
|
|
125
140
|
<>
|
|
126
141
|
<div className="hidden shrink-0 items-center gap-2.5 sm:flex">{actions.map(renderAction)}</div>
|
|
127
142
|
<div className="flex shrink-0 items-center gap-2 sm:hidden">
|
|
128
|
-
{folded.length > 0 &&
|
|
143
|
+
{folded.length > 0 && (
|
|
144
|
+
<MoreMenu items={folded.map(toMenuAction)} label={labels?.moreActions ?? t('pageHeader.moreActions')} />
|
|
145
|
+
)}
|
|
129
146
|
{primary && renderAction(primary, primaryIndex)}
|
|
130
147
|
</div>
|
|
131
148
|
</>
|
|
@@ -138,7 +155,7 @@ export function PageHeader({
|
|
|
138
155
|
onValueChange={(value) => onTabChange?.(String(value))}
|
|
139
156
|
className="mt-5"
|
|
140
157
|
>
|
|
141
|
-
<TabsList aria-label=
|
|
158
|
+
<TabsList aria-label={labels?.sections ?? t('pageHeader.sections')} className="overflow-x-auto">
|
|
142
159
|
{tabs.map((t) => (
|
|
143
160
|
<TabsTab key={t.value} value={t.value} count={t.count}>
|
|
144
161
|
{t.label}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { PageHeaderLabels } from './PageHeader';
|
|
2
3
|
|
|
3
4
|
export const meta: BlockMeta = {
|
|
4
5
|
name: 'Page header',
|
|
5
6
|
family: 'page-chrome',
|
|
6
7
|
status: 'beta',
|
|
7
8
|
description:
|
|
8
|
-
'Screen header with breadcrumb, title and status, description, meta row, actions that fold into a MoreMenu on small screens, and optional navigation tabs. titleRef targets the h1 for titleRef.current.focus(), adding tabIndex=-1 only when supplied so the title stays outside the Tab order. In a StatusLayout heading slot use as="div" and disable breadcrumb, meta, tabs, actions, status and description fixtures; the slot supplies the page’s only h1.',
|
|
9
|
+
'Screen header with breadcrumb, title and status, description, meta row, actions that fold into a MoreMenu on small screens, and optional navigation tabs. titleRef targets the h1 for titleRef.current.focus(), adding tabIndex=-1 only when supplied so the title stays outside the Tab order. In a StatusLayout heading slot use as="div" and disable breadcrumb, meta, tabs, actions, status and description fixtures; the slot supplies the page’s only h1. The tablist name follows I18nProvider (en/es); the Spanish preview keeps caller content unchanged. Optional labels?: Partial<PageHeaderLabels> overrides each built-in label. Explicit content props win over labels, then I18nProvider (en/es); no provider keeps English. Imported fixtures and machine data stay unchanged. See the Catalog labels live preview.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'title', type: 'string', state: 'Heading; explicit title prop wins, including null' },
|
|
12
|
+
{ key: 'description', type: 'string', state: 'Description; explicit description prop wins, including null' },
|
|
13
|
+
{ key: 'moreActions', type: 'string', state: 'Compact actions menu name' },
|
|
14
|
+
{ key: 'sections', type: 'string', state: 'Tablist name' },
|
|
15
|
+
] satisfies Array<{ key: keyof PageHeaderLabels; type: string; state: string }>,
|
|
9
16
|
uses: ['Breadcrumbs', 'Button', 'MoreMenu', 'StatusTag', 'Tabs'],
|
|
10
17
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { PageHeader } from '../PageHeader';
|
|
3
|
+
export default function Labels() {
|
|
4
|
+
return (
|
|
5
|
+
<I18nProvider locale="es">
|
|
6
|
+
<PageHeader
|
|
7
|
+
labels={{
|
|
8
|
+
title: 'Application releases',
|
|
9
|
+
description: 'Build and release history.',
|
|
10
|
+
moreActions: 'Additional actions',
|
|
11
|
+
sections: 'Release sections',
|
|
12
|
+
}}
|
|
13
|
+
/>
|
|
14
|
+
</I18nProvider>
|
|
15
|
+
);
|
|
16
|
+
}
|