{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "primitives-radix-toggle-group",
  "title": "Radix Toggle Group",
  "description": "A set of two-state buttons that can be toggled on or off.",
  "dependencies": [
    "motion",
    "radix-ui"
  ],
  "registryDependencies": [
    "@odysseyui/primitives-effects-highlight",
    "@odysseyui/lib-get-strict-context",
    "@odysseyui/hooks-use-controlled-state"
  ],
  "files": [
    {
      "path": "registry/primitives/radix/toggle-group/index.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { ToggleGroup as ToggleGroupPrimitive } from 'radix-ui';\nimport { AnimatePresence, motion, type HTMLMotionProps } from 'motion/react';\n\nimport {\n  Highlight,\n  HighlightItem,\n  type HighlightItemProps,\n  type HighlightProps,\n} from '@/components/odyssey/primitives/effects/highlight';\nimport { getStrictContext } from '@/lib/get-strict-context';\nimport { useControlledState } from '@/hooks/use-controlled-state';\n\ntype ToggleGroupContextType = {\n  value: string | string[] | undefined;\n  setValue: (value: string | string[] | undefined) => void;\n  type: 'single' | 'multiple';\n};\n\nconst [ToggleGroupProvider, useToggleGroup] =\n  getStrictContext<ToggleGroupContextType>('ToggleGroupContext');\n\ntype ToggleGroupProps = React.ComponentProps<typeof ToggleGroupPrimitive.Root>;\n\nfunction ToggleGroup(props: ToggleGroupProps) {\n  const [value, setValue] = useControlledState<string | string[] | undefined>({\n    value: props.value,\n    defaultValue: props.defaultValue,\n    onChange: props.onValueChange as (\n      value: string | string[] | undefined,\n    ) => void,\n  });\n\n  return (\n    <ToggleGroupProvider value={{ value, setValue, type: props.type }}>\n      <ToggleGroupPrimitive.Root\n        data-slot=\"toggle-group\"\n        {...props}\n        onValueChange={setValue}\n      />\n    </ToggleGroupProvider>\n  );\n}\n\ntype ToggleGroupItemProps = Omit<\n  React.ComponentProps<typeof ToggleGroupPrimitive.Item>,\n  'asChild'\n> &\n  HTMLMotionProps<'button'>;\n\nfunction ToggleGroupItem({ value, disabled, ...props }: ToggleGroupItemProps) {\n  return (\n    <ToggleGroupPrimitive.Item value={value} disabled={disabled} asChild>\n      <motion.button\n        data-slot=\"toggle-group-item\"\n        whileTap={{ scale: 0.95 }}\n        {...props}\n      />\n    </ToggleGroupPrimitive.Item>\n  );\n}\n\ntype ToggleGroupHighlightProps = Omit<HighlightProps, 'controlledItems'>;\n\nfunction ToggleGroupHighlight({\n  transition = { type: 'spring', stiffness: 200, damping: 25 },\n  ...props\n}: ToggleGroupHighlightProps) {\n  const { value } = useToggleGroup();\n\n  return (\n    <Highlight\n      data-slot=\"toggle-group-highlight\"\n      controlledItems\n      value={typeof value === 'string' ? value : null}\n      exitDelay={0}\n      transition={transition}\n      {...props}\n    />\n  );\n}\n\ntype ToggleGroupHighlightItemProps = HighlightItemProps &\n  HTMLMotionProps<'div'> & {\n    children: React.ReactElement;\n  };\n\nfunction ToggleGroupHighlightItem({\n  children,\n  style,\n  ...props\n}: ToggleGroupHighlightItemProps) {\n  const { type, value } = useToggleGroup();\n\n  if (type === 'single') {\n    return (\n      <HighlightItem\n        data-slot=\"toggle-group-highlight-item\"\n        style={{ inset: 0, ...style }}\n        {...props}\n      >\n        {children}\n      </HighlightItem>\n    );\n  }\n\n  if (type === 'multiple' && React.isValidElement(children)) {\n    const isActive = props.value && value && value.includes(props.value);\n\n    const element = children as React.ReactElement<React.ComponentProps<'div'>>;\n\n    return React.cloneElement(\n      children,\n      {\n        style: {\n          ...element.props.style,\n          position: 'relative',\n        },\n        ...element.props,\n      },\n      <>\n        <AnimatePresence>\n          {isActive && (\n            <motion.div\n              data-slot=\"toggle-group-highlight-item\"\n              style={{ position: 'absolute', inset: 0, zIndex: 0, ...style }}\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={{ opacity: 0 }}\n              {...props}\n            />\n          )}\n        </AnimatePresence>\n\n        <div\n          style={{\n            position: 'relative',\n            zIndex: 1,\n          }}\n        >\n          {element.props.children}\n        </div>\n      </>,\n    );\n  }\n}\n\nexport {\n  ToggleGroup,\n  ToggleGroupItem,\n  ToggleGroupHighlight,\n  ToggleGroupHighlightItem,\n  useToggleGroup,\n  type ToggleGroupProps,\n  type ToggleGroupItemProps,\n  type ToggleGroupHighlightProps,\n  type ToggleGroupHighlightItemProps,\n  type ToggleGroupContextType,\n};\n",
      "type": "registry:ui",
      "target": "components/odysseyui/primitives/radix/toggle-group.tsx"
    }
  ],
  "type": "registry:ui"
}