fix: add loading state to buttons in forms and update button styles
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Button as HeadlessButton } from '@headlessui/react'
|
||||
import { ArrowPathIcon } from '@heroicons/react/20/solid'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import type { ReactNode, ElementType, ComponentPropsWithoutRef } from 'react'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
@@ -38,6 +39,7 @@ type ButtonBaseProperties = {
|
||||
variant?: VariantProps<typeof buttonVariants>['variant']
|
||||
size?: VariantProps<typeof buttonVariants>['size']
|
||||
className?: string
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
type PolymorphicReference<C extends ElementType> =
|
||||
@@ -48,22 +50,27 @@ type ButtonProperties<C extends ElementType> = ButtonBaseProperties & {
|
||||
ref?: PolymorphicReference<C>
|
||||
} & Omit<ComponentPropsWithoutRef<C>, keyof ButtonBaseProperties>
|
||||
|
||||
export const Button = <C extends ElementType = 'button'>({
|
||||
as,
|
||||
children,
|
||||
variant,
|
||||
size,
|
||||
className,
|
||||
...properties
|
||||
}: ButtonProperties<C>) => {
|
||||
export const Button = <C extends ElementType = 'button'>(
|
||||
properties: ButtonProperties<C>,
|
||||
) => {
|
||||
const {
|
||||
as,
|
||||
children,
|
||||
variant,
|
||||
size,
|
||||
className,
|
||||
isLoading = false,
|
||||
...restProperties
|
||||
} = properties
|
||||
const Component = as || HeadlessButton
|
||||
const classes = twMerge(buttonVariants({ variant, size, className }))
|
||||
|
||||
return (
|
||||
<Component
|
||||
className={classes}
|
||||
{...properties}
|
||||
{...restProperties}
|
||||
>
|
||||
{isLoading && <ArrowPathIcon className="animate-spin" />}
|
||||
{children}
|
||||
</Component>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user