PartToWhole
One whole, split into its parts: what a pie chart would show, in a bar that can actually be compared and read.
import { PartToWhole } from '@sypnia/ui/react'
Tall and thin
- Tables
- Files
- Backups
- Logs
- Tables56%
- Files25%
- Backups16%
- Logs3%
Code
import { PartToWhole, useSypnia } from '@sypnia/ui/react';
const parts = [
{ label: 'Tables', value: 21_495_808 },
{ label: 'Files', value: 9_437_184 },
{ label: 'Backups', value: 6_291_456 },
{ label: 'Logs', value: 1_048_576 },
];
export default function Storage() {
const { format } = useSypnia();
return (
<div className="sy-stack" style={{ ['--gap' as string]: 'var(--s-6)' }}>
<PartToWhole tall label="Storage by kind" parts={parts} formatValue={format.bytes} />
<PartToWhole label="Storage by kind" parts={parts} formatValue={format.bytes} />
</div>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
- Tables62%
- Files28%
- Backups10%
Code
import { PartToWhole, PartToWholeSkeleton } from '@sypnia/ui/react';
// The bar and the legend, before the parts are measured.
export default function Skeleton() {
return (
<div className="sy-grid">
<PartToWhole label="Storage by kind" parts={[{ label: 'Tables', value: 62 }, { label: 'Files', value: 28 }, { label: 'Backups', value: 10 }]} />
<PartToWholeSkeleton parts={3} />
</div>
);
} When to use it
Use it when
- One total and its two to five parts: storage by kind, requests by result, a plan’s usage by product.
- tall when the shares themselves are the message; thin inside rows and cards.
Do not use it when
- Parts change over time: use a stacked BarChart.
- More than five parts: group the small ones as «Other».
- The parts do not add up to a meaningful whole.
For everyone
- Each part can be focused and gives its name, amount and share.
- The legend names every part, so colour is never the only key.
Props
| PartToWhole | Type | Default |
|---|---|---|
labelrequired | string | |
partsrequired | { label: string; value: number; }[] | |
formatValue | ((v: number) => string) | |
tall | boolean |