{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bar-list",
  "description": "A horizontal bar list component for displaying ranked data",
  "dependencies": [
    "react-aria-components",
    "cn@^0.2.4"
  ],
  "files": [
    {
      "path": "registry/preskok/ui/preskok-ui/bar-list.tsx",
      "content": "\"use client\"\n\nimport React, { useMemo } from \"react\"\nimport { twJoin, twMerge } from \"cn\"\nimport { Button } from \"react-aria-components/Button\"\nimport { Link } from \"react-aria-components/Link\"\n\ntype Bar<T> = T & {\n  key?: string\n  href?: string\n  value: number\n  name: string\n}\n\ninterface BarListProps<T = unknown> extends React.ComponentProps<\"div\"> {\n  data: Array<Bar<T>>\n  valueFormatter?: (value: number) => string\n  showAnimation?: boolean\n  onValueChange?: (payload: Bar<T>) => void\n  sortOrder?: \"ascending\" | \"descending\" | \"none\"\n}\n\nfunction BarList<T>({\n  data = [],\n  valueFormatter = (value) => value.toString(),\n  showAnimation = false,\n  onValueChange,\n  sortOrder = \"descending\",\n  className,\n  ref,\n  ...props\n}: BarListProps<T>) {\n  const Component = onValueChange ? Button : \"div\"\n  const sortedData = useMemo(() => {\n    if (sortOrder === \"none\") {\n      return data\n    }\n    return [...data].sort((a, b) => {\n      return sortOrder === \"ascending\" ? a.value - b.value : b.value - a.value\n    })\n  }, [data, sortOrder])\n\n  const widths = useMemo(() => {\n    const maxValue = Math.max(...sortedData.map((item) => item.value), 0)\n    return sortedData.map((item) =>\n      item.value === 0 ? 0 : Math.max((item.value / maxValue) * 100, 2)\n    )\n  }, [sortedData])\n\n  const rowHeight = \"h-8\"\n\n  return (\n    <div\n      ref={ref}\n      className={twMerge(\"flex justify-between space-x-6\", className)}\n      {...props}\n    >\n      <div className=\"relative w-full space-y-1.5\">\n        {sortedData.map((item, index) => (\n          <Component\n            key={item.key ?? item.name}\n            onClick={() => {\n              onValueChange?.(item)\n            }}\n            className={twJoin(\n              \"group w-full rounded-sm\",\n              \"focus:inset-ring-ring focus:ring-ring/20 focus:ring-2 focus:inset-ring focus:outline-hidden\",\n              onValueChange ? \"hover:bg-secondary -m-0! cursor-pointer\" : \"\"\n            )}\n          >\n            <div\n              className={twJoin(\n                \"bg-primary/15 dark:bg-primary/20 flex items-center rounded-sm transition-all\",\n                rowHeight,\n                onValueChange\n                  ? \"group-hover:bg-primary/20 dark:group-hover:bg-primary/35\"\n                  : \"\",\n                index === sortedData.length - 1 && \"mb-0\",\n                showAnimation && \"duration-700\"\n              )}\n              style={{ width: `${widths[index]}%` }}\n            >\n              <div className=\"absolute left-2 flex max-w-full pr-2\">\n                {item.href ? (\n                  <Link\n                    href={item.href}\n                    className={twJoin(\n                      \"truncate rounded-sm text-sm whitespace-nowrap\",\n                      \"text-foreground\",\n                      \"hover:underline hover:underline-offset-2\",\n                      \"focus:inset-ring-ring focus:ring-ring/20 focus:ring-2 focus:inset-ring focus:outline-hidden\"\n                    )}\n                    target=\"_blank\"\n                    rel=\"noreferrer\"\n                    onClick={(event) => {\n                      event.stopPropagation()\n                    }}\n                  >\n                    {item.name}\n                  </Link>\n                ) : (\n                  <p className=\"truncate text-sm whitespace-nowrap text-foreground\">\n                    {item.name}\n                  </p>\n                )}\n              </div>\n            </div>\n          </Component>\n        ))}\n      </div>\n      <div>\n        {sortedData.map((item, index) => (\n          <div\n            key={item.key ?? item.name}\n            className={twJoin(\n              \"flex items-center justify-end\",\n              rowHeight,\n              index === sortedData.length - 1 ? \"mb-0\" : \"mb-1.5\"\n            )}\n          >\n            <p className=\"truncate text-sm leading-none whitespace-nowrap text-foreground\">\n              {valueFormatter(item.value)}\n            </p>\n          </div>\n        ))}\n      </div>\n    </div>\n  )\n}\n\nexport { BarList, type BarListProps }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}