feat(button): 添加SubmitButton组件并支持ant-design主题

This commit is contained in:
2026-01-16 18:46:18 +08:00
parent 5b40af560e
commit b7eb73c401
8 changed files with 103 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { PrimitiveProps } from 'reka-ui';
import type { ButtonVariants, ButtonVariantSize } from './types';
import type { ButtonTheme, ButtonVariants, ButtonVariantSize } from './types';
import { cn } from '@vben-core/shared/utils';
@@ -12,6 +12,7 @@ import { buttonVariants } from './button';
interface Props extends PrimitiveProps {
class?: any;
size?: ButtonVariantSize;
theme?: ButtonTheme;
variant?: ButtonVariants;
}
@@ -25,7 +26,8 @@ const props = withDefaults(defineProps<Props>(), {
<Primitive
:as="as"
:as-child="asChild"
:class="cn(buttonVariants({ variant, size }), props.class)"
disabled
:class="cn(buttonVariants({ variant, size, theme }), props.class)"
>
<slot></slot>
</Primitive>

View File

@@ -6,18 +6,23 @@ export const buttonVariants = cva(
defaultVariants: {
size: 'default',
variant: 'default',
theme: 'default',
},
variants: {
theme: {
'ant-design': '',
default: '',
},
size: {
default: 'h-9 px-4 py-2',
icon: 'h-8 w-8 rounded-sm px-1 text-lg',
lg: 'h-10 rounded-md px-4',
sm: 'h-8 rounded-md px-2 text-xs',
small: 'h-8 rounded-md px-2 text-xs',
xs: 'h-8 w-8 rounded-sm px-1 text-xs',
},
variant: {
default:
'bg-primary text-primary-foreground shadow hover:bg-primary/90',
default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
destructive:
'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive-hover',
ghost: 'hover:bg-accent hover:text-accent-foreground',
@@ -26,9 +31,20 @@ export const buttonVariants = cva(
link: 'text-primary underline-offset-4 hover:underline',
outline:
'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground',
secondary:
'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',
secondary: 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',
},
},
compoundVariants: [
{
theme: 'ant-design',
size: 'default',
class: 'h-8 rounded-md px-4 text-sm',
},
{
theme: 'ant-design',
size: 'small',
class: 'h-6 rounded-md px-2 text-sm',
},
],
},
);

View File

@@ -3,6 +3,7 @@ export type ButtonVariantSize =
| 'icon'
| 'lg'
| 'sm'
| 'small'
| 'xs'
| null
| undefined;
@@ -18,3 +19,5 @@ export type ButtonVariants =
| 'secondary'
| null
| undefined;
export type ButtonTheme = 'ant-design' | 'default';