Bar List
solid-ui/bar-listFreeComponent
A bar list component
Live preview
live · rendered by the registry
Rendered by solid-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.solid-ui.com/r/bar-list.jsonSource
1import type { ComponentProps, JSX } from "solid-js"2import { For, mergeProps, Show, splitProps } from "solid-js"3import { Dynamic } from "solid-js/web"45import { cn } from "~/lib/utils"67type Bar<T> = T & {8 value: number9 name: JSX.Element10 icon?: (props: ComponentProps<"svg">) => JSX.Element11 href?: string12 target?: string13}1415type SortOrder = "ascending" | "descending" | "none"1617type ValueFormatter = (value: number) => string1819const defaultValueFormatter: ValueFormatter = (value: number) => value.toString()2021type BarListProps<T> = ComponentProps<"div"> & {22 data: Bar<T>[]23 valueFormatter?: ValueFormatter24 sortOrder?: SortOrder25}2627const BarList = <T,>(rawProps: BarListProps<T>) => {28 const props = mergeProps(29 {30 valueFormatter: defaultValueFormatter,31 sortOrder: "descending" as SortOrder32 },33 rawProps34 )35 const [local, others] = splitProps(props, ["class", "data", "valueFormatter", "sortOrder"])3637 const sortedData = () => {38 if (local.sortOrder === "none") {39 return local.data40 }41 return local.data.sort((a, b) =>42 local.sortOrder === "ascending" ? a.value - b.value : b.value - a.value43 )44 }4546 const widths = () => {47 const maxValue = Math.max(...sortedData().map((item) => item.value), 0)48 return sortedData().map((item) =>49 item.value === 0 ? 0 : Math.max((item.value / maxValue) * 100, 2)50 )51 }5253 return (54 <div55 class={cn("flex flex-col space-y-1.5", local.class)}56 aria-sort={local.sortOrder}57 {...others}58 >59 <For each={sortedData()}>60 {(bar, idx) => {61 return (62 <div class="row flex w-full justify-between space-x-6">63 <div class="grow">64 <div65 class={cn("flex h-8 items-center rounded-md bg-secondary px-2")}66 style={{67 width: `${widths()[idx()]}%`68 }}69 >70 <Show when={bar.icon}>71 {(icon) => <Dynamic component={icon()} class="mr-2 size-5 flex-none" />}72 </Show>73 <Show when={bar.href} fallback={<p>{bar.name}</p>}>74 {(href) => (75 <a76 href={href()}77 target={bar.target ?? "_blank"}78 rel="noreferrer"79 class="hover:underline"80 >81 {bar.name}82 </a>83 )}84// … truncated
What it pulls in
npm packages
Files it writes
More from solid-ui
All 55 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | solid-ui | Components | Free | 2 deps | |
| Alertalert | solid-ui | Components | Free | 3 deps | |
| Alert Dialogalert-dialog | solid-ui | Components | Free | 2 deps | |
| Aspect Ratioaspect-ratio | solid-ui | Components | Free | 1 dep | |
| Avataravatar | solid-ui | Components | Free | 2 deps | |
| Badgebadge | solid-ui | Components | Free | 2 deps | |
| Badge Deltabadge-delta | solid-ui | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | solid-ui | Components | Free | 2 deps |
