Skip to content

Commit

Permalink
Iterations on the welcome guide (#21847)
Browse files Browse the repository at this point in the history
* Removed border-radius from SVGs

* Update SVGs to match new size

* Update image height and styles

* Move images above heading

* Layout and spacing updates

* Reduce size of page control dots

* Remove forward/back icons

* Update paragraph margin

* Remove commented code

* More layout updates and remove commented code

* Set forward button in bold

* Remove commented code

* Add 9e6d4e8

* Aligment and spacing of page control dots

* Update heading font-size and spacing

* Update footer's padding

* Update text's margins

* Add top margin to pagination controls

* Remove unecessary "mobile" styles

* Update modal's placement on mobile sizes

* Place footer at bottom of modal on small viewports

* Update mobile styles for Finish button

* Remove little triangle corner from block illustration

* Add more space between pagination dots and heading

* Fix text line height discrepancies when inserter icon is in-line

* Add hover state for prev/next links

* Update hover style of close button

* Normalize modal's height to avoid jump between steps

* Change background color on illustrations

* Add reduced motion query to show/hide gifs

* Add data URI for CanvasImage gif

* Add data URI for EditorImage gif

* Add data URI for BlockLibraryImage gif

* Add data URI for DocumentationImage gif

* Update class names

* Update bg color of image to match illustrations

* Update packages/components/src/guide/README.md

Co-authored-by: Robert Anderson <[email protected]>

Co-authored-by: Robert Anderson <[email protected]>
  • Loading branch information
enriquesanchez and noisysocks authored May 18, 2020
1 parent d8163e8 commit 633f160
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 243 deletions.
5 changes: 5 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
- Fix and issue that would cause the `Popover` component to throw an error under certain
circumstances ([#22264](https://github.com/WordPress/gutenberg/pull/22264)).

### Deprecations

- The `Guide` component no longer supports passing pages as children. Use the `pages` prop instead.
- The `GuidePage` component is deprecated. Use the `pages` prop in `Guide` instead.

## 9.2.0 (2020-02-10)

### Enhancements
Expand Down
29 changes: 18 additions & 11 deletions packages/components/src/guide/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Guide
========

`Guide` is a React component that renders a _user guide_ in a modal. The guide consists of several `GuidePage` components which the user can step through one by one. The guide is finished when the modal is closed or when the user clicks _Finish_ on the last page of the guide.
`Guide` is a React component that renders a _user guide_ in a modal. The guide consists of several pages which the user can step through one by one. The guide is finished when the modal is closed or when the user clicks _Finish_ on the last page of the guide.

## Usage

Expand All @@ -13,14 +13,20 @@ function MyTutorial() {
return null;
}

<Guide onFinish={ () => setIsOpen( false ) }>
<GuidePage>
<p>Welcome to the ACME Store! Select a category to begin browsing our wares.</p>
</GuidePage>
<GuidePage>
<p>When you find something you love, click <i>Add to Cart</i> to add the product to your shopping cart.</p>
</GuidePage>
</Guide>
return (
<Guide
onFinish={ () => setIsOpen( false ) }
pages={ [
{
content: <p>Welcome to the ACME Store!</p>,
},
{
image: <img src="https://acmestore.com/add-to-cart.png" />,
content: <p>Click <i>Add to Cart</i> to buy a product.</p>,
},
] }
/>
);
}
```

Expand All @@ -35,10 +41,11 @@ A function which is called when the guide is finished. The guide is finished whe
- Type: `function`
- Required: Yes

### children
### pages

A list of `GuidePage` components. One page is shown at a time.
A list of objects describing each page in the guide. Each object **must** contain a `'content'` property and may optionally contain a `'image'` property.

- Type: `array`
- Required: Yes

### className
Expand Down
24 changes: 5 additions & 19 deletions packages/components/src/guide/icons.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
/**
* WordPress dependencies
*/
import { SVG, Path, Circle } from '@wordpress/primitives';

export const BackButtonIcon = () => (
<SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24">
<Path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
<Path d="M0 0h24v24H0z" fill="none" />
</SVG>
);

export const ForwardButtonIcon = () => (
<SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24">
<Path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" />
<Path d="M0 0h24v24H0z" fill="none" />
</SVG>
);
import { SVG, Circle } from '@wordpress/primitives';

export const PageControlIcon = ( { isSelected } ) => (
<SVG width="12" height="12" fill="none" xmlns="http://www.w3.org/2000/svg">
<SVG width="8" height="8" fill="none" xmlns="http://www.w3.org/2000/svg">
<Circle
cx="6"
cy="6"
r="6"
cx="4"
cy="4"
r="4"
fill={ isSelected ? '#419ECD' : '#E1E3E6' }
/>
</SVG>
Expand Down
57 changes: 36 additions & 21 deletions packages/components/src/guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useState, Children } from '@wordpress/element';
import { useState, useEffect, Children } from '@wordpress/element';
import deprecated from '@wordpress/deprecated';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -16,7 +17,6 @@ import Modal from '../modal';
import KeyboardShortcuts from '../keyboard-shortcuts';
import Button from '../button';
import PageControl from './page-control';
import { BackButtonIcon, ForwardButtonIcon } from './icons';
import FinishButton from './finish-button';

export default function Guide( {
Expand All @@ -25,12 +25,24 @@ export default function Guide( {
contentLabel,
finishButtonText,
onFinish,
pages = [],
} ) {
const [ currentPage, setCurrentPage ] = useState( 0 );

const numberOfPages = Children.count( children );
useEffect( () => {
if ( Children.count( children ) ) {
deprecated( 'Passing children to <Guide>', {
alternative: 'the `pages` prop',
} );
}
}, [ children ] );

if ( Children.count( children ) ) {
pages = Children.map( children, ( child ) => ( { content: child } ) );
}

const canGoBack = currentPage > 0;
const canGoForward = currentPage < numberOfPages - 1;
const canGoForward = currentPage < pages.length - 1;

const goBack = () => {
if ( canGoBack ) {
Expand All @@ -44,7 +56,7 @@ export default function Guide( {
}
};

if ( numberOfPages === 0 ) {
if ( pages.length === 0 ) {
return null;
}

Expand All @@ -63,36 +75,39 @@ export default function Guide( {
/>

<div className="components-guide__container">
{ children[ currentPage ] }
<div className="components-guide__page">
{ pages[ currentPage ].image }

{ ! canGoForward && (
<FinishButton
className="components-guide__inline-finish-button"
onClick={ onFinish }
>
{ finishButtonText || __( 'Finish' ) }
</FinishButton>
) }
<PageControl
currentPage={ currentPage }
numberOfPages={ pages.length }
setCurrentPage={ setCurrentPage }
/>

{ pages[ currentPage ].content }

{ ! canGoForward && (
<FinishButton
className="components-guide__inline-finish-button"
onClick={ onFinish }
>
{ finishButtonText || __( 'Finish' ) }
</FinishButton>
) }
</div>

<div className="components-guide__footer">
{ canGoBack && (
<Button
className="components-guide__back-button"
icon={ <BackButtonIcon /> }
onClick={ goBack }
>
{ __( 'Previous' ) }
</Button>
) }
<PageControl
currentPage={ currentPage }
numberOfPages={ numberOfPages }
setCurrentPage={ setCurrentPage }
/>
{ canGoForward && (
<Button
className="components-guide__forward-button"
icon={ <ForwardButtonIcon /> }
onClick={ goForward }
>
{ __( 'Next' ) }
Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/guide/page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import deprecated from '@wordpress/deprecated';

export default function GuidePage( props ) {
useEffect( () => {
deprecated( '<GuidePage>', {
alternative: 'the `pages` prop in <Guide>',
} );
}, [] );

return <div { ...props } />;
}
25 changes: 14 additions & 11 deletions packages/components/src/guide/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useState } from '@wordpress/element';
*/
import Button from '../../button';
import Guide from '../';
import GuidePage from '../page';

export default { title: 'Components/Guide', component: Guide };

Expand All @@ -33,16 +32,20 @@ const ModalExample = ( { numberOfPages, ...props } ) => {
Open Guide
</Button>
{ isOpen && (
<Guide { ...props } onFinish={ closeGuide }>
{ times( numberOfPages, ( page ) => (
<GuidePage key={ page }>
<h1>
Page { page + 1 } of { numberOfPages }
</h1>
<p>{ loremIpsum }</p>
</GuidePage>
) ) }
</Guide>
<Guide
{ ...props }
onFinish={ closeGuide }
pages={ times( numberOfPages, ( page ) => ( {
content: (
<>
<h1>
Page { page + 1 } of { numberOfPages }
</h1>
<p>{ loremIpsum }</p>
</>
),
} ) ) }
/>
) }
</>
);
Expand Down
Loading

0 comments on commit 633f160

Please sign in to comment.