/
DME
/
NotesApp
Обзор
Документация
Войти
/
DME
/
NotesApp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/components/ui/button.tsx
59 строк
2 KB
Karasique333
Commit
19 июн 2025, 15:09
19 июн 2025, 15:09
d96c829
Код
Авторство
О чём код?
import { Slot } from '@radix-ui/react-slot' import { type VariantProps, cva } from 'class-variance-authority' import { Loader } from 'lucide-react' import * as React from 'react' import { cn } from '@/lib/utils' const buttonVariants = cva( 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[8px] text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0', { variants: { variant: { primary: 'bg-blue-500 text-white hover:bg-blue-700', secondary: 'border border-neutral-100 bg-neutral-100 text-neutral-600 hover:border-neutral-300 hover:bg-white hover:text-neutral-950', border: 'border border-neutral-300 bg-transparent text-neutral-950 hover:bg-neutral-100 hover:text-neutral-600 dark:text-white dark:hover:text-neutral-950', destructive: 'bg-red-500 text-white hover:bg-red-100 hover:bg-red-500/80', }, size: { default: 'h-9 px-4 py-3', sm: 'h-8 rounded-md px-3 text-xs', lg: 'h-10 rounded-md px-8', icon: 'h-9 w-9', }, }, defaultVariants: { variant: 'primary', size: 'default', }, } ) export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> { asChild?: boolean isLoading?: boolean } const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( ({ className, variant, size, isLoading, asChild = false, ...props }, ref) => { const Comp = asChild ? Slot : 'button' return ( <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} > {isLoading && <Loader className="h-4 w-4 animate-spin" />} {props.children} </Comp> ) } ) Button.displayName = 'Button' export { Button, buttonVariants }