Primitives
Toggle Group
A set of toggle buttons with single or multiple selection and arrow-key navigation.
MotionUses the Toggle color transition.
Install
Install Kineto and follow the theme setup once in your app.
bash
npm install kinetotsx
import { ToggleGroup, ToggleGroupItem } from "kineto/toggle-group";Preview
tsx
"use client";
import * as React from "react";
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
import type { VariantProps } from "class-variance-authority";
import { cn } from "@/lib/cn";
import { toggleVariants } from "@/components/ui/toggle";
export type ToggleGroupProps = React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root>;
const ToggleGroup = React.forwardRef<React.ElementRef<typeof ToggleGroupPrimitive.Root>, ToggleGroupProps>(
({ className, ...props }, ref) => (
<ToggleGroupPrimitive.Root
ref={ref}
className={cn("inline-flex flex-wrap items-center gap-1", className)}
{...props}
/>
),
);
ToggleGroup.displayName = "ToggleGroup";
export interface ToggleGroupItemProps extends React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item>,
VariantProps<typeof toggleVariants> {}
const ToggleGroupItem = React.forwardRef<React.ElementRef<typeof ToggleGroupPrimitive.Item>, ToggleGroupItemProps>(
({ className, variant, size, ...props }, ref) => (
<ToggleGroupPrimitive.Item ref={ref} className={cn(toggleVariants({ variant, size }), className)} {...props} />
),
);
ToggleGroupItem.displayName = "ToggleGroupItem";
export { ToggleGroup, ToggleGroupItem };src/components/ui/toggle-group.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "single" | "multiple" | — | Selection mode. |
| value | string | string[] | — | Controlled selection. Use a string in single mode and an array in multiple mode. |
| onValueChange | (value) => void | — | Receives the updated selection. |