Tables
Share Totals
A table with a totals row that sets the scale: each row's share is computed against the total and drawn as a bar right in the cell beside the number.
- table
- totals
- share
- report
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/table-019?lang=en
| Источник | Значение | Доля |
|---|---|---|
| Поискорганика | 4 120 | 44,6% |
| Рассылкаписьма и дайджест | 2 480 | 26,8% |
| Рекомендациивнутри продукта | 1 310 | 14,2% |
| Соцсетипосты и сторис | 860 | 9,3% |
| Партнёрыинтеграции | 470 | 5,1% |
| Totalпо 5 источникам, visits | 9 240 | 100,0% |
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "table-019" (Share Totals) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/table-019.json
Registry item: https://vibeui.ru/r/table-019.json
Installs to: components/vibeui/table-019.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A table with a totals row that sets the scale: each row's share is computed against the total and drawn as a bar right in the cell beside the number.
A table with a totals row in tfoot and each row's share of that total. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Table019 } from "@/components/vibeui/table-019"
<Table019
caption="Traffic sources this week"
totalLabel="Total"
/>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-table-019-* palette — do not swap it for your theme tokens
- tfoot for the total: otherwise the sum row sorts and prints like any other row
- the share number beside the bar: an aria-hidden bar announces nothing on its own
- computing shares from the row sum rather than an external number: otherwise the shares stop adding to 100%
- the unit explanation in the total label: "total 9,240" of what says nothing
- the component's own light surface: dark text disappears on the dark catalog card
## 6. You may change
- the sources and their values through rows
- the unit of measurement through unit
- the totals row caption through totalLabel
- the table caption through caption
## 7. Rules
- Shares are rounded to one decimal, so they may add up to 99.9% — the total prints 100.0% on purpose.
- Negative values break the bar: it assumes non-negative contributions to a sum.
- The bar is capped at 6rem, otherwise it eats the whole column on a wide screen.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/table-019.jsonhttps://vibeui.ru/r/table-019.jsonКомпонент самодостаточен: один файл, без зависимостей, палитра в переменных --vibeui-table-019-*. Серверный: итог и доли считаются при рендере. Итог лежит в tfoot и отбит двойной линией — принятый в отчётах знак «ниже сумма». Доля печатается числом и дублируется полоской: ширина заливки приходит инлайновой переменной --vibeui-table-019-fill, потому что это динамическое значение, которое нельзя выразить классом. Полоска закрыта aria-hidden, смысл несёт текст рядом. Подпись итога дополнительно объясняет, что именно просуммировано и в каких единицах: «итого» без единиц — самая частая ошибка отчётных таблиц.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Table019Row = {
title: string
hint?: string
value: number
}
export type Table019Props = Omit<
ComponentPropsWithoutRef<"div">,
"children"
> & {
rows?: Table019Row[]
unit?: string
caption?: string
/** Подпись итоговой строки: она же объясняет, что именно просуммировано. */
totalLabel?: string
accent?: string
}
// Идея компонента: итог снизу не просто повторяет сумму — он задаёт масштаб.
// Доля каждой строки считается от итога и рисуется полоской прямо в ячейке,
// поэтому «412» и «41%» стоят рядом. Полоска — оформление, число рядом с ней
// остаётся текстом, иначе доля пропадёт для скринридера.
const STYLES = `
:where([data-vibeui-block="table-019"]){
--vibeui-table-019-bg:oklch(1 0 0);
--vibeui-table-019-fg:oklch(0.24 0.014 265);
--vibeui-table-019-muted:oklch(0.56 0.014 265);
--vibeui-table-019-border:oklch(0.92 0.006 265);
--vibeui-table-019-head:oklch(0.975 0.003 265);
--vibeui-table-019-accent:oklch(0.55 0.2 262);
--vibeui-table-019-track:oklch(0.93 0.008 265);
--vibeui-table-019-fill:0%;
--vibeui-table-019-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="table-019"]{
width:100%;box-sizing:border-box;
font-family:var(--vibeui-table-019-font);color:var(--vibeui-table-019-fg);
}
[data-vibeui-block="table-019"] [data-part="shell"]{
background:var(--vibeui-table-019-bg);
border:1px solid var(--vibeui-table-019-border);border-radius:1rem;overflow:hidden;
}
[data-vibeui-block="table-019"] [data-part="scroll"]{overflow-x:auto}
[data-vibeui-block="table-019"] [data-part="scroll"]:focus-visible{
outline:2px solid var(--vibeui-table-019-accent);outline-offset:-2px;
}
[data-vibeui-block="table-019"] table{width:100%;border-collapse:collapse;font-size:0.8125rem;min-width:24rem}
[data-vibeui-block="table-019"] caption{
padding:0.875rem 1rem 0.5rem;text-align:left;font-size:0.9375rem;font-weight:650;
}
[data-vibeui-block="table-019"] th,
[data-vibeui-block="table-019"] td{
padding:0.5rem 0.875rem;text-align:left;
border-top:1px solid var(--vibeui-table-019-border);
}
[data-vibeui-block="table-019"] thead th{
background:var(--vibeui-table-019-head);font-weight:600;white-space:nowrap;
}
[data-vibeui-block="table-019"] thead th:not(:first-child){text-align:right}
[data-vibeui-block="table-019"] tbody th{font-weight:500}
[data-vibeui-block="table-019"] [data-align="end"]{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
[data-vibeui-block="table-019"] [data-part="hint"]{
display:block;font-size:0.75rem;font-weight:400;color:var(--vibeui-table-019-muted);
}
[data-vibeui-block="table-019"] [data-part="share"]{
display:flex;align-items:center;justify-content:flex-end;gap:0.5rem;
}
[data-vibeui-block="table-019"] [data-part="track"]{
flex:1 1 4rem;max-width:6rem;height:0.375rem;border-radius:9999px;
background:var(--vibeui-table-019-track);overflow:hidden;
}
[data-vibeui-block="table-019"] [data-part="fill"]{
display:block;height:100%;width:var(--vibeui-table-019-fill);
background:var(--vibeui-table-019-accent);border-radius:inherit;
}
[data-vibeui-block="table-019"] [data-part="percent"]{
min-width:2.75rem;text-align:right;font-variant-numeric:tabular-nums;
color:var(--vibeui-table-019-muted);
}
/* Итог отбит двойной линией: это принятый в отчётах знак «ниже — сумма». */
[data-vibeui-block="table-019"] tfoot th,
[data-vibeui-block="table-019"] tfoot td{
border-top:3px double var(--vibeui-table-019-border);
background:var(--vibeui-table-019-head);font-weight:700;
padding-top:0.625rem;padding-bottom:0.625rem;
}
[data-vibeui-block="table-019"] tfoot [data-part="hint"]{font-weight:400}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="table-019"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_ROWS: Table019Row[] = [
{ title: "Поиск", hint: "органика", value: 4120 },
{ title: "Рассылка", hint: "письма и дайджест", value: 2480 },
{ title: "Рекомендации", hint: "внутри продукта", value: 1310 },
{ title: "Соцсети", hint: "посты и сторис", value: 860 },
{ title: "Партнёры", hint: "интеграции", value: 470 },
]
function group(value: number) {
return Math.round(value)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, " ")
}
/**
* Таблица с итоговой строкой снизу и долей каждой строки от итога.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Table019({
rows = DEFAULT_ROWS,
unit = "визитов",
caption = "Источники трафика за неделю",
totalLabel = "Итого",
accent,
className,
style,
...props
}: Table019Props) {
const palette = {
...(accent ? { "--vibeui-table-019-accent": accent } : null),
...style,
} as CSSProperties
const total = rows.reduce((sum, row) => sum + row.value, 0)
return (
<>
<style href="vibeui-table-019" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="table-019"
className={className}
style={palette}
>
<div data-part="shell">
<div
data-part="scroll"
role="region"
aria-label={caption}
tabIndex={0}
>
<table>
<caption>{caption}</caption>
<thead>
<tr>
<th scope="col">Источник</th>
<th scope="col">Значение</th>
<th scope="col">Доля</th>
</tr>
</thead>
<tbody>
{rows.map((row) => {
const percent = total ? (row.value / total) * 100 : 0
return (
<tr key={row.title}>
<th scope="row">
{row.title}
{row.hint ? (
<span data-part="hint">{row.hint}</span>
) : null}
</th>
<td data-align="end">{group(row.value)}</td>
<td data-align="end">
<span data-part="share">
<span
data-part="track"
aria-hidden="true"
style={
{
"--vibeui-table-019-fill": `${percent.toFixed(1)}%`,
} as CSSProperties
}
>
<span data-part="fill" />
</span>
<span data-part="percent">
{percent.toFixed(1).replace(".", ",")}%
</span>
</span>
</td>
</tr>
)
})}
</tbody>
<tfoot>
<tr>
<th scope="row">
{totalLabel}
<span data-part="hint">
по {rows.length} источникам, {unit}
</span>
</th>
<td data-align="end">{group(total)}</td>
<td data-align="end">100,0%</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</>
)
}