@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,4 +1,5 @@
1
1
  import {
2
+ useI18n,
2
3
  Alert,
3
4
  Button,
4
5
  Checkbox,
@@ -12,6 +13,7 @@ import {
12
13
  Skeleton,
13
14
  cn,
14
15
  } from '@gntik-ai/ui';
16
+ import { translatedContent } from '../../forms/translated-content';
15
17
  import { Mail, User } from '@gntik-ai/icons';
16
18
  import { useId, useState, type MouseEvent, type ReactNode } from 'react';
17
19
  import { SsoButtons } from '../SsoButtons/SsoButtons';
@@ -23,6 +25,7 @@ import {
23
25
  authSignUpFieldError,
24
26
  useAsyncSubmit,
25
27
  type AuthSignUpField,
28
+ type AuthSignUpFieldLabels,
26
29
  type AuthUnavailableState,
27
30
  type AuthSignUpValidationMessages,
28
31
  } from '../shared';
@@ -36,7 +39,32 @@ export interface SignUpValues {
36
39
  fields?: Record<string, string>;
37
40
  }
38
41
 
42
+ export interface SignUpFormLabels extends AuthSignUpFieldLabels {
43
+ eyebrow: string;
44
+ title: string;
45
+ description: string;
46
+ name: string;
47
+ namePlaceholder: string;
48
+ nameRequired: string;
49
+ email: string;
50
+ emailPlaceholder: string;
51
+ password: string;
52
+ passwordTooShort: (minimum: number) => string;
53
+ termsRequired: string;
54
+ terms: string;
55
+ privacy: string;
56
+ termsConsent: (terms: ReactNode, privacy: ReactNode) => ReactNode;
57
+ submit: string;
58
+ divider: string;
59
+ signInPrompt: string;
60
+ signIn: string;
61
+ policyLoading: string;
62
+ fallbackError: string;
63
+ emailInvalid: string;
64
+ }
65
+
39
66
  export interface SignUpFormProps {
67
+ labels?: Partial<SignUpFormLabels>;
40
68
  /** Ordered text/email inputs before Password. Omit to keep the default fields and payload. */
41
69
  fields?: readonly AuthSignUpField[];
42
70
  messages?: AuthSignUpValidationMessages;
@@ -68,6 +96,7 @@ export interface SignUpFormProps {
68
96
 
69
97
  /** Account creation: name, work email, password with a strength meter and a required terms checkbox. */
70
98
  export function SignUpForm({
99
+ labels,
71
100
  fields,
72
101
  messages,
73
102
  unavailable,
@@ -83,11 +112,16 @@ export function SignUpForm({
83
112
  signInHref = '#',
84
113
  onSignIn,
85
114
  sso = <SsoButtons />,
86
- eyebrow = 'Get started',
87
- title = 'Create your account',
88
- description = 'Set up a workspace for your team in a couple of minutes.',
115
+ eyebrow: eyebrowProp,
116
+ title: titleProp,
117
+ description: descriptionProp,
89
118
  className,
90
119
  }: SignUpFormProps) {
120
+ const { t } = useI18n();
121
+ const eyebrow = eyebrowProp === undefined ? (labels?.eyebrow ?? t('signUp.eyebrow')) : eyebrowProp;
122
+ const title = titleProp === undefined ? (labels?.title ?? t('signUp.title')) : titleProp;
123
+ const description =
124
+ descriptionProp === undefined ? (labels?.description ?? t('signUp.description')) : descriptionProp;
91
125
  const termsErrorId = useId();
92
126
  const fieldPrefix = useId();
93
127
  const passwordId = `${fieldPrefix}-password`;
@@ -96,7 +130,7 @@ export function SignUpForm({
96
130
  const [submitCount, setSubmitCount] = useState(0);
97
131
  const fieldValue = (id: string) => (Object.hasOwn(fieldValues, id) ? (fieldValues[id] ?? '') : '');
98
132
  const configuredErrors: ValidationIssue[] = (fields ?? []).flatMap((field) => {
99
- const message = authSignUpFieldError(fieldValue(field.id), field);
133
+ const message = authSignUpFieldError(fieldValue(field.id), field, t, labels);
100
134
  return message ? [{ fieldId: `${fieldPrefix}-field-${field.id}`, label: field.label, message }] : [];
101
135
  });
102
136
  const [name, setName] = useState('');
@@ -104,7 +138,7 @@ export function SignUpForm({
104
138
  const [password, setPassword] = useState('');
105
139
  const [terms, setTerms] = useState(false);
106
140
  const [submitted, setSubmitted] = useState(false);
107
- const { loading, error, run } = useAsyncSubmit('The account could not be created.');
141
+ const { loading, error, run } = useAsyncSubmit(labels?.fallbackError ?? t('signUp.fallbackError'));
108
142
  const busy = loadingProp ?? loading;
109
143
  const alert = errorProp ?? error;
110
144
  const nameInvalid = submitted && name.trim() === '';
@@ -114,14 +148,20 @@ export function SignUpForm({
114
148
  const termsInvalid = submitted && termsProp !== false && !terms;
115
149
 
116
150
  const passwordError =
117
- messages?.passwordTooShort?.(minPasswordLength) ?? `Use at least ${minPasswordLength} characters.`;
118
- const termsError = messages?.termsRequired ?? 'Accept the terms to continue.';
151
+ messages?.passwordTooShort?.(minPasswordLength) ??
152
+ labels?.passwordTooShort?.(minPasswordLength) ??
153
+ t('signUp.passwordTooShort', { minimum: minPasswordLength });
154
+ const termsError = messages?.termsRequired ?? labels?.termsRequired ?? t('signUp.termsRequired');
155
+ const termsLink = <Link href={termsHref}>{labels?.terms ?? t('signUp.terms')}</Link>;
156
+ const privacyLink = <Link href={privacyHref}>{labels?.privacy ?? t('signUp.privacy')}</Link>;
119
157
  const summaryErrors = [
120
158
  ...configuredErrors,
121
159
  ...(password.length < minPasswordLength
122
- ? [{ fieldId: passwordId, label: 'Password', message: passwordError }]
160
+ ? [{ fieldId: passwordId, label: labels?.password ?? t('signUp.password'), message: passwordError }]
161
+ : []),
162
+ ...(termsProp !== false && !terms
163
+ ? [{ fieldId: termsId, label: labels?.terms ?? t('signUp.terms'), message: termsError }]
123
164
  : []),
124
- ...(termsProp !== false && !terms ? [{ fieldId: termsId, label: 'Terms', message: termsError }] : []),
125
165
  ];
126
166
 
127
167
  if (unavailable)
@@ -135,7 +175,7 @@ export function SignUpForm({
135
175
  return (
136
176
  <div className={cn(authFormClass, 'flex flex-col gap-4', className)}>
137
177
  <span role="status" className="sr-only">
138
- Loading sign-up policy…
178
+ {labels?.policyLoading ?? t('signUp.policyLoading')}
139
179
  </span>
140
180
  <Skeleton aria-hidden className="h-8 w-3/4" />
141
181
  <Skeleton aria-hidden className="h-4 w-full" />
@@ -150,7 +190,7 @@ export function SignUpForm({
150
190
  <AuthHeader eyebrow={eyebrow} title={title} description={description} />
151
191
  <form
152
192
  noValidate
153
- aria-label="Create account"
193
+ aria-label={labels?.submit ?? t('signUp.submit')}
154
194
  className="flex flex-col gap-4"
155
195
  onSubmit={(e) => {
156
196
  e.preventDefault();
@@ -181,7 +221,7 @@ export function SignUpForm({
181
221
  )}
182
222
  {fields !== undefined ? (
183
223
  fields.map((field) => {
184
- const message = authSignUpFieldError(fieldValue(field.id), field);
224
+ const message = authSignUpFieldError(fieldValue(field.id), field, t, labels);
185
225
  const invalid = submitted && message !== null;
186
226
  return (
187
227
  <Field key={field.id} invalid={invalid}>
@@ -203,34 +243,34 @@ export function SignUpForm({
203
243
  ) : (
204
244
  <>
205
245
  <Field invalid={nameInvalid}>
206
- <FieldLabel>Full name</FieldLabel>
246
+ <FieldLabel>{labels?.name ?? t('signUp.name')}</FieldLabel>
207
247
  <Input
208
248
  leadingIcon={User}
209
249
  autoComplete="name"
210
- placeholder="Avery Collins"
250
+ placeholder={labels?.namePlaceholder ?? t('signUp.namePlaceholder')}
211
251
  value={name}
212
252
  onValueChange={setName}
213
253
  required
214
254
  />
215
- <FieldError match={nameInvalid}>Enter your name.</FieldError>
255
+ <FieldError match={nameInvalid}>{labels?.nameRequired ?? t('signUp.nameRequired')}</FieldError>
216
256
  </Field>
217
257
  <Field invalid={emailInvalid}>
218
- <FieldLabel>Work email</FieldLabel>
258
+ <FieldLabel>{labels?.email ?? t('signUp.email')}</FieldLabel>
219
259
  <Input
220
260
  type="email"
221
261
  leadingIcon={Mail}
222
262
  autoComplete="email"
223
- placeholder="name@company.com"
263
+ placeholder={labels?.emailPlaceholder ?? t('signUp.emailPlaceholder')}
224
264
  value={email}
225
265
  onValueChange={setEmail}
226
266
  required
227
267
  />
228
- <FieldError match={emailInvalid}>Enter a valid email address.</FieldError>
268
+ <FieldError match={emailInvalid}>{labels?.emailInvalid ?? t('authValidation.emailInvalid')}</FieldError>
229
269
  </Field>
230
270
  </>
231
271
  )}
232
272
  <Field invalid={passwordInvalid}>
233
- <FieldLabel>Password</FieldLabel>
273
+ <FieldLabel>{labels?.password ?? t('signUp.password')}</FieldLabel>
234
274
  <PasswordInput
235
275
  id={fields !== undefined ? passwordId : undefined}
236
276
  showStrength
@@ -255,9 +295,8 @@ export function SignUpForm({
255
295
  aria-invalid={termsInvalid || undefined}
256
296
  aria-describedby={termsInvalid ? termsErrorId : undefined}
257
297
  label={
258
- <>
259
- I agree to the <Link href={termsHref}>Terms</Link> and <Link href={privacyHref}>Privacy Policy</Link>.
260
- </>
298
+ labels?.termsConsent?.(termsLink, privacyLink) ??
299
+ translatedContent(t('signUp.termsConsent'), { terms: termsLink, privacy: privacyLink })
261
300
  }
262
301
  />
263
302
  {termsInvalid && (
@@ -268,17 +307,17 @@ export function SignUpForm({
268
307
  </div>
269
308
  )}
270
309
  <Button type="submit" size="lg" loading={busy} className="mt-2 w-full">
271
- Create account
310
+ {labels?.submit ?? t('signUp.submit')}
272
311
  </Button>
273
312
  </form>
274
313
  {sso != null && (
275
314
  <>
276
- <AuthDivider>Or sign up with</AuthDivider>
315
+ <AuthDivider>{labels?.divider ?? t('signUp.divider')}</AuthDivider>
277
316
  {sso}
278
317
  </>
279
318
  )}
280
319
  <p className="mt-7 text-center text-[13px] text-muted-foreground">
281
- Already have an account?{' '}
320
+ {labels?.signInPrompt ?? t('signUp.signInPrompt')}{' '}
282
321
  <Link
283
322
  href={signInHref}
284
323
  onClick={
@@ -290,7 +329,7 @@ export function SignUpForm({
290
329
  : undefined
291
330
  }
292
331
  >
293
- Sign in
332
+ {labels?.signIn ?? t('signUp.signIn')}
294
333
  </Link>
295
334
  </p>
296
335
  </div>
@@ -1,11 +1,37 @@
1
1
  import type { BlockMeta } from '../../meta';
2
+ import type { SignUpFormLabels } from './SignUpForm';
2
3
 
3
4
  export const meta: BlockMeta = {
4
5
  name: 'Sign-up form',
5
6
  family: 'auth',
6
7
  status: 'stable',
7
8
  description:
8
- 'Account creation with default name/email fields or ordered text/email fields (values.fields), a password strength meter and required consent (terms=false opts out). minPasswordLength defaults to 8 and drives length validation and the insufficient-length meter; optional passwordHelp can receive the minimum. Configured fields support help, required, autoComplete and validation messages, with a linked validation summary on invalid submit. policyLoading renders skeletons without a form; unavailable replaces the form with consumer title, message and optional action. loading remains submitting; error is form-level feedback. Examples: custom-fields, no-terms, unavailable, loading, submitting and error.',
9
+ 'Account creation with default name/email fields or ordered text/email fields (values.fields), a password strength meter and required consent (terms=false opts out). minPasswordLength defaults to 8 and drives length validation and the insufficient-length meter; optional passwordHelp can receive the minimum. Configured fields support help, required, autoComplete and validation messages, with a linked validation summary on invalid submit. policyLoading renders skeletons without a form; unavailable replaces the form with consumer title, message and optional action. loading remains submitting; error is form-level feedback. Examples: custom-fields, no-terms, unavailable, loading, submitting and error. Optional labels?: Partial<SignUpFormLabels> 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=sign-up-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: 'string', state: 'Default content and accessible names' },
14
+ { key: 'name', type: 'string', state: 'Default content and accessible names' },
15
+ { key: 'namePlaceholder', type: 'string', state: 'Default content and accessible names' },
16
+ { key: 'nameRequired', type: 'string', state: 'Validation feedback' },
17
+ { key: 'email', type: 'string', state: 'Default content and accessible names' },
18
+ { key: 'emailPlaceholder', type: 'string', state: 'Default content and accessible names' },
19
+ { key: 'password', type: 'string', state: 'Default content and accessible names' },
20
+ { key: 'passwordTooShort', type: '(minimum: number) => string', state: 'Validation feedback' },
21
+ { key: 'termsRequired', type: 'string', state: 'Validation feedback' },
22
+ { key: 'terms', type: 'string', state: 'Default content and accessible names' },
23
+ { key: 'privacy', type: 'string', state: 'Default content and accessible names' },
24
+ { key: 'termsConsent', type: '(terms: ReactNode, privacy: ReactNode) => ReactNode', state: 'Async feedback' },
25
+ { key: 'submit', type: 'string', state: 'Default content and accessible names' },
26
+ { key: 'divider', type: 'string', state: 'Default content and accessible names' },
27
+ { key: 'signInPrompt', type: 'string', state: 'Default content and accessible names' },
28
+ { key: 'signIn', type: 'string', state: 'Default content and accessible names' },
29
+ { key: 'policyLoading', type: 'string', state: 'Async feedback' },
30
+ { key: 'fallbackError', type: 'string', state: 'Validation feedback' },
31
+ { key: 'emailInvalid', type: 'string', state: 'Validation feedback' },
32
+ { key: 'fieldRequired', type: '(label: string) => string', state: 'Validation feedback' },
33
+ { key: 'fieldInvalid', type: 'string', state: 'Validation feedback' },
34
+ ] satisfies Array<{ key: keyof SignUpFormLabels; type: string; state: string }>,
9
35
  uses: [
10
36
  'Field',
11
37
  'Input',
@@ -0,0 +1,29 @@
1
+ import { Button, I18nProvider } from '@gntik-ai/ui';
2
+ import { useState } from 'react';
3
+ import { SignUpForm, type SignUpFormLabels } from '../SignUpForm';
4
+
5
+ export default function Labels() {
6
+ const [spanish, setSpanish] = useState(false);
7
+ const [custom, setCustom] = useState(true);
8
+ const labels: Partial<SignUpFormLabels> = {
9
+ title: 'Join your team',
10
+ submit: 'Register',
11
+ passwordTooShort: (minimum) => `Choose at least ${minimum} characters.`,
12
+ fieldRequired: (label) => `${label} is needed.`,
13
+ };
14
+ return (
15
+ <div className="grid gap-4">
16
+ <div className="flex flex-wrap gap-2">
17
+ <Button variant="secondary" aria-pressed={spanish} onClick={() => setSpanish(!spanish)}>
18
+ Spanish catalog
19
+ </Button>
20
+ <Button variant="secondary" aria-pressed={custom} onClick={() => setCustom(!custom)}>
21
+ Custom labels
22
+ </Button>
23
+ </div>
24
+ <I18nProvider locale={spanish ? 'es' : 'en'}>
25
+ <SignUpForm labels={custom ? labels : undefined} />
26
+ </I18nProvider>
27
+ </div>
28
+ );
29
+ }
@@ -0,0 +1,30 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { I18nProvider, es } from '@gntik-ai/ui';
3
+ import { SsoButtons } from './SsoButtons';
4
+ import { ssoProviders } from './fixtures';
5
+ it('translates its group name and leaves provider fixture labels unchanged', () => {
6
+ const { rerender } = render(<SsoButtons />);
7
+ expect(screen.getByRole('group', { name: 'Single sign-on' })).toBeVisible();
8
+ rerender(
9
+ <I18nProvider locale="es">
10
+ <SsoButtons />
11
+ </I18nProvider>,
12
+ );
13
+ expect(screen.getByRole('group', { name: 'Inicio de sesión único' })).toBeVisible();
14
+ expect(screen.getByRole('group')).toHaveAccessibleName(es['ssoButtons.label']);
15
+ for (const provider of ssoProviders) expect(screen.getByRole('button', { name: provider.label })).toBeVisible();
16
+ });
17
+ it.each(['en', 'es'])('honours labels below explicit props under %s', (locale) => {
18
+ const { rerender } = render(
19
+ <I18nProvider locale={locale}>
20
+ <SsoButtons labels={{ label: 'Custom SSO' }} />
21
+ </I18nProvider>,
22
+ );
23
+ expect(screen.getByRole('group', { name: 'Custom SSO' })).toBeVisible();
24
+ rerender(
25
+ <I18nProvider locale={locale}>
26
+ <SsoButtons labels={{ label: 'Custom SSO' }} label="Explicit SSO" />
27
+ </I18nProvider>,
28
+ );
29
+ expect(screen.getByRole('group', { name: 'Explicit SSO' })).toBeVisible();
30
+ });
@@ -1,9 +1,14 @@
1
- import { Button, cn } from '@gntik-ai/ui';
1
+ import { useI18n, Button, cn } from '@gntik-ai/ui';
2
2
  import { ssoProviders, type SsoProvider } from './fixtures';
3
3
 
4
4
  export type { SsoProvider } from './fixtures';
5
5
 
6
+ export interface SsoButtonsLabels {
7
+ label: string;
8
+ }
9
+
6
10
  export interface SsoButtonsProps {
11
+ labels?: Partial<SsoButtonsLabels>;
7
12
  providers?: SsoProvider[];
8
13
  /** Called with the provider id. */
9
14
  onSelect?: (providerId: string) => void;
@@ -19,14 +24,17 @@ export interface SsoButtonsProps {
19
24
 
20
25
  /** Neutral single-sign-on buttons: text labels and lucide icons, no brand colours or logos. */
21
26
  export function SsoButtons({
27
+ labels,
22
28
  providers = ssoProviders,
23
29
  onSelect,
24
30
  loadingId = null,
25
31
  disabled = false,
26
32
  layout = 'stack',
27
- label = 'Single sign-on',
33
+ label: labelProp,
28
34
  className,
29
35
  }: SsoButtonsProps) {
36
+ const { t } = useI18n();
37
+ const label = labelProp ?? labels?.label ?? t('ssoButtons.label');
30
38
  return (
31
39
  <div
32
40
  role="group"
@@ -1,9 +1,16 @@
1
1
  import type { BlockMeta } from '../../meta';
2
+ import type { SsoButtonsLabels } from './SsoButtons';
2
3
 
3
4
  export const meta: BlockMeta = {
4
5
  name: 'SSO buttons',
5
6
  family: 'auth',
6
7
  status: 'stable',
7
- description: 'Neutral "Continue with …" provider buttons with lucide icons and a per-provider loading state.',
8
+ description:
9
+ 'Neutral "Continue with …" provider buttons with lucide icons and a per-provider loading state. Optional labels?: Partial<SsoButtonsLabels> 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=sso-buttons--labels.',
10
+ labels: [{ key: 'label', type: 'string', state: 'Default content and accessible names' }] satisfies Array<{
11
+ key: keyof SsoButtonsLabels;
12
+ type: string;
13
+ state: string;
14
+ }>,
8
15
  uses: ['Button'],
9
16
  };
@@ -0,0 +1,24 @@
1
+ import { Button, I18nProvider } from '@gntik-ai/ui';
2
+ import { useState } from 'react';
3
+ import { SsoButtons, type SsoButtonsLabels } from '../SsoButtons';
4
+
5
+ export default function Labels() {
6
+ const [spanish, setSpanish] = useState(false);
7
+ const [custom, setCustom] = useState(true);
8
+ const labels: Partial<SsoButtonsLabels> = { label: 'Identity providers' };
9
+ return (
10
+ <div className="grid gap-4">
11
+ <div className="flex flex-wrap gap-2">
12
+ <Button variant="secondary" aria-pressed={spanish} onClick={() => setSpanish(!spanish)}>
13
+ Spanish catalog
14
+ </Button>
15
+ <Button variant="secondary" aria-pressed={custom} onClick={() => setCustom(!custom)}>
16
+ Custom labels
17
+ </Button>
18
+ </div>
19
+ <I18nProvider locale={spanish ? 'es' : 'en'}>
20
+ <SsoButtons labels={custom ? labels : undefined} />
21
+ </I18nProvider>
22
+ </div>
23
+ );
24
+ }
@@ -0,0 +1,71 @@
1
+ import { act, renderHook } from '@testing-library/react';
2
+ import { I18nProvider, useI18n } from '@gntik-ai/ui';
3
+ import { authIdentifierError, authSignUpFieldError, useAsyncSubmit } from './shared';
4
+ import type { ReactNode } from 'react';
5
+ const wrapper = ({ children }: { children: ReactNode }) => <I18nProvider locale="es">{children}</I18nProvider>;
6
+ it('preserves legacy helper signatures and English outputs', () => {
7
+ expect(authIdentifierError('')).toBe('Enter a valid email address.');
8
+ expect(authIdentifierError('', { type: 'text' })).toBe('Enter a valid identifier.');
9
+ expect(authSignUpFieldError('', { id: 'name', label: 'Full name', required: true })).toBe('Enter Full name.');
10
+ expect(authSignUpFieldError('bad', { id: 'email', label: 'Email', type: 'email' })).toBe(
11
+ 'Enter a valid email address.',
12
+ );
13
+ });
14
+ it('accepts a provider translator and keeps explicit validation messages first', () => {
15
+ const { result } = renderHook(() => useI18n(), { wrapper });
16
+ expect(authIdentifierError('', undefined, undefined, result.current.t)).toBe(
17
+ 'Introduce una dirección de correo válida.',
18
+ );
19
+ expect(authIdentifierError('x', { type: 'text', minLength: 3 }, undefined, result.current.t)).toBe(
20
+ 'Introduce un identificador válido.',
21
+ );
22
+ expect(authSignUpFieldError('', { id: 'name', label: 'Nombre', required: true }, result.current.t)).toBe(
23
+ 'Introduce Nombre.',
24
+ );
25
+ expect(authSignUpFieldError('bad', { id: 'email', label: 'Email', type: 'email' }, result.current.t)).toBe(
26
+ 'Introduce una dirección de correo válida.',
27
+ );
28
+ expect(authIdentifierError('', undefined, { identifierRequired: 'Explicit required' }, result.current.t)).toBe(
29
+ 'Explicit required',
30
+ );
31
+ expect(
32
+ authSignUpFieldError(
33
+ '',
34
+ { id: 'name', label: 'Nombre', required: true, messages: { required: 'Explicit field' } },
35
+ result.current.t,
36
+ ),
37
+ ).toBe('Explicit field');
38
+ });
39
+ it('localises non-Error async rejections and honours explicit fallback', async () => {
40
+ const { result, rerender } = renderHook(({ fallback }: { fallback?: string }) => useAsyncSubmit(fallback), {
41
+ wrapper,
42
+ initialProps: { fallback: undefined as string | undefined },
43
+ });
44
+ await act(async () => {
45
+ await result.current.run(() => Promise.reject(null));
46
+ });
47
+ expect(result.current.error).toBe('Algo salió mal. Inténtalo de nuevo.');
48
+ rerender({ fallback: 'Explicit failure' });
49
+ await act(async () => {
50
+ await result.current.run(() => Promise.reject(null));
51
+ });
52
+ expect(result.current.error).toBe('Explicit failure');
53
+ await act(async () => {
54
+ await result.current.run(() => Promise.reject(new Error('Server message')));
55
+ });
56
+ expect(result.current.error).toBe('Server message');
57
+ });
58
+
59
+ it('resolves explicit validation fallbacks before labels and treats undefined as absent', () => {
60
+ expect(
61
+ authIdentifierError('', undefined, { identifierRequired: undefined }, undefined, {
62
+ identifierRequired: 'Custom required',
63
+ }),
64
+ ).toBe('Custom required');
65
+ expect(
66
+ authIdentifierError('x', { type: 'text', minLength: 3 }, { identifierInvalid: 'Explicit invalid' }, undefined, {
67
+ identifierTooShort: 'Custom short',
68
+ }),
69
+ ).toBe('Explicit invalid');
70
+ expect(authSignUpFieldError('', { id: 'literal', label: '$&', required: true })).toBe('Enter $&.');
71
+ });
@@ -1,4 +1,4 @@
1
- import { cn } from '@gntik-ai/ui';
1
+ import { cn, en, useI18n, type I18n } from '@gntik-ai/ui';
2
2
  import { useState, type ReactNode } from 'react';
3
3
 
4
4
  export interface AuthHeaderProps {
@@ -45,7 +45,8 @@ export function AuthDivider({ children }: { children: ReactNode }) {
45
45
  export const authFormClass = 'w-full max-w-[392px]';
46
46
 
47
47
  /** Loading + error state around an async submit handler. A rejection's message becomes the error. */
48
- export function useAsyncSubmit(fallbackError = 'Something went wrong. Try again.') {
48
+ export function useAsyncSubmit(fallbackError?: string) {
49
+ const { t } = useI18n();
49
50
  const [loading, setLoading] = useState(false);
50
51
  const [error, setError] = useState<string | null>(null);
51
52
  const run = async (fn: () => void | Promise<void>) => {
@@ -57,7 +58,7 @@ export function useAsyncSubmit(fallbackError = 'Something went wrong. Try again.
57
58
  return true;
58
59
  } catch (e) {
59
60
  setLoading(false);
60
- setError(e instanceof Error ? e.message : fallbackError);
61
+ setError(e instanceof Error ? e.message : (fallbackError ?? t('authValidation.fallbackError')));
61
62
  return false;
62
63
  }
63
64
  };
@@ -98,17 +99,32 @@ export interface AuthFormAccessibilityProps {
98
99
  'aria-labelledby'?: string;
99
100
  }
100
101
 
101
- export function authIdentifierError(value: string, config?: AuthIdentifierConfig, messages?: AuthValidationMessages) {
102
+ export function authIdentifierError(
103
+ value: string,
104
+ config?: AuthIdentifierConfig,
105
+ messages?: AuthValidationMessages,
106
+ t?: I18n['t'],
107
+ labels?: AuthValidationMessages,
108
+ ) {
102
109
  const trimmed = value.trim();
103
- const fallback = config?.type === 'text' ? 'Enter a valid identifier.' : 'Enter a valid email address.';
104
- if (!trimmed) return messages?.identifierRequired ?? fallback;
110
+ const fallback =
111
+ config?.type === 'text'
112
+ ? (t?.('authValidation.identifierInvalid') ?? en['authValidation.identifierInvalid'])
113
+ : (t?.('authValidation.emailInvalid') ?? en['authValidation.emailInvalid']);
114
+ if (!trimmed) return messages?.identifierRequired ?? labels?.identifierRequired ?? fallback;
105
115
  if (config?.minLength !== undefined && trimmed.length < config.minLength)
106
- return messages?.identifierTooShort ?? messages?.identifierInvalid ?? fallback;
116
+ return (
117
+ messages?.identifierTooShort ??
118
+ messages?.identifierInvalid ??
119
+ labels?.identifierTooShort ??
120
+ labels?.identifierInvalid ??
121
+ fallback
122
+ );
107
123
  if (
108
124
  ((config?.type ?? 'email') === 'email' && !EMAIL_RE.test(trimmed)) ||
109
125
  (config?.maxLength !== undefined && trimmed.length > config.maxLength)
110
126
  )
111
- return messages?.identifierInvalid ?? fallback;
127
+ return messages?.identifierInvalid ?? labels?.identifierInvalid ?? fallback;
112
128
  return null;
113
129
  }
114
130
 
@@ -125,11 +141,32 @@ export interface AuthSignUpField {
125
141
  messages?: { required?: string; invalid?: string };
126
142
  }
127
143
 
128
- export function authSignUpFieldError(value: string, field: AuthSignUpField) {
144
+ export interface AuthSignUpFieldLabels {
145
+ fieldRequired: (label: string) => string;
146
+ fieldInvalid: string;
147
+ }
148
+
149
+ export function authSignUpFieldError(
150
+ value: string,
151
+ field: AuthSignUpField,
152
+ t?: I18n['t'],
153
+ labels?: Partial<AuthSignUpFieldLabels>,
154
+ ) {
129
155
  const trimmed = value.trim();
130
- if (!trimmed) return field.required ? (field.messages?.required ?? `Enter ${field.label}.`) : null;
156
+ if (!trimmed)
157
+ return field.required
158
+ ? (field.messages?.required ??
159
+ labels?.fieldRequired?.(field.label) ??
160
+ t?.('authValidation.fieldRequired', { label: field.label }) ??
161
+ en['authValidation.fieldRequired'].replace('{label}', () => field.label))
162
+ : null;
131
163
  if (field.type === 'email' && !EMAIL_RE.test(trimmed))
132
- return field.messages?.invalid ?? 'Enter a valid email address.';
164
+ return (
165
+ field.messages?.invalid ??
166
+ labels?.fieldInvalid ??
167
+ t?.('authValidation.emailInvalid') ??
168
+ en['authValidation.emailInvalid']
169
+ );
133
170
  return null;
134
171
  }
135
172
 
@@ -0,0 +1,49 @@
1
+ import { render, screen, within } from '@testing-library/react';
2
+ import { I18nProvider } from '@gntik-ai/ui';
3
+ import { LogViewer } from './LogViewer';
4
+ import { makeLogLines } from './fixtures';
5
+
6
+ it('uses Spanish catalog names for chips and filter options', () => {
7
+ const lines = makeLogLines(20);
8
+ render(
9
+ <I18nProvider locale="es">
10
+ <LogViewer lines={lines} height={600} />
11
+ </I18nProvider>,
12
+ );
13
+ const chips = { debug: 'DEBUG', info: 'INFO', warn: 'AVISO', error: 'ERROR' };
14
+ const options = { debug: 'debug', info: 'info', warn: 'aviso', error: 'error' };
15
+ const rows = screen.getByRole('log').querySelectorAll('[data-slot="log-line"]');
16
+ expect(rows).toHaveLength(20);
17
+ lines.forEach((line, i) => {
18
+ expect(within(rows[i] as HTMLElement).getByText(chips[line.level])).toBeVisible();
19
+ });
20
+ for (const level of ['debug', 'info', 'warn', 'error'] as const) {
21
+ const count = lines.filter((line) => line.level === level).length;
22
+ expect(screen.getByRole('button', { name: `${options[level]}${count}` })).toHaveTextContent(
23
+ `${options[level]}${count}`,
24
+ );
25
+ }
26
+ });
27
+
28
+ it.each([
29
+ [{ debug: 'Trace', info: 'Notice', warn: 'Caution', error: 'Failure' }, ['Trace', 'Notice', 'Caution', 'Failure']],
30
+ [{ warn: 'Caution' }, ['DEBUG', 'INFO', 'Caution', 'ERROR']],
31
+ ] as const)('renders level overrides verbatim and falls back per level: %j', (levels, expected) => {
32
+ const lines = makeLogLines(10);
33
+ render(
34
+ <I18nProvider locale="es">
35
+ <LogViewer lines={lines} labels={{ levels }} />
36
+ </I18nProvider>,
37
+ );
38
+ for (const [i, level] of (['debug', 'info', 'warn', 'error'] as const).entries()) {
39
+ const line = lines.find((line) => line.level === level)!;
40
+ const row = screen.getByText(line.message).closest('[data-slot="log-line"]') as HTMLElement;
41
+ expect(within(row).getByText(expected[i]!)).toBeVisible();
42
+ const option = levels[level as keyof typeof levels] ?? level;
43
+ expect(
44
+ screen.getByRole('button', {
45
+ name: `${option}${lines.filter((line) => line.level === level).length}`,
46
+ }),
47
+ ).toBeVisible();
48
+ }
49
+ });