Bar Depth
bklit-ui/bar-depthFreeComponent
3D depth and glossy glass surfaces for BarChart bars
Install it
npx shadcn@latest add https://bklit.com/r/bar-depth.jsonSource
1"use client";23/**4 * Bar 3D depth + glass surfaces — drop-in layers for `<BarChart>`.5 *6 * Adds a head-on perspective and a glossy glass-block sheen to the bars in7 * any `<BarChart>`. Bars left of chart center expose their RIGHT side face;8 * bars right of center expose their LEFT — the vanishing point sits at the9 * chart's horizontal middle, so the row reads like vertical glass blocks10 * viewed straight on.11 *12 * Three surfaces per bar:13 * 1. Side face — a parallelogram on the depth side, lit at the front edge14 * with a horizontal black gradient and shaded toward the back.15 * 2. Top face — a parallelogram lid above the bar's top edge, with a16 * bright catch at the front lip fading to soft white at the back.17 * 3. Glass overlay — a vertical white-to-dark gradient on the bar's front18 * face (sharp top reflection, transparent middle, faint bottom shadow).19 *20 * Usage (purely additive — no changes to `<Bar>`):21 *22 * <BarChart data={data} xDataKey="month">23 * <Grid horizontal />24 * <BarDepthBack dataKey="value" color="var(--chart-1)" /> // before <Bar>25 * <Bar dataKey="value" fill="var(--chart-1)" />26 * <BarDepthFront dataKey="value" /> // after <Bar>27 * </BarChart>28 *29 * Both depth layers read geometry from `useChart()` and figure out the30 * perspective themselves. The only configuration is the bar color31 * (`color` / `colorAccessor`) and, for stacked bars, a `segmentsAccessor`32 * supplied via `<BarDepthProvider>`.33 *34 * An optional `<BarPulse>` paints a looping vertical sweep over a single35 * "active" bar (selected by `activeIndex`) — useful for highlighting a live36 * or in-progress value. Render it AFTER `<BarDepthFront>`.37 *38 * Behavior notes:39 * - Negative values are supported: a bar whose value is below zero grows40 * downward from the baseline, with the lid sitting on the baseline.41 * (This requires the host `<BarChart>` to use a value scale whose42 * domain includes negatives.)43 * - Zero-value bars are skipped by default; set `minBarHeight` on44 * `<BarDepthProvider>` (and `<Bar>`) to floor them to a short visible bar.45 *46 * Performance:47 * - Three shared SVG gradients per layer instance (ID-collision-safe via48 * `useId()`).49 * - A per-bar `<clipPath>` for the side face animates from the baseline so50 * the static side path is revealed bottom-up in lockstep with the bar.51 * Only used where depth ≥ 0.5px.52// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from bklit-ui
All 56 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Area Chartarea-chart | bklit-ui | Components | Free | 4 deps · 14 files | |
| Chart Backgroundbackground | bklit-ui | Components | Free | 2 deps · 3 files | |
| Bar Chartbar-chart | bklit-ui | Components | Free | 4 deps · 13 files | |
| Candlestick Chartcandlestick-chart | bklit-ui | Components | Free | 4 deps · 4 files | |
| Chart Animationchart-animation | bklit-ui | Components | Free | 1 dep · 7 files | |
| Chart Contextchart-context | bklit-ui | Components | Free | 5 deps · 12 files | |
| Chart Series Layerchart-series | bklit-ui | Components | Free | 3 deps · 15 files | |
| Chart Stat Flowchart-stat-flow | bklit-ui | Components | Free | 2 deps |
