@astryxdesign/cli 0.7.1 → 0.7.2-canary.198a7e3

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 (28) hide show
  1. package/api/component/component.test.mjs +357 -184
  2. package/api/template/table-filter-view-tabs.test.mjs +45 -0
  3. package/api/theme/build/build.core-on-demand.test.mjs +113 -0
  4. package/api/theme/build/build.d.mts +13 -13
  5. package/api/theme/build/build.mjs +72 -37
  6. package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
  7. package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
  8. package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
  9. package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
  10. package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
  11. package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
  12. package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
  13. package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
  14. package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
  15. package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
  16. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
  17. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
  18. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
  19. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
  20. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
  21. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
  22. package/assets/templates/pages/detail-page/page.tsx +3 -3
  23. package/assets/templates/pages/table-filter/page.tsx +3 -2
  24. package/assets/templates/pages/table-inbox/page.tsx +10 -8
  25. package/authoring/doctypes/base/type.ts +6 -0
  26. package/authoring/doctypes/component/component.doc.mjs +2 -2
  27. package/clients/cli/lib/component-format.mjs +5 -1
  28. package/package.json +10 -10
@@ -0,0 +1,113 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The theme build imports Core when a build runs, not when the CLI starts.
5
+ *
6
+ * The CLI loads the theme build module for every command, and Core's root
7
+ * entry pulls in all of Core and React. So a command that builds no theme must
8
+ * not ask for either, or `astryx --version` pays for them whenever a Core is
9
+ * installed. A resolve hook in a real subprocess records every request for
10
+ * Core or React and the module that made it, whether or not the request
11
+ * resolves.
12
+ */
13
+
14
+ import {afterAll, beforeAll, describe, expect, it} from 'vitest';
15
+ import {spawnSync} from 'node:child_process';
16
+ import * as fs from 'node:fs';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import {fileURLToPath, pathToFileURL} from 'node:url';
20
+
21
+ const BIN = fileURLToPath(
22
+ new URL('../../../clients/cli/bin/astryx.mjs', import.meta.url),
23
+ );
24
+
25
+ /** @type {string} */
26
+ let dir;
27
+ /** @type {string} */
28
+ let register;
29
+ /** @type {string} */
30
+ let log;
31
+
32
+ beforeAll(() => {
33
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-core-on-demand-'));
34
+ log = path.join(dir, 'requests.jsonl');
35
+ const hooks = path.join(dir, 'hooks.mjs');
36
+ fs.writeFileSync(
37
+ hooks,
38
+ [
39
+ "import {appendFileSync} from 'node:fs';",
40
+ `const LOG = ${JSON.stringify(log)};`,
41
+ 'const WATCHED = /^(?:@astryxdesign\\/core|react|react-dom)(?:\\/|$)/;',
42
+ 'export async function resolve(specifier, context, nextResolve) {',
43
+ ' if (WATCHED.test(specifier)) {',
44
+ ' const parent = context.parentURL ?? null;',
45
+ " appendFileSync(LOG, JSON.stringify({specifier, parent}) + '\\n');",
46
+ ' }',
47
+ ' return nextResolve(specifier, context);',
48
+ '}',
49
+ '',
50
+ ].join('\n'),
51
+ );
52
+ register = path.join(dir, 'register.mjs');
53
+ fs.writeFileSync(
54
+ register,
55
+ `import {register} from 'node:module';\nregister(${JSON.stringify(pathToFileURL(hooks).href)});\n`,
56
+ );
57
+ // A plain theme object: the file itself never imports Core, so a request for
58
+ // Core can only come from the build.
59
+ fs.writeFileSync(
60
+ path.join(dir, 'ocean.mjs'),
61
+ "export default {name: 'ocean', tokens: {'--color-bg': '#0a0a0a'}};\n",
62
+ );
63
+ });
64
+
65
+ afterAll(() => {
66
+ fs.rmSync(dir, {recursive: true, force: true});
67
+ });
68
+
69
+ /**
70
+ * Run the CLI and return each Core or React specifier it asked for, mapped to
71
+ * the first module that asked.
72
+ * @param {string[]} args
73
+ * @returns {{status: number | null, requested: Record<string, string | null>}}
74
+ */
75
+ function run(args) {
76
+ fs.rmSync(log, {force: true});
77
+ const res = spawnSync(
78
+ process.execPath,
79
+ ['--import', pathToFileURL(register).href, BIN, ...args],
80
+ {cwd: dir, encoding: 'utf-8', timeout: 20_000},
81
+ );
82
+ /** @type {Record<string, string | null>} */
83
+ const requested = {};
84
+ const lines = fs.existsSync(log)
85
+ ? fs.readFileSync(log, 'utf-8').split('\n').filter(Boolean)
86
+ : [];
87
+ for (const line of lines) {
88
+ const {specifier, parent} = JSON.parse(line);
89
+ if (!(specifier in requested)) requested[specifier] = parent;
90
+ }
91
+ return {status: res.status, requested};
92
+ }
93
+
94
+ describe('theme build imports Core on demand', () => {
95
+ it('astryx --version asks for neither Core nor React', () => {
96
+ const {status, requested} = run(['--version']);
97
+ expect(status).toBe(0);
98
+ expect(requested).toEqual({});
99
+ });
100
+
101
+ it('theme build imports Core from the theme build module', () => {
102
+ const {requested} = run([
103
+ 'theme',
104
+ 'build',
105
+ 'ocean.mjs',
106
+ '--check',
107
+ '--json',
108
+ ]);
109
+ expect(requested['@astryxdesign/core/theme']).toMatch(
110
+ /\/api\/theme\/build\/build\.mjs$/,
111
+ );
112
+ });
113
+ });
@@ -163,6 +163,19 @@ export function themeBuildFamily(files: string[], options: {
163
163
  checked?: undefined;
164
164
  };
165
165
  }>;
166
+ /**
167
+ * The bindings one Core provides: the namespaces interception spreads, the
168
+ * functions the build calls, and why the import failed, if it did.
169
+ */
170
+ export type CoreBindings = {
171
+ themeModule: any;
172
+ rootModule: any;
173
+ importError: any;
174
+ defineTheme: any;
175
+ generateThemeRulesSplit: any;
176
+ generateOnMediaCSS: any;
177
+ generateAdaptationCSS: any;
178
+ };
166
179
  /**
167
180
  * How one `prop:value` pair on a component target is classified — the single
168
181
  * vocabulary both the root and adaptation paths reason in.
@@ -210,16 +223,3 @@ export type ThemeBuildTrailer = {
210
223
  */
211
224
  fontNotices: string[];
212
225
  };
213
- /**
214
- * The bindings one Core provides: the namespaces interception spreads, the
215
- * functions the build calls, and why the import failed, if it did.
216
- */
217
- export type CoreBindings = {
218
- themeModule: any;
219
- rootModule: any;
220
- importError: any;
221
- defineTheme: any;
222
- generateThemeRulesSplit: any;
223
- generateOnMediaCSS: any;
224
- generateAdaptationCSS: any;
225
- };
@@ -37,6 +37,10 @@
37
37
  * general compatibility scheme for every export an arbitrary older core might
38
38
  * lack.
39
39
  *
40
+ * Core is imported on first use, never when this module loads: the CLI loads
41
+ * this module for every command, and Core's root entry pulls in all of Core
42
+ * and React.
43
+ *
40
44
  * With `{check: true}`, it compiles the same outputs in memory but writes
41
45
  * nothing: it compares each generated file against what is on disk (ignoring
42
46
  * only the volatile `@generated` `Command:` line) and returns a
@@ -91,6 +95,8 @@ import {resolveIconImports} from './icon-imports.mjs';
91
95
  // action). A built, resolvable `@astryxdesign/core` is a hard requirement.
92
96
  // A built, resolvable `@astryxdesign/core` is a hard requirement. These are
93
97
  // populated from a dynamic import (a runtime boundary), so `any` is intentional.
98
+ // That import runs the first time a build needs Core (see `loadCliCore`), not
99
+ // when this module loads.
94
100
  //
95
101
  // The CLI and core are independently versioned optional peers, so this import
96
102
  // can succeed against a core OLDER than the CLI. Only the exports every theme
@@ -120,27 +126,6 @@ import {resolveIconImports} from './icon-imports.mjs';
120
126
  */
121
127
  /** @type {any} */ let _coreRootModule = null;
122
128
  /** @type {any} */ let _coreImportError = null;
123
- try {
124
- const coreTheme = await import('@astryxdesign/core/theme');
125
- _coreThemeModule = coreTheme;
126
- _defineTheme = coreTheme.defineTheme;
127
- _generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
128
- _generateOnMediaCSS = coreTheme.generateOnMediaCSS;
129
- _generateAdaptationCSS = coreTheme.generateAdaptationCSS;
130
- try {
131
- _coreRootModule = await import('@astryxdesign/core');
132
- } catch {
133
- // A core without a usable root entry still builds themes; interception
134
- // falls back to the theme namespace for the root specifier.
135
- }
136
- } catch (e) {
137
- // Capture the reason so the theme action can surface a precise, actionable
138
- // error. We don't throw here: this module is imported eagerly by the CLI
139
- // entrypoint for every command, and a throw at load time would break
140
- // unrelated commands (the entry wraps loads in try/catch and degrades the
141
- // command to a stub). The hard failure happens when `theme build` runs.
142
- _coreImportError = e;
143
- }
144
129
 
145
130
  /**
146
131
  * The bindings one Core provides: the namespaces interception spreads, the
@@ -157,19 +142,65 @@ try {
157
142
  */
158
143
 
159
144
  /**
160
- * The bindings exactly as the CLI's own import left them, kept so each build
161
- * can choose between them and the project's installed Core.
162
- * @type {CoreBindings}
145
+ * Import the CLI's own Core: the `@astryxdesign/core` this module resolves.
146
+ * Never throws. A failed import is kept as `importError`, so the build can
147
+ * surface a precise, actionable error when it runs.
148
+ * @returns {Promise<CoreBindings>}
163
149
  */
164
- const _cliCore = {
165
- themeModule: _coreThemeModule,
166
- rootModule: _coreRootModule,
167
- importError: _coreImportError,
168
- defineTheme: _defineTheme,
169
- generateThemeRulesSplit: _generateThemeRulesSplit,
170
- generateOnMediaCSS: _generateOnMediaCSS,
171
- generateAdaptationCSS: _generateAdaptationCSS,
172
- };
150
+ async function importCliCore() {
151
+ /** @type {CoreBindings} */
152
+ const core = {
153
+ themeModule: null,
154
+ rootModule: null,
155
+ importError: null,
156
+ defineTheme: null,
157
+ generateThemeRulesSplit: null,
158
+ generateOnMediaCSS: null,
159
+ generateAdaptationCSS: null,
160
+ };
161
+ try {
162
+ const coreTheme = await import('@astryxdesign/core/theme');
163
+ core.themeModule = coreTheme;
164
+ core.defineTheme = coreTheme.defineTheme;
165
+ core.generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
166
+ core.generateOnMediaCSS = coreTheme.generateOnMediaCSS;
167
+ core.generateAdaptationCSS = coreTheme.generateAdaptationCSS;
168
+ try {
169
+ core.rootModule = await import('@astryxdesign/core');
170
+ } catch {
171
+ // A core without a usable root entry still builds themes; interception
172
+ // falls back to the theme namespace for the root specifier.
173
+ }
174
+ } catch (e) {
175
+ // Capture the reason so the theme action can surface a precise, actionable
176
+ // error. The hard failure happens when `theme build` runs.
177
+ core.importError = e;
178
+ }
179
+ return core;
180
+ }
181
+
182
+ /**
183
+ * The CLI's own Core, imported once, the first time a build needs it. The CLI
184
+ * loads this module for every command, and Core's root entry loads all of Core
185
+ * and React, so an import at module load would make every command
186
+ * (`--version` included) pay for that whenever a Core resolves.
187
+ * @type {Promise<CoreBindings> | null}
188
+ */
189
+ let _cliCorePromise = null;
190
+
191
+ /**
192
+ * The CLI's own Core, kept so each build can choose between it and the
193
+ * project's installed Core. The first call also points the build at it, so a
194
+ * step that runs before any build has chosen a Core reads the CLI's own.
195
+ * @returns {Promise<CoreBindings>}
196
+ */
197
+ function loadCliCore() {
198
+ _cliCorePromise ??= importCliCore().then(core => {
199
+ setCore(core);
200
+ return core;
201
+ });
202
+ return _cliCorePromise;
203
+ }
173
204
 
174
205
  /**
175
206
  * Point the build at one Core: the module-level bindings every step reads.
@@ -248,13 +279,14 @@ function realOrSelf(file) {
248
279
  * repository, a bare directory), the same Core, or one that does not load.
249
280
  *
250
281
  * @param {string} cwd
282
+ * @param {CoreBindings} cliCore - The CLI's own Core, from {@link loadCliCore}.
251
283
  * @returns {Promise<CoreBindings | null>}
252
284
  */
253
- async function loadProjectCore(cwd) {
285
+ async function loadProjectCore(cwd, cliCore) {
254
286
  const dir = findInstalledPackage(cwd, '@astryxdesign/core');
255
287
  const themeFile = dir ? importTarget(dir, './theme') : null;
256
288
  if (!dir || !themeFile) return null;
257
- if (_cliCore.themeModule) {
289
+ if (cliCore.themeModule) {
258
290
  try {
259
291
  const own = fileURLToPath(
260
292
  import.meta.resolve('@astryxdesign/core/theme'),
@@ -301,9 +333,10 @@ const _projectCores = new Map();
301
333
  * @param {string} cwd
302
334
  */
303
335
  async function selectCore(cwd) {
336
+ const cliCore = await loadCliCore();
304
337
  if (!_projectCores.has(cwd))
305
- _projectCores.set(cwd, await loadProjectCore(cwd));
306
- setCore(_projectCores.get(cwd) ?? _cliCore);
338
+ _projectCores.set(cwd, await loadProjectCore(cwd, cliCore));
339
+ setCore(_projectCores.get(cwd) ?? cliCore);
307
340
  }
308
341
 
309
342
  /**
@@ -1694,6 +1727,8 @@ export async function validateThemePrivateInputs(
1694
1727
  );
1695
1728
  }
1696
1729
 
1730
+ // The CLI's own Core, unless a build in this process already chose one.
1731
+ await loadCliCore();
1697
1732
  const interception = interceptCore(_coreThemeModule, _coreRootModule);
1698
1733
  let theme;
1699
1734
  try {
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ name: 'Edit form with footer actions',
7
+ displayName: 'Edit form with footer actions',
8
+ description:
9
+ 'Compose a Layout with DrawerHeader, the fields in LayoutContent, and Cancel and Save in a pinned LayoutFooter. purpose="form" keeps Escape but ignores scrim clicks, so a stray click outside does not discard edits.',
10
+ exampleFor: 'Drawer',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: [
14
+ 'Drawer',
15
+ 'DrawerHeader',
16
+ 'Button',
17
+ 'Layout',
18
+ 'LayoutContent',
19
+ 'LayoutFooter',
20
+ 'HStack',
21
+ 'VStack',
22
+ 'TextInput',
23
+ ],
24
+ };
@@ -0,0 +1,62 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @input Controlled open state and two editable fields
7
+ * @output A form drawer with a header, scrolling fields, and pinned footer
8
+ * actions; purpose="form" keeps Escape but ignores scrim clicks
9
+ * @position Copyable Drawer example
10
+ */
11
+
12
+ import {useState} from 'react';
13
+ import {Drawer, DrawerHeader} from '@astryxdesign/core/Drawer';
14
+ import {Button} from '@astryxdesign/core/Button';
15
+ import {Layout, LayoutContent, LayoutFooter} from '@astryxdesign/core/Layout';
16
+ import {HStack, VStack} from '@astryxdesign/core/Stack';
17
+ import {TextInput} from '@astryxdesign/core/TextInput';
18
+
19
+ export default function DrawerForm() {
20
+ const [isOpen, setIsOpen] = useState(false);
21
+ const [name, setName] = useState('web-prod-04');
22
+ const [owner, setOwner] = useState('Platform team');
23
+
24
+ return (
25
+ <>
26
+ <Button label="Edit host" onClick={() => setIsOpen(true)} />
27
+ <Drawer
28
+ isOpen={isOpen}
29
+ onOpenChange={setIsOpen}
30
+ label="Edit host"
31
+ purpose="form">
32
+ <Layout
33
+ header={<DrawerHeader title="Edit host" onOpenChange={setIsOpen} />}
34
+ content={
35
+ <LayoutContent>
36
+ <VStack gap={4}>
37
+ <TextInput label="Name" value={name} onChange={setName} />
38
+ <TextInput label="Owner" value={owner} onChange={setOwner} />
39
+ </VStack>
40
+ </LayoutContent>
41
+ }
42
+ footer={
43
+ <LayoutFooter>
44
+ <HStack gap={2} hAlign="end">
45
+ <Button
46
+ label="Cancel"
47
+ variant="secondary"
48
+ onClick={() => setIsOpen(false)}
49
+ />
50
+ <Button
51
+ label="Save"
52
+ variant="primary"
53
+ onClick={() => setIsOpen(false)}
54
+ />
55
+ </HStack>
56
+ </LayoutFooter>
57
+ }
58
+ />
59
+ </Drawer>
60
+ </>
61
+ );
62
+ }
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ name: 'Modal or non-modal (hasScrim)',
7
+ displayName: 'Modal or non-modal (hasScrim)',
8
+ description:
9
+ 'The default modal drawer dims the page, traps focus, and closes on a scrim click. With hasScrim={false}, the drawer has no scrim or focus trap and leaves the page interactive.',
10
+ exampleFor: 'Drawer',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: [
14
+ 'Drawer',
15
+ 'Button',
16
+ 'Layout',
17
+ 'LayoutContent',
18
+ 'HStack',
19
+ 'DrawerHeader',
20
+ 'Text',
21
+ ],
22
+ };
@@ -0,0 +1,68 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @input Separate controlled states for modal and non-modal drawers
7
+ * @output A comparison of hasScrim's two presentations
8
+ * @position Copyable Drawer example
9
+ */
10
+
11
+ import {useState} from 'react';
12
+ import {Drawer, DrawerHeader} from '@astryxdesign/core/Drawer';
13
+ import {Button} from '@astryxdesign/core/Button';
14
+ import {Layout, LayoutContent} from '@astryxdesign/core/Layout';
15
+ import {HStack} from '@astryxdesign/core/Stack';
16
+ import {Text} from '@astryxdesign/core/Text';
17
+
18
+ export default function DrawerScrim() {
19
+ const [openModal, setOpenModal] = useState(false);
20
+ const [openPanel, setOpenPanel] = useState(false);
21
+
22
+ return (
23
+ <>
24
+ <HStack gap={2}>
25
+ <Button label="Open modal drawer" onClick={() => setOpenModal(true)} />
26
+ <Button
27
+ label="Open non-modal drawer"
28
+ onClick={() => setOpenPanel(true)}
29
+ />
30
+ </HStack>
31
+ <Drawer
32
+ isOpen={openModal}
33
+ onOpenChange={setOpenModal}
34
+ label="Edit details">
35
+ <Layout
36
+ header={
37
+ <DrawerHeader title="Edit details" onOpenChange={setOpenModal} />
38
+ }
39
+ content={
40
+ <LayoutContent>
41
+ <Text type="body">
42
+ The scrim blocks the page behind this modal drawer.
43
+ </Text>
44
+ </LayoutContent>
45
+ }
46
+ />
47
+ </Drawer>
48
+ <Drawer
49
+ isOpen={openPanel}
50
+ onOpenChange={setOpenPanel}
51
+ label="Inspector"
52
+ hasScrim={false}>
53
+ <Layout
54
+ header={
55
+ <DrawerHeader title="Inspector" onOpenChange={setOpenPanel} />
56
+ }
57
+ content={
58
+ <LayoutContent>
59
+ <Text type="body">
60
+ The page behind this non-modal drawer stays interactive.
61
+ </Text>
62
+ </LayoutContent>
63
+ }
64
+ />
65
+ </Drawer>
66
+ </>
67
+ );
68
+ }
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ name: 'Basic',
7
+ displayName: 'Basic',
8
+ description:
9
+ 'Open a modal drawer from a single trigger. The scrim dims the page; Escape, a scrim click, or the header close button closes it, and focus returns to the trigger.',
10
+ exampleFor: 'Drawer',
11
+ isReady: true,
12
+ isShowcase: true,
13
+ aspectRatio: 16 / 9,
14
+ componentsUsed: [
15
+ 'Drawer',
16
+ 'Button',
17
+ 'Layout',
18
+ 'LayoutContent',
19
+ 'DrawerHeader',
20
+ 'Text',
21
+ ],
22
+ };
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @input Controlled open state for a modal Drawer
7
+ * @output A single-trigger drawer with a scrim and a DrawerHeader close button
8
+ * @position Drawer's docsite showcase and copyable CLI block
9
+ */
10
+
11
+ import {useState} from 'react';
12
+ import {Drawer, DrawerHeader} from '@astryxdesign/core/Drawer';
13
+ import {Button} from '@astryxdesign/core/Button';
14
+ import {Layout, LayoutContent} from '@astryxdesign/core/Layout';
15
+ import {Text} from '@astryxdesign/core/Text';
16
+
17
+ export default function DrawerShowcase() {
18
+ const [isOpen, setIsOpen] = useState(false);
19
+
20
+ return (
21
+ <>
22
+ <Button label="Open drawer" onClick={() => setIsOpen(true)} />
23
+ <Drawer
24
+ isOpen={isOpen}
25
+ onOpenChange={setIsOpen}
26
+ label="Details"
27
+ width={360}>
28
+ <Layout
29
+ header={<DrawerHeader title="Details" onOpenChange={setIsOpen} />}
30
+ content={
31
+ <LayoutContent>
32
+ <Text type="body">
33
+ Close with Escape, the scrim, or the close button.
34
+ </Text>
35
+ </LayoutContent>
36
+ }
37
+ />
38
+ </Drawer>
39
+ </>
40
+ );
41
+ }
@@ -0,0 +1,21 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ name: 'Slide in from the start edge',
7
+ displayName: 'Slide in from the start edge',
8
+ description:
9
+ 'Set side="start" to open from the inline start edge: left in LTR and right in RTL. The default end edge follows the inspector convention.',
10
+ exampleFor: 'Drawer',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: [
14
+ 'Drawer',
15
+ 'Button',
16
+ 'Layout',
17
+ 'LayoutContent',
18
+ 'DrawerHeader',
19
+ 'Text',
20
+ ],
21
+ };
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @input Controlled open state and the logical start edge
7
+ * @output A Drawer that opens from the start side of the viewport
8
+ * @position Copyable Drawer example
9
+ */
10
+
11
+ import {useState} from 'react';
12
+ import {Drawer, DrawerHeader} from '@astryxdesign/core/Drawer';
13
+ import {Button} from '@astryxdesign/core/Button';
14
+ import {Layout, LayoutContent} from '@astryxdesign/core/Layout';
15
+ import {Text} from '@astryxdesign/core/Text';
16
+
17
+ export default function DrawerStart() {
18
+ const [isOpen, setIsOpen] = useState(false);
19
+
20
+ return (
21
+ <>
22
+ <Button label="Open start drawer" onClick={() => setIsOpen(true)} />
23
+ <Drawer
24
+ isOpen={isOpen}
25
+ onOpenChange={setIsOpen}
26
+ label="Navigation"
27
+ side="start">
28
+ <Layout
29
+ header={<DrawerHeader title="Navigation" onOpenChange={setIsOpen} />}
30
+ content={
31
+ <LayoutContent>
32
+ <Text type="body">
33
+ The start edge follows the page's writing direction.
34
+ </Text>
35
+ </LayoutContent>
36
+ }
37
+ />
38
+ </Drawer>
39
+ </>
40
+ );
41
+ }
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ name: 'Width budget: pixels or any CSS length',
7
+ displayName: 'Width budget: pixels or any CSS length',
8
+ description:
9
+ 'Compare a numeric pixel width with rem and percentage lengths. The width budget also caps the drawer on mobile.',
10
+ exampleFor: 'Drawer',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: [
14
+ 'Drawer',
15
+ 'Button',
16
+ 'Layout',
17
+ 'LayoutContent',
18
+ 'HStack',
19
+ 'DrawerHeader',
20
+ 'Text',
21
+ ],
22
+ };