From 7a62af0cb8a280b53c0e26b6da8d0e74f04ee2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Thu, 24 Oct 2019 23:10:09 +0200 Subject: [PATCH] Storybook: Apply a set of enhancements to the existing stories (#18030) * Storybook: Apply a set of enhancements to the existing stories * Add basic knobs integration to all Button stories --- .../src/button-group/stories/index.js | 2 +- .../components/src/button/stories/index.js | 93 ++++++++++++++----- .../src/checkbox-control/stories/index.js | 29 ++++-- .../src/clipboard-button/stories/index.js | 29 ++++-- .../src/icon-button/stories/index.js | 17 +++- packages/components/src/icon/stories/index.js | 24 +++-- .../src/scroll-lock/stories/index.js | 2 +- 7 files changed, 150 insertions(+), 46 deletions(-) diff --git a/packages/components/src/button-group/stories/index.js b/packages/components/src/button-group/stories/index.js index 1e1646e0268d1..8b1a694691025 100644 --- a/packages/components/src/button-group/stories/index.js +++ b/packages/components/src/button-group/stories/index.js @@ -4,7 +4,7 @@ import Button from '../../button'; import ButtonGroup from '../'; -export default { title: 'Button Group', component: ButtonGroup }; +export default { title: 'ButtonGroup', component: ButtonGroup }; export const _default = () => { const style = { margin: '0 4px' }; diff --git a/packages/components/src/button/stories/index.js b/packages/components/src/button/stories/index.js index ae949a1cd7290..b3c3b408c373e 100644 --- a/packages/components/src/button/stories/index.js +++ b/packages/components/src/button/stories/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { text } from '@storybook/addon-knobs'; + /** * Internal dependencies */ @@ -5,32 +10,78 @@ import Button from '../'; export default { title: 'Button', component: Button }; -export const _default = () => ; +export const _default = () => { + const label = text( 'Label', 'Default Button' ); + + return ( + + ); +}; + +export const primary = () => { + const label = text( 'Label', 'Primary Button' ); + + return ( + + ); +}; + +export const large = () => { + const label = text( 'Label', 'Large Button' ); + + return ( + + ); +}; + +export const largePrimary = () => { + const label = text( 'Label', 'Large Primary Button' ); + + return ( + + ); +}; + +export const small = () => { + const label = text( 'Label', 'Small Button' ); + + return ( + + ); +}; -export const primary = () => ; +export const toggled = () => { + const label = text( 'Label', 'Toggled Button' ); -export const large = () => ; + return ( + + ); +}; -export const largePrimary = () => ( - -); +export const disabled = () => { + const label = text( 'Label', 'Disabled Button' ); -export const small = () => ; + return ( + + ); +}; -export const toggled = () => ; +export const link = () => { + const label = text( 'Label', 'Link Button' ); -export const disabled = () => ; + return ( + + ); +}; -export const link = () => ( - -); +export const disabledLink = () => { + const label = text( 'Label', 'Disabled Link Button' ); -export const disabledLink = () => ( - -); + return ( + + ); +}; diff --git a/packages/components/src/checkbox-control/stories/index.js b/packages/components/src/checkbox-control/stories/index.js index 184abbfe8b161..40b48ccf3ef3a 100644 --- a/packages/components/src/checkbox-control/stories/index.js +++ b/packages/components/src/checkbox-control/stories/index.js @@ -13,31 +13,42 @@ import { useState } from '@wordpress/element'; */ import CheckboxControl from '../'; -export default { title: 'Checkbox Control', component: CheckboxControl }; +export default { title: 'CheckboxControl', component: CheckboxControl }; + +const CheckboxControlWithState = ( { checked, ...props } ) => { + const [ isChecked, setChecked ] = useState( checked ); -export const _default = () => { - const [ isChecked, setChecked ] = useState( true ); return ( ); }; -export const All = () => { - const [ isChecked, setChecked ] = useState( true ); +export const _default = () => { + const label = text( 'Label', 'Is author' ); + + return ( + + ); +}; + +export const all = () => { const heading = text( 'Heading', 'User' ); const label = text( 'Label', 'Is author' ); const help = text( 'Help', 'Is the user an author or not?' ); + return ( - ); }; diff --git a/packages/components/src/clipboard-button/stories/index.js b/packages/components/src/clipboard-button/stories/index.js index 25632614eb249..7e0146448d56d 100644 --- a/packages/components/src/clipboard-button/stories/index.js +++ b/packages/components/src/clipboard-button/stories/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { boolean, text } from '@storybook/addon-knobs'; + /** * WordPress dependencies */ @@ -8,18 +13,30 @@ import { useState } from '@wordpress/element'; */ import ClipboardButton from '../'; -export default { title: 'Clipboard Button', component: ClipboardButton }; +export default { title: 'ClipboardButton', component: ClipboardButton }; + +const ClipboardButtonWithState = ( { copied, ...props } ) => { + const [ isCopied, setCopied ] = useState( copied ); -export const _default = () => { - const [ copied, setCopied ] = useState( false ); return ( setCopied( true ) } onFinishCopy={ () => setCopied( false ) } > - { copied ? 'Copied!' : 'Copy "Text"' } + { isCopied ? 'Copied!' : `Copy "${ props.text }"` } ); }; + +export const _default = () => { + const isPrimary = boolean( 'Is primary', true ); + const copyText = text( 'Text', 'Text' ); + + return ( + + ); +}; diff --git a/packages/components/src/icon-button/stories/index.js b/packages/components/src/icon-button/stories/index.js index d093876a20e0a..b5c4275159dc5 100644 --- a/packages/components/src/icon-button/stories/index.js +++ b/packages/components/src/icon-button/stories/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { text } from '@storybook/addon-knobs'; + /** * Internal dependencies */ @@ -5,7 +10,17 @@ import IconButton from '../'; export default { title: 'IconButton', component: IconButton }; -export const _default = () => ; +export const _default = () => { + const icon = text( 'Icon', 'ellipsis' ); + const label = text( 'Label', 'More' ); + + return ( + + ); +}; export const grouped = () => { const GroupContainer = ( { children } ) => ( diff --git a/packages/components/src/icon/stories/index.js b/packages/components/src/icon/stories/index.js index be4e9fed65787..f2cd8bee1839b 100644 --- a/packages/components/src/icon/stories/index.js +++ b/packages/components/src/icon/stories/index.js @@ -1,19 +1,29 @@ +/** + * External dependencies + */ +import { number, text } from '@storybook/addon-knobs'; + /** * Internal dependencies */ import Icon from '../'; -import { SVG, Path } from '../../'; +import { SVG, Path } from '../../primitives/svg'; export default { title: 'Icon', component: Icon }; const IconSizeLabel = ( { size } ) =>
{ size }px
; -export const _default = () => ( -
- - -
-); +export const _default = () => { + const icon = text( 'Icon', 'screenoptions' ); + const size = number( 'Size', '24' ); + + return ( +
+ + +
+ ); +}; export const sizes = () => { const iconSizes = [ 14, 16, 20, 24, 28, 32, 40, 48, 56 ]; diff --git a/packages/components/src/scroll-lock/stories/index.js b/packages/components/src/scroll-lock/stories/index.js index 865fb6a7e909b..20ef27337fc78 100644 --- a/packages/components/src/scroll-lock/stories/index.js +++ b/packages/components/src/scroll-lock/stories/index.js @@ -6,7 +6,7 @@ import { useState } from '@wordpress/element'; /** * Internal dependencies */ -import { Button } from '../../'; +import Button from '../../button'; import ScrollLock from '../'; export default { title: 'ScrollLock', component: ScrollLock };