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

Iterations on the welcome guide #21847

Merged
merged 37 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
39f5b0b
Removed border-radius from SVGs
enriquesanchez Apr 22, 2020
e3a23de
Update SVGs to match new size
enriquesanchez Apr 23, 2020
cf2bfe3
Update image height and styles
enriquesanchez Apr 23, 2020
c23c6e0
Move images above heading
enriquesanchez Apr 23, 2020
aa1e961
Layout and spacing updates
enriquesanchez Apr 23, 2020
1cc6e95
Reduce size of page control dots
enriquesanchez Apr 23, 2020
12ef718
Remove forward/back icons
enriquesanchez Apr 23, 2020
6583742
Update paragraph margin
enriquesanchez Apr 23, 2020
e936a87
Remove commented code
enriquesanchez Apr 23, 2020
82b1de5
More layout updates and remove commented code
enriquesanchez Apr 23, 2020
10999b9
Set forward button in bold
enriquesanchez Apr 24, 2020
4cefb9a
Remove commented code
enriquesanchez Apr 24, 2020
37af447
Add 9e6d4e8
noisysocks Apr 27, 2020
d773777
Aligment and spacing of page control dots
enriquesanchez Apr 27, 2020
68180dc
Update heading font-size and spacing
enriquesanchez Apr 27, 2020
adf0cc1
Update footer's padding
enriquesanchez Apr 27, 2020
f088927
Update text's margins
enriquesanchez Apr 27, 2020
51e4e1d
Add top margin to pagination controls
enriquesanchez Apr 27, 2020
1d787da
Remove unecessary "mobile" styles
enriquesanchez Apr 27, 2020
046c2cf
Update modal's placement on mobile sizes
enriquesanchez Apr 27, 2020
6c61665
Place footer at bottom of modal on small viewports
enriquesanchez Apr 27, 2020
5fa9feb
Update mobile styles for Finish button
enriquesanchez Apr 27, 2020
cbf68ee
Remove little triangle corner from block illustration
enriquesanchez Apr 29, 2020
01645a4
Add more space between pagination dots and heading
enriquesanchez Apr 29, 2020
a8acd3a
Fix text line height discrepancies when inserter icon is in-line
enriquesanchez Apr 29, 2020
e6aa07d
Add hover state for prev/next links
enriquesanchez Apr 29, 2020
73a389c
Update hover style of close button
enriquesanchez Apr 29, 2020
a820b2f
Normalize modal's height to avoid jump between steps
enriquesanchez Apr 29, 2020
7cd3c5b
Change background color on illustrations
enriquesanchez Apr 29, 2020
6f204ec
Add reduced motion query to show/hide gifs
enriquesanchez May 13, 2020
efce086
Add data URI for CanvasImage gif
enriquesanchez May 13, 2020
0a7e2b0
Add data URI for EditorImage gif
enriquesanchez May 13, 2020
6a1ebe8
Add data URI for BlockLibraryImage gif
enriquesanchez May 13, 2020
a6b41e7
Add data URI for DocumentationImage gif
enriquesanchez May 13, 2020
e327171
Update class names
enriquesanchez May 13, 2020
2742d11
Update bg color of image to match illustrations
enriquesanchez May 13, 2020
4fa7ae2
Update packages/components/src/guide/README.md
enriquesanchez May 18, 2020
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
5 changes: 5 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Master

### 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