import type { ComponentProps, JSX } from "solid-js" import { For, mergeProps, Show, splitProps } from "solid-js" import { Dynamic } from "solid-js/web" import { cn } from "~/styles/utils" type Bar = T & { value: number name: JSX.Element icon?: (props: ComponentProps<"svg">) => JSX.Element href?: string target?: string } type SortOrder = "ascending" | "descending" | "none" type ValueFormatter = (value: number) => string const defaultValueFormatter: ValueFormatter = (value: number) => value.toString() type BarListProps = ComponentProps<"div"> & { data: Bar[] valueFormatter?: ValueFormatter sortOrder?: SortOrder } const BarList = (rawProps: BarListProps) => { const props = mergeProps( { valueFormatter: defaultValueFormatter, sortOrder: "descending" as SortOrder }, rawProps ) const [local, others] = splitProps(props, ["class", "data", "valueFormatter", "sortOrder"]) const sortedData = () => { if (local.sortOrder === "none") { return local.data } return local.data.sort((a, b) => local.sortOrder === "ascending" ? a.value - b.value : b.value - a.value ) } const widths = () => { const maxValue = Math.max(...sortedData().map((item) => item.value), 0) return sortedData().map((item) => item.value === 0 ? 0 : Math.max((item.value / maxValue) * 100, 2) ) } return (
{(bar, idx) => { return (
{(icon) => } {bar.name}

}> {(href) => ( {bar.name} )}
{local.valueFormatter(bar.value)}
) }}
) } export { BarList }