首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-styled flexboxgrid不同视口的不同配置

react-styled flexboxgrid不同视口的不同配置
EN

Stack Overflow用户
提问于 2019-03-12 21:00:38
回答 1查看 211关注 0票数 1

我在https://github.com/yldio/joyent-react-styled-flexboxgrid项目中使用这个网格库,我想为3种不同的屏幕尺寸(不同的gutterWidth和列数)添加3种不同的配置。

在文档中,我只看到创建一个配置并通过主题传递它的可能性。这里有谁知道任何解决方案或其他库,以满足我的需求。

编辑:项目使用NextJS for SSR。

EN

回答 1

Stack Overflow用户

发布于 2019-03-12 22:11:50

在我看来,您应该使用ThemeProvider并根据屏幕宽度更改theme属性。

代码语言:javascript
复制
import React from 'react'

import {ThemeProvider} from 'styled-components'
import {Grid, Col, Row} from 'react-styled-flexboxgrid'

const theme = {
  flexboxgrid: {
    // Defaults
    gridSize: 12, // columns
    gutterWidth: 1, // rem
    outerMargin: 2, // rem
    mediaQuery: 'only screen',
    container: {
      sm: 46, // rem
      md: 61, // rem
      lg: 76  // rem
    },
    breakpoints: {
      xs: 0,  // em
      sm: 48, // em
      md: 64, // em
      lg: 75  // em
    }
  }
}

const sizedTheme = 
    (typeof window !== 'undefined') && 
    (window.innerWidth < 500) ? { ...theme, gutterWidth: .5 } : theme;

const App = props =>
  <ThemeProvider theme={sizedTheme}>
    <Grid>
      <Row>
        <Col xs={6} md={3}>Hello, world!</Col>
      </Row>
    </Grid>
  </ThemeProvider>

像这样的东西,根据你的目标进行调整。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55122127

复制
相关文章

相似问题

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