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

feat(menu): Vertical Pills menu #36

Merged
merged 3 commits into from
Aug 3, 2018
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
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` }),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should make the margin consistent for the pills menu for the vertical and horizontal type, both to be 5px or 8 px whatever you think looks better.

borderRadius: pxToRem(5),
}),
...(shape === 'underlined' && {
Expand Down