Krizaka UI
Krizaka UI
Composants

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.

Web · ✓Mobile · ✗ à construireBureau · ✓BêtaAffichage de données
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 tailwindcss

Styles

@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.

PropTypeDéfautDescription
balancerequisnumber—Credits left.
labelrequisstring—What the balance is (« Crédits »): the heading and the meter's name.
totalrequisnumber—The allowance of the period; the meter fills with what is left.
actionReactNode—The way to buy more: a link or a button.
localestringfr-CADefault fr-CA.
renewalReactNode—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.

PropTypeDéfautDescription
hrefrequisstring—The page's path (and any other parameters); each period is a link to it with ?period=.
labelrequisstring—The accessible name (« Période »).
valuerequisnumber—The period shown, from parsePeriod(searchParams.period).
linkAsLinkComponent—The app's router link (Next's Link); default a plain <a>.
localestringfr-CADefault fr-CA.
paramstringperiodThe query parameter. Default period.
periodLabel((days: number) => string)—The text of a period. Default 7 j (7 d for an English locale).
periodsreadonly number[][7, 30, 90] as constThe 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).

PropTypeDéfautDescription
columnsrequis{ day: string; total: string; }—The text version's column headings: the day, the total.
daysrequisreadonly UsageDay[]—The days, oldest first.
emptyLabelrequisstring—Said when there is nothing in the period.
outcomesrequisreadonly UsageOutcome[]—The outcomes stacked in each bar, bottom first.
loadingboolean—The data is on its way: a skeleton keeps the height.
localestringfr-CADefault fr-CA.

UsageTiles

The figures of the period on the strip, each compared with the previous period in words.

PropTypeDéfautDescription
tilesrequisreadonly UsageTileInput[]—2 to 4 figures.
loadingboolean—The data is on its way: the row keeps its height.
localestring—The language of the figures and the words. Default fr-CA.
periodReactNode—The period switch, above the row.
wordsPartial<UsageWords>—Your own words for the change: {change} is the percentage.

Accessibilité

  • CreditsMeter is a role=meter named by its label, its value in words (« 820 sur 1 000 »); its tone is never the only signal.
  • PeriodSwitch is a navigation of links; the shown period is aria-current="page".
  • UsageChart is 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

TouchesAction
Tab / EnterMoves through the periods; each is a link.

Bonnes pratiques

  • Read the period with parsePeriod(searchParams.period) and pass it to PeriodSwitch and to the query: the server renders the period, the address can be shared.
  • UsageTiles computes the change against the previous period from previous and says it in words (« +12 % vs période précédente »); French and fr-CA figures are the default, locale="en" switches both.
  • Put a Sparkline of @krizaka/charts (64 × 18) in a tile's chart; the tiles stay on the strip, never four full-width stats.
  • Pass outcomes in the order they should stack, bottom first; tones are the tokens' (success, danger…), never colours.
  • Show loading while the data is on its way and give an emptyLabel that says what to do next.

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

Sur cette page