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 18, 2019
1 parent a661b27 commit bc79748
Show file tree
Hide file tree
Showing 20 changed files with 456 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';
93 changes: 93 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,93 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useState, Children } from '@wordpress/element';
import { KeyboardShortcuts, IconButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

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

function Guide( { onFinish, children } ) {
const isMobile = useSelect( ( select ) =>
select( 'core/viewport' ).isViewportMatch( '< small' ) );

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 ] }
{ isMobile && ! canGoForward && (
<StartButton onClick={ onFinish } />
) }
<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>
) }
{ ! isMobile && ! canGoForward && (
<StartButton
className="edit-post-welcome-guide-modal__start-button"
onClick={ onFinish }
/>
) }
</div>
</div>
);
}

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

Guide.Page = Page;

export default Guide;
70 changes: 70 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,70 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { Modal } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __experimentalCreateInterpolateElement } from '@wordpress/element';

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

export default function WelcomeGuideModal() {
const areTipsEnabled = useSelect( ( select ) => select( 'core/nux' ).areTipsEnabled() );

const { disableTips } = useDispatch( 'core/nux' );

if ( ! areTipsEnabled ) {
return null;
}

return (
<Modal
className="edit-post-welcome-guide-modal"
shouldCloseOnClickOutside={ false }
onRequestClose={ disableTips }
>
<Guide onFinish={ disableTips }>
<Guide.Page>
<h1 className="edit-post-welcome-guide-modal__heading">
{ __( 'Welcome to the block editor' ) }
</h1>
<CanvasImage className="edit-post-welcome-guide-modal__image" />
<p className="edit-post-welcome-guide-modal__text">
{ __( 'In the WordPress editor, each paragraph, image, or video is presented as a distinct “block” of content.' ) }
</p>
</Guide.Page>
<Guide.Page>
<h1 className="edit-post-welcome-guide-modal__heading">
{ __( 'Make each block your own' ) }
</h1>
<EditorImage className="edit-post-welcome-guide-modal__image" />
<p className="edit-post-welcome-guide-modal__text">
{ __( '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>
</Guide.Page>
<Guide.Page>
<h1 className="edit-post-welcome-guide-modal__heading">
{ __( 'Get to know the block library' ) }
</h1>
<BlockLibraryImage className="edit-post-welcome-guide-modal__image" />
<p className="edit-post-welcome-guide-modal__text">
{ __experimentalCreateInterpolateElement(
__( 'All of the blocks available to you live in the Block Library. You’ll find it wherever you see the <InserterIconImage /> icon.' ),
{
InserterIconImage: (
<InserterIconImage
className="edit-post-welcome-guide-modal__inserter-icon"
/>
),
}
) }
</p>
</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 bc79748

Please sign in to comment.