Zum Inhalt springen

UI: Button

Als Markdown ansehen

Button und IconButton in den vier Varianten des Desktops. Importiere die Token-Datei einmal (@pithyx/ui/tokens.css) und umschließe die App mit UiProvider; siehe @pithyx/ui.

Beim Build aus den TSDoc-Kommentaren von @pithyx/ui 1.0.0-rc.9 erzeugt; der Text unter den Überschriften ist der Kommentar im Quelltext und bleibt Englisch.

The props of Button: React Aria’s button props plus the look.

  • Omit<AriaButtonProps, "className" | "children">
optional variant?: ButtonVariant;

How much the button stands out; secondary when left out.

optional size?: "md" | "sm";

sm for dense rows and toolbars; md when left out.

optional className?: string;

Extra class names, added after the button’s own.

optional children?: ReactNode;

The label, an icon or both.


The props of IconButton.

optional variant?: ButtonVariant;

How much the button stands out; secondary when left out.

ButtonProps.variant

optional size?: "md" | "sm";

sm for dense rows and toolbars; md when left out.

Omit.size;
optional className?: string;

Extra class names, added after the button’s own.

ButtonProps.className

optional children?: ReactNode;

The label, an icon or both.

ButtonProps.children

label: string;

Accessible name, also shown as tooltip.

optional tooltip?: boolean;

Hides the tooltip where the label is already visible nearby.

type ButtonVariant = 'primary' | 'secondary' | 'quiet' | 'danger';

How much a button stands out: primary for the main action, danger for a destructive one.

function Button(props): Element;

A button in the desktop’s look. Use onPress instead of onClick, so keyboard, touch and screen readers act alike, and isPending for an action that runs.

Parameter Typ Beschreibung
props ButtonProps React Aria’s button props plus variant and size.

Element

The button element.

<Button variant="primary" onPress={save}>
Save
</Button>

function IconButton(props): Element;

A button that shows only an icon; its label is announced and shown as a tooltip. quiet when no variant is set.

Parameter Typ Beschreibung
props IconButtonProps The props of Button plus label and tooltip.

Element

The button, wrapped in a tooltip trigger unless tooltip is false.

<IconButton label="Delete" onPress={remove}>
<IconTrash size={18} />
</IconButton>