Bklit UI

repository·main·Indexed 23 days ago

https://github.com/bklit/bklit-ui

A collection of open-source, customizable, and extendable React chart components designed for the shadcn registry. It includes a wide range of supported charts such as Area, Bar, Candlestick, Choropleth, Composed, Funnel, Gauge, Line, Pie, Radar, Ring, Scatter, and Sankey. The ecosystem features Bklit Studio, a proprietary interactive playground for real-time chart customization, code generation, and registry exports, as well as a dedicated set of editor UI components and a central icon system.

Tokens
74.5K
Snippets
170
Records
413
Agent score
79%

What's inside bklit-ui

  1. Knowledge provided by the bklit-ui skill

    main

    The bklit-ui skill equips your AI assistant with several key domains of knowledge:

    Registry Installation

    Instructions on how to configure the @bklit namespace and install specific charts using the shadcn CLI.

    Composition and Theming

    • Composition: How to nest components (e.g., LineChartGridLineXAxisChartTooltip).
    • Theming: Using chartCssVars for type-safe theming and applying series palette tokens (--chart-1 through --chart-5) or sequential scale tokens (--chart-scale-01 through --chart-scale-05) for heatmaps and choropleths.

    Animation and Tooltips

    • Animation: Default animation settings and replay patterns via revealSignature.
    • Tooltips: Custom tooltip content and the useChart hook for custom indicators.
    • Candlesticks: Using indicatorColor for candlestick charts.

    Chart Catalog

    Access to a decision guide for all 15 supported chart types: area, bar, line, live line, composed, scatter, candlestick, pie, ring, radar, gauge, heatmap, funnel, sankey, and choropleth.

  2. Theme Bklit UI charts with CSS variables

    main

    Avoid hardcoding colors. Bklit UI uses a token-based theming system to ensure consistency and support for light/dark modes.

    Best Practices:

    • Use chartCssVars: Import chartCssVars from @bklitui/ui/charts to access theme tokens instead of writing raw var(--chart-...) strings.
    • Multi-series Palettes: Use the --chart-1 through --chart-5 variables to define colors for different data series.
    • Tooltip Styling: For tooltip surfaces, use Tailwind classes bg-popover text-popover-foreground to prevent visibility issues (like white-on-white) in light mode.
  3. Use the Background component for textured plot fills

    main

    The Background component provides a pattern fill for the plot area of a chart, serving as an alternative to Grid when you want texture instead of reference lines.

    Key behaviors:

    • It must be a child of a cartesian chart (e.g., LineChart, AreaChart, BarChart, ScatterChart, CandlestickChart, ComposedChart, LiveLineChart).
    • It renders behind series layers.
    • On time-series charts, it sits outside the series clip reveal and fades in after the chart finishes loading.
    • It uses @visx/pattern under the hood.
    import { LineChart, Line, Background, ChartTooltip, XAxis } from "@bklitui/ui/charts";
    
    <LineChart data={data}>
      <Background pattern="diagonal" />
      <Line dataKey="value" />
      <XAxis />
      <ChartTooltip />
    </LineChart>
  4. Compose a Bklit UI chart

    main

    Bklit UI charts follow a specific composition pattern. Instead of a single monolithic component, you build charts by nesting specialized components inside a root chart component.

    Composition Rules:

    • Root Component: Every chart must have one root (e.g., LineChart, BarChart, AreaChart). Use ComposedChart if you need to mix different series types (like bars and lines) on the same axes.
    • Layering Order: Place the <Grid /> component before your series components (like <Line /> or <Bar />) so that data renders on top of the grid lines.
    • Required Elements: Always include <ChartTooltip /> as a child of the root chart to enable crosshair and hover functionality.
    • Axes and Series: Series and axes components must live inside the root chart component.
    import { LineChart, Line, Grid, XAxis, ChartTooltip, chartCssVars } from "@bklitui/ui/charts";
    
    <LineChart data={data} xDataKey="date">
      <Grid horizontal />
      <Line dataKey="users" stroke={chartCssVars.linePrimary} />
      <XAxis />
      <ChartTooltip />
    </LineChart>
  5. How the Legend component works

    main

    The Legend component uses a composable API. Instead of passing a configuration object for the layout, you define a single layout using child components (like LegendItemComponent, LegendMarker, etc.) inside the Legend root. The Legend component then automatically maps this layout to every item in your items data array.

    This allows for highly flexible layouts, such as simple horizontal rows, grid-based layouts with progress bars, or complex custom arrangements, all while maintaining a single source of truth for the data.

    const data = [
      { label: "Organic", value: 4250, maxValue: 5000, color: "#0ea5e9" },
      { label: "Paid", value: 3120, maxValue: 5000, color: "#a855f7" },
    ];
    
    <Legend items={data} title="Traffic Sources">
      <LegendItemComponent>
        <LegendMarker />
        <LegendLabel />
        <LegendValue />
      </LegendItemComponent>
    </Legend>
  6. How Radar Chart components work together

    main

    The Radar Chart uses a composable API where a root RadarChart container provides context to specialized child components. You define your metrics and data, then combine components to build the visual layers.

    Typical composition order:

    1. RadarChart: The root container.
    2. RadarGrid: Renders the circular grid lines.
    3. RadarAxis: Renders axis lines from the center to each metric.
    4. RadarLabels: Renders metric labels around the perimeter.
    5. RadarArea: Renders individual data polygons (one per data series).
    import { RadarChart, RadarGrid, RadarAxis, RadarLabels, RadarArea } from "@bklitui/ui/charts";
    
    const metrics = [
      { key: "speed", label: "Speed" },
      { key: "power", label: "Power" },
      { key: "technique", label: "Technique" },
    ];
    
    const data = [
      { label: "Player A", color: "#3b82f6", values: { speed: 85, power: 70, technique: 90 } },
      { label: "Player B", color: "#f59e0b", values: { speed: 65, power: 95, technique: 60 } },
    ];
    
    export default function PerformanceRadar() {
      return (
        <RadarChart data={data} metrics={metrics} size={400}>
          <RadarGrid />
          <RadarAxis />
          <RadarLabels />
          {data.map((item, index) => (
            <RadarArea key={item.label} index={index} />
          ))}
        </RadarChart>
      );
    }
  7. Create custom indicators using useChart

    main

    For advanced custom crosshairs or markers that exist outside the standard ChartTooltip configuration, do not attempt to track mouse position manually via window event listeners. Instead, use the useChart hook from @bklitui/ui/charts to access the tooltipData provided by the chart context.

    import { useChart } from "@bklitui/ui/charts";
    
    function CustomIndicator() {
      const { tooltipData } = useChart();
      // render from tooltipData
    }
  8. Use Axis components in Line and Area charts

    main

    The Axis components provide date labels (X Axis) and value labels (Y Axis) for line and area charts.

    To use them correctly, you must follow these requirements:

    1. Parent Container: Both components must be placed inside a LineChart or AreaChart component.
    2. Rendering: They are designed to render via a portal into the chart container to ensure proper positioning relative to the axes.
  9. Understand the Studio UI architecture

    main

    Studio UI is the design system specifically for the chart editor (sidebars, property rows, motion controls, and pickers). It is distinct from the chart rendering primitives, which reside in @bklitui/ui.

    Key architectural boundaries:

    • @bklitui/studio: Contains editor-only UI components, including property widgets and the editor shell.
    • @bklitui/ui: Contains the actual chart rendering components.
    • @bklitui/icons: The central icon system used across the ecosystem.

    Note: Studio UI is intended for local development/editor use and is not a deployed public site.