All files / web/src/components/create CreateToolCard.tsx

100% Statements 297/297
100% Branches 36/36
100% Functions 1/1
100% Lines 297/297

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 2981x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 12x 18x 30x 30x 30x 30x 30x 30x 30x 30x 12x 18x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 24x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 18x 18x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 12x 12x 12x 12x 12x 18x 18x 18x 18x 18x 18x 30x 30x 30x 12x 18x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x  
'use client'
 
import { css } from '@styled/css'
import Link from 'next/link'
import type { CreateToolMeta } from '@/lib/create-tools/createToolList'
import { CreateToolPreviewSlot, type PreviewLoading } from './CreateToolPreviewSlot'
 
export type CreateToolCardVariant = 'flagship' | 'default' | 'compact'
 
interface CreateToolCardProps {
  tool: CreateToolMeta
  variant?: CreateToolCardVariant
  title: string
  description: string
  features: string[]
  buttonText: string
  /** Small label above the title, e.g. "Start here" on the flagship. */
  eyebrow?: string
}
 
/**
 * The primary row is above the fold at every breakpoint we care about; the
 * "More printables" row is not, so it waits for the browser's lazy-loading.
 */
const PREVIEW_LOADING: Record<CreateToolCardVariant, PreviewLoading> = {
  flagship: 'priority',
  default: 'priority',
  compact: 'lazy',
}
 
/**
 * The grid track each variant occupies, so the browser can pick a srcset entry
 * instead of downloading the full-size capture. Mirrors the grids in
 * `CreateHubContent`: primary is 1 / 2 / 3-up capped at 1200px, secondary is
 * 1 / 2-up, and the flagship spans both columns until it settles into a third
 * at `lg`.
 */
const PREVIEW_SIZES: Record<CreateToolCardVariant, string> = {
  flagship: '(min-width: 1200px) 380px, (min-width: 1024px) 33vw, 100vw',
  default: '(min-width: 1200px) 380px, (min-width: 1024px) 33vw, (min-width: 640px) 50vw, 100vw',
  compact: '(min-width: 1200px) 580px, (min-width: 640px) 50vw, 100vw',
}
 
/**
 * One frame shape for every card. Cards sit shoulder to shoulder in a grid, so
 * a per-variant ratio would drop each card's title onto a different line — and
 * the flagship shares the primary row with `default` cards at `lg` anyway. The
 * artifacts range from 1.12 to 1.60; `contain` absorbs the difference against
 * each capture's own backdrop.
 */
const PREVIEW_FRAME = '4 / 3'
 
/**
 * One tool on the /create hub: a live miniature of what the tool produces,
 * above the copy.
 *
 * A11y shape worth keeping: the card is an `<article>` containing exactly ONE
 * real link — the CTA, which carries the accessible name. The whole tile is
 * still clickable via an inset `_before` overlay on that link, so pointer users
 * get a big target while screen-reader and keyboard users get a single stop
 * instead of a duplicate title-link/CTA-link pair. Focus styling therefore
 * lives on the card via `_focusWithin`.
 */
export function CreateToolCard({
  tool,
  variant = 'default',
  title,
  description,
  features,
  buttonText,
  eyebrow,
}: CreateToolCardProps) {
  const { theme } = tool
  const compact = variant === 'compact'
 
  return (
    <article
      data-element="create-tool-card"
      data-tool-id={tool.id}
      data-tier={tool.tier}
      data-variant={variant}
      className={css({
        position: 'relative',
        display: 'flex',
        flexDirection: 'column',
        height: '100%',
        bg: 'bg.surface',
        borderRadius: { base: '2xl', md: '3xl' },
        border: '1px solid',
        borderColor: 'border.default',
        overflow: 'hidden',
        boxShadow: compact
          ? '0 4px 16px rgba(0,0,0,0.10)'
          : { base: '0 10px 40px rgba(0,0,0,0.15)', md: '0 16px 50px rgba(0,0,0,0.18)' },
        transition:
          'transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s, border-color 0.25s',
        _hover: {
          borderColor: 'border.emphasized',
          _motionSafe: {
            md: { transform: 'translateY(-6px)' },
          },
          boxShadow: compact
            ? '0 10px 28px rgba(0,0,0,0.16)'
            : { base: '0 16px 50px rgba(0,0,0,0.2)', md: '0 26px 70px rgba(0,0,0,0.24)' },
        },
        _focusWithin: {
          outline: '2px solid',
          outlineColor: 'blue.500',
          outlineOffset: '2px',
        },
      })}
    >
      {/* colorway bar — inline style because the gradient is per-tool data */}
      <div
        className={css({
          position: 'absolute',
          top: 0,
          left: 0,
          right: 0,
          height: { base: '4px', md: '6px' },
          zIndex: 1,
        })}
        style={{ background: theme.gradient }}
      />
 
      <div
        className={css({
          p: compact ? 3 : { base: 3, md: 4 },
          pt: compact ? 4 : { base: 4, md: 5 },
        })}
      >
        <CreateToolPreviewSlot
          preview={tool.preview}
          loading={PREVIEW_LOADING[variant]}
          sizes={PREVIEW_SIZES[variant]}
          frame={PREVIEW_FRAME}
        />
      </div>
 
      <div
        className={css({
          display: 'flex',
          flexDirection: 'column',
          flex: 1,
          px: compact ? 4 : { base: 5, md: 6 },
          pb: compact ? 4 : { base: 5, md: 6 },
          gap: compact ? 2 : { base: 2, md: 3 },
        })}
      >
        <div className={css({ display: 'flex', alignItems: 'center', gap: 2 })}>
          <span
            aria-hidden="true"
            className={css({
              display: 'inline-flex',
              alignItems: 'center',
              justifyContent: 'center',
              width: compact ? '26px' : '32px',
              height: compact ? '26px' : '32px',
              borderRadius: 'lg',
              fontSize: compact ? 'sm' : 'md',
              flexShrink: 0,
            })}
            style={{ background: theme.gradient }}
          >
            {tool.emoji}
          </span>
          {eyebrow ? (
            <span
              data-element="create-tool-eyebrow"
              className={css({
                fontSize: '2xs',
                fontWeight: 'bold',
                letterSpacing: 'wider',
                textTransform: 'uppercase',
                color: 'text.muted',
              })}
            >
              {eyebrow}
            </span>
          ) : null}
        </div>
 
        <h3
          className={css({
            fontSize: compact ? 'md' : { base: 'lg', md: 'xl' },
            fontWeight: 'bold',
            color: 'text.primary',
            letterSpacing: 'tight',
          })}
        >
          {title}
        </h3>
 
        <p
          className={css({
            fontSize: compact ? 'xs' : { base: 'sm', md: 'md' },
            color: 'text.secondary',
            lineHeight: '1.6',
          })}
        >
          {description}
        </p>
 
        {/* Features are supporting detail; the preview does this job on small
            screens and on the compact card, so they're dropped there. */}
        {compact ? null : (
          <ul
            className={css({
              listStyle: 'none',
              display: { base: 'none', sm: 'flex' },
              flexDirection: 'column',
              gap: 2,
              mt: 1,
            })}
          >
            {features.map((feature) => (
              <li
                key={feature}
                className={css({
                  display: 'flex',
                  alignItems: 'center',
                  gap: 2,
                  fontSize: { base: 'xs', md: 'sm' },
                  color: 'text.secondary',
                })}
              >
                <span
                  aria-hidden="true"
                  className={css({
                    display: 'inline-flex',
                    alignItems: 'center',
                    justifyContent: 'center',
                    width: '18px',
                    height: '18px',
                    borderRadius: 'full',
                    bg: theme.checkBg,
                    color: theme.checkColor,
                    fontSize: '2xs',
                    fontWeight: 'bold',
                    flexShrink: 0,
                  })}
                >
                  ✓
                </span>
                {feature}
              </li>
            ))}
          </ul>
        )}
 
        <div className={css({ mt: 'auto', pt: compact ? 2 : { base: 3, md: 4 } })}>
          <Link
            href={tool.href}
            data-action="open-create-tool"
            data-tool-id={tool.id}
            className={css({
              display: 'inline-flex',
              alignItems: 'center',
              gap: 2,
              fontWeight: 'bold',
              borderRadius: 'xl',
              transition: 'transform 0.2s, box-shadow 0.2s',
              // the tile-wide hit area; the link itself stays the only tab stop
              _before: {
                content: '""',
                position: 'absolute',
                inset: 0,
                zIndex: 2,
              },
              _focusVisible: { outline: 'none' },
              ...(compact
                ? {
                    color: 'text.primary',
                    fontSize: 'sm',
                    _hover: { color: 'blue.600' },
                  }
                : {
                    color: 'white',
                    fontSize: { base: 'sm', md: 'md' },
                    px: { base: 4, md: 5 },
                    py: { base: 2, md: 3 },
                  }),
            })}
            style={
              compact
                ? undefined
                : { background: theme.gradient, boxShadow: `0 4px 15px ${theme.shadowColor}` }
            }
          >
            <span>{buttonText}</span>
            <span aria-hidden="true">→</span>
          </Link>
        </div>
      </div>
    </article>
  )
}