Command palette

@yasinsensoy/web

Web · Components

Popover

A small panel opened from a button: quick settings, share options, a filter, an info card and so on.

7 exports

Live example

Preview

Code

import { Popover, Button, TextField } from "@yasinsensoy/web";

<Popover
  trigger={<Button variant="outline">Boyutlar</Button>}
  title="Dimensions"
>
  {({ close }) => (
    <>
      <TextField label="Width" defaultValue="100%" />
      <Button size="sm" onClick={close}>Apply</Button>
    </>
  )}
</Popover>

Events

  1. Events appear here when you interact with the preview.

Import

import { Popconfirm, Popover } from "@yasinsensoy/web";

Popover

componentClient component

A small panel opened from a button: quick settings, share options, a filter, an info card and so on. The trigger is given with trigger, the content with children.

  • Native Popover API: opens in the top layer (no z-index), closes on an outside click and with Esc, and focus returns to the trigger on close. The trigger works even before JavaScript loads.
  • Sits next to the trigger with CSS anchor positioning and flips to the other side if it doesn't fit on screen; no JavaScript position math on scroll.
  • Mobile: On small screens it becomes a bottom sheet; it can be closed by pulling down and with the back button.
Popover({ trigger, children, title, description, label, side, open, defaultOpen, onOpenChange, mobileSheet, closeOnBackButton, className, classNames, effect, }: PopoverProps): JSX.Element

Examples

<Popover trigger={<Button variant="outline">Dimensions</Button>} title="Dimensions">
  <TextField label="Width" defaultValue="100%" />
</Popover>

<Popover trigger={<Button>Filter</Button>} className="w-80">
  {({ close }) => <Button onClick={() => { apply(); close(); }}>Apply</Button>}
</Popover>

Popconfirm

componentClient component

A small confirmation bubble attached to a button: "Delete? [Cancel] [Delete]". Lighter than the full-screen confirm window; for in-place confirmations like deleting a table row or removing from a list.

  • The bubble opens next to the element (CSS anchor positioning) and flips to the other side if it doesn't fit on screen. Esc and an outside click cancel; focus returns to the element on close.
  • If onConfirm returns a Promise, the confirm button shows loading and the bubble closes when done; false or an error keeps it open.
  • With tone="danger" the confirm button is red and focus starts on "Cancel".
  • Screen readers announce the bubble as an alertdialog with the question.
  • With disabled asking is skipped (the element's own onClick runs).
Popconfirm(props: PopconfirmProps): JSX.Element

Examples

<Popconfirm title="Delete this record?" description="This action cannot be undone."
  tone="danger" confirmLabel="Delete" onConfirm={() => remove(record.id)}>
  <IconButton icon="trash" label="Delete" variant="ghost" />
</Popconfirm>

<Popconfirm title="Discard changes?" disabled={!dirty} onConfirm={discard}>
  <Button variant="outline" onClick={discard}>Discard</Button>
</Popconfirm>

Classes that can be passed to the inner parts of Popconfirm.

NameTypeDescription
title?stringTitle.
description?stringDescription.
actions?stringButton row.

Props of the Popconfirm component.

NameTypeDefaultDescription
childrenReactElementElement asking for confirmation, usually a Button. On click the action doesn't run immediately; a question bubble opens next to it first.
titleReactNodeThe question (e.g. "Delete this record?").
description?ReactNodeShort description under the question (e.g. "This action cannot be undone.").
icon?IconProp | falseIcon next to the title: a name or an element. If omitted, the status icon of tone; false removes the icon.
tone?Tone"primary"Color of the confirm button. "danger" for irreversible actions such as deleting: in that case focus goes to the "Cancel" button when the bubble opens (so an accidental Enter doesn't delete).
confirmLabel?ReactNode"Onayla"` (`messages.confirm`)Text of the confirm button.
cancelLabel?ReactNode"İptal"` (`messages.cancel`)Text of the cancel button.
showCancel?booleantrueShow the "Cancel" button?
onConfirm?() => unknownRuns on confirm. If it returns a Promise, the confirm button shows loading and the bubble stays open until it settles; if it returns false or throws, the bubble stays open (the error goes to onError).
onCancel?() => voidWhen cancelled (Cancel, Esc or an outside click).
onError?(error: unknown) => voidCalled when onConfirm throws.
disabled?booleanfalseSkip asking: if true, the element works normally with its own onClick and the bubble doesn't open (e.g. when there are no unsaved changes).
side?Placement"top"Position of the bubble relative to the element. See Placement.
open?booleanWhether it is open when controlled.
defaultOpen?booleanfalseIs it initially open when uncontrolled?
onOpenChange?(open: boolean) => voidCalled when it opens or closes.
mobileSheet?booleanfalseTurn into a bottom sheet on small screens? Since the bubble is small, by default it opens next to the element on mobile too.
className?stringClasses added to the bubble (e.g. w-80 for width).
classNames?PopconfirmClassNamesClasses added to the inner parts.

Values received when the Popover content is given as a function.

NameTypeDescription
close() => voidCloses the panel (e.g. on an "Apply" button).

Classes that can be passed to the inner parts of Popover.

NameTypeDescription
title?stringTitle.
description?stringDescription.

PopoverProps

interface

Props of the Popover component.

NameTypeDefaultDescription
triggerReactElementElement that toggles the panel, usually a Button.
children?ReactNode | ((context: PopoverRenderContext) => ReactNode)Content of the panel. If a function is given it receives { close }, so the panel can be closed from the content.
title?ReactNodeTitle at the top of the panel; screen readers announce the panel with this name.
description?ReactNodeDescription under the title.
label?stringScreen reader name; give it if there is no visible title.
side?Placement"auto"Position relative to the trigger: side and alignment (e.g. "top-right", "bottom-left", "right"). See Placement.
open?booleanWhether it is open when controlled.
defaultOpen?booleanfalseIs it initially open when uncontrolled?
onOpenChange?(open: boolean) => voidCalled with the new state when it opens or closes.
mobileSheet?booleantrueTurn into a bottom sheet on small screens (below 640 px)?
closeOnBackButton?booleantrueShould the back button close the open panel?
className?stringClasses added to the panel (e.g. w-80 for width).
classNames?PopoverClassNamesClasses added to the inner parts.
effect?EffectPropEffect or effects of the panel (e.g. "beam", ["border", "glow"]). If omitted, UIProvider appearance.defaults.popover.effect. See BuiltinEffect.