Product hero
Hero
Left-weighted headline and a short sentence next to a real product screen or the actual result a visitor came for, instead of a centered title floating over a gradient.
실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.
내 앱에 넣기
아직 npm 패키지가 없어서 Taster 리포를 받아 그 안의 명령을 씁니다. 내 앱 폴더가 들어 있는 폴더에서 한 번만 받습니다.
git clone https://github.com/makim-414/taster.git && npm ci --prefix taster/packages/engine내 앱 폴더에서 이 부품을 넣습니다. 부품 파일과 토큰 파일이
src/components/taster에 들어갑니다.node ../taster/packages/engine/cli.mjs add marketing/product-hero --from https://taster-six.vercel.app --dir src/components/taster부품은 Tailwind 클래스로 그리고, Taster 프리셋이 그 클래스를 토큰에 연결합니다. Tailwind CSS 를 설치하고,
tokens.css를 앱 루트에서 한 번 불러온 뒤, 앱 루트에 이 설정을 둡니다. 프리셋이 없으면 빌드는 되어도 부품이 스타일 없이 나옵니다.// tailwind.config.cjs module.exports = { presets: [require('./src/components/taster/tailwind-preset.cjs')], content: ['./index.html', './src/**/*.{ts,tsx}'], };Tailwind v3 는 이 파일을 그대로 읽습니다. v4 는 Tailwind 를 불러오는
src/의 스타일시트 맨 위에 이 두 줄을 넣습니다.@import "tailwindcss"; @config "../tailwind.config.cjs";tokens.css는:root에--bg,--text,--border,--accent를 정의합니다. 내 앱의 스타일시트가 같은 이름을 뒤에서 다시 정의하면 그쪽 색이 이깁니다. 새 Vite 앱의 스타터 CSS 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.
언제 쓰나요
- Asymmetric product heroLeft-weighted headline and a short sentence next to a real product screen or the actual result a visitor came for, instead of a centered title floating over a gradient.
- Real product frameA rounded frame around a true screenshot or recording of the product. Drawn skeleton mockups and fake terminals are replaced by the real screen.
대신 없애 주는 AI 티
- Drawn mockup instead of the real thing (AC-17)
- Row of three big stats (CMP-06)
- Fake terminal hero (CMP-07)
- The centered hero formula (LAY-01)
정보
코드 보기
import * as React from 'react'
import { cn } from '../blocks/_cn'
import { safeHref } from '../blocks/_url'
// Product hero: a left-weighted headline block beside a real product screen that is cropped by the
// right edge of the band, so the visual gets the larger share and reads as the actual thing, not a mockup.
// Follows patterns/asymmetric-product-hero and patterns/real-product-frame: one solid action, at most one
// text link, an optional proof line with a date, no pill, no stat strip, no window chrome.
// Pass a screenshot through `media`, or any node (a video with a poster, a result card). A label such
// as "Sample data" sits in the frame corner when the screen does not show real customer data.
// Original code, MIT.
export interface HeroAction {
label: string
href: string
}
export interface ProductHeroMedia {
src: string
alt: string
width: number
height: number
}
export interface ProductHeroProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
/** Short sentence-case line above the title. Optional; leave it out unless it adds a fact. */
eyebrow?: string
title: string
lead: string
primary: HeroAction
secondary?: HeroAction
/** One fact with its date, for example "412 reports run in the last 7 days. Updated 24 Oct." */
proof?: React.ReactNode
media: ProductHeroMedia | React.ReactNode
/** Small label in the frame corner, for example "Sample data". */
mediaLabel?: string
/** One sentence under the frame on narrow screens and beside it on wide ones. */
caption?: string
/** Heading level of the title. The first band of a page uses h1. */
as?: 'h1' | 'h2'
/** Let the frame run past the right edge of the band on wide screens. Default true. */
bleed?: boolean
}
const KEEP = 'break-keep [overflow-wrap:break-word]'
const SOLID =
'inline-flex h-11 items-center justify-center rounded-md bg-accent px-6 text-title font-medium text-accent-fg outline-none ' +
'transition-[opacity,transform] duration-press ease-out hover:opacity-90 active:scale-press focus-visible:ring-2 focus-visible:ring-ring'
const TEXT_LINK =
'inline-flex min-h-11 items-center text-body font-medium text-text-muted underline-offset-4 outline-none ' +
'hover:text-text hover:underline focus-visible:ring-2 focus-visible:ring-ring rounded-sm'
function isMedia(m: unknown): m is ProductHeroMedia {
return !!m && typeof m === 'object' && 'src' in (m as object) && 'alt' in (m as object)
}
export function ProductHero({
eyebrow,
title,
lead,
primary,
secondary,
proof,
media,
mediaLabel,
caption,
as: Heading = 'h1',
bleed = true,
className,
...props
}: ProductHeroProps) {
const titleId = React.useId()
return (
<section aria-labelledby={titleId} className={cn('overflow-hidden', className)} {...props}>
<div className="grid items-center gap-12 py-12 lg:grid-cols-[minmax(0,5fr)_minmax(0,7fr)] lg:py-16">
<div className="max-w-[460px]">
{eyebrow ? <p className={cn('mb-3 text-label font-medium text-text-muted', KEEP)}>{eyebrow}</p> : null}
<Heading
id={titleId}
className={cn('text-h1 font-semibold leading-[var(--lh-tight)] tracking-[-0.01em] text-text text-balance lg:text-display', KEEP)}
>
{title}
</Heading>
<p className={cn('mt-4 text-title font-reg leading-[var(--lh-normal)] text-text-muted text-pretty', KEEP)}>{lead}</p>
<div className="mt-8 flex flex-wrap items-center gap-x-6 gap-y-2">
<a href={safeHref(primary.href)} className={SOLID}>
{primary.label}
</a>
{secondary ? (
<a href={safeHref(secondary.href)} className={TEXT_LINK}>
{secondary.label}
</a>
) : null}
</div>
{proof ? <p className={cn('mt-6 text-label tabular-nums text-text-subtle', KEEP)}>{proof}</p> : null}
</div>
<figure className={cn('m-0 min-w-0', bleed && 'lg:-mr-16')}>
<div className="relative overflow-hidden rounded-xl border border-border bg-bg-sunken">
{isMedia(media) ? (
<img
src={media.src}
alt={media.alt}
width={media.width}
height={media.height}
className="block h-auto w-full"
/>
) : (
media
)}
{mediaLabel ? (
<span className="absolute left-3 top-3 rounded-sm bg-bg px-2 py-1 text-caption text-text-muted">{mediaLabel}</span>
) : null}
</div>
{caption ? <figcaption className={cn('mt-3 text-label text-text-subtle', KEEP)}>{caption}</figcaption> : null}
</figure>
</div>
</section>
)
}