仕組み
The curve is one SVG path computed once for the largest deposit, against a y scale rounded up to a gridline; the gridlines and their labels never move. Because every deposit gives the same shape at a different height, a new deposit is a CSS transition of scaleY on the curve group from the baseline; the strokes keep their width with vector-effect: non-scaling-stroke, and the handle glides on its own vertical track with the same duration and curve, so it stays on the line the whole way. The handle is two nested elements, one moving across the years and one up and down, and a clip rectangle scaled to the handle's position makes the area and line solid up to it. The tip above the handle hangs below it near the top of the chart and slides inward at the ends. Pressing anywhere on the chart moves the handle there; on touch a sideways drag moves it and a vertical swipe scrolls the page.
向いている場面
- Savings, pension or investment calculators where the shape of growth matters more than exact figures.
- Onboarding for a savings goal: pick a monthly amount and see where it leads.
- Any projection that grows by a fixed rule and has one natural input to compare.
向かない場面
- Real historical performance: use a line chart with actual data.
- Projections with several inputs that change the shape (fees, withdrawals, varying rates): use a form with a full chart.
- Anywhere a precise figure is legally binding; this is an estimate.
使い方
import { useState } from 'react'
import { GrowthCurve } from './GrowthCurve.jsx'
export function SavingsCard() {
const [deposit, setDeposit] = useState(250)
const [year, setYear] = useState(10)
return (
<GrowthCurve
title="Savings plan"
subtitle="Rainy-day fund"
presets={[100, 250, 500]}
deposit={deposit}
onDepositChange={setDeposit}
rate={0.05}
years={10}
value={year}
onChange={setYear}
footnote="Assumes 5% a year, compounded monthly."
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
deposit / defaultDeposit / onDepositChange | number / number / (deposit) => void | - / middle preset or 250 / - | Controlled or uncontrolled monthly deposit, and a callback when a preset is chosen. |
presets | number[] | — | Monthly amounts offered as a segmented control under the chart. The largest one fixes the y scale, so switching only lifts or lowers the curve. |
rate | number | 0.05 | Yearly return as a fraction, compounded monthly. |
years | number | 10 | Length of the projection: the last year on the axis. |
value / defaultValue / onChange | number / number / (year) => void | - / years / - | Controlled or uncontrolled selected year (1 to years), and a callback with the snapped year while dragging. |
format | (amount) => string | US dollars, no cents | Formats the hero, the growth delta and the presets, for example with Intl.NumberFormat for another currency. |
formatAxis | (amount) => string | compact US dollars | Formats the gridline labels, which stay put while the curve moves; a compact form such as $20K fits best. |
title / subtitle / icon | ReactNode | — | Title row: the title, a muted qualifier after it, and an icon in a tinted square. |
footnote | ReactNode | — | Small print under the card, such as the assumed return. |
color | 1–8 | string | 1 | Hue of the curve, area and handle: chart palette index or any CSS colour. |
labels | object | — | Replaces built-in text: caption, growth, year, tick, handle, value, deposit, preset. Shallow-merged over the English defaults. |
replayKey | any | — | Change it to play the entrance again, for example after the rate changes. |
...rest | HTMLAttributes | — | Other attributes go to the root <section>. |
アクセシビリティ
- The handle is a role="slider" from year 1 to the last year; aria-valuetext reads the year and the estimated amount.
- Arrow keys move one year, Page Up and Page Down five, Home and End jump to the ends.
- The deposit presets are a radio group named by labels.deposit; arrow keys move the choice.
- The focus ring shows for the keyboard and hides after pointer use.
- Reduced motion shows the final chart and numbers without drawing, counting or gliding.
モーション
Entrance (900ms, cubic-bezier(0.22, 1, 0.36, 1)): the line draws from the left, the area rises from the baseline 80ms behind it, the hero and the growth count up, the handle pops with a light spring when the line reaches it and the tip follows. Picking a year: the handle and the solid area glide 320ms ease-out (140ms while dragging) and the numbers count to the new value in 480ms. A new deposit: the curve scales 640ms on the reveal curve while the handle rides with it.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
GrowthCurve.jsxgrowth-curve.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



