suiss/uim · Pattern

Preview

A link-styled trigger that opens a floating drawer with a quick preview, such as a profile card.

Preview is an open-source mobile pattern from suiss/uim: components composed into a flow for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Preview (open by default) on iOS in light mode

PreviewTrigger renders inline in link color and dims when pressed. It opens a Drawer that floats above the screen edges by default and has a swipe handle.

Use it to show a summary of a person, place or item from a mention or link without leaving the screen.

Installation

$ pnpm dlx @esuiss/uim@latest add preview

The CLI also adds what it builds on: Drawer, Text.

Manual

  1. Install the dependencies:
npx expo install cn
  1. Add the pieces it builds on: Drawer, Text, and the primitives components/primitives/use-render.tsx.

  2. Copy the source into components/patterns/preview.tsx:

uniwind/components/patterns/preview.tsx
import { cn } from "cn"
import type * as React from "react"
import { View } from "react-native"
import { resolveClassName } from "@/components/primitives/use-render"
import { Drawer, DrawerContent, DrawerTrigger } from "@/components/ui/drawer"
import { Text, TextClassContext } from "@/components/ui/text"

function Preview({
  open,
  defaultOpen,
  onOpenChange,
  floating = true,
  children,
}: {
  open?: boolean
  defaultOpen?: boolean
  1. Update the import paths to match your project.

Usage

import { Preview, PreviewTrigger, PreviewContent } from "@/components/patterns/preview"
<PreviewDemo defaultOpen />

Put a PreviewTrigger and a PreviewContent inside Preview. A string or number child of the trigger is wrapped in Text.

The preview can be uncontrolled or controlled with open, defaultOpen and onOpenChange. PreviewContent pads its children and adds end padding when a close button is shown, so content does not sit under it.

Examples

Default

iOS
Preview on iOS in light mode

With close button

Shows a close button with showCloseButton.

iOS
Preview (with close button) on iOS in light mode

With close label

Labels the close button Done with closeLabel.

iOS
Preview (with close label) on iOS in light mode

Attached

Sets floating to false so the drawer sits on the screen edges.

iOS
Preview (attached) on iOS in light mode

API Reference

Preview

The root drawer, floating by default.

PropType
About
Controls whether the preview is open.
Type
boolean
Default
—
About
Whether the preview starts open when uncontrolled.
Type
boolean
Default
—
About
Called when the preview opens or closes.
Type
(open: boolean) => void
Default
—
About
Insets the drawer from the screen edges. Defaults to true.
Type
boolean
Default
true
Type
React.ReactNode
Default
—

PreviewTrigger

The link-styled element that opens the preview.

ExtendsReact.ComponentProps<typeof DrawerTrigger>

PreviewContent

The drawer content with padding for the preview.

ExtendsReact.ComponentProps<typeof DrawerContent>
PropType
Type
string
Default
—

Accessibility

  • Give PreviewContent an accessibilityLabel that names what is previewed.

Notes

  • The trigger uses the text-link color.