From f485edb44112d278a6a2641ac0ae2f626f850544 Mon Sep 17 00:00:00 2001 From: olestang Date: Thu, 1 Oct 2026 10:21:38 +0200 Subject: [PATCH 1/5] feat: add feedback UI components --- .../components/ui/EmptyState/EmptyState.css | 113 ++++++++++++++++ .../components/ui/EmptyState/EmptyState.tsx | 54 ++++++++ .../ui/FeedbackMessage/FeedbackMessage.css | 83 ++++++++++++ .../ui/FeedbackMessage/FeedbackMessage.tsx | 45 ++++++ apps/web/src/components/ui/Toast/Toast.css | 128 ++++++++++++++++++ apps/web/src/components/ui/Toast/Toast.tsx | 62 +++++++++ .../components/ui/internal/feedbackTone.ts | 20 +++ 7 files changed, 505 insertions(+) create mode 100644 apps/web/src/components/ui/EmptyState/EmptyState.css create mode 100644 apps/web/src/components/ui/EmptyState/EmptyState.tsx create mode 100644 apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.css create mode 100644 apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.tsx create mode 100644 apps/web/src/components/ui/Toast/Toast.css create mode 100644 apps/web/src/components/ui/Toast/Toast.tsx create mode 100644 apps/web/src/components/ui/internal/feedbackTone.ts diff --git a/apps/web/src/components/ui/EmptyState/EmptyState.css b/apps/web/src/components/ui/EmptyState/EmptyState.css new file mode 100644 index 0000000..39027a8 --- /dev/null +++ b/apps/web/src/components/ui/EmptyState/EmptyState.css @@ -0,0 +1,113 @@ +@layer components { + .empty-state { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + width: 100%; + + text-align: center; + } + + /* Variants */ + + .empty-state--surface { + background-color: + var(--color-surface); + + border: + var(--border-width-thin) + solid + var(--color-border-subtle); + + border-radius: + var(--radius-xl); + } + + .empty-state--plain { + background-color: + transparent; + } + + /* Sizes */ + + .empty-state--md { + gap: var(--space-4); + + min-height: 18rem; + + padding: + var(--space-8) + var(--space-6); + } + + .empty-state--sm { + gap: var(--space-3); + + min-height: 12rem; + + padding: + var(--space-6) + var(--space-4); + } + + /* Content */ + + .empty-state__content { + display: flex; + flex-direction: column; + align-items: center; + gap: var(--space-2); + + max-width: 30rem; + } + + .empty-state__title { + color: + var(--color-text-primary); + + font-size: + var(--font-size-xl); + + line-height: + var(--line-height-tight); + } + + .empty-state--sm + .empty-state__title { + font-size: + var(--font-size-lg); + } + + .empty-state__description { + color: + var(--color-text-secondary); + + font-size: + var(--font-size-sm); + + line-height: + var(--line-height-relaxed); + } + + /* Action */ + + .empty-state__action { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + gap: var(--space-3); + } + + @media (max-width: 30rem) { + .empty-state--md { + min-height: 15rem; + + padding: + var(--space-6) + var(--space-4); + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/EmptyState/EmptyState.tsx b/apps/web/src/components/ui/EmptyState/EmptyState.tsx new file mode 100644 index 0000000..0f0cea2 --- /dev/null +++ b/apps/web/src/components/ui/EmptyState/EmptyState.tsx @@ -0,0 +1,54 @@ +import type { ComponentType, ReactNode } from "react"; + +import type { IconProps as SvgIconProps } from "../../../icons/types"; +import { IconBadge } from "../IconBadge/IconBadge"; +import "./EmptyState.css"; + +export type EmptyStateVariant = "surface" | "plain"; +export type EmptyStateSize = "sm" | "md"; + +export type EmptyStateProps = { + icon?: ComponentType; + iconProps?: Partial; + title: ReactNode; + description?: ReactNode; + action?: ReactNode; + variant?: EmptyStateVariant; + size?: EmptyStateSize; +}; + +function EmptyState({ + icon, + iconProps, + title, + description, + action, + variant = "surface", + size = "md", +}: EmptyStateProps) { + return ( +
+ {icon && ( +
+ ); +} + +export default EmptyState; diff --git a/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.css b/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.css new file mode 100644 index 0000000..92012d8 --- /dev/null +++ b/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.css @@ -0,0 +1,83 @@ +@layer components { + .feedback-message { + display: flex; + align-items: flex-start; + gap: var(--space-3); + + width: 100%; + + padding: var(--space-4); + + border: + var(--border-width-thin) + solid + transparent; + + border-radius: var(--radius-md); + } + + .feedback-message__icon { + display: inline-flex; + flex: 0 0 auto; + + margin-block-start: 0.1rem; + } + + .feedback-message__icon > svg { + display: block; + + width: var(--icon-size-md); + height: var(--icon-size-md); + } + + .feedback-message__content { + display: flex; + flex: 1 1 auto; + flex-direction: column; + gap: var(--space-1); + + min-width: 0; + } + + .feedback-message__title { + font-weight: var(--font-weight-semibold); + line-height: var(--line-height-snug); + } + + .feedback-message__text { + font-size: var(--font-size-sm); + line-height: var(--line-height-normal); + } + + /* Success */ + + .feedback-message--success { + color: var(--color-feedback-success); + background-color: var(--color-feedback-success-surface); + border-color: var(--color-feedback-success-border); + } + + /* Error */ + + .feedback-message--error { + color: var(--color-feedback-error); + background-color: var(--color-feedback-error-surface); + border-color: var(--color-feedback-error-border); + } + + /* Warning */ + + .feedback-message--warning { + color: var(--color-feedback-warning); + background-color: var(--color-feedback-warning-surface); + border-color: var(--color-feedback-warning-border); + } + + /* Info */ + + .feedback-message--info { + color: var(--color-feedback-info); + background-color: var(--color-feedback-info-surface); + border-color: var(--color-feedback-info-border); + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.tsx b/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.tsx new file mode 100644 index 0000000..94ac026 --- /dev/null +++ b/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.tsx @@ -0,0 +1,45 @@ +import type { HTMLAttributes, ReactNode } from "react"; + +import { Icon } from "../Icon/Icon"; +import { feedbackIcon, feedbackRole, type FeedbackTone } from "../internal/feedbackTone"; +import "./FeedbackMessage.css"; + +export type FeedbackMessageTone = FeedbackTone; + +export type FeedbackMessageProps = HTMLAttributes & { + tone: FeedbackMessageTone; + title?: ReactNode; + children: ReactNode; +}; + +function FeedbackMessage({ + tone, + title, + children, + className = "", + ...props +}: FeedbackMessageProps) { + const classes = ["feedback-message", `feedback-message--${tone}`, className] + .filter(Boolean) + .join(" "); + + return ( +
+ + +
+ {title && {title}} +
{children}
+
+
+ ); +} + +export default FeedbackMessage; diff --git a/apps/web/src/components/ui/Toast/Toast.css b/apps/web/src/components/ui/Toast/Toast.css new file mode 100644 index 0000000..d20beeb --- /dev/null +++ b/apps/web/src/components/ui/Toast/Toast.css @@ -0,0 +1,128 @@ +@layer components { + .toast { + --toast-color: + var(--color-feedback-info); + + --toast-surface: + var(--color-feedback-info-surface); + + --toast-border: + var(--color-feedback-info-border); + + display: flex; + align-items: flex-start; + gap: var(--space-3); + + width: min(24rem, 100%); + + padding: + var(--space-3) + var(--space-3) + var(--space-3) + var(--space-4); + + color: var(--toast-color); + background-color: var(--toast-surface); + + border: + var(--border-width-thin) + solid + var(--toast-border); + + border-radius: var(--radius-lg); + + box-shadow: var(--shadow-lg); + } + + .toast--success { + --toast-color: + var(--color-feedback-success); + + --toast-surface: + var(--color-feedback-success-surface); + + --toast-border: + var(--color-feedback-success-border); + } + + .toast--error { + --toast-color: + var(--color-feedback-error); + + --toast-surface: + var(--color-feedback-error-surface); + + --toast-border: + var(--color-feedback-error-border); + } + + .toast--warning { + --toast-color: + var(--color-feedback-warning); + + --toast-surface: + var(--color-feedback-warning-surface); + + --toast-border: + var(--color-feedback-warning-border); + } + + .toast--info { + --toast-color: + var(--color-feedback-info); + + --toast-surface: + var(--color-feedback-info-surface); + + --toast-border: + var(--color-feedback-info-border); + } + + .toast__icon { + display: inline-flex; + flex: 0 0 auto; + + margin-block-start: var(--space-1); + } + + .toast__icon > svg { + width: var(--icon-size-md); + height: var(--icon-size-md); + } + + .toast__content { + display: flex; + flex: 1 1 auto; + flex-direction: column; + gap: var(--space-1); + + min-width: 0; + + padding-block-start: + var(--space-1); + } + + .toast__title { + color: var(--toast-color); + + font-weight: + var(--font-weight-semibold); + + line-height: + var(--line-height-snug); + } + + .toast__message { + color: var(--color-text-secondary); + + font-size: var(--font-size-sm); + line-height: + var(--line-height-normal); + } + + @media (max-width: 30rem) { + .toast { + width: 100%; + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Toast/Toast.tsx b/apps/web/src/components/ui/Toast/Toast.tsx new file mode 100644 index 0000000..c2d21cb --- /dev/null +++ b/apps/web/src/components/ui/Toast/Toast.tsx @@ -0,0 +1,62 @@ +import { useEffect, type ReactNode } from "react"; + +import { CloseIcon } from "../../../icons/actions"; +import { Icon } from "../Icon/Icon"; +import IconButton from "../IconButton/IconButton"; +import { feedbackIcon, feedbackRole, type FeedbackTone } from "../internal/feedbackTone"; +import "./Toast.css"; + +export type ToastTone = FeedbackTone; + +export type ToastProps = { + open: boolean; + tone?: ToastTone; + title?: ReactNode; + children: ReactNode; + duration?: number | null; + onClose: () => void; +}; + +function Toast({ + open, + tone = "info", + title, + children, + duration = 5000, + onClose, +}: ToastProps) { + useEffect(() => { + if (!open || duration === null) return; + const timeout = window.setTimeout(onClose, duration); + return () => window.clearTimeout(timeout); + }, [open, duration, onClose]); + + if (!open) return null; + + return ( +
+ + +
+ {title && {title}} +
{children}
+
+ + +
+ ); +} + +export default Toast; diff --git a/apps/web/src/components/ui/internal/feedbackTone.ts b/apps/web/src/components/ui/internal/feedbackTone.ts new file mode 100644 index 0000000..06cb609 --- /dev/null +++ b/apps/web/src/components/ui/internal/feedbackTone.ts @@ -0,0 +1,20 @@ +import type { ComponentType } from "react"; +import { AlertTriangleIcon, ErrorIcon, InfoIcon, SuccessIcon } from "../../../icons/status"; +import type { IconProps as SvgIconProps } from "../../../icons/types"; + +export type FeedbackTone = "success" | "error" | "warning" | "info"; + +const FEEDBACK_ICONS: Record> = { + success: SuccessIcon, + error: ErrorIcon, + warning: AlertTriangleIcon, + info: InfoIcon, +}; + +export function feedbackIcon(tone: FeedbackTone) { + return FEEDBACK_ICONS[tone]; +} + +export function feedbackRole(tone: FeedbackTone): "alert" | "status" { + return tone === "error" ? "alert" : "status"; +} From a1f0b3fe26f7976a54618185b5df04042898b65c Mon Sep 17 00:00:00 2001 From: olestang Date: Thu, 1 Oct 2026 10:22:05 +0200 Subject: [PATCH 2/5] feat: add dialog and overlay components --- .../ConfirmationDialog/ConfirmationDialog.css | 70 ++++ .../ConfirmationDialog/ConfirmationDialog.tsx | 80 +++++ apps/web/src/components/ui/Dialog/Dialog.css | 195 +++++++++++ apps/web/src/components/ui/Dialog/Dialog.tsx | 129 +++++++ apps/web/src/components/ui/Sheet/Sheet.css | 314 ++++++++++++++++++ apps/web/src/components/ui/Sheet/Sheet.tsx | 85 +++++ .../ui/internal/useDialogControl.ts | 91 +++++ 7 files changed, 964 insertions(+) create mode 100644 apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.css create mode 100644 apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.tsx create mode 100644 apps/web/src/components/ui/Dialog/Dialog.css create mode 100644 apps/web/src/components/ui/Dialog/Dialog.tsx create mode 100644 apps/web/src/components/ui/Sheet/Sheet.css create mode 100644 apps/web/src/components/ui/Sheet/Sheet.tsx create mode 100644 apps/web/src/components/ui/internal/useDialogControl.ts diff --git a/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.css b/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.css new file mode 100644 index 0000000..7d2773b --- /dev/null +++ b/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.css @@ -0,0 +1,70 @@ +@layer components { + .confirmation-dialog__message { + color: var(--color-text-secondary); + + line-height: var(--line-height-normal); + } + + /* Warning */ + + .confirmation-dialog__message--warning { + padding: var(--space-3); + + color: var(--color-feedback-warning); + background-color: var(--color-feedback-warning-surface); + + border: + var(--border-width-thin) + solid + var(--color-feedback-warning-border); + + border-radius: var(--radius-md); + } + + /* Error */ + + .confirmation-dialog__message--error { + padding: var(--space-3); + + color: var(--color-feedback-error); + background-color: var(--color-feedback-error-surface); + + border: + var(--border-width-thin) + solid + var(--color-feedback-error-border); + + border-radius: var(--radius-md); + } + + /* Actions */ + + .confirmation-dialog__actions { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: flex-end; + gap: var(--space-3); + + width: 100%; + } + + @media (max-width: 30rem) { + .confirmation-dialog__actions { + display: grid; + grid-template-columns: + 1fr + 1fr; + } + + .confirmation-dialog__actions .button { + width: 100%; + } + } + + @media (max-width: 22rem) { + .confirmation-dialog__actions { + grid-template-columns: 1fr; + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.tsx b/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.tsx new file mode 100644 index 0000000..7bdbe35 --- /dev/null +++ b/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.tsx @@ -0,0 +1,80 @@ +import type { ReactNode } from 'react'; + +import { SuccessIcon } from '../../../icons/status'; +import Button from '../Button/Button'; +import Dialog, { type DialogTone } from '../Dialog/Dialog'; +import { feedbackIcon } from '../internal/feedbackTone'; +import './ConfirmationDialog.css'; + +export type ConfirmationDialogProps = { + open: boolean; + title: ReactNode; + description?: ReactNode; + children?: ReactNode; + confirmLabel?: string; + cancelLabel?: string; + tone?: DialogTone; + onConfirm: () => void; + onCancel: () => void; +}; + +function iconForTone(tone: DialogTone) { + if (tone === 'primary' || tone === 'brand') { + return SuccessIcon; + } + + return feedbackIcon(tone); +} + +function ConfirmationDialog({ + open, + title, + description, + children, + confirmLabel = 'Confirm', + cancelLabel = 'Cancel', + tone = 'primary', + onConfirm, + onCancel, +}: ConfirmationDialogProps) { + const isError = tone === 'error'; + + return ( + + + + + + } + > + {children != null && ( +
+ {children} +
+ )} +
+ ); +} + +export default ConfirmationDialog; \ No newline at end of file diff --git a/apps/web/src/components/ui/Dialog/Dialog.css b/apps/web/src/components/ui/Dialog/Dialog.css new file mode 100644 index 0000000..00a49ac --- /dev/null +++ b/apps/web/src/components/ui/Dialog/Dialog.css @@ -0,0 +1,195 @@ +@layer components { + .dialog { + --dialog-max-width: 34rem; + + width: + min( + calc(100% - (var(--space-4) * 2)), + var(--dialog-max-width) + ); + + max-height: + calc(100dvh - (var(--space-6) * 2)); + + margin: auto; + padding: 0; + + color: var(--color-text-primary); + background: transparent; + + border: 0; + border-radius: var(--radius-xl); + + overflow: visible; + } + + /* Sizes */ + + .dialog--sm { + --dialog-max-width: 28rem; + } + + .dialog--md { + --dialog-max-width: 34rem; + } + + /* Backdrop */ + + .dialog::backdrop { + background-color: var(--color-backdrop); + } + + /* Surface */ + + .dialog__surface { + display: flex; + flex-direction: column; + + width: 100%; + max-height: + calc(100dvh - (var(--space-6) * 2)); + + background-color: var(--color-surface); + + border: + var(--border-width-thin) + solid + var(--color-border-subtle); + + border-radius: var(--radius-xl); + + box-shadow: var(--shadow-lg); + + overflow: hidden; + } + + /* Header */ + + .dialog__header { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: var(--space-4); + + padding: + var(--space-5) + var(--space-5) + var(--space-4); + } + + .dialog__header-content { + display: flex; + flex: 1 1 auto; + align-items: flex-start; + gap: var(--space-4); + + min-width: 0; + } + + /* Heading */ + + .dialog__heading { + display: flex; + flex: 1 1 auto; + flex-direction: column; + gap: var(--space-1); + + min-width: 0; + + padding-block-start: var(--space-1); + } + + .dialog__title { + font-size: var(--font-size-xl); + line-height: var(--line-height-tight); + } + + .dialog__description { + color: var(--color-text-secondary); + + font-size: var(--font-size-sm); + line-height: var(--line-height-normal); + } + + /* Body */ + + .dialog__body { + flex: 1 1 auto; + + min-height: 0; + + padding: var(--space-5); + + color: var(--color-text-primary); + + line-height: var(--line-height-normal); + + border-top: + var(--border-width-thin) + solid + var(--color-border-divider); + + overflow-y: auto; + } + + /* Footer */ + + .dialog__footer { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: flex-end; + gap: var(--space-3); + + padding: + var(--space-4) + var(--space-5); + + background-color: var(--color-surface-raised); + + border-top: + var(--border-width-thin) + solid + var(--color-border-divider); + } + + .dialog__header + .dialog__footer { + border-top: + var(--border-width-thin) + solid + var(--color-border-divider); + } + + /* Narrow screens */ + + @media (max-width: 30rem) { + .dialog { + width: + calc(100% - (var(--space-3) * 2)); + + max-height: + calc(100dvh - (var(--space-3) * 2)); + } + + .dialog__surface { + max-height: + calc(100dvh - (var(--space-3) * 2)); + } + + .dialog__header { + padding: var(--space-4); + } + + .dialog__header-content { + gap: var(--space-3); + } + + .dialog__body { + padding: var(--space-4); + } + + .dialog__footer { + padding: var(--space-4); + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Dialog/Dialog.tsx b/apps/web/src/components/ui/Dialog/Dialog.tsx new file mode 100644 index 0000000..4580050 --- /dev/null +++ b/apps/web/src/components/ui/Dialog/Dialog.tsx @@ -0,0 +1,129 @@ +import type { ComponentType, ReactNode } from 'react'; + +import { CloseIcon } from '../../../icons/actions'; +import type { IconProps as SvgIconProps } from '../../../icons/types'; +import IconButton from '../IconButton/IconButton'; +import { + IconBadge, + type IconBadgeTone, + type IconBadgeVariant, +} from '../IconBadge/IconBadge'; +import type { FeedbackTone } from '../internal/feedbackTone'; +import { useDialogControl } from '../internal/useDialogControl'; +import './Dialog.css'; + +export type DialogSize = 'sm' | 'md'; +export type DialogTone = 'primary' | 'brand' | FeedbackTone; + +export type DialogProps = { + open: boolean; + title: ReactNode; + description?: ReactNode; + icon?: ComponentType; + iconProps?: Partial; + children?: ReactNode; + footer?: ReactNode; + size?: DialogSize; + tone?: DialogTone; + closeLabel?: string; + closeOnBackdrop?: boolean; + showCloseButton?: boolean; + onClose: () => void; +}; + +function badgeTreatment(tone: DialogTone): { + tone: IconBadgeTone; + variant: IconBadgeVariant; +} { + if (tone === 'primary') { + return { tone: 'brand', variant: 'solid' }; + } + + if (tone === 'brand') { + return { tone: 'brand', variant: 'soft' }; + } + + return { tone, variant: 'soft' }; +} + +function Dialog({ + open, + title, + description, + icon, + iconProps, + children, + footer, + size = 'md', + tone = 'primary', + closeLabel = 'Close dialog', + closeOnBackdrop = true, + showCloseButton = true, + onClose, +}: DialogProps) { + const { dialogRef, titleId, descriptionId, handleCancel } = useDialogControl({ + open, + onClose, + closeOnBackdrop, + hasDescription: Boolean(description), + }); + + const classes = ['dialog', `dialog--${size}`, `dialog--${tone}`].join(' '); + const badge = badgeTreatment(tone); + + return ( + +
+
+
+ {icon && ( +
+ + {showCloseButton && ( + + )} +
+ + {children &&
{children}
} + + {footer &&
{footer}
} +
+
+ ); +} + +export default Dialog; \ No newline at end of file diff --git a/apps/web/src/components/ui/Sheet/Sheet.css b/apps/web/src/components/ui/Sheet/Sheet.css new file mode 100644 index 0000000..da788e9 --- /dev/null +++ b/apps/web/src/components/ui/Sheet/Sheet.css @@ -0,0 +1,314 @@ +@layer components { + .sheet { + position: fixed; + + inset: + auto + 0 + 0 + 0; + + width: 100%; + max-width: 42rem; + + max-height: + calc( + 100dvh - + var(--space-6) + ); + + margin: 0 auto; + padding: 0; + + color: + var(--color-text-primary); + + background-color: + var(--color-surface); + + border: + var(--border-width-thin) + solid + var(--color-border-subtle); + + border-block-end: 0; + + border-radius: + var(--radius-xl) + var(--radius-xl) + 0 + 0; + + box-shadow: + 0 -12px 32px + color-mix( + in srgb, + var(--color-shadow) 14%, + transparent + ); + + overflow: hidden; + + overscroll-behavior: contain; + } + + .sheet::backdrop { + background-color: + var(--color-backdrop); + + animation: + sheet-backdrop-in + var(--duration-normal) + var(--ease-standard) + both; + } + + .sheet[open] { + animation: + sheet-enter + var(--duration-normal) + var(--ease-standard) + both; + } + + /* ========================================================= + Handle + ========================================================= */ + + .sheet__handle-area { + display: flex; + align-items: center; + justify-content: center; + + height: 1.5rem; + + padding-block-start: + var(--space-2); + + background-color: + var(--color-surface); + } + + .sheet__handle { + display: block; + + width: 2.75rem; + height: 0.25rem; + + background-color: + var(--color-border-strong); + + border-radius: + var(--radius-full); + + opacity: 0.7; + } + + /* ========================================================= + Header + ========================================================= */ + + .sheet__header { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: var(--space-4); + + padding: + var(--space-3) + var(--space-5) + var(--space-4); + + background-color: + var(--color-surface); + + border-bottom: + var(--border-width-thin) + solid + var(--color-border-divider); + } + + .sheet__heading { + display: flex; + flex: 1 1 auto; + flex-direction: column; + gap: var(--space-1); + + min-width: 0; + } + + .sheet__title { + color: + var(--color-text-primary); + + font-size: + var(--font-size-xl); + + font-weight: + var(--font-weight-bold); + + line-height: + var(--line-height-tight); + } + + .sheet__description { + color: + var(--color-text-secondary); + + font-size: + var(--font-size-sm); + + line-height: + var(--line-height-normal); + } + + /* ========================================================= + Body + ========================================================= */ + + .sheet__body { + min-height: 0; + + padding: + var(--space-4) + var(--space-5) + calc( + var(--space-5) + + env(safe-area-inset-bottom) + ); + + overflow-y: auto; + + overscroll-behavior: contain; + } + + /* + * Footer handles the safe-area spacing when present, + * so the body's extra bottom padding is unnecessary. + */ + .sheet__body:has(+ .sheet__footer) { + padding-block-end: + var(--space-4); + } + + /* ========================================================= + Footer + ========================================================= */ + + .sheet__footer { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: flex-end; + gap: var(--space-3); + + padding: + var(--space-4) + var(--space-5) + calc( + var(--space-4) + + env(safe-area-inset-bottom) + ); + + background-color: + var(--color-surface-raised); + + border-top: + var(--border-width-thin) + solid + var(--color-border-divider); + } + + /* ========================================================= + Animation + ========================================================= */ + + @keyframes sheet-enter { + from { + transform: + translateY(100%); + + opacity: 0.7; + } + + to { + transform: + translateY(0); + + opacity: 1; + } + } + + @keyframes sheet-backdrop-in { + from { + opacity: 0; + } + + to { + opacity: 1; + } + } + + /* ========================================================= + Wider screens + ========================================================= */ + + @media (min-width: 48rem) { + .sheet { + inset-block-end: + var(--space-4); + + width: + min( + calc( + 100% - + (var(--space-6) * 2) + ), + 42rem + ); + + border-block-end: + var(--border-width-thin) + solid + var(--color-border-subtle); + + border-radius: + var(--radius-xl); + } + } + + /* ========================================================= + Narrow screens + ========================================================= */ + + @media (max-width: 30rem) { + .sheet__header { + padding-inline: + var(--space-4); + } + + .sheet__body { + padding-inline: + var(--space-4); + } + + .sheet__footer { + padding-inline: + var(--space-4); + } + } + + /* ========================================================= + Reduced motion + ========================================================= */ + + @media ( + prefers-reduced-motion: + reduce + ) { + .sheet[open], + .sheet::backdrop { + animation: none; + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Sheet/Sheet.tsx b/apps/web/src/components/ui/Sheet/Sheet.tsx new file mode 100644 index 0000000..1e0aeb4 --- /dev/null +++ b/apps/web/src/components/ui/Sheet/Sheet.tsx @@ -0,0 +1,85 @@ +import type { ReactNode } from 'react'; + +import { CloseIcon } from '../../../icons/actions'; +import IconButton from '../IconButton/IconButton'; +import { useDialogControl } from '../internal/useDialogControl'; +import './Sheet.css'; + +export type SheetProps = { + open: boolean; + title: ReactNode; + description?: ReactNode; + children: ReactNode; + footer?: ReactNode; + showHandle?: boolean; + showCloseButton?: boolean; + closeLabel?: string; + closeOnBackdrop?: boolean; + onClose: () => void; +}; + +function Sheet({ + open, + title, + description, + children, + footer, + showHandle = true, + showCloseButton = true, + closeLabel = 'Close sheet', + closeOnBackdrop = true, + onClose, +}: SheetProps) { + const { dialogRef, titleId, descriptionId, handleCancel } = useDialogControl({ + open, + onClose, + closeOnBackdrop, + hasDescription: Boolean(description), + }); + + return ( + + {showHandle && ( + + )} + +
+
+

+ {title} +

+ + {description && ( +

+ {description} +

+ )} +
+ + {showCloseButton && ( + + )} +
+ +
{children}
+ + {footer &&
{footer}
} +
+ ); +} + +export default Sheet; \ No newline at end of file diff --git a/apps/web/src/components/ui/internal/useDialogControl.ts b/apps/web/src/components/ui/internal/useDialogControl.ts new file mode 100644 index 0000000..df71988 --- /dev/null +++ b/apps/web/src/components/ui/internal/useDialogControl.ts @@ -0,0 +1,91 @@ +import { + useEffect, + useId, + useRef, + type SyntheticEvent, +} from 'react'; + +type UseDialogControlOptions = { + open: boolean; + onClose: () => void; + closeOnBackdrop?: boolean; + hasDescription?: boolean; +}; + +/** Shared native lifecycle, IDs, backdrop handling, and focus restoration. */ +export function useDialogControl({ + open, + onClose, + closeOnBackdrop = true, + hasDescription = false, +}: UseDialogControlOptions) { + const dialogRef = useRef(null); + const previousFocusRef = useRef(null); + + const generatedId = useId(); + const titleId = `${generatedId}-title`; + const descriptionId = hasDescription + ? `${generatedId}-description` + : undefined; + + useEffect(() => { + const dialog = dialogRef.current; + + if (!dialog) { + return; + } + + if (open && !dialog.open) { + const active = document.activeElement; + + previousFocusRef.current = + active instanceof HTMLElement ? active : null; + + dialog.showModal(); + return; + } + + if (!open && dialog.open) { + dialog.close(); + + const previous = previousFocusRef.current; + previousFocusRef.current = null; + + window.requestAnimationFrame(() => { + previous?.focus(); + }); + } + }, [open]); + + useEffect(() => { + const dialog = dialogRef.current; + + if (!dialog || !closeOnBackdrop) { + return; + } + + const handleBackdropMouseDown = (event: MouseEvent) => { + if (event.target === dialog) { + onClose(); + } + }; + + dialog.addEventListener('mousedown', handleBackdropMouseDown); + + return () => { + dialog.removeEventListener('mousedown', handleBackdropMouseDown); + }; + }, [closeOnBackdrop, onClose]); + + const handleCancel = (event: SyntheticEvent) => { + event.preventDefault(); + onClose(); + }; + + return { + dialogRef, + titleId, + descriptionId, + handleCancel, + }; +} \ No newline at end of file From 96fd354efb7958d87b775c7b232e7e5b5791b2d1 Mon Sep 17 00:00:00 2001 From: olestang Date: Thu, 1 Oct 2026 10:22:51 +0200 Subject: [PATCH 3/5] test: add feedback and overlay component verification --- .../ui/__tests__/ConfirmationDialog.test.tsx | 52 +++ .../components/ui/__tests__/Dialog.test.tsx | 115 +++++++ .../components/ui/__tests__/Sheet.test.tsx | 59 ++++ .../showcase/ConfirmationDialogShowcase.tsx | 152 +++++++++ .../components/ui/showcase/DialogShowcase.tsx | 153 +++++++++ .../ui/showcase/EmptyStateShowcase.tsx | 116 +++++++ .../ui/showcase/FeedbackMessageShowcase.tsx | 128 +++++++ .../components/ui/showcase/SheetShowcase.tsx | 312 ++++++++++++++++++ .../components/ui/showcase/ToastShowcase.tsx | 173 ++++++++++ .../ui/showcase/UiShowcaseCatalog.tsx | 62 ++-- 10 files changed, 1300 insertions(+), 22 deletions(-) create mode 100644 apps/web/src/components/ui/__tests__/ConfirmationDialog.test.tsx create mode 100644 apps/web/src/components/ui/__tests__/Dialog.test.tsx create mode 100644 apps/web/src/components/ui/__tests__/Sheet.test.tsx create mode 100644 apps/web/src/components/ui/showcase/ConfirmationDialogShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/DialogShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/EmptyStateShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/FeedbackMessageShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/SheetShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/ToastShowcase.tsx diff --git a/apps/web/src/components/ui/__tests__/ConfirmationDialog.test.tsx b/apps/web/src/components/ui/__tests__/ConfirmationDialog.test.tsx new file mode 100644 index 0000000..6a19c8e --- /dev/null +++ b/apps/web/src/components/ui/__tests__/ConfirmationDialog.test.tsx @@ -0,0 +1,52 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it, vi } from "vitest"; + +import ConfirmationDialog from "../ConfirmationDialog/ConfirmationDialog"; + +describe("ConfirmationDialog", () => { + it("calls onConfirm from the confirm action", async () => { + const user = userEvent.setup(); + const onConfirm = vi.fn(); + + render( + undefined} + tone="error" + > + This action cannot be undone. + , + ); + + await user.click( + screen.getByRole("button", { name: "Delete" }), + ); + + expect(onConfirm).toHaveBeenCalledTimes(1); + }); + + it("calls onCancel from the cancel action", async () => { + const user = userEvent.setup(); + const onCancel = vi.fn(); + + render( + undefined} + onCancel={onCancel} + tone="error" + />, + ); + + await user.click( + screen.getByRole("button", { name: "Cancel" }), + ); + + expect(onCancel).toHaveBeenCalledTimes(1); + }); +}); diff --git a/apps/web/src/components/ui/__tests__/Dialog.test.tsx b/apps/web/src/components/ui/__tests__/Dialog.test.tsx new file mode 100644 index 0000000..cba9ca3 --- /dev/null +++ b/apps/web/src/components/ui/__tests__/Dialog.test.tsx @@ -0,0 +1,115 @@ +import { useState } from "react"; +import { + fireEvent, + render, + screen, +} from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it, vi } from "vitest"; + +import Dialog from "../Dialog/Dialog"; + +describe("Dialog", () => { + it("has an accessible title and description and closes from its close button", async () => { + const user = userEvent.setup(); + const onClose = vi.fn(); + + render( + + Dialog body + , + ); + + const dialog = screen.getByRole("dialog", { + name: "Recipe information", + }); + const description = screen.getByText( + "Details about this recipe", + ); + + expect(dialog.hasAttribute("open")).toBe(true); + expect(dialog.getAttribute("aria-describedby")).toBe( + description.id, + ); + + await user.click( + screen.getByRole("button", { name: "Close dialog" }), + ); + + expect(onClose).toHaveBeenCalledTimes(1); + }); + + it("requests close from the native cancel event used by Escape", () => { + const onClose = vi.fn(); + + render( + + Dialog body + , + ); + + const dialog = screen.getByRole("dialog"); + + fireEvent( + dialog, + new Event("cancel", { + bubbles: false, + cancelable: true, + }), + ); + + expect(onClose).toHaveBeenCalledTimes(1); + }); + + it("restores focus to the trigger after the dialog closes", async () => { + const user = userEvent.setup(); + + function DialogHarness() { + const [open, setOpen] = useState(false); + + return ( + <> + + + setOpen(false)} + > + Dialog body + + + ); + } + + render(); + + const trigger = screen.getByRole("button", { + name: "Open details", + }); + + await user.click(trigger); + await user.click( + screen.getByRole("button", { name: "Close dialog" }), + ); + await new Promise((resolve) => + requestAnimationFrame(() => resolve(undefined)), + ); + + expect(document.activeElement).toBe(trigger); + }); +}); diff --git a/apps/web/src/components/ui/__tests__/Sheet.test.tsx b/apps/web/src/components/ui/__tests__/Sheet.test.tsx new file mode 100644 index 0000000..6604901 --- /dev/null +++ b/apps/web/src/components/ui/__tests__/Sheet.test.tsx @@ -0,0 +1,59 @@ +import { useState } from "react"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it } from "vitest"; + +import Sheet from "../Sheet/Sheet"; + +describe("Sheet", () => { + it("opens with an accessible title and restores focus after closing", async () => { + const user = userEvent.setup(); + + function SheetHarness() { + const [open, setOpen] = useState(false); + + return ( + <> + + + setOpen(false)} + > + Filter controls + + + ); + } + + render(); + + const trigger = screen.getByRole("button", { + name: "Open filters", + }); + + await user.click(trigger); + + const sheet = screen.getByRole("dialog", { + name: "Recipe filters", + }); + + expect(sheet.hasAttribute("open")).toBe(true); + + await user.click( + screen.getByRole("button", { name: "Close sheet" }), + ); + await new Promise((resolve) => + requestAnimationFrame(() => resolve(undefined)), + ); + + expect(document.activeElement).toBe(trigger); + }); +}); diff --git a/apps/web/src/components/ui/showcase/ConfirmationDialogShowcase.tsx b/apps/web/src/components/ui/showcase/ConfirmationDialogShowcase.tsx new file mode 100644 index 0000000..7dc4c54 --- /dev/null +++ b/apps/web/src/components/ui/showcase/ConfirmationDialogShowcase.tsx @@ -0,0 +1,152 @@ +import { useState } from "react"; + +import Button from "../Button/Button"; +import ConfirmationDialog from "../ConfirmationDialog/ConfirmationDialog"; +import FeedbackMessage from "../FeedbackMessage/FeedbackMessage"; +import { surfaceStyle } from "./showcaseStyles"; + + +type OpenDialog = + | "publish" + | "warning" + | "delete" + | null; + +export default function ConfirmationDialogShowcase() { + const [openDialog, setOpenDialog] = + useState(null); + + const [message, setMessage] = + useState(null); + + return ( +
+
+
+

+ ConfirmationDialog Showcase +

+ +

+ Confirmation dialogs for important, + cautionary, and destructive actions. +

+
+ +
+

Examples

+ +
+
+ + + + + +
+ + {message && ( + + {message} + + )} +
+
+ + + setOpenDialog(null) + } + onConfirm={() => { + setOpenDialog(null); + setMessage( + "Recipe published successfully.", + ); + }} + > + You can still edit the recipe after + it has been published. + + + + setOpenDialog(null) + } + onConfirm={() => { + setOpenDialog(null); + setMessage( + "Draft replaced successfully.", + ); + }} + > + Any unsaved content in the current draft + will be lost. + + + + setOpenDialog(null) + } + onConfirm={() => { + setOpenDialog(null); + setMessage( + "Recipe deleted successfully.", + ); + }} + > + This action cannot be undone. + +
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/DialogShowcase.tsx b/apps/web/src/components/ui/showcase/DialogShowcase.tsx new file mode 100644 index 0000000..2d0df14 --- /dev/null +++ b/apps/web/src/components/ui/showcase/DialogShowcase.tsx @@ -0,0 +1,153 @@ +import { useState } from "react"; + +import Button from "../Button/Button"; +import Dialog, { + type DialogTone, +} from "../Dialog/Dialog"; +import { ChefIcon } from "../../../icons/recipe"; +import { AlertTriangleIcon, ErrorIcon, InfoIcon, SuccessIcon } from "../../../icons/status"; +import { surfaceStyle } from "./showcaseStyles"; + + + + + + + + +const examples: { + tone: DialogTone; + label: string; +}[] = [ + { + tone: "primary", + label: "Primary", + }, + { + tone: "brand", + label: "Brand", + }, + { + tone: "info", + label: "Info", + }, + { + tone: "warning", + label: "Warning", + }, + { + tone: "success", + label: "Success", + }, + { + tone: "error", + label: "Error", + }, +]; + +function iconForTone( + tone: DialogTone, +) { + switch (tone) { + case "primary": + case "brand": + return ChefIcon; + case "info": + return InfoIcon; + case "warning": + return AlertTriangleIcon; + case "success": + return SuccessIcon; + case "error": + return ErrorIcon; + } +} + +export default function DialogShowcase() { + const [openTone, setOpenTone] = + useState(null); + + return ( +
+
+
+

Dialog Showcase

+ +

+ Basic dialogs with different semantic visual tones. +

+
+ +
+

Tones

+ +

+ The buttons preview the visual tone used by each dialog. +

+ +
+ {examples.map((example) => ( + + ))} +
+
+ + {examples.map((example) => ( + + setOpenTone(null) + } + footer={ + + } + > +
+

+ This dialog keeps the main surface neutral while + using its icon treatment to communicate visual + emphasis. +

+ +

+ That keeps the dialog readable without turning the + entire modal into a large colored surface. +

+
+
+ ))} +
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/EmptyStateShowcase.tsx b/apps/web/src/components/ui/showcase/EmptyStateShowcase.tsx new file mode 100644 index 0000000..0a3f569 --- /dev/null +++ b/apps/web/src/components/ui/showcase/EmptyStateShowcase.tsx @@ -0,0 +1,116 @@ +import Button from "../Button/Button"; +import EmptyState from "../EmptyState/EmptyState"; +import { HeartIcon } from "../../../icons/actions"; +import { CookbookIcon, SearchIcon } from "../../../icons/navigation"; +import { surfaceStyle } from "./showcaseStyles"; + + + + + +export default function EmptyStateShowcase() { + return ( +
+
+
+

EmptyState Showcase

+ +

+ Friendly empty and no-results + states with optional actions. +

+
+ +
+

Cookbook

+ + + Explore Recipes + + } + /> +
+ +
+

No Search Results

+ + + + + + + } + /> +
+ +
+

Plain Variant

+ +
+ + Find Recipes + + } + /> +
+
+ +
+

Compact

+ +
+ + Clear Filter + + } + /> +
+
+ +
+

Without Action

+ + +
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/FeedbackMessageShowcase.tsx b/apps/web/src/components/ui/showcase/FeedbackMessageShowcase.tsx new file mode 100644 index 0000000..d4a720b --- /dev/null +++ b/apps/web/src/components/ui/showcase/FeedbackMessageShowcase.tsx @@ -0,0 +1,128 @@ +import FeedbackMessage from "../FeedbackMessage/FeedbackMessage"; +import { surfaceStyle } from "./showcaseStyles"; + + +export default function FeedbackMessageShowcase() { + return ( +
+
+
+

FeedbackMessage Showcase

+ +

+ Inline feedback for success, error, warning, and informational + states. +

+
+ +
+

All Tones

+ +
+ + Spaghetti Carbonara was added to your cookbook. + + + + Check the required fields and try again. + + + + Leaving this page will discard your current changes. + + + + Public recipes can be discovered by other users. + +
+
+ +
+

Without Titles

+ +
+ + Your changes were saved successfully. + + + + Enter a valid email address. + + + + This recipe has not been published yet. + + + + Cooking times are approximate. + +
+
+ +
+

Form Context

+ +
+

Create Account

+ + + Correct the highlighted fields before trying again. + +
+
+ +
+

Narrow Layout

+ +
+ + Preparation and resting time may not be included. + +
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/SheetShowcase.tsx b/apps/web/src/components/ui/showcase/SheetShowcase.tsx new file mode 100644 index 0000000..1bb9f7a --- /dev/null +++ b/apps/web/src/components/ui/showcase/SheetShowcase.tsx @@ -0,0 +1,312 @@ +import { useEffect, useMemo, useRef, useState } from 'react'; + +import { CameraIcon, DeleteIcon, ImageIcon } from '../../../icons/actions'; +import Button from '../Button/Button'; +import FeedbackMessage from '../FeedbackMessage/FeedbackMessage'; +import Menu, { type MenuEntry } from '../Menu/Menu'; +import Sheet from '../Sheet/Sheet'; +import { surfaceStyle } from './showcaseStyles'; + +const searchStyle = { + width: '100%', + minHeight: 'var(--control-height-md)', + + paddingInline: 'var(--space-3)', + + color: 'var(--color-text-primary)', + + backgroundColor: 'var(--color-surface)', + + font: 'inherit', + + border: + 'var(--border-width-thin) solid var(--color-border-input)', + + borderRadius: 'var(--radius-md)', +}; + +const categoryRowStyle = { + display: 'flex', + alignItems: 'center', + justifyContent: 'space-between', + gap: 'var(--space-3)', + + minHeight: 'var(--target-size-min)', + + padding: 'var(--space-2) var(--space-3)', + + borderRadius: 'var(--radius-md)', + + cursor: 'pointer', +}; + +const categories = [ + 'Breakfast', + 'Lunch', + 'Dinner', + 'Appetizer', + 'Dessert', + 'Side Dish', + 'Snack', + 'Soup', + 'Salad', +]; + +export default function SheetShowcase() { + const [categoryOpen, setCategoryOpen] = useState(false); + + const [photoOpen, setPhotoOpen] = useState(false); + + const [selectedCategory, setSelectedCategory] = useState('Dinner'); + + const [search, setSearch] = useState(''); + + const [message, setMessage] = useState(null); + + const searchInputRef = useRef(null); + + useEffect(() => { + if (!categoryOpen) { + return; + } + + const frame = window.requestAnimationFrame(() => { + searchInputRef.current?.focus(); + }); + + return () => { + window.cancelAnimationFrame(frame); + }; + }, [categoryOpen]); + + const filteredCategories = useMemo(() => { + const query = search.trim().toLowerCase(); + + if (!query) { + return categories; + } + + return categories.filter((category) => + category.toLowerCase().includes(query), + ); + }, [search]); + + const photoActions: MenuEntry[] = [ + { + id: 'camera', + label: 'Take Photo', + icon: CameraIcon, + onSelect: () => { + setPhotoOpen(false); + + setMessage('Take Photo selected.'); + }, + }, + { + id: 'library', + label: 'Choose from Library', + icon: ImageIcon, + onSelect: () => { + setPhotoOpen(false); + + setMessage('Choose from Library selected.'); + }, + }, + { + id: 'separator', + type: 'separator', + }, + { + id: 'remove', + label: 'Remove Current Photo', + icon: DeleteIcon, + tone: 'destructive', + onSelect: () => { + setPhotoOpen(false); + + setMessage('Remove Current Photo selected.'); + }, + }, + ]; + + return ( +
+
+
+

Sheet Showcase

+ +

+ Bottom sheets for focused mobile actions and selections. +

+
+ +
+

Recipe Form Examples

+ +
+
+ + + +
+ +

+ Selected category: {selectedCategory} +

+ + {message && ( + {message} + )} +
+
+ + {/* Category Sheet */} + + setCategoryOpen(false)} + footer={ + <> + + + + + } + > +
+ setSearch(event.target.value)} + /> + +
+ Recipe category + +
+ {filteredCategories.map((category) => { + const selected = category === selectedCategory; + + return ( + + ); + })} + + {filteredCategories.length === 0 && ( +

+ No categories match your search. +

+ )} +
+
+
+
+ + {/* Photo Sheet */} + + setPhotoOpen(false)} + footer={ + + } + > + + + +
+

Behavior

+ +
+

+ The sheet can be closed using its close button, the Escape + key, the backdrop, or an explicit action. +

+ +

+ The body scrolls independently when its content becomes taller + than the available viewport. +

+
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/ToastShowcase.tsx b/apps/web/src/components/ui/showcase/ToastShowcase.tsx new file mode 100644 index 0000000..5a850ed --- /dev/null +++ b/apps/web/src/components/ui/showcase/ToastShowcase.tsx @@ -0,0 +1,173 @@ +import { + useCallback, + useState, +} from "react"; + +import Button from "../Button/Button"; +import Toast, { + type ToastTone, +} from "../Toast/Toast"; +import { surfaceStyle } from "./showcaseStyles"; + + +type OpenToast = + | ToastTone + | null; + +export default function ToastShowcase() { + const [openToast, setOpenToast] = + useState(null); + + const closeToast = + useCallback(() => { + setOpenToast(null); + }, []); + + return ( +
+
+
+

Toast Showcase

+ +

+ Temporary feedback for actions that + do not require the user to stop what + they are doing. +

+
+ +
+

Examples

+ +
+ + + + + + + +
+
+ +
+

Preview

+ +
+ {openToast === null && ( +

+ Open a toast above to preview it. +

+ )} + + + Spaghetti Carbonara was saved to + your cookbook. + + + + Your latest changes are now visible. + + + + Your changes are saved, but the + recipe is still private. + + + + Try saving the recipe again. + +
+
+ +
+

Persistent

+ +
+ {}} + > + Setting duration to null prevents + automatic dismissal. + +
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx b/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx index e36e15c..c46aa95 100644 --- a/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx +++ b/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx @@ -1,28 +1,36 @@ -import AvatarShowcase from './AvatarShowcase'; -import BreadcrumbsShowcase from './BreadcrumbsShowcase'; -import ButtonShowcase from './ButtonShowcase'; -import CheckboxShowcase from './CheckboxShowcase'; -import DropdownMenuShowcase from './DropdownMenuShowcase'; -import FieldShowcase from './FieldShowcase'; -import FilterChipShowcase from './FilterChipShowcase'; -import IconBadgeShowcase from './IconBadgeShowcase'; -import IconButtonShowcase from './IconButtonShowcase'; -import IconShowcase from './IconShowcase'; -import LoadingIndicatorShowcase from './LoadingIndicatorShowcase'; -import PaginationShowcase from './PaginationShowcase'; -import RadioShowcase from './RadioShowcase'; -import SelectShowcase from './SelectShowcase'; -import TabsShowcase from './TabsShowcase'; -import TagShowcase from './TagShowcase'; -import TextareaShowcase from './TextareaShowcase'; -import ToggleSwitchShowcase from './ToggleSwitchShowcase'; -import TooltipShowcase from './TooltipShowcase'; - -// Intentionally render every available showcase in one scrollable catalog. +import AvatarShowcase from "./AvatarShowcase"; +import BreadcrumbsShowcase from "./BreadcrumbsShowcase"; +import ButtonShowcase from "./ButtonShowcase"; +import CheckboxShowcase from "./CheckboxShowcase"; +import ConfirmationDialogShowcase from "./ConfirmationDialogShowcase"; +import DialogShowcase from "./DialogShowcase"; +import DropdownMenuShowcase from "./DropdownMenuShowcase"; +import EmptyStateShowcase from "./EmptyStateShowcase"; +import FeedbackMessageShowcase from "./FeedbackMessageShowcase"; +import FieldShowcase from "./FieldShowcase"; +import FilterChipShowcase from "./FilterChipShowcase"; +import IconBadgeShowcase from "./IconBadgeShowcase"; +import IconButtonShowcase from "./IconButtonShowcase"; +import IconShowcase from "./IconShowcase"; +import LoadingIndicatorShowcase from "./LoadingIndicatorShowcase"; +import PaginationShowcase from "./PaginationShowcase"; +import RadioShowcase from "./RadioShowcase"; +import SelectShowcase from "./SelectShowcase"; +import SheetShowcase from "./SheetShowcase"; +import TabsShowcase from "./TabsShowcase"; +import TagShowcase from "./TagShowcase"; +import TextareaShowcase from "./TextareaShowcase"; +import ToastShowcase from "./ToastShowcase"; +import ToggleSwitchShowcase from "./ToggleSwitchShowcase"; +import TooltipShowcase from "./TooltipShowcase"; + +// Intentionally render every showcase in one scrollable catalog. // This page doubles as a quick visual/responsive review surface. export default function UiShowcaseCatalog() { return (
+ + @@ -31,16 +39,26 @@ export default function UiShowcaseCatalog() { + + + + + + + + + + @@ -62,4 +80,4 @@ export default function UiShowcaseCatalog() {
); -} +} \ No newline at end of file From 012b9e7f5e92cc2fda4a945032646275a217f5a9 Mon Sep 17 00:00:00 2001 From: olestang Date: Thu, 1 Oct 2026 10:25:34 +0200 Subject: [PATCH 4/5] docs: document shared UI component library --- apps/web/src/components/ui/README.md | 835 +++++++++++++++++++++++++++ apps/web/src/components/ui/SKILL.md | 380 ++++++++++++ 2 files changed, 1215 insertions(+) create mode 100644 apps/web/src/components/ui/README.md create mode 100644 apps/web/src/components/ui/SKILL.md diff --git a/apps/web/src/components/ui/README.md b/apps/web/src/components/ui/README.md new file mode 100644 index 0000000..7bb0c83 --- /dev/null +++ b/apps/web/src/components/ui/README.md @@ -0,0 +1,835 @@ +# UI Component Library + +This folder contains the shared UI primitives used by the recipe application. The goal is to keep page and feature code focused on product behavior while common interaction, accessibility, spacing, color, and state patterns stay consistent. + +The component library is intentionally small and project-specific. Add a new generic component only when real application code needs a reusable pattern; do not grow this folder just to mirror a large external design system. + +## Visual review + +The app currently renders `showcase/UiShowcaseCatalog.tsx`, which displays the component showcases as one long scrollable page. Use it as the primary visual and responsive review surface. + +Run: + +```bash +npm run dev +``` + +Then scroll through the catalog and resize the browser. The showcase is intentionally kept as one page so it is quick to compare components, inspect states, and notice responsive regressions. + +Storybook is not currently necessary. The showcase already covers the project's main visual-review need with less setup and maintenance. + +## Related styling documentation + +The global CSS system is documented in: + +```text +src/styles/style_guide/SKILL.md +``` + +That guide is the source of truth for cascade layers, design tokens, base styles, utilities, control sizing, spacing, motion, and z-index conventions. + +## Import convention + +This project does **not** use `index.ts` barrel files for UI components. Import the component from its actual file. + +From `src/App.tsx`, for example: + +```tsx +import Button from "./components/ui/Button/Button"; +import IconButton from "./components/ui/IconButton/IconButton"; +import { Icon } from "./components/ui/Icon/Icon"; +``` + +Use the same explicit style for icons: + +```tsx +import { SearchIcon } from "./icons/navigation"; +``` + +Adjust the relative path for the calling file. + +## Folder responsibilities + +```text +components/ui/ + Button/ + Dialog/ + Field/ + ... + internal/ + showcase/ + __tests__/ +``` + +- Component folders contain the public UI component and its component CSS. +- `internal/` contains shared implementation details used by UI components. Application code should normally not import from it. +- `showcase/` contains visual examples and responsive review cases. Showcase helpers are not production UI primitives. +- `__tests__/` contains a deliberately small number of interaction-focused tests. + +## General component conventions + +### Styling + +- Use existing design tokens when an appropriate token exists. +- Keep component appearance in the component's CSS file. +- Wrap component CSS in `@layer components`. +- Use utilities for composition and small layout overrides, not as a replacement for component CSS. +- Add a global token only when the value represents a reusable design-system decision. +- Prefer semantic token names over raw colors. +- Preserve the existing warm cream/orange visual direction unless a product requirement calls for a change. + +### Native semantics first + +Prefer native HTML behavior before recreating it with generic elements: + +- `