Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: alert component #3680

Open
wants to merge 66 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
efb8ec6
feat(alert): began the work on alert component
abhinav700 Aug 23, 2024
d746f6c
fix(readme): making correction
abhinav700 Aug 23, 2024
0de2883
chore(deps): change to 2.0.0
wingkwong Aug 23, 2024
55b479e
chore(docs): update README.md
wingkwong Aug 23, 2024
f2b5252
feat(theme): init alert tv
wingkwong Aug 23, 2024
4634e11
chore(alert): update package.json
wingkwong Aug 23, 2024
547a9dc
feat(alert): init alert storybook structure
wingkwong Aug 23, 2024
d302984
chore(changeset): add changeset
wingkwong Aug 23, 2024
dbc3e44
Merge branch 'adding_alert_component' of https://github.com/abhinav70…
wingkwong Aug 23, 2024
e783488
chore(changeset): change to minor
wingkwong Aug 23, 2024
98589e7
chore(alert): revise alert package.json
wingkwong Aug 23, 2024
d352f9b
feat(alert): init test structure
wingkwong Aug 23, 2024
4a9e147
chore(deps): pnpm-lock.yaml
wingkwong Aug 23, 2024
c079cc0
feat(alert): initailized theme and basic structure
abhinav700 Aug 28, 2024
d8f5b5e
feat(alert): completed use-alert.ts and alert.tsx
abhinav700 Aug 28, 2024
7d13e87
feat(alert): remove innerWrapper, replace helperWrapper with mainWrap…
abhinav700 Aug 29, 2024
e957365
feat(alert): adding isCloseable prop to baseWrapper dependency
abhinav700 Aug 29, 2024
5f7f907
Merge branch 'nextui-org:canary' into adding_alert_component
abhinav700 Aug 29, 2024
b1e031e
feat(alert): setting the default value of isCloseable prop to true
abhinav700 Aug 30, 2024
e56acda
feat(alert): moving CloseIcon inside the button
abhinav700 Aug 30, 2024
099378d
feat(alert): updated package.json
abhinav700 Aug 30, 2024
7402add
feat(alert): default variant and default story
abhinav700 Aug 30, 2024
e60dea2
feat(alert): adding color and radius stories
abhinav700 Aug 31, 2024
4fcb4c0
feat(alert): completed the styling
abhinav700 Aug 31, 2024
248fecd
feat(alert): add stories for isCloseable prop and restyle other stories
abhinav700 Aug 31, 2024
bc9205e
feat(alert): correcting ref type
abhinav700 Sep 1, 2024
2d94b00
feat(alert): add test cases
abhinav700 Sep 1, 2024
a699cc4
feat(alert): remove startContent and endContent props
abhinav700 Sep 1, 2024
81552c8
feat(alert): make styling more accurate
abhinav700 Sep 1, 2024
e185212
feat(alert): fixed default props
abhinav700 Sep 1, 2024
9c727c2
feat(alert): fixed theme docs
abhinav700 Sep 1, 2024
26198ec
feat(alert): add logic for icons
abhinav700 Sep 1, 2024
b29ccae
feat(alert): begin to add docs
abhinav700 Sep 2, 2024
c74b064
chore(alert): implement the changes suggested in code review
abhinav700 Sep 3, 2024
64a4178
feat(alert): add onclose prop to alert
abhinav700 Sep 3, 2024
a83282b
feat(alert): add test cases
abhinav700 Sep 3, 2024
12b5f36
docs(alert): add onClose event
abhinav700 Sep 3, 2024
f7fd9c7
feat(docs): add alert to routes.json
wingkwong Sep 3, 2024
14bea4a
fix(alert): correct the text colors
abhinav700 Sep 4, 2024
44efbaf
docs(alert): fix imports and syntax errors
abhinav700 Sep 4, 2024
9897573
chore(alert): implement the changes suggested in code review
abhinav700 Sep 4, 2024
d271053
chore(alert): lint the code and change isCloseable to isClosable
abhinav700 Sep 5, 2024
e6efe4f
chore(alert): lint the code
abhinav700 Sep 6, 2024
e4aa2ac
chore(alert): recover the branch
abhinav700 Sep 6, 2024
7003759
chore(alert): run pnpm i
abhinav700 Sep 6, 2024
71fa1f3
Merge branch 'nextui-org:canary' into adding_alert_component
abhinav700 Sep 28, 2024
13102e8
fix(alert): fix the logic for close button and add test case
abhinav700 Sep 29, 2024
f4dbcf9
docs(alert): fix docs, change isCloseable to isClosable and change do…
abhinav700 Sep 29, 2024
3f3a7d0
chore(alert): add the support for RTL, refactor the code and fix the …
abhinav700 Sep 29, 2024
04c5a14
docs(alert): grammer issues fix
abhinav700 Sep 29, 2024
316fa11
fix(alert): replace rtl with ms
abhinav700 Sep 29, 2024
29c38e2
Merge branch 'canary' into pr/3680
wingkwong Oct 5, 2024
7069361
chore(alert): custom style and custom implementation, remove isClosab…
abhinav700 Oct 7, 2024
d1609eb
chore(alert): linting and implement coderabbit suggestions
abhinav700 Oct 7, 2024
af2adc2
chore(alert): refactor and typos fix
abhinav700 Oct 9, 2024
61df0e4
chore(alert): add import for closeIcon
abhinav700 Oct 10, 2024
7202be5
chore(alert): add props for closeIcon
abhinav700 Oct 10, 2024
682e9be
chore(alert): refactor fixes
abhinav700 Oct 13, 2024
c9a3781
chore(alert): implement ryo-manba's suggestion on close Icon
abhinav700 Oct 15, 2024
9567d16
chore(alert): make alert more responsive
abhinav700 Oct 15, 2024
22c6a51
chore(alert): fix grammer issues suggested by coderabbit
abhinav700 Oct 16, 2024
427c4fe
fix(alert): add max-w property to make alert responsive
abhinav700 Oct 16, 2024
c4b0987
chore(alert): improve responsiveness and refactor alertIcon
abhinav700 Oct 19, 2024
c1d0ae9
chore(alert): add missing dependency to useMemo
abhinav700 Oct 19, 2024
02dd710
chore(alert): implement coderabbit's suggestions
abhinav700 Oct 19, 2024
0e6e8a8
Merge branch 'nextui-org:canary' into adding_alert_component
abhinav700 Oct 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/poor-sheep-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nextui-org/alert": minor
"@nextui-org/theme": minor
---

introduced Alert component (#2250)
6 changes: 6 additions & 0 deletions apps/docs/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
"keywords": "autocomplete, auto suggest, search, typeahead",
"path": "/docs/components/autocomplete.mdx"
},
{
"key": "alert",
"title": "Alert",
"keywords": "alert, notification, message",
"path": "/docs/components/alert.mdx"
},
{
"key": "avatar",
"title": "Avatar",
Expand Down
27 changes: 27 additions & 0 deletions apps/docs/content/components/alert/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const App = `import {Alert} from "@nextui-org/react";

export default function App() {
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
const title = "Email Sent!!";
const description = "You will get a reply soon";
Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using constants or a configuration object for alert content.

The title and description are currently hardcoded. To improve reusability and facilitate potential internationalization, consider defining these strings as constants or part of a configuration object.

Here's a suggested approach:

const ALERT_CONTENT = {
  title: "Email Sent!!",
  description: "You will get a reply soon"
};

// Then in your component:
const { title, description } = ALERT_CONTENT;

This change would make it easier to update content and potentially support multiple languages in the future.


return (
<div className="flex items-center justify-center w-screen">
<div className="flex flex-col">
{["default", "primary", "secondary", "success", "warning", "danger"].map((color) => (
<div key={color} className="w-full flex justify-between items-center my-3">
<span className="mx-4 text-md">{color}</span>
<Alert title={title} description={description} color={color} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding dismissibility to the Alert component.

The current implementation showcases the Alert component with different colors, which is great. However, one of the objectives mentioned in the PR was to allow users to dismiss the alert. Consider adding a dismissible prop or an onClose handler to the Alert component to fulfill this requirement.

Here's a suggested modification:

<Alert 
  title={title} 
  description={description} 
  color={color} 
  dismissible
  onClose={() => console.log(`${color} alert closed`)}
/>

This change would allow users to dismiss the alert, aligning with the PR objectives and enhancing user interaction.

</div>
))}
</div>
</div>
);
}`;

const react = {
"/App.jsx": App,
};
Comment on lines +21 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure consistency in file extensions

The react object uses the file extension ".jsx", but the component is defined in a ".ts" file. This inconsistency might lead to confusion or issues in the build process.

Consider changing the file extension to match the actual file type:

const react = {
  "/App.ts": App,
};

Alternatively, if you implement the suggested refactoring to move the component to a separate file, use the appropriate extension:

const react = {
  "/App.tsx": App,
};

This change will ensure consistency between the file naming and the actual file type, potentially preventing build issues and improving clarity for other developers.


export default {
...react,
};
140 changes: 140 additions & 0 deletions apps/docs/content/components/alert/custom-impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
const InfoCircleIcon = `export const InfoCircleIcon = (props) => (
<svg
fill="none"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22ZM12.75 16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16L11.25 11C11.25 10.59 11.59 10.25 12 10.25C12.41 10.25 12.75 10.59 12.75 11L12.75 16ZM11.08 7.62C11.13 7.49 11.2 7.39 11.29 7.29C11.39 7.2 11.5 7.13 11.62 7.08C11.74 7.03 11.87 7 12 7C12.13 7 12.26 7.03 12.38 7.08C12.5 7.13 12.61 7.2 12.71 7.29C12.8 7.39 12.87 7.49 12.92 7.62C12.97 7.74 13 7.87 13 8C13 8.13 12.97 8.26 12.92 8.38C12.87 8.5 12.8 8.61 12.71 8.71C12.61 8.8 12.5 8.87 12.38 8.92C12.14 9.02 11.86 9.02 11.62 8.92C11.5 8.87 11.39 8.8 11.29 8.71C11.2 8.61 11.13 8.5 11.08 8.38C11.03 8.26 11 8.13 11 8C11 7.87 11.03 7.74 11.08 7.62Z"
/>
</svg>
);`;
Comment on lines +1 to +14
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor InfoCircleIcon to a proper React component file

The InfoCircleIcon is currently defined as a string literal containing JSX code. This approach may lead to issues with syntax highlighting, code analysis, and potential security risks if used improperly.

Consider refactoring the InfoCircleIcon to a proper React component in a separate file:

  1. Create a new file InfoCircleIcon.jsx or InfoCircleIcon.tsx.
  2. Define the component as a proper React functional component.
  3. Export the component as the default export.

Example:

import React from 'react';

const InfoCircleIcon = (props) => (
  <svg
    fill="none"
    height="24"
    viewBox="0 0 24 24"
    width="24"
    xmlns="http://www.w3.org/2000/svg"
    {...props}
  >
    <path d="M12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22ZM12.75 16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16L11.25 11C11.25 10.59 11.59 10.25 12 10.25C12.41 10.25 12.75 10.59 12.75 11L12.75 16ZM11.08 7.62C11.13 7.49 11.2 7.39 11.29 7.29C11.39 7.2 11.5 7.13 11.62 7.08C11.74 7.03 11.87 7 12 7C12.13 7 12.26 7.03 12.38 7.08C12.5 7.13 12.61 7.2 12.71 7.29C12.8 7.39 12.87 7.49 12.92 7.62C12.97 7.74 13 7.87 13 8C13 8.13 12.97 8.26 12.92 8.38C12.87 8.5 12.8 8.61 12.71 8.71C12.61 8.8 12.5 8.87 12.38 8.92C12.14 9.02 11.86 9.02 11.62 8.92C11.5 8.87 11.39 8.8 11.29 8.71C11.2 8.61 11.13 8.5 11.08 8.38C11.03 8.26 11 8.13 11 8C11 7.87 11.03 7.74 11.08 7.62Z" />
  </svg>
);

export default InfoCircleIcon;

This change will improve code maintainability and reduce potential issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinav700 Understood, I'll disregard this suggestion.

(_/)
( ;_;)
/ >

Comment on lines +1 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor InfoCircleIcon to a proper React component

The InfoCircleIcon is currently defined as a string literal containing JSX code. This approach may lead to issues with syntax highlighting, code analysis, and potential security risks if used improperly.

Consider refactoring InfoCircleIcon to a proper React component in a separate file:

  1. Create a new file InfoCircleIcon.tsx.
  2. Define the component as a proper React functional component.
  3. Export the component as the default export.

Example:

import React from 'react';

const InfoCircleIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
  <svg
    fill="none"
    height="24"
    viewBox="0 0 24 24"
    width="24"
    xmlns="http://www.w3.org/2000/svg"
    {...props}
  >
    <path d="M12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22ZM12.75 16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16L11.25 11C11.25 10.59 11.59 10.25 12 10.25C12.41 10.25 12.75 10.59 12.75 11L12.75 16ZM11.08 7.62C11.13 7.49 11.2 7.39 11.29 7.29C11.39 7.2 11.5 7.13 11.62 7.08C11.74 7.03 11.87 7 12 7C12.13 7 12.26 7.03 12.38 7.08C12.5 7.13 12.61 7.2 12.71 7.29C12.8 7.39 12.87 7.49 12.92 7.62C12.97 7.74 13 7.87 13 8C13 8.13 12.97 8.26 12.92 8.38C12.87 8.5 12.8 8.61 12.71 8.71C12.61 8.8 12.5 8.87 12.38 8.92C12.14 9.02 11.86 9.02 11.62 8.92C11.5 8.87 11.39 8.8 11.29 8.71C11.2 8.61 11.13 8.5 11.08 8.38C11.03 8.26 11 8.13 11 8C11 7.87 11.03 7.74 11.08 7.62Z" />
  </svg>
);

export default InfoCircleIcon;

This change will improve code maintainability and reduce potential issues.


const CloseIcon = `export const CloseIcon = (props) => (
<svg
aria-hidden="true"
fill="none"
focusable="false"
height="1em"
role="presentation"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
viewBox="0 0 24 24"
width="1em"
{...props}
>
<path d="M18 6L6 18M6 6l12 12" />
</svg>
);`;
Comment on lines +16 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor CloseIcon to a proper React component

The CloseIcon is currently defined as a string literal containing JSX code. This approach may lead to issues with syntax highlighting, code analysis, and potential security risks if used improperly.

Consider refactoring CloseIcon to a proper React component in a separate file:

  1. Create a new file CloseIcon.tsx.
  2. Define the component as a proper React functional component.
  3. Export the component as the default export.

Example:

import React from 'react';

const CloseIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
  <svg
    aria-hidden="true"
    fill="none"
    focusable="false"
    height="1em"
    role="presentation"
    stroke="currentColor"
    strokeLinecap="round"
    strokeLinejoin="round"
    strokeWidth={2}
    viewBox="0 0 24 24"
    width="1em"
    {...props}
  >
    <path d="M18 6L6 18M6 6l12 12" />
  </svg>
);

export default CloseIcon;

This change will improve code maintainability and reduce potential issues.


const App = `import React, {forwardRef, useMemo} from "react";
import {useAlert} from "@nextui-org/react";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add missing import for AlertCloseIcon.

The AlertCloseIcon component is used in the code but not imported. To ensure the code works correctly, please import it from '@nextui-org/react'.

Apply this diff to add the missing import:

-import {useAlert} from "@nextui-org/react";
+import {useAlert, AlertCloseIcon} from "@nextui-org/react";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import {useAlert} from "@nextui-org/react";
import {useAlert, AlertCloseIcon} 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,
} = 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",
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
// custom styles
classNames: {
...styles,
},
});

const mainWrapper = useMemo(() => {
return (
<div {...getMainWrapperProps()}>
{title && <div {...getTitleProps()}>{title}</div>}
<div {...getDescriptionProps()}>{description}</div>
</div>
);
}, [title, description, getMainWrapperProps, getTitleProps, getDescriptionProps]);

const baseWrapper = useMemo(() => {
return isVisible ? (
<div ref={domRef} {...getBaseProps()}>
<InfoCircleIcon />
{mainWrapper}
{(isClosable || onClose) && (
<button onClick={handleClose} {...getCloseButtonProps()}>
<CloseIcon {...getCloseIconProps()}/>
</button>
)}
</div>
) : null;
}, [
mainWrapper,
isClosable,
getCloseButtonProps,
isVisible,
domRef,
getBaseProps,
handleClose,
color,
onClose
]);

return <>{baseWrapper}</>;
});

MyAlert.displayName = "MyAlert";

export default MyAlert;`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor MyAlert to a proper React component file and remove hardcoded values

The MyAlert component is currently defined as a string literal, which can lead to various issues including difficulty in maintenance, lack of proper syntax highlighting, and potential security risks. Additionally, the component contains hardcoded values for title and description, limiting its reusability.

Consider the following improvements:

  1. Refactor MyAlert into a separate React component file:

    • Create a new file MyAlert.jsx or MyAlert.tsx.
    • Move the component code into this file, removing the string literal wrapper.
    • Properly import the required dependencies at the top of the file.
  2. Remove hardcoded values for title and description:

    • Remove the following lines:
      // 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",
    • Allow these props to be passed from the parent component instead.
  3. Update import statements:

    import React, { forwardRef, useMemo } from "react";
    import { useAlert } from "@nextui-org/react";
    import InfoCircleIcon from "./InfoCircleIcon";
    import CloseIcon from "./CloseIcon";

Example of refactored MyAlert component:

import React, { forwardRef, useMemo } from "react";
import { useAlert } from "@nextui-org/react";
import InfoCircleIcon from "./InfoCircleIcon";
import CloseIcon from "./CloseIcon";

const styles = {
  // ... (keep the styles object as is)
};

const MyAlert = forwardRef((props, ref) => {
  const {
    title,
    description,
    isClosable,
    domRef,
    handleClose,
    getBaseProps,
    getMainWrapperProps,
    getDescriptionProps,
    getTitleProps,
    getCloseButtonProps,
    color,
    isVisible,
    onClose,
    getCloseIconProps,
  } = useAlert({
    ...props,
    ref,
    classNames: {
      ...styles,
    },
  });

  // ... (keep the rest of the component logic as is)
});

MyAlert.displayName = "MyAlert";

export default MyAlert;

These changes will significantly improve code maintainability, reusability, and reduce potential issues.


const react = {
"/App.jsx": App,
"/InfoCircleIcon": InfoCircleIcon,
"/CloseIcon": CloseIcon,
};

export default {
...react,
};
Comment on lines +135 to +143
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify and standardize the export structure

The current export structure, where React components are defined as string literals and exported through an object, is unconventional and can lead to various issues. This approach makes it difficult to maintain, debug, and use these components effectively.

Consider restructuring the exports as follows:

  1. After refactoring each component into its own file as suggested in previous comments, update this file to import and export the components directly.

  2. Remove the react object and the complex export structure.

Example of a simplified export structure:

import InfoCircleIcon from './InfoCircleIcon';
import CloseIcon from './CloseIcon';
import MyAlert from './MyAlert';

export {
  InfoCircleIcon,
  CloseIcon,
  MyAlert,
};

This restructuring will significantly improve code maintainability, readability, and adherence to React best practices. It will also make it easier for other parts of the application to import and use these components.

46 changes: 46 additions & 0 deletions apps/docs/content/components/alert/custom-styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const App = `import {Alert} from "@nextui-org/react";

export default function App() {
const title = "Email Sent!!";
const description = "You will get a reply soon";

return (
<div className="flex items-center justify-center w-screen">
<Alert
title={title}
description={description}
classNames={{
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",
],
}}
/>
</div>
);
}`;

const react = {
"/App.jsx": App,
};

export default {
...react,
};
15 changes: 15 additions & 0 deletions apps/docs/content/components/alert/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import colors from "./colors";
import usage from "./usage";
import isClosable from "./is-closable";
import radius from "./radius";
import customImpl from "./custom-impl";
import customStyles from "./custom-styles";

export const alertContent = {
colors,
usage,
isClosable,
radius,
customImpl,
customStyles,
};
20 changes: 20 additions & 0 deletions apps/docs/content/components/alert/is-closable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const App = `import {Alert} from "@nextui-org/react";

export default function App() {
const title = "Email Sent!!";
const description = "You will get a reply soon";

return (
<div className="flex items-center justify-center w-screen">
<Alert isClosable={true} title={title} description={description} />
</div>
);
}`;

const react = {
"/App.jsx": App,
};

export default {
...react,
};
27 changes: 27 additions & 0 deletions apps/docs/content/components/alert/radius.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const App = `import {Alert} from "@nextui-org/react";

export default function App() {
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
const title = "Email Sent!!";
const description = "You will get a reply soon";
Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance flexibility with props for alert content

The current implementation uses hardcoded values for the alert title and description. To improve reusability and flexibility, consider accepting these as props.

Refactor the component to accept props:

interface AlertRadiusExampleProps {
  title?: string;
  description?: string;
}

export default function AlertRadiusExample({
  title = "Email Sent!!",
  description = "You will get a reply soon"
}: AlertRadiusExampleProps) {
  // ... rest of the component
}

This change allows for easier customization when using the component in different contexts.


return (
<div className="flex items-center justify-center w-screen">
<div className="flex flex-col">
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
{["none", "sm", "md", "lg", "full"].map((radius) => (
<div key={radius} className="w-full flex justify-between items-center my-3">
<span className="mx-4 text-md">{radius}</span>
<Alert title={title} description={description} radius={radius} />
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
</div>
))}
</div>
</div>
);
}`;

const react = {
"/App.jsx": App,
};

export default {
...react,
};
Comment on lines +21 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify the export structure

The current export structure seems overly complex for a single component example. Consider simplifying it to directly export the component.

Replace the current export structure with a simple default export:

export default AlertRadiusExample;

This change will make the file more straightforward and easier to import and use in other parts of the documentation or examples.

20 changes: 20 additions & 0 deletions apps/docs/content/components/alert/usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const App = `import {Alert} from "@nextui-org/react";

export default function App() {
const title = "Email Sent!!";
const description = "You will get a reply soon";

return (
<div className="flex items-center justify-center w-screen">
<Alert title={title} description={description} />
</div>
);
}`;

const react = {
"/App.jsx": App,
};

export default {
...react,
};
1 change: 1 addition & 0 deletions apps/docs/content/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from "./dropdown";
export * from "./navbar";
export * from "./table";
export * from "./autocomplete";
export * from "./alert";
Loading