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

Storybook: Add stories for ImageSizeControl Component #68285

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

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

const meta = {
title: 'BlockEditor/ImageSizeControl',
component: ImageSizeControl,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'Allow users to control the width & height of an image.',
},
},
},
argTypes: {
imageSizeHelp: {
control: 'text',
description:
'If this property is added, a help text will be generated for the image size control, using imageSizeHelp property as the content.',
table: {
type: { summary: 'string|element' },
},
},
slug: {
control: 'text',
description:
'The currently-selected image size slug (`thumbnail`, `large`, etc). This is used by the parent component to get the specific image, which is used to populate `imageHeight` & `imageWidth`. This is not required, but necessary when `imageSizeOptions` is used.',
table: {
type: { summary: 'string' },
},
},
height: {
control: { type: null },
description: 'The height of the image when displayed.',
table: {
type: { summary: 'number' },
},
},
width: {
control: { type: null },
description: 'The width of the image when displayed.',
table: {
type: { summary: 'number' },
},
},
onChange: {
action: 'onChange',
control: { type: null },
description:
'The function called when the image size changes. It is passed an object with `{ width, height }` (potentially just one if only one dimension changed).',
table: {
type: { summary: 'function' },
},
},
onChangeImage: {
action: 'onChangeImage',
control: { type: null },
description:
'The function called when a new image size is selected. It is passed the `slug` as an argument. This is not required, but necessary when `imageSizeOptions` is used.',
table: {
type: { summary: 'function' },
},
},
imageSizeOptions: {
control: 'object',
description:
'Array of image size slugs and labels. If not provided, the "Image Size" dropdown is not displayed.',
table: {
type: { summary: 'object' },
},
},
isResizable: {
control: 'boolean',
description:
'A boolean control for showing the resize fields "Image Dimensions". Set this to false if you want images to always be the fixed size of the selected image.',
table: {
type: { summary: 'boolean' },
},
},
imageWidth: {
control: 'number',
description:
"The width of the currently selected image, used for calculating the percentage sizes. This will likely be updated when the image size slug changes, but does not control the image display (that's the `width` prop).",
table: {
type: { summary: 'number' },
},
},
imageHeight: {
control: 'number',
description:
"The height of the currently selected image, used for calculating the percentage sizes. This will likely be updated when the image size slug changes, but does not control the image display (that's the `height` prop).",
table: {
type: { summary: 'number' },
},
},
},
};

export default meta;

export const Default = {
args: {
imageWidth: 100,
imageHeight: 100,
imageSizeOptions: [
{ value: 'thumbnail', label: 'Thumbnail' },
{ value: 'medium', label: 'Medium' },
{ value: 'large', label: 'Large' },
],
isResizable: true,
},
render: function Template( { onChange, onChangeImage, ...args } ) {
const [ size, setSize ] = useState( { width: null, height: null } );
return (
<ImageSizeControl
{ ...args }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setSize( ...changeArgs );
} }
onChangeImage={ ( ...changeArgs ) => {
onChangeImage( ...changeArgs );
} }
width={ size.width }
height={ size.height }
/>
);
},
};
Loading