Sidedrawer
A collection of items to build flexible sidedrawer
Sidedrawer
exports components that combine to build complex side navigation.
The Sidedrawer
root
Sidedrawer exposes few main elements to build foundations.
The core element is a Sidedrawer
which wraps entire components composition.
Sidedrawer
has build-in state, but also allows you to pass props to control if from the outside.
The Sidedrawer root is made in top of the radix dialog
Optional Sidedrawer
props
isOpen
property determines if the wholeSidedrawer
is visible or not.onOpenChange
prop should be a function which updatesisOpen
state. This function is triggered automatically when click onSidedrawer.Overlay
,Sidedrawer.Close
or pressEscape
key.
Fundamental root componenents
Sidedrawer.Trigger
- It's the maintrigger element
responsible for opening the wholeSidedrawer.Content
. This component is build on top of radix dialog triggerSidedrawer.Content
- This is whe wrapper for whole content (Sidedrawer.Header
,Sidedrawer.Body
,Sidedrawer.Footer
and other nested elements). This component is build on top of radix dialog content
<Sidedrawer><Sidedrawer.Trigger asChild><Button>Open the navigation</Button></Sidedrawer.Trigger><Sidedrawer.Content>the sidedrawer content</Sidedrawer.Content></Sidedrawer>
The Sidedrawer.Content
children building blocks
Sidedrawer.Header
- It's based onTopBar
component, so it plays really well with allTopBar
subcomponents. This component is flexible, so you can render anything you need inside of it (for example app logo, Sidedrawer.Close etc.)Sidedrawer.Close
- It's an"close" ActionIcon
which triggersSidedrawer.Content
closing.Sidedrawer.Body
- This is the wrapper for allSidedrawer.Item
items. The content is scrollable.Sidedrawer.Footer
- Optional part of theSidedrawer
. It's fixed to the botton. You can pass whatever you need as it's children.
<Sidedrawer><Sidedrawer.Trigger asChild><Button>Open the navigation</Button></Sidedrawer.Trigger><Sidedrawer.Content><Sidedrawer.Header><Sidedrawer.Close /></Sidedrawer.Header><Sidedrawer.Body>Sidedrawer items and Accordions here</Sidedrawer.Body><Sidedrawer.Footer>Footer items here</Sidedrawer.Footer></Sidedrawer.Content></Sidedrawer>
Sidedrawer.Body children
You most likely want to use Sidedrawer.Item
or Sidedrawer.Accordion
inside of Sidedrawer.Body
Sidedrawer.Item
Sidedrawer exposes Item
component to build a navigation elements.
Sidedrawer.Item
is renderes as a link
or a button
depends on passed props.
href
prop determine a link renderonClick
prop determines a button render
Link item:
<Sidedrawer.Item href={'/'}><Icon is={Apps} css={{ mr: '$2' }} />Dashboard</Sidedrawer.Item>
Button item:
<Sidedrawer.Item onClick={logout}><Icon is={Exit} css={{ mr: '$2' }} />Log out</Sidedrawer.Item>
Sidedrawer.Accordion
Accordion item:
Accordion item requires few elements to work properly:
value
property is a unique identifier needed to expand accordion content. read moreSidedrawer.AccordionTrigger
- This component is a trigger which expand/collapse Accordion content. You can pass a text or components composition as its children.Sidedrawer.AccordionContent
- This component contains whole accorion content. Most likely you would like to pass few anotherSidedrawer.Item
items inside. Accordion content is collapsed until you click theSidedrawer.AccordionTrigger
to expand it.
<Sidedrawer.Accordion value="your_unique_identifier"><Sidedrawer.AccordionTrigger><Icon is={New} css={{ mr: '$2' }} />Set work</Sidedrawer.AccordionTrigger><Sidedrawer.AccordionContent><Sidedrawer.Item href={'/practice'}><Icon is={Feed} css={{ mr: '$2' }} />Practice</Sidedrawer.Item><Sidedrawer.Item href={'/test'}><Icon is={Inbox} css={{ mr: '$2' }} />Test</Sidedrawer.Item></Sidedrawer.AccordionContent></Sidedrawer.Accordion>
Whole Sidedrawer components composition
<Sidedrawer><Sidedrawer.Trigger asChild><Button>Open the Sidedrawer</Button></Sidedrawer.Trigger><Sidedrawer.Content><Sidedrawer.Header><Sidedrawer.Close /><TopBar.BrandLogosrc={'https://atomlearning.co.uk/_next/static/media/logo.e9276284.svg'}/></Sidedrawer.Header><Sidedrawer.Body><Sidedrawer.Item href={'/'} active>Dashboard</Sidedrawer.Item><Sidedrawer.Accordion value="1" disabled><Sidedrawer.AccordionTrigger>Set work</Sidedrawer.AccordionTrigger><Sidedrawer.AccordionContent><Sidedrawer.Item href={'/'}>Set Practice</Sidedrawer.Item><Sidedrawer.Item href={'/'}>Mock Tests</Sidedrawer.Item></Sidedrawer.AccordionContent></Sidedrawer.Accordion><Sidedrawer.Accordion value="2"><Sidedrawer.AccordionTrigger>Resources</Sidedrawer.AccordionTrigger><Sidedrawer.AccordionContent><Sidedrawer.Item onClick={() => console.log('clicked!')}>I am a button</Sidedrawer.Item><Sidedrawer.Item href="/">I am a link</Sidedrawer.Item></Sidedrawer.AccordionContent></Sidedrawer.Accordion></Sidedrawer.Body><Sidedrawer.Footer>The footer content</Sidedrawer.Footer></Sidedrawer.Content></Sidedrawer>
API Reference
Sidedrawer
Prop | Type | Default | Required |
---|---|---|---|
open | boolean | - | - |
defaultOpen | boolean | - | - |
onOpenChange | (open: boolean) => void | - | - |
modal | boolean | - | - |
Sidedrawer.AccordionContent
Prop | Type | Default | Required |
---|---|---|---|
asChild | boolean | - | - |
forceMount | true | - | - |
css | CSSProperties | - | - |
Sidedrawer.AccordionTrigger
Prop | Type | Default | Required |
---|---|---|---|
asChild | boolean | - | - |
active | boolean | - | - |
css | CSSProperties | - | - |
Sidedrawer.Body
Prop | Type | Default | Required |
---|
Sidedrawer.Close
Prop | Type | Default | Required |
---|---|---|---|
size | "xs" | "sm" | "md" | "lg" | md | - |
appearance | "outline" | "simple" | "solid" | simple | - |
label | string | close | - |
theme | "primary" | "success" | "danger" | "warning" | "neutral" | neutral | - |
isRounded | boolean | - | - |
onClick | (...args: unknown[]) => void | - | - |
css | CSSProperties | - | - |
as | JSX.IntrinsicElements | - | - |
href | string | - | - |
Sidedrawer.Content
Prop | Type | Default | Required |
---|---|---|---|
asChild | boolean | - | - |
onEscapeKeyDown | (event: KeyboardEvent) => void | - | - |
onPointerDownOutside | (event: PointerDownOutsideEvent) => void | - | - |
onFocusOutside | (event: FocusOutsideEvent) => void | - | - |
onInteractOutside | (event: PointerDownOutsideEvent | FocusOutsideEvent) => void | - | - |
onOpenAutoFocus | (event: Event) => void | - | - |
onCloseAutoFocus | (event: Event) => void | - | - |
forceMount | true | - | - |
css | CSSProperties | - | - |
Sidedrawer.Footer
Prop | Type | Default | Required |
---|---|---|---|
as | JSX.IntrinsicElements | - | - |
css | CSSProperties | - | - |
Sidedrawer.Header
Prop | Type | Default | Required |
---|---|---|---|
css | CSSProperties | - | - |
Sidedrawer.Item
Prop | Type | Default | Required |
---|---|---|---|
active | boolean | - | - |
disabled | boolean | - | - |
href | string | - | - |
onClick | () => void | - | - |
Sidedrawer.Trigger
Prop | Type | Default | Required |
---|---|---|---|
asChild | boolean | - | - |
as | JSX.IntrinsicElements | - | - |
css | CSSProperties | - | - |