Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat(layout): added prop to control toggleable layouts default visibi…
…lity This adds the new prop `defaultToggleableVisible` and some more documentation around controlling the visibility of the layout. Closes #1066
- Loading branch information
Showing
9 changed files
with
333 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Since there might be times where it is useful to update the temporary and | ||
toggleable layouts' visibility, this package also exports a `useLayoutConfig` | ||
hook to help out that returns the current configuration and controls. | ||
|
||
The example below will give a quick example using this hook to control the | ||
visibility of the navigation panel for non-persistent layouts. This example will | ||
also show how to make toggleable layouts default to being visible with a new | ||
`defaultToggleableVisible` prop introduced in `react-md@2.6.0`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.container { | ||
margin: 1rem; | ||
} | ||
|
||
.center { | ||
margin: 0 auto; | ||
} | ||
|
||
.select { | ||
min-width: 15rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { ReactElement, useState } from "react"; | ||
import cn from "classnames"; | ||
import { Checkbox, Select } from "@react-md/form"; | ||
import { Layout, SupportedWideLayout } from "@react-md/layout"; | ||
import { Grid } from "@react-md/utils"; | ||
|
||
import styles from "./ControllingTheLayout.module.scss"; | ||
import LayoutVisibility from "./LayoutVisibility"; | ||
import CloseButton from "./CloseButton"; | ||
|
||
const options: SupportedWideLayout[] = [ | ||
"temporary", | ||
// 'temporary-mini', // not supported yet | ||
"toggleable", | ||
// 'toggleable-mini', // not supported yet | ||
"clipped", | ||
"floating", | ||
"full-height", | ||
]; | ||
|
||
export default function ControllingTheLayout(): ReactElement { | ||
const [defaultVisible, setDefaultVisible] = useState(false); | ||
const [desktopLayout, setDesktopLayout] = useState<SupportedWideLayout>( | ||
"full-height" | ||
); | ||
|
||
return ( | ||
<Layout | ||
id="custom-layout" | ||
title="Toggleable Layout" | ||
navHeaderTitle="Another Title" | ||
tabletLayout="toggleable" | ||
landscapeTabletLayout="toggleable" | ||
desktopLayout={desktopLayout} | ||
largeDesktopLayout={desktopLayout} | ||
defaultToggleableVisible={defaultVisible} | ||
// this is only required since I already have a main element due to the | ||
// documentation site's Layout component | ||
mainProps={{ component: "div" }} | ||
navProps={{ | ||
// added a button since there **has** to be something focusable in the | ||
// nav when the temporary layout is chosen | ||
children: <CloseButton />, | ||
}} | ||
> | ||
<Grid columns={1} className={styles.container}> | ||
<Checkbox | ||
id="visibility" | ||
label="Toggleable default visible?" | ||
checked={defaultVisible} | ||
onChange={(event) => setDefaultVisible(event.currentTarget.checked)} | ||
className={styles.center} | ||
/> | ||
<Select | ||
id="desktop-layout" | ||
label="Desktop Layout" | ||
value={desktopLayout} | ||
options={options} | ||
onChange={(nextValue) => { | ||
if (options.includes(nextValue as SupportedWideLayout)) { | ||
setDesktopLayout(nextValue as SupportedWideLayout); | ||
} | ||
}} | ||
className={cn(styles.center, styles.select)} | ||
/> | ||
<LayoutVisibility /> | ||
</Grid> | ||
</Layout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { ReactElement } from "react"; | ||
import { Button } from "@react-md/button"; | ||
import { isPersistentLayout, useLayoutConfig } from "@react-md/layout"; | ||
|
||
import CodeBlock from "components/Code/CodeBlock"; | ||
import Blockquote from "components/Blockquote"; | ||
|
||
export default function LayoutVisibility(): ReactElement { | ||
const { showNav, hideNav, ...remaining } = useLayoutConfig(); | ||
const code = `const config = ${JSON.stringify( | ||
{ | ||
showNav: "function", | ||
hideNav: "function", | ||
...remaining, | ||
}, | ||
null, | ||
2 | ||
)}`; | ||
|
||
return ( | ||
<div> | ||
<CodeBlock language="typescript">{code}</CodeBlock> | ||
{isPersistentLayout(remaining.layout) && ( | ||
<Blockquote> | ||
The visibility cannot be changed for persistent layouts so the buttons | ||
will do nothing. | ||
</Blockquote> | ||
)} | ||
<Button onClick={showNav}>Show</Button> | ||
<Button onClick={hideNav} theme="secondary"> | ||
Hide | ||
</Button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.