[React] Styled System with extendable Box element

You can have a Box element, which just used for create other element or layout:

复制代码
// example Box.js
import styled from 'styled-components'
import { space, color, layout } from 'styled-system'

const Box = styled.div(
  {
    boxSizing: 'border-box',
    minWidth: 0,
  },
  space,
  color,
  layout
)

export default Box
复制代码

 

Just put 'space', 'color' and 'layout' so that, you can use it with the component built based on Box.

复制代码
import styled from 'styled-components'
import Box from './Box'

const Grid = styled(Box)({
  display: 'grid'
})

Grid.propTypes = Box.propTypes

export default Grid;
复制代码

 

 

Because we have used 'space', 'color' and 'layout' on box, so that we can also do:

复制代码
<Grid
  as="footer"
  gridGap={3}
  justifyContent={[null, 'space-between']}
  justifyItems={['center', null]}
  gridAutoFlow={[null, 'column']}
>
  <Box>© Chuck Norris, 1940</Box>
  <Box>Have a nice day!</Box>
</Grid>
复制代码

 

posted @   Zhentiw  阅读(174)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2019-08-25 Define Interfaces and Share Class Members through Mixins in Dart
2019-08-25 [Dart] Understand Classes and Inheritance in Dart
2016-08-25 [WebGL] Setting Up WebGL
2016-08-25 [Redux] Accessing Dispatch and State with Redux -- connect
2015-08-25 [Angular 2] 8. Better ES5 Code
点击右上角即可分享
微信分享提示