/
SheetSizing.tsx
131 lines (125 loc) · 3.93 KB
/
SheetSizing.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import type { ReactElement } from "react";
import { useEffect, useState } from "react";
import { AppBar, AppBarAction } from "@react-md/app-bar";
import { Button } from "@react-md/button";
import { DialogContent } from "@react-md/dialog";
import {
Checkbox,
Fieldset,
Form,
Select,
useSelectState,
} from "@react-md/form";
import { List, ListItem } from "@react-md/list";
import { ArrowDropDownSVGIcon, CloseSVGIcon } from "@react-md/material-icons";
import type {
SheetHorizontalSize,
SheetPosition,
SheetVerticalSize,
} from "@react-md/sheet";
import { Sheet } from "@react-md/sheet";
import { GridList, useAppSize, useToggle } from "@react-md/utils";
import ConditionalPhone from "components/Phone/ConditionalPhone";
const positions: SheetPosition[] = ["top", "right", "bottom", "left"];
const horizontalSizes: SheetHorizontalSize[] = [
"none",
"touch",
"static",
"media",
];
const verticalSizes: SheetVerticalSize[] = ["none", "touch", "recommended"];
export default function SheetSizing(): ReactElement {
const [visible, show, hide] = useToggle(false);
const [position, setPosition] = useSelectState<SheetPosition>("left");
const [horizontalSize, setHorizontalSize] =
useSelectState<SheetHorizontalSize>("media");
const [verticalSize, setVerticalSize] =
useSelectState<SheetVerticalSize>("recommended");
const isHorizontal = position === "left" || position === "right";
const [emulate, setEmulate] = useState(false);
const { isDesktop } = useAppSize();
useEffect(() => {
if (emulate && !isDesktop) {
setEmulate(false);
}
}, [emulate, isDesktop]);
return (
<Form>
<Fieldset legend="Position Options">
<GridList clone maxCellSize={300}>
<Select
id="sheet-sizing-position"
label="Position"
options={positions}
value={position}
onChange={setPosition}
rightChildren={<ArrowDropDownSVGIcon />}
/>
<Select
id="sheet-sizing-horizontal"
label="Horizontal Size"
options={horizontalSizes}
value={horizontalSize}
onChange={setHorizontalSize}
disabled={!isHorizontal}
rightChildren={<ArrowDropDownSVGIcon />}
/>
<Select
id="sheet-sizing-vertical"
label="Vertical Size"
options={verticalSizes}
value={verticalSize}
onChange={setVerticalSize}
disabled={isHorizontal}
rightChildren={<ArrowDropDownSVGIcon />}
/>
{isDesktop && (
<Checkbox
id="sheet-sizing-emulate"
checked={emulate}
onChange={() => setEmulate(!emulate)}
label="Emulate?"
/>
)}
</GridList>
</Fieldset>
<Button
id="sheet-sizing-toggle"
onClick={show}
type="submit"
theme="secondary"
themeType="contained"
>
Show
</Button>
<ConditionalPhone id="example-sheet" enabled={emulate}>
<Sheet
id="example-sheet"
aria-label="Example Sheet"
position={position}
horizontalSize={horizontalSize}
verticalSize={verticalSize}
visible={visible}
onRequestClose={hide}
portalIntoId={emulate ? "example-sheet-content" : undefined}
disableScrollLock={emulate}
>
<AppBar theme="clear">
<AppBarAction first={position !== "right"} last onClick={hide}>
<CloseSVGIcon />
</AppBarAction>
</AppBar>
<DialogContent>
<List>
{Array.from({ length: 10 }, (_, i) => (
<ListItem id={`example-sheet-item-${i + 1}`} key={i}>
{`Item ${i + 1}`}
</ListItem>
))}
</List>
</DialogContent>
</Sheet>
</ConditionalPhone>
</Form>
);
}