diff --git a/.changeset/sixty-ties-knock.md b/.changeset/sixty-ties-knock.md new file mode 100644 index 0000000000..e8046181a1 --- /dev/null +++ b/.changeset/sixty-ties-knock.md @@ -0,0 +1,6 @@ +--- +"@nextui-org/alert": patch +"@nextui-org/theme": patch +--- + +Alert compoentn styles improved diff --git a/apps/docs/content/components/alert/custom-styles.ts b/apps/docs/content/components/alert/custom-styles.ts index 5a9aeb1af0..437c8f35ee 100644 --- a/apps/docs/content/components/alert/custom-styles.ts +++ b/apps/docs/content/components/alert/custom-styles.ts @@ -1,60 +1,190 @@ -const App = `import {Alert, Button} from "@nextui-org/react"; +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 [isVisible, setIsVisible] = React.useState(true); + const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; return ( -
- {!isVisible && ( - - )} +
+ + +
+ + ))} +
+ ); +}`; + +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 ( setIsVisible(false)} + color={color} + title={title} + variant={variant} + {...props} > -
- - -
+ {children}
+ ); + }, +); + +CustomAlert.displayName = "CustomAlert"; + +export default function App() { + const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; + + return ( +
+ {colors.map((color) => ( + +
+ + +
+
+ ))}
); }`; const react = { "/App.jsx": App, + "/App.tsx": AppTs, }; export default { diff --git a/apps/docs/content/components/alert/variants.ts b/apps/docs/content/components/alert/variants.ts index 48f57385c7..07238ee96f 100644 --- a/apps/docs/content/components/alert/variants.ts +++ b/apps/docs/content/components/alert/variants.ts @@ -4,7 +4,7 @@ export default function App() { return (
{["solid", "bordered", "flat", "faded"].map((variant) => ( - + ))}
); diff --git a/packages/components/alert/src/alert.tsx b/packages/components/alert/src/alert.tsx index 384ed1d0fb..cc8c9a691d 100644 --- a/packages/components/alert/src/alert.tsx +++ b/packages/components/alert/src/alert.tsx @@ -24,9 +24,7 @@ const iconMap = { export type AlertColor = keyof typeof iconMap; -export interface AlertProps extends Omit { - color: AlertColor; -} +export interface AlertProps extends Omit {} const Alert = forwardRef<"div", AlertProps>((props, ref) => { const { diff --git a/packages/components/alert/stories/alert.stories.tsx b/packages/components/alert/stories/alert.stories.tsx index 581a1cf236..cbdac9aa6b 100644 --- a/packages/components/alert/stories/alert.stories.tsx +++ b/packages/components/alert/stories/alert.stories.tsx @@ -1,9 +1,9 @@ import React from "react"; import {Meta} from "@storybook/react"; -import {alert} from "@nextui-org/theme"; +import {alert, cn} from "@nextui-org/theme"; import {Button} from "@nextui-org/button"; -import {Alert} from "../src"; +import {Alert, AlertProps} from "../src"; export default { title: "Components/Alert", @@ -120,57 +120,94 @@ const WithEndContentTemplate = (args) => { ); }; -export const CustomStylesTemplate = (args) => { - const [isVisible, setIsVisible] = React.useState(true); +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 ( - <> - {!isVisible && ( - - )} + return ( setIsVisible(false)} + color={color} + title={title} + variant={variant} + {...props} > -
- - -
+
{children}
- + ); + }, +); + +CustomAlert.displayName = "CustomAlert"; + +const CustomStylesTemplate = (args) => { + const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; + + return ( +
+ {colors.map((color) => ( + +
+ + +
+
+ ))} +
); }; diff --git a/packages/core/theme/src/components/alert.ts b/packages/core/theme/src/components/alert.ts index bc76f4dd23..6ec5039767 100644 --- a/packages/core/theme/src/components/alert.ts +++ b/packages/core/theme/src/components/alert.ts @@ -146,7 +146,7 @@ const alert = tv({ class: { base: [ colorVariants.flat.default, - "bg-default-100 dark:bg-default-50", + "bg-default-100 dark:bg-default-50/50", "text-default-foreground", ], description: "text-default-600", @@ -158,7 +158,7 @@ const alert = tv({ variant: ["flat", "faded"], color: "primary", class: { - base: [colorVariants.flat.primary, "bg-primary-50"], + base: [colorVariants.flat.primary, "bg-primary-50 dark:bg-primary-50/50"], closeButton: "text-primary-500 data-[hover]:bg-primary-200", iconWrapper: "bg-primary-50 dark:bg-primary-100 border-primary-100", }, @@ -167,7 +167,7 @@ const alert = tv({ variant: ["flat", "faded"], color: "secondary", class: { - base: [colorVariants.flat.secondary, "bg-secondary-50"], + base: [colorVariants.flat.secondary, "bg-secondary-50 dark:bg-secondary-50/50"], closeButton: "text-secondary-500 data-[hover]:bg-secondary-200", iconWrapper: "bg-secondary-50 dark:bg-secondary-100 border-secondary-100", }, @@ -176,7 +176,7 @@ const alert = tv({ variant: ["flat", "faded"], color: "success", class: { - base: [colorVariants.flat.success, "bg-success-50"], + base: [colorVariants.flat.success, "bg-success-50 dark:bg-success-50/50"], closeButton: "text-success-500 data-[hover]:bg-success-200", iconWrapper: "bg-success-50 dark:bg-success-100 border-success-100", }, @@ -185,7 +185,7 @@ const alert = tv({ variant: ["flat", "faded"], color: "warning", class: { - base: [colorVariants.flat.warning, "bg-warning-50"], + base: [colorVariants.flat.warning, "bg-warning-50 dark:bg-warning-50/50"], closeButton: "text-warning-500 data-[hover]:bg-warning-200", iconWrapper: "bg-warning-50 dark:bg-warning-100 border-warning-100", }, @@ -194,7 +194,7 @@ const alert = tv({ variant: ["flat", "faded"], color: "danger", class: { - base: [colorVariants.flat.danger, "bg-danger-50"], + base: [colorVariants.flat.danger, "bg-danger-50 dark:bg-danger-50/50"], closeButton: "text-danger-500 data-[hover]:bg-danger-200", iconWrapper: "bg-danger-50 dark:bg-danger-100 border-danger-100", }, @@ -211,7 +211,7 @@ const alert = tv({ variant: "faded", color: "primary", class: { - base: "border-primary-200", + base: "border-primary-200 dark:border-primary-100", }, }, { @@ -225,14 +225,14 @@ const alert = tv({ variant: "faded", color: "success", class: { - base: "border-success-200 dark:border-success-100", + base: "border-success-300 dark:border-success-100", }, }, { variant: "faded", color: "warning", class: { - base: "border-warning-200 dark:border-warning-100", + base: "border-warning-300 dark:border-warning-100", }, }, {