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..5abb626 --- /dev/null +++ b/apps/web/src/components/ui/ConfirmationDialog/ConfirmationDialog.css @@ -0,0 +1,64 @@ +@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; + } + } +} 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..9fdb331 --- /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; 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..5313455 --- /dev/null +++ b/apps/web/src/components/ui/Dialog/Dialog.css @@ -0,0 +1,169 @@ +@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); + } + } +} 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..9e04c59 --- /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; 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..74ae36c --- /dev/null +++ b/apps/web/src/components/ui/EmptyState/EmptyState.css @@ -0,0 +1,93 @@ +@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); + } + } +} 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..61e7919 --- /dev/null +++ b/apps/web/src/components/ui/EmptyState/EmptyState.tsx @@ -0,0 +1,62 @@ +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..ae8f2f3 --- /dev/null +++ b/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.css @@ -0,0 +1,80 @@ +@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); + } +} 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..88f5f6e --- /dev/null +++ b/apps/web/src/components/ui/FeedbackMessage/FeedbackMessage.tsx @@ -0,0 +1,49 @@ +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/README.md b/apps/web/src/components/ui/README.md new file mode 100644 index 0000000..2ed7c71 --- /dev/null +++ b/apps/web/src/components/ui/README.md @@ -0,0 +1,788 @@ +# 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: + +- `