Generator (scripts/generate-htmx-css.ts): track `viaVariants` per slot so
slots that compose another component's variant system (e.g. ToggleGroupItem
via toggleVariants) inherit the referenced CVA's base + variant rules under
their own selector. Previously toggle-group-item's CSS contained only its
override classes, shipping with no padding/height/hover/active state.
Toggle (components/ui/toggle.tsx):
- data-[state=on] now uses bg-primary (orange) instead of bg-accent (grey),
matching every other "commit" affordance in the palette.
- Horizontal padding aligned with Button: px-4/px-3/px-6 per size, plus
has-[>svg]:px-* for icon-only toggles.
ToggleGroup (components/ui/toggle-group.tsx): drop min-w-0 flex-1 shrink-0
from the item override. Items now size to content instead of being clamped
into equal narrow columns where longer labels overflowed the bg box.
Showcase: add ToggleGroup section to the React page (component-matrix.tsx)
and 1:1 HTMX mirror (public/htmx.html) with a new JS bridge branch for
single/multi-select. compare-all.sh extended with the new section; 22/22
pass at ≥99.97%.
Docs: GAPS.md captures the generator gap, overflow root cause, color
rationale, and padding parity with before/after numbers.
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
'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/utils'
|
|
import { toggleVariants } from '@/components/ui/toggle'
|
|
|
|
const ToggleGroupContext = React.createContext<
|
|
VariantProps<typeof toggleVariants>
|
|
>({
|
|
size: 'default',
|
|
variant: 'default',
|
|
})
|
|
|
|
function ToggleGroup({
|
|
className,
|
|
variant,
|
|
size,
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
|
|
VariantProps<typeof toggleVariants>) {
|
|
return (
|
|
<ToggleGroupPrimitive.Root
|
|
data-slot="toggle-group"
|
|
data-variant={variant}
|
|
data-size={size}
|
|
className={cn(
|
|
'group/toggle-group flex w-fit items-center rounded-md data-[variant=outline]:shadow-xs',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
<ToggleGroupContext.Provider value={{ variant, size }}>
|
|
{children}
|
|
</ToggleGroupContext.Provider>
|
|
</ToggleGroupPrimitive.Root>
|
|
)
|
|
}
|
|
|
|
function ToggleGroupItem({
|
|
className,
|
|
children,
|
|
variant,
|
|
size,
|
|
...props
|
|
}: React.ComponentProps<typeof ToggleGroupPrimitive.Item> &
|
|
VariantProps<typeof toggleVariants>) {
|
|
const context = React.useContext(ToggleGroupContext)
|
|
|
|
return (
|
|
<ToggleGroupPrimitive.Item
|
|
data-slot="toggle-group-item"
|
|
data-variant={context.variant || variant}
|
|
data-size={context.size || size}
|
|
className={cn(
|
|
toggleVariants({
|
|
variant: context.variant || variant,
|
|
size: context.size || size,
|
|
}),
|
|
'rounded-none shadow-none first:rounded-l-md last:rounded-r-md focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first:border-l',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</ToggleGroupPrimitive.Item>
|
|
)
|
|
}
|
|
|
|
export { ToggleGroup, ToggleGroupItem }
|