index.tsx
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-02 12:03:38
* @FilePath: \glsk-ai-assistant\app\components\base\button\index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import type { CSSProperties } from "react";
import React from "react";
import { type VariantProps, cva } from "class-variance-authority";
import Spinner from "../spinner";
import classNames from "@/utils/classnames";
const buttonVariants = cva("btn disabled:btn-disabled", {
variants: {
variant: {
primary: "btn-primary",
warning: "btn-warning",
secondary: "btn-secondary",
"secondary-accent": "btn-secondary-accent",
ghost: "btn-ghost",
"ghost-accent": "btn-ghost-accent",
tertiary: "btn-tertiary",
},
size: {
small: "btn-small",
medium: "btn-medium",
large: "btn-large",
},
},
defaultVariants: {
variant: "secondary",
size: "medium",
},
});
export type ButtonProps = {
destructive?: boolean;
loading?: boolean;
styleCss?: CSSProperties;
showArrow?: boolean;
spinnerClassName?: string;
isBlock?: boolean;
} & React.ButtonHTMLAttributes<HTMLButtonElement> &
VariantProps<typeof buttonVariants>;
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
className,
variant,
size,
destructive,
loading,
styleCss,
showArrow,
children,
spinnerClassName,
isBlock,
...props
},
ref
) => {
return (
<button
type="button"
className={classNames(
buttonVariants({ variant, size, className }),
destructive && "btn-destructive",
isBlock && "btn-block"
)}
ref={ref}
style={styleCss}
{...props}
>
{children}
{loading && (
<Spinner
loading={loading}
className={classNames(
"!text-white !h-3 !w-3 !border-2 !ml-1",
spinnerClassName
)}
/>
)}
{showArrow && <span className="arrow-icon"></span>}
</button>
);
}
);
Button.displayName = "Button";
export default Button;
export { Button, buttonVariants };