diff --git a/apps/docs/content/components/alert/colors.raw.jsx b/apps/docs/content/components/alert/colors.raw.jsx new file mode 100644 index 0000000000..a4d123eae5 --- /dev/null +++ b/apps/docs/content/components/alert/colors.raw.jsx @@ -0,0 +1,15 @@ +import {Alert} from "@nextui-org/react"; + +export default function App() { + return ( +
+
+ {["default", "primary", "secondary", "success", "warning", "danger"].map((color) => ( +
+ +
+ ))} +
+
+ ); +} diff --git a/apps/docs/content/components/alert/colors.ts b/apps/docs/content/components/alert/colors.ts index 8e88d2ef12..d5bef810aa 100644 --- a/apps/docs/content/components/alert/colors.ts +++ b/apps/docs/content/components/alert/colors.ts @@ -1,21 +1,4 @@ -const App = `import {Alert} from "@nextui-org/react"; - -export default function App() { - return ( -
-
- {["default", "primary", "secondary", "success", "warning", "danger"].map((color) => ( -
- -
- ))} -
-
- ); -}`; +import App from "./colors.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/controlled.raw.jsx b/apps/docs/content/components/alert/controlled.raw.jsx new file mode 100644 index 0000000000..59444db376 --- /dev/null +++ b/apps/docs/content/components/alert/controlled.raw.jsx @@ -0,0 +1,28 @@ +import {Alert, Button} from "@nextui-org/react"; + +export default function App() { + const [isVisible, setIsVisible] = React.useState(true); + + const title = "Success Notification"; + const description = + "Your action has been completed successfully. We'll notify you when updates are available."; + + return ( +
+ {isVisible ? ( + setIsVisible(false)} + /> + ) : ( + + )} +
+ ); +} diff --git a/apps/docs/content/components/alert/controlled.ts b/apps/docs/content/components/alert/controlled.ts index 33af02947f..2c3f0cacb4 100644 --- a/apps/docs/content/components/alert/controlled.ts +++ b/apps/docs/content/components/alert/controlled.ts @@ -1,33 +1,4 @@ -const App = `import {Alert, Button} from "@nextui-org/react"; - -export default function App() { - const [isVisible, setIsVisible] = React.useState(true); - - const title = "Success Notification"; - const description = "Your action has been completed successfully. We'll notify you when updates are available."; - - return ( -
- {isVisible ? ( - setIsVisible(false)} - /> - ) : ( - - )} -
- ); -}`; +import App from "./controlled.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/custom-impl.raw.jsx b/apps/docs/content/components/alert/custom-impl.raw.jsx new file mode 100644 index 0000000000..a541c7481d --- /dev/null +++ b/apps/docs/content/components/alert/custom-impl.raw.jsx @@ -0,0 +1,124 @@ +import React, {forwardRef, useMemo} from "react"; +import {useAlert} from "@nextui-org/react"; + +export const InfoCircleIcon = (props) => { + return ( + + + + ); +}; + +export const CloseIcon = (props) => { + return ( + + ); +}; + +const styles = { + base: [ + "bg-slate-100", + "border", + "shadow", + "hover:bg-slate-200", + "focus-within:!bg-slate-100", + "dark:bg-slate-900", + "dark:hover:bg-slate-800", + "dark:border-slate-800", + "dark:focus-within:!bg-slate-900", + "cursor-pointer", + ], + title: ["text-base", "text-slate-500", "font-bold"], + description: ["text-base", "text-slate-500"], +}; + +const MyAlert = forwardRef((props, ref) => { + const { + title, + description, + isClosable, + domRef, + handleClose, + getBaseProps, + getMainWrapperProps, + getDescriptionProps, + getTitleProps, + getCloseButtonProps, + color, + isVisible, + onClose, + getAlertIconProps, + } = useAlert({ + ...props, + ref, + // this is just for the example, the props bellow should be passed by the parent component + title: "Email Sent!!", + description: "You will get a reply soon", + // custom styles + classNames: { + ...styles, + }, + }); + + const mainWrapper = useMemo(() => { + return ( +
+ {title &&
{title}
} +
{description}
+
+ ); + }, [title, description, getMainWrapperProps, getTitleProps, getDescriptionProps]); + + const baseWrapper = useMemo(() => { + return isVisible ? ( +
+ + {mainWrapper} + {(isClosable || onClose) && ( + + )} +
+ ) : null; + }, [ + mainWrapper, + isClosable, + getCloseButtonProps, + isVisible, + domRef, + getBaseProps, + handleClose, + color, + onClose, + getAlertIconProps, + ]); + + return <>{baseWrapper}; +}); + +MyAlert.displayName = "MyAlert"; + +export default MyAlert; diff --git a/apps/docs/content/components/alert/custom-impl.ts b/apps/docs/content/components/alert/custom-impl.ts index 9f5a2c70a2..ab37512cec 100644 --- a/apps/docs/content/components/alert/custom-impl.ts +++ b/apps/docs/content/components/alert/custom-impl.ts @@ -1,140 +1,7 @@ -const InfoCircleIcon = `export const InfoCircleIcon = (props) => ( - - - -);`; - -const CloseIcon = `export const CloseIcon = (props) => ( - -);`; - -const App = `import React, {forwardRef, useMemo} from "react"; -import {useAlert} from "@nextui-org/react"; -import {InfoCircleIcon} from "./InfoCircleIcon"; -import {CloseIcon} from "./CloseIcon" - -const styles = { - base: [ - "bg-slate-100", - "border", - "shadow", - "hover:bg-slate-200", - "focus-within:!bg-slate-100", - "dark:bg-slate-900", - "dark:hover:bg-slate-800", - "dark:border-slate-800", - "dark:focus-within:!bg-slate-900", - "cursor-pointer" - ], - title: [ - "text-base", - "text-slate-500", - "font-bold" - ], - description: [ - "text-base", - "text-slate-500", - ], -} - -const MyAlert = forwardRef((props, ref) => { - const { - title, - description, - isClosable, - domRef, - handleClose, - getBaseProps, - getMainWrapperProps, - getDescriptionProps, - getTitleProps, - getCloseButtonProps, - color, - isVisible, - onClose, - getCloseIconProps, - getAlertIconProps, - } = useAlert({ - ...props, - ref, - // this is just for the example, the props bellow should be passed by the parent component - title: "Email Sent!!", - description: "You will get a reply soon", - // custom styles - classNames: { - ...styles, - }, - }); - - const mainWrapper = useMemo(() => { - return ( -
- {title &&
{title}
} -
{description}
-
- ); - }, [title, description, getMainWrapperProps, getTitleProps, getDescriptionProps]); - - const baseWrapper = useMemo(() => { - return isVisible ? ( -
- - {mainWrapper} - {(isClosable || onClose) && ( - - )} -
- ) : null; - }, [ - mainWrapper, - isClosable, - getCloseButtonProps, - isVisible, - domRef, - getBaseProps, - handleClose, - color, - onClose, - getAlertIconProps, - ]); - - return <>{baseWrapper}; -}); - -MyAlert.displayName = "MyAlert"; - -export default MyAlert;`; +import App from "./custom-impl.raw.jsx?raw"; const react = { "/App.jsx": App, - "/InfoCircleIcon": InfoCircleIcon, - "/CloseIcon": CloseIcon, }; export default { diff --git a/apps/docs/content/components/alert/custom-styles.raw.jsx b/apps/docs/content/components/alert/custom-styles.raw.jsx new file mode 100644 index 0000000000..8291720ae1 --- /dev/null +++ b/apps/docs/content/components/alert/custom-styles.raw.jsx @@ -0,0 +1,91 @@ +import {Alert, Button} from "@nextui-org/react"; + +const CustomAlert = React.forwardRef( + ( + {title, children, variant = "faded", color = "secondary", className, classNames = {}, ...props}, + ref, + ) => { + const colorClass = React.useMemo(() => { + switch (color) { + case "default": + return "before:bg-default-300"; + case "primary": + return "before:bg-primary"; + case "secondary": + return "before:bg-secondary"; + case "success": + return "before:bg-success"; + case "warning": + return "before:bg-warning"; + case "danger": + return "before:bg-danger"; + default: + return "before:bg-default-200"; + } + }, []); + + return ( + + {children} + + ); + }, +); + +CustomAlert.displayName = "CustomAlert"; + +export default function App() { + const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; + + return ( +
+ {colors.map((color) => ( + +
+ + +
+
+ ))} +
+ ); +} diff --git a/apps/docs/content/components/alert/custom-styles.raw.tsx b/apps/docs/content/components/alert/custom-styles.raw.tsx new file mode 100644 index 0000000000..9056bf91c8 --- /dev/null +++ b/apps/docs/content/components/alert/custom-styles.raw.tsx @@ -0,0 +1,94 @@ +import type {AlertProps} from "@nextui-org/react"; + +import React from "react"; +import {Alert, Button, cn} from "@nextui-org/react"; + +const CustomAlert = React.forwardRef( + ( + {title, children, variant = "faded", color = "secondary", className, classNames, ...props}, + ref, + ) => { + const colorClass = React.useMemo(() => { + switch (color) { + case "default": + return "before:bg-default-300"; + case "primary": + return "before:bg-primary"; + case "secondary": + return "before:bg-secondary"; + case "success": + return "before:bg-success"; + case "warning": + return "before:bg-warning"; + case "danger": + return "before:bg-danger"; + default: + return "before:bg-default-200"; + } + }, []); + + return ( + + {children} + + ); + }, +); + +CustomAlert.displayName = "CustomAlert"; + +export default function App() { + const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; + + return ( +
+ {colors.map((color) => ( + +
+ + +
+
+ ))} +
+ ); +} diff --git a/apps/docs/content/components/alert/custom-styles.ts b/apps/docs/content/components/alert/custom-styles.ts index 437c8f35ee..29cf5fd0ee 100644 --- a/apps/docs/content/components/alert/custom-styles.ts +++ b/apps/docs/content/components/alert/custom-styles.ts @@ -1,192 +1,15 @@ -const AppTs = `import {Alert, Button} from "@nextui-org/react"; - -const CustomAlert = React.forwardRef( - ( - {title, children, variant = "faded", color = "secondary", className, classNames, ...props}, - ref, - ) => { - const colorClass = React.useMemo(() => { - switch (color) { - case "default": - return "before:bg-default-300"; - case "primary": - return "before:bg-primary"; - case "secondary": - return "before:bg-secondary"; - case "success": - return "before:bg-success"; - case "warning": - return "before:bg-warning"; - case "danger": - return "before:bg-danger"; - default: - return "before:bg-default-200"; - } - }, []); - - return ( - - {children} - - ); - }, -); - -CustomAlert.displayName = "CustomAlert"; - -export default function App() { - const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; - - return ( -
- {colors.map((color) => ( - -
- - -
-
- ))} -
- ); -}`; - -const App = `import {Alert, Button} from "@nextui-org/react"; - -const CustomAlert = React.forwardRef( - ( - {title, children, variant = "faded", color = "secondary", className, classNames = {}, ...props}, - ref, - ) => { - const colorClass = React.useMemo(() => { - switch (color) { - case "default": - return "before:bg-default-300"; - case "primary": - return "before:bg-primary"; - case "secondary": - return "before:bg-secondary"; - case "success": - return "before:bg-success"; - case "warning": - return "before:bg-warning"; - case "danger": - return "before:bg-danger"; - default: - return "before:bg-default-200"; - } - }, []); - - return ( - - {children} - - ); - }, -); - -CustomAlert.displayName = "CustomAlert"; - -export default function App() { - const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; - - return ( -
- {colors.map((color) => ( - -
- - -
-
- ))} -
- ); -}`; +import App from "./custom-styles.raw.jsx?raw"; +import AppTs from "./custom-styles.raw.tsx?raw"; const react = { "/App.jsx": App, +}; + +const reactTs = { "/App.tsx": AppTs, }; export default { ...react, + ...reactTs, }; diff --git a/apps/docs/content/components/alert/radius.raw.jsx b/apps/docs/content/components/alert/radius.raw.jsx new file mode 100644 index 0000000000..07b2f9c5a8 --- /dev/null +++ b/apps/docs/content/components/alert/radius.raw.jsx @@ -0,0 +1,15 @@ +import {Alert} from "@nextui-org/react"; + +export default function App() { + return ( +
+
+ {["none", "sm", "md", "lg", "full"].map((radius) => ( +
+ +
+ ))} +
+
+ ); +} diff --git a/apps/docs/content/components/alert/radius.ts b/apps/docs/content/components/alert/radius.ts index abbf3f5f52..7b78db1ce0 100644 --- a/apps/docs/content/components/alert/radius.ts +++ b/apps/docs/content/components/alert/radius.ts @@ -1,21 +1,4 @@ -const App = `import {Alert} from "@nextui-org/react"; - -export default function App() { - return ( -
-
- {["none", "sm", "md", "lg", "full"].map((radius) => ( -
- -
- ))} -
-
- ); -}`; +import App from "./radius.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/usage.raw.jsx b/apps/docs/content/components/alert/usage.raw.jsx new file mode 100644 index 0000000000..3b5a727e9b --- /dev/null +++ b/apps/docs/content/components/alert/usage.raw.jsx @@ -0,0 +1,12 @@ +import {Alert} from "@nextui-org/react"; + +export default function App() { + const title = "This is an alert"; + const description = "Thanks for subscribing to our newsletter!"; + + return ( +
+ +
+ ); +} diff --git a/apps/docs/content/components/alert/usage.ts b/apps/docs/content/components/alert/usage.ts index 6543526891..1118304c37 100644 --- a/apps/docs/content/components/alert/usage.ts +++ b/apps/docs/content/components/alert/usage.ts @@ -1,15 +1,4 @@ -const App = `import {Alert} from "@nextui-org/react"; - -export default function App() { - const title = "This is an alert"; - const description = "Thanks for subscribing to our newsletter!"; - - return ( -
- -
- ); -}`; +import App from "./usage.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/variants.raw.jsx b/apps/docs/content/components/alert/variants.raw.jsx new file mode 100644 index 0000000000..1bb83af6b3 --- /dev/null +++ b/apps/docs/content/components/alert/variants.raw.jsx @@ -0,0 +1,16 @@ +import {Alert} from "@nextui-org/react"; + +export default function App() { + return ( +
+ {["solid", "bordered", "flat", "faded"].map((variant) => ( + + ))} +
+ ); +} diff --git a/apps/docs/content/components/alert/variants.ts b/apps/docs/content/components/alert/variants.ts index 07238ee96f..ddea95fb2e 100644 --- a/apps/docs/content/components/alert/variants.ts +++ b/apps/docs/content/components/alert/variants.ts @@ -1,14 +1,4 @@ -const App = `import {Alert} from "@nextui-org/react"; - -export default function App() { - return ( -
- {["solid", "bordered", "flat", "faded"].map((variant) => ( - - ))} -
- ); -}`; +import App from "./variants.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/with-action.raw.jsx b/apps/docs/content/components/alert/with-action.raw.jsx new file mode 100644 index 0000000000..8e4ee60a88 --- /dev/null +++ b/apps/docs/content/components/alert/with-action.raw.jsx @@ -0,0 +1,19 @@ +import {Alert, Button} from "@nextui-org/react"; + +export default function App() { + return ( +
+ + Upgrade + + } + title="You have no credits left" + variant="faded" + /> +
+ ); +} diff --git a/apps/docs/content/components/alert/with-action.ts b/apps/docs/content/components/alert/with-action.ts index b4f9665f62..1bb611e21b 100644 --- a/apps/docs/content/components/alert/with-action.ts +++ b/apps/docs/content/components/alert/with-action.ts @@ -1,24 +1,4 @@ -const App = `import {Alert, Button} from "@nextui-org/react"; - -export default function App() { - const [isVisible, setIsVisible] = React.useState(true); - - return ( -
- - Upgrade - - } - title="You have no credits left" - variant="faded" - /> -
- ); -}`; +import App from "./with-action.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/with-icon.raw.jsx b/apps/docs/content/components/alert/with-icon.raw.jsx new file mode 100644 index 0000000000..831e78982f --- /dev/null +++ b/apps/docs/content/components/alert/with-icon.raw.jsx @@ -0,0 +1,33 @@ +import {Alert} from "@nextui-org/react"; + +const UserIcon = ({fill = "currentColor", size, height, width, ...props}) => { + return ( + + + + + + + ); +}; + +export default function App() { + return }>An alert with a custom icon; +} diff --git a/apps/docs/content/components/alert/with-icon.ts b/apps/docs/content/components/alert/with-icon.ts index dd722fe63d..ca7c79da7b 100644 --- a/apps/docs/content/components/alert/with-icon.ts +++ b/apps/docs/content/components/alert/with-icon.ts @@ -1,49 +1,4 @@ -const App = `import {Alert} from "@nextui-org/react"; - -const UserIcon = ({ - fill = 'currentColor', - filled, - size, - height, - width, - label, - ...props -}) => { - return ( - - - - - - - ); -}; - -export default function App() { - return ( - }>An alert with a custom icon - ); -}`; +import App from "./with-icon.raw.jsx?raw"; const react = { "/App.jsx": App, diff --git a/apps/docs/content/components/alert/without-icon.raw.jsx b/apps/docs/content/components/alert/without-icon.raw.jsx new file mode 100644 index 0000000000..bd25d413ed --- /dev/null +++ b/apps/docs/content/components/alert/without-icon.raw.jsx @@ -0,0 +1,12 @@ +import {Alert} from "@nextui-org/react"; + +export default function App() { + const title = "This is an alert"; + const description = "Thanks for subscribing to our newsletter!"; + + return ( +
+ +
+ ); +} diff --git a/apps/docs/content/components/alert/without-icon.ts b/apps/docs/content/components/alert/without-icon.ts index b3432e6802..3c177c66b3 100644 --- a/apps/docs/content/components/alert/without-icon.ts +++ b/apps/docs/content/components/alert/without-icon.ts @@ -1,21 +1,4 @@ -const App = `import {Alert} from "@nextui-org/react"; - -export default function App() { - const title = "This is an alert"; - const description = "Thanks for subscribing to our newsletter!"; - - return ( -
- -
- ); -}`; +import App from "./without-icon.raw.jsx?raw"; const react = { "/App.jsx": App,