【发布时间】:2020-02-17 21:42:09
【问题描述】:
我想用 typescript 和 styled 组件覆盖 Button Ant Design 以个性化样式。但是当我尝试结果并不好。
我尝试了一些测试,但从未有过良好的显示效果。
我尝试这样How to wrap up Ant Design with Styled Components and TypeScript? 但没有结果。
但是结果不是ant Design组件的样式而是button继承了Button ant design和她的props。
ButtonStyledComponent
import { Button as AntButton } from "antd";
import { NativeButtonProps } from "antd/lib/button/button";
import * as React from "react";
import styledComponents from "styled-components";
export const Button = styledComponents<NativeButtonProps>(props => (
<AntButton {...props} />
))`
pType: string;
pSize: string;
pShape: string;
`;
按钮
import * as React from "react";
import { Button } from "./ButtonStyleComponent";
export interface ButtonProps {
pType?: "primary" | "secondary" | "danger";
pSize?: "small" | "medium" | "large";
pShape?: "round" | "rect";
}
class Button extends React.Component<ButtonProps> {
render() {
return (
<Button
{...this.props}
pType={this.props.pType}
pSize={this.props.pSize}
pShape={this.props.pShape}
>
{this.props.children}
</Button>
);
}
}
导出{按钮};
问题是当我执行这段代码时,我只看到一个丑陋的灰色按钮,而不是一个带有 Ant Design Button 设计的按钮。
另一个问题是当我尝试调用 Ant Design Button 的方法时,该方法无法识别(例如:方法 onClick )。
【问题讨论】:
标签: reactjs typescript styled-components antd