@astryxdesign/cli 0.7.5-canary.a17ee0a → 0.7.5-canary.a73f030

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.
@@ -0,0 +1,130 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import transform from '../migrate-codeblock-tokenizer-to-language.mjs';
5
+
6
+ async function applyTransform(source) {
7
+ const jscodeshift = (await import('jscodeshift')).default;
8
+ const j = jscodeshift.withParser('tsx');
9
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
10
+ return transform({source, path: 'test.tsx'}, api) ?? source;
11
+ }
12
+
13
+ /** Collapse whitespace so assertions ignore the printer's line breaks. */
14
+ const flat = text => text.replace(/\s+/g, ' ');
15
+
16
+ describe('migrate-codeblock-tokenizer-to-language', () => {
17
+ it('rewrites tokenizer beside a static language to a custom language', async () => {
18
+ const output = flat(
19
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
20
+ const a = <CodeBlock code={src} language="zig" tokenizer={zigTokens} />;
21
+ const b = <CodeBlock code={src} language={'nim'} tokenizer={(c) => tokens(c)} />;`),
22
+ );
23
+
24
+ expect(output).not.toContain('tokenizer=');
25
+ expect(output).toContain(
26
+ "import { CodeBlock, createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
27
+ );
28
+ expect(output).toContain(
29
+ "language={zigTokens ? createCodeLanguage({ name: 'zig', identifiers: ['zig'], tokenize: zigTokens }) : 'zig'}",
30
+ );
31
+ expect(output).toContain(
32
+ "language={createCodeLanguage({ name: 'nim', identifiers: ['nim'], tokenize: (c) => tokens(c) })}",
33
+ );
34
+ });
35
+
36
+ it('adds the import beside a root-package import and follows aliases', async () => {
37
+ const output = flat(
38
+ await applyTransform(`import {CodeBlock as Code} from '@astryxdesign/core';
39
+ const a = <Code code={src} language="zig" tokenizer={zigTokens} />;`),
40
+ );
41
+
42
+ expect(output).toContain(
43
+ "import { createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
44
+ );
45
+ expect(output).toContain("createCodeLanguage({ name: 'zig'");
46
+ });
47
+
48
+ it('adds a separate import beside a namespace import', async () => {
49
+ const output =
50
+ await applyTransform(`import * as CB from '@astryxdesign/core/CodeBlock';
51
+ const a = <CB.CodeBlock code={src} language="zig" tokenizer={zigTokens} />;`);
52
+ expect(output).toContain(
53
+ "import * as CB from '@astryxdesign/core/CodeBlock';",
54
+ );
55
+ expect(flat(output)).toContain(
56
+ "import { createCodeLanguage } from '@astryxdesign/core/CodeBlock';",
57
+ );
58
+ const jscodeshift = (await import('jscodeshift')).default;
59
+ expect(() => jscodeshift.withParser('tsx')(output)).not.toThrow();
60
+ });
61
+
62
+ it('guards a name or property that may be undefined', async () => {
63
+ const output = flat(
64
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
65
+ const a = <CodeBlock code={src} language="zig" tokenizer={props.tokenizer} />;`),
66
+ );
67
+ expect(output).toContain(
68
+ "language={props.tokenizer ? createCodeLanguage({ name: 'zig', identifiers: ['zig'], tokenize: props.tokenizer }) : 'zig'}",
69
+ );
70
+ });
71
+
72
+ it('imports under a free alias when the file binds the name already', async () => {
73
+ const fromLocal = flat(
74
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
75
+ import {createCodeLanguage} from './my-languages';
76
+ const a = <CodeBlock code={src} language="zig" tokenizer={(c) => t(c)} />;`),
77
+ );
78
+ expect(fromLocal).toContain(
79
+ "import { CodeBlock, createCodeLanguage as createCodeLanguage2 } from '@astryxdesign/core/CodeBlock';",
80
+ );
81
+ expect(fromLocal).toContain(
82
+ "import {createCodeLanguage} from './my-languages';",
83
+ );
84
+ expect(fromLocal).toContain("language={createCodeLanguage2({ name: 'zig'");
85
+
86
+ const fromFunction = flat(
87
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
88
+ function createCodeLanguage() {}
89
+ const a = <CodeBlock code={src} language="zig" tokenizer={(c) => t(c)} />;`),
90
+ );
91
+ expect(fromFunction).toContain('createCodeLanguage as createCodeLanguage2');
92
+ const jscodeshift = (await import('jscodeshift')).default;
93
+ const parse = jscodeshift.withParser('tsx');
94
+ expect(() => parse(fromLocal)).not.toThrow();
95
+ });
96
+
97
+ it('reports a tokenizer value it cannot read twice, naming the tokenizer', async () => {
98
+ const output =
99
+ await applyTransform(`import {CodeBlock} from '@astryxdesign/core/CodeBlock';
100
+ const a = <CodeBlock code={src} language="zig" tokenizer={registry.get('zig').tokenize} />;
101
+ const b = <CodeBlock code={src} language="zig" tokenizer={enabled ? t : undefined} />;`);
102
+ expect(output.match(/this tokenizer value is computed/g)).toHaveLength(2);
103
+ expect(output).not.toContain('the language here is computed');
104
+ expect(output).toContain("tokenizer={registry.get('zig').tokenize}");
105
+ });
106
+
107
+ it('reports what it cannot prove and leaves it unchanged', async () => {
108
+ const source = `import {CodeBlock} from '@astryxdesign/core/CodeBlock';
109
+ const a = <CodeBlock code={src} language={lang} tokenizer={t} />;
110
+ const b = <CodeBlock code={src} tokenizer={t} />;
111
+ const c = <CodeBlock code={src} language="plaintext" tokenizer={t} />;
112
+ const d = <CodeBlock {...rest} code={src} language="zig" tokenizer={t} />;
113
+ const e = <CodeBlock code={src} language="zig" tokenizer={enabled ? t : undefined} />;
114
+ const f = <CodeBlock code={src} language="zig" tokenizer={enabled && t} />;`;
115
+ const output = await applyTransform(source);
116
+
117
+ expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(6);
118
+ expect(output.match(/tokenizer=\{t\}/g)).toHaveLength(4);
119
+ expect(output).toContain('tokenizer={enabled ? t : undefined}');
120
+ expect(output).toContain('tokenizer={enabled && t}');
121
+ expect(output).not.toMatch(/import \{[^}]*createCodeLanguage/);
122
+ expect(await applyTransform(output)).toBe(output);
123
+ });
124
+
125
+ it('leaves files without CodeBlock tokenizer alone', async () => {
126
+ const source = `import {CodeBlock} from '@astryxdesign/core/CodeBlock';
127
+ const a = <CodeBlock code={src} language="ts" />;`;
128
+ expect(await applyTransform(source)).toBe(source);
129
+ });
130
+ });
@@ -7,4 +7,14 @@
7
7
  * this file into the resolved version folder.
8
8
  */
9
9
 
10
- export default [];
10
+ import migrateCodeBlockTokenizerToLanguage, {
11
+ meta as migrateCodeBlockTokenizerToLanguageMeta,
12
+ } from './migrate-codeblock-tokenizer-to-language.mjs';
13
+
14
+ export default [
15
+ {
16
+ name: 'migrate-codeblock-tokenizer-to-language',
17
+ transform: migrateCodeBlockTokenizerToLanguage,
18
+ meta: migrateCodeBlockTokenizerToLanguageMeta,
19
+ },
20
+ ];
@@ -0,0 +1,315 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: migrate CodeBlock tokenizer to a custom language value
5
+ *
6
+ * `tokenizer={fn}` beside a static `language="x"` other than `plaintext`
7
+ * becomes `language={createCodeLanguage({name: 'x', identifiers: ['x'],
8
+ * tokenize: fn})}` (`component:CodeBlock` FR13). The custom language paints
9
+ * with the same function, labels `x`, and reflects `data-language="x"`, so the
10
+ * block looks the same. `createCodeLanguage` is imported from
11
+ * `@astryxdesign/core/CodeBlock` when the file does not import it yet, under
12
+ * a free alias when the file already binds the name to something else. A
13
+ * `tokenizer` that is a name or a call-free property may be undefined at run
14
+ * time, so it is guarded: `fn ? createCodeLanguage({...}) : 'x'`.
15
+ *
16
+ * Built on the shared `transformProp` helper, so it does not follow
17
+ * variables, helpers, wrappers, or types. Where a CodeBlock writes
18
+ * `tokenizer` but the codemod cannot prove the result, it keeps the old prop
19
+ * and leaves a TODO instead of guessing: a computed or missing `language`, a
20
+ * `tokenizer` value that is neither a function literal nor a name or property
21
+ * (a name or property is guarded with `fn ? createCodeLanguage(...) : 'x'`,
22
+ * since it may be undefined), a
23
+ * `plaintext` language (which shows no label today, while a language value
24
+ * does), and any CodeBlock that also spreads props. The deprecated prop keeps
25
+ * working there. Comments are the codemod's only report channel, and each is
26
+ * added once, so a second run changes nothing.
27
+ */
28
+
29
+ import {transformProp} from '../../transform-prop.mjs';
30
+
31
+ export const meta = {
32
+ title: 'Migrate CodeBlock tokenizer to a custom language',
33
+ description:
34
+ 'Replaces `tokenizer={fn}` beside a static `language="x"` with ' +
35
+ "`language={createCodeLanguage({name: 'x', identifiers: ['x'], tokenize: fn})}`. " +
36
+ 'Keeps the old prop with a TODO where the language is computed, missing, ' +
37
+ 'or `plaintext`, and where the CodeBlock also spreads props; the ' +
38
+ 'deprecated prop still works there.',
39
+ };
40
+
41
+ const OLD_NAME = 'tokenizer';
42
+ const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
43
+ const CODEBLOCK_SOURCE = '@astryxdesign/core/CodeBlock';
44
+ const COMPONENT_PROPS = new Map([['CodeBlock', new Set([OLD_NAME])]]);
45
+
46
+ const UNPROVEN_COMMENT =
47
+ ' TODO(astryx upgrade): tokenizer is deprecated. Pass ' +
48
+ 'language={createCodeLanguage({name, identifiers, tokenize})} instead, ' +
49
+ 'with this function as tokenize; the language here is computed, missing, ' +
50
+ 'or plaintext, so it was left unchanged. ';
51
+ const VALUE_COMMENT =
52
+ ' TODO(astryx upgrade): tokenizer is deprecated. Pass ' +
53
+ 'language={createCodeLanguage({name, identifiers, tokenize})} instead; ' +
54
+ 'this tokenizer value is computed (not a function, a name, or a ' +
55
+ 'call-free property), so it was left unchanged. ';
56
+ const SPREAD_COMMENT =
57
+ ' TODO(astryx upgrade): tokenizer is deprecated, but this CodeBlock also ' +
58
+ 'spreads props that may set language or tokenizer, so it was left ' +
59
+ 'unchanged. Pass language={createCodeLanguage({name, identifiers, ' +
60
+ 'tokenize})} by hand. ';
61
+
62
+ const TYPE_WRAPPERS = new Set([
63
+ 'TSAsExpression',
64
+ 'TSSatisfiesExpression',
65
+ 'TSTypeAssertion',
66
+ 'TSNonNullExpression',
67
+ 'TypeCastExpression',
68
+ 'ParenthesizedExpression',
69
+ ]);
70
+
71
+ /** @param {any} node */
72
+ function unwrap(node) {
73
+ let current = node;
74
+ while (current && TYPE_WRAPPERS.has(current.type)) {
75
+ current = current.expression;
76
+ }
77
+ return current;
78
+ }
79
+
80
+ /** @param {any} attribute */
81
+ function attributeValue(attribute) {
82
+ return attribute.value?.type === 'JSXExpressionContainer'
83
+ ? attribute.value.expression
84
+ : attribute.value;
85
+ }
86
+
87
+ /** The static string of a node, or null. @param {any} node */
88
+ function staticString(node) {
89
+ const value = unwrap(node);
90
+ if (
91
+ value != null &&
92
+ (value.type === 'StringLiteral' || value.type === 'Literal') &&
93
+ typeof value.value === 'string'
94
+ ) {
95
+ return value.value;
96
+ }
97
+ if (
98
+ value?.type === 'TemplateLiteral' &&
99
+ value.expressions.length === 0 &&
100
+ value.quasis.length === 1
101
+ ) {
102
+ return value.quasis[0].value.cooked;
103
+ }
104
+ return null;
105
+ }
106
+
107
+ /**
108
+ * A name, or a property chain on one with no call and no computed key other
109
+ * than a literal: safe to read twice, and narrowed by a `?:` guard.
110
+ * @param {any} node
111
+ * @returns {boolean}
112
+ */
113
+ function isCallFreeChain(node) {
114
+ const value = unwrap(node);
115
+ if (value == null) {
116
+ return false;
117
+ }
118
+ if (value.type === 'Identifier' || value.type === 'ThisExpression') {
119
+ return true;
120
+ }
121
+ if (value.type === 'MemberExpression') {
122
+ const key = value.property;
123
+ const literalKey =
124
+ !value.computed ||
125
+ key.type === 'StringLiteral' ||
126
+ key.type === 'NumericLiteral' ||
127
+ key.type === 'Literal';
128
+ return (
129
+ literalKey && value.optional !== true && isCallFreeChain(value.object)
130
+ );
131
+ }
132
+ return false;
133
+ }
134
+
135
+ /** @param {any} j @param {any} node @param {string} text */
136
+ function addComment(j, node, text) {
137
+ node.comments ??= [];
138
+ if (node.comments.some((/** @type {any} */ c) => c.value === text)) {
139
+ return false;
140
+ }
141
+ node.comments.push(j.commentBlock(text, true, false));
142
+ return true;
143
+ }
144
+
145
+ /**
146
+ * The local name `createCodeLanguage` is imported under, adding the import
147
+ * when the file has none.
148
+ * @param {any} j @param {any} root
149
+ */
150
+ function ensureCreateImport(j, root) {
151
+ let local = null;
152
+ root
153
+ .find(j.ImportDeclaration)
154
+ .filter((/** @type {any} */ p) => CORE_IMPORT_RE.test(p.node.source.value))
155
+ .forEach((/** @type {any} */ p) => {
156
+ for (const specifier of p.node.specifiers ?? []) {
157
+ if (
158
+ specifier.type === 'ImportSpecifier' &&
159
+ specifier.imported.name === 'createCodeLanguage'
160
+ ) {
161
+ local = specifier.local?.name ?? 'createCodeLanguage';
162
+ }
163
+ }
164
+ });
165
+ if (local != null) {
166
+ return local;
167
+ }
168
+ // Any other binding of the name (a local import or function) would clash,
169
+ // so the import takes the first free alias instead.
170
+ const name = freeName(j, root, 'createCodeLanguage');
171
+ const specifier =
172
+ name === 'createCodeLanguage'
173
+ ? j.importSpecifier(j.identifier('createCodeLanguage'))
174
+ : j.importSpecifier(
175
+ j.identifier('createCodeLanguage'),
176
+ j.identifier(name),
177
+ );
178
+ const existing = root.find(j.ImportDeclaration).filter(
179
+ (/** @type {any} */ p) =>
180
+ p.node.source.value === CODEBLOCK_SOURCE &&
181
+ p.node.importKind !== 'type' &&
182
+ // A namespace import cannot take a named specifier beside it.
183
+ !(p.node.specifiers ?? []).some(
184
+ (/** @type {any} */ s) => s.type === 'ImportNamespaceSpecifier',
185
+ ),
186
+ );
187
+ if (existing.size() > 0) {
188
+ existing.get().node.specifiers.push(specifier);
189
+ } else {
190
+ const declaration = j.importDeclaration(
191
+ [specifier],
192
+ j.stringLiteral(CODEBLOCK_SOURCE),
193
+ );
194
+ const imports = root.find(j.ImportDeclaration);
195
+ if (imports.size() > 0) {
196
+ imports.at(imports.size() - 1).insertAfter(declaration);
197
+ } else {
198
+ root.get().node.program.body.unshift(declaration);
199
+ }
200
+ }
201
+ return name;
202
+ }
203
+
204
+ /**
205
+ * `preferred`, or `preferred` with a numeric suffix, whichever no binding or
206
+ * reference in the file already uses.
207
+ * @param {any} j @param {any} root @param {string} preferred
208
+ */
209
+ function freeName(j, root, preferred) {
210
+ const used = new Set();
211
+ root.find(j.Identifier).forEach((/** @type {any} */ p) => {
212
+ used.add(p.node.name);
213
+ });
214
+ if (!used.has(preferred)) {
215
+ return preferred;
216
+ }
217
+ let n = 2;
218
+ while (used.has(`${preferred}${n}`)) {
219
+ n++;
220
+ }
221
+ return `${preferred}${n}`;
222
+ }
223
+
224
+ /**
225
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
226
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
227
+ * @returns {string | null | undefined}
228
+ */
229
+ export default function transformer(file, api) {
230
+ const j = api.jscodeshift;
231
+ const root = j(file.source);
232
+ let hasChanges = false;
233
+ /** @type {Array<() => void>} */
234
+ const rewrites = [];
235
+
236
+ transformProp(
237
+ root,
238
+ j,
239
+ {
240
+ matchesImport: source => CORE_IMPORT_RE.test(source),
241
+ components: COMPONENT_PROPS,
242
+ },
243
+ propPath => {
244
+ const opening = propPath.parent?.node;
245
+ const attributes = opening?.attributes ?? [];
246
+ const prop = propPath.node;
247
+ if (
248
+ attributes.some(
249
+ (/** @type {any} */ a) => a.type === 'JSXSpreadAttribute',
250
+ )
251
+ ) {
252
+ hasChanges = addComment(j, prop, SPREAD_COMMENT) || hasChanges;
253
+ return;
254
+ }
255
+ const languageAttribute = attributes.find(
256
+ (/** @type {any} */ a) =>
257
+ a.type === 'JSXAttribute' && a.name?.name === 'language',
258
+ );
259
+ const language =
260
+ languageAttribute == null
261
+ ? null
262
+ : staticString(attributeValue(languageAttribute));
263
+ const tokenize = attributeValue(prop);
264
+ const tokenizeNode = unwrap(tokenize);
265
+ // A function literal is always a function. A name or property may be
266
+ // undefined at run time (a forwarded optional prop), so it is guarded:
267
+ // `fn ? createCodeLanguage({...}) : 'x'` keeps the plain block the
268
+ // released prop drew without one. Anything else is reported.
269
+ const isFunction =
270
+ tokenizeNode?.type === 'ArrowFunctionExpression' ||
271
+ tokenizeNode?.type === 'FunctionExpression';
272
+ const isGuardable = isCallFreeChain(tokenizeNode);
273
+ if (language == null || language === '' || language === 'plaintext') {
274
+ hasChanges = addComment(j, prop, UNPROVEN_COMMENT) || hasChanges;
275
+ return;
276
+ }
277
+ if (!(isFunction || isGuardable)) {
278
+ hasChanges = addComment(j, prop, VALUE_COMMENT) || hasChanges;
279
+ return;
280
+ }
281
+ rewrites.push(() => {
282
+ const create = ensureCreateImport(j, root);
283
+ const value = j.callExpression(j.identifier(create), [
284
+ j.objectExpression([
285
+ j.objectProperty(j.identifier('name'), j.stringLiteral(language)),
286
+ j.objectProperty(
287
+ j.identifier('identifiers'),
288
+ j.arrayExpression([j.stringLiteral(language)]),
289
+ ),
290
+ j.objectProperty(j.identifier('tokenize'), tokenize),
291
+ ]),
292
+ ]);
293
+ languageAttribute.value = j.jsxExpressionContainer(
294
+ isFunction
295
+ ? value
296
+ : j.conditionalExpression(
297
+ tokenize,
298
+ value,
299
+ j.stringLiteral(language),
300
+ ),
301
+ );
302
+ opening.attributes = opening.attributes.filter(
303
+ (/** @type {any} */ a) => a !== prop,
304
+ );
305
+ });
306
+ },
307
+ );
308
+
309
+ for (const rewrite of rewrites) {
310
+ rewrite();
311
+ hasChanges = true;
312
+ }
313
+ if (!hasChanges) return undefined;
314
+ return root.toSource({quote: 'single'});
315
+ }
@@ -4,16 +4,18 @@
4
4
  export const doc = {
5
5
  type: 'block',
6
6
  exampleFor: 'BottomSheetSwitcher',
7
- name: 'Bottom Sheet Switcher — Review flow',
8
- displayName: 'Bottom Sheet Switcher — Review flow',
7
+ alsoExampleFor: ['BottomSheet'],
8
+ // The published registry identity predates the rewrite; keep it.
9
+ registry: {slug: 'review-flow'},
10
+ name: 'Bottom Sheet — Review flow',
11
+ displayName: 'Bottom Sheet — Review flow',
9
12
  description:
10
- 'A two-step form flow that lets a person review settings, confirm them, or move back, each step in its own native dialog under one scrim.',
13
+ 'A two-step form flow of two standalone sheets driven by one state value: Continue replaces the review step with the confirmation in place, and Back returns.',
11
14
  isReady: true,
12
15
  isShowcase: false,
13
16
  aspectRatio: 3 / 4,
14
17
  componentsUsed: [
15
18
  'BottomSheet',
16
- 'BottomSheetSwitcher',
17
19
  'Button',
18
20
  'Heading',
19
21
  'Section',
@@ -3,73 +3,79 @@
3
3
  'use client';
4
4
 
5
5
  import {useState} from 'react';
6
- import {BottomSheet, BottomSheetSwitcher} from '@astryxdesign/core/BottomSheet';
6
+ import {BottomSheet} from '@astryxdesign/core/BottomSheet';
7
7
  import {Button} from '@astryxdesign/core/Button';
8
8
  import {Heading} from '@astryxdesign/core/Heading';
9
9
  import {Section} from '@astryxdesign/core/Section';
10
10
  import {HStack, VStack} from '@astryxdesign/core/Stack';
11
11
  import {Text} from '@astryxdesign/core/Text';
12
12
 
13
+ type Step = 'review' | 'confirm' | null;
14
+
13
15
  export default function BottomSheetSwitcherReviewFlow() {
14
- const [activeSheet, setActiveSheet] = useState<string | null>(null);
16
+ // One state value names the open step; Continue and Back close one sheet
17
+ // and open the other in the same update, which replaces it in place.
18
+ const [step, setStep] = useState<Step>(null);
19
+ // Clear the step only if it is still the open one: a step that closes
20
+ // because the person moved on must not undo the move.
21
+ const close = (own: Step) => (isOpen: boolean) => {
22
+ if (!isOpen) {
23
+ setStep(current => (current === own ? null : current));
24
+ }
25
+ };
15
26
 
16
27
  return (
17
28
  <>
18
- <Button
19
- label="Review settings"
20
- onClick={() => setActiveSheet('review')}
21
- />
22
- <BottomSheetSwitcher
23
- activeSheet={activeSheet}
24
- onActiveSheetChange={setActiveSheet}>
25
- <BottomSheet
26
- sheetId="review"
27
- label="Review notification settings"
28
- height="hug"
29
- purpose="form">
30
- <Section padding={4}>
31
- <VStack gap={4}>
32
- <VStack gap={1}>
33
- <Heading level={3}>Review settings</Heading>
34
- <Text type="supporting" color="secondary">
35
- Daily summaries will be sent by email.
36
- </Text>
37
- </VStack>
38
- <HStack gap={2} hAlign="end">
39
- <Button
40
- label="Cancel"
41
- variant="secondary"
42
- onClick={() => setActiveSheet(null)}
43
- />
44
- <Button
45
- label="Continue"
46
- onClick={() => setActiveSheet('confirm')}
47
- />
48
- </HStack>
29
+ <Button label="Review settings" onClick={() => setStep('review')} />
30
+ <BottomSheet
31
+ isOpen={step === 'review'}
32
+ onOpenChange={close('review')}
33
+ label="Review notification settings"
34
+ height="hug"
35
+ purpose="form">
36
+ <Section padding={4}>
37
+ <VStack gap={4}>
38
+ <VStack gap={1}>
39
+ <Heading level={3}>Review settings</Heading>
40
+ <Text type="supporting" color="secondary">
41
+ Daily summaries will be sent by email.
42
+ </Text>
49
43
  </VStack>
50
- </Section>
51
- </BottomSheet>
52
- <BottomSheet sheetId="confirm" label="Confirm settings" height="hug">
53
- <Section padding={4}>
54
- <VStack gap={4}>
55
- <VStack gap={1}>
56
- <Heading level={3}>Confirm settings</Heading>
57
- <Text type="supporting" color="secondary">
58
- Your notification settings are ready to save.
59
- </Text>
60
- </VStack>
61
- <HStack gap={2} hAlign="end">
62
- <Button
63
- label="Back"
64
- variant="secondary"
65
- onClick={() => setActiveSheet('review')}
66
- />
67
- <Button label="Save" onClick={() => setActiveSheet(null)} />
68
- </HStack>
44
+ <HStack gap={2} hAlign="end">
45
+ <Button
46
+ label="Cancel"
47
+ variant="secondary"
48
+ onClick={() => setStep(null)}
49
+ />
50
+ <Button label="Continue" onClick={() => setStep('confirm')} />
51
+ </HStack>
52
+ </VStack>
53
+ </Section>
54
+ </BottomSheet>
55
+ <BottomSheet
56
+ isOpen={step === 'confirm'}
57
+ onOpenChange={close('confirm')}
58
+ label="Confirm settings"
59
+ height="hug">
60
+ <Section padding={4}>
61
+ <VStack gap={4}>
62
+ <VStack gap={1}>
63
+ <Heading level={3}>Confirm settings</Heading>
64
+ <Text type="supporting" color="secondary">
65
+ Your notification settings are ready to save.
66
+ </Text>
69
67
  </VStack>
70
- </Section>
71
- </BottomSheet>
72
- </BottomSheetSwitcher>
68
+ <HStack gap={2} hAlign="end">
69
+ <Button
70
+ label="Back"
71
+ variant="secondary"
72
+ onClick={() => setStep('review')}
73
+ />
74
+ <Button label="Save" onClick={() => setStep(null)} />
75
+ </HStack>
76
+ </VStack>
77
+ </Section>
78
+ </BottomSheet>
73
79
  </>
74
80
  );
75
81
  }
@@ -4,16 +4,18 @@
4
4
  export const doc = {
5
5
  type: 'block',
6
6
  exampleFor: 'BottomSheetSwitcher',
7
- name: 'Bottom Sheet Switcher',
8
- displayName: 'Bottom Sheet Switcher',
7
+ alsoExampleFor: ['BottomSheet'],
8
+ // The published registry identity predates the rewrite; keep it.
9
+ registry: {slug: 'default'},
10
+ name: 'Bottom Sheet — Multi-step flow',
11
+ displayName: 'Bottom Sheet — Multi-step flow',
9
12
  description:
10
- 'A three-step flow that transitions between content-hugging sheets of different heights, each step in its own native dialog with one scrim handed between them.',
13
+ 'A three-step flow of standalone sheets of different heights, driven by one state value: moving on replaces the open step in place. This is the replacement for the deprecated BottomSheetSwitcher.',
11
14
  isReady: true,
12
15
  isShowcase: true,
13
16
  aspectRatio: 3 / 4,
14
17
  componentsUsed: [
15
18
  'BottomSheet',
16
- 'BottomSheetSwitcher',
17
19
  'Button',
18
20
  'CheckboxInput',
19
21
  'Divider',
@@ -3,7 +3,7 @@
3
3
  'use client';
4
4
 
5
5
  import {useState} from 'react';
6
- import {BottomSheet, BottomSheetSwitcher} from '@astryxdesign/core/BottomSheet';
6
+ import {BottomSheet} from '@astryxdesign/core/BottomSheet';
7
7
  import {Button} from '@astryxdesign/core/Button';
8
8
  import {CheckboxInput} from '@astryxdesign/core/CheckboxInput';
9
9
  import {Divider} from '@astryxdesign/core/Divider';
@@ -15,20 +15,35 @@ import {RadioList, RadioListItem} from '@astryxdesign/core/RadioList';
15
15
 
16
16
  type NotificationSheetHeight = 'hug' | 'capped';
17
17
 
18
- interface NotificationOverviewSheetProps {
18
+ /**
19
+ * Each step is a standalone sheet. Closing the open step and opening the
20
+ * next one in the same update (one `step` state value) replaces it in place.
21
+ */
22
+ interface StepSheetProps {
23
+ isOpen: boolean;
24
+ onOpenChange: (isOpen: boolean) => void;
25
+ hasScrim: boolean;
19
26
  height: NotificationSheetHeight;
27
+ }
28
+
29
+ interface NotificationOverviewSheetProps extends StepSheetProps {
20
30
  onCancel: () => void;
21
31
  onContinue: () => void;
22
32
  }
23
33
 
24
34
  function NotificationOverviewSheet({
35
+ isOpen,
36
+ onOpenChange,
37
+ hasScrim,
25
38
  height,
26
39
  onCancel,
27
40
  onContinue,
28
41
  }: NotificationOverviewSheetProps) {
29
42
  return (
30
43
  <BottomSheet
31
- sheetId="overview"
44
+ isOpen={isOpen}
45
+ onOpenChange={onOpenChange}
46
+ hasScrim={hasScrim}
32
47
  label="Set up notifications"
33
48
  height={height}>
34
49
  <Section padding={4}>
@@ -74,13 +89,15 @@ function NotificationOverviewSheet({
74
89
  );
75
90
  }
76
91
 
77
- interface NotificationFrequencySheetProps {
78
- height: NotificationSheetHeight;
92
+ interface NotificationFrequencySheetProps extends StepSheetProps {
79
93
  onBack: () => void;
80
94
  onContinue: () => void;
81
95
  }
82
96
 
83
97
  function NotificationFrequencySheet({
98
+ isOpen,
99
+ onOpenChange,
100
+ hasScrim,
84
101
  height,
85
102
  onBack,
86
103
  onContinue,
@@ -89,7 +106,9 @@ function NotificationFrequencySheet({
89
106
 
90
107
  return (
91
108
  <BottomSheet
92
- sheetId="frequency"
109
+ isOpen={isOpen}
110
+ onOpenChange={onOpenChange}
111
+ hasScrim={hasScrim}
93
112
  label="Notification frequency"
94
113
  height={height}>
95
114
  <Section padding={4}>
@@ -120,13 +139,15 @@ function NotificationFrequencySheet({
120
139
  );
121
140
  }
122
141
 
123
- interface NotificationChannelsSheetProps {
124
- height: NotificationSheetHeight;
142
+ interface NotificationChannelsSheetProps extends StepSheetProps {
125
143
  onBack: () => void;
126
144
  onFinish: () => void;
127
145
  }
128
146
 
129
147
  function NotificationChannelsSheet({
148
+ isOpen,
149
+ onOpenChange,
150
+ hasScrim,
130
151
  height,
131
152
  onBack,
132
153
  onFinish,
@@ -137,7 +158,9 @@ function NotificationChannelsSheet({
137
158
 
138
159
  return (
139
160
  <BottomSheet
140
- sheetId="channels"
161
+ isOpen={isOpen}
162
+ onOpenChange={onOpenChange}
163
+ hasScrim={hasScrim}
141
164
  label="Notification channels"
142
165
  height={height}>
143
166
  <Section padding={4}>
@@ -175,47 +198,55 @@ function NotificationChannelsSheet({
175
198
  );
176
199
  }
177
200
 
178
- interface MultiStepSwitcherExampleProps {
201
+ type Step = 'overview' | 'frequency' | 'channels' | null;
202
+
203
+ interface MultiStepExampleProps {
179
204
  height: NotificationSheetHeight;
180
205
  hasScrim?: boolean;
181
206
  }
182
207
 
183
- function MultiStepSwitcherExample({
184
- height,
185
- hasScrim = true,
186
- }: MultiStepSwitcherExampleProps) {
187
- const [activeSheet, setActiveSheet] = useState<string | null>(null);
208
+ function MultiStepExample({height, hasScrim = true}: MultiStepExampleProps) {
209
+ // One state value names the open step. Moving on closes one sheet and
210
+ // opens the next in the same update, which replaces it in place.
211
+ const [step, setStep] = useState<Step>(null);
212
+ const stepProps = (id: Step) => ({
213
+ isOpen: step === id,
214
+ onOpenChange: (isOpen: boolean) => {
215
+ // Clear the step only if it is still the open one: a step that closes
216
+ // because the person moved on must not undo the move.
217
+ if (!isOpen) {
218
+ setStep(current => (current === id ? null : current));
219
+ }
220
+ },
221
+ hasScrim,
222
+ height,
223
+ });
188
224
 
189
225
  return (
190
226
  <>
191
227
  <Button
192
228
  label="Set up notifications"
193
- onClick={() => setActiveSheet('overview')}
229
+ onClick={() => setStep('overview')}
230
+ />
231
+ <NotificationOverviewSheet
232
+ {...stepProps('overview')}
233
+ onCancel={() => setStep(null)}
234
+ onContinue={() => setStep('frequency')}
235
+ />
236
+ <NotificationFrequencySheet
237
+ {...stepProps('frequency')}
238
+ onBack={() => setStep('overview')}
239
+ onContinue={() => setStep('channels')}
240
+ />
241
+ <NotificationChannelsSheet
242
+ {...stepProps('channels')}
243
+ onBack={() => setStep('frequency')}
244
+ onFinish={() => setStep(null)}
194
245
  />
195
- <BottomSheetSwitcher
196
- activeSheet={activeSheet}
197
- onActiveSheetChange={setActiveSheet}
198
- hasScrim={hasScrim}>
199
- <NotificationOverviewSheet
200
- height={height}
201
- onCancel={() => setActiveSheet(null)}
202
- onContinue={() => setActiveSheet('frequency')}
203
- />
204
- <NotificationFrequencySheet
205
- height={height}
206
- onBack={() => setActiveSheet('overview')}
207
- onContinue={() => setActiveSheet('channels')}
208
- />
209
- <NotificationChannelsSheet
210
- height={height}
211
- onBack={() => setActiveSheet('frequency')}
212
- onFinish={() => setActiveSheet(null)}
213
- />
214
- </BottomSheetSwitcher>
215
246
  </>
216
247
  );
217
248
  }
218
249
 
219
250
  export default function BottomSheetSwitcherShowcase() {
220
- return <MultiStepSwitcherExample height="hug" />;
251
+ return <MultiStepExample height="hug" />;
221
252
  }
@@ -6,7 +6,7 @@ export const doc = {
6
6
  exampleFor: 'Thumbnail',
7
7
  name: 'Thumbnail — Disabled',
8
8
  displayName: 'Thumbnail — Disabled',
9
- description: 'Thumbnails in the disabled state with reduced opacity. The remove button and click handler are suppressed when disabled.',
9
+ description: 'Thumbnails in the disabled state with reduced opacity. The open and remove buttons stay focusable and announced as disabled, and call nothing.',
10
10
  isReady: true,
11
11
  aspectRatio: 16 / 9,
12
12
  componentsUsed: ['Thumbnail', 'Layout', 'Text'],
@@ -673,6 +673,7 @@ export function detectStylingSystem(targetDir) {
673
673
  '@stylexjs/rollup-plugin',
674
674
  '@stylexjs/webpack-plugin',
675
675
  '@stylexjs/nextjs-plugin',
676
+ '@stylexjs/unplugin',
676
677
  'vite-plugin-stylex',
677
678
  'unplugin-stylex',
678
679
  '@stylexswc/unplugin',
@@ -552,6 +552,11 @@ describe('detectStylingSystem', () => {
552
552
  expect(detectStylingSystem(tmpDir)).toBe('stylex');
553
553
  });
554
554
 
555
+ it('detects the official unplugin (the standard Vite path)', () => {
556
+ writePkg({'@stylexjs/unplugin': '0.10.0'});
557
+ expect(detectStylingSystem(tmpDir)).toBe('stylex');
558
+ });
559
+
555
560
  it('detects tailwind when tailwindcss is present', () => {
556
561
  writePkg({tailwindcss: '4.0.0'});
557
562
  expect(detectStylingSystem(tmpDir)).toBe('tailwind');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.5-canary.a17ee0a",
3
+ "version": "0.7.5-canary.a73f030",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -111,10 +111,10 @@
111
111
  "zod": "^4.4.3"
112
112
  },
113
113
  "peerDependencies": {
114
- "@astryxdesign/charts": "0.7.5-canary.a17ee0a",
115
- "@astryxdesign/core": "0.7.5-canary.a17ee0a",
116
- "@astryxdesign/lab": "0.7.5-canary.a17ee0a",
117
- "@astryxdesign/theme-neutral": "0.7.5-canary.a17ee0a"
114
+ "@astryxdesign/charts": "0.7.5-canary.a73f030",
115
+ "@astryxdesign/core": "0.7.5-canary.a73f030",
116
+ "@astryxdesign/lab": "0.7.5-canary.a73f030",
117
+ "@astryxdesign/theme-neutral": "0.7.5-canary.a73f030"
118
118
  },
119
119
  "peerDependenciesMeta": {
120
120
  "@astryxdesign/charts": {
@@ -131,10 +131,10 @@
131
131
  }
132
132
  },
133
133
  "devDependencies": {
134
- "@astryxdesign/charts": "0.7.5-canary.a17ee0a",
135
- "@astryxdesign/core": "0.7.5-canary.a17ee0a",
136
- "@astryxdesign/lab": "0.7.5-canary.a17ee0a",
137
- "@astryxdesign/theme-neutral": "0.7.5-canary.a17ee0a",
134
+ "@astryxdesign/charts": "0.7.5-canary.a73f030",
135
+ "@astryxdesign/core": "0.7.5-canary.a73f030",
136
+ "@astryxdesign/lab": "0.7.5-canary.a73f030",
137
+ "@astryxdesign/theme-neutral": "0.7.5-canary.a73f030",
138
138
  "@heroicons/react": "^2.2.0",
139
139
  "@stylexjs/stylex": "^0.19.0",
140
140
  "@types/babel__core": "^7.20.5",