Drawer
adn-ui/drawerFreeComponent
A panel that slides in from the edge of the screen with swipe gestures.
Live preview
live · rendered by the registry
Rendered by adn-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.awaiden.com/r/drawer.jsonSource
1"use client";23import "./drawer.css";4import { Drawer as BaseDrawer } from "@base-ui/react/drawer";5import React from "react";6import { cn } from "tailwind-variants";78import { DrawerContext, useDrawerContext } from "./drawer.context";9import { drawerVariants, type DrawerVariants } from "./drawer.variants";1011export type DrawerProviderProps = React.ComponentProps<typeof BaseDrawer.Provider>;1213export const DrawerProvider = (props: DrawerProviderProps) => {14 return <BaseDrawer.Provider {...props} />;15};1617export type DrawerIndentBackgroundProps = React.ComponentProps<typeof BaseDrawer.IndentBackground>;1819export const DrawerIndentBackground = (props: DrawerIndentBackgroundProps) => {20 return <BaseDrawer.IndentBackground {...props} />;21};2223export type DrawerIndentProps = React.ComponentProps<typeof BaseDrawer.Indent>;2425export const DrawerIndent = (props: DrawerIndentProps) => {26 return <BaseDrawer.Indent {...props} />;27};2829const SIDE_TO_SWIPE_DIRECTION: Record<30 NonNullable<DrawerVariants["side"]>,31 React.ComponentProps<typeof BaseDrawer.Root>["swipeDirection"]32> = {33 bottom: "down",34 top: "up",35 left: "left",36 right: "right",37};3839export type DrawerProps = DrawerVariants & React.ComponentProps<typeof BaseDrawer.Root>;4041export const DrawerRoot = ({42 children,43 side = "bottom",44 swipeDirection,45 ...props46}: DrawerProps) => {47 const slots = drawerVariants({ side });48 const resolvedSwipeDirection = swipeDirection ?? (side ? SIDE_TO_SWIPE_DIRECTION[side] : "down");4950 return (51 <DrawerContext.Provider value={{ slots }}>52 <BaseDrawer.Root swipeDirection={resolvedSwipeDirection} {...props}>53 {children}54 </BaseDrawer.Root>55 </DrawerContext.Provider>56 );57};5859export type DrawerTriggerProps = React.ComponentProps<typeof BaseDrawer.Trigger> & {60 render?: React.ReactElement;61 asChild?: boolean;62};6364export const DrawerTrigger = ({65 className,66 children,67 render,68 asChild: _asChild,69 ...props70}: DrawerTriggerProps) => {71 const { slots } = useDrawerContext();72 const renderElement = render ?? (React.isValidElement(children) ? children : undefined);73 return (74 <BaseDrawer.Trigger75 className={cn(slots.trigger(), className)}76 {...props}77 {...(renderElement ? { render: renderElement } : { children })}78 />79 );80};8182export type DrawerSwipeAreaProps = React.ComponentProps<typeof BaseDrawer.SwipeArea>;8384export const DrawerSwipeArea = (props: DrawerSwipeAreaProps) => {85 return <BaseDrawer.SwipeArea {...props} />;86};8788// … truncated
What it pulls in
npm packages
Files it writes
More from adn-ui
All 48 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | adn-ui | Components | Free | 2 deps · 5 files | |
| Alert Dialogalert-dialog | adn-ui | Components | Free | 2 deps · 5 files | |
| Aspect Ratioaspect-ratio | adn-ui | Components | Free | 1 dep · 4 files | |
| Autocompleteautocomplete | adn-ui | Components | Free | 2 deps · 5 files | |
| Avataravatar | adn-ui | Components | Free | 2 deps · 5 files | |
| Badgebadge | adn-ui | Components | Free | 1 dep · 4 files | |
| Breadcrumbbreadcrumb | adn-ui | Components | Free | 1 dep · 5 files | |
| Buttonbutton | adn-ui | Components | Free | 1 dep · 4 files |
