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

feat: menu item suffix #1427

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: The MenuItem accepts a suffix prop

Scenario: MenuItem renders supplied suffix
Given a MenuItem supplied with a suffix is rendered
Then the suffix will be visible
10 changes: 10 additions & 0 deletions components/menu/src/menu-item/features/accepts_suffix/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

Given('a MenuItem supplied with a suffix is rendered', () => {
cy.visitStory('MenuItem', 'With Suffix')
cy.get('[data-test="dhis2-uicore-menuitem"]').should('be.visible')
})

Then('the suffix will be visible', () => {
cy.contains('Suffix').should('be.visible')
})
5 changes: 5 additions & 0 deletions components/menu/src/menu-item/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const MenuItem = ({
label,
showSubMenu,
toggleSubMenu,
suffix,
}) => {
const menuItemRef = useRef()

Expand Down Expand Up @@ -73,6 +74,8 @@ const MenuItem = ({

<span className="label">{label}</span>

{suffix && <span className="suffix">{suffix}</span>}

{(chevron || children) && (
<span className="chevron">
<IconChevronRight24 />
Expand Down Expand Up @@ -118,6 +121,8 @@ MenuItem.propTypes = {
label: PropTypes.node,
/** When true, nested menu items are shown in a Popper */
showSubMenu: PropTypes.bool,
/** A supporting element shown at the end of the menu item */
suffix: PropTypes.node,
/** For using menu item as a link */
target: PropTypes.string,
/** On click, this function is called (without args) */
Expand Down
2 changes: 2 additions & 0 deletions components/menu/src/menu-item/menu-item.stories.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ export const WithTarget = () => (
export const WithIcon = () => (
<MenuItem icon={<div>Icon</div>} label="Menu item" />
)

export const WithSuffix = () => <MenuItem suffix="Suffix" label="Menu item" />
14 changes: 13 additions & 1 deletion components/menu/src/menu-item/menu-item.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { IconApps24 } from '@dhis2/ui-icons'
import { colors } from '@dhis2/ui-constants'
import {
IconApps24,
IconVisualizationColumn24,
IconLaunch16,
} from '@dhis2/ui-icons'
import React, { useState } from 'react'
import { Menu } from '../index.js'
import { MenuItem } from './menu-item.js'
Expand Down Expand Up @@ -85,6 +90,13 @@ Icon.parameters = {
},
}

export const Suffix = Template.bind({})
Suffix.args = {
label: 'Open in Data Visualizer',
icon: <IconVisualizationColumn24 color={colors.grey600} />,
suffix: <IconLaunch16 color={colors.grey600} />,
}

export const OnClick = (args) => (
<Menu>
<MenuItem
Expand Down
6 changes: 6 additions & 0 deletions components/menu/src/menu-item/menu-item.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export default css`
height: 24px;
}

.suffix {
display: flex;
align-items: center;
margin-left: ${spacers.dp8};
}

.chevron {
display: flex;
align-items: center;
Expand Down
17 changes: 16 additions & 1 deletion docs/docs/components/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Menu
---

import { Demo } from '@site/src/components/DemoComponent.jsx'
import { FlyoutMenu, MenuItem, MenuDivider, MenuSectionHeader, IconSave24, IconDelete24, IconShare24, IconEdit24 } from '@dhis2/ui'
import { FlyoutMenu, MenuItem, MenuDivider, MenuSectionHeader, IconSave24, IconDelete24, IconShare24, IconEdit24, IconVisualizationColumn24, IconFilter24, IconClock24, IconLaunch16 } from '@dhis2/ui'

import API from '../../../components/menu/API.md'

Expand Down Expand Up @@ -106,6 +106,21 @@ A menu gives access to menu items, through a panel that opens from a trigger ele
- Dividers can also show a section header, a text label for that group of menu items.
- Use a section header to clarify what the menu items refer to, but don't rely on it. Menus and menu item actions should be clear without needing section headers.

### Suffix

<Demo>
<FlyoutMenu className="demo-fullwidth">
<MenuItem icon= {<IconFilter24 />} label="Filter data" />
<MenuItem icon= {<IconClock24 />} label="Change time period" />
<MenuItem icon= {<IconVisualizationColumn24 />} label="Open in Data Visualizer app" suffix= {<IconLaunch16/>}/>
</FlyoutMenu>
</Demo>

- A menu item can show a suffix.
- Use a suffix to show extra information about the context or intent of a menu item.
- Common use cases include showing a menu item's keyboard shortcut and showing an indicator that a menu item will open a new tab.
- Don't include interactive components, like buttons, in a menu item suffix.

### Icon

<Demo>
Expand Down
3 changes: 3 additions & 0 deletions docs/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,6 @@ footer {
flex-direction: column;
gap: 8px;
}
.demo-fullwidth {
width: 100%;
}
Loading