Javascript 导入PropType以设置组件的颜色

Javascript 导入PropType以设置组件的颜色,javascript,css,reactjs,react-hooks,storybook,Javascript,Css,Reactjs,React Hooks,Storybook,因此,我试图将控件添加到我的故事书组件中。我很难弄清楚如何更改css样式。我已经设置了proptypes来帮助我处理组件的背景颜色,但我不知道如何将其引入到我的故事中。现在,我的背景色什么都不是。我想它是一个特定的颜色开始。我在用React。我在下面添加了我的代码,非常感谢您的帮助 Style.js: import PropTypes from 'prop-types'; import styled from 'styled-components'; import { colors } from

因此,我试图将控件添加到我的故事书组件中。我很难弄清楚如何更改css样式。我已经设置了proptypes来帮助我处理组件的背景颜色,但我不知道如何将其引入到我的故事中。现在,我的背景色什么都不是。我想它是一个特定的颜色开始。我在用React。我在下面添加了我的代码,非常感谢您的帮助

Style.js:

import PropTypes from 'prop-types';
import styled from 'styled-components';
import { colors } from '../utilities';

export const StyledButton = styled.button`
  color: ${colors.text500};
  text-transform: uppercase;
  width: 300px;
  height: 50px;
  font-size: 1.1em;
  letter-spacing: 0.1em;
  margin: 1em;
  padding: 0.25em 1em;
  border-radius: 5px;
  border: none;
  background: ${props => props.color};
`;

StyledButton.PropTypes = {
  color: PropTypes.string.isRequired,
};

export default StyledButton;
Button.stories.js

import React from "react";
import Button from "./Button";
import { colors } from '../utilities';

export default {
  title: "Button",
  component: Button
};

export const Primary = (args) => <Button {...args} />;

Primary.args = {
  label: 'Download',
  color: '${colors.primary500}',
};
从“React”导入React;
从“/”按钮导入按钮;
从“../utilities”导入{colors};
导出默认值{
标题:“按钮”,
组件:按钮
};
导出常量Primary=(args)=>;
Primary.args={
标签:“下载”,
颜色:“${colors.primary500}”,
};

使用@JosephD。“在哪里?”约瑟夫。我尝试过像这样和其他几种方式来更改它,但它不起作用:export const Primary=(args,props)=>;Primary.args.defaultProps={label:'Download',background:'${colors.primary500}',};尝试
Primary.defaultProps
@JosephD。是的,不幸的是,那也不行。