-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: alert component #3680
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
Changes from all commits
efb8ec6
d746f6c
0de2883
55b479e
f2b5252
4634e11
547a9dc
d302984
dbc3e44
e783488
98589e7
d352f9b
4a9e147
c079cc0
d8f5b5e
7d13e87
e957365
5f7f907
b1e031e
e56acda
099378d
7402add
e60dea2
4fcb4c0
248fecd
bc9205e
2d94b00
a699cc4
81552c8
e185212
9c727c2
26198ec
b29ccae
c74b064
64a4178
a83282b
12b5f36
f7fd9c7
14bea4a
44efbaf
9897573
d271053
e6efe4f
e4aa2ac
7003759
71fa1f3
13102e8
f4dbcf9
3f3a7d0
04c5a14
316fa11
29c38e2
7069361
d1609eb
af2adc2
61df0e4
7202be5
682e9be
c9a3781
9567d16
22c6a51
427c4fe
c4b0987
c1d0ae9
02dd710
0e6e8a8
1c94c04
eebab5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) |
| 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() { | ||
| const title = "Email Sent!!"; | ||
| const description = "You will get a reply soon"; | ||
|
Comment on lines
+4
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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.
|
||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
abhinav700 marked this conversation as resolved.
|
||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
| 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.
abhinav700 marked this conversation as 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.
|
||||||
|
|
||||||
| const App = `import React, {forwardRef, useMemo} from "react"; | ||||||
| import {useAlert} from "@nextui-org/react"; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing import for The Apply this diff to add the missing import: -import {useAlert} from "@nextui-org/react";
+import {useAlert, AlertCloseIcon} from "@nextui-org/react";📝 Committable suggestion
Suggested change
|
||||||
| 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.
|
||||||
| // 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.
|
||||||
| 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, | ||
| }; |
| 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, | ||
| }; |
| 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, | ||
| }; |
| 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.
|
||
| const title = "Email Sent!!"; | ||
| const description = "You will get a reply soon"; | ||
|
abhinav700 marked this conversation as 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.
|
||
| </div> | ||
| ))} | ||
|
abhinav700 marked this conversation as resolved.
|
||
| </div> | ||
| </div> | ||
| ); | ||
| }`; | ||
|
abhinav700 marked this conversation as resolved.
|
||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
|
abhinav700 marked this conversation as resolved.
|
||
| 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, | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.