Files
xiaoxia-saas/apps/web/src/components/ui/Button.tsx
T
xiaoxia 0fcb77b991
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Successful in 1m6s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 1m49s
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 3m1s
CI/CD Pipeline / Unit Tests (push) Successful in 3m20s
CI/CD Pipeline / Integration Tests (push) Successful in 1m29s
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 7m4s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 7m54s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 45s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 2m50s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Successful in 3m28s
ci: Prettier纳入两层防御体系 (#520)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-07-18 18:08:19 +08:00

91 lines
2.0 KiB
TypeScript

/**
* V21 Button 按钮
* 封装 Ant Design Button,应用 V21 设计系统样式
*/
import React from "react"
import { Button as AntButton } from "antd"
import type { ButtonProps as AntButtonProps } from "antd"
import classNames from "classnames"
import "./ui.css"
export type ButtonType = "primary" | "secondary" | "ghost" | "text" | "danger" | "link"
export type ButtonSize = "sm" | "md" | "lg"
export interface ButtonProps extends Omit<AntButtonProps, "type" | "size"> {
/** 按钮类型 */
buttonType?: ButtonType
/** 按钮尺寸 */
buttonSize?: ButtonSize
/** 兼容 antd type(用于直接替换) */
type?: AntButtonProps["type"]
/** 兼容 antd size */
size?: AntButtonProps["size"]
}
const TYPE_CLASS_MAP: Record<ButtonType, string> = {
primary: "xx-btn-primary",
secondary: "xx-btn-secondary",
ghost: "xx-btn-ghost",
text: "xx-btn-text",
danger: "xx-btn-danger",
link: "xx-btn-link",
}
const SIZE_CLASS_MAP: Record<ButtonSize, string> = {
sm: "xx-btn-sm",
md: "xx-btn-md",
lg: "xx-btn-lg",
}
/** 将 buttonType 映射到 antd type */
const toAntdType = (bt: ButtonType): AntButtonProps["type"] => {
switch (bt) {
case "primary":
return "primary"
case "danger":
return "primary"
case "link":
return "link"
case "text":
return "text"
default:
return "default"
}
}
const Button: React.FC<ButtonProps> = ({
buttonType = "ghost",
buttonSize = "md",
className,
children,
type,
size,
...rest
}) => {
const antdType = type ?? toAntdType(buttonType)
const antdSize =
size ?? (buttonSize === "sm" ? "small" : buttonSize === "lg" ? "large" : "middle")
const v21Class = classNames(
"xx-btn",
TYPE_CLASS_MAP[buttonType],
SIZE_CLASS_MAP[buttonSize],
className,
)
return (
<AntButton
type={antdType}
size={antdSize}
className={v21Class}
danger={buttonType === "danger" ? true : rest.danger}
{...rest}
>
{children}
</AntButton>
)
}
export default Button