-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec3182f
commit c0fad38
Showing
7 changed files
with
182 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { type VariantProps, cva } from 'class-variance-authority' | ||
import React, { forwardRef } from 'react' | ||
|
||
import { LoadingSpinner } from '@/components/loading-spinner' | ||
import { cn } from '@/utils/cn' | ||
|
||
const buttonVariants = cva( | ||
[ | ||
'relative inline-flex items-center justify-center whitespace-nowrap rounded-xl font-semibold', | ||
'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500', | ||
'disabled:pointer-events-none disabled:select-none disabled:opacity-50', | ||
], | ||
|
||
{ | ||
variants: { | ||
variant: { | ||
default: 'bg-button-base text-white hover:bg-button-base-hover active:bg-red-500', | ||
}, | ||
size: { | ||
default: 'py-4 px-6 font-medium', | ||
}, | ||
fullWidth: { | ||
true: 'w-full', | ||
}, | ||
loading: { | ||
true: 'text-transparent', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'default', | ||
size: 'default', | ||
}, | ||
}, | ||
) | ||
|
||
export interface ButtonProps | ||
extends VariantProps<typeof buttonVariants>, | ||
React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
loading?: boolean | ||
['aria-label']: string | ||
} | ||
|
||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button( | ||
{ variant, size, fullWidth, loading, className, type = 'button', children, ...props }, | ||
ref, | ||
) { | ||
return ( | ||
<button | ||
ref={ref} | ||
type={type} | ||
className={cn(buttonVariants({ variant, size, fullWidth, loading }), className)} | ||
disabled={props.disabled ?? loading ?? false} | ||
aria-disabled={props.disabled ?? loading ?? false} | ||
{...props}> | ||
{loading ? <LoadingSpinner /> : children} | ||
</button> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
|
||
export const Spinner = (props: React.SVGProps<SVGSVGElement>) => { | ||
return ( | ||
<svg | ||
aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 16 16" | ||
{...props}> | ||
<path | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeWidth="2" | ||
d="M2.204 6.447A6 6 0 108 2" | ||
/> | ||
</svg> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { type VariantProps, cva } from 'class-variance-authority' | ||
import React from 'react' | ||
|
||
import { Spinner } from '@/components/icons' | ||
|
||
const loadingSpinnerStyles = cva('animate-spin text-white', { | ||
variants: { | ||
variant: { | ||
md: 'h-4 w-4', | ||
lg: 'h-6 w-6', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'lg', | ||
}, | ||
}) | ||
|
||
export type LoadingIndicatorProps = VariantProps<typeof loadingSpinnerStyles> | ||
|
||
export const LoadingSpinner = ({ variant }: LoadingIndicatorProps) => { | ||
return <Spinner className={loadingSpinnerStyles({ variant })} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { cx, CxOptions } from 'class-variance-authority' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
export function cn(...inputs: CxOptions) { | ||
return twMerge(cx(inputs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters