diff --git a/apps/web/src/components/ui/Icon/Icon.css b/apps/web/src/components/ui/Icon/Icon.css new file mode 100644 index 0000000..f46e06d --- /dev/null +++ b/apps/web/src/components/ui/Icon/Icon.css @@ -0,0 +1,74 @@ +@layer components { + .ui-icon { + color: inherit; + stroke-width: var(--icon-stroke-default); + + display: inline-block; + flex: none; + vertical-align: middle; + + /* + * Icon itself is presentation-only. Interactive parents such as + * Button, IconButton, links, and cards own hover/active states. + */ + transition: + color var(--duration-fast) var(--ease-standard), + stroke-width var(--duration-fast) var(--ease-standard); + } + + /* Color tones */ + + .ui-icon--inherit { + color: inherit; + } + + .ui-icon--default { + color: var(--color-icon-primary); + } + + .ui-icon--secondary { + color: var(--color-icon-secondary); + } + + .ui-icon--muted { + color: var(--color-icon-muted); + } + + .ui-icon--brand { + color: var(--color-brand-primary); + } + + .ui-icon--success { + color: var(--color-feedback-success); + } + + .ui-icon--warning { + color: var(--color-feedback-warning); + } + + .ui-icon--error { + color: var(--color-feedback-error); + } + + .ui-icon--info { + color: var(--color-feedback-info); + } + + .ui-icon--inverse { + color: var(--color-text-inverse); + } + + /* Stroke weights */ + + .ui-icon--stroke-thin { + stroke-width: var(--icon-stroke-thin); + } + + .ui-icon--stroke-default { + stroke-width: var(--icon-stroke-default); + } + + .ui-icon--stroke-strong { + stroke-width: var(--icon-stroke-strong); + } +} diff --git a/apps/web/src/components/ui/Icon/Icon.tsx b/apps/web/src/components/ui/Icon/Icon.tsx new file mode 100644 index 0000000..a59e73e --- /dev/null +++ b/apps/web/src/components/ui/Icon/Icon.tsx @@ -0,0 +1,151 @@ +import type { ComponentType, CSSProperties } from 'react'; + +import type { IconProps as SvgIconProps } from '../../../icons/types'; + +import './Icon.css'; + +export type IconTone = + | 'inherit' + | 'default' + | 'secondary' + | 'muted' + | 'brand' + | 'success' + | 'warning' + | 'error' + | 'info' + | 'inverse'; + +export type IconStroke = 'thin' | 'default' | 'strong'; + +export type UiIconSize = 'sm' | 'md' | 'lg' | 'xl' | SvgIconProps['size']; + +type IconSpecificProps

= Omit; + +export interface IconProps

+ extends Omit { + /** + * Raw SVG icon component to render. + */ + icon: ComponentType

; + + /** + * Design-system size or an explicit CSS/SVG size. + */ + size?: UiIconSize; + + /** + * Semantic icon color. + * + * "inherit" is the default so interactive parents such as + * Button, IconButton, and links can control hover/active color. + */ + tone?: IconTone; + + /** + * Explicit CSS color override. + * + * Prefer tone for normal design-system usage. + */ + color?: string; + + /** + * Design-system stroke weight. + */ + stroke?: IconStroke; + + /** + * Escape hatch for an explicit numeric SVG stroke width. + * + * Prefer stroke="thin" | "default" | "strong" normally. + */ + strokeWidth?: number; + + /** + * Props specific to the chosen raw icon. + * + * Examples: + * { filled: true } + * { variant: "half" } + */ + iconProps?: IconSpecificProps

; +} + +const SIZE_TOKENS: Record<'sm' | 'md' | 'lg' | 'xl', string> = { + sm: 'var(--icon-size-sm)', + md: 'var(--icon-size-md)', + lg: 'var(--icon-size-lg)', + xl: 'var(--icon-size-xl)', +}; + +function resolveSize(size: UiIconSize | undefined): SvgIconProps['size'] { + if (size === undefined) { + return SIZE_TOKENS.md; + } + + if (typeof size === 'string' && size in SIZE_TOKENS) { + return SIZE_TOKENS[size as keyof typeof SIZE_TOKENS]; + } + + return size; +} + +/** + * Design-system wrapper around the raw SVG icons. + * + * Icon intentionally does not define hover/active states itself. + * It inherits color by default so the interactive parent owns + * those states. + * + * Examples: + * + * + * + * + * + * + */ +export function Icon

({ + icon: Component, + iconProps, + size = 'md', + tone = 'inherit', + color, + stroke = 'default', + strokeWidth, + className, + style, + ...svgProps +}: IconProps

) { + const classes = [ + 'ui-icon', + `ui-icon--${tone}`, + `ui-icon--stroke-${stroke}`, + className, + ] + .filter(Boolean) + .join(' '); + + const iconStyle: CSSProperties = { + ...style, + ...(strokeWidth !== undefined ? { strokeWidth } : {}), + }; + + return ( + )} + size={resolveSize(size)} + color={color} + className={classes} + style={iconStyle} + /> + ); +} diff --git a/apps/web/src/components/ui/showcase/IconShowcase.tsx b/apps/web/src/components/ui/showcase/IconShowcase.tsx new file mode 100644 index 0000000..29c3151 --- /dev/null +++ b/apps/web/src/components/ui/showcase/IconShowcase.tsx @@ -0,0 +1,812 @@ +import type { ComponentType, CSSProperties } from 'react'; + +import { Icon, type IconTone } from '../Icon/Icon'; + +import { + AddRecipeIcon, + BookmarkIcon, + CameraIcon, + CheckIcon, + CloseIcon, + DeleteIcon, + DragHandleIcon, + EditIcon, + FilterIcon, + HeartIcon, + ImageIcon, + PrintIcon, + SaveDraftIcon, + SettingsIcon, + ShareIcon, + SortIcon, + UploadPhotoIcon, +} from '../../../icons/actions'; +import { + BackIcon, + ChevronDownIcon, + ChevronLeftIcon, + ChevronRightIcon, + CookbookIcon, + HomeIcon, + LoginIcon, + MenuIcon, + MoreIcon, + ProfileIcon, + SearchIcon, +} from '../../../icons/navigation'; +import { StarIcon } from '../../../icons/rating'; +import { + CategoriesIcon, + ChefIcon, + CookingTimeIcon, + DietaryIcon, + DifficultyIcon, + EmptyStateIcon, + InstructionsIcon, + PrivateIcon, + PublicIcon, + RecentRecipesIcon, + ServingsIcon, + SoupIcon, +} from '../../../icons/recipe'; +import { + AlertIcon, + AlertTriangleIcon, + ErrorIcon, + InfoIcon, + SuccessIcon, +} from '../../../icons/status'; +import type { IconProps as RawIconProps } from '../../../icons/types'; +import { surfaceStyle, raisedSurfaceStyle } from './showcaseStyles'; + +type IconEntry = { + name: string; + Component: ComponentType; +}; + +const iconGridStyle: CSSProperties = { + display: 'grid', + + gridTemplateColumns: 'repeat(auto-fill, minmax(8rem, 1fr))', + + columnGap: 'var(--space-5)', + rowGap: 'var(--space-8)', + + alignItems: 'start', + + paddingBlock: 'var(--space-4)', +}; + +const iconGridItemStyle: CSSProperties = { + display: 'flex', + flexDirection: 'column', + + alignItems: 'center', + + gap: 'var(--space-3)', + + minWidth: 0, + + textAlign: 'center', +}; + +const iconNameStyle: CSSProperties = { + color: 'var(--color-text-secondary)', + + fontFamily: + 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace', + + fontSize: 'var(--font-size-xs)', + + lineHeight: 'var(--line-height-snug)', + + overflowWrap: 'anywhere', +}; + +const allIcons: IconEntry[] = [ + { + name: 'HomeIcon', + Component: HomeIcon, + }, + { + name: 'CookbookIcon', + Component: CookbookIcon, + }, + { + name: 'BookmarkIcon', + Component: BookmarkIcon, + }, + { + name: 'AddRecipeIcon', + Component: AddRecipeIcon, + }, + { + name: 'ProfileIcon', + Component: ProfileIcon, + }, + { + name: 'SearchIcon', + Component: SearchIcon, + }, + { + name: 'HeartIcon', + Component: HeartIcon, + }, + { + name: 'StarIcon', + Component: StarIcon, + }, + + { + name: 'CookingTimeIcon', + Component: CookingTimeIcon, + }, + { + name: 'ServingsIcon', + Component: ServingsIcon, + }, + { + name: 'CategoriesIcon', + Component: CategoriesIcon, + }, + { + name: 'FilterIcon', + Component: FilterIcon, + }, + { + name: 'SortIcon', + Component: SortIcon, + }, + { + name: 'SettingsIcon', + Component: SettingsIcon, + }, + { + name: 'UploadPhotoIcon', + Component: UploadPhotoIcon, + }, + { name: 'CameraIcon', Component: CameraIcon }, + { name: 'ImageIcon', Component: ImageIcon }, + { + name: 'DeleteIcon', + Component: DeleteIcon, + }, + + { + name: 'EditIcon', + Component: EditIcon, + }, + { + name: 'ShareIcon', + Component: ShareIcon, + }, + { + name: 'PrintIcon', + Component: PrintIcon, + }, + { + name: 'PublicIcon', + Component: PublicIcon, + }, + { + name: 'PrivateIcon', + Component: PrivateIcon, + }, + { + name: 'CheckIcon', + Component: CheckIcon, + }, + { + name: 'ChevronDownIcon', + Component: ChevronDownIcon, + }, + { + name: 'ChevronLeftIcon', + Component: ChevronLeftIcon, + }, + { + name: 'ChevronRightIcon', + Component: ChevronRightIcon, + }, + { + name: 'CloseIcon', + Component: CloseIcon, + }, + + { + name: 'BackIcon', + Component: BackIcon, + }, + { + name: 'InfoIcon', + Component: InfoIcon, + }, + { + name: 'SuccessIcon', + Component: SuccessIcon, + }, + { + name: 'ErrorIcon', + Component: ErrorIcon, + }, + { + name: 'AlertIcon', + Component: AlertIcon, + }, + { + name: 'EmptyStateIcon', + Component: EmptyStateIcon, + }, + { + name: 'DietaryIcon', + Component: DietaryIcon, + }, + { name: 'DifficultyIcon', Component: DifficultyIcon }, + { + name: 'ChefIcon', + Component: ChefIcon, + }, + { + name: 'SoupIcon', + Component: SoupIcon, + }, + + { + name: 'LoginIcon', + Component: LoginIcon, + }, + { name: 'MenuIcon', Component: MenuIcon }, + { name: 'MoreIcon', Component: MoreIcon }, + { + name: 'InstructionsIcon', + Component: InstructionsIcon, + }, + { + name: 'SaveDraftIcon', + Component: SaveDraftIcon, + }, + { + name: 'AlertTriangleIcon', + Component: AlertTriangleIcon, + }, + { + name: 'RecentRecipesIcon', + Component: RecentRecipesIcon, + }, + { + name: 'DragHandleIcon', + Component: DragHandleIcon, + }, +]; + +const toneExamples: Array<{ + tone: Exclude; + label: string; +}> = [ + { + tone: 'default', + label: 'Default', + }, + { + tone: 'secondary', + label: 'Secondary', + }, + { + tone: 'muted', + label: 'Muted', + }, + { + tone: 'brand', + label: 'Brand', + }, + { + tone: 'success', + label: 'Success', + }, + { + tone: 'warning', + label: 'Warning', + }, + { + tone: 'error', + label: 'Error', + }, + { + tone: 'info', + label: 'Info', + }, +]; + +export default function IconShowcase() { + return ( +

+
+
+

Icon Showcase

+ +

+ Visual reference for the shared Icon component and the raw recipe + icon collection. +

+
+ + {/* All icons */} + +
+
+

All Icons

+ +

+ The name underneath each icon is its exported React component + name. +

+
+ +
+
+ {allIcons.map(({ name, Component }) => ( +
+ + + {name} +
+ ))} +
+
+
+ +
+ + {/* Sizes */} + +
+
+

Sizes

+ +

+ Named sizes map to the shared icon-size design tokens. +

+
+ +
+
+ + sm +
+ +
+ + md +
+ +
+ + lg +
+ +
+ + xl +
+ +
+ + 2.75rem +
+
+
+ + {/* Inheritance */} + +
+
+

Color Inheritance

+ +

+ Icon uses tone="inherit" by default. This lets an + interactive parent own hover, active, focus, selected, and + disabled colors. +

+
+ +
+
+ + Inherited text color +
+ +
+ + Inherited brand color +
+ +
+ + Inherited error color +
+
+ + + { + '' + } + +
+ + {/* Tones */} + +
+
+

Semantic Tones

+ +

+ Use an explicit tone when the icon has semantic meaning + independent of its parent. +

+
+ +
+ {toneExamples.map(({ tone, label }) => ( +
+ + + {label} +
+ ))} + +
+ + + + Inverse + +
+
+
+ + {/* Stroke */} + +
+
+

Stroke Weight

+ +

+ Named stroke weights use the icon stroke tokens from{' '} + tokens.css. +

+
+ +
+
+ + thin +
+ +
+ + default +
+ +
+ + strong +
+
+ + {''} +
+ + {/* Typical colors */} + +
+

Typical Semantic Usage

+ +
+
+ + Add recipe +
+ +
+ + Success +
+ +
+ + Warning +
+ +
+ + Destructive +
+ +
+ + Information +
+ +
+ + Dietary +
+
+
+ +
+ + {/* Stateful */} + +
+
+

Stateful Icons

+ +

+ Icon-specific state is passed through iconProps. +

+
+ +
+
+

BookmarkIcon

+ +
+
+ + + Unfilled +
+ +
+ + + Filled +
+
+ + + { + '' + } + +
+ +
+

HeartIcon

+ +
+
+ + + Unfilled +
+ +
+ + + Filled +
+
+
+ +
+

StarIcon

+ +
+
+ + + Empty +
+ +
+ + + Half +
+ +
+ + + Full +
+
+
+
+
+ + {/* Explicit overrides */} + +
+
+

Explicit Overrides

+ +

+ Available for exceptional cases. Semantic tones and named stroke + weights should normally be preferred. +

+
+ +
+
+ + + custom color +
+ +
+ + + strokeWidth=2.2 +
+
+
+ + {/* Recipe context */} + +
+

Recipe Context

+ +
+
+ + + 25 min +
+ +
+ + + 4 servings +
+ +
+ + + Vegetarian +
+ +
+ + + 4.8 rating +
+
+
+
+
+ ); +} diff --git a/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx b/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx new file mode 100644 index 0000000..1950bd0 --- /dev/null +++ b/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx @@ -0,0 +1,11 @@ +import IconShowcase from './IconShowcase'; + +// Intentionally render every showcase in one scrollable catalog. +// More showcases can be added back here as they are implemented. +export default function UiShowcaseCatalog() { + return ( +
+ +
+ ); +} diff --git a/apps/web/src/components/ui/showcase/showcaseStyles.ts b/apps/web/src/components/ui/showcase/showcaseStyles.ts new file mode 100644 index 0000000..78e30fc --- /dev/null +++ b/apps/web/src/components/ui/showcase/showcaseStyles.ts @@ -0,0 +1,16 @@ +import type { CSSProperties } from 'react'; + +export const surfaceStyle: CSSProperties = { + padding: 'var(--space-6)', + backgroundColor: 'var(--color-surface)', + border: 'var(--border-width-thin) solid var(--color-border-default)', + borderRadius: 'var(--radius-lg)', +}; + +export const raisedSurfaceStyle: CSSProperties = { + padding: 'var(--space-6)', + backgroundColor: 'var(--color-surface-raised)', + border: 'var(--border-width-thin) solid var(--color-border-subtle)', + borderRadius: 'var(--radius-lg)', + boxShadow: 'var(--shadow-sm)', +}; diff --git a/apps/web/src/icons/IconBase.tsx b/apps/web/src/icons/IconBase.tsx new file mode 100644 index 0000000..ff29bb2 --- /dev/null +++ b/apps/web/src/icons/IconBase.tsx @@ -0,0 +1,45 @@ +import type { ReactNode } from 'react'; +import type { IconProps } from './types'; + +export interface IconBaseProps extends IconProps { + children: ReactNode; + viewBox?: string; +} + +/** Internal base used by the raw SVG icon components. */ +export function IconBase({ + size = 'var(--icon-size-md)', + color, + title, + strokeWidth = 'var(--icon-stroke-default)', + children, + viewBox = '0 0 24 24', + style, + ...rest +}: IconBaseProps) { + const isLabelled = Boolean( + title || rest['aria-label'] || rest['aria-labelledby'], + ); + + return ( + + {title ? {title} : null} + {children} + + ); +} diff --git a/apps/web/src/icons/actions.tsx b/apps/web/src/icons/actions.tsx new file mode 100644 index 0000000..116fc13 --- /dev/null +++ b/apps/web/src/icons/actions.tsx @@ -0,0 +1,186 @@ +import { IconBase } from './IconBase'; +import type { IconProps } from './types'; + +export interface ToggleFillIconProps extends IconProps { + filled?: boolean; +} + +export function BookmarkIcon({ + filled = false, + ...props +}: ToggleFillIconProps) { + return ( + + + + ); +} + +export function AddRecipeIcon(props: IconProps) { + return ( + + + + + ); +} + +export function HeartIcon({ filled = false, ...props }: ToggleFillIconProps) { + return ( + + + + ); +} + +export function FilterIcon(props: IconProps) { + return ( + + + + ); +} + +export function SortIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function SettingsIcon(props: IconProps) { + return ( + + + + + ); +} + +export function UploadPhotoIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function DeleteIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function EditIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ShareIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function PrintIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function CheckIcon(props: IconProps) { + return ( + + + + ); +} + +export function CloseIcon(props: IconProps) { + return ( + + + + ); +} + +export function SaveDraftIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function DragHandleIcon(props: IconProps) { + return ( + + {[8, 12, 16].flatMap((y) => + [9, 15].map((x) => ( + + )), + )} + + ); +} + +export function CameraIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ImageIcon(props: IconProps) { + return ( + + + + + + ); +} diff --git a/apps/web/src/icons/navigation.tsx b/apps/web/src/icons/navigation.tsx new file mode 100644 index 0000000..6098ed6 --- /dev/null +++ b/apps/web/src/icons/navigation.tsx @@ -0,0 +1,110 @@ +import { IconBase } from './IconBase'; +import type { IconProps } from './types'; + +export function HomeIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function CookbookIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ProfileIcon(props: IconProps) { + return ( + + + + + ); +} + +export function SearchIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ChevronDownIcon(props: IconProps) { + return ( + + + + ); +} + +export function ChevronLeftIcon(props: IconProps) { + return ( + + + + ); +} + +export function ChevronRightIcon(props: IconProps) { + return ( + + + + ); +} + +export function BackIcon(props: IconProps) { + return ( + + + + + ); +} + +export function LoginIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function LogoutIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function MenuIcon(props: IconProps) { + return ( + + + + ); +} + +export function MoreIcon(props: IconProps) { + return ( + + + + + + ); +} diff --git a/apps/web/src/icons/rating.tsx b/apps/web/src/icons/rating.tsx new file mode 100644 index 0000000..4ab3064 --- /dev/null +++ b/apps/web/src/icons/rating.tsx @@ -0,0 +1,43 @@ +import { useId } from 'react'; +import { IconBase } from './IconBase'; +import type { IconProps } from './types'; + +export type StarVariant = 'empty' | 'half' | 'full'; + +export interface StarIconProps extends IconProps { + variant?: StarVariant; +} + +const STAR_PATH = + 'M12 3.3 14.7 8.8l6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9Z'; + +export function StarIcon({ variant = 'empty', ...props }: StarIconProps) { + const clipId = useId().replace(/:/g, ''); + + return ( + + {variant === 'half' ? ( + <> + + + + + + + + + ) : ( + + )} + + ); +} diff --git a/apps/web/src/icons/recipe.tsx b/apps/web/src/icons/recipe.tsx new file mode 100644 index 0000000..d49e098 --- /dev/null +++ b/apps/web/src/icons/recipe.tsx @@ -0,0 +1,118 @@ +import { IconBase } from './IconBase'; +import type { IconProps } from './types'; + +export function CookingTimeIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ServingsIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function CategoriesIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function PublicIcon(props: IconProps) { + return ( + + + + + ); +} + +export function PrivateIcon(props: IconProps) { + return ( + + + + + ); +} + +export function EmptyStateIcon(props: IconProps) { + return ( + + + + + + + ); +} + +export function DietaryIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ChefIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function SoupIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function InstructionsIcon(props: IconProps) { + return ( + + + + + ); +} + +export function RecentRecipesIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function DifficultyIcon(props: IconProps) { + return ( + + + + ); +} diff --git a/apps/web/src/icons/status.tsx b/apps/web/src/icons/status.tsx new file mode 100644 index 0000000..5f603b1 --- /dev/null +++ b/apps/web/src/icons/status.tsx @@ -0,0 +1,50 @@ +import { IconBase } from './IconBase'; +import type { IconProps } from './types'; + +export function InfoIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function SuccessIcon(props: IconProps) { + return ( + + + + + ); +} + +export function ErrorIcon(props: IconProps) { + return ( + + + + + ); +} + +export function AlertIcon(props: IconProps) { + return ( + + + + + + ); +} + +export function AlertTriangleIcon(props: IconProps) { + return ( + + + + + + ); +} diff --git a/apps/web/src/icons/types.ts b/apps/web/src/icons/types.ts new file mode 100644 index 0000000..4e9c553 --- /dev/null +++ b/apps/web/src/icons/types.ts @@ -0,0 +1,22 @@ +import type { SVGProps } from 'react'; + +/** A raw icon can use any CSS length or a numeric SVG size. */ +export type IconSize = number | string; + +/** + * Shared props for every raw recipe icon. + * + * Raw icons are intentionally presentation-light: they draw the SVG shape, + * use currentColor, and accept normal SVG props. For design-system sizing and + * semantic colors, prefer components/ui/Icon. + */ +export interface IconProps extends Omit, 'color'> { + /** CSS size, rem value, px number, or token such as var(--icon-size-md). */ + size?: IconSize; + /** Explicit CSS color. Omit it to inherit currentColor. */ + color?: string; + /** Accessible title. Decorative icons are aria-hidden by default. */ + title?: string; + /** Stroke width for outline icons. */ + strokeWidth?: number | string; +}