generated from dream-aim-deliver/dad-ui-kit-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
10 changed files
with
161 additions
and
99 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
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
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 |
---|---|---|
@@ -1,59 +1,48 @@ | ||
import { twMerge } from "tailwind-merge"; | ||
import { | ||
primary as primaryStyles, | ||
secondary as secondaryStyles, | ||
} from "./Button.styles"; | ||
|
||
import { Button as ShadcnButton } from "@/ui/button"; | ||
// import { primary as primaryStyles, secondary as secondaryStyles } from "@/components/button/Button.styles"; | ||
|
||
export interface ButtonProps { | ||
/** | ||
* Is this the principal call to action on the page? | ||
*/ | ||
primary?: boolean; | ||
/** | ||
* What background color to use | ||
*/ | ||
backgroundColor?: string; | ||
variant?: | ||
| "default" | ||
| "destructive" | ||
| "outline" | ||
| "secondary" | ||
| "ghost" | ||
| "link"; | ||
/** | ||
* How large should the button be? | ||
*/ | ||
size?: "small" | "medium" | "large"; | ||
size?: "sm" | "default" | "lg" | "icon"; | ||
/** | ||
* Button contents | ||
* Button contents. Can be a string or a React node (e.g. an icon) | ||
*/ | ||
label: string; | ||
label: string | React.ReactNode; | ||
/** | ||
* Optional click handler | ||
*/ | ||
onClick?: () => void; | ||
|
||
/** | ||
* Optional tailwindcss classes | ||
*/ | ||
className?: string; | ||
} | ||
|
||
/** | ||
* Primary UI component for user interaction | ||
* Button component | ||
*/ | ||
export const Button = ({ | ||
primary = false, | ||
size = "medium", | ||
variant = "default", | ||
size = "default", | ||
label, | ||
...props | ||
}: ButtonProps) => { | ||
const classes = []; | ||
const mode = primary ? primaryStyles : secondaryStyles; | ||
classes.push(mode); | ||
if (size === "small") { | ||
classes.push("text-sm"); | ||
} | ||
if (size === "medium") { | ||
classes.push("text-base"); | ||
} | ||
if (size === "large") { | ||
classes.push("text-xl"); | ||
} | ||
|
||
return ( | ||
<button type="button" className={twMerge(classes)} {...props}> | ||
{primary ? "Primary" : "Secondary"} {label}: {size} | ||
</button> | ||
<ShadcnButton variant={variant} size={size} {...props}> | ||
{label} | ||
</ShadcnButton> | ||
); | ||
}; |
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 * as React from "react"; | ||
import { Slot } from "@radix-ui/react-slot"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
|
||
import { cn } from "@/utils/utils"; | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 dark:ring-offset-slate-950 dark:focus-visible:ring-slate-300", | ||
{ | ||
variants: { | ||
variant: { | ||
default: | ||
"bg-slate-900 text-slate-50 hover:bg-slate-900/90 dark:bg-slate-50 dark:text-slate-900 dark:hover:bg-slate-50/90", | ||
destructive: | ||
"bg-red-500 text-slate-50 hover:bg-red-500/90 dark:bg-red-900 dark:text-slate-50 dark:hover:bg-red-900/90", | ||
outline: | ||
"border border-slate-200 bg-white hover:bg-slate-100 hover:text-slate-900 dark:border-slate-800 dark:bg-slate-950 dark:hover:bg-slate-800 dark:hover:text-slate-50", | ||
secondary: | ||
"bg-slate-100 text-slate-900 hover:bg-slate-100/80 dark:bg-slate-800 dark:text-slate-50 dark:hover:bg-slate-800/80", | ||
ghost: | ||
"hover:bg-slate-100 hover:text-slate-900 dark:hover:bg-slate-800 dark:hover:text-slate-50", | ||
link: "text-slate-900 underline-offset-4 hover:underline dark:text-slate-50", | ||
}, | ||
size: { | ||
default: "h-10 px-4 py-2", | ||
sm: "h-9 rounded-md px-3", | ||
lg: "h-11 rounded-md px-8", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
}, | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}, | ||
); | ||
Button.displayName = "Button"; | ||
|
||
export { Button, buttonVariants }; | ||
Check warning on line 58 in lib/components/ui/button.tsx GitHub Actions / Test Components (18.16.1)
|
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
Oops, something went wrong.