suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
GitHubGet started
DocsComponentsPatternsInteractionsChartsBlocks
Patterns19
  • Overview
  • Action Bar
  • Action Menu
  • App Shell
  • Command Palette
  • Confirm
  • Context Actions
  • Date Picker
  • Flyout
  • Modal
  • Navbar
  • Paged List
  • Panel
  • Picker
  • Preview
  • Search Picker
  • Segment Picker
  • Split View
  • Table List
  • Trail

suiss/ui · Pattern

Context Actions

Actions for an element that open as a context menu on right click, or an action sheet on long press on mobile.

Context Actions is an open-source pattern 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 {
  ContextActions,
  ContextActionsContent,
  ContextActionsItem,
  ContextActionsLabel,
  ContextActionsSeparator,
  ContextActionsTrigger,
} from "@/components/patterns/context-actions"

export default function ContextActionsDemo() {
  return (
    <div className="flex min-h-svh items-center justify-center p-4">
      <ContextActions>
        <ContextActionsTrigger className="flex h-40 w-72 items-center justify-center rounded-2xl border border-dashed text-sm text-muted-foreground">
          Right click or long press
        </ContextActionsTrigger>
        <ContextActionsContent>
          <ContextActionsLabel>Photo.jpg</ContextActionsLabel>
          <ContextActionsItem>Edit</ContextActionsItem>
          <ContextActionsItem>Duplicate</ContextActionsItem>
          <ContextActionsItem>Share</ContextActionsItem>
          <ContextActionsSeparator />
          <ContextActionsItem variant="destructive">Delete</ContextActionsItem>
        </ContextActionsContent>
      </ContextActions>
    </div>
  )
}

ContextActions attaches a set of actions to an area of the page. On desktop it renders a ContextMenu that opens at the pointer on right click. Below the 48rem breakpoint it renders an AlertSheet instead, opened by a 500 ms long press on touch, by the context menu event, or by the ContextMenu key or Shift+F10; the sheet groups the items in a card and appends a Cancel button.

Use it for secondary actions on content such as photos, files or list rows, where actions should stay out of the way until requested.

Installation

CLI

$ pnpm dlx shadcn@latest add @esuiss/context-actions

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 patterns context-actions

Manual

  1. Install the dependencies and add the cn helper:
$ pnpm add @base-ui/react
  1. Add the pieces it builds on: Alert Sheet, Context Menu, use-mobile.

  2. Copy the source into components/patterns/context-actions.tsx:

  1. Update the import paths to match your project.

Usage

import { ContextActions, ContextActionsTrigger, ContextActionsContent, ContextActionsLabel, ContextActionsItem, ContextActionsSeparator } 
<div













Wrap the target area in ContextActionsTrigger and list the actions in ContextActionsContent. The open state is internal; use onOpenChange to react to it. A long press is cancelled if the finger moves more than 10 pixels, so scrolling over the trigger does not open the sheet.

Examples

With icons

Places an icon before every action, including a destructive Delete item.

Not dismissible

Sets dismissible to false so the mobile sheet closes only through an action or Cancel.

API Reference

Anatomy6 parts
<ContextActions>
<ContextActionsTrigger />
<ContextActionsContent>
<ContextActionsLabel />
<ContextActionsItem />
<ContextActionsSeparator />
</ContextActionsContent>
</ContextActions
01

ContextActions

The root that renders a ContextMenu on desktop and an AlertSheet on mobile.

PropTypeDefaultDescription
onOpenChange(open: boolean) => void-Called when the menu or sheet opens or closes.
dismissiblebooleantrueWhen true, the mobile sheet closes on an outside press; when false, it uses an alert dialog that closes only through an action or Cancel.

Also accepts the props of React.ComponentProps<typeof ContextMenu>.

02

ContextActionsTrigger

The area that opens the actions on right click, or on long press and keyboard on mobile.

Also accepts the props of React.HTMLAttributes<HTMLElement>.

03

ContextActionsContent

The popup holding the actions; on mobile it adds a Cancel button below them.

PropTypeDefaultDescription
cancelLabelstring"Cancel"Text of the Cancel button shown below the actions on mobile.

Also accepts the props of React.HTMLAttributes<HTMLElement>.

04

ContextActionsLabel

A non-interactive heading; a menu label on desktop and the sheet title on mobile.

Also accepts the props of React.HTMLAttributes<HTMLElement>.

05

ContextActionsItem

An actionable entry that closes the actions when chosen.

PropTypeDefaultDescription
variant"default" | "destructive"-Use destructive to style the item as a destructive action.
disabledboolean-Prevents the item from being chosen.

Also accepts the props of React.HTMLAttributes<HTMLElement>.

On the aria base, respond to the item with onAction.

06

ContextActionsSeparator

A divider between groups of items, rendered on desktop only.

Also accepts the props of React.HTMLAttributes<HTMLElement>.

Accessibility

  • On desktop the popup has the menu role and receives focus when opened; arrow keys move between menuitems and Enter runs the focused one.
  • Escape closes the menu.
  • On mobile the trigger has role="button", tabIndex={0} and aria-haspopup="dialog", and opens with the ContextMenu key or Shift+F10.

Notes

Parts carry data-slot values context-actions, context-actions-trigger, context-actions-content, context-actions-label, context-actions-item and context-actions-separator. On mobile the trigger disables text selection and the iOS touch callout so a long press does not select text.

ContextActions turns any content into a long-press target. Holding ContextActionsTrigger for 500 ms opens an AlertSheet with the actions grouped in one block and a separate Cancel button below.

Use it for secondary actions on photos, messages or list rows that should not take up space on screen.

Installation

$ pnpm dlx shadcn@latest add @esuiss-rn/context-actions

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

$ pnpm dlx @esuiss/ui@latest add context-actions
$ pnpm dlx @esuiss/ui@latest add context-actions --platform swift
NextDate PickerPreviousConfirm

On this page

  1. 01Installation
    • CLI
    • Manual
  2. 02Usage
  3. 03Examples
    • With icons
    • Not dismissible
  4. 04API Reference
    • ContextActions
    • ContextActionsTrigger
    • ContextActionsContent
    • ContextActionsLabel
    • ContextActionsItem
    • ContextActionsSeparator
  5. 05Accessibility
  6. 06Notes
  7. 07Installation
    • Manual
  8. 08Usage
  9. 09Examples
    • Inline
  10. 10API Reference
    • ContextActions
    • ContextActionsTrigger
    • ContextActionsContent
    • ContextActionsLabel
    • ContextActionsItem
    • ContextActionsSeparator
  11. 11Accessibility
  12. 12Notes
from
"@/components/patterns/context-actions"
className
=
"flex min-h-svh items-center justify-center p-4"
>
<ContextActions>
<ContextActionsTrigger className="flex h-40 w-72 items-center justify-center rounded-2xl border border-dashed text-sm text-muted-foreground">
Right click or long press
</ContextActionsTrigger>
<ContextActionsContent>
<ContextActionsLabel>Photo.jpg</ContextActionsLabel>
<ContextActionsItem>Edit</ContextActionsItem>
<ContextActionsItem>Duplicate</ContextActionsItem>
<ContextActionsItem>Share</ContextActionsItem>
<ContextActionsSeparator />
<ContextActionsItem variant="destructive">Delete</ContextActionsItem>
</ContextActionsContent>
</ContextActions>
</div>
>
$ pnpm dlx @esuiss/ui@latest add context-actions --platform kotlin

The CLI also adds what it builds on: Alert Sheet.

Manual

  1. Add the pieces it builds on: Alert Sheet.

  2. Copy the source into components/patterns/context-actions.tsx:

uniwind/components/patterns/context-actions.tsx
import * as React from "react"
import { Pressable } from "react-native"
import {
  AlertSheet,
  AlertSheetAction,
  AlertSheetCancel,
  AlertSheetContent,
  AlertSheetGroup,
  AlertSheetHeader,
  AlertSheetTitle,
} from "@/components/ui/alert-sheet"

const LONG_PRESS_DELAY = 500

type ContextActionsContextProps = {
  setOpen: (open: boolean) => void
  1. Update the import paths to match your project.
  1. Add the pieces it builds on: Alert Sheet.

  2. Copy the source into components/patterns/context-actions.tsx:

nativewind/components/patterns/context-actions.tsx
import * as React from "react"
import { Pressable } from "react-native"
import {
  AlertSheet,
  AlertSheetAction,
  AlertSheetCancel,
  AlertSheetContent,
  AlertSheetGroup,
  AlertSheetHeader,
  AlertSheetTitle,
} from "@/components/ui/alert-sheet"

const LONG_PRESS_DELAY = 500

type ContextActionsContextProps = {
  setOpen: (open: boolean) => void
  1. Update the import paths to match your project.
  1. Add the pieces it builds on: Alert Sheet.

  2. Copy the source into components/patterns/context-actions.tsx:

stylesheet/components/patterns/context-actions.tsx
import * as React from "react"
import { Pressable, type StyleProp, type ViewStyle } from "react-native"
import {
  AlertSheet,
  AlertSheetAction,
  AlertSheetCancel,
  AlertSheetContent,
  AlertSheetGroup,
  AlertSheetHeader,
  AlertSheetTitle,
} from "@/components/ui/alert-sheet"

const LONG_PRESS_DELAY = 500

type ContextActionsContextProps = {
  setOpen: (open: boolean) => void
  1. Update the import paths to match your project.
  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 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(0x2997FF))
  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(0xA1A1A6))
  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/Patterns/ContextActions.swift
import SwiftUI

public struct ContextActions<Label: View, Content: View>: View {
  let dismissible: Bool
  let cancelLabel: LocalizedStringKey
  let onOpenChange: ((Bool) -> Void)?
  let content: () -> Content
  let label: Label

  @State private var open = false
  @State private var lifts = 0
  @CompactLayout private var compact

  public init(
    dismissible: Bool = true,
    cancelLabel: LocalizedStringKey = "Cancel",
swift/Components/AlertSheet.swift
import SwiftUI

extension View {
  public func alertSheet<Content: View>(
    isPresented: Binding<Bool>,
    dismissible: Bool = true,
    @ViewBuilder content: @escaping () -> Content
  ) -> some View {
    modifier(
      CoverPresenter(
        isPresented: isPresented,
        enter: .timingCurve(0.32, 0.72, 0, 1, duration: 0.3),
        exit: .timingCurve(0.32, 0.72, 0, 1, duration: 0.25)
      ) { visible in
        AlertSheetStage(visible: visible, dismissible: dismissible, content: content)
      }
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, 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: 44
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/ContextMenu.swift
import SwiftUI

public typealias ContextMenuItem<Label: View> = DropdownMenuItem<Label>
public typealias ContextMenuCheckboxItem<Label: View> = DropdownMenuCheckboxItem<Label>
public typealias ContextMenuRadioGroup<Content: View> = DropdownMenuRadioGroup<Content>
public typealias ContextMenuRadioItem<Label: View> = DropdownMenuRadioItem<Label>
public typealias ContextMenuLabel = DropdownMenuLabel
public typealias ContextMenuGroup<Content: View> = DropdownMenuGroup<Content>
public typealias ContextMenuSeparator = DropdownMenuSeparator
public typealias ContextMenuSub<Label: View, Content: View> = DropdownMenuSub<Label, Content>

extension View {
  public func contextMenu<Items: View, Preview: View>(
    @ViewBuilder items: () -> Items,
    @ViewBuilder preview: () -> Preview,
    previewRadius: CGFloat
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/DropdownMenu.swift
import PhosphorSwift
import SwiftUI

enum MenuPresentation: Sendable {
  case system, popup
}

extension EnvironmentValues {
  @Entry var menuPresentation: MenuPresentation = .system
  @Entry var menuRadio = MenuRadioContext()
}

struct MenuRadioContext: @unchecked Sendable {
  var selected: AnyHashable?
  var select: @MainActor @Sendable (AnyHashable) -> Void = { _ in }
}
swift/Components/Field.swift
import 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 {
swift/Components/Haptics.swift
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>(
swift/Components/Overlay.swift
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()
  }
}
swift/Components/Select.swift
import PhosphorSwift
import SwiftUI

struct SelectContext: @unchecked Sendable {
  var selected: AnyHashable?
  var registering = false
  var select: @MainActor @Sendable (AnyHashable) -> Void = { _ in }
}

extension EnvironmentValues {
  @Entry var select = SelectContext()
}

struct SelectLabelsKey: PreferenceKey {
  static var defaultValue: [AnyHashable: Text] { [:] }
swift/Components/Separator.swift
import SwiftUI

public struct Separator: View {
  let orientation: Axis

  public init(_ orientation: Axis = .horizontal) {
    self.orientation = orientation
  }

  public var body: some View {
    Rectangle()
      .fill(EsuissColor.border)
      .frame(width: orientation == .vertical ? 1 : nil, height: orientation == .horizontal ? 1 : nil)
      .frame(maxWidth: orientation == .horizontal ? .infinity : nil, maxHeight: orientation == .vertical ? .infinity : nil)
      .accessibilityHidden(true)
  }
swift/Components/Sheet.swift
import SwiftUI

extension View {
  public func sheet<Content: View>(
    isPresented: Binding<Bool>,
    side: Edge,
    @ViewBuilder content: @escaping () -> Content
  ) -> some View {
    modifier(
      CoverPresenter(
        isPresented: isPresented,
        enter: .easeOut(duration: 0.4),
        exit: .easeIn(duration: 0.3)
      ) { visible in
        SideSheetStage(side: side, visible: visible, content: content)
      }
swift/Components/TextVariant.swift
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
    }
  }
swift/Patterns/ActionList.swift
import SwiftUI

enum ActionListMode: Sendable {
  case sheet, menu
}

extension EnvironmentValues {
  @Entry var actionListMode: ActionListMode = .menu
}

struct ActionSheetBody<Content: View>: View {
  let cancelLabel: LocalizedStringKey
  @ViewBuilder let content: () -> Content

  var body: some View {
    AlertSheetContent {
swift/Patterns/Adaptive.swift
import SwiftUI

extension EnvironmentValues {
  @Entry var patternCompact: Bool? = nil
}

@propertyWrapper
struct CompactLayout: DynamicProperty {
  @Environment(\.patternCompact) private var forced
  @Environment(\.horizontalSizeClass) private var sizeClass

  init() {}

  var wrappedValue: Bool {
    forced ?? (sizeClass != .regular)
  }
  1. Add the files to your app target.
  1. Set minSdk to 24 or higher and add the dependencies:
build.gradle.kts
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 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.DpOffset
kotlin/theme/Tokens.kt
package 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 background: Color,
    val foreground: Color,
    val card: Color,
    val cardForeground: Color,
    val popover: Color,
    val popoverForeground: Color,
    val primary: Color,
    val primaryForeground: Color,
  1. Copy the source and every file it uses:
kotlin/patterns/ContextActions.kt
package com.esuiss.ui.patterns

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.semantics.onLongClick
kotlin/components/AlertSheet.kt
package com.esuiss.ui.components

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
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.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
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/Checkbox.kt
package 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.draw.alpha
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/DropdownMenu.kt
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.height
kotlin/components/Field.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.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.BasicText
kotlin/components/FormSupport.kt
package 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.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
kotlin/components/Haptics.kt
package 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)
}
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/Label.kt
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.draw.alpha
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
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
kotlin/components/Separator.kt
package 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(
kotlin/patterns/ActionList.kt
package com.esuiss.ui.patterns

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier
import com.esuiss.ui.components.AlertSheet
import com.esuiss.ui.components.AlertSheetActionVariant
import com.esuiss.ui.components.AlertSheetCancel
import com.esuiss.ui.components.AlertSheetGroup
import com.esuiss.ui.components.AlertSheetHeader
import com.esuiss.ui.components.AlertSheetTitle
import com.esuiss.ui.components.MenuItemVariant

@Immutable
internal class SheetMenuState(
    val open: Boolean,
  1. Update the com.esuiss.ui package names to match your project.

Usage

import { ContextActions, ContextActionsTrigger, ContextActionsContent, ContextActionsLabel, ContextActionsItem, ContextActionsSeparator } from "@/components/patterns/context-actions"
<ContextActions>
  <ContextActionsTrigger
    accessibilityLabel="Photo"
    className="h-40 items-center justify-center gap-2 rounded-2xl bg-muted active:opacity-80"
  >
    <Icon as={ImageIcon} className="size-8 text-muted-foreground" />
    <Text className="text-sm text-muted-foreground">Long press</Text>
  </ContextActionsTrigger>
  <ContextActionsContent>
    <ContextActionsLabel>Photo</ContextActionsLabel>
    <ContextActionsItem>Copy</ContextActionsItem>
    <ContextActionsItem>Share</ContextActionsItem>
    <ContextActionsItem variant="destructive">Delete</ContextActionsItem>
  </ContextActionsContent>
</ContextActions>

Wrap the target in ContextActionsTrigger and list ContextActionsItems in ContextActionsContent. Add a ContextActionsLabel first to show a title.

The open state is managed internally; use onOpenChange to react to it. ContextActionsTrigger accepts every Pressable prop, so onPress still works for a normal tap, and your own onLongPress runs before the sheet opens. Change the hold time with delayLongPress.

Examples

Inline

A small message bubble as the trigger, with a custom cancelLabel.

iOS
Context Actions (inline) on iOS in light modeContext Actions (inline) on iOS in dark mode
import { View } from "react-native"
import { ContextActions, ContextActionsContent, ContextActionsItem, ContextActionsTrigger } from "@/components/patterns/context-actions"
import { Text } from "@/components/ui/text"

export function ContextActionsInlineExample() {
  return (
    <View className="items-start">
      <ContextActions>
        <ContextActionsTrigger className="rounded-lg bg-secondary px-3 py-2">
          <Text>Hold this message</Text>
        </ContextActionsTrigger>
        <ContextActionsContent cancelLabel="Close">
          <ContextActionsItem>Reply</ContextActionsItem>
          <ContextActionsItem>Forward</ContextActionsItem>
        </ContextActionsContent>
      </ContextActions>
    </View>
  )
}
import EsuissUI
import SwiftUI

struct ContextActionsInlineExample: View {
  var body: some View {
    ContextActions(cancelLabel: "Close") {
      ContextActionsItem("Reply") {}
      ContextActionsItem("Forward") {}
    } label: {
      Text("Hold this message")
        .textStyle(.base)
        .foregroundStyle(EsuissColor.foreground)
        .padding(.horizontal, 12)
        .padding(.vertical, 8)
        .background(EsuissColor.secondary, in: RoundedRectangle(cornerRadius: Radius.lg, style: .continuous))
    }
  }
}
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Text
import com.esuiss.ui.patterns.ContextActions
import com.esuiss.ui.patterns.ContextActionsContent
import com.esuiss.ui.patterns.ContextActionsItem
import com.esuiss.ui.patterns.ContextActionsTrigger
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius

@Composable
fun ContextActionsInline() {
    val shape = RoundedCornerShape(Radius.lg)
    Column {
        ContextActions {
            ContextActionsTrigger(
                modifier = Modifier
                    .clip(shape)
                    .background(EsuissTheme.colors.secondary, shape)
                    .padding(horizontal = 12.dp, vertical = 8.dp),
            ) {
                Text("Hold this message")
            }
            ContextActionsContent(cancelLabel = "Close") {
                ContextActionsItem("Reply", onClick = {})
                ContextActionsItem("Forward", onClick = {})
            }
        }
    }
}

API Reference

01

ContextActions

The root that owns the open state.

PropTypeDefaultDescription
onOpenChange(open: boolean) => void-Called when the sheet opens or closes.
dismissiblebooleantrueWhen false, the sheet ignores outside presses. Defaults to true.
childrenReact.ReactNode-
02

ContextActionsTrigger

A Pressable that opens the sheet on long press.

Also accepts the props of React.ComponentProps<typeof Pressable>.

03

ContextActionsContent

The sheet with the grouped items and a Cancel button.

PropTypeDefaultDescription
cancelLabelstring"Cancel"Text of the Cancel button. Defaults to Cancel.

Also accepts the props of React.ComponentProps<typeof AlertSheetContent>.

04

ContextActionsLabel

A title shown at the top of the group.

Also accepts the props of React.ComponentProps<typeof AlertSheetTitle>.

05

ContextActionsItem

An actionable entry, rendered as an AlertSheetAction.

Also accepts the props of React.ComponentProps<typeof AlertSheetAction>.

06

ContextActionsSeparator

Kept for API parity; renders nothing.

PropTypeDefaultDescription
classNamestring-

Accessibility

  • The trigger has the hint "Long press for actions".
  • It adds longpress and showActions ("Show actions") accessibility actions, so screen reader users can open the sheet without holding.
  • Your own accessibilityActions and onAccessibilityAction are kept.

Notes

  • Item text uses text-primary, or text-destructive for the destructive variant.
  • On iOS the sheet renders in a full-window overlay so it appears above native screens.
iOS
Context Actions on iOS in light modeContext Actions on iOS in dark mode
import { ImageIcon } from "phosphor-react-native"
import { ContextActions, ContextActionsContent, ContextActionsItem, ContextActionsLabel, ContextActionsTrigger } from "@/components/patterns/context-actions"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"

export function ContextActionsExample() {
  return (
    <ContextActions>
      <ContextActionsTrigger
        accessibilityLabel="Photo"
        className="h-40 items-center justify-center gap-2 rounded-2xl bg-muted active:opacity-80"
      >
        <Icon as={ImageIcon} className="size-8 text-muted-foreground" />
        <Text className="text-sm text-muted-foreground">Long press</Text>
      </ContextActionsTrigger>
      <ContextActionsContent>
        <ContextActionsLabel>Photo</ContextActionsLabel>
        <ContextActionsItem>Copy</ContextActionsItem>
        <ContextActionsItem>Share</ContextActionsItem>
        <ContextActionsItem variant="destructive">Delete</ContextActionsItem>
      </ContextActionsContent>
    </ContextActions>
  )
}
import EsuissUI
import PhosphorSwift
import SwiftUI

struct ContextActionsExample: View {
  var body: some View {
    ContextActions {
      ContextActionsLabel("Photo")
      ContextActionsItem("Copy") {}
      ContextActionsItem("Share") {}
      ContextActionsItem("Delete", variant: .destructive) {}
    } label: {
      VStack(spacing: 8) {
        Ph.image.regular
          .frame(width: 32, height: 32)
        Text("Long press")
          .textStyle(.sm)
      }
      .foregroundStyle(EsuissColor.mutedForeground)
      .frame(maxWidth: .infinity)
      .frame(height: 160)
      .background(EsuissColor.muted, in: RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous))
      .accessibilityElement(children: .ignore)
      .accessibilityLabel(Text("Photo"))
    }
  }
}
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.Image
import com.esuiss.ui.components.Icon
import com.esuiss.ui.components.MenuItemVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.patterns.ContextActions
import com.esuiss.ui.patterns.ContextActionsContent
import com.esuiss.ui.patterns.ContextActionsItem
import com.esuiss.ui.patterns.ContextActionsLabel
import com.esuiss.ui.patterns.ContextActionsTrigger
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography

@Composable
fun ContextActionsDefault() {
    val colors = EsuissTheme.colors
    val shape = RoundedCornerShape(Radius.xl2)
    ContextActions {
        ContextActionsTrigger(
            modifier = Modifier
                .fillMaxWidth()
                .height(160.dp)
                .clip(shape)
                .background(colors.muted, shape),
            label = "Photo",
        ) {
            Column(
                modifier = Modifier.align(Alignment.Center),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.spacedBy(8.dp),
            ) {
                Icon(PhosphorIcons.Regular.Image, contentDescription = null, size = 32.dp, tint = colors.mutedForeground)
                Text("Long press", style = Typography.sm.copy(color = colors.mutedForeground))
            }
        }
        ContextActionsContent {
            ContextActionsLabel("Photo")
            ContextActionsItem("Copy", onClick = {})
            ContextActionsItem("Share", onClick = {})
            ContextActionsItem("Delete", onClick = {}, variant = MenuItemVariant.Destructive)
        }
    }
}
components/patterns/context-actions.tsx
"use client"

import { mergeProps } from "@base-ui/react/merge-props"
import * as React from "react"
import {
  AlertSheet,
  AlertSheetAction,
  AlertSheetCancel,
  AlertSheetContent,
  AlertSheetGroup,
  AlertSheetHeader,
  AlertSheetTitle,
} from "@/components/ui/alert-sheet"
import {
  ContextMenu,
  ContextMenuContent,
import {
  CopyIcon,
  PencilSimpleIcon,
  ShareIcon,
  TrashIcon,
} from "@phosphor-icons/react"
import {
  ContextActions,
  ContextActionsContent,
  ContextActionsItem,
  ContextActionsSeparator,
  ContextActionsTrigger,
} from "@/components/patterns/context-actions"

export default function ContextActionsWithIcons() {
  return (
    <div className="flex min-h-svh items-center justify-center p-4">
      <ContextActions>
        <ContextActionsTrigger className="flex h-40 w-72 items-center justify-center rounded-2xl border border-dashed text-sm text-muted-foreground">
          Right click or long press
        </ContextActionsTrigger>
        <ContextActionsContent>
          <ContextActionsItem>
            <PencilSimpleIcon />
            Edit
          </ContextActionsItem>
          <ContextActionsItem>
            <CopyIcon />
            Duplicate
          </ContextActionsItem>
          <ContextActionsItem>
            <ShareIcon />
            Share
          </ContextActionsItem>
          <ContextActionsSeparator />
          <ContextActionsItem variant="destructive">
            <TrashIcon />
            Delete
          </ContextActionsItem>
        </ContextActionsContent>
      </ContextActions>
    </div>
  )
}
import {
  ContextActions,
  ContextActionsContent,
  ContextActionsItem,
  ContextActionsLabel,
  ContextActionsSeparator,
  ContextActionsTrigger,
} from "@/components/patterns/context-actions"

export default function ContextActionsNotDismissible() {
  return (
    <div className="flex min-h-svh items-center justify-center p-4">
      <ContextActions dismissible={false}>
        <ContextActionsTrigger className="flex h-40 w-72 items-center justify-center rounded-2xl border border-dashed text-sm text-muted-foreground">
          Right click or long press
        </ContextActionsTrigger>
        <ContextActionsContent>
          <ContextActionsLabel>Photo.jpg</ContextActionsLabel>
          <ContextActionsItem>Edit</ContextActionsItem>
          <ContextActionsItem>Duplicate</ContextActionsItem>
          <ContextActionsItem>Share</ContextActionsItem>
          <ContextActionsSeparator />
          <ContextActionsItem variant="destructive">Delete</ContextActionsItem>
        </ContextActionsContent>
      </ContextActions>
    </div>
  )
}