Toast
tetra-ui/toastFreeComponent
An opinionated toast component for React Native.
Live preview
live · rendered by the registry
Rendered by tetra-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://tetra-ui.com/r/toast.jsonSource
1import { cva } from "class-variance-authority";2import { ActivityIndicator, View } from "react-native";3import * as ToastPrimitive from "sonner-native";4import { useUniwind } from "uniwind";5import { cn } from "@/lib/utils";6import {7 CircleAlertIcon,8 CircleCheckIcon,9 InfoIcon,10 TriangleAlertIcon,11} from "./icons";12import { Text } from "./text";1314// Types15type ToastVariant =16 | "default"17 | "success"18 | "error"19 | "warning"20 | "info"21 | "loading";2223type ToastIconProps = {24 variant: ToastVariant;25};2627type ToastOptions = NonNullable<28 Parameters<typeof ToastPrimitive.toast.custom>[1]29>;3031type PromiseOptions = {32 loading: string;33 success: string | ((result: unknown) => string);34 error: string | ((error: unknown) => string);35} & Omit<ToastOptions, "description" | "icon">;3637// Components38const ToastIcon = ({ variant }: ToastIconProps) => {39 const iconClassName = iconVariants({ variant });4041 if (variant === "loading") {42 return (43 <View className="size-5 items-center justify-center">44 <ActivityIndicator className="accent-muted-foreground" size="small" />45 </View>46 );47 }4849 if (variant === "success") {50 return <CircleCheckIcon className={iconClassName} />;51 }5253 if (variant === "error") {54 return <TriangleAlertIcon className={iconClassName} />;55 }5657 if (variant === "warning") {58 return <CircleAlertIcon className={iconClassName} />;59 }6061 return <InfoIcon className={iconClassName} />;62};6364type TetraToastProps = {65 variant: ToastVariant;66 title: string;67 description?: string;68 icon?: React.ReactNode;69};7071const TetraToast = ({ variant, title, description, icon }: TetraToastProps) => (72 <View className="mx-4 justify-center rounded-2xl border border-border/80 bg-popover p-4 shadow-md">73 <View74 className={cn(75 "flex-row gap-4",76 description ? "items-start" : "items-center"77 )}78 >79 {icon ?? <ToastIcon variant={variant} />}80 <View className="flex-1">81 <Text className={titleVariants({ variant })}>{title}</Text>82 {description ? (83 <Text className="text-muted-foreground text-sm">{description}</Text>84 ) : null}85 </View>86 </View>87 </View>88);8990export const Toaster = (props: Omit<ToastPrimitive.ToasterProps, "theme">) => {91 const { theme: uniwindTheme } = useUniwind();92 const theme = uniwindTheme === "dark" ? "dark" : "light";9394 return (95 <ToastPrimitive.Toaster {...props} enableStacking gap={4} theme={theme} />96 );97};9899// Utils100// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from tetra-ui
All 41 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | tetra-ui | Components | Free | 1 dep | |
| Action Inputaction-input | tetra-ui | Components | Free | no deps | |
| Alertalert | tetra-ui | Components | Free | no deps | |
| Avataravatar | tetra-ui | Components | Free | no deps | |
| Badgebadge | tetra-ui | Components | Free | no deps | |
| Bottom Sheetbottom-sheet | tetra-ui | Components | Free | 4 deps · 7 files | |
| Buttonbutton | tetra-ui | Components | Free | no deps | |
| Cardcard | tetra-ui | Components | Free | no deps |
