Skip to content

Commit 3ac42ef

Browse files
committed
chore(website): Add demo for rendering DropdownMenus as a Grid
1 parent 2b5fb23 commit 3ac42ef

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This example shows you how you create a `DropdownMenu` that displays the
2+
`MenuItem` in a grid using the `listClassName` prop and a few custom styles.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@use 'react-md' as *;
2+
3+
.grid {
4+
// since the icons are stacked, set the menu icon spacing back to the default
5+
// icon spacing
6+
@include rmd-menu-theme-update-var(icon-spacing, $rmd-icon-spacing-with-text);
7+
8+
display: grid;
9+
gap: 0.25rem;
10+
grid-template-columns: repeat(3, minmax(0, 1fr));
11+
padding: 0.5rem;
12+
}
13+
14+
.item {
15+
flex-direction: column;
16+
text-align: center;
17+
}
18+
19+
.separator {
20+
grid-column-end: span 3;
21+
margin-top: 0.5rem;
22+
}
23+
24+
.all {
25+
grid-column-end: span 3;
26+
text-align: center;
27+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { ReactElement, ReactNode } from "react";
2+
import { AppBar, useActionClassName } from "@react-md/app-bar";
3+
import { TextIconSpacing } from "@react-md/icon";
4+
import {
5+
AppsSVGIcon,
6+
SaveSVGIcon,
7+
SchoolSVGIcon,
8+
SdCardSVGIcon,
9+
ShoppingBasketSVGIcon,
10+
ShopSVGIcon,
11+
ShowChartSVGIcon,
12+
SpaSVGIcon,
13+
StorageSVGIcon,
14+
SubwaySVGIcon,
15+
} from "@react-md/material-icons";
16+
import { DropdownMenu, MenuItem, MenuItemSeparator } from "@react-md/menu";
17+
18+
import styles from "./DropdownMenuGrid.module.scss";
19+
20+
interface GridItemProps {
21+
icon: ReactNode;
22+
children: ReactNode;
23+
}
24+
25+
function GridMenuItem({ children, icon }: GridItemProps): ReactElement {
26+
return (
27+
<MenuItem className={styles.item} textChildren={false}>
28+
<TextIconSpacing stacked icon={icon}>
29+
{children}
30+
</TextIconSpacing>
31+
</MenuItem>
32+
);
33+
}
34+
35+
export default function DropdownMenuGrid(): ReactElement {
36+
return (
37+
<AppBar>
38+
<DropdownMenu
39+
id="grid-like-menu"
40+
aria-label="Apps"
41+
buttonType="icon"
42+
buttonChildren={<AppsSVGIcon />}
43+
renderAsSheet="phone"
44+
listClassName={styles.grid}
45+
className={useActionClassName({ first: true, last: true })}
46+
>
47+
<GridMenuItem icon={<ShopSVGIcon />}>App One</GridMenuItem>
48+
<GridMenuItem icon={<ShowChartSVGIcon />}>App Two</GridMenuItem>
49+
<GridMenuItem icon={<ShoppingBasketSVGIcon />}>App Three</GridMenuItem>
50+
<GridMenuItem icon={<SpaSVGIcon />}>App Four</GridMenuItem>
51+
<GridMenuItem icon={<SchoolSVGIcon />}>App Five</GridMenuItem>
52+
<GridMenuItem icon={<SaveSVGIcon />}>App Six</GridMenuItem>
53+
<GridMenuItem icon={<SdCardSVGIcon />}>App Seven</GridMenuItem>
54+
<GridMenuItem icon={<SubwaySVGIcon />}>App Eight</GridMenuItem>
55+
<GridMenuItem icon={<StorageSVGIcon />}>App Nine</GridMenuItem>
56+
<MenuItemSeparator className={styles.separator} />
57+
<MenuItem className={styles.all}>View All</MenuItem>
58+
</DropdownMenu>
59+
</AppBar>
60+
);
61+
}

packages/documentation/src/components/Demos/Menu/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import menusWithFormComponents from "./MenusWithFormComponents.md";
3434
import HoverableMenus from "./HoverableMenus";
3535
import hoverableMenus from "./HoverableMenus.md";
3636

37+
import DropdownMenuGrid from "./DropdownMenuGrid";
38+
import dropdownMenuGrid from "./DropdownMenuGrid.md";
39+
3740
const demos: DemoConfig[] = [
3841
{
3942
name: "Simple Example",
@@ -80,6 +83,12 @@ const demos: DemoConfig[] = [
8083
fullPageFAB: true,
8184
disableFullPageAppBar: true,
8285
},
86+
{
87+
name: "Dropdown Menu Grid",
88+
description: dropdownMenuGrid,
89+
children: <DropdownMenuGrid />,
90+
disableCard: true,
91+
},
8392
];
8493

8594
// demos will be wrapped with the IconProvider just in-case people inspect the DOM

0 commit comments

Comments
 (0)