reactjs - 如何在 Ant Design 中为现有属性添加额外的变量?
问题描述
AntD 中的Button
组件有一个type
接受变量的属性primary
dashed
ghost
danger
。如何type=success
在我的文件中添加使用特定颜色定义成功的位置.less
?我不是指 AntD 的示例,他们指出如何修改预先存在的原色,而是创建一个新的原色。
解决方案
您可以创建一个新组件,该组件将使用 Ant Design 中的按钮组件。
import { Button } from 'antd';
const antdTypes = ['primary', 'dashed', 'ghost', 'danger'];
function ExtendedButton({ type, ...rest }) {
if (antdTypes.inclues(type))
return <Button type={type} {...rest} />
else
return <Button className={`button--${type}`} {...rest} />
}
例如,您将能够创建 CSS/LESS 类button--success
,然后将类名的第二部分(来自 BEM 的 M)作为道具传递
推荐阅读
- selenium - Testng 获取没有 BeforeMethod 的组名
- django - 在 Django 管理表单中显示创建和编辑的字段
- c# - 使用 c# 即时解压缩谷歌存储上的文件
- python - 如何验证来自 json 响应(Python)的数据?
- reactjs - 用于重度嵌套对象的 TypeScript 类型
- python - 如何根据文件夹中图像文件的字母字符读取python中的图像?
- python - 如何在具有授权的python中发出url请求
- java - MEMORY_LIMIT_EXCEEDED 错误,我用什么代替数组?
- email - 自定义电子邮件的 WooCommerce pdf 附件不起作用
- python - 用法:godaddy bot.py [-h] domain godaddy bot.py: 错误:需要以下参数:domain