Event ticket
A die-cut event ticket with punched notches, a generated barcode and a tear-off stub that peels away when you add it to your wallet.
"use client";
import { useMemo, useState, type ReactElement } from "react";
import "./event-ticket.css";
type EventTicketProps = {
event: string;
date: string;
time: string;
venue: string;
seat: { label: string; value: string }[];
code: string;
theme?: "light" | "dark";
};
/** A deterministic, decorative barcode: bar widths come from the ticket code. */
function bars(code: string) {
return code
.split("")
.flatMap((ch) => {
const n = ch.charCodeAt(0);
return [1 + (n % 3), 1 + ((n >> 2) % 2), 1 + ((n >> 3) % 3)];
})
.slice(0, 42);
}
/**
* EventTicket
* - The notches and the perforated line are made with CSS masks (no images).
* - "Add to wallet" tears the stub off: it rotates and drops away, then the button confirms.
*/
export function EventTicket({
event,
date,
time,
venue,
seat,
code,
theme = "light",
}: EventTicketProps) {
const [torn, setTorn] = useState(false);
const widths = useMemo(() => bars(code), [code]);
return (
<div className="gu-ticket" data-theme={theme} data-torn={torn || undefined}>
<article className="gu-ticket__main" aria-label={`Ticket for ${event}`}>
<p className="gu-ticket__kicker">Admit one</p>
<h3>{event}</h3>
<dl className="gu-ticket__grid">
<div>
<dt>Date</dt>
<dd>{date}</dd>
</div>
<div>
<dt>Doors</dt>
<dd>{time}</dd>
</div>
<div className="gu-ticket__wide">
<dt>Venue</dt>
<dd>{venue}</dd>
</div>
{seat.map((s) => (
<div key={s.label}>
<dt>{s.label}</dt>
<dd>{s.value}</dd>
</div>
))}
</dl>
<button
type="button"
className="gu-ticket__btn"
onClick={() => setTorn(true)}
disabled={torn}
>
{torn ? "Saved to wallet" : "Add to wallet"}
</button>
<p className="gu-ticket__sr" role="status">
{torn ? "Ticket saved to wallet" : ""}
</p>
</article>
<div className="gu-ticket__stub" aria-hidden={torn}>
<svg
className="gu-ticket__code"
viewBox={`0 0 ${widths.reduce((a, b) => a + b + 1, 0)} 40`}
preserveAspectRatio="none"
role="img"
aria-label={`Barcode ${code}`}
>
{
widths.reduce<{ x: number; els: ReactElement[] }>(
(acc, w, i) => {
if (i % 2 === 0)
acc.els.push(
<rect key={i} x={acc.x} y="0" width={w} height="40" />,
);
acc.x += w + 1;
return acc;
},
{ x: 0, els: [] },
).els
}
</svg>
<p className="gu-ticket__num">{code}</p>
</div>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Event ticket
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A die-cut event ticket: an orange main part with event details and an "Add to wallet" button, and a dark stub with a barcode. The notches and perforation are pure CSS. Adding to wallet tears the stub off: it rotates and falls away.
## Layout and look
- Max 560px wide, flex row, drop-shadow filter on the whole ticket so the notches cast real shadows.
- Main part: #ff5a1f, dark text, radius 18px on the left corners; 12px half-circle notches cut out of its right corners with two radial-gradient masks (top half and bottom half).
- Content: "Admit one" kicker, huge event name (weight 900, -0.045em), a grid of label/value pairs (Date, Doors, Venue across the width, Zone, Gate, Row).
- Button: dark pill with orange text; done = lime #d7ff3a with "Saved to wallet".
- Stub: 132px, #0e0e10 (cream in dark mode), notches on its left corners, a dashed perforation line on its left edge (2px × 12px repeating background), an SVG barcode generated from the ticket code and the code in monospace.
## Behavior and motion
1. Barcode: each character of the code gives three bar widths from its char code; every other entry is drawn as a bar.
2. Hover (mouse only) lifts the ticket 4px and rotates it -0.6°.
3. Tear: the stub's transform origin is bottom-left; it moves (30px, 80px) and rotates 28° with an accelerating curve (900ms) and fades out after 400ms.
## Touch
No hover lift; tap the button.
## Accessibility
- The main part is an <article> labelled with the event; details use <dl>; the barcode SVG has role="img" and a label.
- Status region announces "Ticket saved to wallet".
- prefers-reduced-motion: stub fades instead of tearing, no hover lift.
## Props
event, date, time, venue, seat ({ label, value }[]), code, theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### EventTicket.tsx
```tsx
"use client";
import { useMemo, useState, type ReactElement } from "react";
import "./event-ticket.css";
type EventTicketProps = {
event: string;
date: string;
time: string;
venue: string;
seat: { label: string; value: string }[];
code: string;
theme?: "light" | "dark";
};
/** A deterministic, decorative barcode: bar widths come from the ticket code. */
function bars(code: string) {
return code
.split("")
.flatMap((ch) => {
const n = ch.charCodeAt(0);
return [1 + (n % 3), 1 + ((n >> 2) % 2), 1 + ((n >> 3) % 3)];
})
.slice(0, 42);
}
/**
* EventTicket
* - The notches and the perforated line are made with CSS masks (no images).
* - "Add to wallet" tears the stub off: it rotates and drops away, then the button confirms.
*/
export function EventTicket({
event,
date,
time,
venue,
seat,
code,
theme = "light",
}: EventTicketProps) {
const [torn, setTorn] = useState(false);
const widths = useMemo(() => bars(code), [code]);
return (
<div className="gu-ticket" data-theme={theme} data-torn={torn || undefined}>
<article className="gu-ticket__main" aria-label={`Ticket for ${event}`}>
<p className="gu-ticket__kicker">Admit one</p>
<h3>{event}</h3>
<dl className="gu-ticket__grid">
<div>
<dt>Date</dt>
<dd>{date}</dd>
</div>
<div>
<dt>Doors</dt>
<dd>{time}</dd>
</div>
<div className="gu-ticket__wide">
<dt>Venue</dt>
<dd>{venue}</dd>
</div>
{seat.map((s) => (
<div key={s.label}>
<dt>{s.label}</dt>
<dd>{s.value}</dd>
</div>
))}
</dl>
<button
type="button"
className="gu-ticket__btn"
onClick={() => setTorn(true)}
disabled={torn}
>
{torn ? "Saved to wallet" : "Add to wallet"}
</button>
<p className="gu-ticket__sr" role="status">
{torn ? "Ticket saved to wallet" : ""}
</p>
</article>
<div className="gu-ticket__stub" aria-hidden={torn}>
<svg
className="gu-ticket__code"
viewBox={`0 0 ${widths.reduce((a, b) => a + b + 1, 0)} 40`}
preserveAspectRatio="none"
role="img"
aria-label={`Barcode ${code}`}
>
{
widths.reduce<{ x: number; els: ReactElement[] }>(
(acc, w, i) => {
if (i % 2 === 0)
acc.els.push(
<rect key={i} x={acc.x} y="0" width={w} height="40" />,
);
acc.x += w + 1;
return acc;
},
{ x: 0, els: [] },
).els
}
</svg>
<p className="gu-ticket__num">{code}</p>
</div>
</div>
);
}
```
### event-ticket.css
```css
/* EventTicket: change these colors to match your brand. */
.gu-ticket {
--paper: #ff5a1f; /* main part */
--ink: #0e0e10;
--stub: #0e0e10; /* tear-off stub */
--stub-ink: #f3eee3;
--ok: #d7ff3a;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
container-type: inline-size;
display: flex;
width: min(100%, 560px);
font-family: system-ui, sans-serif;
filter: drop-shadow(0 22px 26px rgb(14 14 16 / 0.28));
transition: transform 0.4s var(--ease);
}
.gu-ticket[data-theme="dark"] {
--stub: #f3eee3;
--stub-ink: #0e0e10;
--focus: #d7ff3a;
}
@media (hover: hover) {
.gu-ticket:hover {
transform: translateY(-4px) rotate(-0.6deg);
}
}
/* Main part: notches cut out of the right corners with a radial mask */
.gu-ticket__main {
flex: 1;
padding: 24px 26px;
border-radius: 18px 0 0 18px;
background: var(--paper);
color: var(--ink);
-webkit-mask:
radial-gradient(circle 12px at 100% 0, transparent 98%, #000) top / 100% 51%
no-repeat,
radial-gradient(circle 12px at 100% 100%, transparent 98%, #000) bottom /
100% 51% no-repeat;
mask:
radial-gradient(circle 12px at 100% 0, transparent 98%, #000) top / 100% 51%
no-repeat,
radial-gradient(circle 12px at 100% 100%, transparent 98%, #000) bottom /
100% 51% no-repeat;
}
.gu-ticket__kicker {
margin: 0;
font-size: 0.75rem;
font-weight: 800;
}
.gu-ticket h3 {
margin: 6px 0 16px;
font-size: clamp(1.6rem, 7cqi, 2.4rem);
font-weight: 900;
line-height: 0.95;
letter-spacing: -0.045em;
}
.gu-ticket__grid {
display: grid;
grid-template-columns: repeat(3, auto);
gap: 10px 18px;
margin: 0;
}
.gu-ticket__wide {
grid-column: span 3;
}
.gu-ticket dt {
font-size: 0.7rem;
font-weight: 700;
opacity: 0.7;
}
.gu-ticket dd {
margin: 2px 0 0;
font-size: 0.95rem;
font-weight: 800;
}
.gu-ticket__btn {
margin-top: 18px;
min-height: 44px;
padding: 0 18px;
border: 0;
border-radius: 999px;
background: var(--ink);
color: var(--paper);
font: inherit;
font-weight: 800;
cursor: pointer;
transition:
background-color 0.3s,
color 0.3s;
}
.gu-ticket__btn:disabled {
background: var(--ok);
color: #0e0e10;
cursor: default;
}
.gu-ticket__btn:focus-visible {
outline: 2px solid var(--focus);
outline-offset: 3px;
}
/* Stub: notches on the left + a dashed perforation */
.gu-ticket__stub {
display: flex;
flex: none;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
width: 132px;
padding: 20px 16px;
border-radius: 0 18px 18px 0;
background: var(--stub);
background-image: linear-gradient(var(--paper) 50%, transparent 0);
background-size: 2px 12px;
background-repeat: repeat-y;
background-position: 0 0;
color: var(--stub-ink);
-webkit-mask:
radial-gradient(circle 12px at 0 0, transparent 98%, #000) top / 100% 51%
no-repeat,
radial-gradient(circle 12px at 0 100%, transparent 98%, #000) bottom / 100%
51% no-repeat;
mask:
radial-gradient(circle 12px at 0 0, transparent 98%, #000) top / 100% 51%
no-repeat,
radial-gradient(circle 12px at 0 100%, transparent 98%, #000) bottom / 100%
51% no-repeat;
transform-origin: 0 100%;
transition:
transform 0.9s cubic-bezier(0.55, 0, 0.8, 0.4),
opacity 0.6s 0.4s;
}
.gu-ticket__code {
width: 100%;
height: 90px;
fill: currentColor;
}
.gu-ticket__num {
margin: 0;
font:
700 0.72rem ui-monospace,
monospace;
letter-spacing: 0.08em;
}
.gu-ticket[data-torn] .gu-ticket__stub {
transform: translate(30px, 80px) rotate(28deg);
opacity: 0;
}
.gu-ticket__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@container (max-width: 440px) {
.gu-ticket__grid {
grid-template-columns: repeat(2, auto);
}
.gu-ticket__wide {
grid-column: span 2;
}
.gu-ticket__stub {
width: 96px;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-ticket,
.gu-ticket:hover {
transform: none;
transition: none;
}
.gu-ticket__stub,
.gu-ticket[data-torn] .gu-ticket__stub {
transform: none;
transition: opacity 0.3s;
}
}
```
You might also want
Next piece: Expanding image accordionEmpty states set
Components, beginner
3D tilt card
Components, intermediate
Copy field
Components, beginner