|
1 | | -import { Box, Callout, Code, ExternalLink, Header } from "react-lib-tools"; |
2 | | -import { html as HorizontalHTML } from "../../public/generated/examples/LayoutBasicsHorizontal.json"; |
3 | | -import { html as SeparatorHTML } from "../../public/generated/examples/LayoutBasicsSeparator.json"; |
4 | | -import { html as VerticalHTML } from "../../public/generated/examples/LayoutBasicsVertical.json"; |
| 1 | +import { useDefaultLayout, usePanelRef } from "react-resizable-panels"; |
5 | 2 | import { Group } from "../components/styled-panels/Group"; |
6 | 3 | import { Panel } from "../components/styled-panels/Panel"; |
7 | 4 | import { Separator } from "../components/styled-panels/Separator"; |
8 | 5 |
|
9 | 6 | export default function LayoutBasicsRoute() { |
| 7 | + const { defaultLayout, onLayoutChange } = useDefaultLayout({ |
| 8 | + id: "1", |
| 9 | + storage: localStorage |
| 10 | + }); |
| 11 | + |
| 12 | + const panelRef = usePanelRef(); |
| 13 | + |
| 14 | + const togglePanel = () => { |
| 15 | + const panel = panelRef.current; |
| 16 | + if (panel) { |
| 17 | + if (panel.isCollapsed()) { |
| 18 | + panel.expand(); |
| 19 | + } else { |
| 20 | + panel.collapse(); |
| 21 | + } |
| 22 | + } |
| 23 | + }; |
| 24 | + |
10 | 25 | return ( |
11 | | - <Box direction="column" gap={4}> |
12 | | - <Header section="Examples" title="The basics" /> |
13 | | - <div> |
14 | | - The simplest resizable panel configuration is two panels within a group. |
15 | | - </div> |
16 | | - <Code html={HorizontalHTML} /> |
17 | | - <Group className="h-15"> |
18 | | - <Panel>left</Panel> |
19 | | - <Panel>right</Panel> |
20 | | - </Group> |
21 | | - <div> |
22 | | - Panel groups use a{" "} |
23 | | - <ExternalLink href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Flexible_box_layout/Basic_concepts"> |
24 | | - flexbox |
25 | | - </ExternalLink>{" "} |
26 | | - layout with a default orientation of <em>horizontal</em> but the{" "} |
27 | | - <code>orientation</code> prop can be used to specify a <em>vertical</em>{" "} |
28 | | - layout. |
29 | | - </div> |
30 | | - <Code html={VerticalHTML} /> |
31 | | - <Callout intent="warning"> |
32 | | - Vertical groups require an explicit height to be set using either{" "} |
33 | | - <code>className</code> or <code>style</code> props. |
34 | | - </Callout> |
35 | | - <Group className="h-30" orientation="vertical"> |
36 | | - <Panel>top</Panel> |
37 | | - <Panel>bottom</Panel> |
38 | | - </Group> |
39 | | - <div> |
40 | | - Panels can be resized by clicking on their borders but explicit |
41 | | - separators can be rendered to improve UX. |
42 | | - </div> |
43 | | - <Group className="h-15"> |
44 | | - <Panel>left</Panel> |
45 | | - <Separator orientation="horizontal" /> |
46 | | - <Panel>right</Panel> |
| 26 | + <div> |
| 27 | + <button onClick={togglePanel}>Toggle Panel</button> |
| 28 | + <Group defaultLayout={defaultLayout} onLayoutChange={onLayoutChange}> |
| 29 | + <Panel id="panel1" defaultSize={30}> |
| 30 | + Panel 1 |
| 31 | + </Panel> |
| 32 | + <Separator /> |
| 33 | + <Panel id="panel2" defaultSize={70} collapsible panelRef={panelRef}> |
| 34 | + Panel 2 |
| 35 | + </Panel> |
47 | 36 | </Group> |
48 | | - <Code html={SeparatorHTML} /> |
49 | | - <Callout intent="primary"> |
50 | | - Separators improve keyboard accessibility by providing a tab-focusable{" "} |
51 | | - <ExternalLink href="https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/"> |
52 | | - window splitter |
53 | | - </ExternalLink>{" "} |
54 | | - element. |
55 | | - </Callout> |
56 | | - </Box> |
| 37 | + </div> |
57 | 38 | ); |
58 | 39 | } |
0 commit comments