Skip to content
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

ResizableBox: Remove knobs in stories #46774

Merged
merged 6 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably hide children's control, as it currently shows a react object that can't really be edited

Copy link
Member Author

Choose a reason for hiding this comment

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

True 👍

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,
Comment on lines +50 to +51
Copy link
Member Author

Choose a reason for hiding this comment

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

The parseInt() that used to be here turned out to be unnecessary. Thanks TypeScript 🙏

} );
} }
/>
);
};

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,
},
};