-
Notifications
You must be signed in to change notification settings - Fork 53
feat(menu): Submenu #539
feat(menu): Submenu #539
Changes from all commits
72ea550
d4a3a0c
85981f8
fa99935
8271a18
35e8a76
756f7fa
bea260a
8f678ec
0f4be8b
46d52c6
c1ad2da
acee5ee
4b4976f
5575653
7a17afb
62620ae
d85b164
e091af2
279c7fa
8cc9391
920f253
cbe375b
9e3763e
afbdbfa
d3ab055
5653db3
4bb8ee8
fac4161
0e1941d
168b16a
2baa1cb
708897b
f61533b
636e51d
b97bcce
eec33c1
950cd54
04a5313
f5e66f0
4c8e2d6
2ece67b
a97a2fe
c590f3e
77342ea
69fcf38
54f0a69
9909483
fa2e9bd
df0b11a
1d8e168
fa78e86
4895301
3c6e75e
d3d6012
e5aa7b3
14eb199
3c55948
6aac80b
d2d3412
1849f5f
e592039
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,9 @@ const MenuExampleIconOnlyPrimaryInverted = () => ( | |
items={items} | ||
primary | ||
variables={siteVars => ({ | ||
defaultColor: siteVars.gray06, | ||
defaultBackgroundColor: siteVars.brand, | ||
typePrimaryActiveBorderColor: siteVars.white, | ||
color: siteVars.gray06, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
backgroundColor: siteVars.brand, | ||
primaryActiveBorderColor: siteVars.white, | ||
})} | ||
/> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import * as React from 'react' | |
import { | ||
AutoControlledComponent, | ||
childrenExist, | ||
createShorthandFactory, | ||
customPropTypes, | ||
UIComponentProps, | ||
ChildrenComponentProps, | ||
|
@@ -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 { | ||
mnajdova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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' | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
given this code, what we might expect to be passed as a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
static defaultProps = { | ||
|
@@ -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) => { | ||
|
@@ -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, | ||
|
@@ -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 }) { | ||
|
@@ -151,4 +173,6 @@ class Menu extends AutoControlledComponent<Extendable<MenuProps>, any> { | |
} | ||
} | ||
|
||
Menu.create = createShorthandFactory(Menu, 'items') | ||
|
||
export default Menu |
Uh oh!
There was an error while loading. Please reload this page.