Skip to content

Commit

Permalink
WIP: Implement welcome guide modal
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Nov 6, 2019
1 parent bb0529f commit bab8f7b
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 120 deletions.
15 changes: 0 additions & 15 deletions packages/edit-post/src/components/editor-initialization/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
Expand All @@ -24,14 +18,5 @@ export default function( { postId } ) {
useBlockSelectionListener( postId );
useAdjustSidebarListener( postId );
useUpdatePostLinkListener( postId );
const { triggerGuide } = useDispatch( 'core/nux' );
useEffect( () => {
triggerGuide( [
'core/editor.inserter',
'core/editor.settings',
'core/editor.preview',
'core/editor.publish',
] );
}, [ triggerGuide ] );
return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { withViewportMatch } from '@wordpress/viewport';
import { DotTip } from '@wordpress/nux';
import { __ } from '@wordpress/i18n';
import {
Inserter,
Expand All @@ -30,12 +29,7 @@ function HeaderToolbar( { hasFixedToolbar, isLargeViewport, showInserter, isText
className="edit-post-header-toolbar"
aria-label={ toolbarAriaLabel }
>
<div>
<Inserter disabled={ ! showInserter } position="bottom right" showInserterHelpPanel />
<DotTip tipId="core/editor.inserter">
{ __( 'Welcome to the wonderful world of blocks! Click the “+” (“Add block”) button to add a new block. There are blocks available for all kinds of content: you can insert text, headings, images, lists, and lots more!' ) }
</DotTip>
</div>
<Inserter disabled={ ! showInserter } position="bottom right" showInserterHelpPanel />
<EditorHistoryUndo />
<EditorHistoryRedo />
<TableOfContents hasOutlineItemsDisabled={ isTextModeEnabled } />
Expand Down
22 changes: 8 additions & 14 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@wordpress/editor';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { DotTip } from '@wordpress/nux';

/**
* Internal dependencies
Expand Down Expand Up @@ -63,19 +62,14 @@ function Header( {
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
/>
<div>
<IconButton
icon="admin-generic"
label={ __( 'Settings' ) }
onClick={ toggleGeneralSidebar }
isToggled={ isEditorSidebarOpened }
aria-expanded={ isEditorSidebarOpened }
shortcut={ shortcuts.toggleSidebar }
/>
<DotTip tipId="core/editor.settings">
{ __( 'You’ll find more settings for your page and blocks in the sidebar. Click the cog icon to toggle the sidebar open and closed.' ) }
</DotTip>
</div>
<IconButton
icon="admin-generic"
label={ __( 'Settings' ) }
onClick={ toggleGeneralSidebar }
isToggled={ isEditorSidebarOpened }
aria-expanded={ isEditorSidebarOpened }
shortcut={ shortcuts.toggleSidebar }
/>
<PinnedPlugins.Slot />
<MoreMenu />
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Sidebar from '../sidebar';
import PluginPostPublishPanel from '../sidebar/plugin-post-publish-panel';
import PluginPrePublishPanel from '../sidebar/plugin-pre-publish-panel';
import FullscreenMode from '../fullscreen-mode';
import WelcomeGuideModal from '../welcome-guide-modal';

function Layout( {
mode,
Expand Down Expand Up @@ -92,6 +93,7 @@ function Layout( {
<KeyboardShortcutHelpModal />
<ManageBlocksModal />
<OptionsModal />
<WelcomeGuideModal />
{ ( mode === 'text' || ! isRichEditingEnabled ) && <TextEditor /> }
{ isRichEditingEnabled && mode === 'visual' && <VisualEditor /> }
<div className="edit-post-layout__metaboxes">
Expand Down
2 changes: 0 additions & 2 deletions packages/edit-post/src/components/options-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Section from './section';
import {
EnablePluginDocumentSettingPanelOption,
EnablePublishSidebarOption,
EnableTipsOption,
EnablePanelOption,
EnableFeature,
} from './options';
Expand All @@ -47,7 +46,6 @@ export function OptionsModal( { isModalActive, isViewable, closeModal } ) {
>
<Section title={ __( 'General' ) }>
<EnablePublishSidebarOption label={ __( 'Pre-publish Checks' ) } />
<EnableTipsOption label={ __( 'Tips' ) } />
<EnableFeature feature="showInserterHelpPanel" label={ __( 'Inserter Help Panel' ) } />
</Section>
<Section title={ __( 'Document Panels' ) }>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export { default as EnableCustomFieldsOption } from './enable-custom-fields';
export { default as EnablePanelOption } from './enable-panel';
export { default as EnablePluginDocumentSettingPanelOption } from './enable-plugin-document-setting-panel';
export { default as EnablePublishSidebarOption } from './enable-publish-sidebar';
export { default as EnableTipsOption } from './enable-tips';
export { default as EnableFeature } from './enable-feature';
89 changes: 89 additions & 0 deletions packages/edit-post/src/components/welcome-guide-modal/guide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* WordPress dependencies
*/
import { useState, Children } from '@wordpress/element';
import { KeyboardShortcuts, IconButton, Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import PageControl from './page-control';
import { BackButtonIcon, ForwardButtonIcon } from './vectors';

function Guide( { onRequestClose, children } ) {
const [ currentPage, setCurrentPage ] = useState( 0 );

const numberOfPages = Children.count( children );
const canGoBack = currentPage > 0;
const canGoForward = currentPage < numberOfPages - 1;

const goBack = () => {
if ( canGoBack ) {
setCurrentPage( currentPage - 1 );
}
};

const goForward = () => {
if ( canGoForward ) {
setCurrentPage( currentPage + 1 );
}
};

return (
<div className="edit-post-welcome-guide-modal__guide">
<KeyboardShortcuts key={ currentPage } shortcuts={ {
left: goBack,
right: goForward,
} } />
{ children[ currentPage ] }
<div className="edit-post-welcome-guide-modal__footer">
{ canGoBack && (
<IconButton
className="edit-post-welcome-guide-modal__back-button"
icon={ <BackButtonIcon /> }
onClick={ goBack }
>
{ __( 'Previous' ) }
</IconButton>
) }
<PageControl
currentPage={ currentPage }
numberOfPages={ numberOfPages }
setCurrentPage={ setCurrentPage }
/>
{ canGoForward && (
<IconButton
className="edit-post-welcome-guide-modal__forward-button"
icon={ <ForwardButtonIcon /> }
onClick={ goForward }
>
{ __( 'Next' ) }
</IconButton>
) }
{ ! canGoForward && (
<Button
className="edit-post-welcome-guide-modal__start-button"
isPrimary
isLarge
onClick={ onRequestClose }
>
{ __( 'Get started' ) }
</Button>
) }
</div>
</div>
);
}

function Page( { children } ) {
return (
<div className="edit-post-welcome-guide-modal__page">
{ children }
</div>
);
}

Guide.Page = Page;

export default Guide;
65 changes: 65 additions & 0 deletions packages/edit-post/src/components/welcome-guide-modal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { Modal } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import Guide from './guide';
import { CanvasImage, EditorImage, BlockLibraryImage, inserterIconHTML } from './vectors';

export default function WelcomeGuideModal() {
const isOpen = useSelect( ( select ) =>
select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ) );

const { toggleFeature } = useDispatch( 'core/edit-post' );

if ( ! isOpen ) {
return null;
}

const closeModal = () => {
toggleFeature( 'welcomeGuide' );
};

return (
<Modal className="edit-post-welcome-guide-modal" onRequestClose={ closeModal }>
<Guide onRequestClose={ closeModal }>
<Guide.Page>
<CanvasImage />
<div className="edit-post-welcome-guide-modal__text">
<h1>{ __( 'Welcome to the block editor' ) }</h1>
<p>
{ __( 'In the WordPress editor, each paragraph, image, or video is presented as a distinct “block” of content.' ) }
</p>
</div>
</Guide.Page>
<Guide.Page>
<EditorImage />
<div className="edit-post-welcome-guide-modal__text">
<h1>{ __( 'Make each block your own' ) }</h1>
<p>
{ __( 'Each block comes with its own set of controls for changing things like color, width, and alignment. These will show and hide automatically when you have a block selected.' ) }
</p>
</div>
</Guide.Page>
<Guide.Page>
<BlockLibraryImage />
<div className="edit-post-welcome-guide-modal__text">
<h1>{ __( 'Get to know the block library' ) }</h1>
<p dangerouslySetInnerHTML={ {
__html: sprintf(
/* translators: %s: HTML which displays the inserter icon. */
__( 'All of the blocks available to you live in the Block Library. You’ll find it wherever you see the %s icon.' ),
inserterIconHTML
),
} } />
</div>
</Guide.Page>
</Guide>
</Modal>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* External dependencies
*/
import { times } from 'lodash';

/**
* WordPress dependencies
*/
import { IconButton } from '@wordpress/components';

/**
* Internal dependencies
*/
import { PageControlIcon } from './vectors';

export default function PageControl( { currentPage, numberOfPages, setCurrentPage } ) {
return (
<div className="edit-post-welcome-guide-modal__page-control">
{ times( numberOfPages, ( page ) => (
<IconButton
key={ page }
icon={ <PageControlIcon isSelected={ page === currentPage } /> }
onClick={ () => setCurrentPage( page ) }
/>
) ) }
</div>
);
}
Loading

0 comments on commit bab8f7b

Please sign in to comment.