docs/documentation/components/side-sheet.mdx
The SideSheet component is a panel overlaying the screen on the right side.
It is used to show more details about a certain object or person.
A SideSheet is often triggered by clicking a row in a table.
Side Sheets are a great way to cheat creating a new page.
As a general rule of thumb, a SideSheet should not be used as a replacement
of a new page when the page needs to be accessible by a URL.
Avoid showing a SideSheet based on a URL.
The SideSheet component does not have any opinion about the contents of the SideSheet.
In the examples below are some recipes to make sure usage of the SideSheet is consistent.
It is recommended to compose more opinionated Side Sheets in the consuming application.
When opening the SideSheet, focus will be brought inside the SideSheet by looking for elements with [autofocus] first, [tabindex] second and button last.
When closing the SideSheet, focus will be brought back to the element that was focused before opening the SideSheet.
This is normally the button that triggered the SideSheet.
function BasicSidesheetExample() {
const [isShown, setIsShown] = React.useState(false)
return (
<React.Fragment>
<SideSheet isShown={isShown} onCloseComplete={() => setIsShown(false)}>
<Paragraph margin={40}>Basic Example</Paragraph>
</SideSheet>
<Button onClick={() => setIsShown(true)}>Show Basic Side Sheet</Button>
</React.Fragment>
)
}
The SideSheet component can appearn on all side of the screens.
function CustomPositionSidesheetExample() {
const [isShown, setIsShown] = React.useState(false)
return (
<React.Fragment>
<SideSheet
position={Position.BOTTOM}
isShown={isShown}
onCloseComplete={() => setIsShown(false)}
>
<Paragraph margin={40}>Basic Example</Paragraph>
</SideSheet>
<Button onClick={() => setIsShown(true)}>Show Basic Side Sheet</Button>
</React.Fragment>
)
}
Full featured example with a header with a title, subtitle and a tab bar. Content is a simple card.
function FullyFeaturedSidesheetExample() {
const [isShown, setIsShown] = React.useState(false)
const [selectedIndex, setSelectedIndex] = React.useState(0)
return (
<React.Fragment>
<SideSheet
isShown={isShown}
onCloseComplete={() => setIsShown(false)}
containerProps={{
display: 'flex',
flex: '1',
flexDirection: 'column'
}}
>
<Pane zIndex={1} flexShrink={0} elevation={0} backgroundColor="white">
<Pane padding={16} borderBottom="muted">
<Heading size={600}>Title</Heading>
<Paragraph size={400} color="muted">
Optional description or sub title
</Paragraph>
</Pane>
<Pane display="flex" padding={8}>
<Tablist>
{['Traits', 'Event History', 'Identities'].map((tab, index) => (
<Tab
key={tab}
isSelected={selectedIndex === index}
onSelect={() => setSelectedIndex(index)}
>
{tab}
</Tab>
))}
</Tablist>
</Pane>
</Pane>
<Pane flex="1" overflowY="scroll" background="tint1" padding={16}>
<Card
backgroundColor="white"
elevation={0}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
>
<Heading>Some content</Heading>
</Card>
</Pane>
</SideSheet>
<Button onClick={() => setIsShown(true)}>Show Basic Side Sheet</Button>
</React.Fragment>
)
}
Example with a header with a title. Content is a simple card.
function TitleOnlySideSheet() {
const [isShown, setIsShown] = React.useState(false)
return (
<React.Fragment>
<SideSheet
isShown={isShown}
onCloseComplete={() => setIsShown(false)}
containerProps={{
display: 'flex',
flex: '1',
flexDirection: 'column'
}}
>
<Pane zIndex={1} flexShrink={0} elevation={0} backgroundColor="white">
<Pane padding={16}>
<Heading size={600}>Title</Heading>
</Pane>
</Pane>
<Pane flex="1" overflowY="scroll" background="tint1" padding={16}>
<Card
backgroundColor="white"
elevation={0}
height={240}
display="flex"
alignItems="center"
justifyContent="center"
>
<Heading>Some content</Heading>
</Card>
</Pane>
</SideSheet>
<Button onClick={() => setIsShown(true)}>Show Basic Side Sheet</Button>
</React.Fragment>
)
}
Use the preventBodyScrolling prop to disable scrolling outside the side sheet.
function PreventBodyScrollingSidesheetExample() {
const [isShown, setIsShown] = React.useState(false)
return (
<React.Fragment>
<SideSheet
isShown={isShown}
onCloseComplete={() => setIsShown(false)}
preventBodyScrolling
>
<Paragraph margin={40}>Basic Example</Paragraph>
</SideSheet>
<Button onClick={() => setIsShown(true)}>Show Basic Side Sheet</Button>
</React.Fragment>
)
}