Skip to content

Commit

Permalink
BoxControl: Update story and refactor to Typescript (WordPress#56462)
Browse files Browse the repository at this point in the history
* BoxControl: Update story and refactor to Typescript

* Cleanup and refine story based on feedback

* Add Uncontrolled and Controlled templates and Controlled example

* Remove default values and fix values control
  • Loading branch information
brookewp authored Nov 25, 2023
1 parent cea885c commit 5d86605
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 75 deletions.
75 changes: 0 additions & 75 deletions packages/components/src/box-control/stories/index.story.js

This file was deleted.

82 changes: 82 additions & 0 deletions packages/components/src/box-control/stories/index.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* External dependencies
*/
import type { Meta, StoryFn } from '@storybook/react';

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import BoxControl from '../';

const meta: Meta< typeof BoxControl > = {
title: 'Components (Experimental)/BoxControl',
component: BoxControl,
argTypes: {
values: { control: { type: null } },
},
parameters: {
actions: { argTypesRegex: '^on.*' },
controls: { expanded: true },
docs: { canvas: { sourceState: 'shown' } },
},
};
export default meta;

const TemplateUncontrolled: StoryFn< typeof BoxControl > = ( props ) => {
return <BoxControl { ...props } />;
};

const TemplateControlled: StoryFn< typeof BoxControl > = ( props ) => {
const [ values, setValues ] = useState< ( typeof props )[ 'values' ] >();

return (
<BoxControl
values={ values }
{ ...props }
onChange={ ( nextValue ) => {
setValues( nextValue );
props.onChange?.( nextValue );
} }
/>
);
};

export const Default = TemplateUncontrolled.bind( {} );
Default.args = {
label: 'Label',
};

export const Controlled = TemplateControlled.bind( {} );
Controlled.args = {
...Default.args,
};

export const ArbitrarySides = TemplateControlled.bind( {} );
ArbitrarySides.args = {
...Default.args,
sides: [ 'top', 'bottom' ],
};

export const SingleSide = TemplateControlled.bind( {} );
SingleSide.args = {
...Default.args,
sides: [ 'bottom' ],
};

export const AxialControls = TemplateControlled.bind( {} );
AxialControls.args = {
...Default.args,
splitOnAxis: true,
};

export const AxialControlsWithSingleSide = TemplateControlled.bind( {} );
AxialControlsWithSingleSide.args = {
...Default.args,
sides: [ 'horizontal' ],
splitOnAxis: true,
};

0 comments on commit 5d86605

Please sign in to comment.