-
Notifications
You must be signed in to change notification settings - Fork 28
feat: notification component ui #48
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
Draft
bluecco
wants to merge
8
commits into
feat/react-components
Choose a base branch
from
feat/react-components-notifications
base: feat/react-components
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ad0fd6
feat: notification component ui
bluecco 6c1abbe
chore: update NotificationItem style
bluecco bde1dbf
chore: add exports for notification components
bluecco 33f6c25
feat: activity toast component ui
bluecco f91adba
Merge pull request #49 from argentlabs/feat/react-components-activity…
bluecco 184f146
Merge branch 'feat/react-components' into feat/react-components-notif…
bluecco edc90a6
chore: refactor with SuccessIcon
bluecco 3d937a0
chore: add icons
bluecco 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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| module.exports = { | ||
| plugins: { | ||
| tailwindcss: {}, | ||
| tailwindcss: { | ||
| config: "tailwind.config.cjs", | ||
| }, | ||
| autoprefixer: {}, | ||
| }, | ||
| } |
152 changes: 152 additions & 0 deletions
152
packages/ui/src/components/ActivityToast/ActivityToast.tsx
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,152 @@ | ||
| import { FC, useEffect, useMemo, useState } from "react" | ||
| import { CloseIcon } from "../../icons/CloseIcon" | ||
|
|
||
| type vertical = "top" | "center" | "bottom" | ||
| type horizontal = "left" | "center" | "right" | ||
|
|
||
| interface ActivityToastProps { | ||
| action: string | ||
| description: string | ||
| showToast?: boolean | ||
| closeToast: () => void | ||
| duration?: 1000 | 2000 | 3000 | 4000 | 5000 | ||
| vertical?: vertical | ||
| horizontal?: horizontal | ||
| } | ||
|
|
||
| const durationMap = { | ||
| 1000: "duration-1000", | ||
| 2000: "duration-2000", | ||
| 3000: "duration-3000", | ||
| 4000: "duration-4000", | ||
| 5000: "duration-5000", | ||
| } | ||
|
|
||
| const ActivityToast: FC<ActivityToastProps> = ({ | ||
| action, | ||
| description, | ||
| showToast, | ||
| closeToast, | ||
| duration = 5000, | ||
| vertical = "bottom", | ||
| horizontal = "center", | ||
| }) => { | ||
| return showToast ? ( | ||
| <ActivityToastComponent | ||
| action={action} | ||
| description={description} | ||
| closeToast={closeToast} | ||
| duration={duration} | ||
| vertical={vertical} | ||
| horizontal={horizontal} | ||
| /> | ||
| ) : null | ||
| } | ||
|
|
||
| const ActivityToastComponent: FC<ActivityToastProps> = ({ | ||
| action, | ||
| description, | ||
| closeToast, | ||
| duration = 5000, | ||
| vertical = "bottom", | ||
| horizontal = "center", | ||
| }) => { | ||
| const [isActive, setIsActive] = useState(true) | ||
| useEffect(() => { | ||
| // ensure that the toast is visible, setting the width to full for the progression bar | ||
| setTimeout(() => setIsActive(false), 10) | ||
| const timeout = setTimeout(() => closeToast(), duration) | ||
| return () => { | ||
| closeToast() | ||
| clearTimeout(timeout) | ||
| } | ||
| }, []) | ||
|
|
||
| const position = useMemo(() => { | ||
| let v, h | ||
|
|
||
| switch (horizontal) { | ||
| case "left": | ||
| h = `left-2` | ||
| break | ||
| case "center": | ||
| h = `left-2/4 transform -translate-x-2/4` | ||
| break | ||
| case "right": | ||
| h = `right-2` | ||
| break | ||
| default: | ||
| h = `left-2/4` | ||
| break | ||
| } | ||
|
|
||
| switch (vertical) { | ||
| case "top": | ||
| v = `top-2` | ||
| break | ||
| case "center": | ||
| v = `top-2/4 transform -translate-y-2/4` | ||
| break | ||
| case "bottom": | ||
| v = `bottom-2` | ||
| break | ||
| default: | ||
| v = `top-2/4` | ||
| break | ||
| } | ||
|
|
||
| return `${v} ${h}` | ||
| }, [vertical, horizontal]) | ||
|
|
||
| return ( | ||
| <div className={`fixed ${position}`}> | ||
| <div className="relative p-5 bg-white rounded-lg overflow-hidden shadow-lg border border-solid border-neutrals.200 w-96"> | ||
| <div className="flex flex-1"> | ||
| <div className="flex flex-col justify-center mr-4"> | ||
| {/* TODO: remove hardcode - decide how to manage icons in notifications */} | ||
| <svg | ||
| width="24" | ||
| height="24" | ||
| viewBox="0 0 24 24" | ||
| fill="none" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M16.9016 10.564C17.3511 10.1351 17.3679 9.423 16.939 8.97345C16.5101 8.52389 15.798 8.50713 15.3484 8.93601L10.6225 13.4445L8.65225 11.5617C8.20306 11.1324 7.49093 11.1486 7.06167 11.5978C6.63241 12.0469 6.64856 12.7591 7.09775 13.1883L9.84463 15.8133C10.2792 16.2286 10.9635 16.2289 11.3984 15.814L16.9016 10.564Z" | ||
| fill="#08A681" | ||
| /> | ||
| <path | ||
| fill-rule="evenodd" | ||
| clip-rule="evenodd" | ||
| d="M12 1.875C6.40812 1.875 1.875 6.40812 1.875 12C1.875 17.5919 6.40812 22.125 12 22.125C17.5919 22.125 22.125 17.5919 22.125 12C22.125 6.40812 17.5919 1.875 12 1.875ZM4.125 12C4.125 7.65076 7.65076 4.125 12 4.125C16.3492 4.125 19.875 7.65076 19.875 12C19.875 16.3492 16.3492 19.875 12 19.875C7.65076 19.875 4.125 16.3492 4.125 12Z" | ||
| fill="#08A681" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| <div className="flex flex-col items-start"> | ||
| <h5 className="font-barlow text-xl leading-6 font-semibold"> | ||
| {action} | ||
| </h5> | ||
| <p className="font-barlow text-base text-start leading-5 font-medium text-neutral-600 mt-0.5 mb-1"> | ||
| {description} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="flex flex-1" /> | ||
|
|
||
| <div className="flex flex-col justify-center items-end relative w-6"> | ||
| <CloseIcon cursor="pointer" onClick={closeToast} /> | ||
| </div> | ||
| </div> | ||
| <div | ||
| className={`absolute bottom-0 left-0 right-0 h-1 transition-all ${ | ||
| durationMap[duration] | ||
| } ease-linear ${isActive ? "w-full" : "w-0"}`} | ||
| style={{ backgroundColor: "#197AA6" }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export { ActivityToast } | ||
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
packages/ui/src/components/Notifications/NotificationButton.tsx
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,72 @@ | ||
| import { FC, useEffect, useRef, useState } from "react" | ||
| import { BellIcon } from "../../icons/BellIcon" | ||
| import { NotificationMenu } from "./NotificationMenu" | ||
|
|
||
| interface Notification { | ||
| action: string | ||
| description: string | ||
| isUnread?: boolean | ||
| time: string | ||
| } | ||
|
|
||
| interface NotificationButtonProps { | ||
| address?: string | ||
| hasNotifications?: boolean | ||
| notifications: Notification[] | ||
| } | ||
|
|
||
| const NotificationButton: FC<NotificationButtonProps> = ({ | ||
| hasNotifications, | ||
| notifications, | ||
| }) => { | ||
| const [isOpen, setIsOpen] = useState(false) | ||
| const ref = useRef<HTMLDivElement>(null) | ||
|
|
||
| const toggleMenu = () => { | ||
| setIsOpen((prev) => !prev) | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| const handleClickOutside = (event: MouseEvent) => { | ||
| if (ref.current && !ref.current.contains(event.target as Node)) { | ||
| setIsOpen(false) | ||
| } | ||
| } | ||
|
|
||
| document.addEventListener("mousedown", handleClickOutside) | ||
|
|
||
| return () => { | ||
| document.removeEventListener("mousedown", handleClickOutside) | ||
| } | ||
| }, []) | ||
|
|
||
| return ( | ||
| <div className="relative inline-block" ref={ref}> | ||
| <button | ||
| onClick={toggleMenu} | ||
| className="flex items-center justify-center shadow-list-item rounded-lg h-10 w-10 bg-white" | ||
| > | ||
| <div className="relative"> | ||
| <BellIcon className="w-6 h-6" /> | ||
| {hasNotifications && ( | ||
| <div className="w-[10px] h-[10px] absolute top-0 right-1 rounded-full p-1 z-10 bg-white"> | ||
| <div className="w-2 h-2 bg-[#29C5FF] rounded-full absolute transform -translate-y-2/3"></div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </button> | ||
| <div | ||
| className={`absolute top-10 mt-0.5 w-50 rounded-lg shadow-lg z-20 text-black bg-white ${ | ||
| !isOpen ? "hidden" : "" | ||
| }`} | ||
| > | ||
| <NotificationMenu | ||
| notifications={notifications} | ||
| toggleMenu={toggleMenu} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export { NotificationButton } |
70 changes: 70 additions & 0 deletions
70
packages/ui/src/components/Notifications/NotificationItem.tsx
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,70 @@ | ||
| import { FC } from "react" | ||
|
|
||
| interface NotificationItemProps { | ||
| action: string | ||
| description: string | ||
| isUnread?: boolean | ||
| time: string | ||
| } | ||
|
|
||
| const NotificationItem: FC<NotificationItemProps> = ({ | ||
| action, | ||
| description, | ||
| isUnread, | ||
| time, | ||
| }) => { | ||
| return ( | ||
| <button | ||
| onClick={() => console.log("TODO")} | ||
bluecco marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| className="flex items-center px-6 py-5 border border-solid border-neutrals.200 rounded-lg w-full hover:bg-[#F0F0F0]" | ||
| > | ||
| <div className="flex flex-1"> | ||
| <div className="flex flex-col justify-center mr-4"> | ||
| {/* TODO: remove hardcode - decide how to manage icons in notifications */} | ||
bluecco marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <svg | ||
| width="24" | ||
| height="24" | ||
| viewBox="0 0 24 24" | ||
| fill="none" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M16.9016 10.564C17.3511 10.1351 17.3679 9.423 16.939 8.97345C16.5101 8.52389 15.798 8.50713 15.3484 8.93601L10.6225 13.4445L8.65225 11.5617C8.20306 11.1324 7.49093 11.1486 7.06167 11.5978C6.63241 12.0469 6.64856 12.7591 7.09775 13.1883L9.84463 15.8133C10.2792 16.2286 10.9635 16.2289 11.3984 15.814L16.9016 10.564Z" | ||
| fill="#08A681" | ||
| /> | ||
| <path | ||
| fill-rule="evenodd" | ||
| clip-rule="evenodd" | ||
| d="M12 1.875C6.40812 1.875 1.875 6.40812 1.875 12C1.875 17.5919 6.40812 22.125 12 22.125C17.5919 22.125 22.125 17.5919 22.125 12C22.125 6.40812 17.5919 1.875 12 1.875ZM4.125 12C4.125 7.65076 7.65076 4.125 12 4.125C16.3492 4.125 19.875 7.65076 19.875 12C19.875 16.3492 16.3492 19.875 12 19.875C7.65076 19.875 4.125 16.3492 4.125 12Z" | ||
| fill="#08A681" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| <div className="flex flex-col items-start"> | ||
| <h5 className="font-barlow text-xl leading-6 font-semibold"> | ||
| {action} | ||
| </h5> | ||
| <p className="font-barlow text-base text-start leading-5 font-medium text-neutral-600 mt-0.5 mb-1"> | ||
| {description} | ||
| </p> | ||
| <p className="font-barlow text-xs leading-4 font-normal text-neutral-400"> | ||
| {time} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="flex flex-1" /> | ||
|
|
||
| <div className="flex flex-col justify-center items-end relative w-6"> | ||
| {isUnread && ( | ||
| <div | ||
| className="rounded-full w-2.5 h-2.5 mt-2" | ||
| style={{ backgroundColor: "#29C5FF" }} | ||
| /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </button> | ||
| ) | ||
| } | ||
|
|
||
| export { NotificationItem } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.