~/components/fetch-card
Fetch Card
A neofetch-style info card: ASCII art, a user@host header, key / value rows and a palette strip, with lines that slide in and art that tilts towards the pointer.
███╗ ███╗██████╗ ██╗ ██╗ ████╗ ████║██╔══██╗██║ ██╔╝ ██╔████╔██║██████╔╝█████╔╝ ██║╚██╔╝██║██╔═══╝ ██╔═██╗ ██║ ╚═╝ ██║██║ ██║ ██╗ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
- os
- mpkcn 0.3 x86_64
- shell
- zsh 5.9
- stack
- Next.js · React · TypeScript
- theme
- dark (amber / blue)
- uptime
- 42 days
- status
- open to work
"use client";
import { MotionConfig, motion, type Variants } from "framer-motion";
import { useRef, useSyncExternalStore, type PointerEvent, type ReactNode } from "react";
export type FetchRow = {
/** Key on the left, in amber, e.g. "os". */
label: string;
/** Value on the right. */
value: ReactNode;
};
export type FetchCardProps = {
/** ASCII art on the left. A string is split into lines; any other node is shown as is. */
art?: ReactNode;
/** Accessible name for the art (e.g. the word it spells). Without it the art is hidden from screen readers. */
artLabel?: string;
/** Header user, shown as user@host. @default "guest" */
user?: string;
/** Header host, shown as user@host. @default "localhost" */
host?: string;
/** Replaces the user@host header. */
title?: ReactNode;
/** Key / value rows under the header. */
rows: FetchRow[];
/** Show the row of color swatches at the bottom, like neofetch. @default true */
palette?: boolean;
/** Accent of the art and header. @default "blue" */
tone?: "blue" | "amber";
/** Slide the art lines and rows in when the card scrolls into view. @default true */
animate?: boolean;
/** Tilt the art in 3D towards a mouse pointer. @default true */
tilt?: boolean;
/** Animate even when the user prefers reduced motion. Use only behind an explicit action. @default false */
ignoreReducedMotion?: boolean;
/** Extra classes for the root. */
className?: string;
/** Classes for the art (font size, line height). @default "text-[11px]" */
artClassName?: string;
};
const QUERY = "(prefers-reduced-motion: reduce)";
function subscribe(cb: () => void) {
const mq = window.matchMedia(QUERY);
mq.addEventListener("change", cb);
return () => mq.removeEventListener("change", cb);
}
function useReduced() {
return useSyncExternalStore(subscribe, () => window.matchMedia(QUERY).matches, () => false);
}
function cx(...parts: (string | false | undefined | null)[]): string {
return parts.filter(Boolean).join(" ");
}
const EASE = [0.22, 1, 0.36, 1] as const;
const list: Variants = { hidden: {}, show: { transition: { staggerChildren: 0.045 } } };
const line: Variants = {
hidden: { opacity: 0, x: -12 },
show: { opacity: 1, x: 0, transition: { duration: 0.35, ease: EASE } },
};
const SWATCHES = ["bg-mpk-bg", "bg-mpk-line", "bg-mpk-dim2", "bg-mpk-dim", "bg-mpk-ink", "bg-mpk-amber", "bg-mpk-blue"];
/**
* A neofetch-style info card: ASCII art on the left, a user@host header, then
* key / value rows and a palette strip. Lines slide in when the card scrolls
* into view and the art tilts towards the mouse; under reduced motion it is
* still. Wraps to one column when narrow.
*/
export function FetchCard({
art,
artLabel,
user = "guest",
host = "localhost",
title,
rows,
palette = true,
tone = "blue",
animate = true,
tilt = true,
ignoreReducedMotion = false,
className,
artClassName,
}: FetchCardProps) {
const reduced = useReduced() && !ignoreReducedMotion;
const artRef = useRef<HTMLElement | null>(null);
const setArt = (el: HTMLElement | null) => {
artRef.current = el;
};
const accent = tone === "blue" ? "text-mpk-blue" : "text-mpk-amber";
const onMove = (e: PointerEvent<HTMLDivElement>) => {
const el = artRef.current;
if (!tilt || reduced || !el || e.pointerType !== "mouse") return;
const r = e.currentTarget.getBoundingClientRect();
const px = (e.clientX - r.left) / r.width - 0.5;
const py = (e.clientY - r.top) / r.height - 0.5;
el.style.transform = `rotateX(${(-py * 20).toFixed(2)}deg) rotateY(${(px * 26).toFixed(2)}deg)`;
};
const onLeave = () => {
if (artRef.current) artRef.current.style.transform = "";
};
const show = animate ? { initial: "hidden", whileInView: "show", viewport: { once: true, amount: 0.2 } } : {};
const variants = animate ? line : undefined;
const artA11y = artLabel ? { role: "img" as const, "aria-label": artLabel } : { "aria-hidden": true as const };
return (
<MotionConfig reducedMotion={ignoreReducedMotion ? "never" : "user"}>
<div
className={cx(
"flex w-full flex-wrap items-center gap-x-8 gap-y-5 font-mpk-mono text-[13px] leading-relaxed text-mpk-ink",
className,
)}
>
{art !== undefined && art !== null && (
<div className="[perspective:700px]" onPointerMove={onMove} onPointerLeave={onLeave}>
{typeof art === "string" ? (
<motion.pre
ref={setArt}
{...artA11y}
variants={animate ? list : undefined}
{...show}
className={cx(
"m-0 leading-[1.05] whitespace-pre transition-transform duration-150 ease-out [transform-style:preserve-3d]",
accent,
artClassName ?? "text-[11px]",
)}
>
{art.replace(/^\n+|\n+$/g, "").split("\n").map((l, i) => (
<motion.span key={i} variants={variants} className="block">
{l || " "}
</motion.span>
))}
</motion.pre>
) : (
<div
ref={setArt}
{...artA11y}
className={cx("transition-transform duration-150 ease-out [transform-style:preserve-3d]", accent, artClassName)}
>
{art}
</div>
)}
</div>
)}
<motion.div className="min-w-0 flex-1 basis-56" variants={animate ? list : undefined} {...show}>
<motion.div variants={variants} className="font-bold break-words">
{title ?? (
<>
<span className={accent}>{user}</span>
<span className="text-mpk-dim">@</span>
<span className={accent}>{host}</span>
</>
)}
</motion.div>
<motion.div variants={variants} aria-hidden="true" className="my-1.5 h-px bg-mpk-line" />
<dl className="m-0">
{rows.map((r, i) => (
<motion.div key={`${r.label}-${i}`} variants={variants} className="flex gap-3">
<dt className="w-[8ch] shrink-0 truncate text-mpk-amber">{r.label}</dt>
<dd className="m-0 min-w-0 break-words">{r.value}</dd>
</motion.div>
))}
</dl>
{palette && (
<motion.div variants={variants} aria-hidden="true" className="mt-3 flex">
{SWATCHES.map((s) => (
<span key={s} className={cx("h-3.5 w-6 border border-mpk-line", s)} />
))}
</motion.div>
)}
</motion.div>
</div>
</MotionConfig>
);
}Installation
npx mpkcn add fetch-card01Install the dependencies
npm i framer-motion02Add mpkcn-theme.css if you haven't yet (see Installation)
03Copy the source into your components folder
"use client";
import { MotionConfig, motion, type Variants } from "framer-motion";
import { useRef, useSyncExternalStore, type PointerEvent, type ReactNode } from "react";
export type FetchRow = {
/** Key on the left, in amber, e.g. "os". */
label: string;
/** Value on the right. */
value: ReactNode;
};
export type FetchCardProps = {
/** ASCII art on the left. A string is split into lines; any other node is shown as is. */
art?: ReactNode;
/** Accessible name for the art (e.g. the word it spells). Without it the art is hidden from screen readers. */
artLabel?: string;
/** Header user, shown as user@host. @default "guest" */
user?: string;
/** Header host, shown as user@host. @default "localhost" */
host?: string;
/** Replaces the user@host header. */
title?: ReactNode;
/** Key / value rows under the header. */
rows: FetchRow[];
/** Show the row of color swatches at the bottom, like neofetch. @default true */
palette?: boolean;
/** Accent of the art and header. @default "blue" */
tone?: "blue" | "amber";
/** Slide the art lines and rows in when the card scrolls into view. @default true */
animate?: boolean;
/** Tilt the art in 3D towards a mouse pointer. @default true */
tilt?: boolean;
/** Animate even when the user prefers reduced motion. Use only behind an explicit action. @default false */
ignoreReducedMotion?: boolean;
/** Extra classes for the root. */
className?: string;
/** Classes for the art (font size, line height). @default "text-[11px]" */
artClassName?: string;
};
const QUERY = "(prefers-reduced-motion: reduce)";
function subscribe(cb: () => void) {
const mq = window.matchMedia(QUERY);
mq.addEventListener("change", cb);
return () => mq.removeEventListener("change", cb);
}
function useReduced() {
return useSyncExternalStore(subscribe, () => window.matchMedia(QUERY).matches, () => false);
}
function cx(...parts: (string | false | undefined | null)[]): string {
return parts.filter(Boolean).join(" ");
}
const EASE = [0.22, 1, 0.36, 1] as const;
const list: Variants = { hidden: {}, show: { transition: { staggerChildren: 0.045 } } };
const line: Variants = {
hidden: { opacity: 0, x: -12 },
show: { opacity: 1, x: 0, transition: { duration: 0.35, ease: EASE } },
};
const SWATCHES = ["bg-mpk-bg", "bg-mpk-line", "bg-mpk-dim2", "bg-mpk-dim", "bg-mpk-ink", "bg-mpk-amber", "bg-mpk-blue"];
/**
* A neofetch-style info card: ASCII art on the left, a user@host header, then
* key / value rows and a palette strip. Lines slide in when the card scrolls
* into view and the art tilts towards the mouse; under reduced motion it is
* still. Wraps to one column when narrow.
*/
export function FetchCard({
art,
artLabel,
user = "guest",
host = "localhost",
title,
rows,
palette = true,
tone = "blue",
animate = true,
tilt = true,
ignoreReducedMotion = false,
className,
artClassName,
}: FetchCardProps) {
const reduced = useReduced() && !ignoreReducedMotion;
const artRef = useRef<HTMLElement | null>(null);
const setArt = (el: HTMLElement | null) => {
artRef.current = el;
};
const accent = tone === "blue" ? "text-mpk-blue" : "text-mpk-amber";
const onMove = (e: PointerEvent<HTMLDivElement>) => {
const el = artRef.current;
if (!tilt || reduced || !el || e.pointerType !== "mouse") return;
const r = e.currentTarget.getBoundingClientRect();
const px = (e.clientX - r.left) / r.width - 0.5;
const py = (e.clientY - r.top) / r.height - 0.5;
el.style.transform = `rotateX(${(-py * 20).toFixed(2)}deg) rotateY(${(px * 26).toFixed(2)}deg)`;
};
const onLeave = () => {
if (artRef.current) artRef.current.style.transform = "";
};
const show = animate ? { initial: "hidden", whileInView: "show", viewport: { once: true, amount: 0.2 } } : {};
const variants = animate ? line : undefined;
const artA11y = artLabel ? { role: "img" as const, "aria-label": artLabel } : { "aria-hidden": true as const };
return (
<MotionConfig reducedMotion={ignoreReducedMotion ? "never" : "user"}>
<div
className={cx(
"flex w-full flex-wrap items-center gap-x-8 gap-y-5 font-mpk-mono text-[13px] leading-relaxed text-mpk-ink",
className,
)}
>
{art !== undefined && art !== null && (
<div className="[perspective:700px]" onPointerMove={onMove} onPointerLeave={onLeave}>
{typeof art === "string" ? (
<motion.pre
ref={setArt}
{...artA11y}
variants={animate ? list : undefined}
{...show}
className={cx(
"m-0 leading-[1.05] whitespace-pre transition-transform duration-150 ease-out [transform-style:preserve-3d]",
accent,
artClassName ?? "text-[11px]",
)}
>
{art.replace(/^\n+|\n+$/g, "").split("\n").map((l, i) => (
<motion.span key={i} variants={variants} className="block">
{l || " "}
</motion.span>
))}
</motion.pre>
) : (
<div
ref={setArt}
{...artA11y}
className={cx("transition-transform duration-150 ease-out [transform-style:preserve-3d]", accent, artClassName)}
>
{art}
</div>
)}
</div>
)}
<motion.div className="min-w-0 flex-1 basis-56" variants={animate ? list : undefined} {...show}>
<motion.div variants={variants} className="font-bold break-words">
{title ?? (
<>
<span className={accent}>{user}</span>
<span className="text-mpk-dim">@</span>
<span className={accent}>{host}</span>
</>
)}
</motion.div>
<motion.div variants={variants} aria-hidden="true" className="my-1.5 h-px bg-mpk-line" />
<dl className="m-0">
{rows.map((r, i) => (
<motion.div key={`${r.label}-${i}`} variants={variants} className="flex gap-3">
<dt className="w-[8ch] shrink-0 truncate text-mpk-amber">{r.label}</dt>
<dd className="m-0 min-w-0 break-words">{r.value}</dd>
</motion.div>
))}
</dl>
{palette && (
<motion.div variants={variants} aria-hidden="true" className="mt-3 flex">
{SWATCHES.map((s) => (
<span key={s} className={cx("h-3.5 w-6 border border-mpk-line", s)} />
))}
</motion.div>
)}
</motion.div>
</div>
</MotionConfig>
);
}04Update the import paths to match your project
Usage
Pass ASCII art and the rows. The header reads user@host.
import { FetchCard } from "@/components/mpkcn/fetch-card";
const ART = `
/\\_/\\
( o.o )
> ^ <`;
export function About() {
return (
<FetchCard
art={ART}
artLabel="A cat"
user="you"
host="portfolio"
rows={[
{ label: "role", value: "full-stack developer" },
{ label: "stack", value: "Next.js · React · TypeScript" },
{ label: "loc", value: "Earth" },
]}
/>
);
}A string art is split into lines that slide in one after another. Leading and trailing blank lines are trimmed, so you can start the template literal on a new line. Set its size with artClassName (block-letter logos usually need text-[9px] to text-[11px]).
Any other node works as art too: an <img>, an SVG, an AsciiImage.
Examples
Amber, without the palette
/\_/\ ( o.o ) > ^ <
- os
- mpkcn 0.3 x86_64
- shell
- zsh 5.9
- stack
- Next.js · React · TypeScript
- theme
- dark (amber / blue)
<FetchCard art={ART} tone="amber" palette={false} rows={rows} />Your own header
title replaces the user@host line, for a name or a link.
<FetchCard title={<a href="/about">read more</a>} rows={rows} art={ART} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| art | ReactNode | — | ASCII art on the left. A string is split into lines. |
| artLabel | string | — | Accessible name for the art. Without it the art is hidden from screen readers. |
| user | string | "guest" | User part of the header. |
| host | string | "localhost" | Host part of the header. |
| title | ReactNode | — | Replaces the user@host header. |
| rows | { label: string; value: ReactNode }[] | — | Key / value rows under the header. |
| palette | boolean | true | Show the strip of theme color swatches. |
| tone | "blue" | "amber" | "blue" | Accent of the art and header. |
| animate | boolean | true | Slide the lines in when the card scrolls into view. |
| tilt | boolean | true | Tilt the art in 3D towards a mouse pointer. |
| ignoreReducedMotion | boolean | false | Animate even under reduced motion. Only use it behind an explicit action. |
| className | string | — | Extra classes for the root. |
| artClassName | string | "text-[11px]" | Classes for the art (font size, line height). Replaces the default size. |
Accessibility
- The rows are a description list, so each label is tied to its value.
- ASCII art is noise to a screen reader: it is hidden unless you give it an
artLabel, which turns it into an image with that name. - The palette strip and the rule under the header are decorative and hidden.
- Under
prefers-reduced-motion: reducenothing slides and the art does not tilt. Touch input never tilts it.