diff --git a/r/stat-card.json b/r/stat-card.json index 205d719..5948bb3 100644 --- a/r/stat-card.json +++ b/r/stat-card.json @@ -15,7 +15,7 @@ "path": "src/components/cipher/ui/stat-card.tsx", "type": "registry:file", "target": "src/components/cipher/ui/stat-card.tsx", - "content": "import * as React from \"react\";\n\nimport type { CipherLinkProps } from \"../lib/link\";\nimport { cn } from \"../lib/utils\";\nimport { Card, CardContent, CardLink } from \"./card\";\nimport { Icon, type IconSource } from \"./icon\";\nimport { Media } from \"./item\";\nimport { Skeleton } from \"./skeleton\";\nimport { StatusText } from \"./text\";\n\nimport styles from \"./stat-card.module.css\";\n\nconst trendIcon = {\n up: \"arrow-up\",\n down: \"arrow-down\",\n flat: \"minus\"\n} as const;\nconst trendTone = { up: \"ok\", down: \"bad\", flat: \"neutral\" } as const;\n\nexport type StatCardProps = Omit<\n React.ComponentProps,\n \"title\" | \"badges\" | \"description\" | \"hint\" | \"action\" | \"footer\" | \"footerPlacement\" | \"children\"\n> & {\n label: React.ReactNode;\n value: React.ReactNode;\n icon?: IconSource;\n /** Tone of the icon, for a metric that needs attention. */\n tone?: \"ok\" | \"warn\" | \"bad\" | \"info\";\n /** The change since the last period, such as \"+12%\". Its text carries the direction; the arrow is decoration. */\n delta?: React.ReactNode;\n trend?: \"up\" | \"down\" | \"flat\";\n /** Defaults to ok for up, bad for down and neutral for flat; set it for a metric where up is bad. */\n deltaTone?: \"ok\" | \"bad\" | \"neutral\";\n /** A short line under the value: what the number counts, the comparison period, or a link. */\n note?: React.ReactNode;\n /** Makes the whole card a link, named by the label. */\n link?: CipherLinkProps[\"link\"];\n loading?: boolean;\n /** Replaces the value with this message when the metric failed to load. */\n error?: React.ReactNode;\n};\n\nexport function StatCard({\n label,\n value,\n icon,\n tone,\n delta,\n trend = \"flat\",\n deltaTone,\n note,\n link,\n loading = false,\n error,\n variant = \"framed\",\n className,\n ...props\n}: StatCardProps) {\n const id = React.useId();\n const labelId = `${id}-label`;\n const valueId = `${id}-value`;\n const failed = error !== undefined && error !== null && error !== false;\n return (\n \n \n
\n \n {link ? (\n \n {label}\n \n ) : (\n label\n )}\n \n {icon && }\n
\n {loading ? (\n \n ) : failed ? (\n \n {error}\n \n ) : (\n
\n {value}\n
\n )}\n {!loading && !failed && (delta !== undefined || note !== undefined) && (\n
\n {delta !== undefined && (\n \n \n {delta}\n \n )}\n {note !== undefined && {note}}\n
\n )}\n
\n \n );\n}\n" + "content": "import * as React from \"react\";\n\nimport type { CipherLinkProps } from \"../lib/link\";\nimport { useInFrame } from \"../lib/frame-context\";\nimport { cn } from \"../lib/utils\";\nimport { Card, CardContent, CardLink } from \"./card\";\nimport { Icon, type IconSource } from \"./icon\";\nimport { Media } from \"./item\";\nimport { Skeleton } from \"./skeleton\";\nimport { StatusText } from \"./text\";\n\nimport styles from \"./stat-card.module.css\";\n\nconst trendIcon = {\n up: \"arrow-up\",\n down: \"arrow-down\",\n flat: \"minus\"\n} as const;\nconst trendTone = { up: \"ok\", down: \"bad\", flat: \"neutral\" } as const;\n\nexport type StatCardProps = Omit<\n React.ComponentProps,\n \"title\" | \"badges\" | \"description\" | \"hint\" | \"action\" | \"footer\" | \"footerPlacement\" | \"children\"\n> & {\n label: React.ReactNode;\n value: React.ReactNode;\n icon?: IconSource;\n /** Tone of the icon, for a metric that needs attention. */\n tone?: \"ok\" | \"warn\" | \"bad\" | \"info\";\n /** The change since the last period, such as \"+12%\". Its text carries the direction; the arrow is decoration. */\n delta?: React.ReactNode;\n trend?: \"up\" | \"down\" | \"flat\";\n /** Defaults to ok for up, bad for down and neutral for flat; set it for a metric where up is bad. */\n deltaTone?: \"ok\" | \"bad\" | \"neutral\";\n /** A short line under the value: what the number counts, the comparison period, or a link. */\n note?: React.ReactNode;\n /** Makes the whole card a link, named by the label. */\n link?: CipherLinkProps[\"link\"];\n loading?: boolean;\n /** Replaces the value with this message when the metric failed to load. */\n error?: React.ReactNode;\n};\n\nexport function StatCard({\n label,\n value,\n icon,\n tone,\n delta,\n trend = \"flat\",\n deltaTone,\n note,\n link,\n loading = false,\n error,\n variant = \"framed\",\n backdrop,\n className,\n ...props\n}: StatCardProps) {\n const inFrame = useInFrame(\"StatCard\");\n const panelBackdrop = variant === \"framed\" && !inFrame;\n const id = React.useId();\n const labelId = `${id}-label`;\n const valueId = `${id}-value`;\n const failed = error !== undefined && error !== null && error !== false;\n return (\n \n \n {panelBackdrop && backdrop}\n
\n \n {link ? (\n \n {label}\n \n ) : (\n label\n )}\n \n {icon && }\n
\n {loading ? (\n \n ) : failed ? (\n \n {error}\n \n ) : (\n
\n {value}\n
\n )}\n {!loading && !failed && (delta !== undefined || note !== undefined) && (\n
\n {delta !== undefined && (\n \n \n {delta}\n \n )}\n {note !== undefined && {note}}\n
\n )}\n
\n \n );\n}\n" }, { "path": "src/components/cipher/ui/stat-card.module.css", diff --git a/src/ui/stat-card.tsx b/src/ui/stat-card.tsx index fd38af7..342123c 100644 --- a/src/ui/stat-card.tsx +++ b/src/ui/stat-card.tsx @@ -1,6 +1,7 @@ import * as React from "react"; import type { CipherLinkProps } from "../lib/link"; +import { useInFrame } from "../lib/frame-context"; import { cn } from "../lib/utils"; import { Card, CardContent, CardLink } from "./card"; import { Icon, type IconSource } from "./icon"; @@ -53,9 +54,12 @@ export function StatCard({ loading = false, error, variant = "framed", + backdrop, className, ...props }: StatCardProps) { + const inFrame = useInFrame("StatCard"); + const panelBackdrop = variant === "framed" && !inFrame; const id = React.useId(); const labelId = `${id}-label`; const valueId = `${id}-value`; @@ -68,9 +72,11 @@ export function StatCard({ aria-busy={loading || undefined} variant={variant} className={cn(styles.statCard, className)} + backdrop={panelBackdrop ? undefined : backdrop} {...props} > + {panelBackdrop && backdrop}
{link ? ( diff --git a/visual/baselines/desktop/stat-card-linked--dark.png b/visual/baselines/desktop/stat-card-linked--dark.png index 2f5e9a5..a7c2c54 100644 Binary files a/visual/baselines/desktop/stat-card-linked--dark.png and b/visual/baselines/desktop/stat-card-linked--dark.png differ diff --git a/visual/baselines/desktop/stat-card-linked--light.png b/visual/baselines/desktop/stat-card-linked--light.png index b7d0ffd..4d7fd52 100644 Binary files a/visual/baselines/desktop/stat-card-linked--light.png and b/visual/baselines/desktop/stat-card-linked--light.png differ diff --git a/visual/baselines/mobile/stat-card-linked--dark.png b/visual/baselines/mobile/stat-card-linked--dark.png index 34a759c..bb69fb6 100644 Binary files a/visual/baselines/mobile/stat-card-linked--dark.png and b/visual/baselines/mobile/stat-card-linked--dark.png differ diff --git a/visual/baselines/mobile/stat-card-linked--light.png b/visual/baselines/mobile/stat-card-linked--light.png index 7ec9d4f..f16f728 100644 Binary files a/visual/baselines/mobile/stat-card-linked--light.png and b/visual/baselines/mobile/stat-card-linked--light.png differ