- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个主题文件:
const theme = {
colors: {
dark: "#212121",
normal: "#9E9E9E",
light: "#EEEEEE"
},
typography: {
textSize: "14px",
subtitleSize: "28px",
titleSize: "56px"
}
};
export default theme;
我将它们传递到我的应用程序组件中:
class App extends Component {
render() {
return (
<ThemeProvider theme={theme}>
<Provider {...this.props.stores}>
<Router>
<AppStyles className="app-container">
<Header />
<Main />
</AppStyles>
</Router>
</Provider>
</ThemeProvider>
);
}
}
然后像这样访问嵌套组件:
const HeaderStyles = s.div`
.link-icon {
font-size: ${props => props.theme.typography.subtitleSize};
}
.header-link > a {
font-size: ${props => props.theme.typography.textSize};
color: ${props => props.theme.colors.normal};
text-decoration: none;
}
.header-link .active-link {
color: ${props => props.theme.colors.dark};
}
`;
有没有比每次访问主题 Prop 时都执行 ${props => props.theme.typography.textSize}
更短的方法?
最佳答案
使用 JS 对象表示样式通常是为了保持样式模块化和范围化——这允许您将对象导入到特定组件中,然后使用 dom 元素上的“style”属性传递对象。您的用例似乎违背了这个目的。如果您想使用定义为 JS 对象的样式,我建议避免上面代码块中的间接。或者,考虑使用 CSS 模块或直接 CSS。祝你好运!
关于javascript - 样式化组件 - 比 ${props => props.theme...} 更容易访问传递的主题属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47248495/
我正在开发一个包含大量类的项目,我想将它们编译成 jar。我知道入口点和manifest.txt以及我的jar中的所有需要的项目,我的类都已编译并具有.class文件和所有内容,但问题是我必须将所
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
在我的计算结束时,我打印结果: System.out.println("\nTree\t\tOdds of being by the sought author"); for (ParseTree p
我有一个具有多个时间范围的数据,例如考虑以下列 | from1 | to1 | from2 | to2 | from3 | to3 | | 06:00 | 07:30 | 09:30 |
我对 JavaScript 和 jQuery 相当缺乏经验,但对于我正在处理的 ASP.Net 网站,我需要两者。我正在慢慢弄清楚,但我一直严重依赖 StackOverFlow。 有谁知道有什么工具(
我正在考虑用 PHP 编写一些代码来更改图像的所有 id 以匹配其 alt。在 jQuery 中这会更容易实现吗? 我需要做的是走这条线 img alt="拼图"src="images/cole.jp
鉴于 websinte 的结构
假设我有 struct Value { int foo(); }; size_t *begin = ..., *end = ...; 如果我想在 C++03 中对一堆 Value 索
我开始创建一个将与公共(public) API 交互的 iPhone 应用程序。 我的问题是,使用 XML 还是 JSON 哪个更快和/或更容易? 最佳答案 根据 Sam Soffes , Touch
如果 PHP 是用 C 编写的,那么用 PHP 编写服务器端脚本与用 C 编写服务器端脚本究竟有什么区别,尤其是如果我使用的是 C 的 Web 框架可以处理 mysql 连接、SESSIONS 等?
我记得有一次看到一个人做的一个项目,他用某种语言用类似 json 的字符串编写了这样的东西,创建了非常好的 html。有没有类似的东西我可以用于 C# 或 .NET radio-box{ AName,
我的一位网页设计师 friend 仍在使用表格制作网站,但他使用 css 非常好,我也很好地使用 css,但使用 而且我在布局方面比我的 friend 更多地面临跨浏览器问题。 我向我的 friend
我想创建一个图,在那里可以看到 x 轴的替代刻度,例如pi/2, pi, 3pi/2, 等等。到目前为止,这对我来说只适用于一个相当不方便的代码(看看我创建的行 pi.halfs , pi.fulls
我是一名优秀的程序员,十分优秀!