-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Alert component #3982
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
Merged
Merged
Alert component #3982
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
efb8ec6
feat(alert): began the work on alert component
abhinav700 d746f6c
fix(readme): making correction
abhinav700 0de2883
chore(deps): change to 2.0.0
wingkwong 55b479e
chore(docs): update README.md
wingkwong f2b5252
feat(theme): init alert tv
wingkwong 4634e11
chore(alert): update package.json
wingkwong 547a9dc
feat(alert): init alert storybook structure
wingkwong d302984
chore(changeset): add changeset
wingkwong dbc3e44
Merge branch 'adding_alert_component' of https://github.com/abhinav70…
wingkwong e783488
chore(changeset): change to minor
wingkwong 98589e7
chore(alert): revise alert package.json
wingkwong d352f9b
feat(alert): init test structure
wingkwong 4a9e147
chore(deps): pnpm-lock.yaml
wingkwong c079cc0
feat(alert): initailized theme and basic structure
abhinav700 d8f5b5e
feat(alert): completed use-alert.ts and alert.tsx
abhinav700 7d13e87
feat(alert): remove innerWrapper, replace helperWrapper with mainWrap…
abhinav700 e957365
feat(alert): adding isCloseable prop to baseWrapper dependency
abhinav700 5f7f907
Merge branch 'nextui-org:canary' into adding_alert_component
abhinav700 b1e031e
feat(alert): setting the default value of isCloseable prop to true
abhinav700 e56acda
feat(alert): moving CloseIcon inside the button
abhinav700 099378d
feat(alert): updated package.json
abhinav700 7402add
feat(alert): default variant and default story
abhinav700 e60dea2
feat(alert): adding color and radius stories
abhinav700 4fcb4c0
feat(alert): completed the styling
abhinav700 248fecd
feat(alert): add stories for isCloseable prop and restyle other stories
abhinav700 bc9205e
feat(alert): correcting ref type
abhinav700 2d94b00
feat(alert): add test cases
abhinav700 a699cc4
feat(alert): remove startContent and endContent props
abhinav700 81552c8
feat(alert): make styling more accurate
abhinav700 e185212
feat(alert): fixed default props
abhinav700 9c727c2
feat(alert): fixed theme docs
abhinav700 26198ec
feat(alert): add logic for icons
abhinav700 b29ccae
feat(alert): begin to add docs
abhinav700 c74b064
chore(alert): implement the changes suggested in code review
abhinav700 64a4178
feat(alert): add onclose prop to alert
abhinav700 a83282b
feat(alert): add test cases
abhinav700 12b5f36
docs(alert): add onClose event
abhinav700 f7fd9c7
feat(docs): add alert to routes.json
wingkwong 14bea4a
fix(alert): correct the text colors
abhinav700 44efbaf
docs(alert): fix imports and syntax errors
abhinav700 9897573
chore(alert): implement the changes suggested in code review
abhinav700 d271053
chore(alert): lint the code and change isCloseable to isClosable
abhinav700 e6efe4f
chore(alert): lint the code
abhinav700 e4aa2ac
chore(alert): recover the branch
abhinav700 7003759
chore(alert): run pnpm i
abhinav700 71fa1f3
Merge branch 'nextui-org:canary' into adding_alert_component
abhinav700 13102e8
fix(alert): fix the logic for close button and add test case
abhinav700 f4dbcf9
docs(alert): fix docs, change isCloseable to isClosable and change do…
abhinav700 3f3a7d0
chore(alert): add the support for RTL, refactor the code and fix the …
abhinav700 04c5a14
docs(alert): grammer issues fix
abhinav700 316fa11
fix(alert): replace rtl with ms
abhinav700 29c38e2
Merge branch 'canary' into pr/3680
wingkwong 7069361
chore(alert): custom style and custom implementation, remove isClosab…
abhinav700 d1609eb
chore(alert): linting and implement coderabbit suggestions
abhinav700 af2adc2
chore(alert): refactor and typos fix
abhinav700 61df0e4
chore(alert): add import for closeIcon
abhinav700 7202be5
chore(alert): add props for closeIcon
abhinav700 682e9be
chore(alert): refactor fixes
abhinav700 c9a3781
chore(alert): implement ryo-manba's suggestion on close Icon
abhinav700 9567d16
chore(alert): make alert more responsive
abhinav700 22c6a51
chore(alert): fix grammer issues suggested by coderabbit
abhinav700 427c4fe
fix(alert): add max-w property to make alert responsive
abhinav700 c4b0987
chore(alert): improve responsiveness and refactor alertIcon
abhinav700 c1d0ae9
chore(alert): add missing dependency to useMemo
abhinav700 02dd710
chore(alert): implement coderabbit's suggestions
abhinav700 0e6e8a8
Merge branch 'nextui-org:canary' into adding_alert_component
abhinav700 1c94c04
chore(alert): update docs and refactor
abhinav700 eebab5d
chore(alert): refactor alertIcon and implement coderabbit's suggestion
abhinav700 81c31b4
chore: fixes
jrgarciadev 740e07d
fix: pnpm lock
jrgarciadev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@nextui-org/alert": patch | ||
| "@nextui-org/theme": patch | ||
| --- | ||
|
|
||
| introduced Alert component (#2250) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const App = `import {Alert} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex items-center justify-center w-full"> | ||
| <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"> | ||
| <Alert | ||
| color={color} | ||
| title={\`This is a \${color} alert\`} | ||
| /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 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 ( | ||
| <div className="flex flex-col gap-4"> | ||
| {isVisible ? ( | ||
| <Alert | ||
| title={title} | ||
| description={description} | ||
| isVisible={isVisible} | ||
| onClose={() => setIsVisible(false)} | ||
| /> | ||
| ) : ( | ||
| <Button | ||
| variant="bordered" | ||
| onPress={() => setIsVisible(true)} | ||
| > | ||
| Show Alert | ||
| </Button> | ||
| )} | ||
| </div> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| );`; | ||
|
|
||
| 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> | ||
| );`; | ||
|
|
||
| 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 ( | ||
| <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, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| const App = `import {Alert} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const title = "Success"; | ||
| const description = "Thanks for subscribing to our newsletter!"; | ||
|
|
||
| return ( | ||
| <div className="flex items-center justify-center w-full"> | ||
| <Alert | ||
| title={title} | ||
| description={description} | ||
| classNames={{ | ||
| base: [ | ||
| "bg-background", | ||
| "border", | ||
| "border-foreground-400", | ||
| "shadow", | ||
| "hover:bg-slate-200", | ||
| "cursor-pointer", | ||
| ], | ||
| title: ["text-base", "text-foreground", "font-semibold"], | ||
| description: ["text-base", "text-foreground-600"], | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import colors from "./colors"; | ||
| import usage from "./usage"; | ||
| import radius from "./radius"; | ||
| import customImpl from "./custom-impl"; | ||
| import customStyles from "./custom-styles"; | ||
| import variants from "./variants"; | ||
| import withIcon from "./with-icon"; | ||
| import controlled from "./controlled"; | ||
|
|
||
| export const alertContent = { | ||
| colors, | ||
| usage, | ||
| radius, | ||
| customImpl, | ||
| customStyles, | ||
| variants, | ||
| withIcon, | ||
| controlled, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const App = `import {Alert} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex items-center justify-center w-full"> | ||
| <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"> | ||
| <Alert | ||
| radius={radius} | ||
| title={\`This is a \${radius} radius alert\`} | ||
| /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = "This is an alert"; | ||
| const description = "Thanks for subscribing to our newsletter!"; | ||
|
|
||
| return ( | ||
| <div className="flex items-center justify-center w-full"> | ||
| <Alert title={title} description={description} /> | ||
| </div> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| const App = `import {Alert} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex flex-col gap-4 w-full"> | ||
| <Alert variant="solid"> | ||
| A solid variant alert | ||
| </Alert> | ||
| <Alert variant="bordered"> | ||
| A bordered variant alert | ||
| </Alert> | ||
| <Alert variant="flat"> | ||
| A flat variant alert | ||
| </Alert> | ||
| </div> | ||
| ); | ||
| }`; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type safety for the color prop.
The color prop should be properly typed to ensure only valid color values are used.