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

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 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
1c94c04
chore(alert): update docs and refactor
abhinav700 Oct 22, 2024
eebab5d
chore(alert): refactor alertIcon and implement coderabbit's suggestion
abhinav700 Oct 23, 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 w-full">
{["default", "primary", "secondary", "success", "warning", "danger"].map((color) => (
<div key={color} className="w-full flex 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>
);
}`;
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved

const react = {
"/App.jsx": App,
};
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved

export default {
...react,
};
142 changes: 142 additions & 0 deletions apps/docs/content/components/alert/custom-impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
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>
);`;
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved

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>
);`;
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved

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,
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",
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 {...getAlertIconProps()} />
{mainWrapper}
{(isClosable || onClose) && (
<button onClick={handleClose} {...getCloseButtonProps()}>
<CloseIcon />
</button>
)}
</div>
) : null;
}, [
mainWrapper,
isClosable,
getCloseButtonProps,
isVisible,
domRef,
getBaseProps,
handleClose,
color,
onClose,
getAlertIconProps,
]);

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

MyAlert.displayName = "MyAlert";

export default MyAlert;`;

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

export default {
...react,
};
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved
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";
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved

return (
<div className="flex items-center justify-center w-screen">
<div className="flex flex-col w-full">
{["none", "sm", "md", "lg", "full"].map((radius) => (
<div key={radius} className="w-full flex 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>
))}
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
);
}`;
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved

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

export default {
...react,
};
abhinav700 marked this conversation as resolved.
Show resolved Hide resolved
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