diff --git a/apps/web/src/assets/recipe-fallback.png b/apps/web/src/assets/recipe-fallback.png new file mode 100644 index 0000000..b141e8e Binary files /dev/null and b/apps/web/src/assets/recipe-fallback.png differ diff --git a/apps/web/src/components/brand/LogoMark/LogoMark.css b/apps/web/src/components/brand/LogoMark/LogoMark.css new file mode 100644 index 0000000..1546103 --- /dev/null +++ b/apps/web/src/components/brand/LogoMark/LogoMark.css @@ -0,0 +1,8 @@ +@layer components { + .brand-logo-mark { + display: block; + flex: none; + + color: var(--color-brand-primary); + } +} diff --git a/apps/web/src/components/brand/LogoMark/LogoMark.tsx b/apps/web/src/components/brand/LogoMark/LogoMark.tsx new file mode 100644 index 0000000..b791f4c --- /dev/null +++ b/apps/web/src/components/brand/LogoMark/LogoMark.tsx @@ -0,0 +1,86 @@ +import type { CSSProperties, SVGProps } from 'react'; + +import './LogoMark.css'; + +export interface LogoMarkProps + extends Omit, 'color' | 'width' | 'height'> { + /** Square rendered size. Numbers are treated as CSS pixels. */ + size?: number | string; + + /** + * Explicit logo color override. + * + * The default comes from LogoMark.css and uses --color-brand-primary. + */ + color?: string; + + /** + * Optional accessible title when the mark itself needs an accessible name. + * Leave unset when nearby visible text already names the application. + */ + title?: string; +} + +/** + * Recipe application brand mark. + * + * This is intentionally separate from src/icons: it is brand artwork rather + * than a reusable interface icon. The geometry uses currentColor so the mark + * can use the normal brand color by default and inherit/override color when + * needed (for example, an inverse header treatment later). + */ +export default function LogoMark({ + size = '2rem', + color, + title, + className, + style, + ...svgProps +}: LogoMarkProps) { + const isLabelled = Boolean( + title || svgProps['aria-label'] || svgProps['aria-labelledby'], + ); + + const classes = ['brand-logo-mark', className].filter(Boolean).join(' '); + + const logoStyle: CSSProperties = { + ...style, + ...(color ? { color } : {}), + }; + + return ( + + {title ? {title} : null} + + + + {/* Fork: three rounded tines, a curved shoulder, and one handle. */} + + + + + + {/* Spoon: broad bowl tapering into a straight handle. */} + + + ); +} diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.css b/apps/web/src/components/recipe/RecipeCard/RecipeCard.css new file mode 100644 index 0000000..5806c0c --- /dev/null +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.css @@ -0,0 +1,410 @@ +@layer components { + .recipe-card { + position: relative; + + display: flex; + flex-direction: column; + + container-name: recipe-card; + container-type: inline-size; + + min-width: 0; + overflow: hidden; + + color: var(--color-text-primary); + background-color: var(--color-surface); + + border: var(--border-width-thin) solid var(--color-border-subtle); + border-radius: var(--radius-lg); + box-shadow: var(--shadow-sm); + + transition: + background-color var(--duration-fast) var(--ease-standard), + border-color var(--duration-fast) var(--ease-standard), + box-shadow var(--duration-fast) var(--ease-standard); + } + + .recipe-card:hover { + border-color: var(--color-brand-primary); + + box-shadow: var(--shadow-lg); + } + + .recipe-card:has(.recipe-card__title-link:focus-visible) { + border-color: var(--color-focus-ring); + + box-shadow: + 0 0 0 var(--border-width-medium) var(--color-focus-ring), + var(--shadow-md); + } + + .recipe-card:has(.recipe-card__title-link:active) { + background-color: var(--color-surface-pressed); + + border-color: var(--color-brand-primary-active); + + box-shadow: var(--shadow-sm); + } + + .recipe-card__media { + position: relative; + + aspect-ratio: 16 / 6.75; + overflow: hidden; + + background-color: var(--color-surface-muted); + } + + .recipe-card__image { + display: block; + + width: 100%; + height: 100%; + + object-fit: cover; + object-position: center; + } + + .recipe-card__image--fallback { + object-position: center; + } + + .recipe-card__body { + display: flex; + flex: 1 1 auto; + flex-direction: column; + + gap: var(--space-2); + + min-width: 0; + padding: var(--space-3); + } + + .recipe-card__heading-row { + display: flex; + align-items: flex-start; + justify-content: space-between; + + gap: var(--space-2); + + min-width: 0; + } + + .recipe-card__title { + display: -webkit-box; + overflow: hidden; + + min-width: 0; + + font-size: var(--font-size-md); + font-weight: var(--font-weight-semibold); + line-height: var(--line-height-tight); + letter-spacing: var(--letter-spacing-tight); + + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + line-clamp: 2; + } + + .recipe-card__title-link { + color: var(--color-text-primary); + text-decoration: none; + } + + /* + * The title link owns navigation for the passive + * RecipeCard surface. + */ + .recipe-card__title-link::after { + content: ''; + + position: absolute; + z-index: 1; + inset: 0; + + border-radius: inherit; + + cursor: pointer; + } + + .recipe-card__title-link:hover { + color: var(--color-text-primary); + } + + /* + * Focus for recipe navigation is represented around + * the complete card rather than only the title. + */ + .recipe-card__title-link:focus-visible { + outline: none; + } + + .recipe-card__description { + display: -webkit-box; + overflow: hidden; + + color: var(--color-text-secondary); + + font-size: var(--font-size-sm); + line-height: var(--line-height-snug); + + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + line-clamp: 2; + } + + .recipe-card__action { + position: relative; + z-index: 2; + + flex: 0 0 auto; + } + + /* + * Base Save button. + */ + .recipe-card__save-button.button { + min-height: var(--control-height-sm); + + color: var(--color-brand-primary-active); + + background-color: var(--color-surface); + + border-color: var(--color-brand-primary); + + transform: translateY(0); + + white-space: nowrap; + + transition: + transform var(--duration-fast) var(--ease-standard), + background-color var(--duration-fast) var(--ease-standard), + border-color var(--duration-fast) var(--ease-standard), + box-shadow var(--duration-fast) var(--ease-standard); + } + + /* + * Saved resting state. + * + * The soft background and filled heart communicate + * that the recipe is already saved. + */ + .recipe-card__save-button.button[aria-pressed='true'] { + color: var(--color-brand-primary-active); + + background-color: var(--color-brand-accent-soft); + + border-color: var(--color-brand-primary); + } + + /* + * Shared hover state for Save and Saved. + * + * Both states move onto the same hover surface. + * A stronger shadow and slight upward movement make + * hover clear even when the saved resting color is + * visually close to the hover color. + */ + .recipe-card__save-button.button:hover:not(:disabled) { + color: var(--color-brand-primary-active); + + background-color: var(--color-surface-selected); + + border-color: var(--color-brand-primary-hover); + + box-shadow: var(--shadow-md); + + transform: translateY(-1px); + } + + /* + * Active/pressed state. + * + * Pressing reverses the hover elevation: the button + * moves slightly downward and loses its shadow. + * This keeps active clearly distinct from hover even + * when the warm background colors are similar. + */ + .recipe-card__save-button.button:active:not(:disabled) { + background-color: var(--color-surface-pressed); + + border-color: var(--color-brand-primary-active); + + box-shadow: none; + + transform: translateY(1px); + } + + /* + * Keyboard focus remains separate from pointer + * hover and active states. + * + * The pale outer halo helps the focus indicator + * remain visible when the button sits directly + * over detailed recipe photography. + */ + .recipe-card__save-button.button:focus-visible { + outline: none; + + box-shadow: + 0 0 0 var(--border-width-medium) var(--color-focus-ring), + 0 0 0 calc(var(--border-width-medium) + var(--border-width-thick)) + var(--color-brand-accent-soft), + var(--shadow-md); + } + + .recipe-card__footer { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + + column-gap: var(--space-2); + row-gap: var(--space-2); + + min-width: 0; + margin-block-start: auto; + } + + .recipe-card__tags { + display: flex; + flex: 1 1 10rem; + flex-wrap: wrap; + align-items: center; + justify-content: flex-end; + + gap: var(--space-1); + + min-width: 0; + margin: 0; + padding: 0; + + list-style: none; + } + + .recipe-card__tag-item { + min-width: 0; + max-width: 100%; + } + + .recipe-card__tag.tag { + max-width: min(100%, 11rem); + + min-height: var(--space-6); + + padding-inline: var(--space-2); + + font-size: var(--font-size-xs); + } + + .recipe-card__tag .tag__text { + overflow: hidden; + + text-overflow: ellipsis; + white-space: nowrap; + } + + .recipe-card__tag--overflow.tag { + flex: 0 0 auto; + + color: var(--color-text-secondary); + } + + /* + * Compact card layout. + */ + @container recipe-card (max-width: 23rem) { + .recipe-card__media { + aspect-ratio: 16 / 6.5; + } + + .recipe-card__body { + gap: var(--space-1); + padding: var(--space-2); + } + + .recipe-card__title { + padding-inline-end: var(--space-1); + + font-size: var(--font-size-sm); + } + + .recipe-card__description { + font-size: var(--font-size-xs); + } + + .recipe-card__action { + position: absolute; + z-index: 2; + + top: var(--space-2); + right: var(--space-2); + } + + .recipe-card__save-button.button { + padding-inline: var(--space-2); + + background-color: var(--color-surface); + + box-shadow: var(--shadow-sm); + } + + /* + * Restore the Saved resting surface because the + * compact base rule above explicitly sets the + * button background. + */ + .recipe-card__save-button.button[aria-pressed='true'] { + background-color: var(--color-brand-accent-soft); + } + + /* + * Hover and active rules above have higher + * specificity, so the same interaction behavior + * is preserved in the compact image-overlay layout. + */ + + .recipe-card .recipe-rating { + gap: var(--space-1); + } + + .recipe-card .recipe-meta { + gap: var(--space-2); + } + + .recipe-card__tags { + flex-basis: 9rem; + } + } + + @container recipe-card (max-width: 17rem) { + .recipe-card__footer { + align-items: flex-start; + flex-direction: column; + } + + .recipe-card__tags { + flex: 0 1 auto; + justify-content: flex-start; + + width: 100%; + } + } + + @media (prefers-reduced-motion: reduce) { + .recipe-card, + .recipe-card__save-button.button { + transition: none; + } + + /* + * Preserve color, border, and shadow feedback + * without movement for users who prefer reduced + * motion. + */ + .recipe-card__save-button.button:hover:not(:disabled), + .recipe-card__save-button.button:active:not(:disabled) { + transform: none; + } + } +} diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx new file mode 100644 index 0000000..9aa4e3e --- /dev/null +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx @@ -0,0 +1,266 @@ +import { useState, type ComponentPropsWithoutRef, type ReactNode } from 'react'; +import { Link } from 'react-router-dom'; + +import fallbackRecipeImage from '../../../assets/recipe-fallback.png'; +import { HeartIcon } from '../../../icons/actions'; +import Button from '../../ui/Button/Button'; +import ConfirmationDialog from '../../ui/ConfirmationDialog/ConfirmationDialog'; +import { Icon } from '../../ui/Icon/Icon'; +import Tag, { type TagTone } from '../../ui/Tag/Tag'; +import RecipeMeta from '../RecipeMeta/RecipeMeta'; +import RecipeRating, { + type RecipeRatingData, +} from '../RecipeRating/RecipeRating'; + +import './RecipeCard.css'; + +export type RecipeCardRating = RecipeRatingData; + +export interface RecipeCardTag { + label: string; + tone?: TagTone; +} + +type RecipeCardImageProps = + | { + imageSrc: string; + imageAlt: string; + } + | { + imageSrc?: undefined; + imageAlt?: never; + }; + +type RecipeCardBaseProps = Omit< + ComponentPropsWithoutRef<'article'>, + 'children' | 'title' +> & { + /** + * Identifier used to open the recipe detail route. + * + * The card navigates to /recipes/:id. + */ + recipeId: string; + + title: string; + description: string; + + rating?: RecipeRatingData; + + /** + * Structured cooking time in minutes. + */ + cookingTimeMinutes: number; + + servings: number; + tags?: RecipeCardTag[]; + + /** + * Controlled saved state for the built-in + * Save action. + */ + saved?: boolean; + + /** + * Enables the built-in Save/Saved action + * and handles state changes. + * + * Omit this for recipes that cannot be saved, + * including the current user's own recipes. + */ + onSaveChange?: (saved: boolean) => void; + + /** + * Optional context-specific action such as + * Open or Edit. + * + * Supplying it replaces the built-in + * Save/Saved action. + */ + action?: ReactNode; +}; + +export type RecipeCardProps = RecipeCardBaseProps & RecipeCardImageProps; + +const MAX_VISIBLE_TAGS = 2; + +/** + * Reusable recipe result card for Explore + * and My Cookbook. + * + * Ownership and source attribution stay in + * recipe/user data rather than being shown + * as card badges. The caller decides whether + * saving is available. + */ +export default function RecipeCard({ + recipeId, + title, + description, + imageSrc, + imageAlt, + rating, + cookingTimeMinutes, + servings, + tags = [], + saved = false, + onSaveChange, + action, + className = '', + ...articleProps +}: RecipeCardProps) { + const [confirmUnsaveOpen, setConfirmUnsaveOpen] = useState(false); + + const classes = ['recipe-card', className].filter(Boolean).join(' '); + + const recipePath = `/recipes/${encodeURIComponent(recipeId)}`; + + const usesBuiltInSaveAction = action == null && Boolean(onSaveChange); + + const visibleTags = tags.slice(0, MAX_VISIBLE_TAGS); + + const hiddenTags = tags.slice(MAX_VISIBLE_TAGS); + + const hiddenTagLabels = hiddenTags.map((tag) => tag.label).join(', '); + + function handleSaveButtonClick() { + if (!onSaveChange) { + return; + } + + if (saved) { + setConfirmUnsaveOpen(true); + return; + } + + onSaveChange(true); + } + + function handleConfirmUnsave() { + setConfirmUnsaveOpen(false); + onSaveChange?.(false); + } + + function handleCancelUnsave() { + setConfirmUnsaveOpen(false); + } + + const builtInSaveAction = usesBuiltInSaveAction ? ( + + ) : null; + + const actionContent = action ?? builtInSaveAction; + + return ( + <> +
+
+ {imageSrc +
+ +
+
+

+ + {title} + +

+ + {actionContent ? ( +
{actionContent}
+ ) : null} +
+ +

{description}

+ + {rating ? ( + + ) : null} + +
+ + + {tags.length > 0 ? ( +
    + {visibleTags.map((tag, index) => ( +
  • + + {tag.label} + +
  • + ))} + + {hiddenTags.length > 0 ? ( +
  • + + +{hiddenTags.length} + +
  • + ) : null} +
+ ) : null} +
+
+
+ + {usesBuiltInSaveAction ? ( + + You can save this recipe again later. + + ) : null} + + ); +} diff --git a/apps/web/src/components/recipe/RecipeMeta/RecipeMeta.css b/apps/web/src/components/recipe/RecipeMeta/RecipeMeta.css new file mode 100644 index 0000000..94239ac --- /dev/null +++ b/apps/web/src/components/recipe/RecipeMeta/RecipeMeta.css @@ -0,0 +1,26 @@ +@layer components { + .recipe-meta { + display: flex; + flex: 0 0 auto; + flex-wrap: wrap; + align-items: center; + gap: var(--space-3); + + min-width: 0; + } + + .recipe-meta__item { + display: inline-flex; + align-items: center; + gap: var(--space-1); + + min-width: 0; + + color: var(--color-text-secondary); + + font-size: var(--font-size-xs); + line-height: var(--line-height-tight); + + white-space: nowrap; + } +} diff --git a/apps/web/src/components/recipe/RecipeMeta/RecipeMeta.tsx b/apps/web/src/components/recipe/RecipeMeta/RecipeMeta.tsx new file mode 100644 index 0000000..0036d54 --- /dev/null +++ b/apps/web/src/components/recipe/RecipeMeta/RecipeMeta.tsx @@ -0,0 +1,57 @@ +import type { ComponentPropsWithoutRef } from 'react'; + +import { CookingTimeIcon, ServingsIcon } from '../../../icons/recipe'; +import { Icon } from '../../ui/Icon/Icon'; + +import './RecipeMeta.css'; + +export type RecipeMetaProps = Omit< + ComponentPropsWithoutRef<'div'>, + 'children' +> & { + cookingTimeMinutes: number; + servings: number; +}; + +function formatServings(servings: number) { + return `${servings} ${servings === 1 ? 'serving' : 'servings'}`; +} + +/** + * Shared compact cooking-time and servings + * metadata for recipes. + */ +export default function RecipeMeta({ + cookingTimeMinutes, + servings, + className = '', + ...props +}: RecipeMetaProps) { + const classes = ['recipe-meta', className].filter(Boolean).join(' '); + + return ( +
+ + + + + +
+ ); +} diff --git a/apps/web/src/components/recipe/RecipeRating/RecipeRating.css b/apps/web/src/components/recipe/RecipeRating/RecipeRating.css new file mode 100644 index 0000000..a0011c4 --- /dev/null +++ b/apps/web/src/components/recipe/RecipeRating/RecipeRating.css @@ -0,0 +1,24 @@ +@layer components { + .recipe-rating { + display: inline-flex; + align-items: center; + gap: var(--space-2); + + width: fit-content; + max-width: 100%; + } + + .recipe-rating__stars { + display: inline-flex; + align-items: center; + + color: var(--color-brand-primary); + } + + .recipe-rating__count { + color: var(--color-text-muted); + + font-size: var(--font-size-xs); + line-height: var(--line-height-tight); + } +} diff --git a/apps/web/src/components/recipe/RecipeRating/RecipeRating.tsx b/apps/web/src/components/recipe/RecipeRating/RecipeRating.tsx new file mode 100644 index 0000000..43ebe7b --- /dev/null +++ b/apps/web/src/components/recipe/RecipeRating/RecipeRating.tsx @@ -0,0 +1,85 @@ +import type { ComponentPropsWithoutRef } from 'react'; + +import { StarIcon, type StarVariant } from '../../../icons/rating'; +import { Icon } from '../../ui/Icon/Icon'; + +import './RecipeRating.css'; + +export interface RecipeRatingData { + value: number; + count: number; +} + +export type RecipeRatingProps = Omit< + ComponentPropsWithoutRef<'div'>, + 'children' +> & + RecipeRatingData; + +const ratingCountFormatter = new Intl.NumberFormat(); + +function getStarVariants(rating: number): StarVariant[] { + const rounded = Math.round(Math.min(5, Math.max(0, rating)) * 2) / 2; + + return Array.from({ length: 5 }, (_, index) => { + const starNumber = index + 1; + + if (rounded >= starNumber) { + return 'full'; + } + + if (rounded >= starNumber - 0.5) { + return 'half'; + } + + return 'empty'; + }); +} + +/** + * Shared compact rating display for recipe list + * and detail surfaces. + */ +export default function RecipeRating({ + value, + count, + className = '', + ...props +}: RecipeRatingProps) { + const normalizedValue = Math.min(5, Math.max(0, value)); + + const normalizedCount = Math.max(0, count); + + const classes = ['recipe-rating', className].filter(Boolean).join(' '); + + return ( +
+ + + + ({ratingCountFormatter.format(normalizedCount)}) + +
+ ); +} diff --git a/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx b/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx new file mode 100644 index 0000000..6e7103e --- /dev/null +++ b/apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx @@ -0,0 +1,248 @@ +import { type ComponentProps } from 'react'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { MemoryRouter } from 'react-router-dom'; +import { describe, expect, it, vi } from 'vitest'; + +import RecipeCard from '../RecipeCard/RecipeCard'; + +const baseProps = { + recipeId: 'carbonara', + title: 'Spaghetti Carbonara', + description: 'A classic Italian pasta dish with a rich and creamy sauce.', + cookingTimeMinutes: 25, + servings: 4, + rating: { + value: 4.8, + count: 124, + }, + tags: [ + { + label: 'Dinner', + }, + { + label: 'Italian', + }, + ], +}; + +function renderRecipeCard(props: ComponentProps) { + return render( + + + , + ); +} + +describe('RecipeCard', () => { + it('exposes the recipe link and accessible rating summary', () => { + renderRecipeCard(baseProps); + + const recipeLink = screen.getByRole('link', { + name: 'Spaghetti Carbonara', + }); + + expect(recipeLink.getAttribute('href')).toBe('/recipes/carbonara'); + + expect( + screen.getByRole('img', { + name: '4.8 out of 5 from 124 ratings', + }), + ).toBeTruthy(); + }); + + it('renders structured cooking time and servings metadata', () => { + renderRecipeCard(baseProps); + + expect(screen.getByText('25 min')).toBeTruthy(); + + expect(screen.getByText('4 servings')).toBeTruthy(); + }); + + it('keeps recipe navigation and Save as separate keyboard tab stops', async () => { + const user = userEvent.setup(); + + renderRecipeCard({ + ...baseProps, + saved: false, + onSaveChange: () => undefined, + }); + + const recipeLink = screen.getByRole('link', { + name: 'Spaghetti Carbonara', + }); + + const saveButton = screen.getByRole('button', { + name: 'Save', + }); + + await user.tab(); + + expect(document.activeElement).toBe(recipeLink); + + await user.tab(); + + expect(document.activeElement).toBe(saveButton); + }); + + it('saves an unsaved recipe immediately', async () => { + const user = userEvent.setup(); + + const onSaveChange = vi.fn(); + + renderRecipeCard({ + ...baseProps, + saved: false, + onSaveChange, + }); + + const saveButton = screen.getByRole('button', { + name: 'Save', + }); + + expect(saveButton.getAttribute('aria-pressed')).toBe('false'); + + await user.click(saveButton); + + expect(onSaveChange).toHaveBeenCalledTimes(1); + + expect(onSaveChange).toHaveBeenCalledWith(true); + }); + + it('asks for confirmation before unsaving a recipe', async () => { + const user = userEvent.setup(); + + const onSaveChange = vi.fn(); + + renderRecipeCard({ + ...baseProps, + saved: true, + onSaveChange, + }); + + const savedButton = screen.getByRole('button', { + name: 'Saved', + }); + + expect(savedButton.getAttribute('aria-pressed')).toBe('true'); + + await user.click(savedButton); + + expect(onSaveChange).not.toHaveBeenCalled(); + + expect(screen.getByText('Remove saved recipe?')).toBeTruthy(); + + await user.click( + screen.getByRole('button', { + name: 'Unsave', + }), + ); + + expect(onSaveChange).toHaveBeenCalledTimes(1); + + expect(onSaveChange).toHaveBeenCalledWith(false); + }); + + it('keeps the recipe saved when the unsave dialog is cancelled', async () => { + const user = userEvent.setup(); + + const onSaveChange = vi.fn(); + + renderRecipeCard({ + ...baseProps, + saved: true, + onSaveChange, + }); + + await user.click( + screen.getByRole('button', { + name: 'Saved', + }), + ); + + await user.click( + screen.getByRole('button', { + name: 'Keep saved', + }), + ); + + expect(onSaveChange).not.toHaveBeenCalled(); + }); + + it('does not show Save when saving is not available', () => { + renderRecipeCard(baseProps); + + expect( + screen.queryByRole('button', { + name: 'Save', + }), + ).toBeNull(); + + expect( + screen.queryByRole('button', { + name: 'Saved', + }), + ).toBeNull(); + }); + + it('allows a context action to replace the built-in Save action', () => { + renderRecipeCard({ + ...baseProps, + saved: true, + onSaveChange: () => undefined, + action: , + }); + + expect( + screen.getByRole('button', { + name: 'Open', + }), + ).toBeTruthy(); + + expect( + screen.queryByRole('button', { + name: 'Saved', + }), + ).toBeNull(); + }); + + it('limits visible recipe tags and summarizes the remainder', () => { + renderRecipeCard({ + ...baseProps, + tags: [ + { + label: 'Breakfast', + }, + { + label: 'Healthy', + }, + { + label: 'Vegetarian', + }, + { + label: 'Quick & Easy', + }, + { + label: 'High Protein', + }, + { + label: 'Brunch', + }, + ], + }); + + expect(screen.getByText('Breakfast')).toBeTruthy(); + + expect(screen.getByText('Healthy')).toBeTruthy(); + + expect(screen.queryByText('Vegetarian')).toBeNull(); + + expect(screen.getByText('+4')).toBeTruthy(); + + expect( + screen.getByLabelText( + '4 more recipe tags: Vegetarian, Quick & Easy, High Protein, Brunch', + ), + ).toBeTruthy(); + }); +}); diff --git a/apps/web/src/components/recipe/showcase/RecipeCardShowcase.tsx b/apps/web/src/components/recipe/showcase/RecipeCardShowcase.tsx new file mode 100644 index 0000000..0686ef1 --- /dev/null +++ b/apps/web/src/components/recipe/showcase/RecipeCardShowcase.tsx @@ -0,0 +1,254 @@ +import { useState, type CSSProperties } from 'react'; + +import ShowcaseSection from '../../ui/showcase/ShowcaseSection'; +import { + raisedSurfaceStyle, + surfaceStyle, +} from '../../ui/showcase/showcaseStyles'; +import RecipeCard from '../RecipeCard/RecipeCard'; + +const BURGER_IMAGE = + 'https://pub-aaa82e9851064d22b954c3ebbafc9ae6.r2.dev/legacy/webp/burger-with-melted-cheese-m-Y1i3jpYYJZYfOEfX5dX.webp'; + +const BREAKFAST_IMAGE = + 'https://pub-aaa82e9851064d22b954c3ebbafc9ae6.r2.dev/legacy/webp/colorful-breakfast-spread-on-a-rustic-plate-VGbHfppD0Pq-q4gtkxTDo.webp'; + +const cardGridStyle: CSSProperties = { + display: 'grid', + gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 18rem), 1fr))', + gap: 'var(--space-4)', +}; + +const narrowCardSurfaceStyle: CSSProperties = { + ...raisedSurfaceStyle, + width: '100%', + maxWidth: '22rem', + marginInline: 'auto', +}; + +export default function RecipeCardShowcase() { + const [burgerSaved, setBurgerSaved] = useState(false); + + const [breakfastSaved, setBreakfastSaved] = useState(true); + + const [narrowCardSaved, setNarrowCardSaved] = useState(false); + + return ( +
+
+
+

RecipeCard Showcase

+ +

+ Visual and interaction examples for the reusable RecipeCard across + common Explore states and responsive widths. +

+
+ + + Recipes from other users can be saved. Already-saved recipes + require confirmation before being unsaved. Recipes created by the + current user simply omit the save handler. + + } + > +
+ + + + + +
+
+ + + Saving happens immediately. Clicking Saved afterwards opens the + confirmation dialog before removing it from the cookbook. + + } + > +
+ +
+
+ + +
+ undefined} + /> +
+
+ + +
+ +
+
+
+
+ ); +}