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
+70 -60
View File
@@ -1,67 +1,77 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { Slot } from "radix-ui"
"use client";
import { cn } from "@/lib/utils"
import { forwardRef } from "react";
import type { ButtonHTMLAttributes, ReactNode } from "react";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
outline:
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
ghost:
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
destructive:
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default:
"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
icon: "size-8",
"icon-xs":
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
"icon-sm":
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
"icon-lg": "size-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
type ButtonVariant = "primary" | "secondary" | "outline" | "ghost" | "danger";
type ButtonSize = "sm" | "md" | "lg" | "icon" | "icon-sm";
function Button({
className,
variant = "default",
size = "default",
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot.Root : "button"
export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: ButtonVariant;
size?: ButtonSize;
};
return (
<Comp
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
const variantClasses: Record<ButtonVariant, string> = {
primary:
"border-transparent bg-primary text-primary-foreground shadow-sm hover:bg-primary-hover active:bg-primary-pressed",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-accent active:bg-accent-hover",
outline:
"border-border-strong bg-surface text-foreground shadow-sm hover:bg-accent active:bg-accent-hover",
ghost:
"border-transparent bg-transparent text-foreground hover:bg-accent active:bg-accent-hover",
danger:
"border-transparent bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive-hover active:bg-destructive-pressed",
};
const sizeClasses: Record<ButtonSize, string> = {
sm: "h-8 gap-1.5 px-3 text-xs",
md: "h-10 gap-2 px-4 text-sm",
lg: "h-11 gap-2.5 px-5 text-sm",
icon: "h-9 w-9 p-0",
"icon-sm": "h-8 w-8 p-0",
};
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant = "primary", size = "md", type = "button", ...props }, ref) => (
<button
ref={ref}
type={type}
className={cn(
"inline-flex shrink-0 items-center justify-center rounded-md border font-medium transition-colors",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
variantClasses[variant],
sizeClasses[size],
className,
)}
{...props}
/>
)
}
),
);
export { Button, buttonVariants }
Button.displayName = "Button";
export type IconButtonProps = Omit<ButtonProps, "children" | "size"> & {
label: string;
tooltip?: string;
children: ReactNode;
};
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
({ label, tooltip, children, className, ...props }, ref) => (
<Button
ref={ref}
size="icon"
aria-label={label}
title={tooltip ?? label}
className={className}
{...props}
>
{children}
</Button>
),
);
IconButton.displayName = "IconButton";
+13 -88
View File
@@ -1,103 +1,28 @@
import * as React from "react"
"use client";
import { cn } from "@/lib/utils"
import type { ComponentPropsWithoutRef } from "react";
import { cn } from "@/lib/utils";
function Card({
className,
size = "default",
...props
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
export function Card({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return (
<div
data-slot="card"
data-size={size}
className={cn(
"group/card flex flex-col gap-4 overflow-hidden rounded-xl bg-card py-4 text-sm text-card-foreground ring-1 ring-foreground/10 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
className
"rounded-md border border-border bg-card text-card-foreground shadow-sm",
className,
)}
{...props}
/>
)
);
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn(
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",
className
)}
{...props}
/>
)
export function CardHeader({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return <div className={cn("space-y-1.5 p-5", className)} {...props} />;
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-title"
className={cn(
"font-heading text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",
className
)}
{...props}
/>
)
export function CardTitle({ className, ...props }: ComponentPropsWithoutRef<"h3">) {
return <h3 className={cn("text-base font-semibold", className)} {...props} />;
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
)
}
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-action"
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
)
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
className={cn("px-4 group-data-[size=sm]/card:px-3", className)}
{...props}
/>
)
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-footer"
className={cn(
"flex items-center rounded-b-xl border-t bg-muted/50 p-4 group-data-[size=sm]/card:p-3",
className
)}
{...props}
/>
)
}
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
export function CardContent({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return <div className={cn("p-5 pt-0", className)} {...props} />;
}
+51
View File
@@ -0,0 +1,51 @@
"use client";
import type { ComponentPropsWithoutRef, ReactNode } from "react";
import { cn } from "@/lib/utils";
export function Label({ className, ...props }: ComponentPropsWithoutRef<"label">) {
return (
<label
className={cn("text-sm font-medium leading-none text-foreground", className)}
{...props}
/>
);
}
type FieldProps = ComponentPropsWithoutRef<"div"> & {
label?: ReactNode;
description?: ReactNode;
error?: ReactNode;
htmlFor?: string;
};
export function Field({
label,
description,
error,
htmlFor,
children,
className,
...props
}: FieldProps) {
const descriptionId = htmlFor && description ? `${htmlFor}-description` : undefined;
const errorId = htmlFor && error ? `${htmlFor}-error` : undefined;
return (
<div className={cn("space-y-2", className)} {...props}>
{label ? <Label htmlFor={htmlFor}>{label}</Label> : null}
{children}
{description ? (
<p id={descriptionId} className="text-xs leading-5 text-muted-foreground">
{description}
</p>
) : null}
{error ? (
<p id={errorId} role="alert" className="text-xs leading-5 text-destructive">
{error}
</p>
) : null}
</div>
);
}
+25 -14
View File
@@ -1,19 +1,30 @@
import * as React from "react"
"use client";
import { cn } from "@/lib/utils"
import { forwardRef } from "react";
import type { InputHTMLAttributes, TextareaHTMLAttributes } from "react";
import { cn } from "@/lib/utils";
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
return (
<input
type={type}
data-slot="input"
className={cn(
"h-8 w-full min-w-0 rounded-lg border border-input bg-input-bg px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-1 aria-invalid:ring-destructive/20 md:text-sm",
className
)}
const controlClasses =
"w-full rounded-md border border-input bg-input-bg px-3 text-sm text-foreground shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:bg-muted disabled:text-muted-foreground disabled:opacity-80 aria-invalid:border-destructive aria-invalid:ring-destructive";
export type InputProps = InputHTMLAttributes<HTMLInputElement>;
export const Input = forwardRef<HTMLInputElement, InputProps>(({ className, ...props }, ref) => (
<input ref={ref} className={cn(controlClasses, "h-10", className)} {...props} />
));
Input.displayName = "Input";
export type TextareaProps = TextareaHTMLAttributes<HTMLTextAreaElement>;
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => (
<textarea
ref={ref}
className={cn(controlClasses, "min-h-24 py-2", className)}
{...props}
/>
)
}
),
);
export { Input }
Textarea.displayName = "Textarea";
+1 -1
View File
@@ -1,7 +1,7 @@
"use client";
import { Loader2 } from "lucide-react";
import { Button } from "poyraz-ui/atoms";
import { Button } from "@/components/ui/button";
import type { ComponentProps, ReactNode } from "react";
import { useFormStatus } from "react-dom";
+5 -6
View File
@@ -1,13 +1,12 @@
import { cn } from "@/lib/utils"
import type { ComponentPropsWithoutRef } from "react";
import { cn } from "@/lib/utils";
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
export function Skeleton({ className, ...props }: ComponentPropsWithoutRef<"div">) {
return (
<div
data-slot="skeleton"
aria-hidden="true"
className={cn("animate-pulse rounded-md bg-muted", className)}
{...props}
/>
)
);
}
export { Skeleton }
+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}
/>
);
}