Skip to content

Commit

Permalink
Add a rotating list of tips to the inserter help panel (#20163)
Browse files Browse the repository at this point in the history
Co-authored-by: Matias Ventura <mv@matiasventura.com>
  • Loading branch information
youknowriad and mtias authored Feb 13, 2020
1 parent a46cd2f commit 9d67638
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ import classnames from 'classnames';
*/
import { speak } from '@wordpress/a11y';
import { __, _n, _x, sprintf } from '@wordpress/i18n';
import {
Component,
__experimentalCreateInterpolateElement,
createRef,
} from '@wordpress/element';
import { PanelBody, withSpokenMessages, Tip } from '@wordpress/components';
import { Component, createRef } from '@wordpress/element';
import { PanelBody, withSpokenMessages } from '@wordpress/components';
import {
isReusableBlock,
createBlock,
Expand All @@ -45,6 +41,7 @@ import BlockPreview from '../block-preview';
import BlockTypesList from '../block-types-list';
import BlockCard from '../block-card';
import ChildBlocks from './child-blocks';
import Tips from './tips';
import __experimentalInserterMenuExtension from '../inserter-menu-extension';
import { searchItems } from './search-items';

Expand Down Expand Up @@ -537,14 +534,7 @@ export class InserterMenu extends Component {
) }
</p>
</div>
<Tip>
{ __experimentalCreateInterpolateElement(
__(
'While writing, you can press <kbd>/</kbd> to quickly insert new blocks.'
),
{ kbd: <kbd /> }
) }
</Tip>
<Tips />
</div>
) }
</div>
Expand Down
44 changes: 44 additions & 0 deletions packages/block-editor/src/components/inserter/tips.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalCreateInterpolateElement,
useState,
} from '@wordpress/element';
import { Tip } from '@wordpress/components';

const globalTips = [
__experimentalCreateInterpolateElement(
__(
'While writing, you can press <kbd>/</kbd> to quickly insert new blocks.'
),
{ kbd: <kbd /> }
),
__experimentalCreateInterpolateElement(
__(
'Indent a list by pressing <kbd>space</kbd> at the beginning of a line.'
),
{ kbd: <kbd /> }
),
__experimentalCreateInterpolateElement(
__(
'Outdent a list by pressing <kbd>backspace</kbd> at the beginning of a line'
),
{ kbd: <kbd /> }
),
__( 'Drag files into the editor to automatically insert media blocks.' ),
__( "Change a block's type by pressing the block icon on the toolbar." ),
];

function Tips() {
const [ randomIndex ] = useState(
// Disable Reason: I'm not generating an HTML id.
// eslint-disable-next-line no-restricted-syntax
Math.floor( Math.random() * globalTips.length )
);

return <Tip>{ globalTips[ randomIndex ] }</Tip>;
}

export default Tips;

0 comments on commit 9d67638

Please sign in to comment.