-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement toast on ticker delete
- Loading branch information
1 parent
fdb073e
commit 247b5bd
Showing
10 changed files
with
204 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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
File renamed without changes.
This file contains 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,41 @@ | ||
"use client"; | ||
|
||
import Toast from "@/components/common/toast/toast"; | ||
import { Button } from "@/components/ui/button"; | ||
import React from "react"; | ||
import { toast } from "sonner"; | ||
|
||
const TickerList = React.memo(() => { | ||
const onTickerDelete = React.useCallback(() => { | ||
toast.custom((t) => <Toast t={t} title={`You deleted ${"GOOGLE"}`} isRevertable={true} />); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex h-full w-full flex-1 flex-col items-start"> | ||
<div className="flex w-full flex-1 flex-col items-start gap-4"> | ||
<div className="flex w-full items-center justify-between "> | ||
<p className="text-2xl font-bold">GOOGLE</p> | ||
<Button onClick={onTickerDelete}>Delete</Button> | ||
</div> | ||
<div className="flex w-full items-center justify-between "> | ||
<p className="text-2xl font-bold">GOOGLE</p> | ||
<Button onClick={onTickerDelete}>Delete</Button> | ||
</div> | ||
<div className="flex w-full items-center justify-between "> | ||
<p className="text-2xl font-bold">GOOGLE</p> | ||
<Button onClick={onTickerDelete}>Delete</Button> | ||
</div> | ||
<div className="flex w-full items-center justify-between "> | ||
<p className="text-2xl font-bold">GOOGLE</p> | ||
<Button onClick={onTickerDelete}>Delete</Button> | ||
</div> | ||
<div className="flex w-full items-center justify-between "> | ||
<p className="text-2xl font-bold">GOOGLE</p> | ||
<Button onClick={onTickerDelete}>Delete</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}); | ||
|
||
export default TickerList; |
This file contains 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
File renamed without changes.
This file contains 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,39 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { cn } from "@/utils/cn"; | ||
import React from "react"; | ||
import { toast } from "sonner"; | ||
|
||
export interface ToastProps extends React.HTMLAttributes<HTMLDivElement> { | ||
t?: string | number; | ||
title: string; | ||
isRevertable?: boolean; | ||
} | ||
|
||
const Toast = React.memo(({ t, title, isRevertable, ...props }: ToastProps) => { | ||
const onUndo = React.useCallback(() => { | ||
toast.dismiss(t); | ||
}, [t]); | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
"flex items-center justify-between rounded-lg bg-[#8B95A1] px-5 py-4 text-white shadow", | ||
props.className | ||
)} | ||
{...props} | ||
> | ||
<p>{title}</p> | ||
{isRevertable && <UndoButton onClick={onUndo} />} | ||
</div> | ||
); | ||
}); | ||
|
||
const UndoButton = React.memo(({ onClick }: { onClick: () => void }) => { | ||
return ( | ||
<Button onClick={onClick} variant={"default"}> | ||
<p>Undo</p> | ||
</Button> | ||
); | ||
}); | ||
|
||
export default Toast; |
This file contains 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 @@ | ||
import * as React from "react"; | ||
import { Slot } from "@radix-ui/react-slot"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import { cn } from "@/utils/cn"; | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground hover:bg-primary/90", | ||
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90", | ||
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground", | ||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "text-primary underline-offset-4 hover:underline", | ||
}, | ||
size: { | ||
default: "h-10 px-4 py-2", | ||
sm: "h-9 rounded-md px-3", | ||
lg: "h-11 rounded-md px-8", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
} | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />; | ||
} | ||
); | ||
Button.displayName = "Button"; | ||
|
||
export { Button, buttonVariants }; |
This file contains 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,31 @@ | ||
"use client" | ||
|
||
import { useTheme } from "next-themes" | ||
import { Toaster as Sonner } from "sonner" | ||
|
||
type ToasterProps = React.ComponentProps<typeof Sonner> | ||
|
||
const Toaster = ({ ...props }: ToasterProps) => { | ||
const { theme = "system" } = useTheme() | ||
|
||
return ( | ||
<Sonner | ||
theme={theme as ToasterProps["theme"]} | ||
className="toaster group" | ||
toastOptions={{ | ||
classNames: { | ||
toast: | ||
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg", | ||
description: "group-[.toast]:text-muted-foreground", | ||
actionButton: | ||
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground", | ||
cancelButton: | ||
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground", | ||
}, | ||
}} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export { Toaster } |