Updated
Energy Flow
NewCustomize
Color
Interval1600ms
Capacity13.5kWh
Battery power3.8kW
Now14.4h
Width420px
Installation
npx shadcn@latest add https://uibrik.com/r/energy-flow.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/energy-flow/energy-flow.tsx"use client"; // A home's power at a glance: solar, battery, grid and the house as four // nodes, with dots flowing along the links at a speed that follows the power // in kW. Tapping a node dims every link it isn't part of and swaps the footer // for that node's breakdown, e.g. where the house's power is coming from. // With no node picked, the footer shows today's totals, which count up live. import { IconBatteryVertical3Filled, IconBuildingFactory2, IconHomeFilled, IconSunFilled } from "@tabler/icons-react"; import { animate, AnimatePresence, motion, useMotionValue, useReducedMotion, useTransform } from "motion/react"; import { useEffect, useId, useMemo, useRef, useState, type CSSProperties, type PointerEvent, type RefObject } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; export type EnergyNode = "solar" | "battery" | "grid" | "home"; export type EnergyReading = { /** Solar production in kW. */ solar: number; /** House load in kW. */ home: number; /** Battery charge, 0–100. */ battery: number;
Adds the files to
components/uibrik/energy-flow and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/energy-flow.Usage
import { EnergyFlow } from "@/components/uibrik/energy-flow/energy-flow";<EnergyFlow title="Energy" color="#e8a317" live interval={1600} capacity={13.5} maxBatteryPower={3.8} showCurve now={14.4} width={420} defaultValue={{ solar: 4.6, home: 2.1, battery: 64 }} defaultSelected={null} // value={{ solar: 0, home: 0, battery: 0 }} // history={{ solar: [0], home: [0] }} // selected="solar" // onSelectedChange="solar"/>Where to use Energy Flow
Smart home and solar apps
Flow speed shows how much power moves where, so the card reads before any number does.
Pairs with Gauge
Energy provider dashboards
Tapping a node answers the usual question, where is this power coming from, without a separate chart.
Pairs with KPI Tile
Climate tech landing pages
A live diagram explains a battery and solar setup in a few seconds.
Props
EnergyFlow- title
- Type string
- "Energy"
- Heading above the diagram.
- color
- Type string
- "#e8a317"
- Colour of solar and battery flows. Grid flows stay neutral.
- live
- Type boolean
- true
- Run the built-in simulation when no value is passed.
- interval
- Type number
- 1600
- Time between simulated readings.
- capacity
- Type number
- 13.5
- Battery size.
- maxBatteryPower
- Type number
- 3.8
- Fastest the battery charges or discharges.
- showCurve
- Type boolean
- true
- Show today's solar and home use under the diagram.
- now
- Type number
- 14.4
- Hour of day the curve stops at.
- width
- Type number
- 420
- Width of the card; never wider than its container.
- value
- Type { solar: number; home: number; battery: number }
- –
- Live readings: solar and home in kW, battery charge 0–100. Pass it to drive the card from your own data.
- defaultValue
- Type { solar: number; home: number; battery: number }
- { solar: 4.6, home: 2.1, battery: 64 }
- Starting readings for the simulation.
- history
- Type { solar: number[]; home: number[] }
- –
- Today's kW by hour, 24 values each, for the curve. Generated when left out.
- selected / onSelectedChange
- Type "solar" | "battery" | "grid" | "home" | null
- –
- Picked node, controlled.
- defaultSelected
- Type EnergyNode | null
- null
- Picked node on mount when uncontrolled.
- className
- Type string
- –
- Classes for the wrapper.