【发布时间】:2021-12-10 22:35:08
【问题描述】:
我正在尝试根据导入的每个页面修改按钮。我们来看看我的按钮组件。
import React from "react";
import "./Button.css";
export interface Props {
marginLeft?: string;
name?: string;
backgroundColor?: string;
color?: string;
width?: string;
onClick?: () => void;
border?: string;
fontWeight?: number;
fontSize?: string;
lineHeight?: string;
marginBottom?: string;
height?: string;
display?: string;
alignItems?: string;
}
export const Button: React.FC<Props> = ({
name,
backgroundColor,
onClick,
color,
border,
width,
height,
marginLeft,
fontWeight,
fontSize,
lineHeight,
marginBottom,
display,
alignItems,
}) => {
return (
<button
className="myButton"
style={{
background: backgroundColor,
color: color,
border: border,
width: width,
marginLeft: marginLeft,
fontWeight: fontWeight,
fontSize: fontSize,
lineHeight: lineHeight,
marginBottom: marginBottom,
height: height,
alignItems: alignItems,
display: display,
}}
onClick={onClick}
>
{name}
</button>
);
};
export default Button;
问题来自我的导师。他说我不应该这样做,比如通过 props 发送我的 css ......他建议我更改它并在我导入按钮的每个特定位置使用 className 并且我想更改某些内容。
在他建议我更改之前,我是这样做的。
<Button
backgroundColor="white"
border="1px solid #595959"
width="100%"
name="Add a team member + "
color="#595959"
fontWeight={200}
height="52px"
marginBottom="25px"
/>
<Button
width="13%"
name="Submit Project"
border="none"
color="#FFFFFF"
/>
而且我不知道如何在组件上编写 className。我的意思是我每次尝试做某事时都会出现一个错误,提示我无法做到。你能指导我应该怎么做吗? 我会问我的导师他是不是那么可怕......他没有那么笑......你知道他是一个超过 8 年的编程人员。
【问题讨论】:
标签: javascript css reactjs typescript