Alert Dialog
nativeui/alert-dialogFreeComponent
An alert dialog 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-dialog.jsonSource
1import * as React from "react";2import {3 View,4 Text,5 Pressable,6 Modal,7 TouchableWithoutFeedback,8 Platform,9 Animated,10 Dimensions,11 KeyboardAvoidingView,12} from "react-native";13import { cn } from "@/lib/utils";1415interface AlertDialogProps {16 children: React.ReactNode;17 className?: string;18 open?: boolean;19 onOpenChange?: (open: boolean) => void;20}2122interface AlertDialogTriggerProps {23 children: React.ReactNode;24 className?: string;25 disabled?: boolean;26 asChild?: boolean;27}2829interface AlertDialogContentProps {30 children: React.ReactNode;31 className?: string;32 onInteractOutside?: () => void;33}3435interface AlertDialogHeaderProps {36 className?: string;37 children: React.ReactNode;38}3940interface AlertDialogFooterProps {41 className?: string;42 children: React.ReactNode;43}4445interface AlertDialogTitleProps {46 className?: string;47 children: React.ReactNode;48}4950interface AlertDialogDescriptionProps {51 className?: string;52 children: React.ReactNode;53}5455interface AlertDialogActionProps {56 children: React.ReactElement<{ onPress?: (e: any) => void }>;57 className?: string;58}5960interface AlertDialogCancelProps {61 children: React.ReactElement<{ onPress?: (e: any) => void }>;62 className?: string;63}6465const AlertDialogContext = React.createContext<{66 open: boolean;67 setOpen: (open: boolean) => void;68 handleClose?: () => void;69}>({70 open: false,71 setOpen: () => { },72});7374const AlertDialog = React.forwardRef<View, AlertDialogProps>(75 ({ children, className, open = false, onOpenChange, ...props }, ref) => {76 const [internalOpen, setInternalOpen] = React.useState(false);7778 const isControlled = open !== undefined;79 const isOpen = isControlled ? open : internalOpen;8081 const setOpen = React.useCallback(82 (value: boolean) => {83 if (!isControlled) {84 setInternalOpen(value);85 }86 onOpenChange?.(value);87 },88 [isControlled, onOpenChange]89 );9091 return (92 <AlertDialogContext.Provider value={{ open: isOpen, setOpen }}>93 <View ref={ref} className={cn("", className)} {...props}>94 {children}95 </View>96 </AlertDialogContext.Provider>97 );98 }99);100101AlertDialog.displayName = "AlertDialog";102103const AlertDialogTrigger = React.forwardRef<View, AlertDialogTriggerProps>(104 (105 { children, className, disabled = false, asChild = false, ...props },106 ref107 ) => {108 const { setOpen } = React.useContext(AlertDialogContext);109110 if (asChild) {111// … truncated
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 | |
| Alertalert | nativeui | Components | Free | 2 deps | |
| 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 |
