-
Notifications
You must be signed in to change notification settings - Fork 899
chore: add notification UI components #16818
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86a09a1
chore: add notification UI components
BrunoQuaresma 0079e8e
FMT
BrunoQuaresma 0473e7b
Apply Kayla suggestions
BrunoQuaresma e689179
Merge branch 'main' of https://github.com/coder/coder into bq/notific…
BrunoQuaresma 12fe3d8
Fix test
BrunoQuaresma 2180322
Fix stories
BrunoQuaresma 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,46 @@ | ||
/** | ||
* Copied from shadc/ui on 03/05/2025 | ||
* @see {@link https://ui.shadcn.com/docs/components/scroll-area} | ||
*/ | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"; | ||
import * as React from "react"; | ||
import { cn } from "utils/cn"; | ||
|
||
export const ScrollArea = React.forwardRef< | ||
React.ElementRef<typeof ScrollAreaPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> | ||
>(({ className, children, ...props }, ref) => ( | ||
<ScrollAreaPrimitive.Root | ||
ref={ref} | ||
className={cn("relative overflow-hidden", className)} | ||
{...props} | ||
> | ||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]"> | ||
{children} | ||
</ScrollAreaPrimitive.Viewport> | ||
<ScrollBar /> | ||
<ScrollAreaPrimitive.Corner /> | ||
</ScrollAreaPrimitive.Root> | ||
)); | ||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName; | ||
|
||
export const ScrollBar = React.forwardRef< | ||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>, | ||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar> | ||
>(({ className, orientation = "vertical", ...props }, ref) => ( | ||
<ScrollAreaPrimitive.ScrollAreaScrollbar | ||
ref={ref} | ||
orientation={orientation} | ||
className={cn( | ||
"border-0 border-solid border-border flex touch-none select-none transition-colors", | ||
orientation === "vertical" && | ||
"h-full w-2.5 border-l border-l-transparent p-[1px]", | ||
orientation === "horizontal" && | ||
"h-2.5 flex-col border-t border-t-transparent p-[1px]", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" /> | ||
</ScrollAreaPrimitive.ScrollAreaScrollbar> | ||
)); |
18 changes: 18 additions & 0 deletions
18
site/src/modules/notifications/NotificationsInbox/InboxButton.stories.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,18 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { InboxButton } from "./InboxButton"; | ||
|
||
const meta: Meta<typeof InboxButton> = { | ||
title: "modules/notifications/NotificationsInbox/InboxButton", | ||
component: InboxButton, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof InboxButton>; | ||
|
||
export const AllRead: Story = {}; | ||
|
||
export const Unread: Story = { | ||
args: { | ||
unreadCount: 3, | ||
}, | ||
}; |
30 changes: 30 additions & 0 deletions
30
site/src/modules/notifications/NotificationsInbox/InboxButton.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,30 @@ | ||
import { Button, type ButtonProps } from "components/Button/Button"; | ||
import { BellIcon } from "lucide-react"; | ||
import { type FC, forwardRef } from "react"; | ||
import { UnreadBadge } from "./UnreadBadge"; | ||
|
||
type InboxButtonProps = { | ||
unreadCount: number; | ||
} & ButtonProps; | ||
|
||
export const InboxButton = forwardRef<HTMLButtonElement, InboxButtonProps>( | ||
({ unreadCount, ...props }, ref) => { | ||
return ( | ||
<Button | ||
size="icon-lg" | ||
variant="outline" | ||
className="relative" | ||
ref={ref} | ||
{...props} | ||
> | ||
<BellIcon /> | ||
{unreadCount > 0 && ( | ||
<UnreadBadge | ||
count={unreadCount} | ||
className="absolute top-0 right-0 -translate-y-1/2 translate-x-1/2" | ||
/> | ||
)} | ||
</Button> | ||
); | ||
}, | ||
); |
77 changes: 77 additions & 0 deletions
77
site/src/modules/notifications/NotificationsInbox/InboxItem.stories.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,77 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { expect, fn, userEvent, within } from "@storybook/test"; | ||
import { MockNotification } from "testHelpers/entities"; | ||
import { InboxItem } from "./InboxItem"; | ||
|
||
const meta: Meta<typeof InboxItem> = { | ||
title: "modules/notifications/NotificationsInbox/InboxItem", | ||
component: InboxItem, | ||
render: (args) => { | ||
return ( | ||
<div className="max-w-[460px] border-solid border-border rounded"> | ||
<InboxItem {...args} /> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof InboxItem>; | ||
|
||
export const Read: Story = { | ||
args: { | ||
notification: { | ||
...MockNotification, | ||
read_status: "read", | ||
}, | ||
}, | ||
}; | ||
|
||
export const Unread: Story = { | ||
args: { | ||
notification: { | ||
...MockNotification, | ||
read_status: "unread", | ||
}, | ||
}, | ||
}; | ||
|
||
export const UnreadFocus: Story = { | ||
args: { | ||
notification: { | ||
...MockNotification, | ||
read_status: "unread", | ||
}, | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const notification = canvas.getByRole("menuitem"); | ||
await userEvent.click(notification); | ||
}, | ||
}; | ||
|
||
export const OnMarkNotificationAsRead: Story = { | ||
args: { | ||
notification: { | ||
...MockNotification, | ||
read_status: "unread", | ||
}, | ||
onMarkNotificationAsRead: fn(), | ||
}, | ||
play: async ({ canvasElement, args }) => { | ||
const canvas = within(canvasElement); | ||
const notification = canvas.getByRole("menuitem"); | ||
await userEvent.click(notification); | ||
const markButton = canvas.getByRole("button", { name: /mark as read/i }); | ||
await userEvent.click(markButton); | ||
await expect(args.onMarkNotificationAsRead).toHaveBeenCalledTimes(1); | ||
await expect(args.onMarkNotificationAsRead).toHaveBeenCalledWith( | ||
args.notification.id, | ||
); | ||
}, | ||
parameters: { | ||
chromatic: { | ||
disableSnapshot: true, | ||
}, | ||
}, | ||
}; |
68 changes: 68 additions & 0 deletions
68
site/src/modules/notifications/NotificationsInbox/InboxItem.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,68 @@ | ||
import { Avatar } from "components/Avatar/Avatar"; | ||
import { Button } from "components/Button/Button"; | ||
import { SquareCheckBig } from "lucide-react"; | ||
import type { FC } from "react"; | ||
import { Link as RouterLink } from "react-router-dom"; | ||
import { relativeTime } from "utils/time"; | ||
import type { Notification } from "./types"; | ||
|
||
type InboxItemProps = { | ||
notification: Notification; | ||
onMarkNotificationAsRead: (notificationId: string) => void; | ||
}; | ||
|
||
export const InboxItem: FC<InboxItemProps> = ({ | ||
notification, | ||
onMarkNotificationAsRead, | ||
}) => { | ||
return ( | ||
<div | ||
className="flex items-stretch gap-3 p-3 group" | ||
role="menuitem" | ||
tabIndex={-1} | ||
> | ||
<div className="flex-shrink-0"> | ||
<Avatar fallback="AR" /> | ||
</div> | ||
|
||
<div className="flex flex-col gap-3"> | ||
<span className="text-content-secondary text-sm font-medium"> | ||
{notification.content} | ||
</span> | ||
<div className="flex items-center gap-1"> | ||
{notification.actions.map((action) => { | ||
return ( | ||
<Button variant="outline" size="sm" key={action.label} asChild> | ||
<RouterLink to={action.url}>{action.label}</RouterLink> | ||
</Button> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
|
||
<div className="w-12 flex flex-col items-end flex-shrink-0"> | ||
{notification.read_status === "unread" && ( | ||
<> | ||
<div className="group-focus:hidden group-hover:hidden size-2.5 rounded-full bg-highlight-sky"> | ||
<span className="sr-only">Unread</span> | ||
</div> | ||
|
||
<Button | ||
onClick={() => onMarkNotificationAsRead(notification.id)} | ||
className="hidden group-focus:flex group-hover:flex bg-surface-primary" | ||
variant="outline" | ||
size="sm" | ||
> | ||
<SquareCheckBig /> | ||
mark as read | ||
</Button> | ||
</> | ||
)} | ||
|
||
<span className="mt-auto text-content-secondary text-xs font-medium whitespace-nowrap"> | ||
{relativeTime(new Date(notification.created_at))} | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.
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.