Giter VIP home page Giter VIP logo

open-sesame's Introduction

Open Sesame

Open Sesame is an unstyled, versatile, customizable, responsive, and accessible drawer component for React. Built with Radix 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.

The idea was sparked from my love of the Radix primitive library mixed with a yearning for them to have a drawer component. Luckily, there's Dialog.

open-sesame.mov

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.

  • origin (required): Choose where the drawer opens from. The value can be
    • top
    • right
    • bottom
    • left
  • size (required): Choose the depth of the drawer. The value can be either a number for the number of pixels or a percentage as a string for the percentage of the view.
  • radius (optional): Choose the border radius of the drawer. The value is the pixel value as a number. If none is provided, the border radius defaults as 0.
  • visible (optional): This is required for the drawer's animation powered by framer-motion. The value is used for the drawer's enter and exit animations. The value must be a boolean. I recommend using React's useState and the Root component's open and onOpenChange prop. See the example above.

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.

open-sesame's People

Contributors

jordan-sussman avatar

Stargazers

 avatar Kilian Smiti avatar  avatar

Watchers

Lucian avatar  avatar

open-sesame's Issues

When I provide the size as a percentage string, drawer is not animated and not closable

I have implemented your radix-ui based drawer into my project. The given example works great

Now, I would like to open the drawer up to 50% of the viewport width, so I set

size={"50%"}

which will open the drawer to the correct size, but the opening is not animated and closing no longer works. Going back to

size={450}

makes things work again.

Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.