/
githubmirror
/
gogs
Обзор
Документация
Войти
/
githubmirror
/
gogs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
web/src/components/ui/toggle-group.tsx
54 строки
1 KB
ᴊᴏᴇ ᴄʜᴇɴ
web: align components with React 19 and fix accessibility findings (#8306)
31 май 2026, 18:06
Не верифицирован
31 май 2026, 18:06
2c46f01
Код
Авторство
О чём код?
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"; import { type VariantProps } from "class-variance-authority"; import * as React from "react"; import { toggleVariants } from "@/components/ui/toggle-variants"; import { cn } from "@/lib/utils"; type ToggleVariantProps = VariantProps<typeof toggleVariants>; const ToggleGroupContext = React.createContext<ToggleVariantProps>({ variant: "default", size: "default", }); function ToggleGroup({ className, variant, size, children, ...props }: React.ComponentProps<typeof ToggleGroupPrimitive.Root> & ToggleVariantProps) { const context = React.useMemo(() => ({ variant, size }), [variant, size]); return ( <ToggleGroupPrimitive.Root className={cn("flex items-center justify-center gap-1", className)} {...props}> <ToggleGroupContext.Provider value={context}>{children}</ToggleGroupContext.Provider> </ToggleGroupPrimitive.Root> ); } function ToggleGroupItem({ className, children, variant, size, ...props }: React.ComponentProps<typeof ToggleGroupPrimitive.Item> & ToggleVariantProps) { const context = React.use(ToggleGroupContext); return ( <ToggleGroupPrimitive.Item className={cn( toggleVariants({ variant: context.variant ?? variant, size: context.size ?? size, }), className, )} {...props} > {children} </ToggleGroupPrimitive.Item> ); } export { ToggleGroup, ToggleGroupItem };