Alert

Alerts are used to communicate the status of a system, feature, or page. They indicate a specific state that may require attention from the user.
Installation
API Reference
Spec Doc
This is an illustration of Alert component.
action
variant
<Alert mx="$2.5" action="info" variant="solid">
<AlertIcon as={InfoIcon} mr="$3" />
<AlertText>
We have updated our terms of service. Please review and accept to continue
using our service.
</AlertText>
</Alert>

Installation

Step 1: Install the following dependencies:

npm i @gluestack-ui/alert

Step 2: Copy and paste the following code into your project.

import { AsForwarder, styled } from "@gluestack-style/react"
import { createAlert } from "@gluestack-ui/alert"
import { View, Text } from "react-native"
const StyledRoot = styled(
View,
{
alignItems: "center",
p: "$3",
flexDirection: "row",
borderRadius: "$sm",
variants: {
action: {
error: {
bg: "$backgroundError",
borderColor: "$error300",
_icon: {
color: "$error500",
},
},
warning: {
bg: "$backgroundWarning",
borderColor: "$warning300",
_icon: {
color: "$warning500",
},
},
success: {
bg: "$backgroundSuccess",
borderColor: "$success300",
_icon: {
color: "$success500",
},
},
info: {
bg: "$backgroundInfo",
borderColor: "$info300",
_icon: {
color: "$info500",
},
},
muted: {
bg: "$backgroundMuted",
borderColor: "$secondary300",
_icon: {
color: "$secondary500",
},
},
},
variant: {
solid: {},
outline: {
borderWidth: "$1",
bg: "$white",
},
accent: {
borderLeftWidth: "$4",
},
},
},
defaultProps: {
variant: "solid",
action: "info",
},
},
{
descendantStyle: ["_icon", "_text"],
}
)
const StyledText = styled(
Text,
{
color: "$text700",
flex: 1,
fontWeight: "$normal",
fontFamily: "$body",
fontStyle: "normal",
letterSpacing: "$md",
variants: {
isTruncated: {
true: {
props: {
// @ts-ignore
numberOfLines: 1,
ellipsizeMode: "tail",
},
},
},
bold: {
true: {
fontWeight: "$bold",
},
},
underline: {
true: {
textDecorationLine: "underline",
},
},
strikeThrough: {
true: {
textDecorationLine: "line-through",
},
},
size: {
"2xs": {
fontSize: "$2xs",
},
xs: {
fontSize: "$xs",
},
sm: {
fontSize: "$sm",
},
md: {
fontSize: "$md",
},
lg: {
fontSize: "$lg",
},
xl: {
fontSize: "$xl",
},
"2xl": {
fontSize: "$2xl",
},
"3xl": {
fontSize: "$3xl",
},
"4xl": {
fontSize: "$4xl",
},
"5xl": {
fontSize: "$5xl",
},
"6xl": {
fontSize: "$6xl",
},
},
sub: {
true: {
fontSize: "$xs",
},
},
italic: {
true: {
fontStyle: "italic",
},
},
highlight: {
true: {
bg: "$yellow500",
},
},
},
defaultProps: {
size: "md",
},
},
{
ancestorStyle: ["_text"],
}
)
const StyledIcon = styled(
AsForwarder,
{
variants: {
size: {
"2xs": {
h: "$3",
w: "$3",
props: {
// @ts-ignore
size: 12,
},
},
xs: {
h: "$3.5",
w: "$3.5",
props: {
//@ts-ignore
size: 14,
},
},
sm: {
h: "$4",
w: "$4",
props: {
//@ts-ignore
size: 16,
},
},
md: {
h: "$4.5",
w: "$4.5",
props: {
//@ts-ignore
size: 18,
},
},
lg: {
h: "$5",
w: "$5",
props: {
//@ts-ignore
size: 20,
},
},
xl: {
h: "$6",
w: "$6",
props: {
//@ts-ignore
size: 24,
},
},
},
},
props: {
size: "md",
//@ts-ignore
fill: "none",
},
},
{
ancestorStyle: ["_icon"],
}
)
export const Alert = createAlert({
Root: StyledRoot,
Text: StyledText,
Icon: StyledIcon,
})
export const AlertText = Alert.Text
export const AlertIcon = Alert.Icon

Step 3: Update the import paths to match your project setup.

API Reference

To use this component in your project, include the following import statement in your file.
import { Alert, AlertIcon, AlertText } from "@/components/ui/Alert"
export default () => (
<Alert>
<AlertIcon />
<AlertText />
</Alert>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Alert

Contains all alert related layout style props and actions. It inherits all the properties of React Native's View component.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style AlertText Component
_icon
Prop to style AlertIcon Component

AlertIcon

It inherits all the properties of React Native's View component.

AlertText

Contains all spinner related layout style props and actions. It inherits all the properties of React Native's Text component.

Props

Alert component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.

Alert

Name
Value
Default
action
error | warning | success | info | muted
info
variant
solid | outline | accent
solid

Spec Doc

Explore the comprehensive details of the Alert in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.
Edit this page on GitHub