Skip to content

Commit

Permalink
ResizableBox: Remove knobs in stories (#46774)
Browse files Browse the repository at this point in the history
* ResizableBox: Remove knobs in stories

* Show more props from types

* Remove unimportant prop controls

* Always enable `enable` prop

* Remove `parseInt()` from readme code snippet

* Hide control for `children` prop
  • Loading branch information
mirka committed Jan 6, 2023
1 parent 59ce2c8 commit 9f54821
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 105 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/resizable-box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const Edit = ( props ) => {
} }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
height: parseInt( height + delta.height, 10 ),
width: parseInt( width + delta.width, 10 ),
height: height + delta.height,
width: width + delta.width,
} );
toggleSelection( true );
} }
Expand Down
13 changes: 7 additions & 6 deletions packages/components/src/resizable-box/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ const HANDLE_STYLES = {
};

type ResizableBoxProps = ResizableProps & {
className: string;
children: ReactNode;
showHandle: boolean;
__experimentalShowTooltip: boolean;
__experimentalTooltipProps: Parameters< typeof ResizeTooltip >[ 0 ];
showHandle?: boolean;
__experimentalShowTooltip?: boolean;
__experimentalTooltipProps?: Parameters< typeof ResizeTooltip >[ 0 ];
};

function ResizableBox(
function UnforwardedResizableBox(
{
className,
children,
Expand Down Expand Up @@ -124,4 +123,6 @@ function ResizableBox(
);
}

export default forwardRef( ResizableBox );
export const ResizableBox = forwardRef( UnforwardedResizableBox );

export default ResizableBox;
97 changes: 0 additions & 97 deletions packages/components/src/resizable-box/stories/index.js

This file was deleted.

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

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

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

const meta: ComponentMeta< typeof ResizableBox > = {
title: 'Components/ResizableBox',
component: ResizableBox,
argTypes: {
children: { control: { type: null } },
enable: { control: 'object' },
onResizeStop: { action: 'onResizeStop' },
},
parameters: {
controls: { expanded: true },
docs: { source: { state: 'open' } },
},
};
export default meta;

const Template: ComponentStory< typeof ResizableBox > = ( {
onResizeStop,
...props
} ) => {
const [ { height, width }, setAttributes ] = useState( {
height: 200,
width: 400,
} );

return (
<ResizableBox
{ ...props }
size={ {
height,
width,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
onResizeStop?.( event, direction, elt, delta );
setAttributes( {
height: height + delta.height,
width: width + delta.width,
} );
} }
/>
);
};

export const Default = Template.bind( {} );
Default.args = {
children: (
<div
style={ {
background: '#eee',
display: 'flex',
height: '100%',
width: '100%',
alignItems: 'center',
justifyContent: 'center',
} }
>
Resize
</div>
),
};

/**
* The `enable` prop can be used to disable resizing in specific directions.
*/
export const DisabledDirections = Template.bind( {} );
DisabledDirections.args = {
...Default.args,
enable: {
top: false,
right: true,
bottom: true,
left: false,
topRight: false,
bottomRight: true,
bottomLeft: false,
topLeft: false,
},
};

1 comment on commit 9f54821

@github-actions
Copy link

@github-actions github-actions bot commented on 9f54821 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9f54821.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3857781982
📝 Reported issues:

Please sign in to comment.