function App() {const [showModal, setShowModal] = useState(false)console.log(showModal)const ref = React.useRef(null)return (<Center h={300}><Button onPress={() => setShowModal(true)} ref={ref}><ButtonText>Show Modal</ButtonText></Button><ModalisOpen={showModal}onClose={() => {setShowModal(false)}}finalFocusRef={ref}><ModalBackdrop /><ModalContent><ModalHeader><Heading size="lg">Engage with Modals</Heading><ModalCloseButton><Icon as={CloseIcon} /></ModalCloseButton></ModalHeader><ModalBody><Text>Elevate user interactions with our versatile modals. Seamlesslyintegrate notifications, forms, and media displays. Make an impacteffortlessly.</Text></ModalBody><ModalFooter><Buttonvariant="outline"size="sm"action="secondary"mr="$3"onPress={() => {setShowModal(false)}}><ButtonText>Cancel</ButtonText></Button><Buttonsize="sm"action="positive"borderWidth="$0"onPress={() => {setShowModal(false)}}><ButtonText>Explore</ButtonText></Button></ModalFooter></ModalContent></Modal></Center>)}
import { Modal } from "@gluestack-ui/themed"
export default () => (<Modal><ModalBackdrop /><ModalContent><ModalHeader><ModalCloseButton></ModalCloseButton></ModalHeader><ModalBody /><ModalFooter /></ModalContent></Modal>)
Prop | Type | Default | Description |
---|---|---|---|
isOpen | boolean | - | If true, the modal will open. Useful for controllable state behavior. |
onClose | () => any | - | Callback invoked when the modal is closed. |
useRNModal | boolean | false | If true, renders react-native native modal. |
defaultIsOpen | boolean | - | Specifies the default open state of the Modal |
initialFocusRef | React.RefObject<any> | - | The ref of element to receive focus when the modal opens. |
finalFocusRef | React.RefObject<any> | - | The ref of element to receive focus when the modal closes |
avoidKeyboard | boolean | - | If true, the Modal will avoid the keyboard. |
closeOnOverlayClick | boolean | - | If true, the Modal will close when the overlay is clicked. |
isKeyboardDismissable | boolean | - | If true, the keyboard can dismiss the Modal |
children | any | - | The content to display inside the Modal |
Sx Prop | Description |
---|---|
_content | Prop to style ModalContent Component |
Prop | Type | Default | Description |
---|---|---|---|
focusable | boolean | false | If true, Modal Content will be focusable. |
Sx Prop | Description |
---|---|
_text | Prop to style ModalCloseButton Text Component |
_icon | Prop to style ModalCloseButton Icon Component |
Name | Value | Default |
---|---|---|
size | xs | sm | md | lg | full | md |
function App() {const [showModal, setShowModal] = useState(false)const [showModal2, setShowModal2] = useState(false)const [showModal3, setShowModal3] = useState(false)return (<Center><Center h={400}><Button onPress={() => setShowModal(true)}><ButtonText>Forgot password?</ButtonText></Button></Center><ModalisOpen={showModal}onClose={() => {setShowModal(false)}}><ModalBackdrop /><ModalContent><ModalHeader borderBottomWidth="$0"><VStack space="sm"><Heading size="lg">Forgot password?</Heading><Text size="sm">No worries, we’ll send you reset instructions</Text></VStack></ModalHeader><ModalBody><Input><InputField placeholder="Enter your email" /></Input></ModalBody><ModalFooter borderTopWidth="$0"><VStack space="lg" w="$full"><ButtononPress={() => {setShowModal2(true)}}><ButtonText>Submit</ButtonText></Button><HStack><Buttonvariant="link"size="sm"onPress={() => {setShowModal(false)}}><ButtonIcon as={ArrowLeftIcon} /><ButtonText>Back to login</ButtonText></Button></HStack></VStack></ModalFooter></ModalContent></Modal><ModalisOpen={showModal2}onClose={() => {setShowModal2(false)}}><ModalBackdrop /><ModalContent><ModalHeader borderBottomWidth="$0"><VStack space="sm"><Heading size="lg">Reset password</Heading><Text size="sm">A verification code has been sent to you. Enter code below.</Text></VStack></ModalHeader><ModalBody><Input><InputField placeholder="Enter verification code" /></Input></ModalBody><ModalFooter borderTopWidth="$0"><VStack space="lg" w="$full"><ButtononPress={() => {setShowModal3(true)}}><ButtonText>Continue</ButtonText></Button><Text size="sm">Didn’t receive the email?<Link ml="$1"><Link.Textsize="sm"$dark-color="$textDark200"color="$textLight700"fontWeight="$semibold">Click to resend</Link.Text></Link></Text><HStack space="xs" alignItems="center"><Buttonvariant="link"size="sm"onPress={() => {setShowModal2(false)}}><ButtonIcon as={ArrowLeftIcon} /><ButtonText>Back to login</ButtonText></Button></HStack></VStack></ModalFooter></ModalContent></Modal><ModalisOpen={showModal3}onClose={() => {setShowModal3(false)}}><ModalBackdrop /><ModalContent><ModalHeader borderBottomWidth="$0"><VStack space="sm"><Heading size="lg">Set new password</Heading><Text size="sm">Almost done. Enter your new password and you are all set.</Text></VStack></ModalHeader><ModalBody><VStack space="xl"><Input><InputField placeholder="New password" /></Input><Input><InputField placeholder="Confirm new password" /></Input></VStack></ModalBody><ModalFooter borderTopWidth="$0"><VStack space="lg" w="$full"><ButtononPress={() => {setShowModal(false)setShowModal2(false)setShowModal3(false)}}><ButtonText>Submit</ButtonText></Button><HStack space="xs" alignItems="center"><Buttonvariant="link"size="sm"onPress={() => {setShowModal3(false)}}><ButtonIcon as={ArrowLeftIcon} /><ButtonText>Back to login</ButtonText></Button></HStack></VStack></ModalFooter></ModalContent></Modal></Center>)}
function App() {const [showModal, setShowModal] = React.useState(false)const [size, setSize] = React.useState(undefined)const sizes = ["xs", "sm", "md", "lg", "full"]const ref = React.useRef(null)const handleClick = (currentSize) => {setShowModal(true)setSize(currentSize)}return (<Center h={400}><VStack space="md">{sizes.map((currentSize) => {return (<Button key={currentSize} onPress={() => handleClick(currentSize)}><ButtonText>{currentSize}</ButtonText></Button>)})}</VStack><ModalisOpen={showModal}onClose={() => {setShowModal(false)}}size={size}finalFocusRef={ref}><ModalBackdrop /><ModalContent><ModalHeader><Heading size="lg">Delete Folder</Heading><ModalCloseButton><Icon as={CloseIcon} /></ModalCloseButton></ModalHeader><ModalBody><Text size="sm">Whoa, slow down there! This modal is like a red light at anintersection, reminding you to stop and think before you proceed.Is deleting this folder the right choice?</Text></ModalBody><ModalFooter><Buttonvariant="outline"size="sm"action="secondary"mr="$3"onPress={() => {setShowModal(false)}}><ButtonText>Cancel</ButtonText></Button><Buttonsize="sm"action="primary"borderWidth="$0"onPress={() => {setShowModal(false)}}bg="$error700"$hover-bg="$error800"$active-bg="$error900"><ButtonText>Explore</ButtonText></Button></ModalFooter></ModalContent></Modal></Center>)}