@astryxdesign/cli 0.7.5-canary.2af4d30 → 0.7.5-canary.33645a2
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.
- package/api/template/tokenizer-showcase.test.mjs +47 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +40 -3
- package/api/theme/build/build.test.mjs +27 -0
- package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +82 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
- package/assets/theme.template.ts +18 -5
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/package.json +9 -9
|
@@ -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
|
+
}
|
|
@@ -55,9 +55,11 @@ export const docs = {
|
|
|
55
55
|
['tokens', 'Base tokens are copied first, then child tokens override on top.'],
|
|
56
56
|
['components', 'Deep-merged: child component rules override matching keys from the base.'],
|
|
57
57
|
['icons', 'Shallow-merged: child icons override matching names from the base.'],
|
|
58
|
+
['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
|
|
58
59
|
['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
|
|
59
60
|
['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
|
|
60
|
-
['
|
|
61
|
+
['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio."],
|
|
62
|
+
['typography, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
|
|
61
63
|
['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
|
|
62
64
|
]},
|
|
63
65
|
{type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `{@command theme build}` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it. A base that is not a theme (most often an import that missed) throws when `defineTheme` runs, rather than producing a theme that silently inherits nothing."},
|
|
@@ -101,11 +101,92 @@ export const brandTheme = defineTheme({
|
|
|
101
101
|
},
|
|
102
102
|
});`,
|
|
103
103
|
},
|
|
104
|
+
{
|
|
105
|
+
type: 'prose',
|
|
106
|
+
text: "An entry can also be a function of the request, so the theme maps Icon's size to its icon library's own props or artwork. `Icon` calls it with `{size, variant}`, where `size` is the size it renders at (`xsm`, `sm`, `md`, or `lg`: an explicit `size`, else the owning component's default, else `md`). Reads that return one node — `getIcon()`, `useIcon()`, `getIconRegistry()`, and the theme's `icons` field — call it with `{size: 'md'}`. The same entry shape works in `registerIcons()`.",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'code',
|
|
110
|
+
lang: 'tsx',
|
|
111
|
+
label: 'A size-aware icon entry',
|
|
112
|
+
code: `import {defineTheme} from '@astryxdesign/core/theme';
|
|
113
|
+
import {Info} from 'lucide-react';
|
|
114
|
+
|
|
115
|
+
export const brandTheme = defineTheme({
|
|
116
|
+
name: 'brand',
|
|
117
|
+
icons: {
|
|
118
|
+
// A heavier stroke keeps the small size legible.
|
|
119
|
+
info: ({size}) => <Info strokeWidth={size === 'sm' || size === 'xsm' ? 2.5 : 2} />,
|
|
120
|
+
},
|
|
121
|
+
});`,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
type: 'prose',
|
|
125
|
+
text: 'Keep the function pure and synchronous: it computes its result from the request only, with no hooks, DOM or SVG measurement, browser globals, network access, mutable module state, or side effects. Its result is final. Returning `null` draws no glyph instead of falling back to a registered or built-in icon, while a `null` or `undefined` node entry still falls back. A child theme that sets an entry for a key replaces the inherited entry for that key.',
|
|
126
|
+
},
|
|
104
127
|
],
|
|
105
128
|
},
|
|
106
129
|
{
|
|
107
|
-
title: '
|
|
130
|
+
title: 'Icon Variants',
|
|
108
131
|
category: 'foundations',
|
|
132
|
+
content: [
|
|
133
|
+
{
|
|
134
|
+
type: 'prose',
|
|
135
|
+
text: "A theme lists the icon variant names it supports once, with `iconVariants` in `defineTheme()`. The list belongs to the whole theme, never to one icon, and Astryx defines no names of its own. Inside `defineTheme`, an entry function receives `variant` typed as the listed names, or `undefined`, so a misspelled name is a type error. An entry that receives `undefined` draws its normal artwork.",
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: 'code',
|
|
139
|
+
lang: 'tsx',
|
|
140
|
+
label: 'Listing variants and mapping them to artwork',
|
|
141
|
+
code: `import {defineTheme} from '@astryxdesign/core/theme';
|
|
142
|
+
import {InfoFilledIcon, InfoIcon} from './brand-icons';
|
|
143
|
+
|
|
144
|
+
export const brandTheme = defineTheme({
|
|
145
|
+
name: 'brand',
|
|
146
|
+
iconVariants: ['outline', 'filled'],
|
|
147
|
+
icons: {
|
|
148
|
+
info: ({size, variant}) =>
|
|
149
|
+
variant === 'filled' ? <InfoFilledIcon /> : <InfoIcon bold={size === 'sm'} />,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
brandTheme.iconVariants; // ['outline', 'filled']`,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
type: 'prose',
|
|
157
|
+
text: 'A theme that `extends` another inherits its list unless it sets its own; a list it sets replaces the inherited one instead of merging with it.',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
type: 'prose',
|
|
161
|
+
text: "Request a variant with `Icon`'s `variant` prop. The entry receives it only when the active theme lists it; an entry the theme inherited also needs the theme that defined it to list it. Otherwise the entry receives `undefined` and draws its normal artwork, so an unlisted variant never breaks rendering. A `registerIcons()` entry receives the variants the active theme lists, and a node entry draws the same node for every variant. An icon component passed directly to `Icon` never receives `variant`, and `variant` is never written to the DOM: it selects artwork, so there is no theming selector for it.",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'code',
|
|
165
|
+
lang: 'tsx',
|
|
166
|
+
label: 'Requesting a variant',
|
|
167
|
+
code: `<Icon icon="info" variant="filled" /> // brandTheme: the filled artwork
|
|
168
|
+
<Icon icon="info" /> // the normal artwork`,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
type: 'prose',
|
|
172
|
+
text: 'An application declares the variant names it uses by augmenting `IconVariantMap` from `@astryxdesign/core/Icon`. `IconVariant` is those names, and an entry passed to `registerIcons()` receives `variant` typed as `IconVariant`.',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: 'code',
|
|
176
|
+
lang: 'ts',
|
|
177
|
+
label: 'Declaring the variant names an application uses',
|
|
178
|
+
code: `declare module '@astryxdesign/core/Icon' {
|
|
179
|
+
interface IconVariantMap {
|
|
180
|
+
outline: true;
|
|
181
|
+
filled: true;
|
|
182
|
+
}
|
|
183
|
+
}`,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
title: 'Component and Library Icons',
|
|
189
|
+
category: 'foundations',
|
|
109
190
|
content: [
|
|
110
191
|
{
|
|
111
192
|
type: 'prose',
|
|
@@ -21,6 +21,14 @@ export const docsDense = {
|
|
|
21
21
|
{type: 'prose', text: "new palette: `astryx theme palette generate palette.config.json --out palette.generated.ts` → review + commit module and receipt → `import {palette} from './palette.generated';` → map semantic tokens to stable stops such as `palette.neutral.light[100]` / `palette.neutral.dark[15]`. regeneration updates mapped roles; generation does not rewrite the theme."},
|
|
22
22
|
],
|
|
23
23
|
},
|
|
24
|
+
{
|
|
25
|
+
section: 'Icon sizes',
|
|
26
|
+
title: 'Icon sizes',
|
|
27
|
+
content: [
|
|
28
|
+
{type: 'prose', text: "theme sets each Icon size's glyph dimension: `width` + `height` on `components.icon['size:sm']` (or xsm/md/lg); semantic names + SVG components alike. px or rem only: a semantic icon takes its font size from the dimension, so em also grows its box. unstyled: xsm/sm/md/lg = 12/16/20/24px at 16px root, scale w/ root font size (rem keeps it). size names are fixed."},
|
|
29
|
+
null,
|
|
30
|
+
],
|
|
31
|
+
},
|
|
24
32
|
{
|
|
25
33
|
section: 'Dark mode',
|
|
26
34
|
title: 'Dark mode',
|
|
@@ -53,6 +53,22 @@ export const docs = {
|
|
|
53
53
|
},
|
|
54
54
|
],
|
|
55
55
|
},
|
|
56
|
+
{
|
|
57
|
+
id: 'icon-sizes',
|
|
58
|
+
title: 'Icon sizes',
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'prose',
|
|
62
|
+
text: "A theme sets the dimension of each Icon size in its stylesheet: `width` and `height` on `components.icon['size:sm']` (or `xsm`, `md`, `lg`) resize that size's glyph, for semantic icon names and SVG components passed to `Icon` alike. Give the dimension in `px` or `rem`: a semantic icon takes its font size from it, so an `em` value would also grow its box. A size the theme leaves alone stays 12, 16, 20, or 24px at a 16px root (`xsm`, `sm`, `md`, `lg`) and scales with the root font size; `rem` keeps that scaling. The four size names are fixed.",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'code',
|
|
66
|
+
lang: 'tsx',
|
|
67
|
+
label: 'Set Icon size dimensions',
|
|
68
|
+
code: "const brandTheme = defineTheme({\n name: 'brand',\n components: {\n icon: {\n 'size:sm': {width: '1.125rem', height: '1.125rem'},\n 'size:lg': {width: '1.75rem', height: '1.75rem'},\n },\n },\n});",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
56
72
|
{
|
|
57
73
|
id: 'light-dark-mode',
|
|
58
74
|
title: 'Dark mode',
|
|
@@ -25,6 +25,17 @@ export const docsZh = {
|
|
|
25
25
|
},
|
|
26
26
|
],
|
|
27
27
|
},
|
|
28
|
+
{
|
|
29
|
+
section: 'Icon sizes',
|
|
30
|
+
title: '图标尺寸',
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: 'prose',
|
|
34
|
+
text: "主题在样式表中设置每个 Icon 尺寸的大小:在 `components.icon['size:sm']`(或 `xsm`、`md`、`lg`)上设置 `width` 和 `height`,即可调整该尺寸的图标,语义图标名称和直接传给 `Icon` 的 SVG 组件都适用。请使用 `px` 或 `rem` 设置尺寸:语义图标会据此设置自身的字号,因此 `em` 值也会放大它的外框。主题未设置的尺寸在 16px 根字号下保持 12、16、20 或 24px(`xsm`、`sm`、`md`、`lg`),并随根字号缩放;`rem` 可保留这种缩放。四个尺寸名称是固定的。",
|
|
35
|
+
},
|
|
36
|
+
null,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
28
39
|
{
|
|
29
40
|
section: 'Dark mode',
|
|
30
41
|
title: '深色模式',
|
package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs
CHANGED
|
@@ -4,16 +4,18 @@
|
|
|
4
4
|
export const doc = {
|
|
5
5
|
type: 'block',
|
|
6
6
|
exampleFor: 'BottomSheetSwitcher',
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
|
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',
|