如何在扩展另一个组件的同时用样式组件编写样式对象?

问题描述 投票:0回答:0

更新

找到正确的语法,只需返回如下结果:

const SButton = styled(Button)(p => { return {color: p.color} });

原题:

基于文档这些可能的样式

// Static object
const Box = styled.div({
  background: 'palevioletred',
  height: '50px',
  width: '50px'
});

// Adapting based on props
const PropsBox = styled.div(props => ({
  background: props.background,
  height: '50px',
  width: '50px'
}));

render(
  <div>
    <Box />
    <PropsBox background="blue" />
  </div>
);

但是我像这样扩展

react-bootstrap
Button

const SButton = styled(Button);

我希望能够像这样编写样式对象:

const SButton = styled(Button)(p => { color: p.color });

但是我得到以下错误:

没有过载匹配这个调用。重载第 1 个,共 3 个,'(第一个: TemplateStringsArray): StyledComponent', 给出 以下错误。 '(p: ThemedStyledProps & ButtonProps> & BsPrefixProps & ButtonProps & { ...; }, 任何>) => void' 不可分配给 'TemplateStringsArray' 类型的参数。
重载 2 of 3,'(第一个:TemplateStringsArray | CSSObject | InterpolationFunction & ButtonProps> & BsPrefixProps<...> & ButtonProps & { ...; }, any>>, ...rest: Interpolation<...>[]): StyledComponent<...>',出现以下错误。 '(p: ThemedStyledProps & ButtonProps> & BsPrefixProps & ButtonProps & { ...; }, 任何>) => void' 不可分配给 'TemplateStringsArray | 类型的参数 | CSS对象 | InterpolationFunction & ButtonProps> & BsPrefixProps<...> & ButtonProps & { ...; },任何>>'。 输入 '(p: ThemedStyledProps & ButtonProps> & BsPrefixProps & ButtonProps & { ...; }, 任何>) => void' 不可分配给类型 'InterpolationFunction & ButtonProps> & BsPrefixProps & ButtonProps & { ...; },任何>>'。 类型 'void' 不可分配给类型 'Interpolation & ButtonProps> & BsPrefixProps & ButtonProps & { ...; }, 任何>>'.
重载 3 of 3,'(第一个:TemplateStringsArray | CSSObject | InterpolationFunction & ButtonProps> & BsPrefixProps<...> & ButtonProps & { ...; } & object, any>>, ...rest: Interpolation<...>[]): StyledComponent<...>', 给出了以下内容 错误。 '(p: ThemedStyledProps & ButtonProps> & BsPrefixProps & ButtonProps & { ...; }, 任何>) => void' 不可分配给 'TemplateStringsArray | 类型的参数 | CSS对象 | InterpolationFunction & ButtonProps> & BsPrefixProps<...> & ButtonProps & { ...; } & 对象,任何>>'。 输入 '(p: ThemedStyledProps & ButtonProps> & BsPrefixProps & ButtonProps & { ...; }, 任何>) => void' 不可分配给类型 'InterpolationFunction & ButtonProps> & BsPrefixProps & ButtonProps & { ...; } & 目的, 任何>>'。 类型 'void' 不可分配给类型 'Interpolation & ButtonProps> & BsPrefixProps & ButtonProps & { ...; } & 目的, 任何>>'.

styled-components
© www.soinside.com 2019 - 2024. All rights reserved.