Alert
nativeui/alertFreeComponent
An alert component for React Native applications.
Live preview
live · rendered by the registry
Rendered by nativeui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nativeui.ribbi.ch/r/alert.jsonSource
1import * as React from "react";2import { View, Text } from "react-native";3import { cva, type VariantProps } from "class-variance-authority";45import { cn } from "@/lib/utils";67const alertVariants = cva("w-full rounded-xl border p-4 mb-4", {8 variants: {9 variant: {10 default: "bg-background border-input",11 destructive:12 "border-destructive/50 bg-destructive/10 text-destructive dark:border-destructive",13 success:14 "border-green-500/50 bg-green-500/10 text-green-700 dark:text-green-500 dark:border-green-500",15 warning:16 "border-yellow-500/50 bg-yellow-500/10 text-yellow-700 dark:text-yellow-500 dark:border-yellow-500",17 info: "border-blue-500/50 bg-blue-500/10 text-blue-700 dark:text-blue-500 dark:border-blue-500",18 },19 },20 defaultVariants: {21 variant: "default",22 },23});2425interface AlertProps26 extends React.ComponentPropsWithoutRef<typeof View>,27 VariantProps<typeof alertVariants> {28 icon?: React.ReactNode;29}3031function Alert({ className, variant, icon, children, ...props }: AlertProps) {32 return (33 <View34 className={cn(alertVariants({ variant }), className)}35 accessibilityRole="alert"36 {...props}37 >38 {icon && <View className="mb-2">{icon}</View>}39 <View className={cn(icon ? "pl-0" : "pl-0")}>{children}</View>40 </View>41 );42}4344interface AlertTitleProps extends React.ComponentPropsWithoutRef<typeof Text> { }4546function AlertTitle({ className, ...props }: AlertTitleProps) {47 return (48 <Text49 className={cn(50 "text-lg font-semibold leading-none tracking-tight text-foreground mb-2",51 className52 )}53 {...props}54 />55 );56}5758interface AlertDescriptionProps59 extends React.ComponentPropsWithoutRef<typeof Text> { }6061function AlertDescription({ className, ...props }: AlertDescriptionProps) {62 return (63 <Text64 className={cn("text-base text-foreground opacity-90", className)}65 {...props}66 />67 );68}6970export {71 Alert,72 AlertTitle,73 AlertDescription,74 type AlertProps,75 type AlertTitleProps,76 type AlertDescriptionProps,77};
What it pulls in
npm packages
Files it writes
More from nativeui
All 29 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | nativeui | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | nativeui | Components | Free | 1 dep | |
| Avataravatar | nativeui | Components | Free | 1 dep | |
| Badgebadge | nativeui | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | nativeui | Components | Free | 2 deps | |
| Buttonbutton | nativeui | Components | Free | 2 deps | |
| Calendarcalendar | nativeui | Components | Free | 4 deps | |
| Cardcard | nativeui | Components | Free | 1 dep |
