Tables

Share Table

A share table: the bar is the cell's own background, and the share is computed from the row total, so the sum always adds up.

  • table
  • share
  • bars
  • analytics

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/table-010?lang=en

Traffic sources
ИсточникВизитыДоля
Поиск18 40246,1 %
Прямые заходы7 11817,8 %
Соцсети6 94017,4 %
Письма4 23310,6 %
Реклама3 2118,0 %
Всего39 904100,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-010" (Share Table) 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-010.json

Registry item: https://vibeui.ru/r/table-010.json
Installs to: components/vibeui/table-010.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 share table: the bar is the cell's own background, and the share is computed from the row total, so the sum always adds up.

A source table with shares: a bar inside the cell, the figure beside it and a total at the bottom. Zero dependencies, one file, no client JS.

## 3. How to use it
import { Table010 } from "@/components/vibeui/table-010"

<Table010 rows={[{ source: "Search", visits: 18402 }]} />

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-010-* palette — do not swap it for your theme tokens
- the bar as the cell background: no extra element and no chart library
- computing the share from the row total — a separately supplied share stops adding up
- the figure next to the bar: the bar shows the ratio, the number gives precision
- the total row in tfoot rather than in the body
- tabular figures in the numeric columns

## 6. You may change
- the rows array and the caption
- the bar colour
- the number of decimals
- the accent through the accent prop

## 7. Rules
- Rows are not sorted automatically: sort the data outside for a descending order.
- Rounding to tenths can total 99.9% or 100.1% — the total comes from the sum, not the percentages.
- Bars cannot show change over time: use a chart from the charts category.
- 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-010.json
https://vibeui.ru/r/table-010.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-table-010-*. Серверный: хуков нет. Полоса — линейный градиент в фоне ячейки: ни лишнего элемента, ни библиотеки графиков. Доля вычисляется от суммы визитов, итоговая строка выводит эту же сумму.

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 Table010Row = {
  source: string
  visits: number
}

export type Table010Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  rows?: Table010Row[]
  caption?: string
  accent?: string
}

// Идея компонента: таблица долей с полосой прямо в ячейке. Полоса рисуется
// градиентом фона по проценту, поэтому не добавляет ни элемента, ни библиотеки.
// Число остаётся рядом: полоса показывает соотношение, а точную величину
// читают цифрой. Доля считается от суммы строк, а не задаётся отдельно, —
// иначе итог перестаёт сходиться при правке данных.
const STYLES = `
:where([data-vibeui-block="table-010"]){
--vibeui-table-010-bg:oklch(1 0 0);
--vibeui-table-010-fg:oklch(0.24 0.014 265);
--vibeui-table-010-muted:oklch(0.56 0.014 265);
--vibeui-table-010-border:oklch(0.92 0.006 265);
--vibeui-table-010-head:oklch(0.975 0.003 265);
--vibeui-table-010-bar:oklch(0.55 0.2 262 / 16%);
--vibeui-table-010-accent:oklch(0.55 0.2 262);
--vibeui-table-010-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="table-010"]{
width:100%;box-sizing:border-box;overflow-x:auto;
background:var(--vibeui-table-010-bg);
border:1px solid var(--vibeui-table-010-border);border-radius:0.875rem;
font-family:var(--vibeui-table-010-font);color:var(--vibeui-table-010-fg);
}
[data-vibeui-block="table-010"] table{width:100%;border-collapse:collapse;font-size:0.8125rem}
[data-vibeui-block="table-010"] caption{padding:0.75rem 0.875rem;text-align:left;font-size:0.875rem;font-weight:650}
[data-vibeui-block="table-010"] th,
[data-vibeui-block="table-010"] td{
padding:0.5rem 0.875rem;text-align:left;white-space:nowrap;
border-top:1px solid var(--vibeui-table-010-border);
}
[data-vibeui-block="table-010"] thead th{background:var(--vibeui-table-010-head);font-weight:600}
[data-vibeui-block="table-010"] [data-align="end"]{text-align:right;font-variant-numeric:tabular-nums}
/* Полоса — фон ячейки: лишний элемент и библиотека графиков не нужны. */
[data-vibeui-block="table-010"] [data-part="share"]{
min-width:9rem;
background:linear-gradient(to right,var(--vibeui-table-010-bar) var(--vibeui-table-010-fill),transparent var(--vibeui-table-010-fill));
}
[data-vibeui-block="table-010"] tfoot td{
font-weight:650;background:var(--vibeui-table-010-head);
}
[data-vibeui-block="table-010"] [data-part="total"]{color:var(--vibeui-table-010-muted);font-weight:600}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="table-010"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ROWS: Table010Row[] = [
  { source: "Поиск", visits: 18402 },
  { source: "Прямые заходы", visits: 7118 },
  { source: "Соцсети", visits: 6940 },
  { source: "Письма", visits: 4233 },
  { source: "Реклама", visits: 3211 },
]

/**
 * Таблица долей: полоса рисуется фоном ячейки, число остаётся рядом.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Table010({
  rows = DEFAULT_ROWS,
  caption = "Источники трафика",
  accent,
  className,
  style,
  ...props
}: Table010Props) {
  const total = rows.reduce((sum, row) => sum + row.visits, 0)

  const palette = {
    ...(accent ? { "--vibeui-table-010-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-table-010" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="table-010"
        className={className}
        style={palette}
      >
        <table>
          <caption>{caption}</caption>
          <thead>
            <tr>
              <th scope="col">Источник</th>
              <th scope="col" data-align="end">
                Визиты
              </th>
              <th scope="col" data-align="end">
                Доля
              </th>
            </tr>
          </thead>
          <tbody>
            {rows.map((row) => {
              const share = total ? (row.visits / total) * 100 : 0
              return (
                <tr key={row.source}>
                  <td>{row.source}</td>
                  <td data-align="end">{row.visits.toLocaleString("ru-RU")}</td>
                  <td
                    data-part="share"
                    data-align="end"
                    style={
                      {
                        "--vibeui-table-010-fill": `${share.toFixed(1)}%`,
                      } as CSSProperties
                    }
                  >
                    {share.toLocaleString("ru-RU", {
                      minimumFractionDigits: 1,
                      maximumFractionDigits: 1,
                    })}{" "}
                    %
                  </td>
                </tr>
              )
            })}
          </tbody>
          <tfoot>
            <tr>
              <td data-part="total">Всего</td>
              <td data-align="end">{total.toLocaleString("ru-RU")}</td>
              <td data-align="end">100,0 %</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </>
  )
}