diff --git a/web/app/globals.css b/web/app/globals.css index 0aec970bf..8b84d4ed5 100644 --- a/web/app/globals.css +++ b/web/app/globals.css @@ -43,6 +43,17 @@ --input: #e6decc; --ring: #b0501e; --overlay: rgba(28, 24, 22, 0.42); + --success: #237a4b; + --success-foreground: #14532d; + --success-surface: #ecf8f0; + --warning: #a15c00; + --warning-foreground: #713f12; + --warning-surface: #fff7df; + --info: #2563eb; + --info-foreground: #1e3a8a; + --info-surface: #eff6ff; + --surface-raised: #ffffff; + --shadow-raised: 0 16px 40px rgba(69, 49, 31, 0.12); } /* Dark — warm near-black, same terracotta family as Cream. */ @@ -68,6 +79,17 @@ --input: #3a3634; --ring: #d4734b; --overlay: rgba(0, 0, 0, 0.6); + --success: #5fd08a; + --success-foreground: #bbf7d0; + --success-surface: #173424; + --warning: #f2b84b; + --warning-foreground: #fde68a; + --warning-surface: #3a2c16; + --info: #7ba7ff; + --info-foreground: #bfdbfe; + --info-surface: #172641; + --surface-raised: #2a2826; + --shadow-raised: 0 16px 44px rgba(0, 0, 0, 0.32); } /* Default — pure-white neutral canvas (theme id "snow" kept for stored @@ -96,6 +118,17 @@ --input: #e5e5e5; --ring: #2563eb; --overlay: rgba(0, 0, 0, 0.4); + --success: #16794b; + --success-foreground: #14532d; + --success-surface: #ecfdf3; + --warning: #a15c00; + --warning-foreground: #713f12; + --warning-surface: #fffaeb; + --info: #2563eb; + --info-foreground: #1e3a8a; + --info-surface: #eff6ff; + --surface-raised: #ffffff; + --shadow-raised: 0 16px 40px rgba(13, 13, 13, 0.12); } /* Glass — translucent purple panels on near-black. Slightly brighter @@ -116,10 +149,23 @@ --muted-foreground: #b5b5c7; --accent: rgba(255, 255, 255, 0.12); --accent-foreground: #ffffff; + --destructive: #f07178; + --destructive-foreground: #ffffff; --border: rgba(255, 255, 255, 0.12); --input: rgba(255, 255, 255, 0.06); --ring: #a855f7; --overlay: rgba(0, 0, 0, 0.55); + --success: #68dfa0; + --success-foreground: #bbf7d0; + --success-surface: rgba(34, 197, 94, 0.14); + --warning: #f7c65a; + --warning-foreground: #fde68a; + --warning-surface: rgba(245, 158, 11, 0.16); + --info: #9ab7ff; + --info-foreground: #dbeafe; + --info-surface: rgba(59, 130, 246, 0.16); + --surface-raised: rgba(35, 32, 51, 0.96); + --shadow-raised: 0 18px 48px rgba(0, 0, 0, 0.42); } .theme-glass body { @@ -167,6 +213,9 @@ html { -webkit-font-smoothing: antialiased; + --motion-fast: 120ms; + --motion-base: 180ms; + --motion-slow: 240ms; } html[data-scroll-behavior="smooth"] { @@ -189,6 +238,22 @@ summary::-webkit-details-marker { display: none; } + + :focus-visible { + outline: 2px solid var(--ring); + outline-offset: 2px; + } + + @media (prefers-reduced-motion: reduce) { + *, + *::before, + *::after { + scroll-behavior: auto !important; + animation-duration: 0.01ms !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + } + } } @layer components { @@ -199,6 +264,11 @@ .muted-chip { @apply rounded-full bg-[var(--muted)] px-3 py-1 text-xs text-[var(--muted-foreground)]; } + + .surface-raised { + background: var(--surface-raised); + box-shadow: var(--shadow-raised); + } } @layer utilities { diff --git a/web/components/ui/Button.tsx b/web/components/ui/Button.tsx index 0b2c67e46..23c0f036b 100644 --- a/web/components/ui/Button.tsx +++ b/web/components/ui/Button.tsx @@ -1,64 +1,6 @@ -"use client"; - -import React from "react"; -import { Loader2 } from "lucide-react"; - -interface ButtonProps extends React.ButtonHTMLAttributes { - variant?: "primary" | "secondary" | "danger" | "ghost"; - size?: "sm" | "md" | "lg"; - loading?: boolean; - icon?: React.ReactNode; - children: React.ReactNode; -} - -const variantStyles = { - primary: - "bg-[var(--primary)] text-[var(--primary-foreground)] hover:opacity-90 shadow-md shadow-[var(--primary)]/15", - secondary: - "bg-[var(--secondary)] text-[var(--secondary-foreground)] hover:bg-[var(--muted)]", - danger: - "bg-[var(--destructive)] text-[var(--destructive-foreground)] hover:opacity-90 shadow-md shadow-[var(--destructive)]/15", - ghost: - "text-[var(--muted-foreground)] hover:bg-[var(--muted)] hover:text-[var(--foreground)]", -}; - -const sizeStyles = { - sm: "px-3 py-1.5 text-xs", - md: "px-4 py-2 text-sm", - lg: "px-6 py-3 text-base", -}; - -export default function Button({ - variant = "primary", - size = "md", - loading = false, - icon, - children, - className = "", - disabled, - ...props -}: ButtonProps) { - return ( - - ); -} +export { Button as default, Button } from "@/shared/ui/Button"; +export type { + ButtonProps, + ButtonSize, + ButtonVariant, +} from "@/shared/ui/Button"; diff --git a/web/shared/ui/Button.tsx b/web/shared/ui/Button.tsx new file mode 100644 index 000000000..c31295378 --- /dev/null +++ b/web/shared/ui/Button.tsx @@ -0,0 +1,70 @@ +"use client"; + +import { forwardRef, type ButtonHTMLAttributes, type ReactNode } from "react"; +import { Loader2 } from "lucide-react"; +import { cn } from "./styles"; + +export type ButtonVariant = "primary" | "secondary" | "danger" | "ghost"; +export type ButtonSize = "sm" | "md" | "lg"; + +export interface ButtonProps extends ButtonHTMLAttributes { + variant?: ButtonVariant; + size?: ButtonSize; + loading?: boolean; + icon?: ReactNode; +} + +const variants: Record = { + primary: + "bg-primary text-primary-foreground shadow-sm hover:brightness-95 active:brightness-90", + secondary: + "border border-border bg-secondary text-secondary-foreground hover:bg-muted active:bg-accent", + danger: + "bg-destructive text-destructive-foreground shadow-sm hover:brightness-95 active:brightness-90", + ghost: + "text-muted-foreground hover:bg-muted hover:text-foreground active:bg-accent", +}; + +const sizes: Record = { + sm: "min-h-8 rounded-lg px-3 text-xs", + md: "min-h-10 rounded-xl px-4 text-sm", + lg: "min-h-12 rounded-xl px-5 text-base", +}; + +export const Button = forwardRef(function Button( + { + variant = "primary", + size = "md", + loading = false, + icon, + children, + className, + disabled, + type = "button", + ...props + }, + ref, +) { + return ( + + ); +}); + +export default Button; diff --git a/web/shared/ui/Dialog.tsx b/web/shared/ui/Dialog.tsx new file mode 100644 index 000000000..a1e4d6877 --- /dev/null +++ b/web/shared/ui/Dialog.tsx @@ -0,0 +1,176 @@ +"use client"; + +import { + useEffect, + useId, + useRef, + type KeyboardEvent, + type MouseEvent, + type ReactNode, +} from "react"; +import { X } from "lucide-react"; +import { IconButton } from "./IconButton"; +import { cn } from "./styles"; + +const FOCUSABLE = + 'a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]'; + +export interface DialogProps { + open: boolean; + title: string; + children: ReactNode; + onClose: () => void; + description?: string; + footer?: ReactNode; + size?: "sm" | "md" | "lg" | "xl"; + closeLabel?: string; + closeOnBackdrop?: boolean; + closeOnEscape?: boolean; + busy?: boolean; + alert?: boolean; + className?: string; +} + +const widths = { + sm: "max-w-sm", + md: "max-w-lg", + lg: "max-w-2xl", + xl: "max-w-4xl", +}; + +export function Dialog({ + open, + title, + children, + onClose, + description, + footer, + size = "md", + closeLabel = "Close", + closeOnBackdrop = true, + closeOnEscape = true, + busy = false, + alert = false, + className, +}: DialogProps) { + const dialogRef = useRef(null); + const titleId = useId(); + const descriptionId = useId(); + + useEffect(() => { + if (!open) return; + const previous = document.activeElement as HTMLElement | null; + const previousOverflow = document.body.style.overflow; + document.body.style.overflow = "hidden"; + const frame = requestAnimationFrame(() => { + const root = dialogRef.current; + const target = + root?.querySelector("[data-autofocus]") ?? + root?.querySelector(FOCUSABLE) ?? + root; + target?.focus(); + }); + + return () => { + cancelAnimationFrame(frame); + document.body.style.overflow = previousOverflow; + if (previous && document.contains(previous)) previous.focus(); + }; + }, [open]); + + useEffect(() => { + if (!open || !closeOnEscape || busy) return; + const handleEscape = (event: globalThis.KeyboardEvent) => { + if (event.key !== "Escape") return; + event.stopPropagation(); + onClose(); + }; + window.addEventListener("keydown", handleEscape); + return () => window.removeEventListener("keydown", handleEscape); + }, [busy, closeOnEscape, onClose, open]); + + if (!open) return null; + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key !== "Tab") return; + const focusable = Array.from( + dialogRef.current?.querySelectorAll(FOCUSABLE) ?? [], + ); + if (focusable.length === 0) { + event.preventDefault(); + dialogRef.current?.focus(); + return; + } + const first = focusable[0]; + const last = focusable[focusable.length - 1]; + if (event.shiftKey && document.activeElement === first) { + event.preventDefault(); + last.focus(); + } else if (!event.shiftKey && document.activeElement === last) { + event.preventDefault(); + first.focus(); + } + }; + + const handleBackdrop = (event: MouseEvent) => { + if ( + event.target === event.currentTarget && + closeOnBackdrop && + !busy + ) { + onClose(); + } + }; + + return ( +
+
+
+
+

+ {title} +

+ {description ? ( +

+ {description} +

+ ) : null} +
+ } + size="sm" + disabled={busy} + onClick={onClose} + /> +
+
{children}
+ {footer ? ( +
+ {footer} +
+ ) : null} +
+
+ ); +} diff --git a/web/shared/ui/EmptyState.tsx b/web/shared/ui/EmptyState.tsx new file mode 100644 index 000000000..02792c0df --- /dev/null +++ b/web/shared/ui/EmptyState.tsx @@ -0,0 +1,45 @@ +import type { ReactNode } from "react"; +import { cn } from "./styles"; + +export interface EmptyStateProps { + title: string; + description?: string; + icon?: ReactNode; + action?: ReactNode; + compact?: boolean; + className?: string; +} + +export function EmptyState({ + title, + description, + icon, + action, + compact = false, + className, +}: EmptyStateProps) { + return ( +
+ {icon ? ( +
+ {icon} +
+ ) : null} +
+

{title}

+ {description ? ( +

+ {description} +

+ ) : null} +
+ {action ?
{action}
: null} +
+ ); +} diff --git a/web/shared/ui/Field.tsx b/web/shared/ui/Field.tsx new file mode 100644 index 000000000..971387d4c --- /dev/null +++ b/web/shared/ui/Field.tsx @@ -0,0 +1,65 @@ +import { useId, type ReactElement, type ReactNode } from "react"; +import { cloneElement } from "react"; +import { cn } from "./styles"; + +export interface FieldProps { + label: string; + children: ReactElement<{ + id?: string; + "aria-describedby"?: string; + "aria-invalid"?: boolean; + }>; + hint?: ReactNode; + error?: ReactNode; + optionalLabel?: string; + className?: string; +} + +export function Field({ + label, + children, + hint, + error, + optionalLabel, + className, +}: FieldProps) { + const generatedId = useId(); + const controlId = children.props.id ?? generatedId; + const hintId = `${generatedId}-hint`; + const errorId = `${generatedId}-error`; + const describedBy = [ + children.props["aria-describedby"], + hint ? hintId : undefined, + error ? errorId : undefined, + ] + .filter(Boolean) + .join(" "); + + return ( +
+ + {cloneElement(children, { + id: controlId, + "aria-describedby": describedBy || undefined, + "aria-invalid": error ? true : children.props["aria-invalid"], + })} + {hint ? ( +

+ {hint} +

+ ) : null} + {error ? ( +

+ {error} +

+ ) : null} +
+ ); +} diff --git a/web/shared/ui/IconButton.tsx b/web/shared/ui/IconButton.tsx new file mode 100644 index 000000000..34b79de12 --- /dev/null +++ b/web/shared/ui/IconButton.tsx @@ -0,0 +1,54 @@ +"use client"; + +import { forwardRef, type ButtonHTMLAttributes, type ReactNode } from "react"; +import { Tooltip } from "./Tooltip"; +import { cn } from "./styles"; + +export interface IconButtonProps + extends Omit, "children"> { + label: string; + icon: ReactNode; + size?: "sm" | "md" | "lg"; + tooltipSide?: "top" | "right" | "bottom" | "left"; +} + +const sizes = { + sm: "h-8 w-8 rounded-lg", + md: "h-10 w-10 rounded-xl", + lg: "h-12 w-12 rounded-xl", +}; + +export const IconButton = forwardRef( + function IconButton( + { + label, + icon, + size = "md", + tooltipSide = "bottom", + className, + type = "button", + ...props + }, + ref, + ) { + return ( + + + + ); + }, +); diff --git a/web/shared/ui/InlineAlert.tsx b/web/shared/ui/InlineAlert.tsx new file mode 100644 index 000000000..a60437464 --- /dev/null +++ b/web/shared/ui/InlineAlert.tsx @@ -0,0 +1,53 @@ +import type { HTMLAttributes, ReactNode } from "react"; +import { AlertCircle, CheckCircle2, Info, TriangleAlert } from "lucide-react"; +import { cn } from "./styles"; +import type { StatusTone } from "./StatusChip"; + +export interface InlineAlertProps extends HTMLAttributes { + tone?: Exclude; + title?: string; + action?: ReactNode; +} + +const toneStyles = { + info: "border-info/20 bg-info-surface text-info-foreground", + success: "border-success/20 bg-success-surface text-success-foreground", + warning: "border-warning/20 bg-warning-surface text-warning-foreground", + danger: "border-destructive/20 bg-destructive/10 text-destructive", +}; + +const icons = { + info: Info, + success: CheckCircle2, + warning: TriangleAlert, + danger: AlertCircle, +}; + +export function InlineAlert({ + tone = "info", + title, + action, + children, + className, + ...props +}: InlineAlertProps) { + const Icon = icons[tone]; + return ( +
+ +
+ {title ?

{title}

: null} +
{children}
+
+ {action ?
{action}
: null} +
+ ); +} diff --git a/web/shared/ui/Skeleton.tsx b/web/shared/ui/Skeleton.tsx new file mode 100644 index 000000000..ce2d50635 --- /dev/null +++ b/web/shared/ui/Skeleton.tsx @@ -0,0 +1,12 @@ +import type { HTMLAttributes } from "react"; +import { cn } from "./styles"; + +export function Skeleton({ className, ...props }: HTMLAttributes) { + return ( +