Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MenuList to accept boolean, null and undefined as its children #51

Merged
merged 1 commit into from
Jan 21, 2020
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
4 changes: 3 additions & 1 deletion src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const MenuListContext = React.createContext<MenuListContextType>({
onKeyDown: () => {}
});

type ChildrenType = React.ReactElement<MenuItemProps>;
// This type definition including boolean, null and undefined is based on
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/24f1d0c82da2d898acd03fbb3e692eba3c431f82/types/react/index.d.ts#L202
type ChildrenType = React.ReactElement<MenuItemProps> | boolean | null | undefined;

export interface MenuListProps extends React.HTMLAttributes<HTMLDivElement> {
/** A combination of MenuItem, MenuLabel, and MenuDivider children */
Expand Down
22 changes: 19 additions & 3 deletions src/stories/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/** @jsx jsx */
import { useState } from 'react';
import { jsx } from "@emotion/core";
import * as React from "react";
import { MenuList, MenuItem, MenuDivider, MenuLabel } from "../Menu";
import { Button } from "../Button";
import { storiesOf } from "@storybook/react";
import { ToggleDarkMode } from "./ToggleDarkMode";
import { Text } from "../Text";
import { IconAirplay, IconUser, IconAlertCircle, IconDelete } from "../Icons";

export const MenuStories = storiesOf("MenuList", module)
Expand Down Expand Up @@ -47,4 +46,21 @@ export const MenuStories = storiesOf("MenuList", module)
</MenuItem>
</MenuList>
);
})
.add("Conditional items", () => {
return <ConditionalMenuList />;
});

const ConditionalMenuList = () => {
const [showItem, setShowItem] = useState(false);

return (
<div>
<Button onClick={() => setShowItem(!showItem)}>Toggle list item appearance</Button>
<MenuList css={{ maxWidth: "340px" }}>
<MenuItem>Stable list item</MenuItem>
{showItem && <MenuItem>Toggled list item</MenuItem>}
</MenuList>
</div>
)
}