From 38dd3016feb63f932f2423a4f58bc856c27d9f67 Mon Sep 17 00:00:00 2001 From: Copons Date: Wed, 23 Sep 2020 17:10:51 +0200 Subject: [PATCH 1/4] Split Navigation component stories to improve their consumption --- .../navigation/stories/controlled-state.js | 123 ++++++++++ .../src/navigation/stories/default.js | 71 ++++++ .../src/navigation/stories/index.js | 211 ++---------------- .../src/navigation/stories/more-examples.js | 38 ++++ .../src/navigation/stories/style.css | 14 ++ 5 files changed, 260 insertions(+), 197 deletions(-) create mode 100644 packages/components/src/navigation/stories/controlled-state.js create mode 100644 packages/components/src/navigation/stories/default.js create mode 100644 packages/components/src/navigation/stories/more-examples.js create mode 100644 packages/components/src/navigation/stories/style.css diff --git a/packages/components/src/navigation/stories/controlled-state.js b/packages/components/src/navigation/stories/controlled-state.js new file mode 100644 index 00000000000000..b9619769e9148c --- /dev/null +++ b/packages/components/src/navigation/stories/controlled-state.js @@ -0,0 +1,123 @@ +/** + * WordPress dependencies + */ +import { Button } from '@wordpress/components'; +import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import Navigation from '..'; +import NavigationItem from '../item'; +import NavigationMenu from '../menu'; + +export function ControlledStateStory() { + const [ activeItem, setActiveItem ] = useState( 'item-1' ); + const [ activeMenu, setActiveMenu ] = useState( 'root' ); + + // Mock navigation link + const Link = ( { href, children } ) => ( + + ); + + return ( + <> + + + + Item 1 + + + Item 2 + + + + + setActiveItem( 'child-1' ) } + title="Child 1" + /> + setActiveItem( 'child-2' ) } + title="Child 2" + /> + + + + setActiveItem( 'sub-child-1' ) } + title="Sub-Child 1" + /> + setActiveItem( 'sub-child-2' ) } + title="Sub-Child 2" + /> + + + +
+

+ Menu { activeMenu } is active. +
+ Item { activeItem } is active. +

+

+ +

+

+ +

+
+ + ); +} diff --git a/packages/components/src/navigation/stories/default.js b/packages/components/src/navigation/stories/default.js new file mode 100644 index 00000000000000..00081aeebd11d1 --- /dev/null +++ b/packages/components/src/navigation/stories/default.js @@ -0,0 +1,71 @@ +/** + * WordPress dependencies + */ +import { Icon, wordpress } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import Navigation from '..'; +import NavigationGroup from '../group'; +import NavigationItem from '../item'; +import NavigationMenu from '../menu'; + +export function DefaultStory() { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/packages/components/src/navigation/stories/index.js b/packages/components/src/navigation/stories/index.js index db0e05a17c89d0..09094c914cc939 100644 --- a/packages/components/src/navigation/stories/index.js +++ b/packages/components/src/navigation/stories/index.js @@ -1,210 +1,27 @@ -/** - * External dependencies - */ -import styled from '@emotion/styled'; - -/** - * WordPress dependencies - */ -import { Button } from '@wordpress/components'; -import { useEffect, useState } from '@wordpress/element'; - /** * Internal dependencies */ import Navigation from '..'; +import NavigationBackButton from '../back-button'; import NavigationGroup from '../group'; import NavigationItem from '../item'; import NavigationMenu from '../menu'; +import { DefaultStory } from './default'; +import { ControlledStateStory } from './controlled-state'; +import { MoreExamplesStory } from './more-examples'; +import './style.css'; export default { title: 'Components/Navigation', component: Navigation, + subcomponents: { + NavigationBackButton, + NavigationGroup, + NavigationItem, + NavigationMenu, + }, }; -const Container = styled.div` - max-width: 246px; -`; - -function Example() { - const [ activeItem, setActiveItem ] = useState( 'item-1' ); - const [ activeMenu, setActiveMenu ] = useState( 'root' ); - - const [ delayedBadge, setDelayedBadge ] = useState(); - useEffect( () => { - const timeout = setTimeout( () => setDelayedBadge( 2 ), 1500 ); - return () => clearTimeout( timeout ); - } ); - - // Mock navigation link - const Link = ( { href, children } ) => ( - { - event.preventDefault(); - const item = href.replace( 'https://example.com/', '' ); - setActiveItem( item ); - } } - > - { children } - - ); - - return ( - - - - - - - Item 1 - - - - - Item 2 - - - - - - - - - - { - event.preventDefault(); - setActiveItem( 'item-5' ); - } } - > - WordPress Logo - - - - - - - setActiveItem( 'child-1' ) } - /> - setActiveItem( 'child-2' ) } - /> - - - - - - - setActiveItem( 'sub-child-1' ) } - /> - setActiveItem( 'sub-child-2' ) } - /> - - - - - - - - - - - - - -
-

- Item { activeItem } is active. -

- - -
-
- ); -} - -export const _default = () => ; +export const _default = () => ; +export const controlledState = () => ; +export const moreExamples = () => ; diff --git a/packages/components/src/navigation/stories/more-examples.js b/packages/components/src/navigation/stories/more-examples.js new file mode 100644 index 00000000000000..c10a4135e83f5e --- /dev/null +++ b/packages/components/src/navigation/stories/more-examples.js @@ -0,0 +1,38 @@ +/** + * WordPress dependencies + */ +import { useEffect, useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import Navigation from '..'; +import NavigationItem from '../item'; +import NavigationMenu from '../menu'; + +export function MoreExamplesStory() { + const [ delayedBadge, setDelayedBadge ] = useState(); + useEffect( () => { + const timeout = setTimeout( () => setDelayedBadge( 2 ), 1500 ); + return () => clearTimeout( timeout ); + } ); + + return ( + + + + + + + + + ); +} diff --git a/packages/components/src/navigation/stories/style.css b/packages/components/src/navigation/stories/style.css new file mode 100644 index 00000000000000..5a2b33ff1294b2 --- /dev/null +++ b/packages/components/src/navigation/stories/style.css @@ -0,0 +1,14 @@ +.navigation-story { + max-width: 300px; +} + +.navigation-story__aside { + margin: 48px 0 0 24px; +} + +.navigation-story__wordpress-icon svg { + fill: #949494; +} +.navigation-story__wordpress-icon:hover svg { + fill: #ddd; +} From 32899fa13369af23419f6aa15395ebd122950011 Mon Sep 17 00:00:00 2001 From: Copons Date: Wed, 23 Sep 2020 17:26:57 +0200 Subject: [PATCH 2/4] Move the custom back label to More Examples --- .../components/src/navigation/stories/default.js | 1 - .../src/navigation/stories/more-examples.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/components/src/navigation/stories/default.js b/packages/components/src/navigation/stories/default.js index 00081aeebd11d1..a3eed640a6cda5 100644 --- a/packages/components/src/navigation/stories/default.js +++ b/packages/components/src/navigation/stories/default.js @@ -58,7 +58,6 @@ export function DefaultStory() { + + + + + + ); } From 2edb1d4c4dbc9635961535f62940a96c0c3e88ae Mon Sep 17 00:00:00 2001 From: Copons Date: Thu, 24 Sep 2020 10:51:20 +0200 Subject: [PATCH 3/4] Make Default more default and move less interesting examples to More Examples --- .../src/navigation/stories/default.js | 78 +++++++++---------- .../src/navigation/stories/more-examples.js | 77 +++++++++++++----- .../src/navigation/stories/style.css | 5 ++ 3 files changed, 100 insertions(+), 60 deletions(-) diff --git a/packages/components/src/navigation/stories/default.js b/packages/components/src/navigation/stories/default.js index a3eed640a6cda5..17792bca804dd9 100644 --- a/packages/components/src/navigation/stories/default.js +++ b/packages/components/src/navigation/stories/default.js @@ -1,69 +1,69 @@ /** * WordPress dependencies */ -import { Icon, wordpress } from '@wordpress/icons'; +import { useState } from '@wordpress/element'; /** * Internal dependencies */ import Navigation from '..'; -import NavigationGroup from '../group'; import NavigationItem from '../item'; import NavigationMenu from '../menu'; export function DefaultStory() { + const [ activeItem, setActiveItem ] = useState( 'item-1' ); + return ( - + - - - - - - - - - - - - - - + setActiveItem( 'item-1' ) } + title="Item 1" + /> + setActiveItem( 'item-2' ) } + title="Item 2" + /> + - - - setActiveItem( 'child-1' ) } + title="Child 1" + /> + setActiveItem( 'child-2' ) } + title="Child 2" + /> + - - - + setActiveItem( 'sub-child-1' ) } + title="Sub-Child 1" + /> + setActiveItem( 'sub-child-2' ) } + title="Sub-Child 2" + /> ); diff --git a/packages/components/src/navigation/stories/more-examples.js b/packages/components/src/navigation/stories/more-examples.js index 466a8573170037..d8c1cfd01bd38f 100644 --- a/packages/components/src/navigation/stories/more-examples.js +++ b/packages/components/src/navigation/stories/more-examples.js @@ -2,15 +2,18 @@ * WordPress dependencies */ import { useEffect, useState } from '@wordpress/element'; +import { Icon, wordpress } from '@wordpress/icons'; /** * Internal dependencies */ import Navigation from '..'; +import NavigationGroup from '../group'; import NavigationItem from '../item'; import NavigationMenu from '../menu'; export function MoreExamplesStory() { + const [ activeItem, setActiveItem ] = useState( 'child-1' ); const [ delayedBadge, setDelayedBadge ] = useState(); useEffect( () => { const timeout = setTimeout( () => setDelayedBadge( 2 ), 1500 ); @@ -18,35 +21,67 @@ export function MoreExamplesStory() { } ); return ( - + - - - - - + + + + + + + + setActiveItem( 'item-delayed-badge' ) } + title="Item with a Delayed Badge" + /> + + + + + + + Custom Content + + + - - + setActiveItem( 'child-1' ) } + title="Child 1" + /> + setActiveItem( 'child-2' ) } + title="Child 2" + /> ); diff --git a/packages/components/src/navigation/stories/style.css b/packages/components/src/navigation/stories/style.css index 5a2b33ff1294b2..a702a797b771ad 100644 --- a/packages/components/src/navigation/stories/style.css +++ b/packages/components/src/navigation/stories/style.css @@ -6,8 +6,13 @@ margin: 48px 0 0 24px; } +.navigation-story__wordpress-icon { + align-items: center; + display: inline-flex; +} .navigation-story__wordpress-icon svg { fill: #949494; + margin-right: 8px; } .navigation-story__wordpress-icon:hover svg { fill: #ddd; From 33c0183cf6d469f2b0b249da5fcb01ba640657b8 Mon Sep 17 00:00:00 2001 From: Copons Date: Fri, 25 Sep 2020 16:33:35 +0200 Subject: [PATCH 4/4] Update mock link component name --- .../src/navigation/stories/controlled-state.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/components/src/navigation/stories/controlled-state.js b/packages/components/src/navigation/stories/controlled-state.js index b9619769e9148c..c4aa3aedf02711 100644 --- a/packages/components/src/navigation/stories/controlled-state.js +++ b/packages/components/src/navigation/stories/controlled-state.js @@ -16,7 +16,7 @@ export function ControlledStateStory() { const [ activeMenu, setActiveMenu ] = useState( 'root' ); // Mock navigation link - const Link = ( { href, children } ) => ( + const MockLink = ( { href, children } ) => (