-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
186 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SHOWCASE_HOST = | ||
"https://headlessui-react-native-showcase.vercel.app"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./host"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,104 @@ | ||
import { SHOWCASE_HOST } from "@/constants"; | ||
import React from "react"; | ||
|
||
```jsx copy file=<rootDir>/node_modules/headlessui-react-native-example-ui/src/modal/modal-example.tsx | ||
# Modal (Dialog) | ||
|
||
## Installation | ||
|
||
To get started, install Headless UI via npm: | ||
|
||
``` | ||
npm install headlessui-react-native | ||
``` | ||
|
||
## Basic example | ||
|
||
Modals are built using the `Modal`, `ModalPanel`, and `ModalTitle` components: | ||
|
||
<iframe | ||
src={`${SHOWCASE_HOST}/components/modal`} | ||
width="100%" | ||
height="500px" | ||
></iframe> | ||
|
||
```jsx file=<rootDir>/node_modules/headlessui-react-native-example-ui/src/modal/modal-example.tsx | ||
|
||
``` | ||
|
||
## Examples | ||
|
||
### Showing/hiding the modal | ||
|
||
Modals are controlled components, meaning that you have to provide and manage the open state yourself using the `open` prop and the `onClose` callback. | ||
|
||
The `onClose` callback is called when an modal is dismissed, which happens when the user presses the Esc key or clicks outside the `ModalPanel`. In this callback set the `open` state back to `false` to close the modal. | ||
|
||
```jsx | ||
import { Modal, ModalPanel, ModalTitle } from 'headlessui-react-native' | ||
import { useState } from 'react' | ||
|
||
function Example() { | ||
// The open/closed state lives outside of the `Modal` and is managed by you | ||
let [isOpen, setIsOpen] = useState(true) | ||
|
||
function async handleDeactivate() { | ||
await fetch('/deactivate-account', { method: 'POST' }) | ||
setIsOpen(false) | ||
} | ||
|
||
return ( | ||
<Modal open={isOpen} onClose={() => setIsOpen(false)}> | ||
<ModalPanel> | ||
<ModalTitle>Deactivate account</ModalTitle> | ||
<Text>This will permanently deactivate your account</Text> | ||
<Text>Are you sure you want to deactivate your account? All of your data will be permanently removed.</Text> | ||
|
||
{/* | ||
You can render additional buttons to dismiss your | ||
modal by setting `isOpen` to `false`. | ||
*/} | ||
<Button title="Cancel" onPress={() => setIsOpen(false)}/> | ||
<Button title="Deactivate" onPress={handleDeactivate}/> | ||
</ModalPanel> | ||
</Modal> | ||
) | ||
} | ||
``` | ||
For situations where you don't have easy access to your open/close state, Headless UI provides a `CloseButton` component that will close the nearest modal ancestor when clicked. | ||
```jsx | ||
import { CloseButton } from "headlessui-react-native"; | ||
import { MyModal } from "./my-modal"; | ||
|
||
function Example() { | ||
return ( | ||
<MyModal> | ||
{/* ... */} | ||
<CloseButton>Cancel</CloseButton> | ||
</MyModal> | ||
); | ||
} | ||
``` | ||
### Scrollable modals | ||
<iframe | ||
src={`${SHOWCASE_HOST}/components/modal/scrollable`} | ||
width="100%" | ||
height="500px" | ||
></iframe> | ||
```jsx file=<rootDir>/node_modules/headlessui-react-native-example-ui/src/modal/scrollable-modal-example.tsx | ||
|
||
``` | ||
## Component API | ||
### Modal | ||
### ModalPanel | ||
### ModalTitle | ||
### CloseButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
export default { | ||
import { DocsThemeConfig } from "nextra-theme-docs"; | ||
import React from "react"; | ||
|
||
const config: DocsThemeConfig = { | ||
logo: <span>Headlessui React Native</span>, | ||
project: { | ||
link: "https://github.com/jamsubu/headlessui-react-native", | ||
}, | ||
docsRepositoryBase: | ||
"https://github.com/jamsubu/headlessui-react-native/tree/main/apps/docs", | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"noEmit": true, | ||
"incremental": true, | ||
"module": "esnext", | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./*"] | ||
} | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import { ModalExample } from "headlessui-react-native-example-ui"; | ||
|
||
export default ModalExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { ScrollableModalExample } from "headlessui-react-native-example-ui"; | ||
export default ScrollableModalExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./modal-example"; | ||
export * from "./scrollable-modal-example"; |
43 changes: 43 additions & 0 deletions
43
packages/example-ui/src/modal/scrollable-modal-example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Modal, ModalPanel, ModalTitle } from "headlessui-react-native"; | ||
import React, { useState } from "react"; | ||
import { Button, Text, View } from "react-native"; | ||
|
||
export function ScrollableModalExample() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
return ( | ||
<View> | ||
<Button title="Open dialog" onPress={() => setIsOpen(true)} /> | ||
<Modal onClose={() => setIsOpen(false)} isOpen={isOpen}> | ||
<View | ||
style={{ | ||
width: "100%", | ||
height: "100%", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
padding: 40, | ||
backgroundColor: "rgba(0, 0, 0, 0.5)", | ||
}} | ||
> | ||
<ModalPanel | ||
style={{ | ||
padding: 20, | ||
width: 300, | ||
backgroundColor: "white", | ||
}} | ||
scrollable | ||
> | ||
<ModalTitle style={{ fontSize: 20, fontWeight: "700" }}> | ||
Payment successful | ||
</ModalTitle> | ||
<View style={{ paddingTop: 20, paddingBottom: 20 }}> | ||
{Array.from({ length: 20 }).map((_, index) => ( | ||
<Text key={index}>new line</Text> | ||
))} | ||
</View> | ||
<Button title="Got it, thanks!" onPress={() => setIsOpen(false)} /> | ||
</ModalPanel> | ||
</View> | ||
</Modal> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73d4957
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for headlessui-react-native-showcase ready!
✅ Preview
https://headlessui-react-native-showcase-bfy1lkxyx-nakzyus-projects.vercel.app
Built with commit 73d4957.
This pull request is being automatically deployed with vercel-action