suiss/uim · Interaction
Preview Menu
Long press an element to lift an enlarged preview of it above a dimmed screen, with a menu of actions below.
Preview Menu is an open-source mobile interaction from suiss/uim 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.


import { CopyIcon, HeartIcon, ShareNetworkIcon, TrashIcon } from "phosphor-react-native"
import * as React from "react"
import { View } from "react-native"
import { PreviewMenu, PreviewMenuContent, PreviewMenuItem, PreviewMenuSeparator, PreviewMenuTrigger } from "@/components/interactions/preview-menu"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"
const photos = [
"bg-blue",
"bg-orange",
"bg-green",
"bg-indigo",
"bg-yellow",
"bg-pink",
"bg-teal",
"bg-purple",
"bg-mint",
]
function PhotoGrid({
withDisabled = false,
openIndex,
}: {
withDisabled?: boolean
openIndex?: number
}) {
const [log, setLog] = React.useState("Touch and hold a photo.")
return (
<View className="gap-3">
<View className="flex-row flex-wrap gap-2">
{photos.map((tone, index) => {
const label = `Photo ${index + 1}`
return (
<PreviewMenu key={tone} defaultOpen={index === openIndex}>
<PreviewMenuTrigger
accessibilityLabel={label}
className="aspect-square w-[31%] overflow-hidden rounded-2xl"
>
<View className={`h-full w-full ${tone}`} />
</PreviewMenuTrigger>
<PreviewMenuContent>
<PreviewMenuItem onPress={() => setLog(`Copied ${label}`)}>
Copy
<Icon as={CopyIcon} />
</PreviewMenuItem>
<PreviewMenuItem onPress={() => setLog(`Shared ${label}`)}>
Share
<Icon as={ShareNetworkIcon} />
</PreviewMenuItem>
<PreviewMenuItem
disabled={withDisabled}
onPress={() => setLog(`Favorited ${label}`)}
>
Favorite
<Icon as={HeartIcon} />
</PreviewMenuItem>
<PreviewMenuSeparator />
<PreviewMenuItem
variant="destructive"
onPress={() => setLog(`Deleted ${label}`)}
>
Delete
<Icon as={TrashIcon} />
</PreviewMenuItem>
</PreviewMenuContent>
</PreviewMenu>
)
})}
</View>
<Text variant="muted">{log}</Text>
</View>
)
}
export function PreviewMenuOpenByDefaultExample() {
return (
<PhotoGrid openIndex={1} />
)
}import EsuissUI
import PhosphorSwift
import SwiftUI
struct PreviewMenuOpenByDefaultExample: View {
var body: some View {
PreviewMenuPhotoGrid(openIndex: 1)
}
}
let previewMenuTones: [Color] = [
.accent,
.warning,
.success,
.link,
.danger,
.accentPressed,
.labelTertiary,
.separatorStrong,
.surfaceTertiary,
]
struct PreviewMenuPhotoGrid: View {
var withDisabled = false
var openIndex: Int?
@State private var log: LocalizedStringKey = "Touch and hold a photo."
var body: some View {
VStack(alignment: .leading, spacing: 12) {
GeometryReader { proxy in
let side = ((proxy.size.width - 16) / 3).rounded(.down)
FlowRow(spacing: 8) {
ForEach(previewMenuTones.indices, id: \.self) { index in
PreviewMenuPhoto(
index: index,
side: side,
withDisabled: withDisabled,
open: index == openIndex,
log: $log
)
}
}
}
.aspectRatio(1, contentMode: .fit)
Text(log)
.textVariant(.muted)
}
}
}
struct PreviewMenuPhoto: View {
let index: Int
let side: CGFloat
let withDisabled: Bool
@Binding var log: LocalizedStringKey
@State private var open: Bool
init(index: Int, side: CGFloat, withDisabled: Bool, open: Bool, log: Binding<LocalizedStringKey>) {
self.index = index
self.side = side
self.withDisabled = withDisabled
_log = log
_open = State(initialValue: open)
}
var body: some View {
let label = "Photo \(index + 1)"
previewMenuTones[index]
.frame(width: side, height: side)
.clipShape(RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous))
.accessibilityElement()
.accessibilityLabel(Text(verbatim: label))
.previewMenu(isPresented: $open) {
PreviewMenuItem("Copy", icon: Ph.copy.regular) { log = "Copied \(label)" }
PreviewMenuItem("Share", icon: Ph.shareNetwork.regular) { log = "Shared \(label)" }
PreviewMenuItem("Favorite", icon: Ph.heart.regular) { log = "Favorited \(label)" }
.disabled(withDisabled)
PreviewMenuSeparator()
PreviewMenuItem("Delete", icon: Ph.trash.regular, variant: .destructive) { log = "Deleted \(label)" }
}
}
}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.FlowRow
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
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.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.Copy
import com.adamglin.phosphoricons.regular.Heart
import com.adamglin.phosphoricons.regular.ShareNetwork
import com.adamglin.phosphoricons.regular.Trash
import com.esuiss.ui.components.MenuItemVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.components.TextVariant
import com.esuiss.ui.interactions.PreviewMenu
import com.esuiss.ui.interactions.PreviewMenuItem
import com.esuiss.ui.interactions.PreviewMenuSeparator
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
@Composable
fun PreviewMenuOpenByDefaultExample() {
PreviewMenuPhotoGrid(openIndex = 1)
}
@Composable
fun previewMenuTones(): List<Color> {
val colors = EsuissTheme.colors
return listOf(
colors.blue,
colors.orange,
colors.green,
colors.indigo,
colors.yellow,
colors.pink,
colors.teal,
colors.purple,
colors.mint,
)
}
@Composable
fun PreviewMenuPhotoGrid(withDisabled: Boolean = false, openIndex: Int? = null) {
var log by rememberSaveable { mutableStateOf("Touch and hold a photo.") }
val shape = RoundedCornerShape(Radius.xl2)
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
FlowRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
previewMenuTones().forEachIndexed { index, tone ->
val label = "Photo ${index + 1}"
var open by rememberSaveable(index) { mutableStateOf(index == openIndex) }
PreviewMenu(
open = open,
onOpenChange = { open = it },
trigger = {
Box(
Modifier
.fillMaxSize()
.clip(shape)
.background(tone, shape)
.semantics { contentDescription = label },
)
},
modifier = Modifier.fillMaxWidth(0.31f).aspectRatio(1f),
) {
PreviewMenuItem("Copy", onClick = { log = "Copied $label" }, icon = PhosphorIcons.Regular.Copy)
PreviewMenuItem("Share", onClick = { log = "Shared $label" }, icon = PhosphorIcons.Regular.ShareNetwork)
PreviewMenuItem(
"Favorite",
onClick = { log = "Favorited $label" },
icon = PhosphorIcons.Regular.Heart,
enabled = !withDisabled,
)
PreviewMenuSeparator()
PreviewMenuItem(
"Delete",
onClick = { log = "Deleted $label" },
icon = PhosphorIcons.Regular.Trash,
variant = MenuItemVariant.Destructive,
)
}
}
}
Text(log, variant = TextVariant.Muted)
}
}Long pressing a PreviewMenuTrigger measures it and the menu, then animates its content from its place on screen into a larger preview, up to 360 points wide. The preview and the menu below it are centered together between the top and bottom safe areas. The rest of the screen fades behind a scrim, and the menu grows out of the trigger into place.
The original trigger is hidden while lifted, so the preview appears to rise out of it. With custom preview content, the trigger's content cross-fades into it as it grows. Pressing outside closes the menu and the preview and menu shrink back into the trigger. Use it for photos, messages or cards that benefit from a closer look before acting.
Installation
$ pnpm dlx @esuiss/uim@latest add preview-menu$ pnpm dlx @esuiss/uim@latest add preview-menu --platform swift$ pnpm dlx @esuiss/uim@latest add preview-menu --platform kotlinThe CLI also adds what it builds on: Icon, Text.
Manual
- Install the dependencies:
npx expo install cn react-native-reanimated react-native-safe-area-context react-native-screens react-native-worklets-
Add the pieces it builds on: Icon, Text, and the primitives
components/primitives/preview-menu.tsx,components/primitives/use-render.tsx. -
Copy the source into
components/interactions/preview-menu.tsx:
import { cn } from "cn"
import * as React from "react"
import { Platform, View } from "react-native"
import { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"
import { useSafeAreaInsets } from "react-native-safe-area-context"
import { FullWindowOverlay as RNFullWindowOverlay } from "react-native-screens"
import * as PreviewMenuPrimitive from "@/components/primitives/preview-menu"
import { resolveClassName } from "@/components/primitives/use-render"
import { AnimatedView } from "@/components/ui/animated-view"
import { IconClassContext } from "@/components/ui/icon"
import { Text, TextClassContext } from "@/components/ui/text"
const FullWindowOverlay =
Platform.OS === "ios" ? RNFullWindowOverlay : React.Fragment
function usePreviewMenu() {- Update the import paths to match your project.
- Install the dependencies:
npx expo install cn react-native-reanimated react-native-safe-area-context react-native-screens react-native-worklets-
Add the pieces it builds on: Icon, Text, and the primitives
components/primitives/preview-menu.tsx,components/primitives/use-render.tsx. -
Copy the source into
components/interactions/preview-menu.tsx:
import { cn } from "cn"
import * as React from "react"
import { Platform, View } from "react-native"
import { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"
import { useSafeAreaInsets } from "react-native-safe-area-context"
import { FullWindowOverlay as RNFullWindowOverlay } from "react-native-screens"
import * as PreviewMenuPrimitive from "@/components/primitives/preview-menu"
import { resolveClassName } from "@/components/primitives/use-render"
import { AnimatedView } from "@/components/ui/animated-view"
import { IconClassContext } from "@/components/ui/icon"
import { Text, TextClassContext } from "@/components/ui/text"
const FullWindowOverlay =
Platform.OS === "ios" ? RNFullWindowOverlay : React.Fragment
function usePreviewMenu() {- Update the import paths to match your project.
- Install the dependencies:
npx expo install react-native-reanimated react-native-safe-area-context react-native-screens react-native-worklets-
Add the pieces it builds on: Icon, Text, and the primitives
components/primitives/preview-menu.tsx,components/primitives/use-render.tsx. -
Copy the source into
components/interactions/preview-menu.tsx:
import * as React from "react"
import { Platform, StyleSheet, View, type ViewStyle } from "react-native"
import { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"
import { useSafeAreaInsets } from "react-native-safe-area-context"
import { FullWindowOverlay as RNFullWindowOverlay } from "react-native-screens"
import * as PreviewMenuPrimitive from "@/components/primitives/preview-menu"
import { resolveStyle } from "@/components/primitives/use-render"
import { AnimatedView } from "@/components/ui/animated-view"
import { IconSizeContext } from "@/components/ui/icon"
import { Text, TextStyleContext } from "@/components/ui/text"
import { fontSize, radius, shadow, useTheme } from "@/components/ui/theme"
const FullWindowOverlay =
Platform.OS === "ios" ? RNFullWindowOverlay : React.Fragment
const styles = StyleSheet.create({- Update the import paths to match your project.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")- Copy the theme files every view uses:
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
}import SwiftUI
extension Color {
public static let surface = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
public static let surfaceSecondary = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
public static let surfaceTertiary = Color.adaptive(light: .init(0xE8E8ED), dark: .init(0x2C2C2E))
public static let surfaceRaised = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
public static let label = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
public static let labelSecondary = Color.adaptive(light: .init(0x6E6E73), dark: .init(0xA1A1A6))
public static let labelTertiary = Color.adaptive(light: .init(0x86868B), dark: .init(0x86868B))
public static let labelQuaternary = Color.adaptive(light: .init(0xD2D2D7), dark: .init(0x424245))
public static let control = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
public static let controlPressed = Color.adaptive(light: .init(0x000000, 0.12), dark: .init(0xFFFFFF, 0.22))
public static let controlSelected = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
public static let controlDisabled = Color.adaptive(light: .init(0x000000, 0.03), dark: .init(0xFFFFFF, 0.05))
public static let onControlSelected = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))- Copy the source and every file it uses:
import SwiftUI
public enum PreviewMenuItemVariant: CaseIterable, Sendable {
case `default`, destructive
}
let previewMenuEnter = Animation.timingCurve(0.32, 0.72, 0, 1, duration: 0.4)
let previewMenuExit = Animation.timingCurve(0.32, 0.72, 0, 1, duration: 0.3)
enum PreviewMenuMath {
static let edge: CGFloat = 16
static let menuSpace: CGFloat = 260
static let menuMinHeight: CGFloat = 88
static let maxWidth: CGFloat = 360
static let menuWidth: CGFloat = 250
static let menuGap: CGFloat = 12import 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, icon, iconXs, iconSm, iconLg, iconXl
var height: CGFloat {
switch self {
case .xs, .iconXs: 24
case .sm, .iconSm: 32
case .default, .icon: 36
case .lg, .iconLg: 44import 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
}import PhosphorSwift
import SwiftUI
extension Shadow {
static let control = Shadow(color: .black.opacity(0.08), radius: 0.5, y: 0.5)
static let thumb = Shadow(color: .black.opacity(0.12), radius: 1.5, y: 1)
}
struct SelectionIndicator<Mark: View>: View {
let checked: Bool
let pressed: Bool
let cornerRadius: CGFloat
let mark: Mark
@Environment(\.isEnabled) private var isEnabled
@Environment(\.isInvalid) private var invalidimport SwiftUI
extension EnvironmentValues {
@Entry public var isInvalid = false
@Entry var fieldInset = false
@Entry var fieldGroupInset = false
@Entry var fieldSetInset = false
}
extension View {
public func invalid(_ isInvalid: Bool = true) -> some View {
environment(\.isInvalid, isInvalid)
}
}
public enum FieldOrientation: CaseIterable, Sendable {import SwiftUI
extension EnvironmentValues {
@Entry public var hapticsEnabled = true
}
extension View {
public func haptics(_ enabled: Bool) -> some View {
environment(\.hapticsEnabled, enabled)
}
func hapticFeedback<Trigger: Equatable>(_ feedback: SensoryFeedback, trigger: Trigger) -> some View {
modifier(HapticFeedbackModifier(feedback: feedback, trigger: trigger) { _, _ in true })
}
func hapticFeedback<Trigger: Equatable>(import PhosphorSwift
import Observation
import SwiftUI
public enum PopupAlignment: Sendable, CaseIterable {
case start, center, end
}
struct OverlayDismiss: Sendable {
let action: @MainActor @Sendable () -> Void
@MainActor func callAsFunction() {
action()
}
}import SwiftUI
public struct Separator: View {
let orientation: Axis
public init(_ orientation: Axis = .horizontal) {
self.orientation = orientation
}
public var body: some View {
Rectangle()
.fill(Color.separator)
.frame(width: orientation == .vertical ? 1 : nil, height: orientation == .horizontal ? 1 : nil)
.frame(maxWidth: orientation == .horizontal ? .infinity : nil, maxHeight: orientation == .vertical ? .infinity : nil)
.accessibilityHidden(true)
}import SwiftUI
public enum TextVariant: CaseIterable, Sendable {
case `default`, h1, h2, h3, h4, p, blockquote, code, lead, large, small, muted
var style: TextStyle {
switch self {
case .h1: .xl3
case .h2: .xl2
case .h3: .xl
case .h4, .lead, .large: .lg
case .code, .small, .muted: .sm
default: .base
}
}- Add the files to your app target.
- Set
minSdkto 24 or higher and add the 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")- Copy the theme files every view uses:
package com.esuiss.ui.theme
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.text.TextStyle
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpOffsetpackage com.esuiss.ui.theme
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
@Immutable
data class Colors(
val surface: Color,
val surfaceSecondary: Color,
val surfaceTertiary: Color,
val surfaceRaised: Color,
val label: Color,
val labelSecondary: Color,
val labelTertiary: Color,
val labelQuaternary: Color,- Copy the source and every file it uses:
package com.esuiss.ui.interactions
import android.os.Build
import android.view.WindowManager
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScopepackage 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.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShapepackage 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.Immutablepackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.selection.triStateToggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Colorpackage 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 }package com.esuiss.ui.components
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
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.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightpackage 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.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.LayoutScopeMarker
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextpackage com.esuiss.ui.components
import android.provider.Settings
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Sizepackage com.esuiss.ui.components
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.hapticfeedback.HapticFeedback
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
val LocalHapticsEnabled = staticCompositionLocalOf { true }
@Composable
fun ProvideHaptics(enabled: Boolean, content: @Composable () -> Unit) {
CompositionLocalProvider(LocalHapticsEnabled provides enabled, content = content)
}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,package com.esuiss.ui.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography
@Composablepackage 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.slideInpackage com.esuiss.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.EsuissTheme
@Composable
fun Separator(- Update the
com.esuiss.uipackage names to match your project.
Usage
import { PreviewMenu, PreviewMenuTrigger, PreviewMenuContent, PreviewMenuItem, PreviewMenuSeparator } from "@/components/interactions/preview-menu"<PhotoGrid openIndex={1} />Put a PreviewMenuTrigger with the element and a PreviewMenuContent with PreviewMenuItems inside PreviewMenu. By default the preview repeats the trigger's children; pass preview to show different content, such as a larger image.
Set aspectRatio to size the preview, for example 4 / 3. The menu can be uncontrolled or controlled with open, defaultOpen and onOpenChange. usePreviewMenu returns open, lifted and frame.
Examples
Default


import { CopyIcon, HeartIcon, ShareNetworkIcon, TrashIcon } from "phosphor-react-native"
import * as React from "react"
import { View } from "react-native"
import { PreviewMenu, PreviewMenuContent, PreviewMenuItem, PreviewMenuSeparator, PreviewMenuTrigger } from "@/components/interactions/preview-menu"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"
const photos = [
"bg-blue",
"bg-orange",
"bg-green",
"bg-indigo",
"bg-yellow",
"bg-pink",
"bg-teal",
"bg-purple",
"bg-mint",
]
function PhotoGrid({
withDisabled = false,
openIndex,
}: {
withDisabled?: boolean
openIndex?: number
}) {
const [log, setLog] = React.useState("Touch and hold a photo.")
return (
<View className="gap-3">
<View className="flex-row flex-wrap gap-2">
{photos.map((tone, index) => {
const label = `Photo ${index + 1}`
return (
<PreviewMenu key={tone} defaultOpen={index === openIndex}>
<PreviewMenuTrigger
accessibilityLabel={label}
className="aspect-square w-[31%] overflow-hidden rounded-2xl"
>
<View className={`h-full w-full ${tone}`} />
</PreviewMenuTrigger>
<PreviewMenuContent>
<PreviewMenuItem onPress={() => setLog(`Copied ${label}`)}>
Copy
<Icon as={CopyIcon} />
</PreviewMenuItem>
<PreviewMenuItem onPress={() => setLog(`Shared ${label}`)}>
Share
<Icon as={ShareNetworkIcon} />
</PreviewMenuItem>
<PreviewMenuItem
disabled={withDisabled}
onPress={() => setLog(`Favorited ${label}`)}
>
Favorite
<Icon as={HeartIcon} />
</PreviewMenuItem>
<PreviewMenuSeparator />
<PreviewMenuItem
variant="destructive"
onPress={() => setLog(`Deleted ${label}`)}
>
Delete
<Icon as={TrashIcon} />
</PreviewMenuItem>
</PreviewMenuContent>
</PreviewMenu>
)
})}
</View>
<Text variant="muted">{log}</Text>
</View>
)
}
export function PreviewMenuExample() {
return (
<PhotoGrid />
)
}import EsuissUI
import PhosphorSwift
import SwiftUI
let previewMenuTones: [Color] = [
.accent,
.warning,
.success,
.link,
.danger,
.accentPressed,
.labelTertiary,
.separatorStrong,
.surfaceTertiary,
]
struct PreviewMenuPhotoGrid: View {
var withDisabled = false
var openIndex: Int?
@State private var log: LocalizedStringKey = "Touch and hold a photo."
var body: some View {
VStack(alignment: .leading, spacing: 12) {
GeometryReader { proxy in
let side = ((proxy.size.width - 16) / 3).rounded(.down)
FlowRow(spacing: 8) {
ForEach(previewMenuTones.indices, id: \.self) { index in
PreviewMenuPhoto(
index: index,
side: side,
withDisabled: withDisabled,
open: index == openIndex,
log: $log
)
}
}
}
.aspectRatio(1, contentMode: .fit)
Text(log)
.textVariant(.muted)
}
}
}
struct PreviewMenuPhoto: View {
let index: Int
let side: CGFloat
let withDisabled: Bool
@Binding var log: LocalizedStringKey
@State private var open: Bool
init(index: Int, side: CGFloat, withDisabled: Bool, open: Bool, log: Binding<LocalizedStringKey>) {
self.index = index
self.side = side
self.withDisabled = withDisabled
_log = log
_open = State(initialValue: open)
}
var body: some View {
let label = "Photo \(index + 1)"
previewMenuTones[index]
.frame(width: side, height: side)
.clipShape(RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous))
.accessibilityElement()
.accessibilityLabel(Text(verbatim: label))
.previewMenu(isPresented: $open) {
PreviewMenuItem("Copy", icon: Ph.copy.regular) { log = "Copied \(label)" }
PreviewMenuItem("Share", icon: Ph.shareNetwork.regular) { log = "Shared \(label)" }
PreviewMenuItem("Favorite", icon: Ph.heart.regular) { log = "Favorited \(label)" }
.disabled(withDisabled)
PreviewMenuSeparator()
PreviewMenuItem("Delete", icon: Ph.trash.regular, variant: .destructive) { log = "Deleted \(label)" }
}
}
}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.FlowRow
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
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.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.Copy
import com.adamglin.phosphoricons.regular.Heart
import com.adamglin.phosphoricons.regular.ShareNetwork
import com.adamglin.phosphoricons.regular.Trash
import com.esuiss.ui.components.MenuItemVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.components.TextVariant
import com.esuiss.ui.interactions.PreviewMenu
import com.esuiss.ui.interactions.PreviewMenuItem
import com.esuiss.ui.interactions.PreviewMenuSeparator
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
@Composable
fun previewMenuTones(): List<Color> {
val colors = EsuissTheme.colors
return listOf(
colors.blue,
colors.orange,
colors.green,
colors.indigo,
colors.yellow,
colors.pink,
colors.teal,
colors.purple,
colors.mint,
)
}
@Composable
fun PreviewMenuPhotoGrid(withDisabled: Boolean = false, openIndex: Int? = null) {
var log by rememberSaveable { mutableStateOf("Touch and hold a photo.") }
val shape = RoundedCornerShape(Radius.xl2)
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
FlowRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
previewMenuTones().forEachIndexed { index, tone ->
val label = "Photo ${index + 1}"
var open by rememberSaveable(index) { mutableStateOf(index == openIndex) }
PreviewMenu(
open = open,
onOpenChange = { open = it },
trigger = {
Box(
Modifier
.fillMaxSize()
.clip(shape)
.background(tone, shape)
.semantics { contentDescription = label },
)
},
modifier = Modifier.fillMaxWidth(0.31f).aspectRatio(1f),
) {
PreviewMenuItem("Copy", onClick = { log = "Copied $label" }, icon = PhosphorIcons.Regular.Copy)
PreviewMenuItem("Share", onClick = { log = "Shared $label" }, icon = PhosphorIcons.Regular.ShareNetwork)
PreviewMenuItem(
"Favorite",
onClick = { log = "Favorited $label" },
icon = PhosphorIcons.Regular.Heart,
enabled = !withDisabled,
)
PreviewMenuSeparator()
PreviewMenuItem(
"Delete",
onClick = { log = "Deleted $label" },
icon = PhosphorIcons.Regular.Trash,
variant = MenuItemVariant.Destructive,
)
}
}
}
Text(log, variant = TextVariant.Muted)
}
}Disabled item
Includes a disabled menu item.


import { CopyIcon, HeartIcon, ShareNetworkIcon, TrashIcon } from "phosphor-react-native"
import * as React from "react"
import { View } from "react-native"
import { PreviewMenu, PreviewMenuContent, PreviewMenuItem, PreviewMenuSeparator, PreviewMenuTrigger } from "@/components/interactions/preview-menu"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"
const photos = [
"bg-blue",
"bg-orange",
"bg-green",
"bg-indigo",
"bg-yellow",
"bg-pink",
"bg-teal",
"bg-purple",
"bg-mint",
]
function PhotoGrid({
withDisabled = false,
openIndex,
}: {
withDisabled?: boolean
openIndex?: number
}) {
const [log, setLog] = React.useState("Touch and hold a photo.")
return (
<View className="gap-3">
<View className="flex-row flex-wrap gap-2">
{photos.map((tone, index) => {
const label = `Photo ${index + 1}`
return (
<PreviewMenu key={tone} defaultOpen={index === openIndex}>
<PreviewMenuTrigger
accessibilityLabel={label}
className="aspect-square w-[31%] overflow-hidden rounded-2xl"
>
<View className={`h-full w-full ${tone}`} />
</PreviewMenuTrigger>
<PreviewMenuContent>
<PreviewMenuItem onPress={() => setLog(`Copied ${label}`)}>
Copy
<Icon as={CopyIcon} />
</PreviewMenuItem>
<PreviewMenuItem onPress={() => setLog(`Shared ${label}`)}>
Share
<Icon as={ShareNetworkIcon} />
</PreviewMenuItem>
<PreviewMenuItem
disabled={withDisabled}
onPress={() => setLog(`Favorited ${label}`)}
>
Favorite
<Icon as={HeartIcon} />
</PreviewMenuItem>
<PreviewMenuSeparator />
<PreviewMenuItem
variant="destructive"
onPress={() => setLog(`Deleted ${label}`)}
>
Delete
<Icon as={TrashIcon} />
</PreviewMenuItem>
</PreviewMenuContent>
</PreviewMenu>
)
})}
</View>
<Text variant="muted">{log}</Text>
</View>
)
}
export function PreviewMenuDisabledItemExample() {
return (
<PhotoGrid withDisabled openIndex={0} />
)
}import EsuissUI
import PhosphorSwift
import SwiftUI
struct PreviewMenuDisabledItemExample: View {
var body: some View {
PreviewMenuPhotoGrid(withDisabled: true, openIndex: 0)
}
}
let previewMenuTones: [Color] = [
.accent,
.warning,
.success,
.link,
.danger,
.accentPressed,
.labelTertiary,
.separatorStrong,
.surfaceTertiary,
]
struct PreviewMenuPhotoGrid: View {
var withDisabled = false
var openIndex: Int?
@State private var log: LocalizedStringKey = "Touch and hold a photo."
var body: some View {
VStack(alignment: .leading, spacing: 12) {
GeometryReader { proxy in
let side = ((proxy.size.width - 16) / 3).rounded(.down)
FlowRow(spacing: 8) {
ForEach(previewMenuTones.indices, id: \.self) { index in
PreviewMenuPhoto(
index: index,
side: side,
withDisabled: withDisabled,
open: index == openIndex,
log: $log
)
}
}
}
.aspectRatio(1, contentMode: .fit)
Text(log)
.textVariant(.muted)
}
}
}
struct PreviewMenuPhoto: View {
let index: Int
let side: CGFloat
let withDisabled: Bool
@Binding var log: LocalizedStringKey
@State private var open: Bool
init(index: Int, side: CGFloat, withDisabled: Bool, open: Bool, log: Binding<LocalizedStringKey>) {
self.index = index
self.side = side
self.withDisabled = withDisabled
_log = log
_open = State(initialValue: open)
}
var body: some View {
let label = "Photo \(index + 1)"
previewMenuTones[index]
.frame(width: side, height: side)
.clipShape(RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous))
.accessibilityElement()
.accessibilityLabel(Text(verbatim: label))
.previewMenu(isPresented: $open) {
PreviewMenuItem("Copy", icon: Ph.copy.regular) { log = "Copied \(label)" }
PreviewMenuItem("Share", icon: Ph.shareNetwork.regular) { log = "Shared \(label)" }
PreviewMenuItem("Favorite", icon: Ph.heart.regular) { log = "Favorited \(label)" }
.disabled(withDisabled)
PreviewMenuSeparator()
PreviewMenuItem("Delete", icon: Ph.trash.regular, variant: .destructive) { log = "Deleted \(label)" }
}
}
}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.FlowRow
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
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.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.Copy
import com.adamglin.phosphoricons.regular.Heart
import com.adamglin.phosphoricons.regular.ShareNetwork
import com.adamglin.phosphoricons.regular.Trash
import com.esuiss.ui.components.MenuItemVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.components.TextVariant
import com.esuiss.ui.interactions.PreviewMenu
import com.esuiss.ui.interactions.PreviewMenuItem
import com.esuiss.ui.interactions.PreviewMenuSeparator
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
@Composable
fun PreviewMenuDisabledItemExample() {
PreviewMenuPhotoGrid(withDisabled = true, openIndex = 0)
}
@Composable
fun previewMenuTones(): List<Color> {
val colors = EsuissTheme.colors
return listOf(
colors.blue,
colors.orange,
colors.green,
colors.indigo,
colors.yellow,
colors.pink,
colors.teal,
colors.purple,
colors.mint,
)
}
@Composable
fun PreviewMenuPhotoGrid(withDisabled: Boolean = false, openIndex: Int? = null) {
var log by rememberSaveable { mutableStateOf("Touch and hold a photo.") }
val shape = RoundedCornerShape(Radius.xl2)
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
FlowRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
previewMenuTones().forEachIndexed { index, tone ->
val label = "Photo ${index + 1}"
var open by rememberSaveable(index) { mutableStateOf(index == openIndex) }
PreviewMenu(
open = open,
onOpenChange = { open = it },
trigger = {
Box(
Modifier
.fillMaxSize()
.clip(shape)
.background(tone, shape)
.semantics { contentDescription = label },
)
},
modifier = Modifier.fillMaxWidth(0.31f).aspectRatio(1f),
) {
PreviewMenuItem("Copy", onClick = { log = "Copied $label" }, icon = PhosphorIcons.Regular.Copy)
PreviewMenuItem("Share", onClick = { log = "Shared $label" }, icon = PhosphorIcons.Regular.ShareNetwork)
PreviewMenuItem(
"Favorite",
onClick = { log = "Favorited $label" },
icon = PhosphorIcons.Regular.Heart,
enabled = !withDisabled,
)
PreviewMenuSeparator()
PreviewMenuItem(
"Delete",
onClick = { log = "Deleted $label" },
icon = PhosphorIcons.Regular.Trash,
variant = MenuItemVariant.Destructive,
)
}
}
}
Text(log, variant = TextVariant.Muted)
}
}Custom preview
Shows custom preview content with a 4 / 3 aspect ratio.


import { ShareNetworkIcon, TrashIcon } from "phosphor-react-native"
import { View } from "react-native"
import { PreviewMenu, PreviewMenuContent, PreviewMenuItem, PreviewMenuTrigger } from "@/components/interactions/preview-menu"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"
const photos = [
"bg-blue",
"bg-orange",
"bg-green",
"bg-indigo",
"bg-yellow",
"bg-pink",
"bg-teal",
"bg-purple",
"bg-mint",
]
function AlbumPreview({ defaultOpen }: { defaultOpen?: boolean }) {
return (
<PreviewMenu aspectRatio={4 / 3} defaultOpen={defaultOpen}>
<PreviewMenuTrigger className="flex-row items-center gap-3 rounded-xl bg-surface-secondary p-3">
<View className="size-12 rounded-lg bg-blue" />
<View>
<Text className="font-semibold">Trip to the coast</Text>
<Text variant="muted">48 photos</Text>
</View>
</PreviewMenuTrigger>
<PreviewMenuContent
preview={
<View className="h-full w-full justify-end bg-blue p-4">
<Text className="text-lg font-semibold text-on-accent">
Trip to the coast
</Text>
<Text className="text-sm text-on-accent">
48 photos · Updated today
</Text>
</View>
}
>
<PreviewMenuItem>
Share album
<Icon as={ShareNetworkIcon} />
</PreviewMenuItem>
<PreviewMenuItem variant="destructive">
Delete album
<Icon as={TrashIcon} />
</PreviewMenuItem>
</PreviewMenuContent>
</PreviewMenu>
)
}
export function PreviewMenuCustomPreviewExample() {
return (
<AlbumPreview />
)
}import EsuissUI
import PhosphorSwift
import SwiftUI
struct PreviewMenuAlbum: View {
@State private var open: Bool
init(open: Bool = false) {
_open = State(initialValue: open)
}
var body: some View {
HStack(spacing: 12) {
RoundedRectangle(cornerRadius: Radius.lg, style: .continuous)
.fill(Color.accent)
.frame(width: 48, height: 48)
VStack(alignment: .leading, spacing: 0) {
Text("Trip to the coast")
.textStyle(.base, weight: .semibold)
.foregroundStyle(Color.label)
Text("48 photos")
.textVariant(.muted)
}
}
.padding(12)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.surfaceSecondary, in: RoundedRectangle(cornerRadius: Radius.xl, style: .continuous))
.previewMenu(isPresented: $open, aspectRatio: 4 / 3) {
PreviewMenuItem("Share album", icon: Ph.shareNetwork.regular) {}
PreviewMenuItem("Delete album", icon: Ph.trash.regular, variant: .destructive) {}
} preview: {
VStack(alignment: .leading, spacing: 0) {
Text("Trip to the coast")
.textStyle(.lg, weight: .semibold)
Text("48 photos · Updated today")
.textStyle(.sm)
}
.foregroundStyle(Color.onAccent)
.padding(16)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
.background(Color.accent)
}
}
}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.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
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 com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.ShareNetwork
import com.adamglin.phosphoricons.regular.Trash
import com.esuiss.ui.components.MenuItemVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.components.TextVariant
import com.esuiss.ui.interactions.PreviewMenu
import com.esuiss.ui.interactions.PreviewMenuItem
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography
@Composable
fun PreviewMenuCustomPreviewExample() {
PreviewMenuAlbum(defaultOpen = false)
}
@Composable
fun PreviewMenuAlbum(defaultOpen: Boolean) {
val colors = EsuissTheme.colors
var open by rememberSaveable { mutableStateOf(defaultOpen) }
PreviewMenu(
open = open,
onOpenChange = { open = it },
aspectRatio = 4f / 3f,
trigger = {
Row(
modifier = Modifier
.fillMaxWidth()
.background(colors.surfaceSecondary, RoundedCornerShape(Radius.xl))
.padding(12.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Box(Modifier.size(48.dp).background(colors.blue, RoundedCornerShape(Radius.lg)))
Column {
Text("Trip to the coast", style = Typography.base.copy(fontWeight = FontWeight.SemiBold))
Text("48 photos", variant = TextVariant.Muted)
}
}
},
preview = {
Column(
modifier = Modifier
.fillMaxSize()
.background(colors.blue)
.padding(16.dp),
verticalArrangement = Arrangement.Bottom,
) {
Text("Trip to the coast", style = Typography.lg.copy(color = colors.onAccent, fontWeight = FontWeight.SemiBold))
Text("48 photos · Updated today", style = Typography.sm.copy(color = colors.onAccent))
}
},
) {
PreviewMenuItem("Share album", onClick = {}, icon = PhosphorIcons.Regular.ShareNetwork)
PreviewMenuItem("Delete album", onClick = {}, icon = PhosphorIcons.Regular.Trash, variant = MenuItemVariant.Destructive)
}
}Custom preview open
The custom preview, open on first render.


import { ShareNetworkIcon, TrashIcon } from "phosphor-react-native"
import { View } from "react-native"
import { PreviewMenu, PreviewMenuContent, PreviewMenuItem, PreviewMenuTrigger } from "@/components/interactions/preview-menu"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"
const photos = [
"bg-blue",
"bg-orange",
"bg-green",
"bg-indigo",
"bg-yellow",
"bg-pink",
"bg-teal",
"bg-purple",
"bg-mint",
]
function AlbumPreview({ defaultOpen }: { defaultOpen?: boolean }) {
return (
<PreviewMenu aspectRatio={4 / 3} defaultOpen={defaultOpen}>
<PreviewMenuTrigger className="flex-row items-center gap-3 rounded-xl bg-surface-secondary p-3">
<View className="size-12 rounded-lg bg-blue" />
<View>
<Text className="font-semibold">Trip to the coast</Text>
<Text variant="muted">48 photos</Text>
</View>
</PreviewMenuTrigger>
<PreviewMenuContent
preview={
<View className="h-full w-full justify-end bg-blue p-4">
<Text className="text-lg font-semibold text-on-accent">
Trip to the coast
</Text>
<Text className="text-sm text-on-accent">
48 photos · Updated today
</Text>
</View>
}
>
<PreviewMenuItem>
Share album
<Icon as={ShareNetworkIcon} />
</PreviewMenuItem>
<PreviewMenuItem variant="destructive">
Delete album
<Icon as={TrashIcon} />
</PreviewMenuItem>
</PreviewMenuContent>
</PreviewMenu>
)
}
export function PreviewMenuCustomPreviewOpenExample() {
return (
<AlbumPreview defaultOpen />
)
}import EsuissUI
import PhosphorSwift
import SwiftUI
struct PreviewMenuCustomPreviewOpenExample: View {
var body: some View {
PreviewMenuAlbum(open: true)
}
}
struct PreviewMenuAlbum: View {
@State private var open: Bool
init(open: Bool = false) {
_open = State(initialValue: open)
}
var body: some View {
HStack(spacing: 12) {
RoundedRectangle(cornerRadius: Radius.lg, style: .continuous)
.fill(Color.accent)
.frame(width: 48, height: 48)
VStack(alignment: .leading, spacing: 0) {
Text("Trip to the coast")
.textStyle(.base, weight: .semibold)
.foregroundStyle(Color.label)
Text("48 photos")
.textVariant(.muted)
}
}
.padding(12)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.surfaceSecondary, in: RoundedRectangle(cornerRadius: Radius.xl, style: .continuous))
.previewMenu(isPresented: $open, aspectRatio: 4 / 3) {
PreviewMenuItem("Share album", icon: Ph.shareNetwork.regular) {}
PreviewMenuItem("Delete album", icon: Ph.trash.regular, variant: .destructive) {}
} preview: {
VStack(alignment: .leading, spacing: 0) {
Text("Trip to the coast")
.textStyle(.lg, weight: .semibold)
Text("48 photos · Updated today")
.textStyle(.sm)
}
.foregroundStyle(Color.onAccent)
.padding(16)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
.background(Color.accent)
}
}
}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.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
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 com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.ShareNetwork
import com.adamglin.phosphoricons.regular.Trash
import com.esuiss.ui.components.MenuItemVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.components.TextVariant
import com.esuiss.ui.interactions.PreviewMenu
import com.esuiss.ui.interactions.PreviewMenuItem
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography
@Composable
fun PreviewMenuCustomPreviewOpenExample() {
PreviewMenuAlbum(defaultOpen = true)
}
@Composable
fun PreviewMenuAlbum(defaultOpen: Boolean) {
val colors = EsuissTheme.colors
var open by rememberSaveable { mutableStateOf(defaultOpen) }
PreviewMenu(
open = open,
onOpenChange = { open = it },
aspectRatio = 4f / 3f,
trigger = {
Row(
modifier = Modifier
.fillMaxWidth()
.background(colors.surfaceSecondary, RoundedCornerShape(Radius.xl))
.padding(12.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Box(Modifier.size(48.dp).background(colors.blue, RoundedCornerShape(Radius.lg)))
Column {
Text("Trip to the coast", style = Typography.base.copy(fontWeight = FontWeight.SemiBold))
Text("48 photos", variant = TextVariant.Muted)
}
}
},
preview = {
Column(
modifier = Modifier
.fillMaxSize()
.background(colors.blue)
.padding(16.dp),
verticalArrangement = Arrangement.Bottom,
) {
Text("Trip to the coast", style = Typography.lg.copy(color = colors.onAccent, fontWeight = FontWeight.SemiBold))
Text("48 photos · Updated today", style = Typography.sm.copy(color = colors.onAccent))
}
},
) {
PreviewMenuItem("Share album", onClick = {}, icon = PhosphorIcons.Regular.ShareNetwork)
PreviewMenuItem("Delete album", onClick = {}, icon = PhosphorIcons.Regular.Trash, variant = MenuItemVariant.Destructive)
}
}API Reference
PreviewMenu
The root that owns the open state and preview size.
- 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
- Width-to-height ratio of the lifted preview.
- Type
number- Default
- —
- Type
React.ReactNode- Default
- —
PreviewMenuTrigger
The element that opens the preview on long press.
React.ComponentProps<typeof PreviewMenuPrimitive.Trigger>PreviewMenuContent
The scrim, the lifted preview and the menu.
React.ComponentProps<typeof PreviewMenuPrimitive.Popup>- About
- Content to show in the preview instead of the trigger's children.
- Type
React.ReactNode- Default
- —
- About
- Classes for the preview container.
- Type
string- Default
- —
- About
- Name of a portal host to render into.
- Type
string- Default
- —
PreviewMenuItem
A menu action.
React.ComponentProps<typeof PreviewMenuPrimitive.Item>- About
defaultordestructive, which uses the danger color.- Type
"default""destructive"- Default
- "default"
- Type
React.ReactNode- Default
- —
PreviewMenuSeparator
A thick divider between groups of items.
React.ComponentProps<typeof PreviewMenuPrimitive.Separator>Accessibility
- The trigger has a
longpressaccessibility action, so screen reader users can open the menu without holding. - The trigger exposes
expandedanddisabledstates. - The preview is hidden from screen readers; focus goes to the menu.
Notes
- A medium impact haptic plays when the menu opens, if the app provides an adapter through
HapticsProvider. - The menu uses
bg-surface-raisedwith a border that is stronger in dark mode, and the backdrop usesbg-scrim. - The preview stays within the top and bottom safe areas and leaves room for the measured height of the menu.
- Animations respect the system reduce motion setting.
- On iOS the content renders in a full-window overlay so it appears above native screens.