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

Popover

A glass bubble sized to its content, with a tail pointing at its source.

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

Basic

By default it goes above the source, else below, else beside, wherever it fits. arrowEdge names the bubble's edge with the tail, as in SwiftUI: top puts the bubble below the source. A tap outside or Escape dismisses it.

const about = useRef<HTMLSpanElement>(null);
const below = useRef<HTMLSpanElement>(null);
const [shown, setShown] = useState<"about" | "below" | null>(null);

<Button buttonStyle="glass" onClick={() => setShown("about")}>
  <span ref={about}>About</span>
</Button>
<Button buttonStyle="glass" onClick={() => setShown("below")}>
  <span ref={below}>Below</span>
</Button>

<Popover source={about} isPresented={shown === "about"} onDismiss={() => setShown(null)}>
  <div style={{ padding: 16, font: "400 17px/20.667px Inter", whiteSpace: "pre" }}>
    {"Sized to its content\nAt least 68 x 68"}
  </div>
</Popover>
<Popover source={below} arrowEdge="top" isPresented={shown === "below"} onDismiss={() => setShown(null)}>
  <div style={{ padding: 16, font: "400 17px/20.667px Inter", whiteSpace: "pre" }}>
    Hello from a popover
  </div>
</Popover>

On a phone

On a phone (and the Duo's outer screen) a popover keeps its bubble by default. With compactAdaptation="sheet" (or automatic) it shows its content in a large sheet instead. On an iPad window both are bubbles.

<Button buttonStyle="glass" onClick={() => setOpen(true)}>
  <span ref={source}>Details</span>
</Button>
<Popover source={source} compactAdaptation="sheet" isPresented={open} onDismiss={() => setOpen(false)}>
  <div style={{ padding: 16, font: "400 17px/20.667px Inter", whiteSpace: "pre" }}>
    A sheet on a phone, a bubble on an iPad
  </div>
</Popover>

Props

PropTypeDefaultDescription
childrenReactNode-Required. The content: measured unseen at its natural size, then shown in the bubble.
sourceRefObject<HTMLElement | null> | Frame-What it points at: an element, or a box in the window's coordinates.
arrowEdge"top" | "bottom" | "leading" | "trailing"-The bubble's edge with the tail, tried first. Unset: above, else below, else beside.
compactAdaptation"popover" | "none" | "sheet" | "automatic""popover"On a phone or the Duo's outer screen: sheet or automatic show the content in a large sheet; popover and none keep the bubble.
minTopnumber-The highest a bubble beside its source may go, in window px (one under a status bar).
isPresentedboolean-Required. Shown while true.
onDismiss() => void-Runs on a tap outside or Escape: set isPresented back to false.
glass{ frostSize?: number; tableSize?: number }-Fitting only: which measured sizes draw the glass.

Behaviour

The bubble is at least 68 x 68 and at most the window's room; it grows out of its tail. It portals to the root of its PresentationRoot, or document.body, takes focus when it opens (Tab stays inside) and gives it back when it closes. The demos sit in a PresentationRoot over their phone frame (see Alert). The glass targets Chromium.

SwiftUI

SwiftUI@adamexu/glass
.popover(isPresented:, arrowEdge:) { content }<Popover source isPresented onDismiss arrowEdge>
.presentationCompactAdaptation(.popover / .sheet)compactAdaptation="popover" / "sheet"