首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不具有样式的可重用组件的响应样式-组件

问不具有样式的可重用组件的响应样式-组件
EN

Stack Overflow用户
提问于 2019-09-18 16:35:04
回答 1查看 177关注 0票数 0

我有一个可重用的组件,它包含一个名为AnimationLoader的动画。此组件是用于加载状态的可重用组件。我只是尝试接受这个组件,并在另一个组件中使用它,UnpublishBlogBtn作为加载程序,在单击按钮之后--这一切都很好。然而,我想改变UnpublishBlogBtn内动画的高度和宽度,而我的生活无法使它正常工作。

我尝试实现Object.assign,从另一个文件中引入CSS,只需改变高度和宽度。我还尝试通过执行<style={{}}>来更改CSS,并将组件包装在一个有样式添加的div中(这似乎只是改变了按钮,而不是动画本身)。

代码语言:javascript
复制
<Button type="main" className="blogBtn">
   {currentlyUnpublishingBlog ? <AnimatedLoader css={{ height: 1, width: 1 }}/> : 
   'Unpublish Blog'}
</Button>
代码语言:javascript
复制
const AnimatedLoader = () => {
  return (
    <div
      css={{
        height: 45,
        width: 45
      }}
    >
      <AnimatedIcon 
        css={{
          animationDelay: '0.7s',
          height: 35,
          left: 10,
          position: 'absolute',
          top: 10,
          width: 35
        }}
      />
      <AnimatedIcon 
        css={{
          animationDelay: '0.7s'
          display: 'none',
          height: 45,
          left: 0,
          top: 0,
          width: 45,
        }}
      />
      <div
        css={{
          borderRadius: 20,
          borderStyle: 'solid',
          borderWidth: 3,
          height: 45,
          position: 'absolute',
          width: 45,
        }}
      />
    </div>
  )
};

export default AnimatedLoader;

用户单击Unpublish按钮后,加载程序应该在按钮顶部显示较小的宽度和高度。目前,它保持与AnimatedLoader组件中列出的大小相同的大小,我希望在UnpublishBlogBtn组件中更改大小。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-18 16:40:12

你可以把你的css作为道具传递给你的AnimatedLoader

代码语言:javascript
复制
 const AnimatedLoader = ({css={
        height: 45,
        width: 45
      }}) => {
  return (
    <div
      {...css}
    >
      <AnimatedIcon 
        css={{
          animationDelay: '0.7s',
          height: 35,
          left: 10,
          position: 'absolute',
          top: 10,
          width: 35
        }}
     // ....

如果您需要做更复杂的事情,那么传递一个将不同样式的选项描述为一个组的道具可能更明智。因此,isSmallSize作为布尔值,或者不同大小的值作为枚举等等。

然后,在组件中,根据支柱来调整样式。

代码语言:javascript
复制
const AnimatedLoader = ({ isSmallSize = false }) => {
    const outerSize = isSmallSize ? 
                       { height: 45, width: 45 } : { height: 1, width: 1 }
    const iconSize = isSmallSize ? 
                       { height: 35, width: 35 } : { height: 1, width: 1 }
    return (
       <div css={{ ...outerSize }}>
         <AnimatedIcon
           css={{
             animationDelay: '0.7s',
             left: 10,
             position: 'absolute',
             top: 10,
             ...iconSize
           }}
         />
         <AnimatedIcon
           css={{
             animationDelay: '0.7s',
             display: 'none',
             left: 0,
             top: 0,
             ...iconSize
           }}
         />
         <div
           css={{
             borderRadius: 20,
             borderStyle: 'solid',
             borderWidth: 3,
             position: 'absolute',
             ...iconSize
           }}
      />
    </div>
  )
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57997259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档