@gntik-ai/blocks 0.10.0 → 0.11.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.
Files changed (111) hide show
  1. package/dist/index.d.ts +301 -40
  2. package/dist/index.js +1441 -297
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -6
  5. package/src/auth/ForgotPasswordForm/ForgotPasswordForm.labels.test.tsx +179 -0
  6. package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +59 -24
  7. package/src/auth/ForgotPasswordForm/block.meta.ts +22 -1
  8. package/src/auth/ForgotPasswordForm/examples/Labels.tsx +29 -0
  9. package/src/auth/MfaChallenge/MfaChallenge.labels.test.tsx +139 -0
  10. package/src/auth/MfaChallenge/MfaChallenge.tsx +69 -23
  11. package/src/auth/MfaChallenge/block.meta.ts +29 -1
  12. package/src/auth/MfaChallenge/examples/Labels.tsx +28 -0
  13. package/src/auth/ResetPasswordForm/ResetPasswordForm.labels.test.tsx +104 -0
  14. package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +42 -15
  15. package/src/auth/ResetPasswordForm/block.meta.ts +17 -1
  16. package/src/auth/ResetPasswordForm/examples/Labels.tsx +28 -0
  17. package/src/auth/SignInForm/SignInForm.labels.test.tsx +137 -0
  18. package/src/auth/SignInForm/SignInForm.tsx +43 -16
  19. package/src/auth/SignInForm/block.meta.ts +22 -1
  20. package/src/auth/SignInForm/examples/Labels.tsx +29 -0
  21. package/src/auth/SignUpForm/SignUpForm.labels.test.tsx +217 -0
  22. package/src/auth/SignUpForm/SignUpForm.tsx +65 -26
  23. package/src/auth/SignUpForm/block.meta.ts +27 -1
  24. package/src/auth/SignUpForm/examples/Labels.tsx +29 -0
  25. package/src/auth/SsoButtons/SsoButtons.labels.test.tsx +30 -0
  26. package/src/auth/SsoButtons/SsoButtons.tsx +10 -2
  27. package/src/auth/SsoButtons/block.meta.ts +8 -1
  28. package/src/auth/SsoButtons/examples/Labels.tsx +24 -0
  29. package/src/auth/shared.i18n.test.tsx +71 -0
  30. package/src/auth/shared.tsx +48 -11
  31. package/src/builders/LogViewer/LogViewer.levels.test.tsx +49 -0
  32. package/src/builders/LogViewer/LogViewer.tsx +29 -8
  33. package/src/builders/LogViewer/LogViewer.wrap.test.tsx +181 -0
  34. package/src/builders/LogViewer/block.meta.ts +6 -1
  35. package/src/builders/LogViewer/examples/Wrap.tsx +62 -0
  36. package/src/builders/LogViewer/use-wrapped-log-rows.ts +42 -0
  37. package/src/data-display/DescriptionListCard/DescriptionListCard.options.test.tsx +64 -0
  38. package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +38 -17
  39. package/src/data-display/DescriptionListCard/block.meta.ts +1 -1
  40. package/src/data-display/DescriptionListCard/examples/Spanish.tsx +7 -0
  41. package/src/feedback/EmptyStates/EmptyStates.tsx +32 -14
  42. package/src/feedback/EmptyStates/NoAccessEmpty.options.test.tsx +38 -0
  43. package/src/feedback/EmptyStates/block.meta.ts +1 -1
  44. package/src/feedback/EmptyStates/examples/Spanish.tsx +7 -0
  45. package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.labels.test.tsx +115 -0
  46. package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +63 -21
  47. package/src/forms/CreateApiKeyDialog/block.meta.ts +22 -1
  48. package/src/forms/CreateApiKeyDialog/examples/Labels.tsx +29 -0
  49. package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.labels.test.tsx +165 -0
  50. package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.tsx +31 -8
  51. package/src/forms/CredentialDisclosureDialog/SecretCopy.tsx +16 -8
  52. package/src/forms/CredentialDisclosureDialog/block.meta.ts +19 -1
  53. package/src/forms/CredentialDisclosureDialog/examples/Labels.tsx +38 -0
  54. package/src/forms/DangerZone/ConfirmDestructiveDialog.tsx +17 -3
  55. package/src/forms/DangerZone/DangerZone.labels.test.tsx +87 -0
  56. package/src/forms/DangerZone/DangerZone.tsx +20 -5
  57. package/src/forms/DangerZone/block.meta.ts +10 -1
  58. package/src/forms/DangerZone/examples/Labels.tsx +29 -0
  59. package/src/forms/DateRangeFilter/DateRangeFilter.labels.test.tsx +52 -0
  60. package/src/forms/DateRangeFilter/DateRangeFilter.tsx +11 -3
  61. package/src/forms/DateRangeFilter/block.meta.ts +8 -1
  62. package/src/forms/DateRangeFilter/examples/Labels.tsx +28 -0
  63. package/src/forms/DialogWizard/DialogWizard.labels.test.tsx +37 -0
  64. package/src/forms/DialogWizard/DialogWizard.tsx +13 -2
  65. package/src/forms/DialogWizard/block.meta.ts +7 -1
  66. package/src/forms/DialogWizard/examples/Labels.tsx +39 -0
  67. package/src/forms/FileUploadPanel/FileUploadPanel.labels.test.tsx +126 -0
  68. package/src/forms/FileUploadPanel/FileUploadPanel.tsx +81 -18
  69. package/src/forms/FileUploadPanel/block.meta.ts +22 -1
  70. package/src/forms/FileUploadPanel/examples/Labels.tsx +29 -0
  71. package/src/forms/FormSection/FormSection.labels.test.tsx +37 -0
  72. package/src/forms/FormSection/FormSection.tsx +14 -3
  73. package/src/forms/FormSection/block.meta.ts +7 -1
  74. package/src/forms/FormSection/examples/Labels.tsx +27 -0
  75. package/src/forms/InviteMembersDialog/InviteMembersDialog.labels.test.tsx +87 -0
  76. package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +51 -16
  77. package/src/forms/InviteMembersDialog/block.meta.ts +20 -1
  78. package/src/forms/InviteMembersDialog/examples/Labels.tsx +28 -0
  79. package/src/forms/SettingsRow/SettingsRow.labels.test.tsx +33 -0
  80. package/src/forms/SettingsRow/SettingsRow.tsx +14 -3
  81. package/src/forms/SettingsRow/block.meta.ts +7 -1
  82. package/src/forms/SettingsRow/examples/Labels.tsx +27 -0
  83. package/src/forms/ValidationSummary/ValidationSummary.labels.test.tsx +47 -0
  84. package/src/forms/ValidationSummary/ValidationSummary.tsx +9 -3
  85. package/src/forms/ValidationSummary/block.meta.ts +6 -1
  86. package/src/forms/ValidationSummary/examples/Labels.tsx +24 -0
  87. package/src/forms/index.ts +5 -1
  88. package/src/forms/translated-content.tsx +12 -0
  89. package/src/page-chrome/PageHeader/PageHeader.options.test.tsx +34 -0
  90. package/src/page-chrome/PageHeader/PageHeader.tsx +7 -1
  91. package/src/page-chrome/PageHeader/block.meta.ts +1 -1
  92. package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
  93. package/src/tables/DataTable/DataTable.cross-page-selection.test.tsx +322 -0
  94. package/src/tables/DataTable/DataTable.labels.test.tsx +74 -0
  95. package/src/tables/DataTable/DataTable.server-pagination.test.tsx +1 -1
  96. package/src/tables/DataTable/DataTable.single-select.test.tsx +47 -7
  97. package/src/tables/DataTable/DataTable.test.tsx +55 -0
  98. package/src/tables/DataTable/DataTable.tsx +134 -67
  99. package/src/tables/DataTable/block.meta.ts +21 -3
  100. package/src/tables/DataTable/data-table-props.ts +14 -5
  101. package/src/tables/DataTable/data-table-row.tsx +7 -3
  102. package/src/tables/DataTable/data-table-utils.ts +2 -0
  103. package/src/tables/DataTable/examples/client-selection.tsx +33 -0
  104. package/src/tables/DataTable/examples/paginated-single-selection.tsx +46 -0
  105. package/src/tables/DataTable/examples/server-pagination.tsx +55 -15
  106. package/src/tables/DataTable/labels.ts +4 -0
  107. package/src/tables/DataTable/selection-strip.tsx +31 -0
  108. package/src/tables/DataTable/single-selection.tsx +0 -7
  109. package/src/tables/DataTable/use-multiple-selection.ts +86 -0
  110. package/src/test/OptInDefaults.test.tsx +27 -0
  111. package/src/test/fixtures/opt-in-defaults.json +10 -0
@@ -1,10 +1,45 @@
1
- import { Alert, Button, Field, FieldDescription, FieldError, FieldLabel, Input, OtpInput, cn } from '@gntik-ai/ui';
1
+ import {
2
+ useI18n,
3
+ Alert,
4
+ Button,
5
+ Field,
6
+ FieldDescription,
7
+ FieldError,
8
+ FieldLabel,
9
+ Input,
10
+ OtpInput,
11
+ cn,
12
+ } from '@gntik-ai/ui';
2
13
  import { useEffect, useState, type ReactNode } from 'react';
3
14
  import { AuthHeader, authFormClass, useAsyncSubmit } from '../shared';
4
15
 
5
16
  export type MfaMethod = 'code' | 'backup';
6
17
 
18
+ export interface MfaChallengeLabels {
19
+ eyebrow: string;
20
+ title: string;
21
+ backupTitle: string;
22
+ backupDescription: string;
23
+ destinationDescription: (length: number, destination: string) => string;
24
+ description: (length: number) => string;
25
+ formLabel: string;
26
+ codeLabel: string;
27
+ codeRequired: (length: number) => string;
28
+ backupLabel: string;
29
+ backupPlaceholder: string;
30
+ backupHint: string;
31
+ backupRequired: string;
32
+ submit: string;
33
+ useCode: string;
34
+ resendIn: (remaining: number) => string;
35
+ resend: string;
36
+ resent: string;
37
+ backToSignIn: string;
38
+ fallbackError: string;
39
+ }
40
+
7
41
  export interface MfaChallengeProps {
42
+ labels?: Partial<MfaChallengeLabels>;
8
43
  /** Verifies the code. A returned promise shows the loading state; a rejection shows in the alert. */
9
44
  onVerify?: (code: string, method: MfaMethod) => void | Promise<void>;
10
45
  /** Sends a new code; the resend button then waits `resendCooldown` seconds. */
@@ -31,6 +66,7 @@ export interface MfaChallengeProps {
31
66
  * and a resend button with a countdown.
32
67
  */
33
68
  export function MfaChallenge({
69
+ labels,
34
70
  onVerify,
35
71
  onResend,
36
72
  resendCooldown = 30,
@@ -40,10 +76,13 @@ export function MfaChallenge({
40
76
  error: errorProp,
41
77
  loading: loadingProp,
42
78
  onCancel,
43
- eyebrow = 'Two-step verification',
44
- title = 'Enter your verification code',
79
+ eyebrow: eyebrowProp,
80
+ title: titleProp,
45
81
  className,
46
82
  }: MfaChallengeProps) {
83
+ const { t } = useI18n();
84
+ const eyebrow = eyebrowProp === undefined ? (labels?.eyebrow ?? t('mfaChallenge.eyebrow')) : eyebrowProp;
85
+ const title = titleProp === undefined ? (labels?.title ?? t('mfaChallenge.title')) : titleProp;
47
86
  const [method, setMethod] = useState<MfaMethod>('code');
48
87
  const [code, setCode] = useState('');
49
88
  const [backup, setBackup] = useState('');
@@ -53,7 +92,7 @@ export function MfaChallenge({
53
92
  const [now, setNow] = useState(start);
54
93
  const [resendAt, setResendAt] = useState(() => start + (initialCooldown ?? resendCooldown) * 1000);
55
94
  const [resent, setResent] = useState(false);
56
- const { loading, error, run } = useAsyncSubmit('That code did not work. Try again.');
95
+ const { loading, error, run } = useAsyncSubmit(labels?.fallbackError ?? t('mfaChallenge.fallbackError'));
57
96
  const busy = loadingProp ?? loading;
58
97
  const alert = errorProp ?? error;
59
98
  const remaining = Math.max(0, Math.ceil((resendAt - now) / 1000));
@@ -73,30 +112,31 @@ export function MfaChallenge({
73
112
  };
74
113
 
75
114
  const resend = async () => {
76
- const t = Date.now();
77
- setNow(t);
78
- setResendAt(t + resendCooldown * 1000);
115
+ const time = Date.now();
116
+ setNow(time);
117
+ setResendAt(time + resendCooldown * 1000);
79
118
  setResent(true);
80
119
  await onResend?.();
81
120
  };
82
121
 
83
122
  const description =
84
123
  method === 'backup'
85
- ? 'Enter one of the backup codes you saved when you turned on two-step verification. Each code works once.'
124
+ ? (labels?.backupDescription ?? t('mfaChallenge.backupDescription'))
86
125
  : destination
87
- ? `We sent a ${length}-digit code to ${destination}.`
88
- : `Open your authenticator app and enter the ${length}-digit code.`;
126
+ ? (labels?.destinationDescription?.(length, destination) ??
127
+ t('mfaChallenge.destinationDescription', { length, destination }))
128
+ : (labels?.description?.(length) ?? t('mfaChallenge.description', { length }));
89
129
 
90
130
  return (
91
131
  <div className={cn(authFormClass, className)}>
92
132
  <AuthHeader
93
133
  eyebrow={eyebrow}
94
- title={method === 'backup' ? 'Use a backup code' : title}
134
+ title={method === 'backup' ? (labels?.backupTitle ?? t('mfaChallenge.backupTitle')) : title}
95
135
  description={description}
96
136
  />
97
137
  <form
98
138
  noValidate
99
- aria-label="Verify your identity"
139
+ aria-label={labels?.formLabel ?? t('mfaChallenge.formLabel')}
100
140
  className="flex flex-col gap-5"
101
141
  onSubmit={(e) => {
102
142
  e.preventDefault();
@@ -106,7 +146,7 @@ export function MfaChallenge({
106
146
  {alert && <Alert tone="destructive" description={alert} />}
107
147
  {method === 'code' ? (
108
148
  <Field invalid={invalid}>
109
- <FieldLabel>Verification code</FieldLabel>
149
+ <FieldLabel>{labels?.codeLabel ?? t('mfaChallenge.codeLabel')}</FieldLabel>
110
150
  <OtpInput
111
151
  length={length}
112
152
  value={code}
@@ -116,25 +156,27 @@ export function MfaChallenge({
116
156
  groupSize={length / 2}
117
157
  disabled={busy}
118
158
  />
119
- <FieldError match={invalid}>Enter all {length} digits.</FieldError>
159
+ <FieldError match={invalid}>
160
+ {labels?.codeRequired?.(length) ?? t('mfaChallenge.codeRequired', { length })}
161
+ </FieldError>
120
162
  </Field>
121
163
  ) : (
122
164
  <Field invalid={invalid}>
123
- <FieldLabel>Backup code</FieldLabel>
165
+ <FieldLabel>{labels?.backupLabel ?? t('mfaChallenge.backupLabel')}</FieldLabel>
124
166
  <Input
125
167
  value={backup}
126
168
  onValueChange={setBackup}
127
- placeholder="xxxx-xxxx"
169
+ placeholder={labels?.backupPlaceholder ?? t('mfaChallenge.backupPlaceholder')}
128
170
  autoComplete="one-time-code"
129
171
  spellCheck={false}
130
172
  inputClassName="font-mono tracking-wider"
131
173
  />
132
- <FieldDescription>Backup codes are 8 characters, with or without the dash.</FieldDescription>
133
- <FieldError match={invalid}>Enter a backup code.</FieldError>
174
+ <FieldDescription>{labels?.backupHint ?? t('mfaChallenge.backupHint')}</FieldDescription>
175
+ <FieldError match={invalid}>{labels?.backupRequired ?? t('mfaChallenge.backupRequired')}</FieldError>
134
176
  </Field>
135
177
  )}
136
178
  <Button type="submit" size="lg" loading={busy} className="w-full">
137
- Verify
179
+ {labels?.submit ?? t('mfaChallenge.submit')}
138
180
  </Button>
139
181
  </form>
140
182
  <div className="mt-6 flex flex-wrap items-center justify-between gap-3 text-[13px]">
@@ -147,21 +189,25 @@ export function MfaChallenge({
147
189
  setSubmitted(false);
148
190
  }}
149
191
  >
150
- {method === 'code' ? 'Use a backup code' : 'Use a verification code'}
192
+ {method === 'code'
193
+ ? (labels?.backupTitle ?? t('mfaChallenge.backupTitle'))
194
+ : (labels?.useCode ?? t('mfaChallenge.useCode'))}
151
195
  </Button>
152
196
  {method === 'code' && onResend !== undefined && (
153
197
  <Button variant="ghost" size="sm" disabled={remaining > 0} onClick={() => void resend()}>
154
- {remaining > 0 ? `Resend code in ${remaining}s` : 'Resend code'}
198
+ {remaining > 0
199
+ ? (labels?.resendIn?.(remaining) ?? t('mfaChallenge.resendIn', { remaining }))
200
+ : (labels?.resend ?? t('mfaChallenge.resend'))}
155
201
  </Button>
156
202
  )}
157
203
  </div>
158
204
  <span role="status" className="sr-only">
159
- {resent ? 'A new code was sent.' : ''}
205
+ {resent ? (labels?.resent ?? t('mfaChallenge.resent')) : ''}
160
206
  </span>
161
207
  {onCancel && (
162
208
  <p className="mt-6 text-center">
163
209
  <Button variant="ghost" size="sm" onClick={onCancel}>
164
- Back to sign in
210
+ {labels?.backToSignIn ?? t('mfaChallenge.backToSignIn')}
165
211
  </Button>
166
212
  </p>
167
213
  )}
@@ -1,9 +1,37 @@
1
1
  import type { BlockMeta } from '../../meta';
2
+ import type { MfaChallengeLabels } from './MfaChallenge';
2
3
 
3
4
  export const meta: BlockMeta = {
4
5
  name: 'MFA challenge',
5
6
  family: 'auth',
6
7
  status: 'stable',
7
- description: 'Second-factor step with a one-time code (auto-submit), a backup-code mode and resend with a countdown.',
8
+ description:
9
+ 'Second-factor step with a one-time code (auto-submit), a backup-code mode and resend with a countdown. Optional labels?: Partial<MfaChallengeLabels> 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=mfa-challenge--labels.',
10
+ labels: [
11
+ { key: 'eyebrow', type: 'string', state: 'Default content and accessible names' },
12
+ { key: 'title', type: 'string', state: 'Default content and accessible names' },
13
+ { key: 'backupTitle', type: 'string', state: 'Default content and accessible names' },
14
+ { key: 'backupDescription', type: 'string', state: 'Default content and accessible names' },
15
+ {
16
+ key: 'destinationDescription',
17
+ type: '(length: number, destination: string) => string',
18
+ state: 'Default content and accessible names',
19
+ },
20
+ { key: 'description', type: '(length: number) => string', state: 'Default content and accessible names' },
21
+ { key: 'formLabel', type: 'string', state: 'Default content and accessible names' },
22
+ { key: 'codeLabel', type: 'string', state: 'Default content and accessible names' },
23
+ { key: 'codeRequired', type: '(length: number) => string', state: 'Validation feedback' },
24
+ { key: 'backupLabel', type: 'string', state: 'Default content and accessible names' },
25
+ { key: 'backupPlaceholder', type: 'string', state: 'Default content and accessible names' },
26
+ { key: 'backupHint', type: 'string', state: 'Default content and accessible names' },
27
+ { key: 'backupRequired', type: 'string', state: 'Validation feedback' },
28
+ { key: 'submit', type: 'string', state: 'Default content and accessible names' },
29
+ { key: 'useCode', type: 'string', state: 'Default content and accessible names' },
30
+ { key: 'resendIn', type: '(remaining: number) => string', state: 'Default content and accessible names' },
31
+ { key: 'resend', type: 'string', state: 'Default content and accessible names' },
32
+ { key: 'resent', type: 'string', state: 'Async feedback' },
33
+ { key: 'backToSignIn', type: 'string', state: 'Default content and accessible names' },
34
+ { key: 'fallbackError', type: 'string', state: 'Validation feedback' },
35
+ ] satisfies Array<{ key: keyof MfaChallengeLabels; type: string; state: string }>,
8
36
  uses: ['OtpInput', 'Field', 'Input', 'Button', 'Alert'],
9
37
  };
@@ -0,0 +1,28 @@
1
+ import { Button, I18nProvider } from '@gntik-ai/ui';
2
+ import { useState } from 'react';
3
+ import { MfaChallenge, type MfaChallengeLabels } from '../MfaChallenge';
4
+
5
+ export default function Labels() {
6
+ const [spanish, setSpanish] = useState(false);
7
+ const [custom, setCustom] = useState(true);
8
+ const labels: Partial<MfaChallengeLabels> = {
9
+ title: 'Confirm access',
10
+ submit: 'Confirm code',
11
+ codeRequired: (length) => `Provide the ${length} digits.`,
12
+ };
13
+ return (
14
+ <div className="grid gap-4">
15
+ <div className="flex flex-wrap gap-2">
16
+ <Button variant="secondary" aria-pressed={spanish} onClick={() => setSpanish(!spanish)}>
17
+ Spanish catalog
18
+ </Button>
19
+ <Button variant="secondary" aria-pressed={custom} onClick={() => setCustom(!custom)}>
20
+ Custom labels
21
+ </Button>
22
+ </div>
23
+ <I18nProvider locale={spanish ? 'es' : 'en'}>
24
+ <MfaChallenge labels={custom ? labels : undefined} />
25
+ </I18nProvider>
26
+ </div>
27
+ );
28
+ }
@@ -0,0 +1,104 @@
1
+ import { fireEvent, render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { I18nProvider, en, es } from '@gntik-ai/ui';
4
+ import { ResetPasswordForm, type ResetPasswordFormLabels } from './ResetPasswordForm';
5
+ import { expectNoAxeViolations } from '../../test/a11y';
6
+ it('preserves English defaults without a provider', () => {
7
+ render(<ResetPasswordForm />);
8
+ expect(screen.getByRole('heading', { name: 'Set a new password' })).toBeVisible();
9
+ expect(screen.getByRole('form', { name: 'Set a new password' })).toBeVisible();
10
+ expect(screen.getByText('Account recovery')).toBeVisible();
11
+ expect(screen.getByText('Use at least 8 characters. Avoid passwords you use elsewhere.')).toBeVisible();
12
+ expect(screen.getByLabelText('New password')).toBeVisible();
13
+ expect(screen.getByLabelText('Confirm password')).toBeVisible();
14
+ expect(screen.getByRole('button', { name: 'Update password' })).toBeVisible();
15
+ });
16
+ it('translates every label, parameterised validation and success state', async () => {
17
+ let fails = true;
18
+ render(
19
+ <I18nProvider locale="es">
20
+ <ResetPasswordForm onSubmit={() => (fails ? Promise.reject(null) : undefined)} minPasswordLength={10} />
21
+ </I18nProvider>,
22
+ );
23
+ expect(screen.getByText(es['resetPassword.eyebrow'])).toBeVisible();
24
+ expect(screen.getByRole('heading', { name: es['resetPassword.title'] })).toBeVisible();
25
+ expect(screen.getByText('Usa al menos 10 caracteres. Evita contraseñas que uses en otros sitios.')).toBeVisible();
26
+ fireEvent.submit(screen.getByRole('form', { name: es['resetPassword.title'] }));
27
+ expect(screen.getByText('Usa al menos 10 caracteres.')).toBeVisible();
28
+ fireEvent.change(screen.getByLabelText(es['resetPassword.newPassword']), { target: { value: 'password123' } });
29
+ await userEvent.click(screen.getByRole('button', { name: es['resetPassword.submit'] }));
30
+ expect(screen.getByText(es['resetPassword.passwordMismatch'])).toBeVisible();
31
+ fireEvent.change(screen.getByLabelText(es['resetPassword.confirmPassword']), { target: { value: 'password123' } });
32
+ await userEvent.click(screen.getByRole('button', { name: es['resetPassword.submit'] }));
33
+ expect(await screen.findByText(es['resetPassword.fallbackError'])).toBeVisible();
34
+ await expectNoAxeViolations(screen.getByRole('form'));
35
+ fails = false;
36
+ await userEvent.click(screen.getByRole('button', { name: es['resetPassword.submit'] }));
37
+ expect(await screen.findByRole('heading', { name: es['resetPassword.successTitle'] })).toBeVisible();
38
+ expect(screen.getByText(es['resetPassword.successDescription'])).toBeVisible();
39
+ expect(screen.getByRole('status')).toHaveTextContent(es['resetPassword.successStatus']);
40
+ expect(screen.getByRole('button', { name: es['resetPassword.continue'] })).toBeVisible();
41
+ });
42
+ it.each(['en', 'es'])('honours all label overrides under %s', async (locale) => {
43
+ const labels: ResetPasswordFormLabels = {
44
+ eyebrow: 'Custom eyebrow',
45
+ title: 'Custom title',
46
+ description: (minimum) => `Custom description ${minimum}`,
47
+ newPassword: 'Custom newPassword',
48
+ confirmPassword: 'Custom confirmPassword',
49
+ passwordTooShort: (minimum) => `Custom passwordTooShort ${minimum}`,
50
+ passwordMismatch: 'Custom passwordMismatch',
51
+ submit: 'Custom submit',
52
+ successTitle: 'Custom successTitle',
53
+ successDescription: 'Custom successDescription',
54
+ successStatus: 'Custom successStatus',
55
+ continue: 'Custom continue',
56
+ fallbackError: 'Custom fallbackError',
57
+ };
58
+ let fails = true;
59
+ const { rerender } = render(
60
+ <I18nProvider locale={locale}>
61
+ <ResetPasswordForm labels={labels} onSubmit={() => (fails ? Promise.reject(null) : undefined)} />
62
+ </I18nProvider>,
63
+ );
64
+ expect(screen.getByText(labels.eyebrow)).toBeVisible();
65
+ expect(screen.getByRole('heading', { name: labels.title })).toBeVisible();
66
+ expect(screen.getByText('Custom description 8')).toBeVisible();
67
+ fireEvent.submit(screen.getByRole('form', { name: labels.title }));
68
+ expect(screen.getByText('Custom passwordTooShort 8')).toBeVisible();
69
+ fireEvent.change(screen.getByLabelText(labels.newPassword), { target: { value: 'password123' } });
70
+ await userEvent.click(screen.getByRole('button', { name: labels.submit }));
71
+ expect(screen.getByText(labels.passwordMismatch)).toBeVisible();
72
+ fireEvent.change(screen.getByLabelText(labels.confirmPassword), { target: { value: 'password123' } });
73
+ await userEvent.click(screen.getByRole('button', { name: labels.submit }));
74
+ expect(await screen.findByText(labels.fallbackError)).toBeVisible();
75
+ fails = false;
76
+ await userEvent.click(screen.getByRole('button', { name: labels.submit }));
77
+ expect(await screen.findByRole('heading', { name: labels.successTitle })).toBeVisible();
78
+ expect(screen.getByText(labels.successDescription)).toBeVisible();
79
+ expect(screen.getByRole('status')).toHaveTextContent(labels.successStatus);
80
+ expect(screen.getByRole('button', { name: labels.continue })).toBeVisible();
81
+ rerender(
82
+ <I18nProvider locale={locale}>
83
+ <ResetPasswordForm labels={labels} eyebrow="Explicit eyebrow" />
84
+ </I18nProvider>,
85
+ );
86
+ expect(screen.getByText('Explicit eyebrow')).toBeVisible();
87
+ });
88
+ it('freezes the original English catalog values', () => {
89
+ expect(en['resetPassword.eyebrow']).toBe('Account recovery');
90
+ expect(en['resetPassword.title']).toBe('Set a new password');
91
+ expect(en['resetPassword.description']).toBe('Use at least {minimum} characters. Avoid passwords you use elsewhere.');
92
+ expect(en['resetPassword.newPassword']).toBe('New password');
93
+ expect(en['resetPassword.confirmPassword']).toBe('Confirm password');
94
+ expect(en['resetPassword.passwordTooShort']).toBe('Use at least {minimum} characters.');
95
+ expect(en['resetPassword.passwordMismatch']).toBe("Passwords don't match.");
96
+ expect(en['resetPassword.submit']).toBe('Update password');
97
+ expect(en['resetPassword.successTitle']).toBe('Password updated');
98
+ expect(en['resetPassword.successDescription']).toBe(
99
+ 'You can now sign in with your new password. Other sessions were signed out.',
100
+ );
101
+ expect(en['resetPassword.successStatus']).toBe('Password updated.');
102
+ expect(en['resetPassword.continue']).toBe('Continue to sign in');
103
+ expect(en['resetPassword.fallbackError']).toBe('Your password could not be updated.');
104
+ });
@@ -1,9 +1,26 @@
1
- import { Alert, Button, Field, FieldError, FieldLabel, PasswordInput, cn } from '@gntik-ai/ui';
1
+ import { useI18n, Alert, Button, Field, FieldError, FieldLabel, PasswordInput, cn } from '@gntik-ai/ui';
2
2
  import { CircleCheck } from '@gntik-ai/icons';
3
3
  import { useState, type ReactNode } from 'react';
4
4
  import { AuthHeader, authFormClass, useAsyncSubmit } from '../shared';
5
5
 
6
+ export interface ResetPasswordFormLabels {
7
+ eyebrow: string;
8
+ title: string;
9
+ description: (minimum: number) => string;
10
+ newPassword: string;
11
+ confirmPassword: string;
12
+ passwordTooShort: (minimum: number) => string;
13
+ passwordMismatch: string;
14
+ submit: string;
15
+ successTitle: string;
16
+ successDescription: string;
17
+ successStatus: string;
18
+ continue: string;
19
+ fallbackError: string;
20
+ }
21
+
6
22
  export interface ResetPasswordFormProps {
23
+ labels?: Partial<ResetPasswordFormLabels>;
7
24
  /** Saves the new password. A returned promise shows the loading state; a rejection shows in the alert. */
8
25
  onSubmit?: (password: string) => void | Promise<void>;
9
26
  error?: string | null;
@@ -16,19 +33,22 @@ export interface ResetPasswordFormProps {
16
33
 
17
34
  /** New password + confirmation with length and mismatch validation, then a success state. */
18
35
  export function ResetPasswordForm({
36
+ labels,
19
37
  onSubmit,
20
38
  error: errorProp,
21
39
  minPasswordLength = 8,
22
40
  onContinue,
23
- eyebrow = 'Account recovery',
41
+ eyebrow: eyebrowProp,
24
42
  className,
25
43
  }: ResetPasswordFormProps) {
44
+ const { t } = useI18n();
45
+ const eyebrow = eyebrowProp === undefined ? (labels?.eyebrow ?? t('resetPassword.eyebrow')) : eyebrowProp;
26
46
  const [password, setPassword] = useState('');
27
47
  const [confirm, setConfirm] = useState('');
28
48
  const [confirmTouched, setConfirmTouched] = useState(false);
29
49
  const [submitted, setSubmitted] = useState(false);
30
50
  const [done, setDone] = useState(false);
31
- const { loading, error, run } = useAsyncSubmit('Your password could not be updated.');
51
+ const { loading, error, run } = useAsyncSubmit(labels?.fallbackError ?? t('resetPassword.fallbackError'));
32
52
  const alert = errorProp ?? error;
33
53
  const tooShort = password.length < minPasswordLength;
34
54
  const mismatch = confirm !== password;
@@ -43,14 +63,14 @@ export function ResetPasswordForm({
43
63
  </span>
44
64
  <AuthHeader
45
65
  eyebrow={eyebrow}
46
- title="Password updated"
47
- description="You can now sign in with your new password. Other sessions were signed out."
66
+ title={labels?.successTitle ?? t('resetPassword.successTitle')}
67
+ description={labels?.successDescription ?? t('resetPassword.successDescription')}
48
68
  />
49
69
  <div role="status" className="sr-only">
50
- Password updated.
70
+ {labels?.successStatus ?? t('resetPassword.successStatus')}
51
71
  </div>
52
72
  <Button size="lg" className="w-full" onClick={onContinue}>
53
- Continue to sign in
73
+ {labels?.continue ?? t('resetPassword.continue')}
54
74
  </Button>
55
75
  </div>
56
76
  );
@@ -60,12 +80,14 @@ export function ResetPasswordForm({
60
80
  <div className={cn(authFormClass, className)}>
61
81
  <AuthHeader
62
82
  eyebrow={eyebrow}
63
- title="Set a new password"
64
- description={`Use at least ${minPasswordLength} characters. Avoid passwords you use elsewhere.`}
83
+ title={labels?.title ?? t('resetPassword.title')}
84
+ description={
85
+ labels?.description?.(minPasswordLength) ?? t('resetPassword.description', { minimum: minPasswordLength })
86
+ }
65
87
  />
66
88
  <form
67
89
  noValidate
68
- aria-label="Set a new password"
90
+ aria-label={labels?.title ?? t('resetPassword.title')}
69
91
  className="flex flex-col gap-4"
70
92
  onSubmit={(e) => {
71
93
  e.preventDefault();
@@ -76,12 +98,15 @@ export function ResetPasswordForm({
76
98
  >
77
99
  {alert && <Alert tone="destructive" description={alert} />}
78
100
  <Field invalid={passwordInvalid}>
79
- <FieldLabel>New password</FieldLabel>
101
+ <FieldLabel>{labels?.newPassword ?? t('resetPassword.newPassword')}</FieldLabel>
80
102
  <PasswordInput showStrength value={password} onValueChange={setPassword} required />
81
- <FieldError match={passwordInvalid}>Use at least {minPasswordLength} characters.</FieldError>
103
+ <FieldError match={passwordInvalid}>
104
+ {labels?.passwordTooShort?.(minPasswordLength) ??
105
+ t('resetPassword.passwordTooShort', { minimum: minPasswordLength })}
106
+ </FieldError>
82
107
  </Field>
83
108
  <Field invalid={confirmInvalid}>
84
- <FieldLabel>Confirm password</FieldLabel>
109
+ <FieldLabel>{labels?.confirmPassword ?? t('resetPassword.confirmPassword')}</FieldLabel>
85
110
  <PasswordInput
86
111
  autoComplete="new-password"
87
112
  value={confirm}
@@ -89,10 +114,12 @@ export function ResetPasswordForm({
89
114
  onBlur={() => setConfirmTouched(true)}
90
115
  required
91
116
  />
92
- <FieldError match={confirmInvalid}>Passwords don't match.</FieldError>
117
+ <FieldError match={confirmInvalid}>
118
+ {labels?.passwordMismatch ?? t('resetPassword.passwordMismatch')}
119
+ </FieldError>
93
120
  </Field>
94
121
  <Button type="submit" size="lg" loading={loading} className="mt-2 w-full">
95
- Update password
122
+ {labels?.submit ?? t('resetPassword.submit')}
96
123
  </Button>
97
124
  </form>
98
125
  </div>
@@ -1,10 +1,26 @@
1
1
  import type { BlockMeta } from '../../meta';
2
+ import type { ResetPasswordFormLabels } from './ResetPasswordForm';
2
3
 
3
4
  export const meta: BlockMeta = {
4
5
  name: 'Reset password form',
5
6
  family: 'auth',
6
7
  status: 'stable',
7
8
  description:
8
- 'New password with a strength meter and a confirmation field with mismatch validation, then a success state.',
9
+ 'New password with a strength meter and a confirmation field with mismatch validation, then a success state. Optional labels?: Partial<ResetPasswordFormLabels> 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=reset-password-form--labels.',
10
+ labels: [
11
+ { key: 'eyebrow', type: 'string', state: 'Default content and accessible names' },
12
+ { key: 'title', type: 'string', state: 'Default content and accessible names' },
13
+ { key: 'description', type: '(minimum: number) => string', state: 'Default content and accessible names' },
14
+ { key: 'newPassword', type: 'string', state: 'Default content and accessible names' },
15
+ { key: 'confirmPassword', type: 'string', state: 'Default content and accessible names' },
16
+ { key: 'passwordTooShort', type: '(minimum: number) => string', state: 'Validation feedback' },
17
+ { key: 'passwordMismatch', type: 'string', state: 'Validation feedback' },
18
+ { key: 'submit', type: 'string', state: 'Default content and accessible names' },
19
+ { key: 'successTitle', type: 'string', state: 'Async feedback' },
20
+ { key: 'successDescription', type: 'string', state: 'Async feedback' },
21
+ { key: 'successStatus', type: 'string', state: 'Async feedback' },
22
+ { key: 'continue', type: 'string', state: 'Default content and accessible names' },
23
+ { key: 'fallbackError', type: 'string', state: 'Validation feedback' },
24
+ ] satisfies Array<{ key: keyof ResetPasswordFormLabels; type: string; state: string }>,
9
25
  uses: ['Field', 'PasswordInput', 'Button', 'Alert'],
10
26
  };
@@ -0,0 +1,28 @@
1
+ import { Button, I18nProvider } from '@gntik-ai/ui';
2
+ import { useState } from 'react';
3
+ import { ResetPasswordForm, type ResetPasswordFormLabels } from '../ResetPasswordForm';
4
+
5
+ export default function Labels() {
6
+ const [spanish, setSpanish] = useState(false);
7
+ const [custom, setCustom] = useState(true);
8
+ const labels: Partial<ResetPasswordFormLabels> = {
9
+ title: 'Choose a password',
10
+ submit: 'Save password',
11
+ passwordTooShort: (minimum) => `Choose at least ${minimum} characters.`,
12
+ };
13
+ return (
14
+ <div className="grid gap-4">
15
+ <div className="flex flex-wrap gap-2">
16
+ <Button variant="secondary" aria-pressed={spanish} onClick={() => setSpanish(!spanish)}>
17
+ Spanish catalog
18
+ </Button>
19
+ <Button variant="secondary" aria-pressed={custom} onClick={() => setCustom(!custom)}>
20
+ Custom labels
21
+ </Button>
22
+ </div>
23
+ <I18nProvider locale={spanish ? 'es' : 'en'}>
24
+ <ResetPasswordForm labels={custom ? labels : undefined} />
25
+ </I18nProvider>
26
+ </div>
27
+ );
28
+ }