Repository navigation
docs(core): prop types name only types the package exports; Toast's doc marks the card's timing props required #12337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c20b58a
03c20f5
305b2de
b0a864e
503c1bc
f245db1
db93636
e015cee
83a4ebc
0db46bd
85268d7
f8552e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [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. | ||
|
|
||
| @cixzhang |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| import {allSyntaxPresets} from '@astryxdesign/core/theme/syntax'; | ||
| import {describe, expect, it} from 'vitest'; | ||
| import { | ||
| NO_SYNTAX_THEME, | ||
| selectedSyntaxTheme, | ||
| syntaxThemeChoices, | ||
| syntaxPresetName, | ||
| syntaxThemeFor, | ||
| } from '../components/component-detail/syntaxThemeChoices'; | ||
|
|
||
| describe('the playground syntax theme control', () => { | ||
| it('shows an unset optional prop as None, and None sends nothing', () => { | ||
| expect(syntaxThemeChoices(false)[0].value).toBe(NO_SYNTAX_THEME); | ||
| expect(selectedSyntaxTheme(undefined, false)).toBe(NO_SYNTAX_THEME); | ||
| expect(syntaxThemeFor(NO_SYNTAX_THEME)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('offers no None for a required prop, which shows the first preset', () => { | ||
| expect( | ||
| syntaxThemeChoices(true).some(choice => choice.value === NO_SYNTAX_THEME), | ||
| ).toBe(false); | ||
| expect(selectedSyntaxTheme(undefined, true)).toBe(allSyntaxPresets[0].name); | ||
| }); | ||
|
|
||
| it('shows and sends a chosen preset', () => { | ||
| const preset = allSyntaxPresets[1]; | ||
| expect(selectedSyntaxTheme(preset, false)).toBe(preset.name); | ||
| expect(syntaxThemeFor(preset.name)).toBe(preset); | ||
| }); | ||
|
|
||
| it('names the preset a value is', () => { | ||
| const dracula = allSyntaxPresets.find(theme => theme.name === 'dracula'); | ||
| const oneDarkPro = allSyntaxPresets.find( | ||
| theme => theme.name === 'one-dark-pro', | ||
| ); | ||
| expect(syntaxPresetName(dracula)).toBe('dracula'); | ||
| expect(syntaxPresetName(oneDarkPro)).toBe('one-dark-pro'); | ||
| expect(syntaxPresetName({name: 'dracula'})).toBeNull(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file syntaxThemeChoices.ts | ||
| * @input The value of a syntax-theme prop and whether the prop is required | ||
| * @output The preset choices the playground offers, the selected choice, the | ||
| * value a choice sends, and the name of the preset a value is | ||
| * @position Logic of the playground's syntax-theme control | ||
| * (PlaygroundPropsTable) | ||
| */ | ||
|
|
||
| import {allSyntaxPresets} from '@astryxdesign/core/theme/syntax'; | ||
|
|
||
| /** The choice that leaves an optional syntax-theme prop unset. */ | ||
| export const NO_SYNTAX_THEME = 'None'; | ||
|
|
||
| const presets = allSyntaxPresets.map(theme => ({ | ||
| value: theme.name, | ||
| label: theme.name | ||
| .split('-') | ||
| .map(part => part.charAt(0).toUpperCase() + part.slice(1)) | ||
| .join(' '), | ||
| theme, | ||
| })); | ||
|
|
||
| /** | ||
| * The presets, with a first choice that leaves the prop unset when the prop | ||
| * is optional. An unset prop keeps the theme-level syntax colors. | ||
| */ | ||
| export function syntaxThemeChoices( | ||
| isRequired: boolean, | ||
| ): {value: string; label: string}[] { | ||
| const choices = presets.map(({value, label}) => ({value, label})); | ||
| return isRequired | ||
| ? choices | ||
| : [{value: NO_SYNTAX_THEME, label: NO_SYNTAX_THEME}, ...choices]; | ||
| } | ||
|
|
||
| /** The choice that shows `value`. */ | ||
| export function selectedSyntaxTheme( | ||
| value: unknown, | ||
| isRequired: boolean, | ||
| ): string { | ||
| const match = presets.find( | ||
| option => | ||
| option.theme === value || | ||
| (value != null && | ||
| typeof value === 'object' && | ||
| 'name' in value && | ||
| option.theme.name === value.name), | ||
| ); | ||
| if (match) { | ||
| return match.value; | ||
| } | ||
| return isRequired ? presets[0].value : NO_SYNTAX_THEME; | ||
| } | ||
|
|
||
| /** | ||
| * The name of the preset `value` is, such as "one-dark-pro"; null when | ||
| * `value` is not a preset. | ||
| */ | ||
| export function syntaxPresetName(value: unknown): string | null { | ||
| return presets.find(option => option.theme === value)?.value ?? null; | ||
| } | ||
|
|
||
| /** The value a choice sends: a preset, or nothing for the unset choice. */ | ||
| export function syntaxThemeFor(choice: string): unknown { | ||
| return presets.find(option => option.value === choice)?.theme; | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,12 +41,7 @@ | |
| "src/TimeInput/TimeInput.doc.mjs TimeInput.controlClassName not_in_doc", | ||
| "src/TimeInput/TimeInput.doc.mjs TimeInput.controlStyle not_in_doc", | ||
| "src/TimeInput/TimeInput.doc.mjs TimeInput.hasAutoFocus not_in_doc", | ||
| "src/Toast/Toast.doc.mjs Toast.autoHideDuration required_mismatch", | ||
| "src/Toast/Toast.doc.mjs Toast.collisionBehavior not_in_code", | ||
| "src/Toast/Toast.doc.mjs Toast.isAutoHide required_mismatch", | ||
| "src/Toast/Toast.doc.mjs Toast.onHide not_in_code", | ||
| "src/Toast/Toast.doc.mjs Toast.type required_mismatch", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entry stays, so the description's Testing line "Core's docs now match Core's props for Toast" is broader than the change: |
||
| "src/Toast/Toast.doc.mjs Toast.uniqueID not_in_code", | ||
| "src/Tokenizer/Tokenizer.doc.mjs Tokenizer.onKeyDown not_in_doc", | ||
| "src/Tooltip/Tooltip.doc.mjs Tooltip.content required_mismatch", | ||
| "src/TopNav/TopNavHeading.doc.mjs TopNavHeading.logoLabel not_in_doc", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test reaches this branch:
syntax-theme-control.test.ts:33-41now checks only thatsyntaxPresetNamereturns'one-dark-pro', andinteractive-preview.test.ts:31mocksallSyntaxPresetsas[]. With this line changed toreturn syntaxPreset;every docsite test still passes while Show code printssyntaxTheme={one-dark-pro}, so the description's "cover these" does not hold for Show code. A case that picks a preset and expectssyntaxTheme={oneDarkPro}in Show code would pin it; otherwise narrow that sentence to the picker and the None choice.