Skip to content
Domphy

chartLineStep

A Charts block/component from shadcn/ui — clean-room reimplemented for Domphy (see methodology). Call chartLineStep() with no arguments for a working demo, or edit the code below live.

Props

PropTypeDescription
titlestring
descriptionstring
seriesLabelstring
seriesColorThemeColor
dataMonthlyPoint[]
stepModeNonNullable<LineSeriesOption["step"]>Where the vertical jump sits relative to each pair of points. Defaults to "middle" (the jump happens midway between adjacent points — matches the upstream block's d3 curveStep).
trendHeadlinestring
trendSubtitlestring
trendDirection"up" | "down"
Implementation notes

Identical to chartLineDefault with LineSeriesOption.step (default 'start', exposed as a stepMode prop). Same mount-reveal approximation as chartLineDefault. Direct-source-diff fix (2026-07-05): Step interpolation used the wrong mode — upstream's recharts type="step" is a curveStep (jump at the midpoint), matched here by switching stepMode from 'start' to 'middle'.

Status: ported · Reference: shadcn/ui original

// shadcn/ui "charts/line-step" block — clean-room reimplementation.
//
// Same single-series six-month chart as chartLineDefault, but rendered as a
// stepped/staircase line: the line holds each value horizontally then jumps
// vertically to the next one. Everything else — card chrome, grid, axis,
// tooltip and footer — is unchanged.
//
// Implemented purely from the block's public functional/visual spec — no
// upstream shadcn/ui source was viewed or copied.

import type { ChartOption, LineSeriesOption } from "@domphy/chart";
import type { DomphyElement } from "@domphy/core";
import type { ThemeColor } from "@domphy/theme";
import {
  chartCard,
  chartLineSeriesColor,
  chartPlot,
  computeYDomain,
  DEFAULT_LINE_GRID,
  hiddenLabelYAxis,
  lineSwatchLabelValueTooltipFormatter,
  MONTHLY_VISITOR_DATA,
  type MonthlyPoint,
  monthCategoryXAxis,
  trendFooter,
} from "./chart-line-shared.js";

/** Props for {@link chartLineStep}. */
export interface ChartLineStepProps {
  title?: string;
  description?: string;
  seriesLabel?: string;
  seriesColor?: ThemeColor;
  data?: MonthlyPoint[];
  /** Where the vertical jump sits relative to each pair of points. Defaults to
   * "middle" (the jump happens midway between adjacent points — matches the
   * upstream block's d3 `curveStep`). */
  stepMode?: NonNullable<LineSeriesOption["step"]>;
  trendHeadline?: string;
  trendSubtitle?: string;
  trendDirection?: "up" | "down";
}

/**
 * shadcn/ui "charts/line-step" — the default single-line chart rendered as a
 * staircase. Call with no arguments for a fully working demo.
 */
function chartLineStep(props: ChartLineStepProps = {}): DomphyElement<"div"> {
  const {
    title = "Line Chart - Step",
    description = "January - June 2026",
    seriesLabel = "Desktop",
    seriesColor = "primary",
    data = MONTHLY_VISITOR_DATA,
    stepMode = "middle",
    trendHeadline = "Trending up by 5.2% this month",
    trendSubtitle = "Showing total visitors for the last 6 months",
    trendDirection = "up",
  } = props;

  const categories = data.map((point) => point.month);
  const values = data.map((point) => point.desktop);
  const yDomain = computeYDomain(values);

  const option: ChartOption = {
    grid: DEFAULT_LINE_GRID,
    xAxis: monthCategoryXAxis(categories),
    yAxis: hiddenLabelYAxis(yDomain),
    tooltip: {
      trigger: "axis",
      axisPointer: { type: "none" },
      formatter: (params) =>
        lineSwatchLabelValueTooltipFormatter(
          params,
          chartLineSeriesColor(0).css,
        ),
    },
    series: [
      {
        type: "line",
        name: seriesLabel,
        data: values,
        smooth: false,
        step: stepMode,
        showSymbol: false,
        // Upstream's stroke is var(--chart-1): the engine pins strokes to
        // shift-9, so the ramp step is approximated via stroke opacity.
        lineStyle: { width: 2, opacity: chartLineSeriesColor(0).strokeOpacity },
        color: seriesColor,
      },
    ],
  };

  return chartCard({
    title,
    description,
    plot: chartPlot({ option }),
    footer: trendFooter({
      headline: trendHeadline,
      subtitle: trendSubtitle,
      direction: trendDirection,
    }),
  });
}

export { chartLineStep };

← Back to shadcn/ui catalog