jordan-sussman / open-sesame

A customizable drawer component for React
MIT License
6 stars 0 forks source link
dialog drawer framer-motion radix radix-ui react

Open Sesame

Open Sesame is an unstyled, versatile, customizable, responsive, and accessible drawer component for React. Built from Radix's Dialog primitive and animated with framer-motion, it's designed to be a drop-in solution to fulfill all your drawer needs. You can put anything your heart desires into this drawer; the only limit is your imagination.

This came from a clear need from the community for a Radix-based drawer component - https://github.com/radix-ui/primitives/issues/986

https://github.com/jordan-sussman/open-sesame/assets/52428171/01eee7f8-0536-47ee-89d0-e8ba9e5cb0dd

In this example, the drawer is styled, opens from the left, has a size of 450, and a border radius of 20.

Usage

import { Drawer } from 'open-sesame'
import React from 'react'

function MyComponent() {
  const [open, setOpen] = React.useState(false)
  return (
    <Drawer.Root open={open} onOpenChange={setOpen}>
      <Drawer.Trigger>Open</Drawer.Trigger>
        <Drawer.Content
          origin={origin} // ''
          radius={radius} // #
          size={size} // # or '' (px or %)
          visible={open} // bool
        >
          <Drawer.Close />
          <Drawer.Title>Open Sesame</Drawer.Title>
          <Drawer.Description>Lovely stuff.<Drawer.Description>
          <div>Content</div>
        </Drawer.Content>
    </Drawer.Root>
  )
}

Props

Because Open Sesame is built with Radix's Dialog primitive, you get all Radix props out of the box. On top of this, Open Sesame adds a few more to make it a truly powerful drawer component.

Subcomponents

Root - Parent element that contains all elements of the component. Props.

Trigger - The button or element used to open. Props.

Content - The wrapper that renders the content. Props.

Title - An accessible title that's announced when opened. Props.

Description - An accessible description that's announced when opened. Props.

Close - The button or element used to close. Props.

Poke Around

Find the component in src/OpenSesame.
Find the example from the above video in src/Example.

Setup Locally

Install:

npm install

To run example locally with Vite:

npm run dev

Note that the project example was built using Vite. If you want to view the example, and Vite provides prompts, select React then TypeScript.