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 all 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
13 changes: 10 additions & 3 deletions packages/components/src/navigation/item/index.js
Expand Up @@ -15,7 +15,7 @@ import { isRTL } from '@wordpress/i18n';
*/
import Button from '../../button';
import { useNavigationContext } from '../context';
import { ItemUI } from '../styles/navigation-styles';
import { ItemUI, ItemIconUI } from '../styles/navigation-styles';
import NavigationItemBaseContent from './base-content';
import NavigationItemBase from './base';

Expand All @@ -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,18 @@ export default function NavigationItem( props ) {
<NavigationItemBase { ...baseProps } className={ classes }>
{ children || (
<ItemUI { ...itemProps }>
{ icon && (
<ItemIconUI>
<Icon icon={ icon } />
</ItemIconUI>
) }

<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 @@ -184,6 +184,11 @@ export const ItemUI = styled.div`
opacity: 0.7;
`;

export const ItemIconUI = styled.span`
display: flex;
margin-right: ${ space( 2 ) };
`;

export const ItemBadgeUI = styled.span`
margin-left: ${ () => ( isRTL() ? '0' : space( 2 ) ) };
margin-right: ${ () => ( isRTL() ? space( 2 ) : '0' ) };
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