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: Adds story for Spacing-sizes-control. #68339

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

vipul0425
Copy link
Contributor

@vipul0425 vipul0425 commented Dec 27, 2024

What?

This PR adds story for SpacingSizesControl component.

Why?

Part of: #67165

Testing Instructions

  1. Start Storybook by running npm run storybook:dev
  2. Open Storybook at http://localhost:50240/
  3. Test the story for SpacingSizesControl

Screenshots or screencast

Screen.Recording.2024-12-27.at.1.52.15.PM.mov

@vipul0425 vipul0425 marked this pull request as ready for review December 27, 2024 08:23
@vipul0425 vipul0425 requested a review from ellatrix as a code owner December 27, 2024 08:23
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: vipul0425 <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

Thanks for the work on this. Seems like a good start. In testing, I found that when switching to a size preset the component currently errors (I left a specific comment about that). Once that’s fixed and switching to presets works, there aren’t any available since the component depends on getting them from the block editor store. I'm including a diff here that makes some presets available and includes a fix for the error I mentioned earlier.

Add presets and update values prop
diff --git a/packages/block-editor/src/components/spacing-sizes-control/stories/index.story.js b/packages/block-editor/src/components/spacing-sizes-control/stories/index.story.js
index 2716bb3fa9..921070855c 100644
--- a/packages/block-editor/src/components/spacing-sizes-control/stories/index.story.js
+++ b/packages/block-editor/src/components/spacing-sizes-control/stories/index.story.js
@@ -7,10 +7,46 @@ import { useState } from '@wordpress/element';
  * Internal dependencies
  */
 import SpacingSizesControl from '../';
+import { ExperimentalBlockEditorProvider } from '../../provider';
 
 const meta = {
 	title: 'BlockEditor/SpacingSizesControl',
 	component: SpacingSizesControl,
+	// The component depends on block-editor store state for size presets so the
+	// provider is required to supply those.
+	decorators: [
+		( Story ) => (
+			<ExperimentalBlockEditorProvider
+				settings={ {
+					__experimentalFeatures: {
+						spacing: {
+							spacingSizes: {
+								default: [
+									{
+										name: 'Small',
+										slug: '40',
+										size: '1rem',
+									},
+									{
+										name: 'Medium',
+										slug: '50',
+										size: '1.5rem',
+									},
+									{
+										name: 'Large',
+										slug: '60',
+										size: '2.25rem',
+									},
+								],
+							},
+						},
+					},
+				} }
+			>
+				<Story />
+			</ExperimentalBlockEditorProvider>
+		),
+	],
 	argTypes: {
 		label: {
 			control: 'text',
@@ -114,10 +150,10 @@ export const Default = {
 	args: {
 		label: 'Padding',
 		values: {
-			top: 10,
-			right: 12,
-			bottom: 23,
-			left: 25,
+			top: '10px',
+			right: '1.5rem',
+			bottom: '2em',
+			left: '12px',
 		},
 		minimumCustomValue: 0,
 		sides: [ 'top', 'right', 'bottom', 'left' ],

Comment on lines +117 to +120
top: 10,
right: 12,
bottom: 23,
left: 25,
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing this out I found that these need to be strings or the component errors when switching one of the sides to use a size preset. I think too it’s probably better to actual provide a unit as well, e.g. '10px'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storybook Storybook and its stories for components [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants