• Stars
    star
    220
  • Rank 180,422 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A responsive grid components for styled-components.

styled-components-grid

npm npm bundle size (minified + gzip) npm Build Status

Responsive grid components for styled-components ๐Ÿ’….

Change log

Have a look ๐Ÿ‘€ at styled-components-breakpoint and styled-components-spacing which work well with this package.

Installation

yarn add styled-components styled-components-grid

Usage

Examples

Using the default breakpoints

import React from 'react';
import Grid from 'styled-components-grid';

<Grid>
  <Grid.Unit size={1 / 6}>Awesome!</Grid.Unit>
  <Grid.Unit size={1 / 3}>Amazing!</Grid.Unit>
  <Grid.Unit size={{ tablet: 1 / 2, desktop: 1 / 4 }}>Out of this world!</Grid.Unit>
</Grid>;

Using custom breakpoints

You can customise the default breakpoints. If you would like to use the same breakpoints as Bootstrap, you can do so like this:

import React from 'react';
import { ThemeProvider } from 'styled-components';
import Grid from 'styled-components-grid';

const theme = {
  breakpoints: {
    xs: 0,
    sm: 576,
    md: 768,
    lg: 992,
    xl: 1200
  }
};

<ThemeProvider theme={theme}>
  <Grid>
    <Grid.Unit size={1 / 6}>Awesome!</Grid.Unit>
    <Grid.Unit size={1 / 3}>Amazing!</Grid.Unit>
    <Grid.Unit size={{ lg: 1 / 5 }}>Out of this world!</Grid.Unit>
  </Grid>
</ThemeProvider>;

Using the mixins

import React from 'react';
import styled from 'styled-components';
import { grid } from 'styled-components-grid';

const FeaturePanel = styled`
  ${grid({})}
`;

const Feature = styled`
  ${grid.unit({ size: { tablet: 1 / 3 } })}
`;

<FeaturePanel>
  <Feature>Awesome!</Feature>
  <Feature>Amazing!</Feature>
  <Feature>Out of this world!</Feature>
</FeaturePanel>;

Components

<Grid/>

horizontalAlign

Controls the horizontal alignment of grid units.

A string equal to one of left|right|center|justify|justify-center OR an object where the values are strings equal to one of left|right|center|justify|justify-center for each desired breakpoint. Defaults to left.

verticalAlign

Controls the vertical alignment of grid units.

A string equal to one of top|bottom|center|stretch OR an object where the values are strings equal to one of top|bottom|center|stretch for each desired breakpoint. Defaults to stretch.

reverse

Reverse the order of the grid units.

A boolean OR an object where the values are booleanss for each desired breakpoint. Defaults to false.

wrap

Whether the grid units should wrap across multiple lines or a single line.

A boolean OR an object where the values are booleanss for each desired breakpoint. Defaults to true.

component

The component to render the styles on.

Optional. A string or valid React component. Defaults to div.

<Grid.Unit/>

size

Controls the width of the grid unit.

A number between 0 and 1 OR a string of min or max OR an object where the values are a number between 0 and 1 OR a string of min or max for each desired breakpoint.

visible

Controls whether the grid unit is visible.

A boolean OR an object where the values are booleanss for each desired breakpoint. Defaults to true.

component

The component to render the styles on.

Optional. A string or valid React component. Defaults to div.

Mixins

grid(opts)

Apply grid styles.

  • halign
  • valign
  • wrap
  • reverse

grid.unit(opts)

Apply grid unit styles.

  • size
  • visible

More Repositories

1

styled-components-breakpoint

Utility function for using breakpoints with styled-components ๐Ÿ’….
JavaScript
240
star
2

styled-components-spacing

Responsive margin and padding components for styled-components ๐Ÿ’….
JavaScript
213
star
3

xhr-mock

Utility for mocking XMLHttpRequest.
TypeScript
197
star
4

react-lazily-render

Delay mounting expensive components until a placeholder component has been scrolled into view.
JavaScript
22
star
5

react-create-component-from-tag-prop

Create a `react` component from a `tag` prop.
JavaScript
18
star
6

redux-when

Redux middleware for delaying dispatch of an action until a condition evaluates to true.
JavaScript
18
star
7

redux-formo

An alternate forms framework for Redux+React.
JavaScript
9
star
8

satay

A utility for uploading static sites to AWS S3.
TypeScript
9
star
9

react-render-image

Render an image in React.
TypeScript
8
star
10

wait-for-event

Wait for events to be triggered.
TypeScript
6
star
11

react-testutils-render

A lite wrapper for shallow rendering React components.
JavaScript
6
star
12

substance

โš—๏ธPrimitives for building components.
TypeScript
5
star
13

publish-if-not-published

Publish a package if the current version isn't already published.
TypeScript
4
star
14

sass-triangle

Mixin for creating CSS triangles.
CSS
4
star
15

tradie-v4

A framework for building tools like `create-react-app` tailored to your use case and tech stack.
TypeScript
4
star
16

webpack-resolve-short-path-plugin

A plugin for `enhanced-resolve` (Webpack v2) that resolves paths like `~module` to `%rootPath%/module` so you don't have to write relative paths like `../../../module`.
JavaScript
4
star
17

react-firebase

React hooks for working with firebase.
TypeScript
3
star
18

koa

A number of packages made to work with koa.
TypeScript
3
star
19

tradie

A semi-opinionated build tool for frontend projects. Use it to lint, bundle and test your script and style files.
JavaScript
3
star
20

run-if-diff

Run a command if files have changed.
JavaScript
3
star
21

react-app-example

JavaScript
1
star
22

react

๐Ÿ“ฆ โš›๏ธ A collection of packages for building React applications.
TypeScript
1
star
23

react-testutils-query

Utility functions for retrieving elements from within a React virtual-dom tree.
JavaScript
1
star
24

buildkite-pipelines

Generate Buildkite pipelines from code.
TypeScript
1
star
25

now-deploy-action

Deploy a project using ZEIT Now.
JavaScript
1
star
26

rev-manifest-path

Get the cache busted path of an asset from a `gulp-rev` or `gulp-rev-all` manifest.
JavaScript
1
star
27

cancelable-promise

A cancelable promise implementation.
TypeScript
1
star
28

tradie-template-react-static-site

Tradie template for building static sites with React.
JavaScript
1
star
29

generator-fed

Yeoman generator for Frontend Development with Browserify and SASS Composer.
JavaScript
1
star
30

react-static-site-example

react-static-site-example
JavaScript
1
star
31

design-system-example

A demonstration of the tooling setup for a React based Design System.
TypeScript
1
star
32

koa-reload-middleware

Reload middleware if it changes during development.
TypeScript
1
star
33

workspace-metadata-webpack-plugin

Display workspace metadata on your website.
TypeScript
1
star