All Projects → jameslnewell → Styled Components Spacing

jameslnewell / Styled Components Spacing

Responsive margin and padding components for styled-components 💅.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Styled Components Spacing

Animate Css Styled Components
simple port of animate css for styled-components
Stars: ✭ 173 (-17.22%)
Mutual labels:  styled-components
Smakosh.com
My personal website
Stars: ✭ 185 (-11.48%)
Mutual labels:  styled-components
Styled React Boilerplate
Minimal & Modern boilerplate for building apps with React & styled-components
Stars: ✭ 198 (-5.26%)
Mutual labels:  styled-components
React Simon Says
A "Simon Says" game built with React and Redux 👾
Stars: ✭ 175 (-16.27%)
Mutual labels:  styled-components
Elm Styled
Styling your Html Elements with typed Css 💅
Stars: ✭ 180 (-13.88%)
Mutual labels:  styled-components
React Landing Page
🛬 Everything you need for a modern landing page, built with React & Styled Components
Stars: ✭ 193 (-7.66%)
Mutual labels:  styled-components
Browser Hack Sass Mixins
Browser hack sass mixin - Apply your SCSS to a specific browser - CSS hacks for: IE, Chrome, Firefox, Edge, Opera
Stars: ✭ 170 (-18.66%)
Mutual labels:  mixins
Styled Components Vs Emotion
a short doc comparing the popular CSS-in-JS libraries styled-components and emotion
Stars: ✭ 204 (-2.39%)
Mutual labels:  styled-components
Styled Theme
Extensible theming system for styled-components 💅
Stars: ✭ 183 (-12.44%)
Mutual labels:  styled-components
Styled Bootstrap Components
The bootstrap components made with styled-components 💅
Stars: ✭ 196 (-6.22%)
Mutual labels:  styled-components
Ran
⚡ RAN! React . GraphQL . Next.js Toolkit ⚡ - SEO-Ready, Production-Ready, SSR, Hot-Reload, CSS-in-JS, Caching, CLI commands and more...
Stars: ✭ 2,128 (+918.18%)
Mutual labels:  styled-components
Grid
This package has moved and renamed
Stars: ✭ 2,079 (+894.74%)
Mutual labels:  styled-components
Css In Js
Autocomplete React Native / JS Styles and converting plain CSS to JS styles
Stars: ✭ 192 (-8.13%)
Mutual labels:  styled-components
Bedrock
Foundational Layout Primitives for your React App
Stars: ✭ 173 (-17.22%)
Mutual labels:  styled-components
Lerna Yarn Workspaces Monorepo
🐉 A Monorepo with multiple packages and a shared build, test, and release process.
Stars: ✭ 201 (-3.83%)
Mutual labels:  styled-components
React Elastic Carousel
A flexible and responsive carousel component for react https://sag1v.github.io/react-elastic-carousel
Stars: ✭ 173 (-17.22%)
Mutual labels:  styled-components
Frontend
Save and share your best solutions
Stars: ✭ 191 (-8.61%)
Mutual labels:  styled-components
Web Portfolio
Personal portfolio website made with the React
Stars: ✭ 207 (-0.96%)
Mutual labels:  mixins
Layouts
Grab-and-go layouts for React
Stars: ✭ 202 (-3.35%)
Mutual labels:  styled-components
Reactour
Tourist Guide into your React Components
Stars: ✭ 2,782 (+1231.1%)
Mutual labels:  styled-components

styled-components-spacing

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

Responsive margin and padding components for styled-components 💅.

Change log

Have a look 👀 at styled-components-breakpoint and styled-components-grid which both work well with this package.

Installation

npm install --save styled-components styled-components-spacing

Usage

Examples

Using the default spacings at the default breakpoints

import React from 'react';
import { Margin, Padding } from 'styled-components-spacing';

<HeroPanel>
  <Padding all={{ mobile: 2, tablet: 4, desktop: 6 }}>
    <Title>Hello World</Title>
    <SubTitle>You are on earth!</SubTitle>
    <Margin top={1}>
      <Button>Blast off!</Button>
    </Margin>
  </Padding>
</HeroPanel>;

Using custom spacings at custom breakpoints

Spacings and breakpoints can be customised using ThemeProvider. For example, to use the same breakpoints and spacings as Bootstrap, you can do so like this:

import React from 'react';
import { ThemeProvider } from 'styled-components';
import { Margin, Padding } from 'styled-components-spacing';

const theme = {
  breakpoints: {
    xs: 0,
    sm: 576,
    md: 768,
    lg: 992,
    xl: 1200
  },
  spacing: {
    0: '0',
    1: '0.25rem',
    2: '0.5rem',
    3: '1rem',
    4: '1.5rem',
    5: '3rem'
  }
};

<ThemeProvider theme={theme}>
  <HeroPanel>
    <Padding all={{ sm: 1, lg: 2 }}>
      <Title>Hello World</Title>
      <SubTitle>You are on earth!</SubTitle>
      <Margin top={1}>
        <Button>Blast off!</Button>
      </Margin>
    </Padding>
  </HeroPanel>
</ThemeProvider>;

Using the mixins

import React from 'react';
import styled from 'styled-components';
import { my, px } from 'styled-components-spacing';

const Panel = styled.div`
  ${my({ mobile: 2, tablet: 4 })} ${px(6)};
`;

Components

<Margin/>

all

Margin on all sides.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

horizontal

Margin on the left and right.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

vertical

Margin on the top and bottom.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

top

Margin on the top.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

bottom

Margin on the bottom.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

left

Margin on the left.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

right

Margin on the right.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

inline

Size the element to the width of its children.

Optional. A boolean. Defaults to false.

<Padding/>

all

Padding on all sides.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

horizontal

Padding on the left and right.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

vertical

Padding on the top and bottom.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

top

Padding on the top.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

bottom

Padding on the bottom.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

left

Padding on the left.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

right

Padding on the right.

Optional. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

inline

Size the element to the width of its children.

Optional. A boolean. Defaults to false.

Mixins

m(values)

Margin on all sides.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

mx(values)

Margin on the left and right.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

my(values)

Margin on the top and bottom.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

mt(values)

Margin on the top.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

mr(values)

Margin on the right.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

mb(values)

Margin on the bottom.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

ml(values)

Margin on the left.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

p(values)

Padding on all sides.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

px(values)

Padding on the left and right.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

py(values)

Padding on the top and bottom.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

pt(values)

Padding on the top.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

pr(values)

Padding on the right.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

pb(values)

Padding on the bottom.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

pl(values)

Padding on the left.

Parameters:

  • values - Required. A string or number specifying the spacing key. May be a keyed object specifying spacing keys for multiple breakpoints.

Defaults

{
  0: '0',
  1: '0.25rem',
  2: '0.5rem',
  3: '1rem',
  4: '2rem',
  5: '4rem',
  6: '8rem'
}

Rendering on a custom component

This library no longer supports the component prop - if you wish to use a custom component with this library use .withComponent()

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].