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

Commit

Permalink
feat(menu): Vertical Pills menu (#36)
Browse files Browse the repository at this point in the history
* feat(menu): Vertical Pills menu

* changelog
  • Loading branch information
miroslavstastny authored and kuzhelov committed Aug 3, 2018
1 parent 0f6fce0 commit dfb30a8
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add Button `disabled` prop @Bugaa92 ([#14](https://github.com/stardust-ui/react/pull/14))
- Add Label `icon`, `onIconClick` and `iconPosition` props @mnajdova ([#19](https://github.com/stardust-ui/react/pull/19))
- Add Menu `vertical` prop @miroslavstastny ([#21](https://github.com/stardust-ui/react/pull/21))
- Add Menu support for `shape="pills" vertical` @miroslavstastny ([#36](https://github.com/stardust-ui/react/pull/36))

### Documentation
- Improve UX for "knobs" form on component examples @levithomason ([#20](https://github.com/stardust-ui/react/pull/20))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { Menu } from '@stardust-ui/react'

const items = [
{ key: 'editorials', content: 'Editorials' },
{ key: 'review', content: 'Reviews' },
{ key: 'events', content: 'Upcoming Events' },
]

class MenuExamplePillsPrimaryVerticalShorthand extends React.Component {
render() {
return <Menu defaultActiveIndex={0} items={items} shape="pills" type="primary" vertical />
}
}

export default MenuExamplePillsPrimaryVerticalShorthand
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import _ from 'lodash'
import { Menu, MenuItem } from '@stardust-ui/react'

const items = [
{ key: 'editorials', content: 'Editorials' },
{ key: 'review', content: 'Reviews' },
{ key: 'events', content: 'Upcoming Events' },
]

class MenuExamplePillsPrimaryVertical extends React.Component {
state = { activeIndex: 0 }

handleItemClick = activeIndex => () => {
this.setState({ activeIndex })
}

render() {
const { activeIndex } = this.state
return (
<Menu defaultActiveIndex={0} shape="pills" type="primary" vertical>
{_.times(3, i => {
return (
<MenuItem
key={items[i].key}
content={items[i].content}
shape="pills"
type="primary"
vertical
active={activeIndex === i}
onClick={this.handleItemClick(i)}
/>
)
})}
</Menu>
)
}
}

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

const items = [
{ key: 'editorials', content: 'Editorials' },
{ key: 'review', content: 'Reviews' },
{ key: 'events', content: 'Upcoming Events' },
]

class MenuExamplePillsVerticalShorthand extends React.Component {
render() {
return <Menu defaultActiveIndex={0} items={items} shape="pills" vertical />
}
}

export default MenuExamplePillsVerticalShorthand
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import _ from 'lodash'
import { Menu, MenuItem } from '@stardust-ui/react'

const items = [
{ key: 'editorials', content: 'Editorials' },
{ key: 'review', content: 'Reviews' },
{ key: 'events', content: 'Upcoming Events' },
]

class MenuExamplePillsVertical extends React.Component {
state = { activeIndex: 0 }

handleItemClick = activeIndex => () => {
this.setState({ activeIndex })
}

render() {
const { activeIndex } = this.state
return (
<Menu defaultActiveIndex={0} shape="pills" vertical>
{_.times(3, i => {
return (
<MenuItem
key={items[i].key}
content={items[i].content}
shape="pills"
vertical
active={activeIndex === i}
onClick={this.handleItemClick(i)}
/>
)
})}
</Menu>
)
}
}

export default MenuExamplePillsVertical
10 changes: 10 additions & 0 deletions docs/src/examples/components/Menu/Variations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ const Variations = () => (
description="A menu can adjust its appearance to de-emphasize its contents."
examplePath="components/Menu/Variations/MenuExamplePills"
/>
<ComponentExample
title="Pills Vertical"
description="A vertical variant of Pills menu"
examplePath="components/Menu/Variations/MenuExamplePillsVertical"
/>
<ComponentExample
title="Pills Primary"
description="A menu can adjust its appearance to de-emphasize its contents."
examplePath="components/Menu/Variations/MenuExamplePillsPrimary"
/>
<ComponentExample
title="Pills Primary Vertical"
description="A vertical variant of Pills Primary menu"
examplePath="components/Menu/Variations/MenuExamplePillsPrimaryVertical"
/>
<ComponentExample
title="Pointing"
description="A menu can point to show its relationship to nearby content."
Expand Down
4 changes: 2 additions & 2 deletions src/components/Menu/menuItemRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const itemSeparator = ({ props, variables }) => {

export default {
root: ({ props, variables }) => {
const { active, shape, type } = props
const { active, shape, type, vertical } = props
return {
color: variables.defaultColor,
lineHeight: 1,
Expand All @@ -41,7 +41,7 @@ export default {
cursor: 'pointer',
display: 'block',
...(shape === 'pills' && {
margin: `0 ${pxToRem(8)} 0 0`,
...(vertical ? { margin: `0 0 ${pxToRem(5)} 0` } : { margin: `0 ${pxToRem(8)} 0 0` }),
borderRadius: pxToRem(5),
}),
...(shape === 'underlined' && {
Expand Down

0 comments on commit dfb30a8

Please sign in to comment.