This repository was archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
This repository was archived by the owner on Mar 31, 2021. It is now read-only.
Allow title prop of Menu.Group
to be PropTypes.element
. #48
Copy link
Copy link
Open
Labels
good first issueGood for newcomersGood for newcomers
Description
Would be useful when Menu.Group#title
would be also allow element
in addition to string
. So it's easier to combine <Hidden.Container>
and <Menu.Group>
.
<Menu.Group
title={<Box onClick={hidden.toggle}>Group A</Box>}>
<Hidden isVisible={hidden.isVisible}>
<Menu.Item>Item 1</Menu.Item>
</Hidden>
</Menu.Group>
Warning message in browser console:
Warning: Failed prop type: Invalid prop
title
of typeobject
supplied toMenuGroup$$1
, expectedstring
Current propTypes
:
MenuGroup.propTypes = {
children: PropTypes.node.isRequired,
title: PropTypes.string
};
Proposed propTypes
:
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
Example Menu.jsx
:
import React from "react"
import {
Set,
Box,
Flex,
Menu,
Hidden,
Text,
ThemeProvider,
css,
} from "fannypack"
export const theme = () => ({
Menu: {
Group: {
base: css`
cursor: pointer;
user-select: none;
`,
},
Item: {
base: css``,
},
},
})
export default ({ ...otherProps }) => {
return (
<ThemeProvider theme={theme()}>
<Box {...otherProps}>
<Menu a11yTitle="Main menu">
<Hidden.Container defaultVisible={true}>
{hidden => (
<Menu.Group
title={
<Flex onClick={hidden.toggle}>
<Text flex="1">Group A</Text>
<Text>{hidden.isVisible ? "opened" : "closed"}</Text>
</Flex>
}
>
<Hidden isVisible={hidden.isVisible}>
<Menu.Item>Item 1</Menu.Item>
<Menu.Item>Item 2</Menu.Item>
<Menu.Item isActive>Item 3</Menu.Item>
<Menu.Item>Item 4</Menu.Item>
</Hidden>
</Menu.Group>
)}
</Hidden.Container>
</Menu>
</Box>
</ThemeProvider>
)
}
Example Menu.mdx
:
import { Playground } from "docz"
import Menu from "./Menu"
<Playground>
<Menu />
</Playground>
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers