function Example() {const [showAlertDialog, setShowAlertDialog] = React.useState(false)return (<Center h={300}><Button onPress={() => setShowAlertDialog(true)}><ButtonText>Click me</ButtonText></Button><AlertDialogisOpen={showAlertDialog}onClose={() => {setShowAlertDialog(false)}}><AlertDialogBackdrop /><AlertDialogContent><AlertDialogHeader><Heading size="lg">Deactivate account</Heading><AlertDialogCloseButton><Icon as={CloseIcon} /></AlertDialogCloseButton></AlertDialogHeader><AlertDialogBody><Text size="sm">Are you sure you want to deactivate your account? Your data willbe permanently removed and cannot be undone.</Text></AlertDialogBody><AlertDialogFooter><ButtonGroup space="lg"><Buttonvariant="outline"action="secondary"onPress={() => {setShowAlertDialog(false)}}><ButtonText>Cancel</ButtonText></Button><Buttonbg="$error600"action="negative"onPress={() => {setShowAlertDialog(false)}}><ButtonText>Deactivate</ButtonText></Button></ButtonGroup></AlertDialogFooter></AlertDialogContent></AlertDialog></Center>)}
import {AlertDialog,AlertDialogBackdrop,AlertDialogContent,AlertDialogHeader,AlertDialogCloseButton,AlertDialogFooter,AlertDialogBody,} from "@gluestack-ui/themed"
export default () => (<AlertDialog><AlertDialogBackdrop /><AlertDialogContent><AlertDialogHeader><AlertDialogCloseButton /></AlertDialogHeader><AlertDialogBody /><AlertDialogFooter /></AlertDialogContent></AlertDialog>)
Prop | Type | Default | Description |
---|---|---|---|
isOpen | boolean | false | If true, the alert-dialog will open. Useful for controllable state behavior. |
onClose | () => any | - | Callback invoked when the alert-dialog is closed. |
useRNModal | boolean | false | If true, renders react-native native modal. (Only works in react-native) |
defaultIsOpen | boolean | false | Specifies the default open state of the AlertDialog |
initialFocusRef | React.RefObject<any> | - | The ref of element to receive focus when the alert-dialog opens. |
finalFocusRef | React.RefObject<any> | - | The ref of element to receive focus when the alert-dialog closes. |
avoidKeyboard | boolean | - | If true, the AlertDialog will avoid the keyboard. |
closeOnOverlayClick | boolean | true | If true, the AlertDialog will close when the overlay is clicked. |
isKeyboardDismissable | boolean | true | If true, the keyboard can dismiss the AlertDialog |
animationPreset | slide | fade | slide | Specifies the animation preset for the AlertDialog |
Sx Prop | Description |
---|---|
_content | Prop to style AlertDialogContent Component |
Sx Prop | Description |
---|---|
_text | Prop to style AlertDialogCloseButton Text Component |
_icon | Prop to style AlertDialogCloseButton Icon Component |
Name | Value | Default |
---|---|---|
size | xs | sm | md | lg | full | md |
function App() {const [showAlertDialog, setShowAlertDialog] = React.useState(false)return (<><Center h={300}><Button onPress={() => setShowAlertDialog(true)}><ButtonText>Click me</ButtonText></Button></Center><AlertDialogisOpen={showAlertDialog}onClose={() => {setShowAlertDialog(false)}}><AlertDialogBackdrop /><AlertDialogContent><AlertDialogHeader borderBottomWidth="$0"><HStack space="sm" alignItems="center"><Iconas={CheckCircleIcon}color="$success700"$dark-color="$success300"/><Heading size="lg">Order placed</Heading></HStack></AlertDialogHeader><AlertDialogBody><Text size="sm">Congratulations, your order has been placed! You will receive aconfirmation email shortly. Thank you for shopping with us.</Text></AlertDialogBody><AlertDialogFooter borderTopWidth="$0"><Buttonvariant="outline"size="sm"action="secondary"mr="$3"onPress={() => {setShowAlertDialog(false)}}><ButtonText>Okay</ButtonText></Button></AlertDialogFooter></AlertDialogContent></AlertDialog></>)}
function App() {const [showAlertDialog, setShowAlertDialog] = React.useState(false)return (<><Center h={300}><Button onPress={() => setShowAlertDialog(true)}><ButtonText>Click me</ButtonText></Button></Center><AlertDialogisOpen={showAlertDialog}onClose={() => {setShowAlertDialog(false)}}size="md"><AlertDialogBackdrop /><AlertDialogContent><AlertDialogHeader borderBottomWidth="$0"><HStack space="sm" alignItems="center"><Icon as={AlertTriangleIcon} color="$error700" /><Heading size="lg">Order placed</Heading></HStack></AlertDialogHeader><AlertDialogBody><Text>You have exceeded your monthly upload limit. Please upgrade to apremium account to continue uploading.</Text></AlertDialogBody><AlertDialogFooter borderTopWidth="$0"><ButtonGroup space="lg"><Buttonvariant="outline"action="secondary"onPress={() => {setShowAlertDialog(false)}}><ButtonText fontSizes="$md">Close</ButtonText></Button><Buttonaction="primary"onPress={() => {setShowAlertDialog(false)}}bgColor="$darkBlue700"><ButtonText>View plans</ButtonText></Button></ButtonGroup></AlertDialogFooter></AlertDialogContent></AlertDialog></>)}