Skip to content

Commit 14d2aa0

Browse files
authored
Add icons to navigation sidebar items (#36893)
* Add icons to navigation sidebar items * Add storybook example * Move icon into main item file and add margin * Target first child * Use first-of-type * Switch to using the sybmolFilled icon for template parts * Add another wrapper to replace fragile class
1 parent 63bd2bf commit 14d2aa0

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

packages/components/src/navigation/item/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { isRTL } from '@wordpress/i18n';
1515
*/
1616
import Button from '../../button';
1717
import { useNavigationContext } from '../context';
18-
import { ItemUI } from '../styles/navigation-styles';
18+
import { ItemUI, ItemIconUI } from '../styles/navigation-styles';
1919
import NavigationItemBaseContent from './base-content';
2020
import NavigationItemBase from './base';
2121

@@ -29,6 +29,7 @@ export default function NavigationItem( props ) {
2929
navigateToMenu,
3030
onClick = noop,
3131
title,
32+
icon,
3233
hideIfTargetMenuEmpty,
3334
isText,
3435
...restProps
@@ -62,7 +63,7 @@ export default function NavigationItem( props ) {
6263

6364
onClick( event );
6465
};
65-
const icon = isRTL() ? chevronLeft : chevronRight;
66+
const navigationIcon = isRTL() ? chevronLeft : chevronRight;
6667
const baseProps = children ? props : { ...props, onClick: undefined };
6768
const itemProps = isText
6869
? restProps
@@ -72,12 +73,18 @@ export default function NavigationItem( props ) {
7273
<NavigationItemBase { ...baseProps } className={ classes }>
7374
{ children || (
7475
<ItemUI { ...itemProps }>
76+
{ icon && (
77+
<ItemIconUI>
78+
<Icon icon={ icon } />
79+
</ItemIconUI>
80+
) }
81+
7582
<NavigationItemBaseContent
7683
title={ title }
7784
badge={ badge }
7885
/>
7986

80-
{ navigateToMenu && <Icon icon={ icon } /> }
87+
{ navigateToMenu && <Icon icon={ navigationIcon } /> }
8188
</ItemUI>
8289
) }
8390
</NavigationItemBase>

packages/components/src/navigation/stories/more-examples.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* WordPress dependencies
33
*/
44
import { useEffect, useState } from '@wordpress/element';
5-
import { Icon, wordpress } from '@wordpress/icons';
5+
import { Icon, wordpress, home } from '@wordpress/icons';
66

77
/**
88
* Internal dependencies
@@ -33,6 +33,7 @@ export function MoreExamplesStory() {
3333
</NavigationGroup>
3434
<NavigationGroup title="Items with Unusual Features">
3535
<NavigationItem
36+
icon={ home }
3637
item="item-sub-menu"
3738
navigateToMenu="sub-menu"
3839
title="Sub-Menu with Custom Back Label"

packages/components/src/navigation/styles/navigation-styles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ export const ItemUI = styled.div`
184184
opacity: 0.7;
185185
`;
186186

187+
export const ItemIconUI = styled.span`
188+
display: flex;
189+
margin-right: ${ space( 2 ) };
190+
`;
191+
187192
export const ItemBadgeUI = styled.span`
188193
margin-left: ${ () => ( isRTL() ? '0' : space( 2 ) ) };
189194
margin-right: ${ () => ( isRTL() ? space( 2 ) : '0' ) };

packages/edit-site/src/components/navigation-sidebar/navigation-panel/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import { __ } from '@wordpress/i18n';
2020
import { ESCAPE } from '@wordpress/keycodes';
2121
import { decodeEntities } from '@wordpress/html-entities';
2222
import { addQueryArgs } from '@wordpress/url';
23+
import {
24+
home as siteIcon,
25+
layout as templateIcon,
26+
symbolFilled as templatePartIcon,
27+
} from '@wordpress/icons';
2328

2429
/**
2530
* Internal dependencies
@@ -88,6 +93,7 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
8893
<NavigationMenu>
8994
<NavigationGroup title={ __( 'Editor' ) }>
9095
<NavigationItem
96+
icon={ siteIcon }
9197
title={ __( 'Site' ) }
9298
item={ SITE_EDITOR_KEY }
9399
href={ addQueryArgs( window.location.href, {
@@ -96,6 +102,7 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
96102
} ) }
97103
/>
98104
<NavigationItem
105+
icon={ templateIcon }
99106
title={ __( 'Templates' ) }
100107
item="wp_template"
101108
href={ addQueryArgs( window.location.href, {
@@ -104,6 +111,7 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
104111
} ) }
105112
/>
106113
<NavigationItem
114+
icon={ templatePartIcon }
107115
title={ __( 'Template Parts' ) }
108116
item="wp_template_part"
109117
href={ addQueryArgs( window.location.href, {

0 commit comments

Comments
 (0)