A list used with a Menu to group a collection of related actions a user can act upon.
List
also display a collection of related items that can be acted upon.
The distinction is the items in the List
are nouns that you can take action on
and the items in the Menu
are verbs and themselves are actions.
List | Menu |
---|---|
Sally Engineer | Close Story |
Ken Test Engineer | Delete Story |
Danny Developer | Assign Story |
{() => {
class StateManager extends React.Component {
constructor(props) {
super(props)
this.state = {
isOpenIndex: -1,
items: [
{ name: 'My Shared View', project: 'Project A' },
{ name: 'Backlog Shared View', project: 'Project A' },
{ name: 'Backlog Shared View', project: 'Project B' },
{ name: 'Holiday Party', project: 'Project A' },
{ name: 'Roadmaping Latest Quarter', project: 'Project A' },
{ name: 'Team Q Backlog', project: 'Project A' },
],
}
this.open = this.open.bind(this)
this.close = this.close.bind(this)
}
open(index) {
return () => this.setState({ isOpenIndex: index })
}
close() {
this.setState({ isOpenIndex: -1 })
}
render() {
const getMenuForItemAt = index => {
const isOpen = this.state.isOpenIndex === index
return (
<Menu
anchor={<IconButton icon={InfoIcon} onClick={this.open(index)} />}
open={isOpen}
placement="bottom-end"
onClickOutside={this.close}
>
<List bordered>
<ListItem onClick={() => {}}>
<ListItemText primary="Action 1" />
<ListItem onClick={() => {}}>
<ListItemText primary="Action 2" />
</ListItem>
</List>
</Menu>
)
}
const ListItems = this.state.items.map((item, index) => (
<ListItem key={index} secondaryAction={getMenuForItemAt(index)}>
<ListItemText primary={item.name} secondary={item.project} />
</ListItem>
))
return (
<SpacedGroup xs={24}>
<Paper>
<List bordered>{ListItems}</List>
</Paper>
</SpacedGroup>
)
}
}
return <StateManager />
}}
</Playground>
{() => {
const InlineContainer = createComponent(
() => ({
display: 'inline-block',
}),
'div',
)
class StateManager extends React.Component {
constructor() {
super()
this.state = {
[0]: false,
[1]: false,
}
this.close = this.close.bind(this)
this.open = this.open.bind(this)
}
close(id) {
return () => {
this.setState({ [id]: false })
}
}
open(id) {
return () => {
this.setState({ [id]: true })
}
}
render() {
return (
<SpacedGroup>
<InlineContainer>
<Menu
disableContainment
anchor={<IconButton icon={InfoIcon} onClick={this.open(0)} />}
onClickOutside={this.close(0)}
open={this.state[0]}
placement="bottom-end"
>
<List bordered>
<ListItem onClick={() => {}}>
<ListItemText primary="Action 1" />
<ListItem onClick={() => {}}>
<ListItemText primary="Action 2" />
</ListItem>
</List>
</Menu>
</InlineContainer>
<InlineContainer>
<Menu
disableContainment
disableScrim
anchor={<IconButton icon={InfoIcon} onClick={this.open(1)} />}
open={this.state[1]}
onClickOutside={this.close(1)}
placement="bottom-end"
>
<List bordered>
<ListItem onClick={() => {}}>
<ListItemText primary="Action 1" />
</ListItem>
<ListItem onClick={() => {}}>
<ListItemText primary="Action 2" />
</ListItem>
</List>
</Menu>
</InlineContainer>
</SpacedGroup>
)
}
}
return <StateManager />
}}
</Playground>