This browser is not supported. The glass needs a Chromium browser or Electron. Why

ConfirmationDialog

A glass bubble of actions with a tail pointing at what opened it: above it, else below, else beside.

import { ConfirmationDialog } from "@adamexu/glass";

From a button

source is what it points at: a ref to an element, or a box in the window. As in research's demo app, the ref goes on the button's label. The cancel action isn't drawn: Escape and a tap outside cancel. The title is hidden by default, as on iOS.

nothing chosen
const source = useRef<HTMLSpanElement>(null);
const [open, setOpen] = useState(false);

<Button buttonStyle="glass" onClick={() => setOpen(true)}>
  <span ref={source}>Share</span>
</Button>
<ConfirmationDialog
  title="Share This Album?"
  actions={[
    { title: "Share Link", action: () => setChoice("Share Link") },
    { title: "Invite People", action: () => setChoice("Invite People") },
    { title: "Stop Sharing", role: "destructive", action: () => setChoice("Stop Sharing") },
    { title: "Cancel", role: "cancel" },
  ]}
  source={source}
  isPresented={open}
  onDismiss={() => setOpen(false)}
/>

With a visible title and a message

titleVisibility="visible" draws the title over the message. The demos sit in a PresentationRoot over their phone frame (see Alert), so the bubble is placed in the frame.

nothing chosen
const source = useRef<HTMLSpanElement>(null);
const [open, setOpen] = useState(false);

<Button buttonStyle="glass" onClick={() => setOpen(true)}>
  <span ref={source}>Options</span>
</Button>
<ConfirmationDialog
  title="Draft 3"
  titleVisibility="visible"
  message="This draft hasn't been sent."
  actions={[
    { title: "Send Now", action: () => setChoice("Send Now") },
    { title: "Discard", role: "destructive", action: () => setChoice("Discard") },
    { title: "Cancel", role: "cancel" },
  ]}
  source={source}
  isPresented={open}
  onDismiss={() => setOpen(false)}
/>

Props

PropTypeDefaultDescription
titlestring-Required. Labels the dialog, drawn when visible.
titleVisibility"visible" | "hidden" | "automatic""automatic"automatic hides it, as iOS does.
messagestring-Text under the title.
actionsPresentationAction[]-Required. The cancel action isn't drawn: Escape and a tap outside cancel.
sourceRefObject<HTMLElement | null> | Frame-What it points at: an element, or a box in the window's coordinates.
isPresentedboolean-Required. Shown while true.
onDismiss() => void-Runs after a button's action, a tap outside or Escape: set isPresented back to false.
glass{ frostSize?: number; tableSize?: number }-Fitting only: which measured sizes draw the glass.

PresentationAction

PropTypeDefaultDescription
titlestring-The button's title.
role"destructive" | "cancel"-destructive draws it red; cancel is not drawn, and its action runs on Escape.
action() => void-Runs when it is chosen, before onDismiss.

Frame

PropTypeDefaultDescription
{ x, y, width, height }number-A box in the presentation window, in CSS px from its top left.

Behaviour

The bubble is a role="dialog". It portals to the root of its PresentationRoot, or document.body, takes focus when it opens (Tab stays inside), gives it back when it closes, and closes on Escape or a tap outside. On a phone it grows from its top center; on an iPad from the side facing the source when there isn't much room below. The glass targets Chromium.

SwiftUI

SwiftUI@adamexu/glass
.confirmationDialog(title, isPresented:, titleVisibility:) { } message: { }<ConfirmationDialog title titleVisibility message actions isPresented onDismiss>
Button(title, role: .destructive / .cancel) { } in a presentation{ title, role: "destructive" / "cancel", action }
the view it is attached tosource={ref} (an element, or a Frame)