-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storybook: Support proper extraction of TypeScript prop types (#38842)
* Export WordPressComponent types properly * Expand code by default in Docs tab * Heading: Use unconnected component for extraction Export unconnected `Heading` * Heading: Tweak story for Controls * Divider: Extract types for stories * Divider: Tweak story for "all Controls" view * Convert contextConnect to TS * Heading: Simply named export connected component * Heading: Export with correct name This is required for the code snippets to show the correct component name. * Heading: Fix doc comment * Divider: Rejigger exports * Storybook: Allow tsx stories * Heading: Convert story to TS * Divider: Convert story to TS * Replace Emotion with inline style * Move source expansion setting to per-component * Remove `unstable_system` prop from types * Text: Remove extraneous type alias * Enforce TS checks on ComponentMeta argTypes * Don't exclude tsx stories from type check * Improve prop sorting `requiredFirst` seems to also sort the rest of the props alphabetically 🎉 * Add more control type hints * Add JSDoc description for `as` prop * Change `Ref` to `ForwardedRef` * Clarify `as` prop comment
- Loading branch information
Showing
14 changed files
with
159 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Text } from '../../text'; | ||
import { Divider } from '..'; | ||
|
||
const meta: ComponentMeta< typeof Divider > = { | ||
component: Divider, | ||
title: 'Components (Experimental)/Divider', | ||
argTypes: { | ||
margin: { | ||
control: { type: 'number' }, | ||
}, | ||
marginStart: { | ||
control: { type: 'number' }, | ||
}, | ||
marginEnd: { | ||
control: { type: 'number' }, | ||
}, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
const HorizontalTemplate: ComponentStory< typeof Divider > = ( args ) => ( | ||
<div> | ||
<Text>Some text before the divider</Text> | ||
<Divider { ...args } /> | ||
<Text>Some text after the divider</Text> | ||
</div> | ||
); | ||
|
||
const VerticalTemplate: ComponentStory< typeof Divider > = ( args ) => { | ||
const styles = { | ||
display: 'flex', | ||
alignItems: 'stretch', | ||
justifyContent: 'start', | ||
}; | ||
|
||
return ( | ||
<div style={ styles }> | ||
<Text>Some text before the divider</Text> | ||
<Divider { ...args } /> | ||
<Text>Some text after the divider</Text> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Horizontal: ComponentStory< | ||
typeof Divider | ||
> = HorizontalTemplate.bind( {} ); | ||
Horizontal.args = { | ||
margin: 2, | ||
}; | ||
|
||
export const Vertical: ComponentStory< typeof Divider > = VerticalTemplate.bind( | ||
{} | ||
); | ||
Vertical.args = { | ||
...Horizontal.args, | ||
orientation: 'vertical', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Heading } from '..'; | ||
|
||
const meta: ComponentMeta< typeof Heading > = { | ||
component: Heading, | ||
title: 'Components (Experimental)/Heading', | ||
argTypes: { | ||
adjustLineHeightForInnerControls: { control: { type: 'text' } }, | ||
as: { control: { type: 'text' } }, | ||
color: { control: { type: 'color' } }, | ||
display: { control: { type: 'text' } }, | ||
letterSpacing: { control: { type: 'text' } }, | ||
lineHeight: { control: { type: 'text' } }, | ||
optimizeReadabilityFor: { control: { type: 'color' } }, | ||
variant: { control: { type: 'radio' }, options: [ 'muted' ] }, | ||
weight: { control: { type: 'text' } }, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
export const Default: ComponentStory< typeof Heading > = ( props ) => ( | ||
<Heading { ...props } /> | ||
); | ||
Default.args = { | ||
children: 'Heading', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.