feat: add new UI components and improve existing ones

- Introduced `Field` and `Label` components for better form handling.
- Refactored `Input` and `Textarea` components to use forward refs and improved styling.
- Updated `PendingSubmitButton` to use the new `Button` component.
- Enhanced `Skeleton` component for better layout handling.
- Revamped `Toast` component to support live regions and improved accessibility.
- Updated sidebar configuration to use typed icons.
- Added phase 3 UI boundary checks to prevent usage of deprecated imports.
- Implemented new authentication action handler for better cookie management.
- Improved setup logic for freelancer accounts with repair functionality.
This commit is contained in:
Poyraz
2026-07-10 22:47:02 +03:00
parent ae8fa1425c
commit 24fcdf9a77
28 changed files with 1183 additions and 943 deletions
+142 -114
View File
@@ -1,129 +1,157 @@
"use client"
"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 { useEffect, useState } from "react";
import type { ComponentPropsWithoutRef, ReactElement } from "react";
import { X } from "lucide-react";
import { IconButton } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { cn } from "@/lib/utils"
type ToastTone = "success" | "error" | "info";
const ToastProvider = ToastPrimitives.Provider
type ToastItem = {
id: number;
message: string;
tone: ToastTone;
};
const ToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Viewport
ref={ref}
className={cn(
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
className
)}
{...props}
/>
))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
type ToastPayload = {
message: string;
tone?: ToastTone;
};
const toastVariants = cva(
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 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: "border bg-background text-foreground",
destructive:
"destructive group border-destructive bg-destructive text-destructive-foreground",
},
},
defaultVariants: {
variant: "default",
},
const toastEventName = "neta:toast";
let toastId = 0;
export function showToast(payload: ToastPayload) {
if (typeof window === "undefined") {
return;
}
)
const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => {
window.dispatchEvent(new CustomEvent<ToastPayload>(toastEventName, { detail: payload }));
}
export function Toaster() {
const [items, setItems] = useState<ToastItem[]>([]);
useEffect(() => {
function handleToast(event: Event) {
const customEvent = event as CustomEvent<ToastPayload>;
const item = {
id: ++toastId,
message: customEvent.detail.message,
tone: customEvent.detail.tone ?? "info",
};
setItems((current) => [...current.slice(-2), item]);
window.setTimeout(() => {
setItems((current) => current.filter((toast) => toast.id !== item.id));
}, 4500);
}
window.addEventListener(toastEventName, handleToast);
return () => window.removeEventListener(toastEventName, handleToast);
}, []);
return (
<ToastPrimitives.Root
ref={ref}
className={cn(toastVariants({ variant }), className)}
<div
aria-live="polite"
aria-relevant="additions text"
className="fixed bottom-4 right-4 z-[80] flex w-[min(calc(100vw-2rem),24rem)] flex-col gap-2"
>
{items.map((item) => (
<div
key={item.id}
className={cn(
"flex items-start gap-3 rounded-md border bg-surface p-4 text-sm shadow-lg",
item.tone === "error" && "border-destructive/30",
item.tone === "success" && "border-success/30",
)}
>
<div
className={cn(
"mt-1 h-2 w-2 shrink-0 rounded-full bg-info",
item.tone === "error" && "bg-destructive",
item.tone === "success" && "bg-success",
)}
/>
<p className="min-w-0 flex-1 text-foreground">{item.message}</p>
<IconButton
label="Bildirimi kapat"
variant="ghost"
className="-mr-2 -mt-2 h-8 w-8"
onClick={() => setItems((current) => current.filter((toast) => toast.id !== item.id))}
>
<X className="h-4 w-4" />
</IconButton>
</div>
))}
</div>
);
}
export type ToastProps = ComponentPropsWithoutRef<"div"> & {
open?: boolean;
onOpenChange?: (open: boolean) => void;
variant?: "default" | "destructive";
};
export type ToastActionElement = ReactElement;
export function ToastProvider({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
export function Toast({ open = true, onOpenChange, variant, className, ...props }: ToastProps) {
if (!open) {
return null;
}
return (
<div
role={variant === "destructive" ? "alert" : "status"}
className={cn(
"group pointer-events-auto flex w-full items-start gap-3 rounded-md border bg-surface p-4 text-sm shadow-lg",
variant === "destructive" && "border-destructive/30",
className,
)}
data-on-open-change={onOpenChange ? "" : undefined}
{...props}
/>
)
})
Toast.displayName = ToastPrimitives.Root.displayName
);
}
const ToastAction = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Action>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
>(({ className, ...props }, ref) => (
<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 transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring 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
export function ToastTitle({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return <div className={cn("font-medium text-foreground", className)} {...props} />;
}
const ToastClose = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Close>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Close
ref={ref}
className={cn(
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
className
)}
toast-close=""
{...props}
>
<X className="h-4 w-4" />
</ToastPrimitives.Close>
))
ToastClose.displayName = ToastPrimitives.Close.displayName
export function ToastDescription({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return <div className={cn("text-sm text-muted-foreground", className)} {...props} />;
}
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 [&+div]:text-xs", className)}
{...props}
/>
))
ToastTitle.displayName = ToastPrimitives.Title.displayName
export function ToastClose({ className, ...props }: ComponentPropsWithoutRef<"button">) {
return (
<button
type="button"
className={cn(
"ml-auto rounded-sm p-1 text-muted-foreground opacity-80 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
className,
)}
{...props}
>
<X className="h-4 w-4" />
<span className="sr-only">Bildirimi kapat</span>
</button>
);
}
const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Description
ref={ref}
className={cn("text-sm opacity-90", className)}
{...props}
/>
))
ToastDescription.displayName = ToastPrimitives.Description.displayName
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
type ToastActionElement = React.ReactElement<typeof ToastAction>
export {
type ToastProps,
type ToastActionElement,
ToastProvider,
ToastViewport,
Toast,
ToastTitle,
ToastDescription,
ToastClose,
ToastAction,
export function ToastViewport({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return (
<div
className={cn(
"fixed bottom-4 right-4 z-[80] flex w-[min(calc(100vw-2rem),24rem)] flex-col gap-2",
className,
)}
{...props}
/>
);
}