Alert
Status indicators notify users of important system, feature, or page conditions that require attention.
Installation
API Reference
Important Note
This is the documentation for gluestack-ui v2 (beta). For @gluestack-ui/themed (stable) documentation, refer to gluestack-ui v1.
This is an illustration of Alert component.
action
variant
<Alert action="muted" variant="solid"><AlertIcon as={InfoIcon} /><AlertText>Description of alert!</AlertText></Alert>
Installation
CLI
Manual
Run the following command:
npx gluestack-ui add alert
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.
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.
Alert
Name | Value | Default |
---|---|---|
action | error | warning | success | info | muted | info |
variant | solid | outline | solid |
Examples
The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.
Alert with CTA
<Alertaction="success"className="gap-4 max-w-[585px] w-full self-center items-start min-[400px]:items-center"><VStack className="gap-4 min-[400px]:flex-row justify-between flex-1 min-[400px]:items-center"><AlertText className="font-semibold text-typography-900" size="sm">Verify your phone number to create an API key</AlertText><Button size="sm"><ButtonText>Start verification</ButtonText></Button></VStack><Icon as={CloseIcon} /></Alert>
Alert on cloud sync
<Alertaction="warning"className="gap-4 max-w-[516px] w-full flex-row flex py-4 items-start self-center"><AlertIcon as={RepeatIcon} className="mt-1" /><HStack className="justify-between flex-1 items-center gap-1 sm:gap-8"><VStack className="flex-1"><Text className="font-semibold text-typography-900">Sync is disabled</Text><AlertText className="text-typography-900" size="sm">Enable cloud sync to help safeguard your data</AlertText></VStack><Button size="xs"><ButtonText>Turn on</ButtonText></Button></HStack></Alert>
Warning alert
<Alert action="error" className="gap-3">{/* Bomb is imported from 'lucide-react-native' */}<AlertIcon as={Bomb} size="lg" /><AlertText className="text-typography-900" size="sm"><Text className="mr-2 font-semibold text-typography-900">Heads up:</Text>Once done, this action cannot be undone</AlertText></Alert>
Alert on confirm password modal
function Example() {const [showPassword, setShowPassword] = React.useState(false)const handleState = () => {setShowPassword((showState) => {return !showState})}return (<VStack className="gap-5 sm:gap-8 p-6 sm:p-9 border border-outline-200 bg-background-0 rounded-xl shadow-hard-5 w-full max-w-[423px]"><VStack className="items-center gap-1"><Heading size="xl">Confirm our password?</Heading><Text>johnsmith@gmail.com</Text></VStack><VStack className="gap-3 sm:gap-5"><Input className="rounded-md" size="sm"><InputFieldtype={showPassword ? "text" : "password"}placeholder="Enter password"/><InputSlot className="mr-3" onPress={handleState}>{/* EyeIcon, EyeOffIcon are both imported from 'lucide-react-native' */}<InputIconsize="xs"as={showPassword ? EyeIcon : EyeOffIcon}className="stroke-background-600"/></InputSlot></Input><Button className="w-full rounded-md" size="sm"><ButtonText>Confirm</ButtonText></Button></VStack><Alert className="items-start" action="muted"><AlertIcon as={InfoIcon} size="xs" className="stroke-background-500" /><AlertText className="text-typography-600" size="xs">Minimum 8 characters, with at least 1 uppercase, 1 lowercase, and 1number required.</AlertText></Alert></VStack>)}