A theme-aware receipt with cutouts, clear details, and composable payment, barcode, and action areas.
Default
You're on the list!
- Ticket number
- 204800618
- Amount paid
- $35.00
- Date & time
Alex Morgan
Mastercard · ending in 8237
Purpose
A ticket card presents event details and access information together so people can find what they need at a glance.
Parts & Composition
Order: Header → Content → optional Stub (barcode, footer). Omit stub for a flat receipt; content closes the bottom border when last.
| Part | Role | Notes |
|---|---|---|
TicketCard | article | texture; padding on parts via className |
TicketCardHeader | header | Optional mesh |
TicketCardDetails / Detail / Label / Value | dl grid | span={2} on detail |
TicketCardPayment | summary | Consumer content |
TicketCardStub / Footer / Barcode | stub region | Optional |
TicketBarcode | Code 128 | value, showValue |
Link title with aria-labelledby or aria-label. TicketCardTitle as sets heading level (default h3). Root title is the native tooltip.
API & Props
| Prop | Purpose |
|---|---|
texture | paper / none |
mesh on Header | { colors: [3], opacity? } (clamped 0–1) |
Parts forward native props, className, style, ref.
Theming, Layout & Responsiveness
Card, border, primary, radius tokens. texture="paper" adds grain (CSS variable overridable).
Fluid to max-w-sm. Consistent gap inside content and stub.
Motion & Accessibility
Optional icon lift and payment reflection on hover/focus-within. Reduced motion respected.
Valid Code 128 for TicketBarcode, or supply your own graphic in TicketCardBarcode. Payment credentials stay out of barcodes meant for scanning.
Guidance for Coding Agents
Compose the ticket regions and supply real event and access details. Keep the perforation and other visual details in the component. Use named controls for download or reveal actions, and protect sensitive ticket data.
Pass a valid Code 128 string to TicketBarcode (or supply a custom SVG/image inside TicketCardBarcode). Keep payment credentials out of the barcode.
Start from the closest Preview → Usage example and use this page’s API table for component parts and options.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/ticket-cardimport { cva } from 'class-variance-authority';
import JsBarcode from 'jsbarcode';
import type { ComponentProps, CSSProperties } from 'react';
import { controlTextSizes, type StandardControlSize } from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const ticketCardSizes = cva(
'group/ticket isolate w-full min-w-0 text-card-foreground drop-shadow-sm [--ticket-paper-grain:var(--ticket-paper-grain-light)] dark:[--ticket-paper-grain:var(--ticket-paper-grain-dark)]',
{
variants: {
size: {
xs: `max-w-xs ${controlTextSizes.xs}`,
sm: `max-w-xs ${controlTextSizes.sm}`,
md: `max-w-sm ${controlTextSizes.md}`,
lg: `max-w-md ${controlTextSizes.lg}`,
} satisfies Record<StandardControlSize, string>,
},
defaultVariants: { size: 'md' },
},
);
type TicketCardProps = ComponentProps<'article'> & {
size?: StandardControlSize;
texture?: 'paper' | 'none';
};
type TicketCardHeaderProps = ComponentProps<'header'> & {
mesh?: { colors: readonly [string, string, string]; opacity?: number };
};
function createPaperGrain(opacity: number) {
return `url("data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160" viewBox="0 0 160 160"><filter id="paper" x="0" y="0" width="100%" height="100%"><feTurbulence type="fractalNoise" baseFrequency=".75 .45" numOctaves="3" stitchTiles="stitch"/><feColorMatrix type="saturate" values="0"/></filter><path d="M0 0h160v160H0z" filter="url(#paper)" opacity="${opacity}"/></svg>`,
)}")`;
}
const lightPaperGrain = createPaperGrain(0.18);
const darkPaperGrain = createPaperGrain(0.09);
/** Native, server-compatible root. Compose the receipt content directly. */
function TicketCard({
size = 'md',
texture = 'paper',
className,
style,
...props
}: TicketCardProps) {
return (
<article
{...props}
data-slot="ticket-card"
data-size={size}
data-texture={texture}
style={
{
'--ticket-paper-grain-light': texture === 'paper' ? lightPaperGrain : 'none',
'--ticket-paper-grain-dark': texture === 'paper' ? darkPaperGrain : 'none',
...style,
} as CSSProperties
}
className={cn(ticketCardSizes({ size }), className)}
/>
);
}
function TicketCardHeader({ mesh, className, children, ...props }: TicketCardHeaderProps) {
return (
<header
{...props}
data-slot="ticket-card-header"
className={cn(
'relative isolate rounded-t-lg border border-b-0 border-border bg-card bg-[image:var(--ticket-paper-grain)] bg-size-[160px_160px] text-center',
'[mask-image:radial-gradient(circle_at_0_100%,transparent_10px,#000_10.5px),radial-gradient(circle_at_100%_100%,transparent_10px,#000_10.5px)] [mask-composite:intersect]',
'px-6 pt-8 pb-9 md:px-7',
className,
)}
>
{mesh && (
<span
aria-hidden="true"
data-slot="ticket-card-mesh"
className="pointer-events-none absolute inset-0 -z-10 rounded-[inherit] [mask-image:linear-gradient(#000_0%,#000_55%,transparent_100%)]"
style={{
backgroundImage: `radial-gradient(ellipse at 12% 0%, ${mesh.colors[0]} 0%, transparent 65%), radial-gradient(ellipse at 90% 10%, ${mesh.colors[1]} 0%, transparent 65%), radial-gradient(ellipse at 50% 70%, ${mesh.colors[2]} 0%, transparent 65%)`,
opacity: Number.isFinite(mesh.opacity ?? 0.18)
? Math.min(1, Math.max(0, mesh.opacity ?? 0.18))
: 0.18,
}}
/>
)}
{children}
<span
aria-hidden="true"
className="absolute inset-x-[18%] bottom-0 h-px bg-[repeating-linear-gradient(to_right,var(--muted-foreground)_0_4px,transparent_4px_10px)] opacity-60"
/>
<span
aria-hidden="true"
className="pointer-events-none absolute -inset-x-px bottom-0 h-[11px] bg-[radial-gradient(circle_at_0_100%,transparent_10px,var(--border)_10px,var(--border)_11px,transparent_11px),radial-gradient(circle_at_100%_100%,transparent_10px,var(--border)_10px,var(--border)_11px,transparent_11px)]"
/>
</header>
);
}
function TicketCardIcon({ className, ...props }: ComponentProps<'div'>) {
return (
<div
aria-hidden="true"
{...props}
data-slot="ticket-card-icon"
className={cn(
'mx-auto mb-4 flex size-12 items-center justify-center text-primary [&>svg]:size-14 transition-transform duration-200 ease-out motion-safe:group-hover/ticket:-translate-y-0.5 motion-safe:group-focus-within/ticket:-translate-y-0.5 motion-reduce:transition-none',
className,
)}
/>
);
}
function TicketCardTitle({
as: Heading = 'h3',
className,
...props
}: ComponentProps<'h3'> & { as?: 'h2' | 'h3' | 'h4' }) {
return (
<Heading
{...props}
data-slot="ticket-card-title"
className={cn('m-0 break-words text-xl font-semibold tracking-tight', className)}
/>
);
}
function TicketCardDescription({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="ticket-card-description"
className={cn(
'mx-auto mt-1 max-w-[28ch] break-words text-sm leading-relaxed text-muted-foreground',
className,
)}
/>
);
}
function TicketCardContent({ className, children, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="ticket-card-body"
className={cn(
'relative flex min-w-0 flex-col gap-6 border-x border-border bg-card bg-[image:var(--ticket-paper-grain)] bg-size-[160px_160px]',
'[mask-image:radial-gradient(circle_at_0_0,transparent_10px,#000_10.5px),radial-gradient(circle_at_100%_0,transparent_10px,#000_10.5px)] [mask-composite:intersect]',
'p-6 last:rounded-b-lg last:border-b',
className,
)}
>
<span
aria-hidden="true"
className="pointer-events-none absolute -inset-x-px top-0 h-[11px] bg-[radial-gradient(circle_at_0_0,transparent_10px,var(--border)_10px,var(--border)_11px,transparent_11px),radial-gradient(circle_at_100%_0,transparent_10px,var(--border)_10px,var(--border)_11px,transparent_11px)]"
/>
{children}
</div>
);
}
function TicketCardDetails({ className, ...props }: ComponentProps<'dl'>) {
return (
<dl
{...props}
data-slot="ticket-card-details"
className={cn('m-0 grid min-w-0 grid-cols-2 gap-x-5 gap-y-5', className)}
/>
);
}
function TicketCardDetail({
span = 1,
className,
...props
}: ComponentProps<'div'> & { span?: 1 | 2 }) {
return (
<div
{...props}
data-slot="ticket-card-detail"
className={cn('min-w-0', span === 2 && 'col-span-2', className)}
/>
);
}
function TicketCardLabel({ className, ...props }: ComponentProps<'dt'>) {
return (
<dt
{...props}
data-slot="ticket-card-label"
className={cn(
'break-words text-xs font-medium uppercase leading-relaxed tracking-wider text-muted-foreground',
className,
)}
/>
);
}
function TicketCardValue({ className, ...props }: ComponentProps<'dd'>) {
return (
<dd
{...props}
data-slot="ticket-card-value"
className={cn(
'm-0 mt-1 break-words text-sm font-medium leading-relaxed tabular-nums [overflow-wrap:anywhere]',
className,
)}
/>
);
}
function TicketCardPayment({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="ticket-card-payment"
className={cn(
'flex min-w-0 items-center gap-3 rounded-lg border border-border/50 ring-2 ring-border/20 bg-muted/50 p-3 text-sm [&>svg]:size-7 [&>svg]:shrink-0',
'relative isolate overflow-hidden shadow-[inset_0_1px_0_rgb(255_255_255/0.14),inset_0_-1px_0_rgb(0_0_0/0.04)]',
'before:pointer-events-none before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:bg-linear-to-br before:from-white/20 before:via-transparent before:to-black/5 dark:before:from-white/8 dark:before:to-black/10',
'after:pointer-events-none after:absolute after:inset-y-[-40%] after:start-0 after:-z-10 after:w-2/3 after:-translate-x-[150%] after:-skew-x-20 after:bg-linear-to-r after:from-transparent after:via-white/30 after:to-transparent after:transition-transform after:duration-700 after:ease-out dark:after:via-white/12 motion-safe:group-hover/ticket:after:translate-x-[180%] motion-safe:group-focus-within/ticket:after:translate-x-[180%] motion-reduce:after:hidden motion-reduce:after:transition-none',
className,
)}
/>
);
}
function TicketCardStub({ className, children, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="ticket-card-stub"
className={cn(
'relative flex min-w-0 flex-col gap-6 rounded-b-lg border-x border-b border-border bg-card bg-[image:var(--ticket-paper-grain)] bg-size-[160px_160px] px-5 pt-5 pb-7',
'[mask-image:radial-gradient(circle_at_50%_100%,transparent_10px,#000_10.5px)] [mask-size:40px_100%] [mask-position:center] [mask-repeat:repeat-x]',
className,
)}
>
<span
aria-hidden="true"
className="pointer-events-none absolute -inset-x-px -bottom-px h-[11px] bg-[radial-gradient(circle_at_50%_100%,transparent_10px,var(--border)_10px,var(--border)_11px,transparent_11px)] bg-size-[40px_100%] bg-center bg-repeat-x"
/>
<span
aria-hidden="true"
className="absolute inset-x-0 top-0 h-[3px] bg-[repeating-linear-gradient(to_right,var(--muted)_0_22px,transparent_22px_28px)]"
/>
{children}
</div>
);
}
function TicketCardBarcode({ className, ...props }: ComponentProps<'div'>) {
return (
<div
{...props}
data-slot="ticket-card-barcode"
className={cn(
'mx-auto min-w-0 max-w-full [&>svg]:mx-auto [&>svg]:h-auto [&>svg]:max-w-full [&>img]:mx-auto [&>img]:h-auto [&>img]:max-w-full',
className,
)}
/>
);
}
function TicketCardFooter({ className, ...props }: ComponentProps<'footer'>) {
return (
<footer
{...props}
data-slot="ticket-card-footer"
className={cn(
'flex min-w-0 flex-wrap items-center justify-center gap-2 [&>*]:max-w-full',
className,
)}
/>
);
}
type TicketBarcodeProps = Omit<ComponentProps<'figure'>, 'children'> & {
/** The actual identifier to encode as Code 128, not a decorative label. */
value: string;
showValue?: boolean;
};
/** JsBarcode supplies the encoding; React renders it without DOM mutation or a client effect. */
function TicketBarcode({ value, showValue = true, className, ...props }: TicketBarcodeProps) {
const target: { encodings?: { data: string }[] } = {};
// JsBarcode documents object output, but its community types only declare DOM targets.
const encode = JsBarcode as unknown as (
output: typeof target,
text: string,
options: { format: string; displayValue: boolean },
) => void;
encode(target, value, { format: 'CODE128', displayValue: false });
const bits = target.encodings?.map((encoding) => encoding.data).join('');
if (!bits) throw new Error('TicketBarcode requires a nonempty Code 128-compatible value.');
const quietZone = 10;
const barHeight = 36;
const paths: string[] = [];
for (let start = 0; start < bits.length; ) {
if (bits[start] !== '1') {
start += 1;
continue;
}
let end = start + 1;
while (bits[end] === '1') end += 1;
const width = end - start;
paths.push(`M${start + quietZone} 0h${width}v${barHeight}h-${width}Z`);
start = end;
}
return (
<figure
{...props}
aria-label={props['aria-label'] ?? `Code 128 barcode: ${value}`}
data-slot="ticket-barcode"
className={cn(
'm-0 mx-auto w-fit max-w-full rounded-lg p-3 text-foreground',
'opacity-100 blur-none transition-[opacity,filter] duration-500 ease-out starting:opacity-0 motion-safe:starting:blur-[6px] motion-reduce:transition-none motion-reduce:starting:opacity-100 motion-reduce:starting:blur-none',
className,
)}
>
<svg
aria-hidden="true"
viewBox={`0 0 ${bits.length + quietZone * 2} ${barHeight}`}
width={(bits.length + quietZone * 2) * 2}
className="block h-auto max-w-full"
shapeRendering="crispEdges"
>
<path fill="currentColor" d={paths.join('')} />
</svg>
{showValue && (
<figcaption
aria-hidden="true"
className="mt-2 break-words text-center font-mono text-xs tracking-[0.18em] [overflow-wrap:anywhere]"
>
{value}
</figcaption>
)}
</figure>
);
}
export type { TicketBarcodeProps, TicketCardHeaderProps, TicketCardProps };
export {
TicketBarcode,
TicketCard,
TicketCardBarcode,
TicketCardContent,
TicketCardDescription,
TicketCardDetail,
TicketCardDetails,
TicketCardFooter,
TicketCardHeader,
TicketCardIcon,
TicketCardLabel,
TicketCardPayment,
TicketCardStub,
TicketCardTitle,
TicketCardValue,
};
import { cn } from '@/lib/utils';
type ClassValue = string | false | null | undefined;
type PartClassValue<State> = ClassValue | ((state: State) => ClassValue);
/** Composes static class names and UI-SDK state class functions into a single `className` prop. */
export function partClass<State>(...parts: PartClassValue<State>[]) {
if (parts.some((part) => typeof part === 'function')) {
return (state: State) =>
cn(...parts.map((part) => (typeof part === 'function' ? part(state) : part)));
}
return cn(...(parts as ClassValue[]));
}
export const surfacePadding = 'p-1 [--surface-padding:1.5rem] [--concentric-inset:0.25rem]';
export const surfaceRegionInset = 'p-[calc(var(--surface-padding,1rem)-0.5rem)]';
export const surfaceHeaderRadius = 'rounded-t-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
export const surfaceFooterRadius = 'rounded-b-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
/** Concentric inner radius (`outer - inset`); set `[--concentric-inset:0.125rem]` on `p-0.5` rails (defaults to `0.25rem` for `p-1`). */
export const concentricRadius =
'rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))]';
export const surfaceBodyPadding =
'py-[max(0px,calc(var(--surface-padding,1rem)-1rem))] has-[>[data-slot=list]:not([data-variant=plain])]:p-0 has-[>[data-slot=list-items-container]]:p-0';
export type StandardControlSize = 'xs' | 'sm' | 'md' | 'lg';
/** Standard control heights (`28px / 32px / 40px / 48px`) for buttons, inputs, selects, tabs, and sliders. */
export const controlHeights = {
xs: 'h-7',
sm: 'h-8',
md: 'h-10',
lg: 'h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard minimum control heights (`28px / 32px / 40px / 48px`) for expandable controls and menu items. */
export const controlMinHeights = {
xs: 'min-h-7',
sm: 'min-h-8',
md: 'min-h-10',
lg: 'min-h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard control text sizes (`xs / xs / sm / base`) paired with `StandardControlSize`. */
export const controlTextSizes = {
xs: 'text-xs',
sm: 'text-xs',
md: 'text-sm',
lg: 'text-base',
} as const satisfies Record<StandardControlSize, string>;
/** Compact control heights (`1.25rem / 1.3rem / 1.625rem / 1.75rem`), one step smaller than standard, for switches and compact controls. */
export const compactControlHeights = {
xs: 'h-[1.3rem]',
sm: 'h-[1.4rem]',
md: 'h-[1.5rem]',
lg: 'h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Compact minimum control heights (`1rem / 1.25rem / 1.5rem / 1.75rem`) for badges and tooltips. */
export const compactControlMinHeights = {
xs: 'min-h-[1.3rem]',
sm: 'min-h-[1.4rem]',
md: 'min-h-[1.5rem]',
lg: 'min-h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Universal keyboard focus + invalid ring/border styles shared across controls. */
export const focusRing =
'touch-manipulation outline-none focus-visible:border-ring/30 transition-ring focus-visible:ring-3 focus-visible:ring-ring/15 focus-visible:brightness-[0.97] dark:focus-visible:brightness-[1.15] has-[:focus-visible]:border-ring/30 has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/15 has-[:focus-visible]:brightness-[0.97] dark:has-[:focus-visible]:brightness-[1.15] data-active:border-ring/30 data-active:ring-3 data-active:ring-ring/15 data-active:brightness-[0.97] dark:data-active:brightness-[1.15] data-open:border-ring/30 data-open:ring-3 data-open:ring-ring/15 data-open:brightness-[0.97] dark:data-open:brightness-[1.15] data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/25 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/25 has-[[data-invalid]]:border-destructive has-[[data-invalid]]:ring-3 has-[[data-invalid]]:ring-destructive/25 group-aria-invalid/control:border-destructive group-aria-invalid/control:ring-3 group-aria-invalid/control:ring-destructive/25 group-data-invalid/control:border-destructive group-data-invalid/control:ring-3 group-data-invalid/control:ring-destructive/25 group-has-[input[aria-invalid=true]]/control:border-destructive group-has-[input[aria-invalid=true]]/control:ring-3 group-has-[input[aria-invalid=true]]/control:ring-destructive/25 hover:brightness-[0.97] dark:hover:brightness-[1.15]';
/** Shared sliding highlight indicator base (pointer-safe, concentric inner radius inside rounded-lg containers, 200ms transition). */
export const slidingHighlight =
'pointer-events-none -z-10 rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))] bg-primary/10 [clip-path:inset(0px_round_max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem))))] transition-[transform,width,height,opacity] duration-200 ease-out motion-reduce:transition-none';
export const textFieldSurfaces = {
filled: 'border-input bg-card text-card-foreground',
outline: 'border-input bg-transparent text-foreground dark:bg-transparent',
ghost: 'border-transparent bg-muted text-foreground shadow-none',
underline:
'rounded-none border-0 border-b-2 border-input bg-transparent px-0 text-foreground shadow-none focus-visible:border-ring focus-visible:ring-0 aria-invalid:ring-0 data-invalid:ring-0 dark:bg-transparent',
} as const;
export const textFieldUnderlineMotion =
'border-transparent! bg-origin-border bg-bottom bg-no-repeat [--underline-color:var(--primary)] [background-image:linear-gradient(var(--underline-color),var(--underline-color)),linear-gradient(var(--input),var(--input))] [background-size:0%_2px,100%_2px] focus:[background-size:100%_2px,100%_2px] aria-invalid:[--underline-color:var(--destructive)] data-invalid:[--underline-color:var(--destructive)] transition-[border-color,background-color,box-shadow,filter,background-size] duration-200 motion-reduce:transition-none';
/** Generic balanced icon & floating-label layout tokens shared across all text-field sizes. */
export const textFieldLayout = {
icon: 'size-4',
iconStart: 'start-3',
iconEnd: 'end-3',
padStart: 'ps-9',
padEnd: 'pe-9',
underlinePadStart: 'ps-7',
underlinePadEnd: 'pe-7',
floatingStart: 'start-2.5',
floatingWithIcon: 'start-8',
floatingUnderlineIcon: 'start-6',
} as const;
export const textFieldLabelSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
/** Clamps per-grapheme wave delay (ms) so total staggering stays within 300ms. */
export function clampWaveDelay(waveDelay: number, count: number): number {
return Math.max(
0,
Math.min(Number.isFinite(waveDelay) ? waveDelay : 24, 80, 300 / Math.max(1, count - 1)),
);
}
/** Shared scale/color transition for floating labels inside a `group/field` wrapper. */
export const textFieldLabelMotion =
'inline-block origin-left backdrop-blur-xs transition-[scale,color] duration-200 ease-out group-has-[input:focus]/field:scale-85 group-has-[input:not(:placeholder-shown)]/field:scale-85 rtl:origin-right motion-reduce:transition-none';
/** Resolves start/end padding for a text field when a leading or trailing icon is present. */
export function getTextFieldIconPadding(iconPosition: 'start' | 'end', underline: boolean): string {
if (iconPosition === 'start') {
return underline ? textFieldLayout.underlinePadStart : textFieldLayout.padStart;
}
return underline ? textFieldLayout.underlinePadEnd : textFieldLayout.padEnd;
}
/** Shared per-grapheme ripple transition for wave labels inside a `group/field` wrapper. */
export const textFieldWaveMotion =
'inline-block origin-left backdrop-blur-xs transition-[translate,scale,color] duration-200 ease-out group-has-[input:focus]/field:-translate-y-5 group-has-[input:focus]/field:scale-85 group-has-[input:focus]/field:text-primary group-has-[input:not(:placeholder-shown)]/field:-translate-y-5 group-has-[input:not(:placeholder-shown)]/field:scale-85 group-has-[input[aria-invalid=true]]/field:text-destructive rtl:origin-right motion-reduce:transition-none';