Skip to content
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(app/pano):used toast component #577

Merged
merged 11 commits into from
Aug 6, 2023
3 changes: 3 additions & 0 deletions apps/kampus/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type ReactNode } from "react";
import { Inter } from "next/font/google";

import { Toaster } from "@kampus/ui-next";

import { RelayEnvironmentProvider } from "~/features/relay/RelayEnvironmentProvider";

import "./globals.css";
Expand All @@ -20,6 +22,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
<body className={inter.className}>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<RelayEnvironmentProvider>{children}</RelayEnvironmentProvider>
<Toaster />
</ThemeProvider>
</body>
</html>
Expand Down
17 changes: 14 additions & 3 deletions apps/kampus/app/pano/features/post-list/MoreOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { MoreHorizontal } from "lucide-react";

import {
Expand All @@ -6,6 +8,7 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
useToast,
} from "@kampus/ui-next";

interface Props {
Expand All @@ -25,8 +28,8 @@ type Post = {

export const MoreOptionsDropdown = ({ post, shareUrl }: Props) => {
// const user = useUserContext();
console.log(post, shareUrl);

//console.log(post, shareUrl);
usirin marked this conversation as resolved.
Show resolved Hide resolved
const { toast } = useToast();
const ownerItems: JSX.Element[] = [];
// if (canUserEdit(user, post)) {
// ownerItems.push(
Expand Down Expand Up @@ -54,7 +57,15 @@ export const MoreOptionsDropdown = ({ post, shareUrl }: Props) => {
</DropdownMenuTrigger>
<DropdownMenuContent>
{ownerItems}
<DropdownMenuItem>Adresi kopyala</DropdownMenuItem>
<DropdownMenuItem
onSelect={() => {
toast({
description: "Link kopyalandı",
});
}}
>
Linki kopyala
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from "./toast";
export * from "./top-nav";
export * from "./use-toast";
export * from "./user-avatar";
export * from "./toaster";
66 changes: 36 additions & 30 deletions packages/ui/components/toast.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"use client";
import * as React from "react"
import * as ToastPrimitives from "@radix-ui/react-toast"
import { cva, type VariantProps } from "class-variance-authority"
import { X } from "lucide-react"

import * as React from "react";
import * as ToastPrimitives from "@radix-ui/react-toast";
import { cva, type VariantProps } from "class-variance-authority";
import { X } from "lucide-react";
import { cn } from "@kampus/ui-next/utils"

import { cn } from "@kampus/ui-next/utils";

const ToastProvider = ToastPrimitives.Provider;
const ToastProvider = ToastPrimitives.Provider

const ToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>,
Expand All @@ -21,38 +20,39 @@ const ToastViewport = React.forwardRef<
)}
{...props}
/>
));
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName

const toastVariants = cva(
"data-[swipe=move]:transition-none group relative pointer-events-auto flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full data-[state=closed]:slide-out-to-right-full",
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
{
variants: {
variant: {
default: "bg-background border",
default: "border bg-background",
destructive:
"group destructive border-destructive bg-destructive text-destructive-foreground",
"destructive group border-destructive bg-destructive text-destructive-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
);
)

const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & VariantProps<typeof toastVariants>
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => {
return (
<ToastPrimitives.Root
ref={ref}
className={cn(toastVariants({ variant }), className)}
{...props}
/>
);
});
Toast.displayName = ToastPrimitives.Root.displayName;
)
})
Toast.displayName = ToastPrimitives.Root.displayName

const ToastAction = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Action>,
Expand All @@ -61,13 +61,13 @@ const ToastAction = React.forwardRef<
<ToastPrimitives.Action
ref={ref}
className={cn(
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/30 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
className
)}
{...props}
/>
));
ToastAction.displayName = ToastPrimitives.Action.displayName;
))
ToastAction.displayName = ToastPrimitives.Action.displayName

const ToastClose = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Close>,
Expand All @@ -84,16 +84,20 @@ const ToastClose = React.forwardRef<
>
<X className="h-4 w-4" />
</ToastPrimitives.Close>
));
ToastClose.displayName = ToastPrimitives.Close.displayName;
))
ToastClose.displayName = ToastPrimitives.Close.displayName

const ToastTitle = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Title>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Title ref={ref} className={cn("text-sm font-semibold", className)} {...props} />
));
ToastTitle.displayName = ToastPrimitives.Title.displayName;
<ToastPrimitives.Title
ref={ref}
className={cn("text-sm font-semibold", className)}
{...props}
/>
))
ToastTitle.displayName = ToastPrimitives.Title.displayName

const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>,
Expand All @@ -104,12 +108,12 @@ const ToastDescription = React.forwardRef<
className={cn("text-sm opacity-90", className)}
{...props}
/>
));
ToastDescription.displayName = ToastPrimitives.Description.displayName;
))
ToastDescription.displayName = ToastPrimitives.Description.displayName

type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>

type ToastActionElement = React.ReactElement<typeof ToastAction>;
type ToastActionElement = React.ReactElement<typeof ToastAction>

export {
type ToastProps,
Expand All @@ -121,4 +125,6 @@ export {
ToastDescription,
ToastClose,
ToastAction,
};
}


33 changes: 33 additions & 0 deletions packages/ui/components/toaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import {
Toast,
ToastClose,
ToastDescription,
ToastProvider,
ToastTitle,
ToastViewport,
useToast,
} from "@kampus/ui-next";

export function Toaster() {
const { toasts } = useToast();

return (
<ToastProvider>
{toasts.map(function ({ id, title, description, action, ...props }) {
return (
<Toast key={id} {...props}>
<div className="grid gap-1">
{title && <ToastTitle>{title}</ToastTitle>}
{description && <ToastDescription>{description}</ToastDescription>}
</div>
{action}
<ToastClose />
</Toast>
);
})}
<ToastViewport />
</ToastProvider>
);
}
1 change: 1 addition & 0 deletions packages/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

export * from "./components";