Skip to content

Commit

Permalink
Prefer @wordpress/icons over dashicons in docs and tests (#20094)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Feb 7, 2020
1 parent def0768 commit a7fbd6e
Show file tree
Hide file tree
Showing 26 changed files with 415 additions and 329 deletions.
173 changes: 104 additions & 69 deletions docs/designers-developers/developers/block-api/block-registration.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ This slot will add a new item to the More Tools & Options section.
## Example

```js
const { registerPlugin } = wp.plugins;
const { PluginMoreMenuItem } = wp.editPost;
import { registerPlugin } from '@wordpress/plugins';
import { PluginMoreMenuItem } from '@wordpress/edit-post';
import { image } from '@wordpress/icons';

const MyButtonMoreMenuItemTest = () => (
<PluginMoreMenuItem
icon="smiley"
onClick={ () => { alert( 'Button Clicked' ) } }
icon={ image }
onClick={ () => {
alert( 'Button Clicked' );
} }
>
More Menu Item
</PluginMoreMenuItem>
Expand All @@ -23,4 +26,3 @@ registerPlugin( 'more-menu-item-test', { render: MyButtonMoreMenuItemTest } );
## Location

![Location](https://raw.githubusercontent.com/WordPress/gutenberg/master/docs/designers-developers/assets/plugin-more-menu-item.png?raw=true)

Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
This slot allows the creation of a `<PluginSidebar>` with a menu item that when clicked will expand the sidebar to the appropriate Plugin section.
This is done by setting the `target` on `<PluginSidebarMoreMenuItem>` to match the `name` on the `<PluginSidebar>`


## Example

```js
const { registerPlugin } = wp.plugins;

const {
import { registerPlugin } from '@wordpress/plugins';
import {
PluginSidebar,
PluginSidebarMoreMenuItem
} = wp.editPost;
} from '@wordpress/edit-post';
import { image } from '@wordpress/icons';

const { Fragment } = wp.element;
const myIcon =

const PluginSidebarMoreMenuItemTest = () => (
<Fragment>
<PluginSidebarMoreMenuItem
target="sidebar-name"
icon="smiley"
icon={ image }
>
Expanded Sidebar - More item
</PluginSidebarMoreMenuItem>
<PluginSidebar
name="sidebar-name"
icon="smiley"
icon={ image }
title="My Sidebar" >
Content of the sidebar
</PluginSidebar>
Expand Down
18 changes: 9 additions & 9 deletions docs/designers-developers/developers/slotfills/plugin-sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ Using this slot will add an icon to the bar that, when clicked, will open a side
## Example

```js
const { registerPlugin } = wp.plugins;
const { PluginSidebar } = wp.editPost;
import { registerPlugin } from '@wordpress/plugins';
import { PluginSidebar } from '@wordpress/edit-post';
import { image } from '@wordpress/icons';

const PluginSidebarTest = () => {
return(
return (
<PluginSidebar
name='plugin-sidebar-test'
title='My Plugin'
icon="smiley"
name="plugin-sidebar-test"
title="My Plugin"
icon={ image }
>
<p>Plugin Sidebar</p>
</PluginSidebar>
)
}
);
};
registerPlugin( 'plugin-sidebar-test', { render: PluginSidebarTest } );

```

## Location
Expand Down
9 changes: 5 additions & 4 deletions packages/block-editor/src/components/block-icon/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { shallow } from 'enzyme';
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { image } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -15,21 +16,21 @@ import BlockIcon from '../';

describe( 'BlockIcon', () => {
it( 'renders a Icon', () => {
const wrapper = shallow( <BlockIcon icon="format-image" /> );
const wrapper = shallow( <BlockIcon icon={ image } /> );

expect(
wrapper.containsMatchingElement( <Icon icon="format-image" /> )
wrapper.containsMatchingElement( <Icon icon={ image } /> )
).toBe( true );
} );

it( 'renders a span without the has-colors classname', () => {
const wrapper = shallow( <BlockIcon icon="format-image" /> );
const wrapper = shallow( <BlockIcon icon={ image } /> );

expect( wrapper.find( 'span' ).hasClass( 'has-colors' ) ).toBe( false );
} );

it( 'renders a span with the has-colors classname', () => {
const wrapper = shallow( <BlockIcon icon="format-image" showColors /> );
const wrapper = shallow( <BlockIcon icon={ image } showColors /> );

expect( wrapper.find( 'span' ).hasClass( 'has-colors' ) ).toBe( true );
} );
Expand Down
33 changes: 11 additions & 22 deletions packages/components/src/button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TestUtils from 'react-dom/test-utils';
* WordPress dependencies
*/
import { createRef } from '@wordpress/element';
import { plusCircle } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -85,36 +86,24 @@ describe( 'Button', () => {
} );

it( 'should render an icon button', () => {
const iconButton = shallow( <Button icon="plus" /> );
const iconButton = shallow( <Button icon={ plusCircle } /> );
expect( iconButton.hasClass( 'has-icon' ) ).toBe( true );
expect( iconButton.prop( 'aria-label' ) ).toBeUndefined();
} );

it( 'should render a Dashicon component matching the wordpress icon', () => {
const iconButton = shallow( <Button icon="wordpress" /> );
expect(
iconButton
.find( 'Icon' )
.dive()
.shallow()
.hasClass( 'dashicons-wordpress' )
).toBe( true );
const iconButton = shallow( <Button icon={ plusCircle } /> );
expect( iconButton.find( 'Icon' ).dive() ).not.toBeNull();
} );

it( 'should render child elements and icon', () => {
const iconButton = shallow(
<Button
icon="wordpress"
icon={ plusCircle }
children={ <p className="test">Test</p> }
/>
);
expect(
iconButton
.find( 'Icon' )
.dive()
.shallow()
.hasClass( 'dashicons-wordpress' )
).toBe( true );
expect( iconButton.find( 'Icon' ).dive() ).not.toBeNull();
expect(
iconButton
.find( '.test' )
Expand All @@ -125,7 +114,7 @@ describe( 'Button', () => {

it( 'should add an aria-label when the label property is used, with Tooltip wrapper', () => {
const iconButton = shallow(
<Button icon="WordPress" label="WordPress" />
<Button icon={ plusCircle } label="WordPress" />
);
expect( iconButton.name() ).toBe( 'Tooltip' );
expect( iconButton.prop( 'text' ) ).toBe( 'WordPress' );
Expand All @@ -142,7 +131,7 @@ describe( 'Button', () => {
it( 'should allow tooltip disable', () => {
const iconButton = shallow(
<Button
icon="WordPress"
icon={ plusCircle }
label="WordPress"
showTooltip={ false }
/>
Expand All @@ -153,15 +142,15 @@ describe( 'Button', () => {

it( 'should show the tooltip for empty children', () => {
const iconButton = shallow(
<Button icon="WordPress" label="WordPress" children={ [] } />
<Button icon={ plusCircle } label="WordPress" children={ [] } />
);
expect( iconButton.name() ).toBe( 'Tooltip' );
expect( iconButton.prop( 'text' ) ).toBe( 'WordPress' );
} );

it( 'should not show the tooltip when icon and children defined', () => {
const iconButton = shallow(
<Button icon="WordPress" label="WordPress">
<Button icon={ plusCircle } label="WordPress">
Children
</Button>
);
Expand All @@ -170,7 +159,7 @@ describe( 'Button', () => {

it( 'should force showing the tooltip even if icon and children defined', () => {
const iconButton = shallow(
<Button icon="WordPress" label="WordPress" showTooltip>
<Button icon={ plusCircle } label="WordPress" showTooltip>
Children
</Button>
);
Expand Down
79 changes: 38 additions & 41 deletions packages/components/src/draggable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,53 @@ The component accepts the following props:

The HTML id of the element to clone on drag

- Type: `string`
- Required: Yes
- Type: `string`
- Required: Yes

### transferData

Arbitrary data object attached to the drag and drop event.

- Type: `Object`
- Required: Yes
- Type: `Object`
- Required: Yes

### onDragStart

A function to be called when dragging starts.

- Type: `Function`
- Required: No
- Default: `noop`
- Type: `Function`
- Required: No
- Default: `noop`

### onDragEnd

A function to be called when dragging ends.

- Type: `Function`
- Required: No
- Default: `noop`
- Type: `Function`
- Required: No
- Default: `noop`

## Usage

```jsx
import { Dashicon, Draggable, Panel, PanelBody } from '@wordpress/components';
import { Draggable, Panel, PanelBody } from '@wordpress/components';
import { Icon, more } from '@wordpress/icons';

const MyDraggable = () => (
<div id="draggable-panel">
<Panel header="Draggable panel" >
<Panel header="Draggable panel">
<PanelBody>
<Draggable
elementId="draggable-panel"
transferData={ { } }
>
{
( { onDraggableStart, onDraggableEnd } ) => (
<div className="example-drag-handle" draggable>
<Dashicon
icon="move"
onDragStart={ onDraggableStart }
onDragEnd={ onDraggableEnd }
/>
</div>
)
}
<Draggable elementId="draggable-panel" transferData={ {} }>
{ ( { onDraggableStart, onDraggableEnd } ) => (
<div
className="example-drag-handle"
draggable
onDragStart={ onDraggableStart }
onDragEnd={ onDraggableEnd }
>
<Icon icon={ more } />
</div>
) }
</Draggable>
</PanelBody>
</Panel>
Expand All @@ -72,29 +69,29 @@ const MyDraggable = () => (
In case you want to call your own `dragstart` / `dragend` event handlers as well, you can pass them to `Draggable` and it'll take care of calling them after their own:

```jsx
import { Dashicon, Draggable, Panel, PanelBody } from '@wordpress/components';
import { Draggable, Panel, PanelBody } from '@wordpress/components';
import { Icon, more } from '@wordpress/icons';

const MyDraggable = ( { onDragStart, onDragEnd } ) => (
<div id="draggable-panel">
<Panel header="Draggable panel" >
<Panel header="Draggable panel">
<PanelBody>
<Draggable
elementId="draggable-panel"
transferData={ { } }
transferData={ {} }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
>
{
( { onDraggableStart, onDraggableEnd } ) => (
<div className="example-drag-handle" draggable>
<Dashicon
icon="move"
onDragStart={ onDraggableStart }
onDragEnd={ onDraggableEnd }
/>
</div>
)
}
{ ( { onDraggableStart, onDraggableEnd } ) => (
<div
className="example-drag-handle"
draggable
onDragStart={ onDraggableStart }
onDragEnd={ onDraggableEnd }
>
<Icon icon={ more } />
</div>
) }
</Draggable>
</PanelBody>
</Panel>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/draggable/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { Icon, more } from '@wordpress/icons';

/**
* Internal dependencies
*/
import Draggable from '../';
import Dashicon from '../../dashicon';

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

Expand Down Expand Up @@ -56,7 +56,7 @@ const DraggalbeExample = () => {
onDragEnd={ handleOnDragEnd }
draggable
>
<Dashicon icon="move" />
<Icon icon={ more } />
</Box>
);
} }
Expand Down
Loading

0 comments on commit a7fbd6e

Please sign in to comment.