import * as React from "react"; import { createPortal } from "react-dom"; import { sheetPortalTarget, useEscape } from "./Sheet"; /** * Action sheet - the iOS pattern for a short set of choices the user asked for. * * Two groups, exactly as Apple describes them: the choices in one rounded * card, "Cancel" alone in a second one below it with a gap between. The gap is * not decoration - it is what makes Cancel unmistakably the way out rather * than one more option in the list. * * Deliberately identical in geometry to `.sheet` in the panel's * audi-dashboard.css, which already implemented this pattern: 10px side * margins, 16px corners, 52px minimum row height, one hairline between rows, * opaque surface. Two codebases, one look. * * Use `Sheet` instead when the content is a form rather than a list of * choices. */ export interface ActionSheetAktion { label: React.ReactNode; onClick: () => void; /** Red, for anything that removes or overwrites something. */ destructive?: boolean; disabled?: boolean; } export interface ActionSheetProps { open: boolean; onClose: () => void; /** Optional heading above the choices. */ title?: React.ReactNode; /** One explanatory line under the title. */ description?: React.ReactNode; actions: ActionSheetAktion[]; /** Label of the separated bottom button. Pass null to leave it out. */ cancelLabel?: string | null; /** Rendered between the heading and the choices - an error line, a hint. */ children?: React.ReactNode; className?: string; portalTarget?: Element; } export function ActionSheet({ open, onClose, title, description, actions, cancelLabel = "Abbrechen", children, className, portalTarget, }: ActionSheetProps) { useEscape(open, onClose); const target = sheetPortalTarget(portalTarget); if (!open || !target) return null; const classes = ["ads-aktionsblatt"]; if (className) classes.push(className); return createPortal( <>
{(title || description) && (
{title && {title}} {description && {description}}
)} {children &&
{children}
} {actions.map((aktion, i) => ( ))}
{cancelLabel !== null && ( )}
, target, ); }