Skip to content

Commit eef4320

Browse files
committed
Merge pull request #12337 into drain/integration
2 parents d0d4c58 + 5052b6d commit eef4320

15 files changed

Lines changed: 189 additions & 87 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[docs] Four docs name prop types the package exports. Selector's `options` are `SelectorOptionType[]` (`SelectorOption` is a component), SyntaxTheme's `theme` is a `SyntaxThemeDefinition`, and `useImperativeDialog` and `useImperativeAlertDialog` write their `show()` options with the exported Dialog and AlertDialog props. Toast's doc marks the card's `isAutoHide` and `autoHideDuration` required, as `ToastProps` declares, and the show-only options (`uniqueID`, `collisionBehavior`, `onHide`) leave its props table, because `useToast`'s doc lists them with their defaults; `type` keeps its documented `'info'` default.
6+
7+
@cixzhang

‎apps/docsite/src/__tests__/component-prop-controls.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ describe('component detail prop controls', () => {
9090
}
9191
});
9292

93+
it('gives a SyntaxThemeDefinition prop the syntax theme preset control', () => {
94+
expect(parsePropType('SyntaxThemeDefinition', 'theme')).toEqual({
95+
kind: 'syntax-theme',
96+
});
97+
});
98+
9399
it('derives IconType options from the canonical icon registry', () => {
94100
const control = parsePropType('IconType', 'labelIcon');
95101

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
import {allSyntaxPresets} from '@astryxdesign/core/theme/syntax';
4+
import {describe, expect, it} from 'vitest';
5+
import {
6+
NO_SYNTAX_THEME,
7+
selectedSyntaxTheme,
8+
syntaxThemeChoices,
9+
syntaxPresetName,
10+
syntaxThemeFor,
11+
} from '../components/component-detail/syntaxThemeChoices';
12+
13+
describe('the playground syntax theme control', () => {
14+
it('shows an unset optional prop as None, and None sends nothing', () => {
15+
expect(syntaxThemeChoices(false)[0].value).toBe(NO_SYNTAX_THEME);
16+
expect(selectedSyntaxTheme(undefined, false)).toBe(NO_SYNTAX_THEME);
17+
expect(syntaxThemeFor(NO_SYNTAX_THEME)).toBeUndefined();
18+
});
19+
20+
it('offers no None for a required prop, which shows the first preset', () => {
21+
expect(
22+
syntaxThemeChoices(true).some(choice => choice.value === NO_SYNTAX_THEME),
23+
).toBe(false);
24+
expect(selectedSyntaxTheme(undefined, true)).toBe(allSyntaxPresets[0].name);
25+
});
26+
27+
it('shows and sends a chosen preset', () => {
28+
const preset = allSyntaxPresets[1];
29+
expect(selectedSyntaxTheme(preset, false)).toBe(preset.name);
30+
expect(syntaxThemeFor(preset.name)).toBe(preset);
31+
});
32+
33+
it('names the preset a value is', () => {
34+
const dracula = allSyntaxPresets.find(theme => theme.name === 'dracula');
35+
const oneDarkPro = allSyntaxPresets.find(
36+
theme => theme.name === 'one-dark-pro',
37+
);
38+
expect(syntaxPresetName(dracula)).toBe('dracula');
39+
expect(syntaxPresetName(oneDarkPro)).toBe('one-dark-pro');
40+
expect(syntaxPresetName({name: 'dracula'})).toBeNull();
41+
});
42+
});

‎apps/docsite/src/components/component-detail/InteractivePreview.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from 'react';
1515
import * as stylex from '@stylexjs/stylex';
1616
import {getComponent, resolveValue} from './resolveElements';
17+
import {syntaxPresetName} from './syntaxThemeChoices';
1718
import {AppShellMobileContext} from '@astryxdesign/core/AppShell';
1819
import {Button} from '@astryxdesign/core/Button';
1920
import {Card} from '@astryxdesign/core/Card';
@@ -122,6 +123,10 @@ function formatValue(
122123
if (value === null) {
123124
return 'null';
124125
}
126+
const syntaxPreset = syntaxPresetName(value);
127+
if (syntaxPreset != null) {
128+
return toIdentifierName(syntaxPreset);
129+
}
125130
if (
126131
value != null &&
127132
typeof value === 'object' &&

‎apps/docsite/src/components/component-detail/PlaygroundPropsTable.tsx‎

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ import {Badge} from '@astryxdesign/core/Badge';
2222
import {IconButton} from '@astryxdesign/core/IconButton';
2323
import {Minus, Plus} from 'lucide-react';
2424
import {useMediaQuery} from '@astryxdesign/core/hooks';
25-
import {allSyntaxPresets} from '@astryxdesign/core/theme/syntax';
2625
import {themeObjectsFull} from '../../generated/themeRegistry';
2726
import {coerceEnumOption, type PropControlDescriptor} from './parsePropType';
27+
import {
28+
selectedSyntaxTheme,
29+
syntaxThemeChoices,
30+
syntaxThemeFor,
31+
} from './syntaxThemeChoices';
2832
import {resolveTypeRefs, TypeRefText} from './TypeRefText';
2933
import type {KnobProp} from './InteractivePreview';
3034
import {resolveElementDescriptor} from './resolveElements';
@@ -166,15 +170,6 @@ const themeOptions = Object.entries(themeObjectsFull).map(
166170
}),
167171
);
168172

169-
const syntaxThemeOptions = allSyntaxPresets.map(theme => ({
170-
value: theme.name,
171-
label: theme.name
172-
.split('-')
173-
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
174-
.join(' '),
175-
theme,
176-
}));
177-
178173
function ThemeControl({
179174
value,
180175
onChange,
@@ -217,36 +212,20 @@ function ThemeControl({
217212

218213
function SyntaxThemeControl({
219214
value,
215+
isRequired,
220216
onChange,
221217
}: {
222218
value: unknown;
219+
isRequired: boolean;
223220
onChange: (next: unknown) => void;
224221
}) {
225-
const selected =
226-
syntaxThemeOptions.find(
227-
option =>
228-
option.theme === value ||
229-
(value != null &&
230-
typeof value === 'object' &&
231-
'name' in value &&
232-
option.theme.name === value.name),
233-
)?.value ?? syntaxThemeOptions[0].value;
234-
235222
return (
236223
<Selector
237224
label="Syntax theme"
238225
isLabelHidden
239-
value={selected}
240-
options={syntaxThemeOptions.map(({value: optionValue, label}) => ({
241-
value: optionValue,
242-
label,
243-
}))}
244-
onChange={next => {
245-
const match = syntaxThemeOptions.find(option => option.value === next);
246-
if (match) {
247-
onChange(match.theme);
248-
}
249-
}}
226+
value={selectedSyntaxTheme(value, isRequired)}
227+
options={syntaxThemeChoices(isRequired)}
228+
onChange={next => onChange(syntaxThemeFor(next))}
250229
/>
251230
);
252231
}
@@ -475,7 +454,13 @@ function InlineControl({
475454
case 'theme':
476455
return <ThemeControl value={value} onChange={onChange} />;
477456
case 'syntax-theme':
478-
return <SyntaxThemeControl value={value} onChange={onChange} />;
457+
return (
458+
<SyntaxThemeControl
459+
value={value}
460+
isRequired={!!prop.required}
461+
onChange={onChange}
462+
/>
463+
);
479464
case 'string':
480465
return (
481466
<TextInput

‎apps/docsite/src/components/component-detail/parsePropType.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function parsePropType(
183183
if (t === 'DefinedTheme') {
184184
return {kind: 'theme'};
185185
}
186-
if (t === 'SyntaxTheme') {
186+
if (t === 'SyntaxThemeDefinition') {
187187
return {kind: 'syntax-theme'};
188188
}
189189
if (t === 'IconType' || t === 'IconName') {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file syntaxThemeChoices.ts
5+
* @input The value of a syntax-theme prop and whether the prop is required
6+
* @output The preset choices the playground offers, the selected choice, the
7+
* value a choice sends, and the name of the preset a value is
8+
* @position Logic of the playground's syntax-theme control
9+
* (PlaygroundPropsTable)
10+
*/
11+
12+
import {allSyntaxPresets} from '@astryxdesign/core/theme/syntax';
13+
14+
/** The choice that leaves an optional syntax-theme prop unset. */
15+
export const NO_SYNTAX_THEME = 'None';
16+
17+
const presets = allSyntaxPresets.map(theme => ({
18+
value: theme.name,
19+
label: theme.name
20+
.split('-')
21+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
22+
.join(' '),
23+
theme,
24+
}));
25+
26+
/**
27+
* The presets, with a first choice that leaves the prop unset when the prop
28+
* is optional. An unset prop keeps the theme-level syntax colors.
29+
*/
30+
export function syntaxThemeChoices(
31+
isRequired: boolean,
32+
): {value: string; label: string}[] {
33+
const choices = presets.map(({value, label}) => ({value, label}));
34+
return isRequired
35+
? choices
36+
: [{value: NO_SYNTAX_THEME, label: NO_SYNTAX_THEME}, ...choices];
37+
}
38+
39+
/** The choice that shows `value`. */
40+
export function selectedSyntaxTheme(
41+
value: unknown,
42+
isRequired: boolean,
43+
): string {
44+
const match = presets.find(
45+
option =>
46+
option.theme === value ||
47+
(value != null &&
48+
typeof value === 'object' &&
49+
'name' in value &&
50+
option.theme.name === value.name),
51+
);
52+
if (match) {
53+
return match.value;
54+
}
55+
return isRequired ? presets[0].value : NO_SYNTAX_THEME;
56+
}
57+
58+
/**
59+
* The name of the preset `value` is, such as "one-dark-pro"; null when
60+
* `value` is not a preset.
61+
*/
62+
export function syntaxPresetName(value: unknown): string | null {
63+
return presets.find(option => option.theme === value)?.value ?? null;
64+
}
65+
66+
/** The value a choice sends: a preset, or nothing for the unset choice. */
67+
export function syntaxThemeFor(choice: string): unknown {
68+
return presets.find(option => option.value === choice)?.theme;
69+
}

‎docs/specs/components/Toast/Toast.spec.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ This table is a review projection; the body below is authoritative.
7070
Toast shows brief, non-modal notifications. This record covers the toast card
7171
(`Toast`), the viewport that stacks, hosts, and announces toasts
7272
(`ToastViewport`, which has no consumer doc of its own), and the behavior the
73-
`useToast` show function drives. Consumer usage lives in `Toast.doc.mjs`.
73+
`useToast` show function drives. Consumer usage lives in `Toast.doc.mjs` (the
74+
card) and `useToast.doc.mjs` (the show function).
7475

7576
## Compatibility and migration
7677

‎packages/cli/test/core-prop-docs.known-drift.json‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@
4141
"src/TimeInput/TimeInput.doc.mjs TimeInput.controlClassName not_in_doc",
4242
"src/TimeInput/TimeInput.doc.mjs TimeInput.controlStyle not_in_doc",
4343
"src/TimeInput/TimeInput.doc.mjs TimeInput.hasAutoFocus not_in_doc",
44-
"src/Toast/Toast.doc.mjs Toast.autoHideDuration required_mismatch",
45-
"src/Toast/Toast.doc.mjs Toast.collisionBehavior not_in_code",
46-
"src/Toast/Toast.doc.mjs Toast.isAutoHide required_mismatch",
47-
"src/Toast/Toast.doc.mjs Toast.onHide not_in_code",
4844
"src/Toast/Toast.doc.mjs Toast.type required_mismatch",
49-
"src/Toast/Toast.doc.mjs Toast.uniqueID not_in_code",
5045
"src/Tokenizer/Tokenizer.doc.mjs Tokenizer.onKeyDown not_in_doc",
5146
"src/Tooltip/Tooltip.doc.mjs Tooltip.content required_mismatch",
5247
"src/TopNav/TopNavHeading.doc.mjs TopNavHeading.logoLabel not_in_doc",

‎packages/core/src/AlertDialog/useImperativeAlertDialog.doc.mjs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export const docs = {
66
name: 'useImperativeAlertDialog',
77
subComponentOf: 'AlertDialog',
88
displayName: 'useImperativeAlertDialog',
9-
description: 'Hook for showing an alert dialog without managing open state. Call alert.show(options) to open and alert.hide() to close. Render alert.element in your JSX tree.',
9+
description:
10+
'Hook for showing an alert dialog without managing open state. Call alert.show(options) to open and alert.hide() to close. Render alert.element in your JSX tree.',
1011
props: [
1112
{
1213
name: 'show',
13-
type: '(options: AlertDialogOptions) => void',
14-
description: 'Show the alert dialog with the given options. Options are the same as AlertDialog props minus isOpen/onOpenChange.',
14+
type: "(options: Omit<AlertDialogProps, 'isOpen' | 'onOpenChange'>) => void",
15+
description:
16+
'Show the alert dialog with the given options. Options are the same as AlertDialog props minus isOpen/onOpenChange.',
1517
},
1618
{
1719
name: 'hide',
@@ -33,7 +35,8 @@ export const docs = {
3335

3436
export const docsDense = {
3537
name: 'useImperativeAlertDialog',
36-
description: 'Hook to show alert dialog w/o managing open state. Call alert.show(options) to open, alert.hide() to close; render alert.element in JSX tree.',
38+
description:
39+
'Hook to show alert dialog w/o managing open state. Call alert.show(options) to open, alert.hide() to close; render alert.element in JSX tree.',
3740
propDescriptions: {
3841
show: 'show dialog w/ options; same as AlertDialog props minus isOpen/onOpenChange',
3942
hide: 'hide dialog',

0 commit comments

Comments
 (0)