如何扩展ANTD的按钮类型

发布于 2025-01-28 02:40:09 字数 1461 浏览 1 评论 0原文

我正在开发一个基于ANTD(我称之为yoooo ui)的UI框架,

而ANTD的默认样式有所不同,我做了一些事情来设置不同的颜色,大小,保证金和Blablabla,并使用更少的变量设置 - 请遵循官方解决方案。

另外,还有一些新的东西,例如我扩展了按钮的类型 - 添加'atype','btype','ctype'到button component。 一样使用它

import { Button } from 'yooooo-ui';

<Button type="atype" />

这意味着我可以将其像解决方案

import { ButtonType } from 'antd/lib/button';
import { BaseButtonProps } from 'antd/lib/button/button';

const ExtendedButtonTypes = tuple(
  'atype',
  'btype',
  'ctype'
);

type ExtendButtonType = typeof ExtendedButtonTypes[number];
type MyButtonType = ButtonType | ExtendButtonType;

interface MyBaseButtonProps extends Omit<BaseButtonProps, 'type'> {
  type?: MyButtonType;
}

// ...something else codes

来支持此功能,但是有一个条件是modal组件使用button component antd中的相对路径。

// codes in antd
import { ButtonProps } from './button'
// ...something else

这意味着,如果我在yoooo ui中什么都不做并使用modal组件,则按钮类型'Atype'是无效的,因为modal component do d do d'' t使用我的自定义按钮组件,

import { Modal } from 'yoooo-ui';

const buttonProps = {
  type: 'atype' // <-- error happened
}

<Modal
  okButtonProps={buttonProps}
/>

我想找出一种通常以一种方式处理此条件的方法。

I am developing an UI framework based on antd (I call it Yooooo UI)

The design is a little different with the default style of antd and I did something to set the different color, size, margin and blablabla with setting less variables - follow the official solution.

Also, there is something new, such as I extend the type of Buttons - add 'atype', 'btype', 'ctype' to Button Component. That means I can use it like

import { Button } from 'yooooo-ui';

<Button type="atype" />

The solution for supporting this is here below

import { ButtonType } from 'antd/lib/button';
import { BaseButtonProps } from 'antd/lib/button/button';

const ExtendedButtonTypes = tuple(
  'atype',
  'btype',
  'ctype'
);

type ExtendButtonType = typeof ExtendedButtonTypes[number];
type MyButtonType = ButtonType | ExtendButtonType;

interface MyBaseButtonProps extends Omit<BaseButtonProps, 'type'> {
  type?: MyButtonType;
}

// ...something else codes

But there is a condition that Modal component used the Button component with a relative path in antd.

// codes in antd
import { ButtonProps } from './button'
// ...something else

that means, if I do nothing in Yoooo UI and use the Modal component, the button type 'atype' is invalid since Modal component doesn't use my customized Button component

import { Modal } from 'yoooo-ui';

const buttonProps = {
  type: 'atype' // <-- error happened
}

<Modal
  okButtonProps={buttonProps}
/>

I wanna figure out a way to handle this condition with a commonly way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文