From 67a90baf382ed7098bcc68ddc2c7afd640847559 Mon Sep 17 00:00:00 2001 From: ruru <142723369+ruru-m07@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:56:59 +0530 Subject: [PATCH] docs(component): add documentation for modal component --- .../components/preview/Modal/customWidth.tsx | 56 ++ .../components/preview/Modal/customWidth2.tsx | 57 ++ .../www/components/preview/Modal/disabled.tsx | 55 ++ apps/www/components/preview/Modal/preview.tsx | 93 +++ .../components/preview/Modal/singleButton.tsx | 56 ++ apps/www/components/preview/Modal/trigger.tsx | 55 ++ apps/www/components/preview/Modal/usage.tsx | 60 ++ apps/www/components/preview/index.tsx | 6 + apps/www/content/docs/cli.mdx | 2 +- apps/www/content/docs/components/modal.mdx | 550 ++++++++++++++++++ apps/www/content/docs/components/textarea.mdx | 58 +- .../www/public/registry/components/modal.json | 2 +- packages/ui/src/components/modal.tsx | 19 +- 13 files changed, 1034 insertions(+), 35 deletions(-) create mode 100644 apps/www/components/preview/Modal/customWidth.tsx create mode 100644 apps/www/components/preview/Modal/customWidth2.tsx create mode 100644 apps/www/components/preview/Modal/disabled.tsx create mode 100644 apps/www/components/preview/Modal/preview.tsx create mode 100644 apps/www/components/preview/Modal/singleButton.tsx create mode 100644 apps/www/components/preview/Modal/trigger.tsx create mode 100644 apps/www/components/preview/Modal/usage.tsx create mode 100644 apps/www/content/docs/components/modal.mdx diff --git a/apps/www/components/preview/Modal/customWidth.tsx b/apps/www/components/preview/Modal/customWidth.tsx new file mode 100644 index 0000000..4bfbdc6 --- /dev/null +++ b/apps/www/components/preview/Modal/customWidth.tsx @@ -0,0 +1,56 @@ +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const CustomWidth = () => { + return ( + + + + + + + + + Custom Width + + + This modal opens with a Custom Width button. + + + + + + + + + Cancel + + + + + ); +}; + +export default CustomWidth; diff --git a/apps/www/components/preview/Modal/customWidth2.tsx b/apps/www/components/preview/Modal/customWidth2.tsx new file mode 100644 index 0000000..7a299c2 --- /dev/null +++ b/apps/www/components/preview/Modal/customWidth2.tsx @@ -0,0 +1,57 @@ +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const CustomWidth2 = () => { + return ( + + + + + + + + + Custom Width + + + This modal opens with a Custom Width button. + + + + + + + + + Cancel + + Submit + + + + ); +}; + +export default CustomWidth2; diff --git a/apps/www/components/preview/Modal/disabled.tsx b/apps/www/components/preview/Modal/disabled.tsx new file mode 100644 index 0000000..bd8a2c8 --- /dev/null +++ b/apps/www/components/preview/Modal/disabled.tsx @@ -0,0 +1,55 @@ +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const Disabled = () => { + return ( + + + + + + + + + Disabled + + + This modal opens with a Disabled button. + + + + + + + + Cancel + Submit + + + + ); +}; + +export default Disabled; diff --git a/apps/www/components/preview/Modal/preview.tsx b/apps/www/components/preview/Modal/preview.tsx new file mode 100644 index 0000000..24e46d0 --- /dev/null +++ b/apps/www/components/preview/Modal/preview.tsx @@ -0,0 +1,93 @@ +"use client"; + +import React, { useState } from "react"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; +import { Input } from "ruru-ui/components/input"; + +const Preview = () => { + const [isLoading, setIsLoading] = useState(false); + const [status, setStatus] = useState(false); + + const handleSubmit = async () => { + setIsLoading(true); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + setStatus(true); + setIsLoading(false); + + await new Promise((resolve) => setTimeout(resolve, 500)); + + setStatus(false); + }; + + return ( +
+ + Deploy + + + + + Deploy to production + + + Deploy your site to production by clicking the button below. + + + + + + + + Cancel + + {status ? ( + + + + ) : ( + "Deploy" + )} + + + + +
+ ); +}; + +export default Preview; diff --git a/apps/www/components/preview/Modal/singleButton.tsx b/apps/www/components/preview/Modal/singleButton.tsx new file mode 100644 index 0000000..15dcbb7 --- /dev/null +++ b/apps/www/components/preview/Modal/singleButton.tsx @@ -0,0 +1,56 @@ +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const SingleButton = () => { + return ( + + + + + + + + + Single Button + + + This modal opens with a Single Button. + + + + + + + + + Cancel + + + + + ); +}; + +export default SingleButton; diff --git a/apps/www/components/preview/Modal/trigger.tsx b/apps/www/components/preview/Modal/trigger.tsx new file mode 100644 index 0000000..e424323 --- /dev/null +++ b/apps/www/components/preview/Modal/trigger.tsx @@ -0,0 +1,55 @@ +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const Trigger = () => { + return ( + + + + + + + + + Custom Trigger + + + This modal opens with a custom trigger button. + + + + + + + + Cancel + Submit + + + + ); +}; + +export default Trigger; diff --git a/apps/www/components/preview/Modal/usage.tsx b/apps/www/components/preview/Modal/usage.tsx new file mode 100644 index 0000000..855c688 --- /dev/null +++ b/apps/www/components/preview/Modal/usage.tsx @@ -0,0 +1,60 @@ +"use client"; + +import React, { useState } from "react"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const Usage = () => { + const [isLoading, setIsLoading] = useState(false); + + const handleSubmit = async () => { + setIsLoading(true); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + setIsLoading(false); + }; + + return ( +
+ + Open Modal + + + + + Create Username + + + Enter a unique name for your token to differentiate it from + other tokens and then select the scope. + + + + + + + + Cancel + + Submit + + + + +
+ ); +}; + +export default Usage; diff --git a/apps/www/components/preview/index.tsx b/apps/www/components/preview/index.tsx index cf81028..ca12b50 100644 --- a/apps/www/components/preview/index.tsx +++ b/apps/www/components/preview/index.tsx @@ -27,6 +27,7 @@ import { import { BadgePreview } from "../badgePreview"; import Tabspreview from "../tabs"; +import { default as ModalPreview } from "./Modal/preview"; export default { button: ( @@ -163,4 +164,9 @@ export default { ), + modal: ( + + + + ), } as Record; diff --git a/apps/www/content/docs/cli.mdx b/apps/www/content/docs/cli.mdx index 07481fb..803e2f2 100644 --- a/apps/www/content/docs/cli.mdx +++ b/apps/www/content/docs/cli.mdx @@ -1,5 +1,5 @@ --- -title: Cli +title: CLI description: The CLI is a command-line interface that allows you to add components to your project. --- diff --git a/apps/www/content/docs/components/modal.mdx b/apps/www/content/docs/components/modal.mdx new file mode 100644 index 0000000..bbabba9 --- /dev/null +++ b/apps/www/content/docs/components/modal.mdx @@ -0,0 +1,550 @@ +--- +title: Modal +description: The Modal component is used to display content in a modal dialog. +preview: modal +--- + + +import Modal, { ModalProvider } from "ruru-ui/components/modal"; +import { Tab, Tabs } from "fumadocs-ui/components/tabs"; +import { Tabs as Rutabs, Tab as Rutab } from "ruru-ui/components/tabs"; +import Usage from "../../../components/preview/Modal/usage.tsx"; +import Trigger from "../../../components/preview/Modal/trigger.tsx"; +import SingleButton from "../../../components/preview/Modal/singleButton.tsx"; +import Disabled from "../../../components/preview/Modal/disabled.tsx"; +import CustomWidth from "../../../components/preview/Modal/customWidth.tsx"; +import CustomWidth2 from "../../../components/preview/Modal/customWidth2.tsx"; +import Preview from "../../../components/preview/Modal/preview.tsx"; + +## Installation + + + + + +```bash +npx ruru-ui-cli@latest add modal +``` + + +```bash +pnpm dlx ruru-ui-cli@latest add modal +``` + + +```bash +npx ruru-ui-cli@latest add modal +``` + + +```bash +bunx --bun ruru-ui-cli@latest add modal +``` + + + + + +```package-install +npm install ruru-ui@latest +``` + + + + +## Usage + +Here is an example of how to use the `Modal` component. + + + + + + +```tsx +"use client"; + +import React, { useState } from "react"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const Usage = () => { + const [isLoading, setIsLoading] = useState(false); + + const handleSubmit = async () => { + setIsLoading(true); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + setIsLoading(false); + }; + + return ( +
+ + Open Modal + + + + + Create Username + + + Enter a unique name for your token to differentiate it from + other tokens and then select the scope. + + + + + + + + Cancel + + Submit + + + + +
+ ); +}; + +export default Usage; +``` +
+
+ + +## Example + +### Modal with Trigger + +The `Modal` component can be used with a custom trigger button. + + + + + + +```tsx +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const TriggerDemo = () => { + return ( + + + + + + + + + Custom Trigger + + + This modal opens with a custom trigger button. + + + + + + + + Cancel + Submit + + + + ); +}; + +export default TriggerDemo; +``` + + + + +### Single button + +The `Modal` component can be used with a single button. + + + + + + +```tsx +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const SingleButton = () => { + return ( + + + + + + + + + Custom Trigger + + + This modal opens with a custom trigger button. + + + + + + + + Cancel + + + + ); +}; + +export default SingleButton; +``` + + + +### Disabled actions + +The `Modal` component can be used with disabled actions. + + + + + + +```tsx +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const Disabled = () => { + return ( + + + + + + + + + Custom Trigger + + + This modal opens with a custom trigger button. + + + + + + + + Cancel + Submit + + + + ); +}; + +export default Disabled; +``` + + + +### Modal with custom width + +The `Modal` component can be used with a custom width. + + + + + + +```tsx +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const CustomWidth = () => { + return ( + + + + + + + + + Custom Width + + + This modal opens with a Custom Width button. + + + + + + + + Cancel + + + + ); +}; + +export default CustomWidth; +``` + + + + + + + + +```tsx +"use client"; + +import React from "react"; +import { Button } from "ruru-ui/components/button"; +import { Input } from "ruru-ui/components/input"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; + +const CustomWidth2 = () => { + return ( + + + + + + + + + Custom Width + + + This modal opens with a Custom Width button. + + + + + + + + + Cancel + + Submit + + + + ); +}; + +export default CustomWidth2; +``` + + + +### Preview Component + +The component that you see on preview + + + + + + +```tsx +"use client"; + +import React, { useState } from "react"; +import Modal, { ModalProvider } from "ruru-ui/components/modal"; +import { Input } from "ruru-ui/components/input"; + +const Preview = () => { + const [isLoading, setIsLoading] = useState(false); + const [status, setStatus] = useState(false); + + const handleSubmit = async () => { + setIsLoading(true); + + await new Promise((resolve) => setTimeout(resolve, 2000)); + setStatus(true); + setIsLoading(false); + + await new Promise((resolve) => setTimeout(resolve, 500)); + + setStatus(false); + }; + + return ( +
+ + Deploy + + + + + Deploy to production + + + Deploy your site to production by clicking the button below. + + + + + + + + Cancel + + {status ? ( + + + + ) : ( + "Deploy" + )} + + + + +
+ ); +}; + +export default Preview; +``` +
+
+ +## Props + +Here's how the props table would look for the `Modal` component, formatted in the same style: + +## Props + +### Modal + +| Name | Type | Default | Description | +| ----------------- | --------------------------------- | ----------- | -------------------------------------------------------------------------------------- | +| **children** | **ReactNode** | `undefined` | The children of the Modal component. | +| **onClickOutside**| **() => void** | `undefined` | The function to call when the user clicks outside the modal. | + +### ModalAction + +| Name | Type | Default | Description | +| ----------------- | --------------------------------- | ----------- | -------------------------------------------------------------------------------------- | +| **fullWidth** | **boolean** | `false` | Determines if the action button should take the full width. | +| **onClick** | **() =\> void \| Promise\** | `undefined` | The function to call when the user clicks the action. | + +### Trigger + +| Name | Type | Default | Description | +| ----------------- | --------------------------------- | ----------- | -------------------------------------------------------------------------------------- | +| **children** | **ReactNode** | `undefined` | The children of the Modal component. | +| **onClick** | **() => void** | `undefined` | The function to call when the user clicks the trigger. | +| **asChild** | **boolean** | `false` | Render as a child component. | + +### DivProps + +| Name | Type | Default | Description | +| ----------------- | --------------------------------- | ----------- | -------------------------------------------------------------------------------------- | +| **className** | **string** | `""` | Additional class names for the container. | +| **children** | **ReactNode** | `undefined` | The children of the component. | + +### PTagProps + +| Name | Type | Default | Description | +| ----------------- | --------------------------------- | ----------- | -------------------------------------------------------------------------------------- | +| **className** | **string** | `""` | Additional class names for the paragraph element. | +| **children** | **ReactNode** | `undefined` | The children of the paragraph element. | + diff --git a/apps/www/content/docs/components/textarea.mdx b/apps/www/content/docs/components/textarea.mdx index 0c06252..f794464 100644 --- a/apps/www/content/docs/components/textarea.mdx +++ b/apps/www/content/docs/components/textarea.mdx @@ -11,38 +11,38 @@ import { Tabs as Rutabs, Tab as Rutab } from "ruru-ui/components/tabs"; ## Installation - - - - ```bash - npx ruru-ui-cli@latest add textarea - ``` - - - ```bash - pnpm dlx ruru-ui-cli@latest add textarea - ``` - - - ```bash - npx ruru-ui-cli@latest add textarea - ``` - - - ```bash - bunx --bun ruru-ui-cli@latest add textarea - ``` - - + + + +```bash +npx ruru-ui-cli@latest add textarea +``` + + +```bash +pnpm dlx ruru-ui-cli@latest add textarea +``` + + +```bash +npx ruru-ui-cli@latest add textarea +``` + + +```bash +bunx --bun ruru-ui-cli@latest add textarea +``` + + - - + + - ```package-install - npm install ruru-ui@latest - ``` +```package-install +npm install ruru-ui@latest +``` - + ## Usage diff --git a/apps/www/public/registry/components/modal.json b/apps/www/public/registry/components/modal.json index 7fa6bd3..9389d04 100644 --- a/apps/www/public/registry/components/modal.json +++ b/apps/www/public/registry/components/modal.json @@ -3,7 +3,7 @@ "files": [ { "name": "modal.tsx", - "content": "import React, {\n useState,\n useContext,\n useCallback,\n ReactNode,\n createContext,\n useEffect,\n} from \"react\";\nimport {\n AnimatePresence,\n ForwardRefComponent,\n HTMLMotionProps,\n motion,\n} from \"framer-motion\";\nimport { cn } from \"@/utils/cn\";\nimport { Button, ButtonProps } from \"./button\";\n\n\nexport interface ModalContextProps {\n \n isOpen: boolean;\n \n openModal: () => void;\n \n closeModal: () => void;\n}\n\n\nexport interface ModalProps\n extends Partial>> {\n \n children: ReactNode;\n \n onClickOutside?: () => void;\n}\n\n\nexport interface ModalActionProps extends ButtonProps {\n \n fullWidth?: boolean;\n \n onClick?: () => void | Promise;\n}\n\n\nexport interface TriggerProps extends ButtonProps {\n \n children: ReactNode;\n \n onClick?: () => void;\n \n asChild?: boolean;\n}\n\n\nexport interface DivProps\n extends React.DetailedHTMLProps<\n React.HTMLAttributes,\n HTMLDivElement\n > {}\n\n\nconst ModalContext = createContext(undefined);\n\n\nexport const ModalProvider = ({\n children,\n}: {\n children: ReactNode;\n}): React.ReactElement => {\n const [isOpen, setIsOpen] = useState(false);\n\n const openModal = useCallback(() => setIsOpen(true), []);\n const closeModal = useCallback(() => setIsOpen(false), []);\n\n return (\n \n {children}\n \n );\n};\n\n\nexport const useModal = (): ModalContextProps => {\n const context = useContext(ModalContext);\n if (!context) {\n throw new Error(\"useModal must be used within a ModalProvider\");\n }\n return context;\n};\n\n\nconst Modal = ({\n children,\n onClickOutside,\n ...props\n}: ModalProps): React.ReactElement => {\n const { isOpen, closeModal } = useModal();\n\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n closeModal();\n }\n };\n\n if (isOpen) {\n document.addEventListener(\"keydown\", handleEscape);\n } else {\n document.removeEventListener(\"keydown\", handleEscape);\n }\n\n return () => document.removeEventListener(\"keydown\", handleEscape);\n }, [isOpen, closeModal]);\n\n const modalVariants = {\n hidden: {\n opacity: 0,\n y: -50,\n rotateX: \"0deg\",\n transition: { duration: 0.15 },\n },\n visible: {\n opacity: 1,\n y: 0,\n rotateX: \"0deg\",\n transition: { duration: 0.15 },\n },\n exit: {\n opacity: 0,\n y: -50,\n rotateX: \"-10deg\",\n transition: { duration: 0.15 },\n },\n };\n\n return (\n \n {isOpen && (\n \n e.stopPropagation()}\n variants={modalVariants}\n initial=\"hidden\"\n animate=\"visible\"\n exit=\"exit\"\n >\n {children}\n \n \n )}\n \n );\n};\n\n\nModal.Trigger = ({\n children,\n onClick,\n asChild = false,\n}: TriggerProps): React.ReactElement => {\n const { openModal } = useModal();\n\n const handleClick = () => {\n openModal();\n if (onClick) {\n onClick();\n }\n };\n\n if (asChild) {\n return (\n
\n {children}\n
\n );\n }\n\n return ;\n};\n\n\nModal.Body = ({ children, ...props }: DivProps): React.ReactElement => (\n
\n {children}\n
\n);\n\n\nModal.Header = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n
\n {children}\n
\n);\n\n\nModal.Title = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n

\n {children}\n

\n);\n\n\nModal.Content = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n
\n {children}\n
\n);\n\n\nModal.Subtitle = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n

\n {children}\n

\n);\n\n\nModal.Actions = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n \n {children}\n \n);\n\n\nModal.Action = ({\n fullWidth = false,\n onClick,\n className,\n ...props\n}: ModalActionProps): React.ReactElement => {\n const { closeModal } = useModal();\n\n const handleClick = async () => {\n if (onClick) {\n await onClick();\n }\n closeModal();\n };\n\n return (\n \n {props.children}\n \n );\n};\n\n\nModal.Close = (props: ModalActionProps): React.ReactElement => (\n \n {props.children}\n \n);\n\nexport default Modal;\n" + "content": "\"use client\";\n\nimport React, {\n useState,\n useContext,\n useCallback,\n ReactNode,\n createContext,\n useEffect,\n} from \"react\";\nimport {\n AnimatePresence,\n ForwardRefComponent,\n HTMLMotionProps,\n motion,\n} from \"framer-motion\";\nimport { cn } from \"@/utils/cn\";\nimport { Button, ButtonProps } from \"./button\";\n\n\nexport interface ModalContextProps {\n \n isOpen: boolean;\n \n openModal: () => void;\n \n closeModal: () => void;\n}\n\n\nexport interface ModalProps\n extends Partial>> {\n \n children: ReactNode;\n \n onClickOutside?: () => void;\n}\n\n\nexport interface ModalActionProps extends ButtonProps {\n \n fullWidth?: boolean;\n \n onClick?: () => void | Promise;\n}\n\n\nexport interface TriggerProps extends ButtonProps {\n \n children: ReactNode;\n \n onClick?: () => void;\n \n asChild?: boolean;\n}\n\n\nexport interface DivProps\n extends React.DetailedHTMLProps<\n React.HTMLAttributes,\n HTMLDivElement\n > {}\n\n\nexport interface PTagProps\n extends React.DetailedHTMLProps<\n React.HTMLAttributes,\n HTMLParagraphElement\n > {}\n\n\nconst ModalContext = createContext(undefined);\n\n\nexport const ModalProvider = ({\n children,\n}: {\n children: ReactNode;\n}): React.ReactElement => {\n const [isOpen, setIsOpen] = useState(false);\n\n const openModal = useCallback(() => setIsOpen(true), []);\n const closeModal = useCallback(() => setIsOpen(false), []);\n\n return (\n \n {children}\n \n );\n};\n\n\nexport const useModal = (): ModalContextProps => {\n const context = useContext(ModalContext);\n if (!context) {\n throw new Error(\"useModal must be used within a ModalProvider\");\n }\n return context;\n};\n\n\nconst Modal = ({\n children,\n onClickOutside,\n ...props\n}: ModalProps): React.ReactElement => {\n const { isOpen, closeModal } = useModal();\n\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n closeModal();\n }\n };\n\n if (isOpen) {\n document.addEventListener(\"keydown\", handleEscape);\n } else {\n document.removeEventListener(\"keydown\", handleEscape);\n }\n\n return () => document.removeEventListener(\"keydown\", handleEscape);\n }, [isOpen, closeModal]);\n\n const modalVariants = {\n hidden: {\n opacity: 0,\n y: -50,\n rotateX: \"0deg\",\n transition: { duration: 0.15 },\n },\n visible: {\n opacity: 1,\n y: 0,\n rotateX: \"0deg\",\n transition: { duration: 0.15 },\n },\n exit: {\n opacity: 0,\n y: -50,\n rotateX: \"-10deg\",\n transition: { duration: 0.15 },\n },\n };\n\n return (\n \n {isOpen && (\n \n e.stopPropagation()}\n variants={modalVariants}\n initial=\"hidden\"\n animate=\"visible\"\n exit=\"exit\"\n >\n {children}\n \n \n )}\n \n );\n};\n\n\nModal.Trigger = ({\n children,\n onClick,\n asChild = false,\n}: TriggerProps): React.ReactElement => {\n const { openModal } = useModal();\n\n const handleClick = () => {\n openModal();\n if (onClick) {\n onClick();\n }\n };\n\n if (asChild) {\n return (\n
\n {children}\n
\n );\n }\n\n return ;\n};\n\n\nModal.Body = ({ children, ...props }: DivProps): React.ReactElement => (\n
\n {children}\n
\n);\n\n\nModal.Header = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n
\n {children}\n
\n);\n\n\nModal.Title = ({\n children,\n className,\n ...props\n}: PTagProps): React.ReactElement => (\n

\n {children}\n

\n);\n\n\nModal.Content = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n
\n {children}\n
\n);\n\n\nModal.Subtitle = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n

\n {children}\n

\n);\n\n\nModal.Actions = ({\n children,\n className,\n ...props\n}: DivProps): React.ReactElement => (\n \n {children}\n \n);\n\n\nModal.Action = ({\n fullWidth = false,\n onClick,\n className,\n ...props\n}: ModalActionProps): React.ReactElement => {\n const { closeModal } = useModal();\n\n const handleClick = async () => {\n if (onClick) {\n await onClick();\n }\n closeModal();\n };\n\n return (\n \n {props.children}\n \n );\n};\n\n\nModal.Close = (props: ModalActionProps): React.ReactElement => (\n \n {props.children}\n \n);\n\nexport default Modal;\n" } ], "type": "components:ui", diff --git a/packages/ui/src/components/modal.tsx b/packages/ui/src/components/modal.tsx index 193ac33..017e5d7 100644 --- a/packages/ui/src/components/modal.tsx +++ b/packages/ui/src/components/modal.tsx @@ -1,3 +1,5 @@ +"use client"; + import React, { useState, useContext, @@ -109,6 +111,15 @@ export interface DivProps HTMLDivElement > {} +/** + * Represents the props for the Modal component. + */ +export interface PTagProps + extends React.DetailedHTMLProps< + React.HTMLAttributes, + HTMLParagraphElement + > {} + /** * Represents the Modal component. * @@ -296,17 +307,17 @@ Modal.Header = ({ /** * Represents the Modal component. * - * @param {DivProps} props - The props for the Modal component. + * @param {PTagProps} props - The props for the Modal component. * @returns {React.ReactElement} */ Modal.Title = ({ children, className, ...props -}: DivProps): React.ReactElement => ( -

+}: PTagProps): React.ReactElement => ( +

{children} -

+

); /**