Bar List

A ranked list where each row has a bar sized to its value, such as top pages by visits.

Yahoo
Direct
Github
Yandex
Bing
Google
ChatGPT
20K
100K
100K
100K
200K
1.2M
1.35M

Usage

Code
import { BarList, useChart } from '@leverui/components';
Code
function TrafficList() {
  const chart = useChart({
    data: [
      { name: 'Direct', value: 50 },
      { name: 'Referral', value: 25 },
    ],
    series: [{ name: 'name', color: 'teal.subtle' }],
  });

  return (
    <BarList.Root chart={chart}>
      <BarList.Title>Traffic</BarList.Title>
      <BarList.Content>
        <BarList.Label title="Source" flex="1">
          <BarList.Bar tooltip />
        </BarList.Label>
        <BarList.Label title="Visits">
          <BarList.Value />
        </BarList.Label>
      </BarList.Content>
    </BarList.Root>
  );
}

Examples

Basic

Render the descending search source list.

ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo
1.35M
1.2M
200K
100K
100K
100K
20K

Formatter

Show each funnel value and its share of the total.

Created
Initial contact
Booked demo
Closed
120 (45%)
90 (34%)
45 (17%)
10 (4%)

Label

Label the bar and value columns.

Search engine
ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo
Visits
1.35M
1.2M
200K
100K
100K
100K
20K

Turn funnel names into links while preserving the bar widths.

Multi Value

Add a separate percentage column.

Search engine
ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo
Visits
1.35M
1.2M
200K
100K
100K
100K
20K
%
43.88%
39.15%
6.53%
3.26%
3.26%
3.26%
0.65%

Tooltip

Reveal the full numeric value when hovering a bar.

Search engine
ChatGPT
Google
Bing
Direct
Github
Yandex
Yahoo
Visits
1.35M
1.2M
200K
100K
100K
100K
20K

Props

Root

PropDefaultTypeDescription
chart—UseChartReturn<BarListData>Value returned by useChart. Required.
barSize2.5remstringRow height.

barSize and the minW prop of Label take a spacing token such as "12" (3rem) or a CSS length such as "48px".

Label

PropDefaultTypeDescription
title—JSX.ElementColumn heading. Required.
titleAlignment—stringCSS text-align of the heading, such as right.
flex—string | numberCSS flex of the column. 1 fills space.
minW—stringNarrowest the column gets.

Optional column. Put a Bar or a Value inside it.

Bar

PropDefaultTypeDescription
label—functionRender your own content in place of the name.
tooltipfalseboolean | functionShow the row's value on hover and focus.

label gets { payload, index }: the data row and its position in the list. A tooltip function gets { payload } and renders your own tooltip.

The largest value gets the longest bar. The others are sized against it.

Value

PropDefaultTypeDescription
valueFormatter—(value: number) => JSX.ElementFormat each number.

Without valueFormatter, numbers are short, with up to two decimal places, such as 1.25K.

Tooltip

PropDefaultTypeDescription
payload—BarListDataRow the tooltip belongs to. Required.
labelFormatter—(value: number) => JSX.ElementFormat the value.

Bar adds this part for you when tooltip is on. Without labelFormatter, it shows the full number.

Title and Content have no props of their own. Other attributes and event handlers go to each part's outer element.

Data fields

FieldTypeDescription
namestringName shown on the row. Required.
valuenumberNumber the bar stands for. Required.
hrefstringLink for the row. Read it in a custom label.

Pass sort to useChart to order the rows.

Bar color: add a series entry named 'name' with a color, a token such as teal.subtle or a CSS color. Default: teal.subtle.

Keyboard

Each row takes focus when tooltip is on.

KeyAction
TabNext row. Shows its value.

Styling

Code
<BarList.Root chart={chart} class="traffic-list">
  ...
</BarList.Root>
Code
.traffic-list {
  --leverui-bar-list-size: 3rem;
}

.traffic-list .leverui-bar-list__fill {
  border-radius: 0.75rem;
}

Variables

VariableDefaultDescription
--leverui-bar-list-size2.5remRow height.

barSize sets this variable on one list.

Classes

Parts, each prefixed with .leverui-bar-list__: root, title, content, label, labelHeading, bar, row, fill, rowLabel, value, valueRow, tooltip.

A hovered or focused row has data-hovered and, by default, a light background.