Usage
The blocks of a « Credits & usage » page: the balance on a meter, the period switch (the address holds it), the figures on a strip with their trend in words, and the activity stacked by outcome.
import { CreditsMeter, PeriodSwitch, UsageTiles, UsageChart, parsePeriod } from "@krizaka/ui/usage";Web uniquement — React, depuis @krizaka/ui/usage. Bêta : son API peut encore changer à une version mineure.
- Mobile · ✗ à construire. The phone apps show their credits through Meter and Stat by hand; a native twin of the blocks follows the first app that moves onto them. issue #728
Pourquoi il est là. Yomizaka « Crédits et usage » (krizaka/yomizaka#314), Akinaza's activity panel (akinaza#325); Orazaka moves onto it in its dispatch.
Quand l’utiliser
- A « Credits & usage » page or panel: what is left, how it was used over 7, 30 or 90 days, and what happened to each run.
- Any metered product (checks, runs, storage) that bills or limits by credits.
Quand ne pas l’utiliser
- A single quota against a plan, with no period.À la place : Quota meter
- A free-form dashboard of charts.À la place : Dashboard layout
- A single key figure.À la place : Stat
Installation
Installer
npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcssStyles
@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";Importer
import { CreditsMeter, PeriodSwitch, UsageTiles, UsageChart, parsePeriod } from "@krizaka/ui/usage";Exemples
Credits & usage
The balance, the period switch, the strip of figures and the activity by outcome (demo data).
Loading and empty
The skeletons while the data is on its way, then the empty state.
Props
CreditsMeter
The balance: the figure large, a meter that turns to warning then danger as it runs low, the renewal and the way to buy.
| Prop | Type | Défaut | Description |
|---|---|---|---|
balancerequis | number | — | Credits left. |
labelrequis | string | — | What the balance is (« Crédits »): the heading and the meter's name. |
totalrequis | number | — | The allowance of the period; the meter fills with what is left. |
action | ReactNode | — | The way to buy more: a link or a button. |
locale | string | fr-CA | Default fr-CA. |
renewal | ReactNode | — | The renewal, written by the app (« Renouvelés le 1er novembre »). |
PeriodSwitch
7 · 30 · 90 d: links, so the address holds the period (?period=30) and the server renders it.
| Prop | Type | Défaut | Description |
|---|---|---|---|
hrefrequis | string | — | The page's path (and any other parameters); each period is a link to it with ?period=. |
labelrequis | string | — | The accessible name (« Période »). |
valuerequis | number | — | The period shown, from parsePeriod(searchParams.period). |
linkAs | LinkComponent | — | The app's router link (Next's Link); default a plain <a>. |
locale | string | fr-CA | Default fr-CA. |
param | string | period | The query parameter. Default period. |
periodLabel | ((days: number) => string) | — | The text of a period. Default 7 j (7 d for an English locale). |
periods | readonly number[] | [7, 30, 90] as const | The periods offered, in days. Default 7 · 30 · 90. |
UsageChart
The activity of the period, one bar per day stacked by outcome — with its legend and its text version (a table).
| Prop | Type | Défaut | Description |
|---|---|---|---|
columnsrequis | { day: string; total: string; } | — | The text version's column headings: the day, the total. |
daysrequis | readonly UsageDay[] | — | The days, oldest first. |
emptyLabelrequis | string | — | Said when there is nothing in the period. |
outcomesrequis | readonly UsageOutcome[] | — | The outcomes stacked in each bar, bottom first. |
loading | boolean | — | The data is on its way: a skeleton keeps the height. |
locale | string | fr-CA | Default fr-CA. |
UsageTiles
The figures of the period on the strip, each compared with the previous period in words.
| Prop | Type | Défaut | Description |
|---|---|---|---|
tilesrequis | readonly UsageTileInput[] | — | 2 to 4 figures. |
loading | boolean | — | The data is on its way: the row keeps its height. |
locale | string | — | The language of the figures and the words. Default fr-CA. |
period | ReactNode | — | The period switch, above the row. |
words | Partial<UsageWords> | — | Your own words for the change: {change} is the percentage. |
Accessibilité
CreditsMeteris arole=meternamed by its label, its value in words (« 820 sur 1 000 »); its tone is never the only signal.PeriodSwitchis a navigation of links; the shown period isaria-current="page".UsageChartis a figure with a caption; the bars are decorative and the text version is a table with every day and outcome.- Loading is
aria-busy; the skeleton does not animate under reduced motion.
Clavier
| Touches | Action |
|---|---|
| Tab / Enter | Moves through the periods; each is a link. |
Bonnes pratiques
- Read the period with
parsePeriod(searchParams.period)and pass it toPeriodSwitchand to the query: the server renders the period, the address can be shared. UsageTilescomputes the change against the previous period frompreviousand says it in words (« +12 % vs période précédente »); French andfr-CAfigures are the default,locale="en"switches both.- Put a
Sparklineof @krizaka/charts (64 × 18) in a tile'schart; the tiles stay on the strip, never four full-width stats. - Pass
outcomesin the order they should stack, bottom first; tones are the tokens' (success,danger…), never colours. - Show
loadingwhile the data is on its way and give anemptyLabelthat says what to do next.
Composants liés
Générée depuis le code de @krizaka/ui 3.63.1 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub