{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "toggle-group", "type": "registry:ui", "title": "Toggle Group", "files": [ { "path": "ui/toggle-group.tsrx", "type": "registry:ui", "target": "components/ui/toggle-group.tsrx", "content": "// Base UI base toggle-group — runs on @octanejs/base-ui's ToggleGroup.\n//\n// THERE IS NO `Item` PART. Verified by rendering the primitive: Base UI's ToggleGroup is a single\n// component whose children are ordinary `Toggle`s carrying a `value`, where radix pairs\n// `ToggleGroup.Root` with `ToggleGroup.Item`. So `ToggleGroupItem` here wraps `Toggle` — the same\n// primitive `toggle.tsrx` uses — and the exported names and `data-slot` values stay as shadcn\n// defines them, so consumers see no difference between bases.\n//\n// TWO API DIFFERENCES A CONSUMER CAN OBSERVE, both inherent to the primitive:\n//\n// 1. `type=\"single\" | \"multiple\"` is translated to Base UI's `multiple` boolean, so markup\n// written against the radix base keeps working.\n//\n// 2. VALUES ARE ALWAYS ARRAYS. Base UI's `value` / `defaultValue` / `onValueChange` speak\n// `string[]` in both modes, where radix's single mode speaks a bare `string`. That is not\n// translated: faking a scalar would mean inventing conversion behavior on every change, and\n// silently reshaping the argument to the consumer's handler is worse than a documented\n// difference. Single mode still yields at most one entry.\n//\n// The pressed dialect is `data-pressed`, not radix's `data-[state=on]` — see toggle.tsrx, whose\n// `toggleVariants` this file reuses, so the two bases cannot drift apart.\n//\n// ToggleGroup is composed with createElement: the consumer's children must sit INSIDE the context\n// Provider, and opaque compiled .tsrx children can only flow through the props.children channel\n// (see breadcrumb.tsrx's comment).\n//\n// UNVERIFIED PROVENANCE: class strings come from this package's radix base rather than\n// transcribed from upstream's Base UI source.\nimport { createContext, createElement, useContext, type OctaneNode } from 'octane';\nimport { type VariantProps } from 'class-variance-authority';\nimport { ToggleGroup as ToggleGroupPrimitive } from '@octanejs/base-ui/toggle-group';\nimport { Toggle as TogglePrimitive } from '@octanejs/base-ui/toggle';\n\nimport { cn } from '@/lib/utils';\nimport { toggleVariants } from '@/components/ui/toggle';\n\nconst ToggleGroupContext = createContext<\n\tVariantProps & {\n\t\tspacing?: number;\n\t\torientation?: 'horizontal' | 'vertical';\n\t}\n>({\n\tsize: 'default',\n\tvariant: 'default',\n\tspacing: 2,\n\torientation: 'horizontal',\n});\n\nexport interface ToggleGroupProps extends Record {\n\tclassName?: string;\n\tvariant?: VariantProps['variant'];\n\tsize?: VariantProps['size'];\n\tspacing?: number;\n\torientation?: 'horizontal' | 'vertical';\n\ttype?: 'single' | 'multiple';\n\tchildren?: OctaneNode;\n}\n\nexport function ToggleGroup({\n\tclassName,\n\tvariant,\n\tsize,\n\tspacing = 2,\n\torientation = 'horizontal',\n\ttype,\n\tchildren,\n\t...props\n}: ToggleGroupProps) {\n\treturn createElement(\n\t\tToggleGroupPrimitive,\n\t\t{\n\t\t\t'data-slot': 'toggle-group',\n\t\t\t'data-variant': variant,\n\t\t\t'data-size': size,\n\t\t\t'data-spacing': spacing,\n\t\t\t// Forwarded to the primitive: it drives the arrow-key axis (a vertical group must\n\t\t\t// ignore left/right and use up/down). The primitive also emits `data-orientation`\n\t\t\t// itself, so unlike the radix base this is not set by hand.\n\t\t\torientation,\n\t\t\tmultiple: type === 'multiple',\n\t\t\tstyle: { '--gap': spacing },\n\t\t\tclassName: cn(\n\t\t\t\t'group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs',\n\t\t\t\tclassName,\n\t\t\t),\n\t\t\t...props,\n\t\t},\n\t\tcreateElement(\n\t\t\tToggleGroupContext.Provider,\n\t\t\t{ value: { variant, size, spacing, orientation } },\n\t\t\tchildren,\n\t\t),\n\t);\n}\n\nexport interface ToggleGroupItemProps extends Record {\n\tclassName?: string;\n\tvariant?: VariantProps['variant'];\n\tsize?: VariantProps['size'];\n}\n\nexport function ToggleGroupItem({\n\tclassName,\n\tvariant = 'default',\n\tsize = 'default',\n\t...props\n}: ToggleGroupItemProps) @{\n\tconst context = useContext(ToggleGroupContext);\n\t\n}\n" } ], "dependencies": [ "@octanejs/base-ui@0.1.33", "class-variance-authority" ], "registryDependencies": [ "@octane/toggle", "@octane/utils" ] }