import { AnchorHTMLAttributes, ButtonHTMLAttributes, FC, HTMLAttributes, MouseEvent, Ref } from 'react'; import { ButtonLoadingType, ButtonShape, SvgFC } from '@befe/brick-core'; type AnchorButtonProps = Omit, 'href' | 'target' | 'onClick' | 'style'>; type NativeButtonProps = Omit, 'type' | 'onClick' | 'style'>; export interface ButtonProps extends Partial { /** * 自定义 class */ className?: string; /** * 尺寸 * use config context `baseSize` as default */ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'; /** * 形状 * @private 规范暂无定义,隐藏 * 存在是因为,此前为了支持 hi 作为二级规范的扩展需要(现 luffy 组件库) */ shape?: ButtonShape; /** * 是否禁用 */ disabled?: boolean; /** * 类型 */ type?: 'normal' | 'intensive' | 'important' | 'plain' | 'ghost'; /** * 颜色 * * **NOTE** 已废弃的 `primary` 仍会在运行时归一到 `brand`,但不再作为合法类型 */ color?: 'normal' | 'brand' | 'success' | 'danger' | 'warning'; /** * 图标 */ icon?: FC; /** * 控制是否处于 loading 状态 * - loading spin icon 会根据 loadingDelay 延迟显示 * - loading 状态 click 无效,但无 disabled 样式 */ loading?: boolean; /** * 自定义 loading Icon */ loadingIcon?: SvgFC; /** * loading 类型 */ loadingType?: ButtonLoadingType; /** * loading 图标的延迟响应时间 * 单位 ms * 0 为立即显示 */ loadingDelay?: number; /** * 链接跳转的地址 * 若给如非 undefined 的值,将使用 作为 Button 的元素 */ href?: string; /** * 链接跳转的 target */ target?: string; /** * download 属性 * * 用以指示浏览器去下载 href 所指的资源,而不是导航打开 */ download?: string; /** * 点击回调 * 返回 promise 会自动触发 async action 模式而进入 loading 状态直到 promise.resolve() * - loading 状态将不再触发 onClick,即自动防连击 * - loading spin icon 会根据 loadingDelay 延迟显示 */ onClick?: ((e: MouseEvent) => void | Promise) | ((e: MouseEvent) => void | Promise); /** * ref html element */ refHTMLElement?: Ref | Ref; } export interface ButtonState { showLoading: boolean; asyncLoading: boolean; } export interface GroupedButtonsProps extends HTMLAttributes { /** * 自定义 class */ className?: string; } export {};