-
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.
BorderBoxControl: Refactor stories to TypeScript and Controls (#45002)
- Loading branch information
1 parent
91b2a2e
commit 1cff757
Showing
5 changed files
with
154 additions
and
118 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 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
106 changes: 0 additions & 106 deletions
106
packages/components/src/border-box-control/stories/index.js
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
packages/components/src/border-box-control/stories/index.tsx
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,92 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import type { ComponentProps } from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from '../../button'; | ||
import Popover from '../../popover'; | ||
import { BorderBoxControl } from '../'; | ||
import { Provider as SlotFillProvider } from '../../slot-fill'; | ||
|
||
const meta: ComponentMeta< typeof BorderBoxControl > = { | ||
title: 'Components (Experimental)/BorderBoxControl', | ||
component: BorderBoxControl, | ||
argTypes: { | ||
onChange: { action: 'onChange' }, | ||
value: { control: { type: null } }, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
// Available border colors. | ||
const colors = [ | ||
{ name: 'Blue 20', color: '#72aee6' }, | ||
{ name: 'Blue 40', color: '#3582c4' }, | ||
{ name: 'Red 40', color: '#e65054' }, | ||
{ name: 'Red 70', color: '#8a2424' }, | ||
{ name: 'Yellow 10', color: '#f2d675' }, | ||
{ name: 'Yellow 40', color: '#bd8600' }, | ||
]; | ||
|
||
const Template: ComponentStory< typeof BorderBoxControl > = ( props ) => { | ||
const { onChange, ...otherProps } = props; | ||
const [ borders, setBorders ] = useState< typeof props[ 'value' ] >(); | ||
|
||
const onChangeMerged: ComponentProps< | ||
typeof BorderBoxControl | ||
>[ 'onChange' ] = ( newBorders ) => { | ||
setBorders( newBorders ); | ||
onChange( newBorders ); | ||
}; | ||
|
||
return ( | ||
<SlotFillProvider> | ||
<div style={ { maxWidth: '248px', padding: '16px' } }> | ||
<BorderBoxControl | ||
{ ...otherProps } | ||
onChange={ onChangeMerged } | ||
value={ borders } | ||
/> | ||
</div> | ||
<hr | ||
style={ { | ||
marginTop: '100px', | ||
borderColor: '#ddd', | ||
borderStyle: 'solid', | ||
borderBottom: 'none', | ||
} } | ||
/> | ||
<p style={ { color: '#aaa', fontSize: '0.9em' } }> | ||
The BorderBoxControl is intended to be used within a component | ||
that will provide reset controls. The button below is only for | ||
convenience. | ||
</p> | ||
<Button | ||
variant="primary" | ||
onClick={ () => onChangeMerged( undefined ) } | ||
> | ||
Reset | ||
</Button> | ||
{ /* @ts-expect-error Ignore until Popover.Slot is converted to TS */ } | ||
<Popover.Slot /> | ||
</SlotFillProvider> | ||
); | ||
}; | ||
export const Default = Template.bind( {} ); | ||
Default.args = { | ||
colors, | ||
label: 'Borders', | ||
}; |
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