Card
Soft or outline hairline cards with an optional bottom glow, plus a white inset panel for rows.
Render exactly the page you need
Every option is one parameter.
Block ads
Viewport
1440 × 900Outline card
White with a hairline, for pricing, settings and forms.
Install
$ npx shadcn@latest add @nudgekit/cardOr with no config: npx shadcn@latest add https://ui.nudgekit.app/r/card.json
Brings in class-variance-authority, and the theme.
Usage
usage.tsx
import { Card, CardTitle, CardDescription, CardPanel, CardRow } from "@/components/ui/card"
<Card glow={2}>
<CardTitle>Render exactly the page you need</CardTitle>
<CardDescription>Every option is one parameter.</CardDescription>
<CardPanel>
<CardRow>Block ads <Switch defaultChecked /></CardRow>
</CardPanel>
</Card>
<Card variant="outline">…</Card>Do
- Use soft cards for features and outline cards for settings and pricing.
- Use glow only on soft feature cards.
Don't
- Add a shadow to a card.
- Lift a card on hover.
Code
What the CLI writes into your project. It is yours to change.
components/ui/card.tsx
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const cardVariants = cva("relative overflow-hidden rounded-card border border-border p-6", {
variants: {
variant: {
/** Soft grey fill. The default for feature cards. */
soft: "bg-surface",
/** White with a hairline. For pricing, settings and anything that holds controls. */
outline: "bg-card",
},
},
defaultVariants: { variant: "soft" },
});
const glowColor = { 1: "var(--glow-1)", 2: "var(--glow-2)", 3: "var(--glow-3)" } as const;
export interface CardProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof cardVariants> {
/** Fades one of the three glow colours up from the bottom of a soft card. */
glow?: 1 | 2 | 3;
}
/** A hairline card with no shadow. */
function Card({ className, variant, glow, children, ...props }: CardProps) {
return (
<div data-slot="card" className={cn(cardVariants({ variant }), className)} {...props}>
{glow && (
<div
aria-hidden
className="pointer-events-none absolute inset-x-0 bottom-0 h-[55%] opacity-55"
style={{ background: `linear-gradient(to top, ${glowColor[glow]}, transparent)` }}
/>
)}
<div className="relative">{children}</div>
</div>
);
}
function CardTitle({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) {
return <h3 data-slot="card-title" className={cn("text-xl font-medium leading-snug tracking-[-0.02em] text-foreground", className)} {...props} />;
}
function CardDescription({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {
return <p data-slot="card-description" className={cn("mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground", className)} {...props} />;
}
/** A white inset panel inside a soft card, for rows of settings or files. */
function CardPanel({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return <div data-slot="card-panel" className={cn("mt-6 rounded-xl border border-border bg-card px-4 py-1", className)} {...props} />;
}
/** One row inside a CardPanel: label on the left, control or value on the right. */
function CardRow({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
data-slot="card-row"
className={cn("flex items-center justify-between gap-4 border-b border-border py-3 text-sm last:border-0", className)}
{...props}
/>
);
}
export { Card, CardTitle, CardDescription, CardPanel, CardRow, cardVariants };