{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider-26",
  "title": "Price slider with histogram",
  "description": "A price range over a histogram of items, with fields and a result count.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/slider.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-slider-with-input.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/slider/slider-26.tsx",
      "content": "'use client';\n\nimport { useId, type KeyboardEvent } from 'react';\n\nimport { useSliderWithInput } from '@/registry/ndeko/hooks/use-slider-with-input';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { Slider } from '@/registry/ndeko/ui/slider';\n\nconst PRICES = [\n  80, 95, 110, 125, 130, 140, 145, 150, 155, 165, 175, 185, 195, 205, 215, 225,\n  235, 245, 255, 260, 265, 270, 275, 280, 285, 290, 290, 295, 295, 295, 298,\n  299, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365,\n  365, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430, 435, 440,\n  445, 450, 455, 460, 465, 470, 475, 480, 485, 490, 495, 495, 498, 499, 500,\n  500, 500, 515, 530, 545, 560, 575, 590, 605, 620, 635, 650, 655, 660, 665,\n  670, 675, 680, 685, 690, 695, 700, 700, 700, 700, 700, 700, 725, 750, 775,\n  800, 815, 830, 845, 845, 845, 870, 875, 880, 885, 890, 895, 898, 900,\n];\n\nconst BAR_COUNT = 40;\nconst MIN_PRICE = Math.min(...PRICES);\nconst MAX_PRICE = Math.max(...PRICES);\nconst BAR_WIDTH = (MAX_PRICE - MIN_PRICE) / BAR_COUNT;\nconst INITIAL_PRICES = [200, 780];\n\ntype Bar = {\n  start: number;\n  end: number;\n  count: number;\n};\n\nfunction countPricesBetween(min: number, max: number) {\n  const pricesInRange = PRICES.filter((price) => {\n    const isAboveMin = price >= min;\n    const isBelowMax = price <= max;\n    return isAboveMin && isBelowMax;\n  });\n  return pricesInRange.length;\n}\n\nfunction barAt(index: number): Bar {\n  const start = MIN_PRICE + index * BAR_WIDTH;\n  const end = start + BAR_WIDTH;\n  const pricesInBar = PRICES.filter((price) => {\n    const isFromStart = price >= start;\n    const isBeforeEnd = price < end;\n    return isFromStart && isBeforeEnd;\n  });\n  return { start, end, count: pricesInBar.length };\n}\n\nconst BARS = Array.from({ length: BAR_COUNT }, (_, index) => barAt(index));\nconst BAR_COUNTS = BARS.map((bar) => bar.count);\nconst TALLEST_BAR = Math.max(...BAR_COUNTS);\n\nfunction barHeightOf(bar: Bar) {\n  const ratio = bar.count / TALLEST_BAR;\n  const percent = ratio * 100;\n  return `${percent}%`;\n}\n\nfunction isBarSelected(bar: Bar, range: readonly number[], matches: number) {\n  const [lowest, highest] = range;\n  const hasMatches = matches > 0;\n  const startsBeforeHighest = bar.start <= highest;\n  const endsAfterLowest = bar.end >= lowest;\n  return hasMatches && startsBeforeHighest && endsAfterLowest;\n}\n\nfunction showLabelOf(matches: number) {\n  if (matches === 0) {\n    return 'No items in this range';\n  }\n  if (matches === 1) {\n    return 'Show 1 item';\n  }\n  return `Show ${matches} items`;\n}\n\nexport default function Slider26() {\n  const id = useId();\n  const minId = `${id}-min`;\n  const maxId = `${id}-max`;\n  const {\n    sliderValue,\n    inputValues,\n    validateAndUpdateValue,\n    handleInputChange,\n    handleSliderChange,\n  } = useSliderWithInput({\n    minValue: MIN_PRICE,\n    maxValue: MAX_PRICE,\n    initialValue: INITIAL_PRICES,\n  });\n  const [lowest, highest] = sliderValue;\n  const matches = countPricesBetween(lowest, highest);\n  const hasMatches = matches > 0;\n\n  function commitInput(index: number) {\n    validateAndUpdateValue(inputValues[index], index);\n  }\n\n  function commitOnEnter(\n    event: KeyboardEvent<HTMLInputElement>,\n    index: number\n  ) {\n    if (event.key !== 'Enter') {\n      return;\n    }\n    commitInput(index);\n  }\n\n  return (\n    <div className='flex w-full max-w-xs flex-col gap-4'>\n      <Label>Price</Label>\n      <div className='flex flex-col'>\n        <div className='flex h-12 w-full items-end' aria-hidden='true'>\n          {BARS.map((bar) => {\n            const isSelected = isBarSelected(bar, sliderValue, matches);\n            return (\n              <div\n                key={bar.start}\n                className='flex flex-1 justify-center'\n                style={{ height: barHeightOf(bar) }}\n              >\n                <span\n                  className={cn(\n                    'bg-foreground/10 size-full transition-colors duration-150',\n                    isSelected && 'bg-primary/40'\n                  )}\n                />\n              </div>\n            );\n          })}\n        </div>\n        <Slider\n          value={sliderValue}\n          onValueChange={handleSliderChange}\n          min={MIN_PRICE}\n          max={MAX_PRICE}\n          thumbLabels={['Minimum price', 'Maximum price']}\n        />\n      </div>\n      <div className='grid grid-cols-2 gap-4'>\n        <div className='flex flex-col gap-1.5'>\n          <Label htmlFor={minId}>Min price</Label>\n          <div className='relative'>\n            <Input\n              id={minId}\n              className='peer ps-6 tabular-nums'\n              type='text'\n              inputMode='decimal'\n              value={inputValues[0]}\n              onChange={(event) => handleInputChange(event, 0)}\n              onBlur={() => commitInput(0)}\n              onKeyDown={(event) => commitOnEnter(event, 0)}\n            />\n            <span className='text-muted-foreground pointer-events-none absolute inset-y-0 start-0 flex items-center ps-2.5 text-[13px] peer-disabled:opacity-50'>\n              $\n            </span>\n          </div>\n        </div>\n        <div className='flex flex-col gap-1.5'>\n          <Label htmlFor={maxId}>Max price</Label>\n          <div className='relative'>\n            <Input\n              id={maxId}\n              className='peer ps-6 tabular-nums'\n              type='text'\n              inputMode='decimal'\n              value={inputValues[1]}\n              onChange={(event) => handleInputChange(event, 1)}\n              onBlur={() => commitInput(1)}\n              onKeyDown={(event) => commitOnEnter(event, 1)}\n            />\n            <span className='text-muted-foreground pointer-events-none absolute inset-y-0 start-0 flex items-center ps-2.5 text-[13px] peer-disabled:opacity-50'>\n              $\n            </span>\n          </div>\n        </div>\n      </div>\n      <Button variant='outline' className='w-full' disabled={!hasMatches}>\n        {showLabelOf(matches)}\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "slider"
  ],
  "type": "registry:component"
}