我正在创建一组使用 CSS 设置样式的可重用组件(包装材料 UI)。我需要通过传入自定义按钮的道具动态设置组件的宽度。
我想使用类名来合并为 MyButton 定义的 const 根样式(我已在沙箱中将其剥离,但它设置了颜色、图标等)和可以根据传入的 prop 定义的动态 sizeStyle。
const sizeStyle: JSON = { minWidth: "300px !important"};
//always apply the buttonstyle, only apply the size style if a width prop has been supplied
const rootStyle: Object = classNames({
buttonStyle: true,
sizeStyle: props.width
///});
我看不出为什么样式没有应用于页面上的第一个按钮,其中有一个道具通过 - 我可以在控制台上看到这两种样式应该被应用。
这里的沙箱: https ://codesandbox.io/s/css-styling-custom-muibutton-width-as-prop-36w4r
TIA