如何扩展ANTD的按钮类型
我正在开发一个基于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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论