@astryxdesign/cli 0.1.6-canary.fec872b → 0.1.6

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 (54) hide show
  1. package/package.json +9 -13
  2. package/src/api/template.mjs +28 -104
  3. package/src/api/validate-integration.mjs +8 -0
  4. package/src/codemods/__tests__/registry.test.mjs +0 -1
  5. package/src/codemods/registry.mjs +0 -1
  6. package/src/config.mjs +14 -5
  7. package/src/integration.mjs +15 -4
  8. package/src/lib/component-discovery.mjs +5 -15
  9. package/src/lib/component-format.mjs +13 -45
  10. package/src/lib/component-format.test.mjs +1 -95
  11. package/src/lib/component-loader.mjs +2 -104
  12. package/src/lib/config-schema.mjs +30 -0
  13. package/src/lib/hook-format.mjs +3 -8
  14. package/src/lib/xle/registry.mjs +5 -0
  15. package/src/template.mjs +67 -9
  16. package/src/types/config.d.ts +66 -11
  17. package/src/types/integration.d.ts +18 -7
  18. package/src/types/template-api.d.ts +50 -14
  19. package/templates/blocks/components/Avatar/AvatarGroup.tsx +7 -5
  20. package/templates/blocks/components/Avatar/AvatarShowcase.tsx +6 -4
  21. package/templates/blocks/components/Avatar/AvatarUserCard.tsx +5 -3
  22. package/templates/blocks/components/Avatar/AvatarWithImage.tsx +6 -8
  23. package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +5 -3
  24. package/templates/blocks/components/ChatComposerInput/ChatComposerInputControlledInput.tsx +1 -1
  25. package/templates/blocks/components/ChatComposerInput/ChatComposerInputDisabled.tsx +1 -1
  26. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +1 -1
  27. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +1 -1
  28. package/templates/blocks/components/ChatComposerInput/ChatComposerInputShowcase.tsx +1 -1
  29. package/templates/blocks/components/ChatComposerInput/ChatComposerInputSlashCommands.tsx +1 -1
  30. package/templates/pages/ide/page.tsx +41 -35
  31. package/templates/pages/theme-showcase/page.tsx +7 -7
  32. package/templates/themes/neutral/neutralTheme.ts +32 -63
  33. package/docs/integration-authoring.md +0 -105
  34. package/docs/internationalization.doc.mjs +0 -243
  35. package/src/api/integration-block-exports.test.mjs +0 -240
  36. package/src/api/template-suffix.test.mjs +0 -246
  37. package/src/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +0 -120
  38. package/src/codemods/transforms/v0.1.7/index.mjs +0 -19
  39. package/src/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +0 -188
  40. package/src/doc.mjs +0 -27
  41. package/src/doc.test.mjs +0 -383
  42. package/src/lib/component-discovery.importpath.test.mjs +0 -59
  43. package/src/lib/componentDocOverlay.test.mjs +0 -111
  44. package/src/schemas/doc-schema.mjs +0 -226
  45. package/src/schemas/template-schema.mjs +0 -47
  46. package/src/types/doc.d.ts +0 -23
  47. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.doc.mjs +0 -14
  48. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.tsx +0 -41
  49. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +0 -13
  50. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +0 -78
  51. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.doc.mjs +0 -14
  52. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.tsx +0 -38
  53. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +0 -14
  54. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +0 -47
@@ -43,7 +43,7 @@ export default function ChatComposerInputMentionTrigger() {
43
43
  };
44
44
 
45
45
  return (
46
- <Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
46
+ <Stack direction="vertical" gap={3} style={{width: '100%', maxWidth: 450}}>
47
47
  <ChatComposer
48
48
  onSubmit={() => setValue('')}
49
49
  input={
@@ -54,7 +54,7 @@ export default function ChatComposerInputMultipleTriggers() {
54
54
  };
55
55
 
56
56
  return (
57
- <Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
57
+ <Stack direction="vertical" gap={3} style={{width: '100%', maxWidth: 450}}>
58
58
  <Text type="supporting" color="secondary">
59
59
  Type @ for mentions (blue) or / for commands (yellow)
60
60
  </Text>
@@ -7,7 +7,7 @@ import {Stack} from '@astryxdesign/core/Layout';
7
7
 
8
8
  export default function ChatComposerInputShowcase() {
9
9
  return (
10
- <Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
10
+ <Stack direction="vertical" style={{width: '100%', maxWidth: 450}}>
11
11
  <ChatComposer
12
12
  onSubmit={() => {}}
13
13
  input={
@@ -40,7 +40,7 @@ export default function ChatComposerInputSlashCommands() {
40
40
  };
41
41
 
42
42
  return (
43
- <Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
43
+ <Stack direction="vertical" style={{width: '100%', maxWidth: 450}}>
44
44
  <ChatComposer
45
45
  onSubmit={() => {}}
46
46
  input={
@@ -69,8 +69,8 @@ const styles: Record<string, CSSProperties> = {
69
69
  propertyActions: {
70
70
  marginTop: 'auto',
71
71
  },
72
- terminalPanel: {
73
- flexShrink: 0,
72
+ terminalArea: {
73
+ height: '100%',
74
74
  overflow: 'hidden',
75
75
  },
76
76
  };
@@ -301,40 +301,46 @@ export default function ResizableWorkspacePage() {
301
301
  label="Resize terminal"
302
302
  />
303
303
  {!bottomPanel.isCollapsed && (
304
- <Stack
305
- direction="vertical"
306
- height={bottomPanel.size}
307
- style={styles.terminalPanel}>
308
- <TabList
309
- value={activeTermTab}
310
- onChange={val => setActiveTermTab(val)}
311
- size="sm"
312
- hasDivider={false}
313
- style={styles.tabListPadding}>
314
- <Tab label="Terminal" value="terminal" />
315
- <Tab label="Problems" value="problems" />
316
- <Tab label="Output" value="output" />
317
- <Tab label="Debug" value="debug" />
318
- </TabList>
319
- <StackItem
320
- size="fill"
321
- style={styles.terminalWrapper}>
322
- <CodeBlock
323
- code={TERMINAL_OUTPUT}
324
- language="bash"
325
- container="section"
326
- hasLanguageLabel={false}
327
- hasCopyButton={false}
304
+ <div
305
+ style={{
306
+ height: bottomPanel.size,
307
+ flexShrink: 0,
308
+ overflow: 'hidden',
309
+ }}>
310
+ <Stack
311
+ direction="vertical"
312
+ style={styles.contentFill}>
313
+ <TabList
314
+ value={activeTermTab}
315
+ onChange={val => setActiveTermTab(val)}
328
316
  size="sm"
329
- style={{
330
- width: '100%',
331
- height: '100%',
332
- borderWidth: 0,
333
- borderRadius: 0,
334
- }}
335
- />
336
- </StackItem>
337
- </Stack>
317
+ hasDivider={false}
318
+ style={styles.tabListPadding}>
319
+ <Tab label="Terminal" value="terminal" />
320
+ <Tab label="Problems" value="problems" />
321
+ <Tab label="Output" value="output" />
322
+ <Tab label="Debug" value="debug" />
323
+ </TabList>
324
+ <StackItem
325
+ size="fill"
326
+ style={styles.terminalWrapper}>
327
+ <CodeBlock
328
+ code={TERMINAL_OUTPUT}
329
+ language="bash"
330
+ container="section"
331
+ hasLanguageLabel={false}
332
+ hasCopyButton={false}
333
+ size="sm"
334
+ style={{
335
+ width: '100%',
336
+ height: '100%',
337
+ borderWidth: 0,
338
+ borderRadius: 0,
339
+ }}
340
+ />
341
+ </StackItem>
342
+ </Stack>
343
+ </div>
338
344
  )}
339
345
  </Stack>
340
346
  </LayoutContent>
@@ -282,14 +282,14 @@ const DEFAULT_PRODUCTS: ProductSpec[] = [
282
282
 
283
283
  // Neutral product photos, served from the shared astryx asset CDN so the
284
284
  // scaffolded template renders real imagery without needing local public assets.
285
+ const NEUTRAL_CDN = 'https://lookaside.facebook.com/assets/astryx';
285
286
  const DEFAULT_IMAGES: Record<string, string> = {
286
- watch: 'https://lookaside.facebook.com/assets/astryx/Neutral-Watch.png',
287
- headphones:
288
- 'https://lookaside.facebook.com/assets/astryx/Neutral-Headphones.png',
289
- backpack: 'https://lookaside.facebook.com/assets/astryx/Neutral-Backpack.png',
290
- wallet: 'https://lookaside.facebook.com/assets/astryx/Neutral-Wallet.png',
291
- tumbler: 'https://lookaside.facebook.com/assets/astryx/Neutral-Tumbler.png',
292
- throw_: 'https://lookaside.facebook.com/assets/astryx/Neutral-Blanket.png',
287
+ watch: `${NEUTRAL_CDN}/Neutral-Watch.png`,
288
+ headphones: `${NEUTRAL_CDN}/Neutral-Headphones.png`,
289
+ backpack: `${NEUTRAL_CDN}/Neutral-Backpack.png`,
290
+ wallet: `${NEUTRAL_CDN}/Neutral-Wallet.png`,
291
+ tumbler: `${NEUTRAL_CDN}/Neutral-Tumbler.png`,
292
+ throw_: `${NEUTRAL_CDN}/Neutral-Blanket.png`,
293
293
  };
294
294
 
295
295
  export interface ThemeShowcaseProps {
@@ -39,19 +39,19 @@ import {neutralIconRegistry} from './icons';
39
39
  const neutralSyntax = defineSyntaxTheme({
40
40
  name: 'xds-neutral',
41
41
  tokens: {
42
- keyword: ['#700084', '#efa8ff'], // purple T30/T80
43
- string: ['#005600', '#a6d2a2'], // green (sat T30 / pastel T80)
44
- comment: ['#737373', '#a3a3a3'], // neutral
45
- number: ['#6e3500', '#ffb37f'], // orange
46
- function: ['#00458c', '#a0caff'], // blue T30/T80 H=255
47
- type: ['#700084', '#efa8ff'], // purple
48
- variable: ['#171717', '#e5e5e5'], // near-black / near-white
49
- operator: ['#737373', '#a3a3a3'], // neutral
50
- constant: ['#6e3500', '#ffb37f'], // orange
51
- tag: ['#89001a', '#ffaeaa'], // red
52
- attribute: ['#584400', '#eec12f'], // yellow
53
- property: ['#005348', '#83dac9'], // teal
54
- punctuation: ['#a3a3a3', '#525252'], // neutral
42
+ keyword: ['#700084', '#efa8ff'], // purple T30/T80
43
+ string: ['#005600', '#a6d2a2'], // green (sat T30 / pastel T80)
44
+ comment: ['#737373', '#a3a3a3'], // neutral
45
+ number: ['#6e3500', '#ffb37f'], // orange
46
+ function: ['#00458c', '#a0caff'], // blue T30/T80 H=255
47
+ type: ['#700084', '#efa8ff'], // purple
48
+ variable: ['#171717', '#e5e5e5'], // near-black / near-white
49
+ operator: ['#737373', '#a3a3a3'], // neutral
50
+ constant: ['#6e3500', '#ffb37f'], // orange
51
+ tag: ['#89001a', '#ffaeaa'], // red
52
+ attribute: ['#584400', '#eec12f'], // yellow
53
+ property: ['#005348', '#83dac9'], // teal
54
+ punctuation: ['#a3a3a3', '#525252'],// neutral
55
55
  background: ['#fafafa', '#0a0a0a'],
56
56
  },
57
57
  });
@@ -127,39 +127,39 @@ export const neutralTheme = defineTheme({
127
127
  // All values use the OKLCH Neutral tonal palette (chroma=0).
128
128
  // =========================================================================
129
129
  '--color-background-surface': ['#ffffff', '#262626'],
130
- '--color-background-body': ['#f1f1f1', '#1b1b1b'],
131
- '--color-background-card': ['#ffffff', '#1b1b1b'],
130
+ '--color-background-body': ['#f1f1f1', '#1b1b1b'],
131
+ '--color-background-card': ['#ffffff', '#1b1b1b'],
132
132
  '--color-background-popover': ['#ffffff', '#1b1b1b'],
133
- '--color-background-muted': ['#f1f1f1', '#1b1b1b'],
133
+ '--color-background-muted': ['#f1f1f1', '#1b1b1b'],
134
134
 
135
135
  // Accent + neutral surface tints (sit alongside backgrounds)
136
- '--color-accent': ['#262626', '#ebebeb'],
136
+ '--color-accent': ['#262626', '#ebebeb'],
137
137
  '--color-accent-muted': ['#f1f1f1', '#262626'],
138
- '--color-neutral': ['#0000000F', '#FFFFFF1A'],
138
+ '--color-neutral': ['#0000000F', '#FFFFFF1A'],
139
139
 
140
140
  // Overlays (modal scrims, hover/pressed tints)
141
- '--color-overlay': ['#00000080', '#000000CC'],
142
- '--color-overlay-hover': ['#0000000D', '#FFFFFF0D'],
141
+ '--color-overlay': ['#00000080', '#000000CC'],
142
+ '--color-overlay-hover': ['#0000000D', '#FFFFFF0D'],
143
143
  '--color-overlay-pressed': ['#0000001A', '#FFFFFF1A'],
144
144
 
145
145
  // Text
146
- '--color-text-primary': ['#171717', '#fafafa'],
146
+ '--color-text-primary': ['#171717', '#fafafa'],
147
147
  '--color-text-secondary': ['#737373', '#a3a3a3'],
148
- '--color-text-disabled': ['#a3a3a3', '#525252'],
149
- '--color-text-accent': ['#262626', '#ebebeb'],
150
- '--color-on-dark': '#ffffff',
151
- '--color-on-light': '#171717',
148
+ '--color-text-disabled': ['#a3a3a3', '#525252'],
149
+ '--color-text-accent': ['#262626', '#ebebeb'],
150
+ '--color-on-dark': '#ffffff',
151
+ '--color-on-light': '#171717',
152
152
  // Contrast: neutral accent is near-black (L) / near-white (D)
153
- '--color-on-accent': ['#ffffff', '#171717'],
153
+ '--color-on-accent': ['#ffffff', '#171717'],
154
154
  '--color-on-success': ['#ffffff', '#171717'],
155
- '--color-on-error': ['#ffffff', '#171717'],
155
+ '--color-on-error': ['#ffffff', '#171717'],
156
156
  '--color-on-warning': '#171717',
157
157
 
158
158
  // Icon
159
- '--color-icon-accent': ['#262626', '#ebebeb'],
160
- '--color-icon-primary': ['#171717', '#fafafa'],
159
+ '--color-icon-accent': ['#262626', '#ebebeb'],
160
+ '--color-icon-primary': ['#171717', '#fafafa'],
161
161
  '--color-icon-secondary': ['#737373', '#a3a3a3'],
162
- '--color-icon-disabled': ['#a3a3a3', '#525252'],
162
+ '--color-icon-disabled': ['#a3a3a3', '#525252'],
163
163
 
164
164
  // Status / Sentiment — dark mode follows the issue #2150 rubric:
165
165
  //
@@ -372,8 +372,8 @@ export const neutralTheme = defineTheme({
372
372
  // =========================================================================
373
373
  button: {
374
374
  'variant:destructive': {
375
- backgroundColor: 'var(--color-error-muted)', // locked pastel red bg
376
- color: 'var(--color-error)', // locked T30 red — matches banner/input error text
375
+ backgroundColor: 'var(--color-error-muted)', // locked pastel red bg
376
+ color: 'var(--color-error)', // locked T30 red — matches banner/input error text
377
377
  },
378
378
  },
379
379
 
@@ -482,37 +482,6 @@ export const neutralTheme = defineTheme({
482
482
  },
483
483
  },
484
484
 
485
- // =========================================================================
486
- // StatusDot — fill uses the SAME vivid stops as the filled semantic Badge
487
- // (and ProgressBar), so a dot and its badge read as one status language.
488
- //
489
- // The default component maps each variant to a raw semantic token
490
- // (--color-success / --color-error / --color-warning / --color-icon-
491
- // secondary), which in light mode are the dark T30/T40 stops meant to
492
- // sit as TEXT on a pastel surface — as a solid dot they read muddy
493
- // (dark green / maroon / brown). Redirect them to the badge fills.
494
- //
495
- // success → badge success bg (green T45 / dark-ramp T60)
496
- // warning → badge warning bg (yellow T85, same hex both modes)
497
- // error → badge error bg (red T55 / dark-ramp T60)
498
- // accent → badge info bg (blue T50 / dark-ramp T60) — the
499
- // StatusDot "accent" is the info/attention color, so it
500
- // pairs with the info badge rather than --color-accent
501
- // (near-black #262626, the darkest offender).
502
- //
503
- // `neutral` is intentionally NOT overridden: the neutral badge bg is a
504
- // near-invisible light gray (--color-background-gray #e5e5e5 / 10% white
505
- // wash), fine as a large pill but unreadable as an 8px dot. It keeps the
506
- // component default's visible mid-gray (--color-icon-secondary), which is
507
- // not among the "too dark" cases.
508
- // =========================================================================
509
- statusdot: {
510
- 'variant:success': {backgroundColor: 'light-dark(#198100, #64af4c)'},
511
- 'variant:warning': {backgroundColor: '#ffce2f'},
512
- 'variant:error': {backgroundColor: 'light-dark(#e33f4a, #ff705d)'},
513
- 'variant:accent': {backgroundColor: 'light-dark(#0074e2, #6d9cfe)'},
514
- },
515
-
516
485
  // =========================================================================
517
486
  // Banner — sits on a hue-tinted surface with colored text/icon:
518
487
  // Light: pastel T90 bg (pulled from --color-{X}-muted / --color-background-blue)
@@ -1,105 +0,0 @@
1
- # Authoring an Astryx Integration
2
-
3
- > **Status:** working notes. This should eventually move to the public wiki
4
- > alongside the rest of the integration-authoring guidance; it lives here for
5
- > now so it ships and is versioned with the CLI.
6
-
7
- An **Integration** is an npm package that contributes components, templates, and/or
8
- codemods to a consumer's design-system workflow. Consumers install the 3rd party
9
- package, add a line to their astryx.config file:
10
-
11
- ```js
12
- import {createConfig} from '@astryxdesign/cli/config';
13
-
14
- export default createConfig({
15
- integrations: ['@acme/astryx-widgets'],
16
- ...
17
- });
18
- ```
19
-
20
- Then the integration's components and templates will be surfaced alongside Astryx
21
- components in the Astryx CLI.
22
-
23
- ```sh
24
- astryx component AcmeCarousel --props
25
- astryx component --list --package @acme/astryx-widgets
26
- ```
27
-
28
- ## The Integration File
29
-
30
- In order to register your package as an Astryx Integration, create an
31
- `astryx.integration.{ts,mjs,js}` file as a sibling to your `package.json`. This file
32
- tells Astryx where to find your components, templates, codemods, etc.
33
-
34
- ```js
35
- // astryx.integration.{ts,mjs,js}
36
- import {createIntegration} from '@astryxdesign/cli/integration';
37
-
38
- export default createIntegration({
39
- components: './components',
40
- templates: './templates',
41
- codemods: './codemods',
42
- issuesUrl: 'https://github.com/acme/widgets/issues',
43
- });
44
- ```
45
-
46
- ## Components
47
-
48
- Your components themselves may be exported from your library as you see fit (consumers
49
- will still import them from your package) but Astryx CLI will look for a .doc.{ts,mjs,js}
50
- file with the same stem e.g. `AcmeCarousel.tsx` and `AcmeCarousel.doc.ts`.
51
-
52
- ```js
53
- // AcmeCarousel.doc.ts
54
- import {createComponentDoc} from '@astryxdesign/cli/doc';
55
-
56
- export default createComponentDoc({
57
- name: 'AcmeCarousel',
58
- description: '...',
59
- ...
60
- });
61
- ```
62
-
63
- ## Templates
64
-
65
- Templates are typically not exported from the package directly, but instead accessed
66
- via the Astryx CLI. Consumers can look through your templates and materialize them
67
- into their apps.
68
-
69
- You define a template with the `createPageTemplate` (for full pages) or `createBlockTemplate`
70
- (for smaller chunks). e.g. `AcmeLandingPage.tsx`, `AcmeLandingPage.template.ts`
71
-
72
- ```js
73
- // AcmeLandingPage.template.ts
74
- import {createPageTemplate} from '@astryxdesign/cli/template';
75
-
76
- export default createPageTemplate({
77
- ...
78
- });
79
- ```
80
-
81
- Note that, since the CLI needs access to the template source code, you need to make sure
82
- that it is included in your published package. This will also allow us to render previews
83
- of templates in the future by bundling your template into a doc site build.
84
-
85
- Typically, this is done via the package.json `exports` key.
86
-
87
- ```jsonc
88
- {
89
- "exports": {
90
- // ...
91
- "./templates/*.tsx": "./templates/*.tsx",
92
- },
93
- }
94
- ```
95
-
96
- In order to verify that it's working, you can test importing the template component like this:
97
-
98
- ```ts
99
- import('@acme/astryx-widgets/templates/AcmeLandingPage.tsx');
100
- ```
101
-
102
- Import **with the `.tsx` extension** — an extensionless specifier won't resolve
103
- under `moduleResolution: bundler`. The extensionful `"./templates/*.tsx"` export
104
- above is what lets that import type-check without consumers enabling
105
- `allowImportingTsExtensions`.
@@ -1,243 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /** @type {import('../../core/src/docs-types').ReferenceDoc} */
4
-
5
- export const docs = {
6
- name: 'internationalization',
7
- title: 'Internationalization',
8
- category: 'guide',
9
- description:
10
- 'Localize astryx component strings, provide translation catalogs, override default text, coexist with your own i18n library, swap languages at runtime, and test translations with the pseudo locale.',
11
-
12
- sections: [
13
- {
14
- title: 'Quick Start',
15
- category: 'guide',
16
- content: [
17
- {
18
- type: 'prose',
19
- text: 'Internationalization ships with `@astryxdesign/core`. There is nothing to install. Wrap your app in `<InternationalizationProvider>` and set a `locale` — astryx components pick up localized strings automatically.',
20
- },
21
- {
22
- type: 'code',
23
- lang: 'tsx',
24
- label: 'Wrap your app',
25
- code: `import {InternationalizationProvider} from '@astryxdesign/core';
26
-
27
- function App() {
28
- return (
29
- <InternationalizationProvider locale="en">
30
- <YourApp />
31
- </InternationalizationProvider>
32
- );
33
- }`,
34
- },
35
- {
36
- type: 'code',
37
- lang: 'tsx',
38
- label: 'Read strings inside a component',
39
- code: `import {useTranslator} from '@astryxdesign/core';
40
-
41
- function SaveButton() {
42
- const t = useTranslator();
43
- return <button>{t('@myapp.actions.save')}</button>;
44
- }`,
45
- },
46
- {
47
- type: 'prose',
48
- text: 'The hook is available to consumer components too, but using it is entirely optional — many teams keep their app strings on their existing i18n library (react-intl, i18next, next-intl, LinguiJS) and only use `useTranslator` when reading astryx keys. If you do route your own strings through it, we recommend namespacing them (`@myapp.*` or your npm scope) to keep them separated from `@astryx.*`, but this is a convention, not a requirement — the resolver treats every key as an opaque string.',
49
- },
50
- {
51
- type: 'prose',
52
- text: "Astryx ships translations only for English today. First-party translations for other locales are on the roadmap and coming soon — track https://github.com/facebook/astryx/issues/3641. In the meantime, if you want astryx UI translated into another locale, you can ship your own catalog through the `messages` prop (covered in the next section). If you're using `useTranslator` for your own strings, you'll want to ship your own catalog either way — astryx only carries the fallback for `@astryx.*` keys, not the ones you author.",
53
- },
54
- ],
55
- },
56
- {
57
- title: 'Providing locale catalogs',
58
- category: 'guide',
59
- content: [
60
- {
61
- type: 'prose',
62
- text: 'Astryx bundles only the English catalog today. To render in any other locale, provide a translation catalog through the `messages` prop and set `locale` accordingly. This matches how MUI, Ant Design, and AG Grid work — the consumer app supplies the catalogs it actually needs so unused translations stay out of the bundle.',
63
- },
64
- {
65
- type: 'code',
66
- lang: 'tsx',
67
- label: 'Add French',
68
- code: `import {InternationalizationProvider} from '@astryxdesign/core';
69
- import fr from './locales/astryx/fr.json';
70
-
71
- <InternationalizationProvider locale="fr" messages={{fr}}>
72
- <App />
73
- </InternationalizationProvider>;`,
74
- },
75
- {
76
- type: 'prose',
77
- text: "See `@astryxdesign/core/locales/en.json` for the full inventory of keys to translate. Copy it as the starting point — every key you translate replaces the English default; anything you omit falls back through the locale chain to English (e.g. `pt-BR` walks to `pt` then to shipped `en`), so a partial translation renders as a mix rather than empty text or raw key names.",
78
- },
79
- {
80
- type: 'prose',
81
- text: 'A community-maintained set of astryx translations is on the roadmap but not shipped yet. For now, consumer apps that ship in multiple languages own their astryx catalogs alongside their app catalogs. Contributions to a first-party set are welcome — track discussion at https://github.com/facebook/astryx/issues/3641.',
82
- },
83
- ],
84
- },
85
- {
86
- title: "Overriding astryx's default text",
87
- category: 'guide',
88
- content: [
89
- {
90
- type: 'prose',
91
- text: 'Use `overrides` to change individual strings without shipping a full catalog. Overrides are keyed by locale and merged on top of the built-in and user-supplied catalogs.',
92
- },
93
- {
94
- type: 'code',
95
- lang: 'tsx',
96
- label: 'Change one string in English',
97
- code: `<InternationalizationProvider
98
- locale="en"
99
- overrides={{en: {'@astryx.pagination.next': 'Next →'}}}
100
- >
101
- <App />
102
- </InternationalizationProvider>`,
103
- },
104
- {
105
- type: 'prose',
106
- text: 'Overrides win over both bundled English and any `messages` catalog for the same key. Use them for brand voice tweaks or one-off wording changes.',
107
- },
108
- ],
109
- },
110
- {
111
- title: 'Using astryx with your own i18n library',
112
- category: 'guide',
113
- content: [
114
- {
115
- type: 'prose',
116
- text: "Astryx components render astryx strings through astryx's provider. Consumer components render consumer strings through whatever i18n library you already use — react-intl, i18next, next-intl, LinguiJS, and so on. The two systems coexist and read from the same source of truth for the active locale.",
117
- },
118
- {
119
- type: 'code',
120
- lang: 'tsx',
121
- label: 'Astryx + react-intl side by side',
122
- code: `import {InternationalizationProvider} from '@astryxdesign/core';
123
- import {Selector} from '@astryxdesign/core/Selector';
124
- import {Button} from '@astryxdesign/core/Button';
125
- import {FormattedMessage, IntlProvider, useIntl} from 'react-intl';
126
- import astryxFr from './locales/astryx/fr.json'; // astryx's UI, in French
127
- import appFr from './locales/app/fr.json'; // your app strings, in French
128
-
129
- function Pricing() {
130
- // Consumer strings — resolved by react-intl.
131
- const intl = useIntl();
132
-
133
- return (
134
- <section>
135
- <h1><FormattedMessage id="pricing.heading" /></h1>
136
-
137
- {/* Astryx Selector — trigger placeholder, search-box placeholder,
138
- clear-button aria-label all resolved by
139
- <InternationalizationProvider>. Options come from react-intl. */}
140
- <Selector
141
- label={intl.formatMessage({id: 'pricing.region.label'})}
142
- options={[
143
- {value: 'na', label: intl.formatMessage({id: 'pricing.region.na'})},
144
- {value: 'eu', label: intl.formatMessage({id: 'pricing.region.eu'})},
145
- ]}
146
- hasSearch
147
- hasClear
148
- />
149
-
150
- <Button label={intl.formatMessage({id: 'pricing.cta.subscribe'})} />
151
- </section>
152
- );
153
- }
154
-
155
- export default function App() {
156
- return (
157
- // Same locale, two providers reading their own catalogs.
158
- <IntlProvider locale="fr" messages={appFr}>
159
- <InternationalizationProvider locale="fr" messages={{fr: astryxFr}}>
160
- <Pricing />
161
- </InternationalizationProvider>
162
- </IntlProvider>
163
- );
164
- }`,
165
- },
166
- {
167
- type: 'prose',
168
- text: 'Keep the two providers in sync on locale, and each library owns its own catalog. Astryx never sees your app strings, and your i18n library never sees astryx internals. Runtime locale swap works the same way — re-render both providers with a new `locale` prop and the whole tree updates live.',
169
- },
170
- {
171
- type: 'prose',
172
- text: "Single-catalog usage — where an external i18n runtime like react-intl or i18next resolves both your app strings AND astryx's strings through one provider — is on the roadmap via a `Translator` adapter. Track https://github.com/facebook/astryx/issues/4029. For now, run the two providers side by side as shown above.",
173
- },
174
- ],
175
- },
176
- {
177
- title: 'Runtime language swap',
178
- category: 'guide',
179
- content: [
180
- {
181
- type: 'prose',
182
- text: 'Re-render `<InternationalizationProvider>` with a new `locale` prop and every astryx string updates live. No reload, no separate API call.',
183
- },
184
- {
185
- type: 'code',
186
- lang: 'tsx',
187
- label: 'Toggle between locales',
188
- code: `const [locale, setLocale] = useState<'en' | 'fr'>('en');
189
-
190
- <InternationalizationProvider locale={locale} messages={{fr}}>
191
- <Button
192
- label={locale === 'en' ? 'Français' : 'English'}
193
- onClick={() => setLocale(l => (l === 'en' ? 'fr' : 'en'))}
194
- />
195
- <App />
196
- </InternationalizationProvider>;`,
197
- },
198
- {
199
- type: 'prose',
200
- text: "Persisting the user's choice (localStorage, cookie, URL segment, account setting) is up to the consumer. Astryx reads whatever `locale` you pass in.",
201
- },
202
- ],
203
- },
204
- {
205
- title: 'Testing your translations',
206
- category: 'guide',
207
- content: [
208
- {
209
- type: 'prose',
210
- text: 'Astryx generates a `pseudo` locale that wraps every string in `⟦…⟧` and replaces letters with accented look-alikes. Switching to it in development instantly reveals any astryx string that isn\'t going through the translator, plus any layout that breaks under longer text.',
211
- },
212
- {
213
- type: 'code',
214
- lang: 'tsx',
215
- label: 'Turn on pseudo-localization',
216
- code: `import pseudo from '@astryxdesign/core/locales/pseudo.json';
217
-
218
- <InternationalizationProvider locale="pseudo" messages={{pseudo}}>
219
- <App />
220
- </InternationalizationProvider>;`,
221
- },
222
- {
223
- type: 'prose',
224
- text: 'Any bare English text you still see on screen is a hardcoded string that needs to be routed through `useTranslator`.',
225
- },
226
- {
227
- type: 'prose',
228
- text: "Pseudoloc also has a subtle caveat worth knowing: the pseudo catalog is complete (astryx generates it from every shipped key), so a component using an astryx-shipped key will always render its pseudo version. Your handwritten translation catalogs, on the other hand, only cover the keys you translated — anything missing falls back to English. That means \"looks perfect in pseudo\" is not the same guarantee as \"looks perfect in French.\" Check each real locale by hand for coverage gaps.",
229
- },
230
- ],
231
- },
232
- {
233
- title: 'For contributors',
234
- category: 'guide',
235
- content: [
236
- {
237
- type: 'prose',
238
- text: "Astryx's own strings live in `packages/core/locales/en.json`. New user-facing strings must go through `useTranslator` — this is enforced by the `@astryx/no-hardcoded-i18n-string` ESLint rule. See the AI contribution guide for the alias-and-resolve pattern used when adding new keys.",
239
- },
240
- ],
241
- },
242
- ],
243
- };