Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

feat(menu): Submenu #539

Merged
merged 62 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
72ea550
feat(menuItem: add menu prop)
Oct 12, 2018
d4a3a0c
Only one submenu open at a time
Oct 15, 2018
85981f8
Fix bug: submenu noe closes on clicking a menuItem with no submenu
Oct 15, 2018
fa99935
Code cleanup
Oct 15, 2018
8271a18
Remove the activeIndex prop passed to the menuItem
Oct 15, 2018
35e8a76
Remove Popup and implement submenu without it
Nov 13, 2018
756f7fa
Merge branch 'master' into feat/menuitem-menu-prop
jurokapsiar Nov 28, 2018
bea260a
initial keyboard support
jurokapsiar Nov 29, 2018
8f678ec
left/right arrow handling
jurokapsiar Nov 29, 2018
0f4be8b
simplify keyboard handlers
jurokapsiar Nov 29, 2018
46d52c6
-fixed import in the MenuItem
Nov 30, 2018
c1ad2da
-added submenuIndicator
Nov 30, 2018
acee5ee
-clicking on leaf element should close the submenus (the same should …
Nov 30, 2018
4b4976f
Merge branch 'master' into feat/menuitem-menu-prop
Dec 7, 2018
5575653
-implemented outside click to close all menus
Dec 7, 2018
7a17afb
-fixed import
Dec 7, 2018
62620ae
-refactored MenuItem handlers - fixed issues
Dec 11, 2018
d85b164
-added setActiveIndex callback and removed onKeyDown in the creation …
Dec 12, 2018
e091af2
-right arrow key is closing the submenus and goes to the next element…
Dec 12, 2018
279c7fa
-handled left arrow key
Dec 12, 2018
8cc9391
-changed ref
Dec 13, 2018
920f253
-added Ref component instead of using the itemRef on the ElementType
Dec 13, 2018
cbe375b
Merge branch 'master' into feat/menuitem-menu-prop
Dec 13, 2018
9e3763e
-fixes
Dec 13, 2018
afbdbfa
-moved ref //TODO: figure out tests failing
Dec 13, 2018
d3ab055
-close menu on outside focus
Dec 14, 2018
5653db3
-improved comments
Dec 14, 2018
4bb8ee8
-fixed escape key not focusing the active element
Dec 14, 2018
fac4161
-fixing key problems
Dec 14, 2018
0e1941d
-refactored submenuRef element
Dec 14, 2018
168b16a
fix broken tests
layershifter Dec 14, 2018
2baa1cb
-added comments in the tests
Dec 14, 2018
708897b
Merge branch 'master' into feat/menuitem-menu-prop
Dec 14, 2018
f61533b
-renamed inSubmenu to submenu prop in the Menu
Dec 16, 2018
636e51d
-fixed with the auto-controlled prop in the Menu
Dec 16, 2018
b97bcce
-added state interface in the Menu
Dec 16, 2018
eec33c1
-fixed variables in examples
Dec 16, 2018
950cd54
-remove state initialization in the MenuItem component
Dec 17, 2018
04a5313
-added new handler for escape
Dec 17, 2018
f5e66f0
-refactored conditions using doesNodeContainClick
Dec 17, 2018
4c8e2d6
-renamed submenu* props to menu in the MenuItem component
Dec 18, 2018
2ece67b
-improved example
Dec 18, 2018
a97a2fe
-exported MenuState
Dec 18, 2018
c590f3e
-fixed underlined active + hovered style
Dec 18, 2018
77342ea
-fixed border corner clipped by adding custom styles for the first ch…
Dec 19, 2018
69fcf38
-addressed comments on PR
Dec 19, 2018
54f0a69
chore: prepare release 0.15.0 [ci skip]
miroslavstastny Dec 17, 2018
9909483
0.15.0
miroslavstastny Dec 17, 2018
fa2e9bd
fix(Prototype): Fix Popover prototype after breaking changes (#623)
sophieH29 Dec 17, 2018
df0b11a
chore: cache results of vulnerability scans (#621)
kuzhelov Dec 18, 2018
1d8e168
feat(text): color prop (#597)
Dec 18, 2018
fa78e86
feat(header): header and header description color prop (#628)
Dec 18, 2018
4895301
fix(Popup): allow to 'detach' from trigger and RTL adjustments (#612)
kuzhelov Dec 18, 2018
3c6e75e
fix(SelectableList): Items in list should be selectable (#566)
sophieH29 Dec 19, 2018
d3d6012
docs(Examples): allow to use TS in examples (#617)
layershifter Dec 19, 2018
e5aa7b3
-updated changelog
Dec 19, 2018
14eb199
Merge branch 'master' into feat/menuitem-menu-prop
Dec 19, 2018
3c55948
-updated changelog
Dec 19, 2018
6aac80b
-updated changelog with breaking changes
Dec 19, 2018
d2d3412
Merge branch 'master' into feat/menuitem-menu-prop
Dec 19, 2018
1849f5f
Merge branch 'master' into feat/menuitem-menu-prop
Dec 19, 2018
e592039
-fixed imports in examples
Dec 19, 2018
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### BREAKING CHANGES
- renamed Teams theme menu variables the contains props names as prefixes @mnajdova ([#539](https://github.com/stardust-ui/react/pull/539))

### Fixes
- Ensure `Popup` properly flips values of `offset` prop in RTL @kuzhelov ([#612](https://github.com/stardust-ui/react/pull/612))
- Fix `List` - items should be selectable @sophieH29 ([#566](https://github.com/stardust-ui/react/pull/566))
Expand All @@ -25,6 +28,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `color` prop to `Text` component @Bugaa92 ([#597](https://github.com/stardust-ui/react/pull/597))
- Add `color` prop to `Header` and `HeaderDescription` components @Bugaa92 ([#628](https://github.com/stardust-ui/react/pull/628))
- Add and export compose icons in Teams theme @joheredi ([#639](https://github.com/stardust-ui/react/pull/639))
- Add `menu` prop to `MenuItem` @mnajdova ([#539](https://github.com/stardust-ui/react/pull/539))

<!--------------------------------[ v0.15.0 ]------------------------------- -->
## [v0.15.0](https://github.com/stardust-ui/react/tree/v0.15.0) (2018-12-17)
Expand Down
1 change: 0 additions & 1 deletion docs/src/components/CodeSnippet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from 'lodash'
import * as React from 'react'

import formatCode from '../utils/formatCode'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react'
import { Menu } from '@stardust-ui/react'

const items = [
{
key: 'editorials',
content: 'Editorials',
menu: {
items: [
{ key: '1', content: 'item1' },
{
key: '2',
content: 'item2',
menu: { items: [{ key: '1', content: 'item1' }, { key: '2', content: 'item2' }] },
},
],
},
},
{ key: 'review', content: 'Reviews' },
{ key: 'events', content: 'Upcoming Events' },
]

const MenuExampleVerticalWithSubmenu = () => <Menu defaultActiveIndex={0} vertical items={items} />

export default MenuExampleVerticalWithSubmenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react'
import { Menu } from '@stardust-ui/react'

const items = [
{
key: 'editorials',
content: 'Editorials',
menu: {
items: [
{ key: '1', content: 'item1' },
{
key: '2',
content: 'item2',
menu: { items: [{ key: '1', content: 'item2.1' }, { key: '2', content: 'item2.2' }] },
},
{
key: '3',
content: 'item3',
menu: { items: [{ key: '1', content: 'item3.1' }, { key: '2', content: 'item3.2' }] },
},
],
},
},
{
key: 'review',
content: 'Reviews',
menu: {
items: [
{ key: '1', content: 'item1' },
{
key: '2',
content: 'item2',
menu: { items: [{ key: '1', content: 'item2.1' }, { key: '2', content: 'item2.2' }] },
},
],
},
},
{ key: 'events', content: 'Upcoming Events' },
]

const MenuExampleWithSubMenu = () => <Menu defaultActiveIndex={0} items={items} />

export default MenuExampleWithSubMenu
6 changes: 6 additions & 0 deletions docs/src/examples/components/Menu/Types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const Types = () => (
description="A vertical menu displays elements vertically."
examplePath="components/Menu/Types/MenuExampleVertical"
/>
<ComponentExample
title="Menu with submenus"
description="A menu can have submenus."
examplePath="components/Menu/Types/MenuExampleWithSubmenu"
/>
<ComponentExample examplePath="components/Menu/Types/MenuExampleVerticalWithSubmenu" />
</ExampleSection>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const MenuExampleIconOnlyPrimaryInverted = () => (
items={items}
primary
variables={siteVars => ({
defaultColor: siteVars.gray06,
defaultBackgroundColor: siteVars.brand,
typePrimaryActiveBorderColor: siteVars.white,
color: siteVars.gray06,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

backgroundColor: siteVars.brand,
primaryActiveBorderColor: siteVars.white,
})}
/>
)
Expand Down
36 changes: 30 additions & 6 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as React from 'react'
import {
AutoControlledComponent,
childrenExist,
createShorthandFactory,
customPropTypes,
UIComponentProps,
ChildrenComponentProps,
Expand Down Expand Up @@ -60,12 +61,19 @@ export interface MenuProps extends UIComponentProps, ChildrenComponentProps {

/** A vertical menu displays elements vertically. */
vertical?: boolean

/** Indicates whether the menu is submenu. */
submenu?: boolean
}

export interface MenuState {
activeIndex?: number | string
}

/**
* A menu displays grouped navigation actions.
*/
class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> {
class Menu extends AutoControlledComponent<Extendable<MenuProps>, MenuState> {
static displayName = 'Menu'

static className = 'ui-menu'
Expand All @@ -88,6 +96,7 @@ class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> {
secondary: customPropTypes.every([customPropTypes.disallow(['primary']), PropTypes.bool]),
underlined: PropTypes.bool,
vertical: PropTypes.bool,
submenu: PropTypes.bool,
Copy link
Contributor

@kuzhelov kuzhelov Dec 17, 2018

Choose a reason for hiding this comment

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

here is another clear example - lets just take a look on the following code:

<Menu submenu={...} />

given this code, what we might expect to be passed as a submenu's value? actually, I would expect items collection. This is what we have for MenuItem's menu, but here - this is a boolean flag :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally agree, for consistency I will leave it as this, and will create issue for renaming all boolean props to have the is prefix. Thanks for pointing this out.

}

static defaultProps = {
Expand All @@ -107,6 +116,15 @@ class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> {

_.invoke(predefinedProps, 'onClick', e, itemProps)
},
onActiveChanged: (e, props) => {
const { index, active } = props
if (active) {
this.trySetState({ activeIndex: index })
} else if (this.state.activeIndex === index) {
this.trySetState({ activeIndex: null })
}
_.invoke(predefinedProps, 'onActiveChanged', e, props)
},
})

renderItems = (variables: ComponentVariablesObject) => {
Expand All @@ -119,11 +137,14 @@ class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> {
secondary,
underlined,
vertical,
submenu,
} = this.props
const { activeIndex } = this.state

return _.map(items, (item, index) =>
MenuItem.create(item, {
return _.map(items, (item, index) => {
const active =
(typeof activeIndex === 'string' ? parseInt(activeIndex, 10) : activeIndex) === index
return MenuItem.create(item, {
defaultProps: {
iconOnly,
pills,
Expand All @@ -134,11 +155,12 @@ class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> {
variables,
vertical,
index,
active: parseInt(activeIndex, 10) === index,
active,
inSubmenu: submenu,
},
overrideProps: this.handleItemOverrides,
}),
)
})
})
}

renderComponent({ ElementType, classes, accessibility, variables, rest }) {
Expand All @@ -151,4 +173,6 @@ class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> {
}
}

Menu.create = createShorthandFactory(Menu, 'items')

export default Menu
Loading