Knit UI
GitHub

Usage

An Alert is inline and static: it sits in the layout next to whatever it is about and stays until the content changes.

import { Alert } from "@knitui/components";

<Alert title="Payment failed" theme="red">
  Your card was declined. Try another payment method.
</Alert>;

Severity is expressed through the theme, not a separate severity prop — theme="red" / "yellow" / "green" / "blue" recolour the whole block from the palette ramp, the same vocabulary every other component uses.

Add icon for a leading glyph, and withCloseButton with an onClose when the message is dismissible. For full control over the layout, compose the parts directly (see the Compound Parts example below).

When to use something else

  • A transient message that appears over the UI and leaves on its own → Notification
  • Validation text belonging to one field → the error prop on the input itself (e.g. TextInput)
  • A blocking message that needs a decision → Modal

Examples

Variants

Every visual variant stacked.

Loading example…

VariantsSourceStorybook

Sizes

Every size on the full token scale.

Loading example…

SizesSourceStorybook

With Title

A title is rendered bold above the body and wired as the alert's label.

Loading example…

With TitleSourceStorybook

With Icon

An icon sits in a column beside the body.

Loading example…

With IconSourceStorybook

With Close Button

A close button pinned top-right; wire onClose to dismiss.

Loading example…

With Close ButtonSourceStorybook

Radius

Rounded corners via the radius prop.

Loading example…

RadiusSourceStorybook

Themed

The palette ramp follows the active theme — same alert, different accent.

Loading example…

ThemedSourceStorybook

Compound Parts

Alert.Title and Alert.Message are the compound parts the default layout composes — usable directly for fully custom alert bodies.

Loading example…

Compound PartsSourceStorybook

Gradient

The gradient variant fills the panel with a linear gradient. With no gradient prop it follows the theme ramp; otherwise it accepts a two-color shorthand, $colorN tokens, or a multi-step stops list. Text renders white.

Loading example…

GradientSourceStorybook

Gradient Presets

A set of curated multi-color gradient presets.

Loading example…

Gradient PresetsSourceStorybook

Gradient Themed

The themed gradient (no gradient prop) derives its ramp from the active theme.

Loading example…

Gradient ThemedSourceStorybook

Gradient Angles

The same two-color gradient swept across a range of angles.

Loading example…

Gradient AnglesSourceStorybook

Shadows

Optional elevation via the shadow prop — the shared ladder from xs to xl.

Loading example…

ShadowsSourceStorybook

Styles

Per-slot styles targets individual parts — here the title and message.

Loading example…

StylesSourceStorybook

Props

PropTypeDefaultDescription
closeButtonLabelstring | undefined"Close"`aria-label` for the close button.
disabled systemboolean | undefined——
gradient systemGradientValue | undefined—Gradient fill for variant='gradient' — { from, to, deg } or { stops, deg }.
iconReactNode—Icon displayed in a column next to the body.
onClose(() => void) | undefined—Called when the close button is pressed.
radius systemstring | number | undefined—Theme radius token (e.g. `$sm`) or any CSS value.
shadow system"xs" | "sm" | "md" | "lg" | "xl" | "xxs" | "xxl" | undefined
unset · xs · sm · md · lg · xl
—Elevation — drop shadow from the shared ladder.
size system"xs" | "sm" | "md" | "lg" | "xl" | "xxs" | "xxl" | undefined
xxs · xs · sm · md · lg · xl · xxl
—Token size for panel spacing, content gaps, text, and close button metrics.
styles systemSlotStyles<AlertStyles> | undefined—Per-slot style sugar — props spread onto the matching styled part.
theme systemThemeName | null | undefined
unset · blue · red · green · yellow · pink
—Applies a theme to this element
titleReactNodeAlert title, rendered bold above the body.
variant system"light" | "outline" | "white" | "transparent" | "default" | "filled" | "gradient" | undefined
filled · light · outline · default · transparent · white · gradient
lightVisual fill — how the theme color ramp is applied.
withCloseButtonboolean | undefinedfalseShow a close button pinned to the top-right.

Style slots

Every part of Alert can be styled through the styles prop. Explicit props on the component always win over slot styles.

SlotTargets
bodyProps for the body column that holds title + message (.Body).
closeButtonProps spread onto the close button (under closeButtonLabel).
contentProps for the content column (rich, non-text children) (.Content).
iconProps for the icon column wrapper (.Icon).
messageProps for the message text (text-only children) (.Message).
titleProps for the title text (.Title).
Accessibility & DOM props (2)
PropType
keyKey | null | undefined
refRef<TamaguiElement> | undefined

Plus 498 inherited style props from Box — the full Tamagui/React Native style surface, including token shorthands like p, mx, bg and c. See Tokens for the scales they accept, or the full list.

Accessibility

The container renders with role="alert", so assistive technology announces it as soon as it appears — without moving focus.

Naming is wired automatically: when you pass title it gets a generated id and becomes the block's aria-labelledby target, and the body is referenced through aria-describedby. Title and message are announced together.

  • role="alert" is an interruption. It is correct for something that just happened and the user must know about. For a message that is simply present on the page — a persistent tip or a static notice — the announcement is noise; render the content in a plain Paper or Card instead.
  • Because it announces on appearance, mount an Alert when the state changes rather than rendering it hidden and revealing it with styles — a hidden-then-shown alert may never be announced.
  • The close button takes its accessible name from closeButtonLabel (default "Close"); override it when the alert's subject makes a more specific label clearer.
  • Don't rely on colour alone to carry severity: the title or icon should make the meaning explicit for anyone who can't distinguish the theme.

Edit this page on GitHub