{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-dashboard-stats",
  "type": "registry:block",
  "title": "App, stat panel row",
  "description": "A row of two to four figures for a dashboard: label, large value, the change with a sign and an arrow, and what it is measured against. A definition list for assistive tech, with loading and error states.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/banner.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/skeleton.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-dashboard-stats/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-dashboard-stats/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  items: z\n    .array(\n      z.object({\n        label: t(40),\n        value: t(20),\n        /** The change, with its sign: \"+12%\". The arrow beside it repeats the direction, it never carries it alone. */\n        change: t(30),\n        trend: z.enum(['up', 'down', 'flat']),\n        /** What the change is measured against: \"vs last month\". */\n        against: t(40),\n      }),\n    )\n    .min(2)\n    .max(4),\n  /** filled: the figures. loading: placeholders, announced once. error: a message and a retry. */\n  state: z.enum(['filled', 'loading', 'error']),\n  messages: z.object({ loading: t(60), error: t(120), retry: t(30) }),\n});\n\nexport const spec = defineSpec({\n  type: 'app-dashboard-stats',\n  aliases: ['app/dashboard-stats'],\n  name: 'App, stat panel row',\n  category: 'app',\n  role: 'body',\n  description: 'A row of two to four figures for a dashboard: label, large value, the change with a sign and an arrow, and what it is measured against. A definition list for assistive tech, with loading and error states.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Overview\",\n    \"title\": \"Name the period or scope\",\n    \"description\": \"Say how it is going and what it is compared with.\",\n    \"items\": [\n      {\n        \"label\": \"Name a measure\",\n        \"value\": \"00%\",\n        \"change\": \"+0%\",\n        \"trend\": \"up\",\n        \"against\": \"vs before\"\n      },\n      {\n        \"label\": \"Name a measure\",\n        \"value\": \"000\",\n        \"change\": \"+00\",\n        \"trend\": \"up\",\n        \"against\": \"vs before\"\n      },\n      {\n        \"label\": \"Name a measure\",\n        \"value\": \"0.0 units\",\n        \"change\": \"0.0\",\n        \"trend\": \"flat\",\n        \"against\": \"vs before\"\n      },\n      {\n        \"label\": \"Name a measure\",\n        \"value\": \"0\",\n        \"change\": \"−0\",\n        \"trend\": \"down\",\n        \"against\": \"vs before\"\n      }\n    ],\n    \"state\": \"filled\",\n    \"messages\": {\n      \"loading\": \"Say they are loading\",\n      \"error\": \"Say the figures did not load and to retry.\",\n      \"retry\": \"Try again\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-dashboard-stats/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-dashboard-stats/index.tsx",
      "content": "import { useId } from 'react';\nimport { ArrowDown, ArrowRight, ArrowUp } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Banner } from '../../ui/banner';\nimport { Button } from '../../ui/button';\nimport { Skeleton } from '../../ui/skeleton';\nimport { Container, Section, SectionHeader } from '../_shared/kit';\nimport { StateSlot } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nconst arrows = { up: ArrowUp, down: ArrowDown, flat: ArrowRight };\n\nfunction AppDashboardStats({ props }: BlockProps<Props>) {\n  const id = useId();\n  const { state, messages } = props;\n  return (\n    <Section labelledBy={id}>\n      <Container>\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <StateSlot show={state === 'error'} className=\"mt-10\">\n          <Banner tone=\"error\" action={<Button variant=\"secondary\"><Text path={['messages', 'retry']} value={messages.retry} as=\"span\" /></Button>}>\n            <Text path={['messages', 'error']} value={messages.error} as=\"span\" />\n          </Banner>\n        </StateSlot>\n        <StateSlot show={state === 'loading'} className=\"mt-6 text-kh-small text-kh-muted\">\n          <p role=\"status\">\n            <Text path={['messages', 'loading']} value={messages.loading} as=\"span\" />\n          </p>\n        </StateSlot>\n        <StateSlot show={state !== 'error'}>\n          <dl aria-busy={state === 'loading' || undefined} className=\"mt-10 grid gap-4 @xl:grid-cols-2 @4xl:grid-cols-[repeat(auto-fit,minmax(12rem,1fr))]\">\n            {props.items.map((it, i) => {\n              const Arrow = arrows[it.trend];\n              return (\n                <div key={i} className=\"flex flex-col gap-2 rounded-kh-lg border border-kh-line bg-kh-surface p-6\">\n                  <dt className=\"text-kh-small font-medium text-kh-muted\">\n                    <Text path={['items', i, 'label']} value={it.label} as=\"span\" />\n                  </dt>\n                  <dd className=\"m-0 flex flex-col gap-2\">\n                    {state === 'loading' ? (\n                      <>\n                        <Skeleton className=\"h-8 w-24\" />\n                        <Skeleton className=\"h-4 w-32\" />\n                        <span hidden>\n                          <Text path={['items', i, 'value']} value={it.value} as=\"span\" />\n                          <Text path={['items', i, 'change']} value={it.change} as=\"span\" />\n                          <Text path={['items', i, 'against']} value={it.against} as=\"span\" />\n                        </span>\n                      </>\n                    ) : (\n                      <>\n                        <Text path={['items', i, 'value']} value={it.value} as=\"span\" className=\"text-kh-heading font-semibold tabular-nums text-kh-ink\" />\n                        <span className=\"flex flex-wrap items-center gap-x-2 text-kh-small text-kh-muted\">\n                          <span className=\"inline-flex items-center gap-1 font-medium text-kh-ink-2\">\n                            <Arrow aria-hidden className=\"size-3.5\" />\n                            <Text path={['items', i, 'change']} value={it.change} as=\"span\" />\n                          </span>\n                          <Text path={['items', i, 'against']} value={it.against} as=\"span\" />\n                        </span>\n                      </>\n                    )}\n                  </dd>\n                </div>\n              );\n            })}\n          </dl>\n        </StateSlot>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppDashboardStats);\n"
    }
  ]
}
