suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Drawer

A panel that slides in from an edge of the screen and can be dismissed with a swipe.

Drawer is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerDemo() {
  return (
    <Drawer swipeDirection="down" floating={false} showSwipeHandle modal>
      <DrawerTrigger render={<Button variant="outline" />}>

Drawer wraps the Base UI Drawer. The Drawer root manages the open state and the swipe direction, and DrawerTrigger opens it. DrawerContent renders the panel in a portal, over a dimmed DrawerOverlay when modal, with an optional swipe handle and close button. Inside it, DrawerHeader holds the DrawerTitle and DrawerDescription, and DrawerFooter holds the actions. DrawerClose closes the drawer from any element.

The drawer opens from the bottom by default and can also open from the top, left or right. It supports snap points, a floating style inset from the screen edges, a non-modal mode and a page behind it that scales down. Use a drawer for touch-friendly, swipeable panels; for a centered window, use a dialog.

Installation

$ pnpm dlx shadcn@latest add @esuiss/drawer

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add drawer
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react @phosphor-icons/react
  1. Add the pieces it builds on: Button, use-scrollbar-gap.

  2. Copy and paste the following code into your project.

components/ui/drawer.tsx
"use client"

import { Drawer as DrawerPrimitive } from "@base-ui/react/drawer"
import { XIcon } from "@phosphor-icons/react"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { useScrollbarGap } from "@/hooks/use-scrollbar-gap"
import { cn } from "@/lib/utils"

type DrawerContextProps = {
  floating: boolean
  hasSnapPoints: boolean
  modal: DrawerPrimitive.Root.Props["modal"]
  showSwipeHandle: boolean
  swipeDirection: NonNullable<DrawerPrimitive.Root.Props["swipeDirection"]>
}
  1. Update the import paths to match your project setup.

Usage

import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerIndent,
  DrawerIndentBackground,
  DrawerOverlay,
  DrawerPortal,
  DrawerProvider,
  DrawerSwipeHandle,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Button } from "@/components/ui/button"
<Drawer swipeDirection="down" showSwipeHandle modal>
  <DrawerTrigger render={<Button variant="outline" />}>
    Open drawer
  </DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>Move goal</DrawerTitle>
      <DrawerDescription>Set your daily activity goal.</DrawerDescription>
    </DrawerHeader>
    <div className="flex flex-col items-center gap-1 p-4">
      <span className="text-5xl font-semibold tracking-tight">350</span>
      <span className="text-muted-foreground text-xs uppercase">
        Calories per day
      </span>
    </div>
    <DrawerFooter>
      <Button>Save goal</Button>
      <DrawerClose render={<Button variant="outline" />}>
        Cancel
      </DrawerClose>
    </DrawerFooter>
  </DrawerContent>
</Drawer>
<Drawer swipeDirection="down" showSwipeHandle modal>
  <DrawerTrigger asChild>
    <Button variant="outline">Open drawer</Button>
  </DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>Move goal</DrawerTitle>
      <DrawerDescription>Set your daily activity goal.</DrawerDescription>
    </DrawerHeader>
    <div className="flex flex-col items-center gap-1 p-4">
      <span className="text-5xl font-semibold tracking-tight">350</span>
      <span className="text-muted-foreground text-xs uppercase">
        Calories per day
      </span>
    </div>
    <DrawerFooter>
      <Button>Save goal</Button>
      <DrawerClose asChild>
        <Button variant="outline">Cancel</Button>
      </DrawerClose>
    </DrawerFooter>
  </DrawerContent>
</Drawer>

Composition

Use the following composition to build a Drawer:

Drawer
├── DrawerTrigger
└── DrawerContent
    ├── DrawerHeader
    │   ├── DrawerTitle
    │   └── DrawerDescription
    └── DrawerFooter
        └── DrawerClose

Examples

Directions

Set swipeDirection to down, up, left or right to choose the edge the drawer opens from and the direction it is swiped to close.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerDirections() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Drawer floating={false} showSwipeHandle modal swipeDirection="down">

With close button

Set showCloseButton on DrawerContent to add an icon close button in the top corner.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerWithCloseButton() {
  return (
    <Drawer swipeDirection="down" floating={false} showSwipeHandle modal>
      <DrawerTrigger render={<Button variant="outline" />}>
        Open drawer

With close label

Set closeLabel on DrawerContent to replace the close button's icon with text.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerWithCloseLabel() {
  return (
    <Drawer swipeDirection="down" floating={false} showSwipeHandle modal>
      <DrawerTrigger render={<Button variant="outline" />}>
        Open drawer

Floating

Set floating to inset the drawer from the screen edges and round all of its corners.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerFloating() {
  return (
    <Drawer swipeDirection="down" floating showSwipeHandle modal>
      <DrawerTrigger render={<Button variant="outline" />}>

With snap points

Pass snapPoints, such as [0.5, 1], to let people drag the drawer between heights. This one opens at half height and expands when dragged up.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerWithSnapPoints() {
  return (
    <Drawer
      swipeDirection="down"

Non modal

Set modal={false} to keep the rest of the page interactive. No overlay is rendered in that case.

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function DrawerNonModal() {
  return (
    <Drawer
      swipeDirection="down"

Sheet with detents

An event sheet with snap points that scales the page behind it. Place DrawerIndentBackground and DrawerIndent inside DrawerProvider and put the page content in DrawerIndent.

import { PlusIcon } from "@phosphor-icons/react"
import * as React from "react"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerIndent,
  DrawerIndentBackground,
  DrawerProvider,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Input } from "@/components/ui/input"
import { Switch } from "@/components/ui/switch"

Accessibility

  • The panel has the dialog role. DrawerTitle provides its accessible name and DrawerDescription its accessible description.
  • Opening the drawer moves focus inside it. Escape closes it and returns focus to the trigger.
  • A non-modal drawer does not set aria-modal.
  • The swipe handle is hidden from assistive technology, so always provide another way to close the drawer, such as a DrawerClose button.
  • The icon-only close button has a visually hidden Close label.

API Reference

DrawerProvider

Coordinates drawers with DrawerIndent so the page can react when a drawer opens.

Also accepts the props of DrawerPrimitive.Provider.Props.

Place DrawerIndentBackground and DrawerIndent inside it and put the page content in DrawerIndent.

DrawerIndentBackground

The dark layer shown behind the page when it scales down.

Also accepts the props of DrawerPrimitive.IndentBackground.Props.

DrawerIndent

Wraps the page content and scales it down while a bottom drawer is open.

Also accepts the props of DrawerPrimitive.Indent.Props.

The page is scaled while a non-floating drawer that opens from the bottom is open, and, with snap points, only at the last snap point. It gets data-raised while the page is scaled. Animations are disabled when reduced motion is preferred.

Drawer

The root that manages the open state, swipe direction and snap points.

PropTypeDefault
floatingbooleanfalse
showSwipeHandlebooleanfalse

Also accepts the props of DrawerPrimitive.Root.Props.

The drawer is uncontrolled by default; set defaultOpen to start open, or control it with open and onOpenChange. With snapPoints it opens at the first snap point unless you set defaultSnapPoint, or control it with snapPoint and onSnapPointChange. showSwipeHandle shows a grab bar on the edge of the panel that faces the screen center. Nested drawers stack, with the drawer behind scaled down slightly.

DrawerTrigger

The button that opens the drawer.

PropTypeDefault
asChildbooleanfalse

Also accepts the props of DrawerPrimitive.Trigger.Props.

Render the trigger as another component, such as a Button, with the render prop.

Set asChild to render your own Button as the trigger instead of a button.

DrawerPortal

Renders its children into a portal outside the current DOM hierarchy.

Also accepts the props of DrawerPrimitive.Portal.Props.

DrawerClose

A button that closes the drawer.

PropTypeDefault
asChildbooleanfalse

Also accepts the props of DrawerPrimitive.Close.Props.

Render the close button as another component, such as a Button, with the render prop.

Set asChild to render your own Button as the close button instead of a button.

DrawerOverlay

The dimmed layer behind a modal drawer, which fades as the drawer is swiped away.

Also accepts the props of DrawerPrimitive.Backdrop.Props.

DrawerSwipeHandle

The grab bar people drag to move or dismiss the drawer.

Also accepts the props of React.ComponentProps<"div">.

DrawerContent

The drawer panel, rendered in a portal with an optional overlay, swipe handle and close button.

PropTypeDefault
showCloseButtonbooleanfalse
closeLabelstring-

Also accepts the props of DrawerPrimitive.Popup.Props.

The panel sets data-swipe-direction, data-swipe-axis, and, when applicable, data-floating and data-snap-points. A drawer at its last snap point gets data-expanded. Side drawers are 75% wide, and 24rem wide from the sm breakpoint. Top and bottom drawers are limited to the viewport height minus 6rem.

DrawerHeader

Groups the title and description.

Also accepts the props of React.ComponentProps<"div">.

DrawerFooter

Holds the drawer's actions at the bottom of the panel.

Also accepts the props of React.ComponentProps<"div">.

DrawerTitle

The drawer's title, which also names it for assistive technology.

PropTypeDefault
asChildbooleanfalse

Also accepts the props of DrawerPrimitive.Title.Props.

DrawerDescription

Supporting text that describes the drawer for assistive technology.

PropTypeDefault
asChildbooleanfalse

Also accepts the props of DrawerPrimitive.Description.Props.

Each part sets a data-slot, such as drawer-content or drawer-swipe-handle, for styling.

Web

Web preview

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"

export default function DrawerOpenByDefault() {
  return (

This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.

import SwiftUI

struct DrawerOpenByDefaultExample: View {
  var body: some View {
    DrawerGoal(open: true)
  }
}

struct DrawerGoal: View {
  @State private var open: Bool

  init(open: Bool = false) {
    _open = State(initialValue: open)
  }

  var body: some View {
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp

Drawer presents content in a panel attached to an edge of the screen. It slides in from the bottom by default, or from the top, left or right with swipeDirection, and the user can drag it closed in that direction. The content renders through a portal (inside a full-window overlay on iOS) and respects the safe-area insets.

Installation

$ pnpm dlx shadcn@latest add @esuiss/drawer

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add drawer
$ pnpm dlx shadcn@latest add @esuiss/drawer

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add drawer --platform swift
$ pnpm dlx shadcn@latest add @esuiss/drawer

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add drawer --platform kotlin

The CLI also adds what it builds on: Button, Icon, Text. It also adds the animated view components/ui/animated-view.tsx.

  1. Install the following dependencies:
npx expo install cn phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, Text.

  2. Copy the animated view into components/ui/animated-view.tsx:

uniwind/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
uniwind/components/primitives/dialog.tsx
import * as React from "react"
import {
  type GestureResponderEvent,
  type HostInstance,
  Pressable,
  StyleSheet,
  Text,
  View,
  type ViewStyle,
} from "react-native"
import { REASONS } from "./event-details"
import {
  FloatingHandle,
  FloatingPortal,
  type FloatingRootActions,
  type FloatingRootValue,
uniwind/components/primitives/drawer.tsx
import * as React from "react"
import {
  type LayoutChangeEvent,
  Pressable,
  useWindowDimensions,
  View,
  type ViewStyle,
} from "react-native"
import {
  Gesture,
  GestureDetector,
  GestureHandlerRootView,
} from "react-native-gesture-handler"
import Animated, {
  ReduceMotion,
  type SharedValue,
uniwind/components/primitives/event-details.ts
import type { HostInstance } from "react-native"
import type {
  BaseUIChangeEventDetails,
  BaseUIGenericEventDetails,
  ChangeEvent,
} from "./types"

const REASONS = {
  none: "none",
  triggerPress: "trigger-press",
  triggerLongPress: "trigger-long-press",
  outsidePress: "outside-press",
  itemPress: "item-press",
  closePress: "close-press",
  backPress: "back-press",
  accessibilityEscape: "accessibility-escape",
uniwind/components/primitives/floating-root.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  type GestureResponderEvent,
  type HostInstance,
  type Role,
  useWindowDimensions,
} from "react-native"
import { createChangeEventDetails, REASONS } from "./event-details"
import { useBackHandler, useComposedRefs, useEffectEvent } from "./hooks"
import { Portal } from "./portal"
import type {
  AnchorRect,
  BaseUIChangeEventDetails,
  ChangeEvent,
  MeasurableAnchor,
uniwind/components/primitives/haptics.tsx
import * as React from "react"

type HapticsImpactStyle = "light" | "medium" | "heavy" | "soft" | "rigid"

type HapticsNotificationType = "success" | "warning" | "error"

interface HapticsAdapter {
  impact(style: HapticsImpactStyle): void
  selection(): void
  notification(type: HapticsNotificationType): void
}

interface HapticsContextValue {
  adapter: HapticsAdapter | null
  enabled: boolean
}
uniwind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
uniwind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
uniwind/components/primitives/portal.tsx
import * as React from "react"
import { HapticsContext } from "./haptics"

const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"

type PortalEntries = ReadonlyMap<string, React.ReactNode>

const EMPTY_ENTRIES: PortalEntries = new Map()

let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()

function emit() {
  for (const listener of listeners) listener()
}
uniwind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
uniwind/components/primitives/use-controllable-state.ts
import * as React from "react"
import { useEffectEvent } from "./hooks"
import type { BaseUIChangeEventDetails } from "./types"

interface CancelableDetails {
  readonly isCanceled: boolean
}

interface UseControllableStateParameters<
  T,
  Details extends CancelableDetails = BaseUIChangeEventDetails,
> {
  value?: T | undefined
  defaultValue: T
  onChange?: ((value: T, details: Details) => void) | undefined
}
uniwind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/drawer.tsx:
uniwind/components/ui/drawer.tsx
import { cn } from "cn"
import { XIcon } from "phosphor-react-native"
import * as React from "react"
import {
  Platform,
  useWindowDimensions,
  View,
  type ViewProps,
  type ViewStyle,
} from "react-native"
import {
  FadeIn,
  FadeOut,
  ReduceMotion,
  SlideInDown,
  SlideInLeft,
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install cn phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, Text.

  2. Copy the animated view into components/ui/animated-view.tsx:

nativewind/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
nativewind/components/primitives/dialog.tsx
import * as React from "react"
import {
  type GestureResponderEvent,
  type HostInstance,
  Pressable,
  StyleSheet,
  Text,
  View,
  type ViewStyle,
} from "react-native"
import { REASONS } from "./event-details"
import {
  FloatingHandle,
  FloatingPortal,
  type FloatingRootActions,
  type FloatingRootValue,
nativewind/components/primitives/drawer.tsx
import * as React from "react"
import {
  type LayoutChangeEvent,
  Pressable,
  useWindowDimensions,
  View,
  type ViewStyle,
} from "react-native"
import {
  Gesture,
  GestureDetector,
  GestureHandlerRootView,
} from "react-native-gesture-handler"
import Animated, {
  ReduceMotion,
  type SharedValue,
nativewind/components/primitives/event-details.ts
import type { HostInstance } from "react-native"
import type {
  BaseUIChangeEventDetails,
  BaseUIGenericEventDetails,
  ChangeEvent,
} from "./types"

const REASONS = {
  none: "none",
  triggerPress: "trigger-press",
  triggerLongPress: "trigger-long-press",
  outsidePress: "outside-press",
  itemPress: "item-press",
  closePress: "close-press",
  backPress: "back-press",
  accessibilityEscape: "accessibility-escape",
nativewind/components/primitives/floating-root.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  type GestureResponderEvent,
  type HostInstance,
  type Role,
  useWindowDimensions,
} from "react-native"
import { createChangeEventDetails, REASONS } from "./event-details"
import { useBackHandler, useComposedRefs, useEffectEvent } from "./hooks"
import { Portal } from "./portal"
import type {
  AnchorRect,
  BaseUIChangeEventDetails,
  ChangeEvent,
  MeasurableAnchor,
nativewind/components/primitives/haptics.tsx
import * as React from "react"

type HapticsImpactStyle = "light" | "medium" | "heavy" | "soft" | "rigid"

type HapticsNotificationType = "success" | "warning" | "error"

interface HapticsAdapter {
  impact(style: HapticsImpactStyle): void
  selection(): void
  notification(type: HapticsNotificationType): void
}

interface HapticsContextValue {
  adapter: HapticsAdapter | null
  enabled: boolean
}
nativewind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
nativewind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
nativewind/components/primitives/portal.tsx
import * as React from "react"
import { HapticsContext } from "./haptics"

const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"

type PortalEntries = ReadonlyMap<string, React.ReactNode>

const EMPTY_ENTRIES: PortalEntries = new Map()

let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()

function emit() {
  for (const listener of listeners) listener()
}
nativewind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
nativewind/components/primitives/use-controllable-state.ts
import * as React from "react"
import { useEffectEvent } from "./hooks"
import type { BaseUIChangeEventDetails } from "./types"

interface CancelableDetails {
  readonly isCanceled: boolean
}

interface UseControllableStateParameters<
  T,
  Details extends CancelableDetails = BaseUIChangeEventDetails,
> {
  value?: T | undefined
  defaultValue: T
  onChange?: ((value: T, details: Details) => void) | undefined
}
nativewind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/drawer.tsx:
nativewind/components/ui/drawer.tsx
import { cn } from "cn"
import { XIcon } from "phosphor-react-native"
import * as React from "react"
import {
  Platform,
  useWindowDimensions,
  View,
  type ViewProps,
  type ViewStyle,
} from "react-native"
import {
  FadeIn,
  FadeOut,
  ReduceMotion,
  SlideInDown,
  SlideInLeft,
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, Text.

  2. Copy the animated view into components/ui/animated-view.tsx:

stylesheet/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
stylesheet/components/primitives/dialog.tsx
import * as React from "react"
import {
  type GestureResponderEvent,
  type HostInstance,
  Pressable,
  StyleSheet,
  Text,
  View,
  type ViewStyle,
} from "react-native"
import { REASONS } from "./event-details"
import {
  FloatingHandle,
  FloatingPortal,
  type FloatingRootActions,
  type FloatingRootValue,
stylesheet/components/primitives/drawer.tsx
import * as React from "react"
import {
  type LayoutChangeEvent,
  Pressable,
  useWindowDimensions,
  View,
  type ViewStyle,
} from "react-native"
import {
  Gesture,
  GestureDetector,
  GestureHandlerRootView,
} from "react-native-gesture-handler"
import Animated, {
  ReduceMotion,
  type SharedValue,
stylesheet/components/primitives/event-details.ts
import type { HostInstance } from "react-native"
import type {
  BaseUIChangeEventDetails,
  BaseUIGenericEventDetails,
  ChangeEvent,
} from "./types"

const REASONS = {
  none: "none",
  triggerPress: "trigger-press",
  triggerLongPress: "trigger-long-press",
  outsidePress: "outside-press",
  itemPress: "item-press",
  closePress: "close-press",
  backPress: "back-press",
  accessibilityEscape: "accessibility-escape",
stylesheet/components/primitives/floating-root.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  type GestureResponderEvent,
  type HostInstance,
  type Role,
  useWindowDimensions,
} from "react-native"
import { createChangeEventDetails, REASONS } from "./event-details"
import { useBackHandler, useComposedRefs, useEffectEvent } from "./hooks"
import { Portal } from "./portal"
import type {
  AnchorRect,
  BaseUIChangeEventDetails,
  ChangeEvent,
  MeasurableAnchor,
stylesheet/components/primitives/haptics.tsx
import * as React from "react"

type HapticsImpactStyle = "light" | "medium" | "heavy" | "soft" | "rigid"

type HapticsNotificationType = "success" | "warning" | "error"

interface HapticsAdapter {
  impact(style: HapticsImpactStyle): void
  selection(): void
  notification(type: HapticsNotificationType): void
}

interface HapticsContextValue {
  adapter: HapticsAdapter | null
  enabled: boolean
}
stylesheet/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
stylesheet/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
stylesheet/components/primitives/portal.tsx
import * as React from "react"
import { HapticsContext } from "./haptics"

const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"

type PortalEntries = ReadonlyMap<string, React.ReactNode>

const EMPTY_ENTRIES: PortalEntries = new Map()

let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()

function emit() {
  for (const listener of listeners) listener()
}
stylesheet/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
stylesheet/components/primitives/use-controllable-state.ts
import * as React from "react"
import { useEffectEvent } from "./hooks"
import type { BaseUIChangeEventDetails } from "./types"

interface CancelableDetails {
  readonly isCanceled: boolean
}

interface UseControllableStateParameters<
  T,
  Details extends CancelableDetails = BaseUIChangeEventDetails,
> {
  value?: T | undefined
  defaultValue: T
  onChange?: ((value: T, details: Details) => void) | undefined
}
stylesheet/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/drawer.tsx:
stylesheet/components/ui/drawer.tsx
import { XIcon } from "phosphor-react-native"
import * as React from "react"
import {
  Platform,
  StyleSheet,
  useWindowDimensions,
  View,
  type ViewProps,
  type ViewStyle,
} from "react-native"
import {
  FadeIn,
  FadeOut,
  ReduceMotion,
  SlideInDown,
  SlideInLeft,
  1. Update the import paths to match your project setup.
  1. Target iOS 17 or later.

  2. Add the Swift package to your app:

Package.swift
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
  1. Copy the theme files every view uses:
swift/Theme/Theme.swift
import CoreText
import SwiftUI
import UIKit

struct RGBA: Sendable {
  let red: CGFloat
  let green: CGFloat
  let blue: CGFloat
  let alpha: CGFloat

  init(_ hex: UInt32, _ alpha: CGFloat = 1) {
    red = CGFloat((hex >> 16) & 0xFF) / 255
    green = CGFloat((hex >> 8) & 0xFF) / 255
    blue = CGFloat(hex & 0xFF) / 255
    self.alpha = alpha
  }
swift/Theme/Tokens.swift
import SwiftUI

public enum EsuissColor {
  public static let background = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
  public static let foreground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let card = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let cardForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let popover = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let popoverForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let primary = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0A84FF))
  public static let primaryForeground = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF))
  public static let secondary = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
  public static let secondaryForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let muted = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
  public static let mutedForeground = Color.adaptive(light: .init(0x6E6E73), dark: .init(0x86868B))
  public static let accent = Color.adaptive(light: .init(0x000000, 0.06), dark: .init(0xFFFFFF, 0.1))
  1. Copy the source and every file it uses:
swift/Components/Drawer.swift
import SwiftUI

extension View {
  public func drawer<Content: View>(
    isPresented: Binding<Bool>,
    detents: Set<PresentationDetent>? = nil,
    selection: Binding<PresentationDetent>? = nil,
    onDismiss: (() -> Void)? = nil,
    @ViewBuilder content: @escaping () -> Content
  ) -> some View {
    let binding = isPresented
    return sheet(isPresented: isPresented, onDismiss: onDismiss) {
      DrawerHost(detents: detents, selection: selection, content: content)
        .environment(\.overlayDismiss, OverlayDismiss { binding.wrappedValue = false })
    }
  }
swift/Components/Button.swift
import SwiftUI

public struct VariantButtonStyle: ButtonStyle {
  public enum Variant: CaseIterable, Sendable {
    case `default`, outline, secondary, tinted, ghost, plain, destructive, link
  }

  public enum Size: CaseIterable, Sendable {
    case `default`, xs, sm, lg, xl, form, icon, iconXs, iconSm, iconLg, iconXl

    var height: CGFloat {
      switch self {
      case .xs, .iconXs: Metrics.Height.buttonXs
      case .sm, .iconSm: Metrics.Height.buttonSm
      case .default, .icon: Metrics.Height.button
      case .lg, .iconLg: Metrics.Height.buttonLg
swift/Components/ButtonGroup.swift
import SwiftUI

extension EnvironmentValues {
  @Entry var buttonGroup: Axis? = nil
  @Entry var buttonGroupSize: CGSize = .zero
}

enum ButtonGroupSpace: Hashable {
  case group
}

struct ButtonGroupFrame {
  let bounds: Anchor<CGRect>
  let outlined: Bool
}
swift/Components/Dialog.swift
import SwiftUI

extension View {
  public func dialog<Content: View>(
    isPresented: Binding<Bool>,
    @ViewBuilder content: @escaping () -> Content
  ) -> some View {
    modifier(
      CoverPresenter(isPresented: isPresented) { visible in
        CenteredStage(visible: visible, dismissible: true, content: content)
      }
    )
  }
}

struct CenteredStage<Content: View>: View {
swift/Components/Overlay.swift
import Observation
import PhosphorSwift
import SwiftUI

public enum PopupAlignment: Sendable, CaseIterable {
  case start, center, end
}

struct OverlayDismiss: Sendable {
  let action: @MainActor @Sendable () -> Void

  @MainActor func callAsFunction() {
    action()
  }
}
  1. Add the files to your app target.
  1. Apply the Compose compiler plugin, enable Compose, set compileSdk to 37 or higher and minSdk to 24 or higher, and add the dependencies:
build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
    implementation("com.adamglin:phosphor-icon-android:1.0.0")
}
  1. Copy the theme files every view uses:
kotlin/theme/Theme.kt
package com.esuiss.ui.theme

import android.content.res.AssetManager
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.shadow.Shadow as DropShadow
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
kotlin/theme/Tokens.kt
package com.esuiss.ui.theme

import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Immutable
data class Colors(
    val background: Color,
    val foreground: Color,
    val card: Color,
    val cardForeground: Color,
    val popover: Color,
    val popoverForeground: Color,
    val primary: Color,
  1. Copy the source and every file it uses:
kotlin/components/Drawer.kt
package com.esuiss.ui.components

import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.AnchoredDraggableDefaults
import androidx.compose.foundation.gestures.AnchoredDraggableState
import androidx.compose.foundation.gestures.DraggableAnchors
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.anchoredDraggable
import androidx.compose.foundation.gestures.animateTo
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
kotlin/components/Button.kt
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
kotlin/components/ButtonGroup.kt
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Immutable
kotlin/components/Content.kt
package com.esuiss.ui.components

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

val LocalContentStyle = compositionLocalOf { TextStyle.Default }

val LocalContentColor = compositionLocalOf { Color.Unspecified }

val LocalIconSize = compositionLocalOf { 20.dp }
kotlin/components/Icon.kt
package com.esuiss.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import com.esuiss.ui.theme.EsuissTheme

@Composable
fun Icon(
    imageVector: ImageVector,
kotlin/components/Overlay.kt
package com.esuiss.ui.components

import android.os.Build
import android.view.Window
import android.view.WindowManager
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideIn
  1. Update the com.esuiss.ui package names to match your project.

Usage

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger } from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"

function GoalContent() {
  return (
    <DrawerContent>
      <DrawerHeader>
        <DrawerTitle>Move goal</DrawerTitle>
        <DrawerDescription>Set your daily activity goal.</DrawerDescription>
      </DrawerHeader>
      <View className="items-center gap-1 p-4">
        <Text className="text-5xl font-semibold tracking-tight">350</Text>
        <Text className="text-xs text-muted-foreground uppercase">
          Calories/day
        </Text>
      </View>
      <DrawerFooter>
        <Button>
          <Text>Submit</Text>
        </Button>
        <DrawerClose render={<Button variant="secondary" />}>
          <Text>Cancel</Text>
        </DrawerClose>
      </DrawerFooter>
    </DrawerContent>
  )
}

export function DrawerExample() {
  return (
    <View className="items-start">
      <Drawer showSwipeHandle>
        <DrawerTrigger render={<Button variant="outline" />}>
          <Text>Open drawer</Text>
        </DrawerTrigger>
        <GoalContent />
      </Drawer>
    </View>
  )
}

This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.

import SwiftUI

struct DrawerGoal: View {
  @State private var open: Bool

  init(open: Bool = false) {
    _open = State(initialValue: open)
  }

  var body: some View {
    Button("Open drawer") { open = true }
      .buttonStyle(.variant(.outline))
      .drawer(isPresented: $open) {
        DrawerGoalContent()
      }
  }
}

struct DrawerGoalContent: View {
  var body: some View {
    DrawerContent {
      DrawerHeader {
        DrawerTitle("Move goal")
        DrawerDescription("Set your daily activity goal.")
      }
      VStack(spacing: 4) {
        Text(verbatim: "350")
          .font(.system(size: 48, weight: .semibold))
          .tracking(-1.2)
          .foregroundStyle(EsuissColor.foreground)
        Text("Calories/day")
          .textCase(.uppercase)
          .textStyle(.xs)
          .foregroundStyle(EsuissColor.mutedForeground)
      }
      .frame(maxWidth: .infinity)
      .padding(16)
      DrawerFooter {
        Button {} label: {
          Text("Submit").frame(maxWidth: .infinity)
        }
        .buttonStyle(.variant())
        DrawerClose {
          Text("Cancel").frame(maxWidth: .infinity)
        }
        .buttonStyle(.variant(.secondary))
      }
    }
  }
}
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
import com.esuiss.ui.components.Button
import com.esuiss.ui.components.ButtonVariant
import com.esuiss.ui.components.Drawer
import com.esuiss.ui.components.DrawerDescription
import com.esuiss.ui.components.DrawerFooter
import com.esuiss.ui.components.DrawerHeader
import com.esuiss.ui.components.DrawerTitle
import com.esuiss.ui.components.Text
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography

@Composable
fun DrawerExample() {
    DrawerGoal(defaultOpen = false, floating = false)
}

@Composable
fun ColumnScope.DrawerGoalContent(onClose: () -> Unit) {
    DrawerHeader {
        DrawerTitle("Move goal")
        DrawerDescription("Set your daily activity goal.")
    }
    Column(
        modifier = Modifier.fillMaxWidth().padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.spacedBy(4.dp),
    ) {
        Text(
            "350",
            style = Typography.xl3.copy(fontSize = 48.sp, lineHeight = 48.sp, letterSpacing = (-0.025).em, fontWeight = FontWeight.SemiBold),
        )
        Text("CALORIES/DAY", style = Typography.xs.copy(color = EsuissTheme.colors.mutedForeground))
    }
    DrawerFooter {
        Button("Submit", onClick = {}, modifier = Modifier.fillMaxWidth())
        Button("Cancel", onClick = onClose, modifier = Modifier.fillMaxWidth(), variant = ButtonVariant.Secondary)
    }
}

@Composable
fun DrawerGoal(defaultOpen: Boolean, floating: Boolean, label: String = "Open drawer") {
    var open by rememberSaveable { mutableStateOf(defaultOpen) }
    Column {
        Button(label, onClick = { open = true }, variant = ButtonVariant.Outline)
        Drawer(open = open, onOpenChange = { open = it }, floating = floating, showSwipeHandle = true) {
            DrawerGoalContent(onClose = { open = false })
        }
    }
}

Examples

Default

Web

Web preview

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"

export default function DrawerDemo() {
  return (

This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.

import SwiftUI

struct DrawerGoal: View {
  @State private var open: Bool

  init(open: Bool = false) {
    _open = State(initialValue: open)
  }

  var body: some View {
    Button("Open drawer") { open = true }
      .buttonStyle(.variant(.outline))
      .drawer(isPresented: $open) {
        DrawerGoalContent()
      }
  }
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp

Snap points

A drawer that rests at 40% and full height.

snapPoints accepts fractions of the screen such as [0.4, 1]; control the current one with snapPoint and onSnapPointChange.

Web

Web preview

import { ScrollView, View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"

const ITEMS = Array.from({ length: 20 }, (_, index) => `Item ${index + 1}`)

export default function DrawerSnapPoints() {
  return (
import { ScrollView, View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"
import { radius, useTheme } from "@/components/ui/theme"

const ITEMS = Array.from({ length: 20 }, (_, index) => `Item ${index + 1}`)

export default function DrawerSnapPoints() {
import SwiftUI

struct DrawerSnapPoints: View {
  @State private var open = false

  var body: some View {
    Button("Open with snap points") { open = true }
      .buttonStyle(.variant(.outline))
      .drawer(isPresented: $open, detents: [.fraction(0.4), .large]) {
        DrawerContent(showCloseButton: true) {
          DrawerHeader {
            DrawerTitle("Snap points")
            DrawerDescription("Drag up to expand, drag down to collapse or dismiss.")
          }
          ScrollView {
            VStack(spacing: 12) {
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment

Floating

Set floating to inset the panel from the screen edges with all corners rounded.

Web

Web preview

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"

export default function DrawerFloating() {
  return (

This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp

Sides

Set swipeDirection to open drawers from the top, bottom, left and right.

Web

Web preview

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"

export default function DrawerSides() {
  return (
    <View className="items-start gap-3">
      <Drawer swipeDirection="up" showSwipeHandle>
import { View } from "react-native"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerContent,
  DrawerDescription,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Text } from "@/components/ui/text"
import { fontSize, useTheme } from "@/components/ui/theme"

export default function DrawerSides() {
  const { colors } = useTheme()
  return (

The React Native tab shows 2 more examples.

The React Native tab shows 1 more example.

Accessibility

  • The popup has the dialog role and is labelled by the title.
  • The swipe handle and decorative edge fill are hidden from screen readers.
  • The icon close button is labelled "Close".

API Reference

DrawerProvider

Tracks open drawers for the indent effect.

Also accepts the props of DrawerPrimitive.ProviderProps.

Wrap your app in it and render DrawerIndentBackground behind a DrawerIndent that holds the screen, to scale the page back behind an open bottom drawer.

DrawerIndentBackground

Background shown behind the scaled screen.

Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.IndentBackground>.

DrawerIndent

Screen wrapper that scales back while a bottom drawer is open.

Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Indent>.

Drawer

Root that holds the open state, direction and snap points.

PropTypeDefault
floatingbooleanfalse
showSwipeHandlebooleanfalse

Also accepts the props of DrawerPrimitive.RootProps.

showSwipeHandle shows a grab handle. With modal={false} there is no scrim. A docked drawer extends its background past the screen edge so drag overshoot shows no gap, and animations respect the system Reduce Motion setting.

DrawerOverlay

Dimmed scrim behind a modal drawer.

Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Backdrop>.

DrawerSwipeHandle

Grab handle on the dragging edge.

Also accepts the props of ViewProps.

DrawerContent

Sliding panel with optional handle and close button.

PropTypeDefault
portalHoststring-
showCloseButtonbooleanfalse
closeLabelstring-

Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Popup>.

Set showCloseButton for a corner close button, and closeLabel to show text instead of the icon. portalHost names the portal host to render into. Padding follows the safe-area insets. Use DrawerClose to close the drawer from a button.

DrawerHeader

Area for the title and description.

Also accepts the props of ViewProps.

DrawerFooter

Area for actions at the end of the panel.

Also accepts the props of ViewProps.

DrawerTitle

Drawer heading, centered for top and bottom drawers.

Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Title>.

DrawerDescription

Supporting text.

Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Description>.

.drawer

ParameterTypeDefault
isPresentedBinding<Bool>-
detentsSet<PresentationDetent>?nil
selectionBinding<PresentationDetent>?nil
onDismiss(() -> Void)?nil
content() -> Content-

DrawerContent

Sliding panel with optional handle and close button.

ParameterTypeDefault
showCloseButtonBoolfalse
closeLabelLocalizedStringKey?nil
content() -> Content-

DrawerHeader

Area for the title and description.

ParameterTypeDefault
content() -> Content-

DrawerFooter

Area for actions at the end of the panel.

ParameterTypeDefault
content() -> Content-

Drawer

Root that holds the open state, direction and snap points.

ParameterTypeDefault
openBoolean-
onOpenChange(Boolean) -> Unit-
modifierModifierModifier
snapPointsList<Float>emptyList()
onSnapPointChange(Float) -> Unit{}
floatingBooleanfalse
showSwipeHandleBooleanfalse
showCloseButtonBooleanfalse
closeLabelString?null
content@Composable ColumnScope.() -> Unit-

DrawerHeader

Area for the title and description.

ParameterTypeDefault
modifierModifierModifier
content@Composable ColumnScope.() -> Unit-

DrawerFooter

Area for actions at the end of the panel.

Receiver: ColumnScope.

ParameterTypeDefault
modifierModifierModifier
content@Composable ColumnScope.() -> Unit-

DrawerTitle

Drawer heading, centered for top and bottom drawers.

ParameterTypeDefault
textString-
modifierModifierModifier

DrawerDescription

Supporting text.

ParameterTypeDefault
textString-
modifierModifierModifier
NextDropdown MenuPreviousDirection

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • Directions
    • With close button
    • With close label
    • Floating
    • With snap points
    • Non modal
    • Sheet with detents
  5. 05Accessibility
  6. 06API Reference
    • DrawerProvider
    • DrawerIndentBackground
    • DrawerIndent
    • Drawer
    • DrawerTrigger
    • DrawerPortal
    • DrawerClose
    • DrawerOverlay
    • DrawerSwipeHandle
    • DrawerContent
    • DrawerHeader
    • DrawerFooter
    • DrawerTitle
    • DrawerDescription
  7. 07Installation
  8. 08Usage
  9. 09Examples
    • Default
    • Snap points
    • Floating
    • Sides
  10. 10Accessibility
  11. 11API Reference
    • DrawerProvider
    • DrawerIndentBackground
    • DrawerIndent
    • Drawer
    • DrawerOverlay
    • DrawerSwipeHandle
    • DrawerContent
    • DrawerHeader
    • DrawerFooter
    • DrawerTitle
    • DrawerDescription
    • .drawer
    • DrawerContent
    • DrawerHeader
    • DrawerFooter
    • Drawer
    • DrawerHeader
    • DrawerFooter
    • DrawerTitle
    • DrawerDescription