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 nav badges #24528

Merged
merged 6 commits into from
Aug 18, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/components/src/navigation/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { Icon, chevronRight } from '@wordpress/icons';
* Internal dependencies
*/
import Button from '../button';
import { MenuItemUI } from './styles/navigation-styles';
import { MenuItemUI, BadgeUI } from './styles/navigation-styles';
import Text from '../text';

const NavigationMenuItem = ( props ) => {
const {
badge,
children,
hasChildren,
id,
Expand All @@ -43,6 +44,7 @@ const NavigationMenuItem = ( props ) => {
<Text variant="body.small">
<span>{ title }</span>
</Text>
{ badge && <BadgeUI>{ badge }</BadgeUI> }
{ hasChildren ? <Icon icon={ chevronRight } /> : null }
</Button>
</MenuItemUI>
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/navigation/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ const data = [
{
title: 'Category',
id: 'item-3',
badge: '2',
},
{
title: 'Child 1',
id: 'child-1',
parent: 'item-3',
badge: '1',
},
{
title: 'Child 2',
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/navigation/styles/navigation-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import styled from '@emotion/styled';

/**
* Internal dependencies
*/
import { LIGHT_GRAY } from '../../utils/colors-values';

export const Root = styled.div`
width: 100%;
`;
Expand All @@ -22,3 +27,11 @@ export const MenuItemUI = styled.li`
border-bottom: 2px solid var( --wp-admin-theme-color );
}
`;

export const BadgeUI = styled.span`
margin-left: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed to keep even spacing between elements if a menu item name is longer. Note the spacing here is uneven:
Screen Shot 2020-08-17 at 4 13 13 PM

Keeping the margin on the badge is a better choice than the text so that elements are preemptively shortened if a badge does not exist.

display: inline-flex;
padding: 4px 12px;
border-radius: 2px;
background-color: ${ LIGHT_GRAY[ 300 ] };
`;