{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "filter-button",
  "type": "registry:ui",
  "title": "FilterButton",
  "description": "FilterButton is a compact multi-select trigger that opens a checklist in a popup.",
  "dependencies": [
    "@radix-ui/react-compose-refs@^1.1.3",
    "@remixicon/react@^4.9.0",
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "https://wideset.co/r/checkbox.json",
    "https://wideset.co/r/icon-button.json",
    "https://wideset.co/r/list-item.json",
    "https://wideset.co/r/motion.json",
    "https://wideset.co/r/popup.json",
    "https://wideset.co/r/styles.json",
    "https://wideset.co/r/utils.json"
  ],
  "files": [
    {
      "path": "src/components/filter-button/FilterButton.hooks.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/filter-button/FilterButton.hooks.ts",
      "content": "'use client';\n\nimport { type KeyboardEvent, useCallback, useRef, useState } from 'react';\n\ntype UseKeyboardNavigationParams = {\n  itemCount: number;\n  isDisabled?: (index: number) => boolean;\n  onSelect: (index: number) => void;\n  loop?: boolean;\n};\n\nexport function useKeyboardNavigation({\n  itemCount,\n  isDisabled,\n  onSelect,\n  loop = true,\n}: UseKeyboardNavigationParams) {\n  const [activeIndex, setActiveIndex] = useState(0);\n  const itemRefs = useRef<Array<HTMLElement | null>>([]);\n\n  const focusIndex = useCallback((index: number) => {\n    setActiveIndex(index);\n    itemRefs.current[index]?.focus();\n  }, []);\n\n  const findEnabled = useCallback(\n    (from: number, direction: 1 | -1) => {\n      if (itemCount === 0) return -1;\n\n      let next = from;\n\n      for (let step = 0; step < itemCount; step++) {\n        next += direction;\n\n        if (next >= itemCount) {\n          if (!loop) return -1;\n          next = 0;\n        } else if (next < 0) {\n          if (!loop) return -1;\n          next = itemCount - 1;\n        }\n\n        if (!isDisabled?.(next)) return next;\n      }\n\n      return -1;\n    },\n    [itemCount, isDisabled, loop],\n  );\n\n  const focusFirstEnabled = useCallback(() => {\n    const index = findEnabled(-1, 1);\n    if (index !== -1) focusIndex(index);\n  }, [findEnabled, focusIndex]);\n\n  const handleKeyDown = useCallback(\n    (event: KeyboardEvent<HTMLElement>, index: number) => {\n      switch (event.key) {\n        case 'ArrowDown':\n        case 'ArrowUp': {\n          event.preventDefault();\n          const next = findEnabled(index, event.key === 'ArrowDown' ? 1 : -1);\n          if (next !== -1) focusIndex(next);\n          break;\n        }\n        case 'Enter':\n        case ' ':\n          event.preventDefault();\n          if (!isDisabled?.(index)) onSelect(index);\n          break;\n      }\n    },\n    [findEnabled, focusIndex, isDisabled, onSelect],\n  );\n\n  const getItemProps = useCallback(\n    (index: number) => ({\n      ref: (el: HTMLElement | null) => {\n        itemRefs.current[index] = el;\n      },\n      tabIndex: activeIndex === index ? 0 : -1,\n      onKeyDown: (event: KeyboardEvent<HTMLElement>) => handleKeyDown(event, index),\n      onFocus: () => setActiveIndex(index),\n    }),\n    [activeIndex, handleKeyDown],\n  );\n\n  return { getItemProps, focusFirstEnabled, activeIndex };\n}\n"
    },
    {
      "path": "src/components/filter-button/FilterButton.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/filter-button/FilterButton.tsx",
      "content": "'use client';\n\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { RiArrowDownSLine, RiCloseLine } from '@remixicon/react';\nimport React, { useMemo, useRef, useState } from 'react';\nimport { IconButton } from '@/components/ui/wideset/button/IconButton';\nimport { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';\nimport { ListItem } from '@/components/ui/wideset/list-item/ListItem';\nimport { Popup } from '@/components/ui/wideset/popup/Popup';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useDefaultMotion } from '@/lib/wideset/motion/MotionProvider';\nimport { useKeyboardNavigation } from './FilterButton.hooks';\nimport type { FilterButtonProps } from './FilterButton.types';\nimport {\n  filterButtonClearPlaceholderVariants,\n  filterButtonClearSizes,\n  filterButtonClearVariants,\n  filterButtonLabelsVariants,\n  filterButtonPlaceholderVariants,\n  filterButtonTriggerMotionVariants,\n  filterButtonTriggerVariants,\n  filterButtonValueVariants,\n} from './FilterButton.variants';\n\nexport const FilterButton = React.forwardRef<HTMLButtonElement, FilterButtonProps>(\n  (\n    {\n      className,\n      options,\n      placeholder = 'Filter',\n      onChange,\n      value,\n      defaultValue,\n      label = 'Filter',\n      size,\n      disabled,\n      clearFilterAriaLabel = 'Clear filter',\n      defaultMotion,\n      // eslint-disable-next-line unused-imports/no-unused-vars\n      selected: _selected,\n      ...props\n    },\n    ref,\n  ) => {\n    const motion = useDefaultMotion(defaultMotion);\n    const triggerRef = useRef<HTMLButtonElement>(null);\n    const composedRef = useComposedRefs(ref, triggerRef);\n    const isControlled = value !== undefined;\n    const [innerValue, setInnerValue] = useState<string[]>(isControlled ? [] : defaultValue || []);\n    const selectedValues = isControlled ? value : innerValue;\n\n    const handleSelect = (optionValue: string) => {\n      if (disabled) return;\n\n      const updatedValues = selectedValues.includes(optionValue)\n        ? selectedValues.filter((selectedValue) => selectedValue !== optionValue)\n        : [...selectedValues, optionValue];\n\n      if (!isControlled) {\n        setInnerValue(updatedValues);\n      }\n\n      onChange(updatedValues);\n    };\n\n    const handleReset = () => {\n      const emptyValue: string[] = [];\n\n      setInnerValue(emptyValue);\n      onChange(emptyValue);\n    };\n\n    const { getItemProps, focusFirstEnabled } = useKeyboardNavigation({\n      itemCount: options.length,\n      isDisabled: (index) => Boolean(options[index]?.disabled),\n      onSelect: (index) => handleSelect(options[index].value),\n    });\n\n    const hasSelection = selectedValues.length > 0;\n\n    const displayedValue = useMemo(() => {\n      if (!selectedValues.length) return;\n\n      const label = options.find((option) => option.value === selectedValues[0])?.label;\n\n      return selectedValues.length > 1 ? `${label}, +${selectedValues.length - 1}` : label;\n    }, [selectedValues, options]);\n\n    return (\n      <Popup>\n        <div data-slot=\"filter-button-wrapper\" className=\"flex max-w-full items-center\">\n          <Popup.Trigger asChild>\n            <button\n              data-slot=\"filter-button\"\n              {...props}\n              className={cn(\n                filterButtonTriggerVariants({ size, selected: hasSelection, disabled }),\n                filterButtonTriggerMotionVariants({ enabled: motion }),\n                className,\n              )}\n              ref={composedRef}\n              disabled={disabled}\n            >\n              {hasSelection ? (\n                <span className={filterButtonLabelsVariants({ size })}>\n                  <span>{label}</span>\n                  {displayedValue && (\n                    <span className={filterButtonValueVariants({ size, disabled })}>\n                      {displayedValue}\n                    </span>\n                  )}\n                </span>\n              ) : (\n                <span className={filterButtonPlaceholderVariants({ size })}>{placeholder}</span>\n              )}\n              {hasSelection ? (\n                <span\n                  aria-hidden=\"true\"\n                  className={filterButtonClearPlaceholderVariants({ size })}\n                />\n              ) : (\n                <RiArrowDownSLine aria-hidden=\"true\" focusable=\"false\" />\n              )}\n            </button>\n          </Popup.Trigger>\n          {hasSelection && (\n            <IconButton\n              icon={RiCloseLine}\n              variant=\"secondary\"\n              preset=\"ghost\"\n              size={filterButtonClearSizes[size ?? 'sm']}\n              aria-label={clearFilterAriaLabel}\n              defaultMotion={motion}\n              disabled={disabled}\n              className={filterButtonClearVariants({ size })}\n              onClick={() => {\n                handleReset();\n                triggerRef.current?.focus();\n              }}\n            />\n          )}\n        </div>\n        <Popup.Container\n          // Width floor: max(trigger, Size/28) so the list neither shrinks below\n          // the menu minimum nor jumps around as the trigger's own width\n          // changes with the selection summary.\n          className=\"rounded-ws-container-sm p-ws-3 z-ws-popout w-auto min-w-[max(var(--radix-popover-trigger-width),var(--spacing-ws-28))]\"\n          defaultMotion={motion}\n          onOpenAutoFocus={(e) => {\n            e.preventDefault();\n            focusFirstEnabled();\n          }}\n        >\n          <div\n            role=\"listbox\"\n            aria-multiselectable\n            aria-label={label}\n            className=\"max-h-[18rem] overflow-x-hidden overflow-y-auto outline-none\"\n          >\n            {options.map((option, index) => {\n              const selected = selectedValues.includes(option.value);\n\n              return (\n                <ListItem\n                  key={option.value}\n                  role=\"option\"\n                  aria-selected={selected}\n                  disabled={option.disabled}\n                  onClick={() => {\n                    if (option.disabled) return;\n                    handleSelect(option.value);\n                  }}\n                  // Figma binds the row's min-height to `Size/14` (32px); the\n                  // padding alone (Gap/3 + 20px content + Gap/3) only reaches 28px.\n                  defaultMotion={motion}\n                  className={cn('min-h-ws-14', {\n                    'bg-ws-dynamic-primary-alpha-default': selected,\n                  })}\n                  {...getItemProps(index)}\n                >\n                  <ListItem.Prefix>\n                    <Checkbox\n                      checked={selected}\n                      className=\"pointer-events-none\"\n                      tabIndex={-1}\n                      defaultMotion={motion}\n                    />\n                  </ListItem.Prefix>\n                  <ListItem.Label>{option.label}</ListItem.Label>\n                </ListItem>\n              );\n            })}\n          </div>\n        </Popup.Container>\n      </Popup>\n    );\n  },\n);\n\nFilterButton.displayName = 'FilterButton';\n\nexport type { FilterButtonOption, FilterButtonProps } from './FilterButton.types';\nexport { filterButtonTriggerVariants } from './FilterButton.variants';\n"
    },
    {
      "path": "src/components/filter-button/FilterButton.types.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/filter-button/FilterButton.types.ts",
      "content": "import type { VariantProps } from 'class-variance-authority';\nimport type { ButtonHTMLAttributes } from 'react';\n\nimport type { MotionProps } from '@/lib/wideset/motion/Motion.types';\nimport type { filterButtonTriggerVariants } from './FilterButton.variants';\n\nexport type FilterButtonOption = {\n  /** Unique option value returned in the selected values array. */\n  value: string;\n  /** Visible label rendered in the trigger summary and options list. */\n  label: string;\n  /** Prevents selecting the option while keeping it visible in the list. */\n  disabled?: boolean;\n};\n\n/** A compact trigger for selecting multiple filter values. */\nexport type FilterButtonProps = {\n  /** Available options rendered inside the filter popover. */\n  options: FilterButtonOption[];\n  /** Placeholder shown in the trigger when no options are selected. */\n  placeholder?: string;\n  /** Called with the full array of selected option values whenever selection changes. */\n  onChange: (value: string[]) => void;\n  /** Controlled array of selected option values. */\n  value?: string[];\n  /** Initial selected option values in uncontrolled mode. */\n  defaultValue?: string[];\n  /** Prefix label shown before the selected-value summary. */\n  label?: string;\n  /** Accessible label for the clear-filter button. Defaults to `'Clear filter'`. */\n  clearFilterAriaLabel?: string;\n} & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> &\n  MotionProps &\n  VariantProps<typeof filterButtonTriggerVariants>;\n"
    },
    {
      "path": "src/components/filter-button/FilterButton.variants.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/filter-button/FilterButton.variants.ts",
      "content": "import { cva } from 'class-variance-authority';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { hoverTintMotion, pressMotion } from '@/lib/wideset/motion/recipes';\n\n/**\n * Figma wraps the label in a `Label` frame carrying its own `Gap/2`–`Gap/3` inset,\n * so the visible text inset is `frame padding + wrapper padding`\n * (sm 10+2=12, md 12+4=16, lg 12+4=16).\n *\n * That wrapper is reproduced in code as `filterButtonPlaceholderVariants` rather\n * than folded into `pl-*`, so `pr-*`/`pl-*` here stay equal to Figma's own\n * frame-level padding and the two sides can drift independently — folding the sum\n * into `pl-*` would match the text inset while leaving the icon side wrong.\n */\nexport const filterButtonTriggerVariants = cva(\n  cn(\n    'text-ws-static-base border-ws-dynamic-secondary-default bg-ws-static-highlight-base shadow-ws-controls-control placeholder:text-ws-static-subtle hover:border-ws-dynamic-secondary-hover active:border-ws-dynamic-secondary-pressed relative flex max-w-full cursor-pointer items-center overflow-hidden border text-nowrap',\n    'focus-visible:wds-focus-visible focus-visible:outline-ws-dynamic-primary-strong-default focus-visible:outline-solid',\n    '[&>svg]:text-ws-dynamic-secondary-default [&_svg]:size-ws-9 [&_svg]:shrink-0',\n  ),\n  {\n    variants: {\n      size: {\n        sm: 'rounded-ws-control-lg typography-label-sm h-ws-forms-sm gap-ws-3 pr-ws-5 pl-ws-6',\n        md: 'rounded-ws-control-lg typography-label-md h-ws-forms-md gap-ws-3 pr-ws-7 pl-ws-7',\n        lg: 'rounded-ws-control-xl typography-label-md h-ws-forms-lg gap-ws-4 pr-ws-9 pl-ws-7',\n      },\n      selected: {\n        true: 'border-ws-dynamic-primary-default hover:border-ws-dynamic-primary-hover active:border-ws-dynamic-primary-pressed',\n        false: '',\n      },\n      disabled: {\n        true: 'text-ws-static-subtle bg-ws-dynamic-primary-alpha-default border-ws-dynamic-secondary-disabled [&>svg]:text-ws-dynamic-secondary-disabled pointer-events-none cursor-default shadow-none',\n      },\n    },\n    compoundVariants: [\n      // Selected swaps the trailing chevron for a clear IconButton, which Figma\n      // sits closer to the edge and on a tighter gap than the bare chevron.\n      { size: 'sm', selected: true, class: 'gap-ws-2 pr-ws-3 pl-ws-7' },\n      { size: 'md', selected: true, class: 'gap-ws-4 pr-ws-3 pl-ws-9' },\n      { size: 'lg', selected: true, class: 'gap-ws-4 pr-ws-5 pl-ws-9' },\n    ],\n    defaultVariants: {\n      size: 'sm',\n      disabled: false,\n      selected: false,\n    },\n  },\n);\n\n/**\n * Figma's `Label` frame around the bare placeholder — applies only when no value is\n * selected. With a value the text sits inside `filterButtonLabelsVariants` instead.\n */\nexport const filterButtonPlaceholderVariants = cva('', {\n  variants: {\n    size: {\n      sm: 'px-ws-2',\n      md: 'px-ws-3',\n      lg: 'px-ws-3',\n    },\n  },\n  defaultVariants: { size: 'sm' },\n});\n\n/**\n * Figma's `Labels` group — the gap between the prefix label and the value summary.\n * It carries no padding of its own: the distance from the value to the clear button\n * is the trigger's own `gap-*` (see the selected compound variants above).\n */\nexport const filterButtonLabelsVariants = cva('flex min-w-0 items-center overflow-hidden', {\n  variants: {\n    size: {\n      sm: 'gap-ws-3',\n      md: 'gap-ws-4',\n      lg: 'gap-ws-4',\n    },\n  },\n  defaultVariants: { size: 'sm' },\n});\n\n/**\n * The selected value summary. Carries the size ramp explicitly rather than inheriting\n * it, because it is the one piece of text that goes strong while the prefix label\n * stays regular. Disabled drops back to the non-strong utility — Figma renders the\n * disabled value at `Font/Weight/Normal`.\n */\nexport const filterButtonValueVariants = cva('', {\n  variants: {\n    size: {\n      sm: '',\n      md: '',\n      lg: '',\n    },\n    disabled: { true: 'text-ws-static-subtle', false: 'text-ws-dynamic-primary-default' },\n  },\n  compoundVariants: [\n    { size: 'sm', disabled: false, class: 'typography-label-strong-sm' },\n    { size: 'md', disabled: false, class: 'typography-label-strong-md' },\n    { size: 'lg', disabled: false, class: 'typography-label-strong-md' },\n    { size: 'sm', disabled: true, class: 'typography-label-sm' },\n    { size: 'md', disabled: true, class: 'typography-label-md' },\n    { size: 'lg', disabled: true, class: 'typography-label-md' },\n  ],\n  defaultVariants: { size: 'sm', disabled: false },\n});\n\n/** Figma binds the clear button to `Components/Forms/*`: 24px at sm, 32px at md and lg. */\nexport const filterButtonClearSizes = {\n  sm: 'xs',\n  md: 'sm',\n  lg: 'sm',\n} as const;\n\nexport const filterButtonClearPlaceholderVariants = cva('shrink-0', {\n  variants: {\n    size: {\n      sm: 'h-ws-forms-xs w-ws-forms-xs',\n      md: 'h-ws-forms-sm w-ws-forms-sm',\n      lg: 'h-ws-forms-sm w-ws-forms-sm',\n    },\n  },\n  defaultVariants: { size: 'sm' },\n});\n\nexport const filterButtonClearVariants = cva('relative shrink-0', {\n  variants: {\n    size: {\n      sm: 'mr-[calc(var(--spacing-ws-3)+1px)] -ml-[calc(var(--spacing-ws-3)+var(--spacing-ws-forms-xs)+1px)]',\n      md: 'mr-[calc(var(--spacing-ws-3)+1px)] -ml-[calc(var(--spacing-ws-3)+var(--spacing-ws-forms-sm)+1px)]',\n      lg: 'mr-[calc(var(--spacing-ws-5)+1px)] -ml-[calc(var(--spacing-ws-5)+var(--spacing-ws-forms-sm)+1px)]',\n    },\n  },\n  defaultVariants: { size: 'sm' },\n});\n\nexport const filterButtonTriggerMotionVariants = cva('', {\n  variants: {\n    enabled: { true: cn(hoverTintMotion, pressMotion), false: '' },\n  },\n  defaultVariants: { enabled: true },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "commit": "8bb3627"
  }
}
