Demos
Default DrawerList, triggered by a ToggleButton
const DrawerListWithState = props => {const [opened, setOpened] = React.useState(false)const Relative = styled.span`position: relative;`return (<Relative><ToggleButtontext="Toggle"checked={opened}icon={'chevron_' + (opened ? 'up' : 'down')}icon_position="left"on_change={({ checked }) => setOpened(checked)}/><DrawerListskip_portaldata={data}opened={opened}on_hide={() => setOpened(false)}{...props}/></Relative>)}render(<DrawerListWithState />)
DrawerList list - only to visualize
Default DrawerList
<DrawerListskip_portalopenedprevent_closetriangle_position="left"data={data}value={3}on_change={({ data: selectedDataItem }) => {console.log('on_change', selectedDataItem)}}on_show={() => {console.log('on_show')}}/>
Custom event and link on single item
const CustomComponent = () => (<CustomComponentInneronTouchStart={preventDefault}onClick={e => {console.log('Do something different')preventDefault(e)}}>Custom event handler</CustomComponentInner>)const CustomComponentInner = styled.span`display: block;width: 100%;margin: -1rem -2rem -1rem -1rem;padding: 1rem 2rem 1rem 1rem;`const preventDefault = e => {e.stopPropagation()e.preventDefault()}const CustomWidth = styled(DrawerList)`.dnb-drawer-list__list {width: var(--drawer-list-width);}`render(<CustomWidthskip_portalopenedprevent_closemore_menurighttitle="Choose an item"data={() => [<Link href="/">Go to this Link</Link>,'Or press on me',<CustomComponent />]}on_change={({ value }) => {console.log('More menu:', value)}}suffix={<HelpButton title="Modal Title">Modal content</HelpButton>}/>)
Using List and Items markup
NB: By using this method you lose currently a lot of the core functionality like keyboard support and other accessibility features.
const list = [{ value: 'A' },{ value: 'B' },{ value: 'C' }]const CustomWidth = styled(DrawerList)`.dnb-drawer-list__list {width: var(--drawer-list-width);}`const DrawerListWithState = props => {const [selected, setSelected] = React.useState('C')return (<CustomWidthskip_portalopenedprevent_close><DrawerList.Options>{list.map(({ value, ...props }, i) => (<DrawerList.Itemkey={i}{...props}selected={value === selected}value={value}on_click={({ value }) => setSelected(value)}{...props}>{value}</DrawerList.Item>))}</DrawerList.Options></CustomWidth>)}render(<DrawerListWithState />)