styled-jsx
约 1 分钟阅读
- vercel/styled-jsxGitHubvercel/styled-jsxvercel/styled-jsx · 默认不支持传递样式到 children #573 · 如果 a 是在一个组件里,无法影响到 · 使用 · 或者传递 css.resolve 返回的 className 到子组件 · 启用后不会使用 SWC 编译 - 推荐使用 css module笔记:styled-jsx
- 默认不支持传递样式到 children #573GitHub Issuevercel/styled-jsx#573
.ment-item > a如果 a 是在一个组件里,无法影响到- 使用
.menu-item > :global(a) - 或者传递 css.resolve 返回的 className 到子组件
import css from 'styled-jsx/css';
// 全局样式 - 不使用 className 限定
const body = css.global`
body {
margin: 0;
}
`;
// babel-plugin-macros 可作为 babel macros
const { className, styles } = css.resolve`
a {
color: green;
}
`;
export default () => (
<div>
<style jsx>{`
/* 通过不修饰 a 影响子组件 */
div > :global(a) {
// 通过 styled-jsx-plugin-postcss 使用 postcss - 使用 tailwind
@apply text-red;
}
`}</style>
{/* 通过传递 className 影响子组件 */}
<Link className={className}>About</Link>
{styles}
{/* 渲染 global */}
<style jsx global>
{body}
</style>
</div>
);tailwind
- 启用后不会使用 SWC 编译 - 推荐使用 css module
{
"presets": [
[
"next/babel",
{
"styled-jsx": {
"plugins": ["styled-jsx-plugin-postcss"]
}
}
]
]
}关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- Web Awesome笔记 · styled-jsx
https://www.c82.net/iconography/ · https://www.photopea.com/ · ryohey/signal · MIT, TS · Online MIDI Editor: signal · http://oskarstalberg.com/Townscaper/
参考资料
GitHub2 条
- vercel/styled-jsxgithub.com/vercel/styled-jsx
- vercel/styled-jsx#573github.com/vercel/styled-jsx/issues/573