Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icons to navigation sidebar items #36893

Merged
merged 7 commits into from Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/components/src/navigation/item/index.js
Expand Up @@ -29,6 +29,7 @@ export default function NavigationItem( props ) {
navigateToMenu,
onClick = noop,
title,
icon,
hideIfTargetMenuEmpty,
isText,
...restProps
Expand Down Expand Up @@ -62,7 +63,7 @@ export default function NavigationItem( props ) {

onClick( event );
};
const icon = isRTL() ? chevronLeft : chevronRight;
const navigationIcon = isRTL() ? chevronLeft : chevronRight;
const baseProps = children ? props : { ...props, onClick: undefined };
const itemProps = isText
? restProps
Expand All @@ -72,12 +73,14 @@ export default function NavigationItem( props ) {
<NavigationItemBase { ...baseProps } className={ classes }>
{ children || (
<ItemUI { ...itemProps }>
{ icon && <Icon icon={ icon } /> }

<NavigationItemBaseContent
title={ title }
badge={ badge }
/>

{ navigateToMenu && <Icon icon={ icon } /> }
{ navigateToMenu && <Icon icon={ navigationIcon } /> }
</ItemUI>
) }
</NavigationItemBase>
Expand Down
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useEffect, useState } from '@wordpress/element';
import { Icon, wordpress } from '@wordpress/icons';
import { Icon, wordpress, home } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -33,6 +33,7 @@ export function MoreExamplesStory() {
</NavigationGroup>
<NavigationGroup title="Items with Unusual Features">
<NavigationItem
icon={ home }
item="item-sub-menu"
navigateToMenu="sub-menu"
title="Sub-Menu with Custom Back Label"
Expand Down
Expand Up @@ -182,6 +182,10 @@ export const ItemUI = styled.div`
width: 100%;
color: inherit;
opacity: 0.7;

> svg:first-of-type {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This selector seems a little bit fragile. Could we add a className to the <Icon> component or wrap it with a <span>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is what I was unsure about. I guess BEM style classnames aren't generally used in components that use css-in-js.

Adding another wrapper isn't great either, but that's what I've gone for here to remove this fragile selector.

If there's another way I'm open to more feedback and can fix it in a follow-up.

margin-right: ${ space( 2 ) };
}
`;

export const ItemBadgeUI = styled.span`
Expand Down
Expand Up @@ -20,6 +20,11 @@ import { __ } from '@wordpress/i18n';
import { ESCAPE } from '@wordpress/keycodes';
import { decodeEntities } from '@wordpress/html-entities';
import { addQueryArgs } from '@wordpress/url';
import {
home as siteIcon,
layout as templateIcon,
symbolFilled as templatePartIcon,
} from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -87,6 +92,7 @@ const NavigationPanel = ( {
<NavigationMenu>
<NavigationGroup title={ __( 'Editor' ) }>
<NavigationItem
icon={ siteIcon }
title={ __( 'Site' ) }
item={ SITE_EDITOR_KEY }
href={ addQueryArgs( window.location.href, {
Expand All @@ -95,6 +101,7 @@ const NavigationPanel = ( {
} ) }
/>
<NavigationItem
icon={ templateIcon }
title={ __( 'Templates' ) }
item="wp_template"
href={ addQueryArgs( window.location.href, {
Expand All @@ -103,6 +110,7 @@ const NavigationPanel = ( {
} ) }
/>
<NavigationItem
icon={ templatePartIcon }
title={ __( 'Template Parts' ) }
item="wp_template_part"
href={ addQueryArgs( window.location.href, {
Expand Down