【发布时间】:2018-02-04 07:57:09
【问题描述】:
有没有办法同时使用styled-components 和react-bootstrap? react-bootstrap 为其组件公开bsClassproperties 而不是className,这似乎与样式化组件不兼容。
有什么经验吗?
【问题讨论】:
标签: reactjs react-bootstrap styled-components
有没有办法同时使用styled-components 和react-bootstrap? react-bootstrap 为其组件公开bsClassproperties 而不是className,这似乎与样式化组件不兼容。
有什么经验吗?
【问题讨论】:
标签: reactjs react-bootstrap styled-components
您可以扩展样式以保持组件的原始样式不受引导。你会发现更多关于使用第三方库的文档,比如 react bootstrap with styled-components here。
const StyledButton = styled(Button)`
color: palevioletred;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;
`;
这里有一个沙盒供参考:https://codesandbox.io/s/2vpm40qk90
【讨论】:
className 属性传入的第三方或外部组件。
styled(Carousel)` border: 2px solid red; & .carousel-control { background-image: none; } `;
each feature of border 的意思吗?任何有效的 CSS 在样式组件内都是有效的
; Instead, I think it's suppose to be written like this to be recognized by current compiler: const StyledButton = styled(Button) ...边框宽度:2px;边框颜色:淡紫色; ...`;这仅与样式组件有关。对于常规 CSS,它确实有效。
我想提供一个更好的选择和方法。
我之前一直在使用 react-bootstrap,我们发现当前的实现并没有完全将 bootstrap 移植到 react 中,我们仍然需要依赖外部文件,例如 CSS/Fonts,这不是样式组件的理念和最佳实践.
考虑到 styled-components 提供 css 接口,我们在一个名为 bootstrap-styled 的项目中移植了具有最佳 ES6 实践的 bootstrap 4。
此 Twitter Bootstrap v4 bootstrap 实现完全针对样式化组件实现,无需 CSS 或额外文件。
从完整的 js api、主题、模块化和可重用性开始,这带来了几个好处。
要覆盖样式,可以通过<ThemeProvider /> 或在any component 上使用props.theme 来完成。我们还导出了一个包含<ThemeProvider /> 的<BootstrapProvider /> 组件,并在其范围内提供了诸如.d-none 等引导类实用程序。
你可以看到demo here
【讨论】:
styled(text-center) font-color: #abc123;`