# Week bars (Notchset): prompt.md (v2.0.0)

- id: `week-bars` · version 2.0.0 · component · free
- category: Charts
- build: one set of files for every shadcn style
- install: `npx shadcn@latest add https://notchset.dev/r/week-bars.json`
- npm dependencies: none
- registry dependencies: utils, https://notchset.dev/r/notchset-foundation.json, @notchset/chart
- docs: https://notchset.dev/components/week-bars
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Bars by day in the series' soft tint with each value written inside its top, today lit in the lilac focus and the period's average as a dashed line. Scrub or use the arrow keys to read a day; a day with nothing recorded is a dashed stub, never a zero; the table carries every day..

## Build it
- Stack: React 18.3 or 19, TypeScript, Tailwind CSS v4 utility classes on the foundation's roles, a components.json (imports use its aliases).
- Packages: none beyond React.
- Files: `components/ui/notchset/week-bars.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`, `chart`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `WeekBars`, and every exported type.
- CSS: the install adds the notchset foundation (its roles, keyframes and motion switch, reading your shadcn tokens for colour) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- This item reads `--ns-font-mono`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-panel`, `--ns-series`, `--ns-series-lilac`, `--ns-text-meta`, `--ns-time-color`, `--ns-weight-medium`.
- Retune it (on any ancestor) with the foundation's roles and hooks: `--ns-bad`, `--ns-bad-ink`, `--ns-band`, `--ns-band-edge`, `--ns-band-grade`, `--ns-band-optimal`, `--ns-beat`, `--ns-bezel`, `--ns-canvas`, `--ns-cat-1`, `--ns-cat-2`, `--ns-cat-3`, `--ns-cat-4`, `--ns-cat-5`, `--ns-cat-6`, `--ns-check`, `--ns-chip`, `--ns-control`, `--ns-control-pad`, `--ns-control-sm`, `--ns-deep`, `--ns-deep-ink`, `--ns-deep-ink-2`, `--ns-deep-line`, `--ns-dialog`, `--ns-dialog-lg`, `--ns-dialog-sm`, `--ns-ease`, `--ns-ease-in`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-field`, `--ns-flood-arc`, `--ns-flood-aurora`, `--ns-flood-behind-1`, `--ns-flood-behind-2`, `--ns-flood-bloom`, `--ns-flood-deep`, `--ns-flood-dial-bloom`, `--ns-flood-glass`, `--ns-flood-grain`, `--ns-flood-image`, `--ns-flood-ink`, `--ns-flood-ink-low`, `--ns-flood-light`, `--ns-flood-mid`, `--ns-flood-pale`, `--ns-flood-pane`, `--ns-flood-pane-edge`, `--ns-flood-pill-ink`, `--ns-flood-ribbon`, `--ns-flood-ribbon-core`, `--ns-flood-shadow`, `--ns-flood-sheen`, `--ns-flood-wash`, `--ns-font-body`, `--ns-font-display`, `--ns-font-mono`, `--ns-font-script`, `--ns-glass`, `--ns-glass-blur`, `--ns-glass-shadow`, `--ns-glow`, `--ns-grain`, `--ns-gutter`, `--ns-header`, `--ns-heat`, `--ns-hover`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-ink-4`, `--ns-leading`, `--ns-lift`, `--ns-light-1`, `--ns-light-2`, `--ns-light-3`, `--ns-light-spread`, `--ns-light-strength`, `--ns-line`, `--ns-line-soft`, `--ns-lit-edge`, `--ns-menu-dy`, `--ns-menu-row`, `--ns-mesh`, `--ns-mesh-frost`, `--ns-ok`, `--ns-ok-ink`, `--ns-orb-body`, `--ns-orb-cool`, `--ns-orb-core`, `--ns-orb-dawn`, `--ns-orb-deep`, `--ns-orb-edge`, `--ns-orb-grain`, `--ns-orb-ground`, `--ns-orb-halo`, `--ns-orb-inner`, `--ns-orb-key`, `--ns-orb-lift`, `--ns-orb-limb`, `--ns-orb-limb-from`, `--ns-orb-rim`, `--ns-orb-skin-hi`, `--ns-orb-skin-lo`, `--ns-orb-skin-mid`, `--ns-orb-warm`, `--ns-panel`, `--ns-panel-w`, `--ns-prism-edge`, `--ns-prism-glint`, `--ns-prism-sheen`, `--ns-prism-tint`, `--ns-pulse`, `--ns-radius`, `--ns-radius-card`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-sm`, `--ns-radius-xl`, `--ns-raised`, `--ns-range`, `--ns-row`, `--ns-row-compact`, `--ns-segment`, `--ns-selected`, `--ns-series`, `--ns-series-core`, `--ns-series-lilac`, `--ns-series-tint`, `--ns-shadow-dialog`, `--ns-shadow-float`, `--ns-shadow-panel`, `--ns-sheet`, `--ns-sheet-bottom`, `--ns-side`, `--ns-signal`, `--ns-sleep-awake`, `--ns-sleep-deep`, `--ns-sleep-light`, `--ns-sleep-rem`, `--ns-space-1`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-5`, `--ns-space-6`, `--ns-space-8`, `--ns-space-section`, `--ns-stack-on`, `--ns-standing-critical`, `--ns-standing-in`, `--ns-standing-out`, `--ns-state-doing`, `--ns-state-done`, `--ns-state-review`, `--ns-state-todo`, `--ns-switch-h`, `--ns-switch-w`, `--ns-text-body`, `--ns-text-control`, `--ns-text-display`, `--ns-text-figure`, `--ns-text-headline`, `--ns-text-hero`, `--ns-text-lede`, `--ns-text-meta`, `--ns-text-page`, `--ns-text-record`, `--ns-text-small`, `--ns-text-strong`, `--ns-text-sub`, `--ns-text-title`, `--ns-tile-shadow`, `--ns-time-born`, `--ns-time-color`, `--ns-time-dialog`, `--ns-time-menu`, `--ns-time-page`, `--ns-time-panel`, `--ns-time-toast`, `--ns-tint`, `--ns-tint-ink`, `--ns-toast-bottom`, `--ns-toast-left`, `--ns-touch`, `--ns-tracking-display`, `--ns-tracking-headline`, `--ns-warn`, `--ns-warn-ink`, `--ns-wash-clay`, `--ns-wash-dusk`, `--ns-wash-graphite`, `--ns-wash-ink`, `--ns-wash-sage`, `--ns-wash-sand`, `--ns-weight-light`, `--ns-weight-medium`, `--ns-weight-regular`, `--ns-weight-strong`, `--ns-well`.
- Never add Tailwind colour classes inside the component.

```tsx
import { WeekBars } from "@/components/ui/notchset/week-bars";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/week-bars.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when

### Not when

## Built from
- chart (`chart`), installed with it: reuse it, don't rebuild it

## Mistakes
- Recreating the component instead of installing it

## Usage

```tsx
"use client";
import { WeekBars } from "@/components/ui/notchset/week-bars";

const W: [string, number, string][] = [["Mon", 7.07, "7:04"], ["Tue", 6.37, "6:22"], ["Wed", 7.3, "7:18"], ["Thu", 6.68, "6:41"], ["Fri", 6.2, "6:12"], ["Sat", 7.42, "7:25"], ["Sun", 6.95, "6:57"]];

export default function WeekBarsDemo() {
  return (
    <div className="max-w-[560px]">
      <WeekBars label="Sleep this week, Mon 19 to Sun 25 October" bars={W.map(([label, value, text]) => ({ label, value, text }))} avg={6.85} avgText="6 h 51" floor={4} />
    </div>
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `bars` | `WeekBar[]` |  | Required. |
| `label` | `string` |  | what and when, for the chart's name |
| `avg` | `number \| null` |  | the period's average, drawn dashed |
| `avgText` | `string` |  |  |
| `today` | `number` | `bars.length - 1` | the bar that's today (default: the last) |
| `height` | `number` | `168` |  |
| `floor` | `number` | `0` | the floor the bars stand on (sleep reads from 4 h, not 0) |
| `goal` | `number` |  | a goal to clear, drawn as a quiet solid line with its words in a gutter at its right end ("70% goal") |
| `goalText` | `string` |  |  |
| `ceiling` | `number` |  | the ceiling of the scale (time in range reads to 100%); left out, the tallest bar |
| `labelEvery` | `number` | `1` | write every nth day's label under the bars (a month or a year of bars); the table keeps them all |

Full docs: https://notchset.dev/components/week-bars

## Customising
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- Dark mode follows the `.dark` class or `data-theme="dark"` on an ancestor (the shadcn and next-themes conventions).
- Update later: Commit or stash local changes first (or copy the files), so the update can be undone. Read https://notchset.dev/r/changelog.json for the new versions: a major version, an entry marked breaking or a merge says what to change. Then re-run the install with `--overwrite`, on a branch. It replaces the component's files, the shared helper files they import, and the item's CSS rules in the global stylesheet, so review the whole diff (components, shared files, CSS), re-apply your own edits, and run the app's typecheck, tests and build.

## Accessibility contract (preserve when editing)

## Install

```bash
npx shadcn@latest add https://notchset.dev/r/week-bars.json
```

Or add the `@notchset` registry to components.json and run `npx shadcn@latest add @notchset/week-bars`. Every components.json style gets the same files.

## Continue the workflow

- [Day timeline](https://notchset.dev/components/day-timeline)
- [Ghost trend](https://notchset.dev/components/ghost-trend)
- [Glucose day](https://notchset.dev/components/glucose-day)

## Source

### components/ui/notchset/week-bars.tsx

```tsx
// Notchset week-bars 2.0.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
import { ChartGuide, ChartPill, ChartSurface, ChartTable, ChartTableToggle, barPath, useChartWidth } from "@/components/ui/notchset/chart";

/*
 * Week bars: a value by day as rounded bars in the series' soft tint, the value written inside each bar's top, today
 * lit in the lilac focus and the period's average as a dashed ink line. Still on arrival; scrub or use the arrow keys
 * to read a day, and the table carries every day. A day with nothing recorded is a dashed stub, never a zero.
 *
 *   <WeekBars label="Sleep this week" bars={[{ label: "Mon", value: 7.07, text: "7:04" }, …]} avg={6.85} avgText="6 h 51" />
 */
type WeekBar = { label: string; value: number | null; text?: string | undefined };
type WeekBarsProps = {
  bars: WeekBar[];
  /** what and when, for the chart's name */
  label: string;
  /** the period's average, drawn dashed */
  avg?: number | null | undefined;
  avgText?: string | undefined;
  /** the bar that's today (default: the last) */
  today?: number | undefined;
  height?: number | undefined;
  /** the floor the bars stand on (sleep reads from 4 h, not 0) */
  floor?: number | undefined;
  /** a goal to clear, drawn as a quiet solid line with its words in a gutter at its right end ("70% goal") */
  goal?: number | undefined;
  goalText?: string | undefined;
  /** the ceiling of the scale (time in range reads to 100%); left out, the tallest bar */
  ceiling?: number | undefined;
  /** write every nth day's label under the bars (a month or a year of bars); the table keeps them all */
  labelEvery?: number | undefined;
  className?: string | undefined;
};

function WeekBars({ bars, label, avg, avgText, goal, goalText, ceiling, today = bars.length - 1, height = 168, floor = 0, labelEvery = 1, className }: WeekBarsProps) {
  const [box, W] = useChartWidth<HTMLDivElement>(420);
  const [active, setActive] = React.useState<number | null>(null);
  /* each chart its own gradient, so two on a page don't share one */
  const gid = `wb-today-${React.useId().replace(/:/g, "")}`;
  const [table, setTable] = React.useState(false);
  const n = Math.max(1, bars.length);
  /* the goal and average words sit in a gutter at the right end of their lines, never over a bar */
  const words = [goal != null ? goalText : undefined, avg != null && avgText ? `avg ${avgText}` : undefined].filter((t): t is string => !!t);
  const G = words.length ? Math.min(150, Math.max(...words.map((t) => t.length)) * 6.6 + 16) : 0;
  const P = Math.max(120, W - G);
  /* a week keeps wide gaps; a month or a year of bars shares the width, a third of each step for the gap */
  const gap = n > 14 ? Math.max(1, (P / n) * 0.3) : Math.max(6, Math.min(14, P / n / 6));
  const bw = (P - gap * (n - 1)) / n;
  /* a sparse axis keeps its labels at least 64px apart, whatever the width */
  const every = labelEvery > 1 ? Math.max(labelEvery, Math.ceil(64 / (bw + gap))) : 1;
  const vals = bars.map((b) => b.value).filter((v): v is number => v != null);
  const top = ceiling ?? Math.max(floor + 1, ...vals, avg ?? 0, goal ?? 0) * 1.04;
  const y = (v: number) => height - ((v - floor) / (top - floor)) * height;
  const x = (i: number) => i * (bw + gap);
  const text = (b: WeekBar) => (b.value == null ? "nothing recorded" : (b.text ?? String(b.value)));
  const at = active == null ? null : bars[active];
  return (
    <div data-slot="week-bars" className={cn("flex min-w-0 flex-col gap-2", className)}>
      <div ref={box} className="relative min-w-0">
        <ChartSurface
          label={label}
          valueText={at ? `${at.label}: ${text(at)}` : `${bars[today]?.label ?? ""}: ${bars[today] ? text(bars[today]) : ""}`}
          count={n}
          active={active}
          rest={today}
          onActive={setActive}
          height={height}
          padX={[bw / 2, W - P + bw / 2]}
          step={1}
          hint="Arrow keys move a day; Enter pins; Esc lets go."
        >
          <svg aria-hidden width={W} height={height} className="absolute inset-0 block overflow-visible">
            <defs>
              <linearGradient id={gid} x1="0" x2="0" y1="0" y2="1">
                <stop offset="0" stopColor="var(--ns-series-lilac)" />
                <stop offset="1" stopColor="var(--ns-series)" />
              </linearGradient>
            </defs>
            {bars.map((b, i) => {
              if (b.value == null) return <rect key={i} x={x(i) + 0.5} y={height - 6} width={bw - 1} height={5} rx={2.5} fill="none" stroke="var(--ns-ink-3)" strokeDasharray="2 3" />;
              const h = Math.max(4, height - y(b.value));
              const lit = i === today;
              return <path key={i} d={barPath(x(i), height - h, bw, h, 7)} fill={lit ? `url(#${gid})` : "var(--ns-series)"} fillOpacity={lit ? 1 : active === i ? 0.42 : 0.26} style={{ transition: "fill-opacity var(--ns-time-color)" }} />;
            })}
            {goal != null && <line x1={0} x2={W} y1={Math.round(y(goal)) + 0.5} y2={Math.round(y(goal)) + 0.5} stroke="var(--ns-ink-3)" strokeWidth={1} />}
            {avg != null && <line x1={0} x2={W} y1={Math.round(y(avg)) + 0.5} y2={Math.round(y(avg)) + 0.5} stroke="var(--ns-ink-2)" strokeWidth={1} strokeDasharray="3 4" />}
          </svg>
          {bars.map((b, i) =>
            b.value == null || height - y(b.value) < 26 || bw < 30 ? null : (
              <span key={i} aria-hidden className={cn("absolute font-[family-name:var(--ns-font-mono)] text-[length:var(--ns-text-meta)] leading-none tabular-nums", i === today ? "text-[var(--ns-panel)]" : "text-[var(--ns-ink)]")} style={{ left: x(i), width: bw, top: y(b.value) + 8, textAlign: "center" }}>
                {b.text ?? b.value}
              </span>
            ),
          )}
          {goal != null && goalText && (
            <span aria-hidden data-slot="week-bars-goal" className="absolute right-0 font-[family-name:var(--ns-font-mono)] text-[length:var(--ns-text-meta)] leading-none text-[var(--ns-ink-2)]" style={{ top: avg != null && avgText && y(goal) > y(avg) && y(goal) - y(avg) < 16 ? y(goal) + 4 : Math.max(0, y(goal) - 14) }}>
              {goalText}
            </span>
          )}
          {avg != null && avgText && (
            <span aria-hidden data-slot="week-bars-avg" className="absolute right-0 font-[family-name:var(--ns-font-mono)] text-[length:var(--ns-text-meta)] leading-none text-[var(--ns-ink-2)]" style={{ top: goal != null && goalText && y(avg) > y(goal) && y(avg) - y(goal) < 16 ? y(avg) + 4 : Math.max(0, y(avg) - 14) }}>
              avg {avgText}
            </span>
          )}
          <ChartGuide x={active == null ? 0 : x(active) + bw / 2} on={false} />
          <ChartPill x={active == null ? 0 : x(active) + bw / 2} y={at?.value != null ? y(at.value) : height - 8} width={W} on={at != null} value={at ? text(at) : ""} detail={at?.label} />
        </ChartSurface>
        <div aria-hidden className="mt-2 grid text-center text-[length:var(--ns-text-meta)] text-[var(--ns-ink-3)]" style={{ gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))`, columnGap: gap, paddingRight: W - P }}>
          {bars.map((b, i) => (
            <span key={i} className={cn(labelEvery > 1 ? cn("flex overflow-visible whitespace-nowrap", i === n - 1 ? "justify-end" : "justify-center") : "truncate", i === today && "font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]")}>
              {/* a sparse axis: every nth label back from the last, none so near the start that it would spill off */}
              {every === 1 || ((n - 1 - i) % every === 0 && (i === n - 1 || i >= 3)) ? b.label : ""}
            </span>
          ))}
        </div>
      </div>
      <ChartTableToggle open={table} onToggle={() => setTable(!table)} />
      <ChartTable caption={label} head={["Day", "Value"]} rows={bars.map((b) => [b.label, text(b)])} open={table} active={active} onPick={setActive} />
    </div>
  );
}

export { WeekBars, type WeekBar, type WeekBarsProps };
```

The foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://notchset.dev/r/notchset-foundation.json.
