glasscn
ShowcaseDocsComponentsStudioThemingNative
5Get started
Guides
IntroductionInstallationThemingFonts & typeStudioReact Native
Surfaces
AuroraBackdropGlassLiquid glassCardTheme scopeBackground extensionScroll areaAccordionCollapsibleAlertItemEmpty
Typography
TypographyProse
Controls
ButtonBadgeInputTextareaLabelSwitchCheckboxSegmented controlTabsGlass groupGlass clusterGlass morphSliderProgressKbdSeparatorAvatarGlass preferencesComboboxCalendarDate pickerSpinnerSkeletonSelectRadio groupFieldInput groupButton groupToggleToggle groupStepper
Overlays
DialogAlert dialogSheetAction sheetPopoverTooltipDropdown menuToasterCommandDrawerContext menuConfirmation popover
Navigation
DockToolbarScroll edgeNavigation barSidebarSearch fieldGrouped list
Data
Activity ringsProgress ringSparklineStatKPIWidgetRange chartBar listGaugeTrackerCategory barHeatmapChartArea chartBar chartLine chartDonut chartTableData table
Chat
ChatChat markdownChat parts
Blocks
More Apple glass examplesLiquid Glass examplesDashboardAnalyticsSettingsSign inChat
glasscn — a shadcn registry. Copy it, own it, change it.DocsThemingregistry.json
Data

Bar list

Ranked horizontal bars with the label inside and the value at the end — top habits, sources, pages.

Installation

pnpm dlx shadcn@latest add https://glasscn.app/r/bar-list.json

React Native (iOS, Android and web through react-native-web) — same parts and props:

pnpm dlx shadcn@latest add https://glasscn.app/r/native-bar-list.json

Or with the namespace set up: shadcn add @glasscn-app/bar-list

Props

PropTypeDefault
data{ name, value, href?, icon?, key? }[]

Rows in display order — sort them yourself.

—
maxnumber

What a full-width bar means, e.g. 30 days.

the largest value
valueFormat(value: number) => ReactNodetoLocaleString
colorstring

Bars are a 22% wash of it.

"var(--primary)"
onSelect(item, index) => void

Makes rows buttons (or runs on link click).

—

Source

components/glass/bar-list.tsx
import * as React from "react"
import { cn } from "@/lib/glass-cn"

import { barShares, drawEase, glassTime } from "@/lib/glass-charts"

export interface BarListItem {
  name: React.ReactNode
  value: number
  /** Makes the row a link. */
  href?: string
  icon?: React.ReactNode
  /** Stable key when `name` isn't a string. */
  key?: string
}

/**
 * Ranked horizontal bars: label inside the bar, value at the end. Bars grow in
 * once; widths are shares of the largest value (or `max`). Sort the items
 * yourself — the list keeps your order.
 */
function BarList({
  data,
  max,
  valueFormat = (v) => v.toLocaleString(),
  color = "var(--primary)",
  onSelect,
  className,
  ...props
}: Omit<React.ComponentProps<"ul">, "onSelect"> & {
  data: BarListItem[]
  max?: number
  valueFormat?: (value: number) => React.ReactNode
  color?: string
  onSelect?: (item: BarListItem, index: number) => void
}) {
  const shares = barShares(
    data.map((d) => d.value),
    max
  )
  return (
    <ul data-slot="bar-list" className={cn("grid gap-[calc(0.375rem*var(--glass-density))]", className)} {...props}>
      {data.map((item, i) => {
        const body = (
          <>
            <span className="relative min-w-0 flex-1">
              <span
                data-slot="bar-list-bar"
                aria-hidden
                data-glass-motion
                className="absolute inset-y-0 start-0 origin-left rounded-control-sm rtl:origin-right"
                style={{
                  width: `max(${shares[i]}%, 0.375rem)`,
                  background: `color-mix(in oklch, ${color} 22%, transparent)`,
                  animation: `glass-grow ${glassTime(4)} ${drawEase} ${glassTime(i * 0.2)} both`,
                }}
              />
              <span className="relative flex h-control-sm items-center gap-2 px-pad-xs text-sm">
                {item.icon ? <span className="shrink-0 text-muted-foreground [&_svg:not([class*='size-'])]:size-4">{item.icon}</span> : null}
                <span className="truncate">{item.name}</span>
              </span>
            </span>
            <span data-slot="bar-list-value" className="shrink-0 text-sm font-medium numeric-glass">
              {valueFormat(item.value)}
            </span>
          </>
        )
        const row = "glass-focus flex w-full items-center gap-3 rounded-control-sm text-start"
        const key = item.key ?? (typeof item.name === "string" ? item.name : i)
        return (
          <li key={key} data-slot="bar-list-item">
            {item.href ? (
              <a href={item.href} className={cn(row, "transition-colors duration-(--glass-duration) ease-glass hover:bg-fill")} onClick={onSelect ? () => onSelect(item, i) : undefined}>
                {body}
              </a>
            ) : onSelect ? (
              <button type="button" className={cn(row, "cursor-pointer transition-colors duration-(--glass-duration) ease-glass hover:bg-fill")} onClick={() => onSelect(item, i)}>
                {body}
              </button>
            ) : (
              <div className={row}>{body}</div>
            )}
          </li>
        )
      })}
    </ul>
  )
}

export { BarList }
Range chartGauge
HabitDays this month
  • Walk 8k steps26/30
  • Read 20 pages22/30
  • Lights out by 1119/30
  • Strength session12/30
  • Meditate8/30