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

Add FontSizePicker component to Storybook #18149

Merged
merged 2 commits into from
Oct 31, 2019
Merged
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
107 changes: 107 additions & 0 deletions packages/components/src/font-size-picker/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* External dependencies
*/
import { number, object } from '@storybook/addon-knobs';

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

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

export default { title: 'FontSizePicker', component: FontSizePicker };

const FontSizePickerWithState = ( { ...props } ) => {
brentswisher marked this conversation as resolved.
Show resolved Hide resolved
const [ fontSize, setFontSize ] = useState( 16 );
Copy link
Member

Choose a reason for hiding this comment

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

Actually, you could use knobs with the value and the fontSizes. This way folks could play with the default font size and all the possible font sizes provided. What do you think? @ItsJonQ will be able to help if that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the fontSizes to a knob, but the value I left as it was. The default 16 is only used on page load, after which point the state takes over. Since changing a knob doesn't reload the component in storybook, there wouldn't be any point in making the value a knob. Because changing it wouldn't reload the component, and reloading the page would reset it to the initial value. Unless I am mistaken about something? (Which is entirely possible 😄 )

Copy link
Member

Choose a reason for hiding this comment

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

I gave it a spin and you are 100% correct. It isn't entirely what I assumed 🙂

Let's leave it as is. I need to double-check other stories and update those which set the initial state with knobs as it doesn't reload as you pointed out.


return (
<FontSizePicker
{ ...props }
value={ fontSize }
onChange={ setFontSize }
/>
);
};

export const _default = () => {
const fontSizes = object( 'Font Sizes', [
{
name: 'Small',
slug: 'small',
size: 12,
},
{
name: 'Normal',
slug: 'normal',
size: 16,
},
{
name: 'Big',
slug: 'big',
size: 26,
},
] );
return (
<FontSizePickerWithState
fontSizes={ fontSizes }
/>
);
};

export const withSlider = () => {
const fontSizes = object( 'Font Sizes', [
{
name: 'Small',
slug: 'small',
size: 12,
},
{
name: 'Normal',
slug: 'normal',
size: 16,
},
{
name: 'Big',
slug: 'big',
size: 26,
},
] );
const fallbackFontSize = number( 'Fallback Font Size - Slider Only', 16 );
return (
<FontSizePickerWithState
fontSizes={ fontSizes }
fallbackFontSize={ fallbackFontSize }
withSlider
/>
);
};

export const withoutCustomSizes = () => {
const fontSizes = object( 'Font Sizes', [
{
name: 'Small',
slug: 'small',
size: 12,
},
{
name: 'Normal',
slug: 'normal',
size: 16,
},
{
name: 'Big',
slug: 'big',
size: 26,
},
] );
return (
<FontSizePickerWithState
fontSizes={ fontSizes }
disableCustomFontSizes
/>
);
};