Command palette

@yasinsensoy/native

React Native · Components

Button

Button.

10 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { Button } from "@yasinsensoy/native";

<Button effect="ripple" tooltip="Saves the changes" onClick={async () => await kaydet()}>Save</Button>

Events

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

Press effects (click or Space/Enter)

Corner shape

Style × color

primary
neutral
danger
success
warning

Sizes and IconButton

Tooltip: custom text on a disabled button and an IconButton

Import

import { Button, IconButton, ButtonGroup } from "@yasinsensoy/native";

Button

component

Button. Same API as web's Button: variant, tone, size, shape, icon, loading, effect, tooltip, and an automatic loading state with an onPress that returns a Promise. Looks the same on Android and iOS (shadows and gradients via RN's platform-independent boxShadow and backgroundImage styles, effects drawn on the native driver). The touch target is at least 44×44 pixels.

  • For app-wide variant, color, size, shape and effect use UIProvider appearance.defaults.button; for your own variants appearance.variants.button (the style's color field is the text and icon color).
  • Inside a ButtonGroup, missing variant, tone, size and disabled come from the group.
  • For icon-only buttons use IconButton.
Button(props: ButtonProps): ReactNode

Examples

<Button onPress={save}>Save</Button>
<Button variant="outline" tone="danger" icon="trash">Delete</Button>
<Button variant="gradient" shape="pill" effect="ripple">Get started</Button>
<Button tooltip="Saved as a draft" variant="ghost">Draft</Button>

IconButton

component

Square icon-only button (web's IconButton). Its height matches text buttons via size; the variant defaults to ghost (the group's variant inside a ButtonGroup). Its name shows as a tooltip on press and hold.

IconButton({ label, tooltip, variant, ...props }: IconButtonProps): JSX.Element

Examples

<IconButton icon="close" label="Close" onPress={close} />
<IconButton icon="trash" label="Delete" tone="danger" variant="soft" />

ButtonGroup

component

Brings related buttons together as a single piece (same API as web's ButtonGroup): toolbars, split buttons (Save + ▾), view switchers, alignment and formatting buttons.

  • Two ways to use: put your own Button/IconButton/Menu elements in children, or pass an items array and let the group render the buttons. Selection mode, split buttons and the "More" menu work with items.
  • Attached (default): inner corners are removed, borders overlap, and solid buttons get a thin line between them.
  • Selection mode: selection="single" is single-select, "multiple" multi-select; pressed buttons carry aria-pressed and look highlighted.
  • Phone: with overflow="menu" buttons that do not fit move into a trailing ⋯ menu; recalculated when the width changes (rotation, split screen); measurements are cached so it does not flicker.
ButtonGroup(props: ButtonGroupProps<V>): JSX.Element

Examples

<ButtonGroup variant="outline" label="Navigation">
  <IconButton icon="chevronLeft" label="Previous" />
  <Button>Today</Button>
  <IconButton icon="chevronRight" label="Next" />
</ButtonGroup>

<ButtonGroup
  variant="outline"
  label="Alignment"
  selection="single"
  required
  value={align}
  onValueChange={setAlign}
  items={[
    { value: "left", label: "Left", icon: "alignLeft", iconOnly: true },
    { value: "center", label: "Center", icon: "alignCenter", iconOnly: true },
  ]}
/>

Button variant (same names and look as web's ButtonVariant).

  • solid: filled; the primary action on the screen.
  • soft: tinted background; a secondary but colored action.
  • outline: bordered.
  • ghost: no background; toolbars and lists.
  • link: text like a link.
  • gradient: a filled button with a subtle gradient from the tone color.
  • elevated: shadowed, raised from the surface.
  • dashed: dashed border; placeholder actions like "add".
type ButtonVariant = "solid" | "soft" | "outline" | "ghost" | "link" | "gradient" | "elevated" | "dashed"

Corner shape: rounded theme radius, pill fully round, sharp square corners.

type ButtonShape = "rounded" | "pill" | "sharp"

ButtonProps

interface

Props of Button.

Extends: Omit<PressableProps, "children" | "style" | "onPress">

NameTypeDefaultDescription
ref?Ref<ViewRef>Ref of the underlying native element.
children?ReactNodeButton text or content.
variant?ButtonVariant | (string & {})"solid"Variant: one of the built-in variants (ButtonVariant) or a name added via UIProvider appearance.variants.button. If omitted, the ButtonGroup's variant is used, then appearance.defaults.button.
tone?Tone"primary"Color: the meaning of the action.
size?Size"md"Height: sm 32, md 40, lg 48 pixels.
shape?ButtonShape"rounded"` (or `appearance.defaults.button.shape`)Corner shape.
effect?EffectPropEffect or effects: on press scale, ripple, pulse, bounce; while pressed lift, border, beam, glow, tilt, shine; or a custom effect added via appearance.effects. Can be combined as an array (["ripple", "glow"]). Defaults to appearance.defaults.button.effect, otherwise scale (no effect for the link variant). "none" turns all off. See BuiltinEffect.
tooltip?TooltipPropTooltip shown on press and hold: text, content or settings ({ content, side, touch }). Works while the button is disabled too; useful to explain why it cannot be pressed. See TooltipProp.
icon?IconPropIcon before the text. See IconProp.
iconEnd?IconPropIcon after the text.
loading?booleanLoading: a spinner instead of the icon, cannot be pressed.
block?booleanFills its row.
onPress?(event: GestureResponderEvent) => unknownCalled on press. If it returns a Promise the button shows loading automatically until it settles (same behavior as web's onClick).
accessibilityLabel?stringScreen reader label; should be considered required only on icon-only buttons.
style?StyleProp<ViewStyle>Container style.

Props of IconButton.

Extends: Omit<Omit<PressableProps, "children" | "style" | "onPress">, "children" | "iconEnd" | "block" | "accessibilityLabel">

NameTypeDefaultDescription
iconIconPropIcon shown on the button: a name ("trash") or an element.
labelstringName of the button. Screen readers read it; shown as a tooltip on press and hold. Required, because an icon alone is not a name.
tooltip?TooltipPropTooltip. Defaults to label; use it to give a different text or settings, turn it off with false.
ref?Ref<ViewRef>Ref of the underlying native element.
variant?ButtonVariant | (string & {})"solid"Variant: one of the built-in variants (ButtonVariant) or a name added via UIProvider appearance.variants.button. If omitted, the ButtonGroup's variant is used, then appearance.defaults.button.
tone?Tone"primary"Color: the meaning of the action.
size?Size"md"Height: sm 32, md 40, lg 48 pixels.
shape?ButtonShape"rounded"` (or `appearance.defaults.button.shape`)Corner shape.
effect?EffectPropEffect or effects: on press scale, ripple, pulse, bounce; while pressed lift, border, beam, glow, tilt, shine; or a custom effect added via appearance.effects. Can be combined as an array (["ripple", "glow"]). Defaults to appearance.defaults.button.effect, otherwise scale (no effect for the link variant). "none" turns all off. See BuiltinEffect.
loading?booleanLoading: a spinner instead of the icon, cannot be pressed.
onPress?(event: GestureResponderEvent) => unknownCalled on press. If it returns a Promise the button shows loading automatically until it settles (same behavior as web's onClick).
style?StyleProp<ViewStyle>Container style.

A button in the ButtonGroup items array (same fields as web).

NameTypeDescription
value?VID of the item. In selection mode (selection) this is the selected value; also used as the React key. Required in selection mode.
labelReactNodeButton text. With iconOnly it must be given as text; it becomes the screen reader name and tooltip.
icon?IconPropIcon at the start of the text: a name or an element.
iconEnd?IconPropIcon at the end of the text.
iconOnly?booleanShows only the icon (square button, IconButton); label becomes the name and tooltip.
tone?ToneThis button's color; defaults to the group's color.
disabled?booleanCannot be pressed. Locks this item regardless of the group's disabled.
loading?booleanLoading state. Happens automatically when onPress returns a Promise.
tooltip?TooltipPropTooltip (on press and hold). See TooltipProp.
onPress?(event: GestureResponderEvent | undefined) => unknownCalled on press. If it returns a Promise the button shows loading automatically. In selection mode it is called after the selection changes. If the item moved into the "More" menu, it is also called when chosen from the menu.
menu?readonly MenuEntry[]When given, the button opens a menu (like the arrow part of a split button).
style?StyleProp<ViewStyle>Button style.

What happens to buttons that do not fit in the group (same as web).

  • "none": Nothing; buttons stay on one line.
  • "wrap": They wrap to the next line. Only meaningful with attached={false}.
  • "menu": Those that do not fit move into a trailing "More actions" (⋯) menu (opens as a bottom sheet on phones). The group takes the full width of its area. Works only with items and in a horizontal group.
type ButtonGroupOverflow = "none" | "wrap" | "menu"

Props of ButtonGroup: an action group, single-select or multi-select group.

type ButtonGroupProps = ButtonGroupActionProps | ButtonGroupSingleProps<V> | ButtonGroupMultipleProps<V>
NameTypeDefaultDescription
selection?undefined | "single" | "multiple"Selection mode off.
value?undefined | V | null | V[]Selected value(s) (controlled); only with selection.
defaultValue?undefined | V | null | V[]Initial selection; only with selection.
onValueChange?undefined | (value: V | null) => void | (value: V[]) => voidCalled when the selection changes; only with selection.
required?undefined | boolean | booleanKeeps a button pressed; only with selection.
ref?Ref<ViewRef>Ref of the container.
variant?ButtonVariant | (string & {})Variant of the buttons inside (a button's own variant wins).
tone?ToneColor of the buttons inside.
size?SizeHeight of the buttons inside.
disabled?booleanDisables all buttons.
orientation?"horizontal" | "vertical""horizontal"Layout direction.
attached?booleantrueAre the buttons attached? With true the inner corners are removed and borders merge; with false there is a gap between buttons.
block?booleanTakes the full width of its area; buttons share the area equally.
label?stringScreen reader name of the group (e.g. "Text alignment").
overflow?ButtonGroupOverflow"none"What happens to buttons that do not fit. See ButtonGroupOverflow.
items?readonly ButtonGroupItem[] | readonly ButtonGroupItem<V>[] | readonly ButtonGroupItem<V>[]Buttons as an array. Selection mode, split buttons (menu) and overflow="menu" work this way. If omitted, children is rendered.
children?ReactNodeYour own buttons: Button, IconButton, Menu with a button trigger. Missing variant, tone, size, disabled come from the group.
style?StyleProp<ViewStyle>Container style.
testID?stringTest ID.