Code Monkey home page Code Monkey logo

grid's Introduction

Rebass Grid

Responsive React grid system built with styled-system, with support for styled-components and emotion (previously called grid-styled)

https://rebassjs.org/grid

Build Status Downloads Version

Getting Started

npm i @rebass/grid
import React from 'react'
import { Flex, Box } from '@rebass/grid'

const App = () => (
  <Flex>
    <Box width={1/2} px={2}>
      Half width
    </Box>
    <Box width={1/2} px={2}>
      Half width
    </Box>
  </Flex>
)

Emotion

Or for emotion , import @rebass/grid/emotion (uses v10 @emotion/styled)

import { Flex, Box } from '@rebass/grid/emotion'

Box

The Box component handles width, margin and padding.

// Different widths at different breakpoints
<Box
  width={[
    1/2,
    1/3,
    1/4,
    1/6
  ]}
/>

// Fixed pixel width
<Box width={256} />

// CSS value width
<Box width='40em' />
// Padding
<Box p={2} />

// Padding top
<Box pt={2} />

// Padding bottom
<Box pb={2} />

// Padding left
<Box pl={2} />

// Padding right
<Box pr={2} />

// x-axis padding (left and right)
<Box px={2} />

// y-axis padding (top and bottom)
<Box py={2} />
// Margin
<Box m={2} />

// Margin top
<Box mt={2} />

// Margin bottom
<Box mb={2} />

// Margin left
<Box ml={2} />

// Margin right
<Box mr={2} />

// x-axis margin (left and right)
<Box mx={2} />

// y-axis margin (top and bottom)
<Box my={2} />
// margin auto
<Box m='auto' />

// negative margins
<Box mx={-2} />

Props

All @rebass/grid components use styled-system for style props, which pick up values from a theme and allow for responsive styles to be passed as array values.

width (number|string|array)

Sets width, where numbers 0-1 are percentage values, larger numbers are pixel values, and strings are raw CSS values with units. Pass an array to set different widths at different breakpoints for responsive styles.

Margin and Padding Props

Both margin and padding props accept numbers, strings, and arrays as values. Using a number from 0-8 (i.e. an index of theme.space) will reference a step on the spacing scale. Larger numbers are converted to pixel values. Negative Numbers can be used to set negative margins and compensate for grid gutters. Strings are passed directly for other valid CSS values.

Use array values to set different margin or padding values per breakpoint for responsive styles.

Margin and padding props follow a shorthand syntax for specifying direction.

  • m: margin
  • mt: margin-top
  • mr: margin-right
  • mb: margin-bottom
  • ml: margin-left
  • mx: margin-left and margin-right
  • my: margin-top and margin-bottom
  • p: padding
  • pt: padding-top
  • pr: padding-right
  • pb: padding-bottom
  • pl: padding-left
  • px: padding-left and padding-right
  • py: padding-top and padding-bottom

flex (string|array)

Sets the flex property.

<Box flex='1 1 auto' />

order (number|string|array)

Sets the order property.

<Box order={2} />

alignSelf (string|array)

Sets the align-self property.

<Box alignSelf='flex-end' />

css (string|object)

Pass styles to styled-components or emotion. This is useful as an escape hatch for one-off styles or as a way to extend Rebass Grid components.

<Box
  bg='blue'
  css={{
    borderRadius: '4px'
  }}
/>

Flex

The Flex component extends the Box component and sets display flex.

import React from 'react'
import { Flex, Box } from '@rebass/grid'

const App = props =>
  <Flex>
    <Box>Flex</Box>
    <Box>Box</Box>
  </Flex>

In addition to the Box component props, Flex also includes the following:

  • alignItems (string|array) sets align-items
  • justifyContent (string|array) sets justify-content
  • flexDirection (string|array) sets flex-direction
  • flexWrap (string|array) sets flex-wrap: wrap

Responsive Styles

Rebass Grid props accept arrays as values for mobile-first responsive styles, where the first value is for all breakpoints, then each value after is for a min-width media query from that breakpoint and up.

// 100% below the smallest breakpoint,
// 50% from the next breakpoint and up,
// and 25% from the next breakpoint and up
<Box width={[ 1, 1/2, 1/4 ]} />

// responsive margin
<Box m={[ 1, 2, 3, 4 ]} />

// responsive padding
<Box p={[ 1, 2, 3, 4 ]} />

Extending Components

Component can be extended with React or using styled-components or emotion.

InlineFlex

import React from 'react'
import { Flex } from '@rebass/grid'

const InlineFlex = props =>
  <Flex
    {...props}
    css={{
      display: 'inline-flex'
    }}
  />
// styled-components example
import styled from 'styled-components'
import { Flex } from '@rebass/grid'

const InlineFlex = styled(Flex)`
  display: inline-flex;
`

Max-Width Container

import React from 'react'
import { Box } from '@rebass/grid'

const Container = props =>
  <Box
    {...props}
    mx='auto'
    css={{
      maxWidth: '1024px'
    }}
  />
// styled-components example
import styled from 'styled-components'
import { Box } from '@rebass/grid'

const Container = styled(Box)`
  max-width: 1024px;
`
Container.defaultProps = {
  mx: 'auto'
}

Auto Grid

This example creates components for a grid with set gutters where the columns expand to fill in the space.

// Example
import React from 'react'
import { Flex, Box } from '@rebass/grid'

const Row = props => (
  <Flex
    {...props}
    mx={-3}
  />
)

const Column = props => (
  <Box
    {...props}
    px={3}
    flex='1 1 auto'
  />
)

Changing the HTML element

Rebass Grid is intended for use with styled-components v4. To change the underlying HTML element, use the styled-components as prop.

<Box as='header' />

Note: Previous versions of grid-styled supported an is prop, which has been deprecated in favor of the styled-components as prop.

Theming

Rebass Grid uses smart defaults, but to customize the values, use the ThemeProvider component from styled-components or emotion.

import React from 'react'
import { ThemeProvider } from 'styled-components'
import { Box } from '@rebass/grid'

const theme = {
  space: [ 0, 6, 12, 18, 24 ],
  breakpoints: [ '32em', '48em', '64em' ]
}

const App = () => (
  <ThemeProvider theme={theme}>
    <div>
      <Box width={[1, 1/2, 1/4]} px={2}>Box with custom spacing scale and breakpoints</Box>
    </div>
  </ThemeProvider>
)

Breakpoints

The Flex and Box components use a mobile-first responsive approach, where any value set works from that breakpoint and wider. Breakpoints are hard-coded to the following min-widths: 40em, 52em, 64em.

To customize, provide an array of string values that will be converted to media queries.

Spacing Scale

Rebass Grid components' margin and padding props use a 4 step spacing scale to help keep things aligned and keep layouts consistent.

The default scale is based on an 8px/powers-of-two grid: [ 0, 4, 8, 16, 32, 64, 128, 256, 512 ], which helps keep spacing consistent and elements aligned even when nesting components.

Styled Space

Rebass Grid also works with the optional Rebass Space package.

import React from 'react'
import { Flex, Box } from '@rebass/grid'
import Space from '@rebass/space'

const App = () => (
  <Flex>
    <Space mx={3}>
      <h1>Hello</h1>
      <Box>Beep</Box>
    </Space>
  </Flex>
)

Related

MIT License

grid's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grid's Issues

Weird prop-types error started popping roughly 7 days ago

Nothing has changed on my end code-wise, but I started getting this error during webpack build roughly 7 days ago.

ERROR in main.d9eb1ec8.js from UglifyJs
Unexpected token: punc (,) [./node_modules/styled-system/src/prop-types.js:116,0][main.d9eb1ec8.js:75669,7]

If I disable uglifyJS, I get this error in browser:

Uncaught TypeError: PropTypes.oneOfType is not a function
    at eval (VM1737 prop-types.js:3)
    at Object../node_modules/styled-system/src/prop-types.js (VM60 main.js:19478)
    at __webpack_require__ (VM60 main.js:678)
    at fn (VM60 main.js:88)
    at eval (VM1736 prop-types.js:3)
    at Object../node_modules/styled-system/dist/prop-types.js (VM60 main.js:19349)
    at __webpack_require__ (VM60 main.js:678)
    at fn (VM60 main.js:88)
    at eval (VM1709 index.js:34)
    at Object../node_modules/styled-system/dist/index.js (VM60 main.js:19323)
(anonymous) @ VM1737 prop-types.js:3
./node_modules/styled-system/src/prop-types.js @ VM60 main.js:19478
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1736 prop-types.js:3
./node_modules/styled-system/dist/prop-types.js @ VM60 main.js:19349
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1709 index.js:34
./node_modules/styled-system/dist/index.js @ VM60 main.js:19323
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1550 Box.js:16
./node_modules/grid-styled/dist/Box.js @ VM60 main.js:5829
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1549 index.js:7
./node_modules/grid-styled/dist/index.js @ VM60 main.js:5920
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1548 index.js:11
./src/components/ActionList/index.js @ VM60 main.js:22239
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1547 index.js:24
./src/containers/Home/index.js @ VM60 main.js:22691
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1542 routes.js:11
./src/routes.js @ VM60 main.js:22992
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
(anonymous) @ VM1519 index.js:25
./src/containers/App/index.js @ VM60 main.js:22641
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
renderApp @ VM591 client.js:45
(anonymous) @ VM591 client.js:87
(anonymous) @ VM591 client.js:109
./src/client.js @ VM60 main.js:22201
__webpack_require__ @ VM60 main.js:678
fn @ VM60 main.js:88
0 @ VM60 main.js:23032
__webpack_require__ @ VM60 main.js:678
(anonymous) @ VM60 main.js:724
(anonymous) @ VM60 main.js:727

Digging, I find this change made 7 days aggo: styled-system/styled-system@975d9fa#diff-fc1ee4ce413fadea319293ee9bcba6aaR9

My webpack config which hasn't changed during this time:

'use strict'; // eslint-disable-line

const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const StyleLintPlugin = require('stylelint-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { CSSModules, vendor } = require('./config')

const nodeEnv = process.env.NODE_ENV || 'development'
const isDev = nodeEnv !== 'production'

const WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin')
const webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(require('./WIT.config')).development(isDev)

// Setting the plugins for development/production
const getPlugins = () => {
  // Common
  const plugins = [
    new ExtractTextPlugin({
      filename: '[name].[contenthash:8].css'
      , allChunks: true
      , disable: isDev // Disable css extracting on development
      , ignoreOrder: CSSModules
    })
    , new webpack.LoaderOptionsPlugin({
      options: {
        // Javascript lint
        eslint: {}
        , context: '/' // Required for the sourceMap of css/sass loader
        , debug: isDev
        , minimize: !isDev
      }
    })
    // Style lint
    , new StyleLintPlugin({ files: ['src/**/*.css'], quiet: false })
    // Setup environment variables for client
    , new webpack.EnvironmentPlugin({ NODE_ENV: JSON.stringify(nodeEnv) })
    // Setup global variables for client
    , new webpack.DefinePlugin({
      __CLIENT__: true
      , __SERVER__: false
      , __DEV__: isDev
    })
    , new webpack.NoEmitOnErrorsPlugin()
    , webpackIsomorphicToolsPlugin
  ]

  if (isDev) { // For development
    plugins.push(
      new webpack.HotModuleReplacementPlugin(),
      // Prints more readable module names in the browser console on HMR updates
      new webpack.NamedModulesPlugin(),
      new webpack.IgnorePlugin(/webpack-stats\.json$/), // eslint-disable-line comma-dangle
      new BundleAnalyzerPlugin({
        analyzerMode: 'static'
        , openAnalyzer: false
      })
    )
  } else {
    plugins.push( // For production
      new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: Infinity }),
      new webpack.HashedModuleIdsPlugin(),
      new webpack.optimize.UglifyJsPlugin({
        sourceMap: true,
        beautify: false,
        mangle: { screw_ie8: true },
        compress: {
          screw_ie8: true, // React doesn't support IE8
          warnings: false,
          unused: true,
          dead_code: true
        },
        output: { screw_ie8: true, comments: false }
      }) // eslint-disable-line comma-dangle
    )
  }

  return plugins
}

// Setting the entry for development/production
const getEntry = () => {
  // For development
  let entry = [
    'babel-polyfill' // Support promise for IE browser (for dev)
    , 'react-hot-loader/patch'
    , 'webpack-hot-middleware/client?reload=true'
    , './src/client.js'
  ]

  // For production
  if (!isDev) {
    entry = {
      main: './src/client.js'
      // Register vendors here
      , vendor
    }
  }

  return entry
}

// Setting webpack config
module.exports = {
  name: 'client'
  , target: 'web'
  , cache: isDev
  , devtool: isDev ? 'cheap-module-eval-source-map' : 'hidden-source-map'
  , context: path.join(process.cwd())
  , entry: getEntry()
  , output: {
    path: path.join(process.cwd(), './build/public/assets')
    , publicPath: '/assets/'
    // Don't use chunkhash in development it will increase compilation time
    , filename: isDev ? '[name].js' : '[name].[chunkhash:8].js'
    , chunkFilename: isDev ? '[name].chunk.js' : '[name].[chunkhash:8].chunk.js'
    , pathinfo: isDev
  }
  , module: {
    rules: [
      {
        test: /\.jsx?$/
        , enforce: 'pre'
        , exclude: /node_modules/
        , loader: 'eslint'
      }
      , {
        test: /\.jsx?$/
        , exclude: /node_modules/
        , loader: 'babel'
        , options: {
          cacheDirectory: isDev
          , babelrc: false
          , presets: [
            ['env', {
              targets: {
                browsers: ['last 2 versions', 'ie >= 10']
              }
              , useBuiltIns: true
            }]
            , 'react'
          ]
          , plugins: [
            'react-hot-loader/babel'
            , 'transform-object-rest-spread'
            , 'transform-class-properties'
          ]
        }
      }
      , {
        test: /\.css$/
        , exclude: /node_modules/
        , loader: ExtractTextPlugin.extract({
          fallback: 'style'
          , use: [
            {
              loader: 'css'
              , options: {
                importLoaders: 1
                , sourceMap: true
                , modules: CSSModules
                // "context" and "localIdentName" need to be the same with server config,
                // or the style will flick when page first loaded
                , context: path.join(process.cwd(), './src')
                , localIdentName: isDev ? '[name]__[local].[hash:base64:5]' : '[hash:base64:5]'
                , minimize: !isDev
              }
            }
            , {
              loader: 'postcss'
            }
          ]
        })
      }
      , {
        test: /\.css$/
        , use: ExtractTextPlugin.extract({
          fallback: 'style-loader'
          , use: [{
            loader: 'css-loader'
          }]
        })
        , include: /node_modules[/\\]animate.css/
      }
      , {
        test: /\.(woff2?|ttf|eot|svg)$/
        , loader: 'url'
        , options: { limit: 10000 }
      }
      , {
        test: webpackIsomorphicToolsPlugin.regular_expression('images')
        // Any image below or equal to 10K will be converted to inline base64 instead
        , use: [
          {
            loader: 'url'
            , options: { limit: 10240 }
          }
          // Using for image optimization
          , {
            loader: 'image-webpack'
            , options: { bypassOnDebug: true }
          }
        ]
      }
    ]
  }
  , plugins: getPlugins()
  // Where to resolve our loaders
  , resolveLoader: {
    modules: ['src', 'node_modules']
    , moduleExtensions: ['-loader']
  }
  , resolve: {
    modules: ['src', 'node_modules']
    , descriptionFiles: ['package.json']
    , moduleExtensions: ['-loader']
    , extensions: ['.js', '.jsx', '.json']
  }
  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  // https://webpack.github.io/docs/configuration.html#node
  // https://github.com/webpack/node-libs-browser/tree/master/mock
  , node: {
    fs: 'empty'
    , vm: 'empty'
    , net: 'empty'
    , tls: 'empty'
  }
}

Any idea what I'm missing?

Grid Overlay

Is there a way to create a full grid overlay for development?

bootstrap xs={12} md={4} like functionality

If I want a div to take up a 33.333% width in devices that are not mobile and a 100% width in mobile

In bootstrap I would do this:
<Col xs={12} md={4}>{children}</Col>

How would I do this in grid-styled?

Fixed and null values

When a value is not defined in the API, then the prop is added with null value.

From your example at rebass:

<div>
	<Button
		onClick={e => update(toggle('fixed'))}
		children='Toggle Fixed'
	/>
	{fixed && (
		<Fixed
			m={2}
			p={3}
			bg='green3'
			z={1}
			right
			bottom>
			Hello
		</Fixed>
	)}
</div>

It's is rendered as:

screen shot 2017-08-05 at 15 09 32

index at project root

currently need to:

import {Box, Flex} from 'grid-styled/dist';

from typescript at least

Responsive Order

First of all - this is an awesome library ! Thanks for all the time you spend on it.

I love the way you handle the responsive sizing.

Is there a way to do similiar things with the Flex order property?

<Flex order={[1, 1, 0]} />

Support for `flex`, `flex-shrink` and `flex-grow`

I sometimes have the need to set the flex property of an element. Right now I'd have to extend the Flex component using Styled Components or use inline styles (which don't get prefixed).

I was wondering if there is a reason that the flex property is not supported right now. If there's no reason than I'll gladly create a PR that implements this feature :).

alignSelf absent

I need to align-self a component in a flex container but Flex nor Box support's alignSelf

Responsiveness doesn't change on parent resize

I have my Flex grid setup with a parent container. If I resize the browser, the breakpoints seem to trigger as expected, however if I update the parent containers width to simulate a mobile preview, it doesn't seem to adjust. Any idea if something else needs to occurs?

Allow to pass className to Flex/Box/Grid

For the moment it's impossible to pass className prop to Flex/Box/Grid components.

At the same time it would be very usefull to define className for these elements.

For example, we can provide additional styling via JSS for these containers.

Allow border properties on `Box`

Any thoughts on adding border properties on Box? It's trivial to recreate with createComponent, but I figured it might be a nice addition if it's a common use case.

Expose display as an API?

Hi, I love grid-styled. Its really great. Thank you.

I wonder whether you would consider to expose display as an API? It would e.g. be nice to be able to hide boxes at certain breakpoints.

<Box display={["none", "block"]}>

As an example please consider the following: I would like to display some thumbnails as a teaser, 4 for large screens, 2 for medium screens, 1 for small screens.

In a react component I have:

  renderThumbs = thumbs => {
    let gallery = []
    const start = 1
    const end = 4

    for (let i = start; i <= end; i++) {
      gallery.push(
        <MyBox
          width={[1, 1 / 2, 1 / 4]}
          key={i}
          px={1}
          display={[`${i < 2 ? "block" : "none"}`, `${i < 3 ? "block" : "none"}`, "block"]}
        >
          <Img
            data-sizes="360px"
            src={thumbs[i]["0360"]}
            className="lazyload blur-up"
            alt={"Thumb " + i}
          />
        </MyBox>
      )
    }
    return gallery
  }

where <MyBox /> is extending <Box />:

import styled from "styled-components"
import { Box } from "grid-styled"

const MyBox = styled(Box).attrs({
  display: props => props.display || "block"
})`
  display: ${props => props.display[0]};
  @media (min-width: ${props => props.theme.breakpoints[0]}em) {
    display: ${props => props.display[1]};
  }
  @media (min-width: ${props => props.theme.breakpoints[1]}em) {
    display: ${props => props.display[2]};
  }
`

export default MyBox

Access to flex-direction property?

I don't know if I'm missing something in the docs but I can only see a bool to switch between row and column directions.
I took a look at the Flex component and could something like the following be added?

const direction = props => props.direction ? `flex-direction:${props.direction};` : null

It would conflict with the current column prop though.
Thoughts?

Cheers

Using the Box component failed to extend tag with 'withComponent' but works with the Grid Component

First of all, thanks for this awesome tool 👍.

I was trying to use the Box component to extend the tag with the withComponent helper provided by styled-components like this:

const MyComp = Box.withComponent('li');

but I got the error _gridStyled.Box.withComponent is not a function

So I'm confused because it works correctly when Grid is used instead of Box or even the Flex one.
Is there something I'm missing. Thanks for your help!

SRR Support.

Functionality breaks when SSR is involved, probably back then styled-component hadn't supported SSR yet, but now that it does, hopefully grid-styled do as well.

Add prop align-self to Box?

It is nice that <Flex/> allows the alignment of its children, however, currently children are not able to break out of their alignment (if I have not overlooked it). Would you consider to add align-self or a shorthand such as align as a prop to the <Box/> at least in order to match the flexbox specification also in this respect?

<Flex align="center" direction="column">
    <Box>
        Aligned centered
    </Box>
    <Box align-self="flex-end">
        Expose align-self as a prop
    </Box>
    <Box align="flex-end">
        Expose align as a shorthand for align-self as a prop
    </Box>
</Flex>

typescript definitions

Is there anyone currently working on writing typescript definitions for this project? If not, I'll have a go at it myself in a few hours

Special Character isn't being interpreted as a valid character

https://github.com/jxnblk/grid-styled/blob/6e8433265717d3d0f25707f71b1600ba2e7fc0aa/src/Golden.js#L4

Transpiled output:

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.B = exports.A = exports.gb = exports.ga = exports.� = undefined;

// ...

var � = exports.� = (1 + Math.sqrt(5)) / 2;
var ga = exports.ga = � - 1;
var gb = exports.gb = 1 - ga;

Throwing the following Error:

Golden.js:6 Uncaught SyntaxError: Invalid or unexpected token
   ...

I found this by way of rebass#v1.0.4 (using "grid-styled": "^2.0.0-10",).

Module not found: Can't resolve 'grid-styled'

I just installed the grid-styled component and when I try importing it in my component, I get a module not found error.

Below are my dependencies from package.json

"dependencies": {
"grid-styled": "^2.0.0-0",
"immutable": "^3.8.1",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"redux": "^3.6.0",
"redux-saga": "^0.15.3",
"reselect": "^3.0.1",
"styled-components": "^2.0.1"
},

Custom Props

When extending a grid-styled element and using custom props, the resulting props are not being removed from the element, resulting in unknown attribute errors in React 16. See below for a contrived example.

import { Flex } from 'grid-styled';

const MyFlex = styled(Flex)`
  color: ${props => props.isPrimary ? 'red' : 'blue'}
`;

export default () => <MyFlex isPrimary />

My react component won't render because the φ is coming up as an illegal character

Using this plugin with our react project. It appears to fail when after we run WebPack and I try to run the react components inside of our production environment because of the "φ" phi character. The browser reports an illegal character and then it will break.

I see that inside of webpack it's using this character is there any way to stop it from doing this?

Publish to npm

Hey 👋 ,

I see the latest version version on npm is 1.0.0-beta.1 which depends on styled-components v1, which is causing some issues. Could you publish the new src?

Extending Components with Adative Props

If one tries to use Styled Components feature of Adaptive Props on an extended grid-styled component, React will not be able to determine the prop. The desired effect of the Styled Component's CSS will still be applied however.

Unknown prop `<$primary>` on <div> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in div (created by Base)
    in Base (created by Box)
    in Box (created by Flex)

Example:

export default CustomFlex = styled(Flex)`
	color: ${props => props.primary ? 'white' : 'palevioletred'};
`;

render(<CustomFlex primary />);

If this example is not clear I can make additions, or if I simply am not writing the additional prop correct, please inform! I believe this issue may be common for others.

ThemeProvider ignored

Very cool lib, kudoz!

I'm trying to override the default breakpoints and spaces but the theme object is empty.

I have configured the theme provider like that:

<ThemeProvider theme={theme}>
        <div className="App">
          <Header />
          <main>
            <Container>
              <MyFirstPage />
            </Container>
          </main>
          <Footer />
        </div>
      </ThemeProvider>

theme:

const theme = {
  space: [ 0, 8, 16, 24, 32 ], // pixels
  breakpoints: [ 32, 64, 75], //em => 320px, 1024px, 1200px
}
export default theme

Then in Footer I'm using

 <Flex wrap>
          <Box px={2} py={1} width={[1,1,1/5]}>
            <Heading level="5" negative>Bla bla</Heading>
            <Paragraph negative>
              bla bla
            </Paragraph>
          </Box>
</Flex>

The theme object in Flex or Box components is empty rather than in my Heading or Paragraph components I can see it.
Should I do something different to propagate the theme?

<Box w={1200}> should use max-width

<Box w={1200}> is resulting in width: 1200px, but for responsive displays I think it would be better to have:

width: 100%;
max-width: 1200px;

Add width and height to <Flex />

Ability to add width and height to would be great. Scenario I've ran into is wanting to make a fullscreen so I can center the children 's to the viewport.

Error when loading page

Hey,

I was testing your grid-styled but I had the following issue. After using "npm i grid-styled" on my project I imported Grid as followed by the doc but I encountered the following error:

Dynamic page loading failed TypeError: (0 , _styledComponents2.default) is not a function(…)

So, I copy-pasted the /src/Grid.js by itself ni a directory that I imported straight to my testing page and that enabled the Grid to work properly. I then tried the same process but this time with /dist/Grid.js, This time i encountered the same error.

It seems, but I am not sure, that there is an issue with Grid.js when it is used via its ES5 version.

True grid

The current Grid component is using display: 'inline-block'. Is there any chance to use display: grid | inline-grid | subgrid;?

The browser support now is very positive
https://caniuse.com/#feat=css-grid

Unable to pass ref to DOM node

Not sure if this is the correct place to create this issue, or in the tag-hoc issue, but here it goes anyways.

I'm unable to get a React ref to the DOM nodes these components create. For instance, when passing innerRef to <Box /, it is tag-hoc's Base that gets the ref, not the div underneath.

screen shot 2017-09-18 at 12 12 44

I would also like to thank you for this library. I'm using it together with styled-system in my current project. My styled-components feels so clean and reusable. Many thanks!

Creating a generic Container with grid-styled

Hi there

My apologies if this has been addressed and I just missed it but I would like to create either a component or styled component that can act as a Container for the main section of the site. Rather than create a generic styled component with arbitrary padding/margin, I would like to take advantage of grid-styled padding and margin shorthands so it is homogenous with the other grids. I'm trying to avoid having to manually put px props everywhere the Container is used. Is this possible?

thanks!

Feature Request: "hide" property

It would be cool if I can hide within the grid system perhaps?

<Box hide={[false, true]} ...> // hides on everything but smallest bp
<Box hide={[true, false]} ...> // hides only on smallest bp
<Box hide={[true, false, true]} ...> // only shows on second bp

Box and Grid give warning with server side rendering

#If you use Box or Grid in a SSR app (for example - using next.js), you'll see a warning similar to this:

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) -in1kw1-1 glNHox sc-htpNat iSNGhk sc-bdV
(server) -in1kw1-1 glNHox sc-kkGfuU kGURps sc-hMq

The babel-plugin-styled-components plugin fixes this by generating the displayName and componentId at compile time. That lets the server and client share the same generated class name.

I tried to add the plugin to this project, however Box and Grid don't use TaggedTemplateLiterals which is necessary for the babel plugin to generate the correct code. I've never seen how Box and Grid call styled before so I don't know how to go about updating things to get the correct code generated by babel.

For reference, with a component defined like so:

const Label = styled.label``

in the file src/components/Label/index.js, the babel plugin will generate:

var Label = _styledComponents2.default.label.withConfig({
  displayName: 'Label__Label',
  componentId: 'bteeh0-0'
})(['']);

Maintainer

@jxnblk Looks like the activity on this repo is kind of stalled. We use this library heavily at Weedmaps. We would be happy to contribute and are going to open up some PRs soon. Are you still actively working on this?

Feature request: make 'display' a responsive attribute

Reason: if I need to change layout direction to provide responsiveness, most of the time I prefer not to switch between 'row' and 'column' values of flex-direction, but just switch flex layout on and off altogether by changing display property. I prefer this because flex-direction column is pretty buggy and because in most cases for mobile layout you need just a normal elements stack without any fancy flex behaviour. So my proposal is to make a display property responsive, so that you could
<Flex display={['block', 'flex']}>. What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.