Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Responsive margin and padding components for styled-components 💅.

NotificationsYou must be signed in to change notification settings

jameslnewell/styled-components-spacing

Repository files navigation

npmnpm bundle size (minified + gzip)npmBuild Status

Responsive margin and padding components forstyled-components 💅.

Change log

Have a look 👀 atstyled-components-breakpoint andstyled-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

importReactfrom'react';import{Margin,Padding}from'styled-components-spacing';<HeroPanel><Paddingall={{mobile:2,tablet:4,desktop:6}}><Title>Hello World</Title><SubTitle>You are on earth!</SubTitle><Margintop={1}><Button>Blast off!</Button></Margin></Padding></HeroPanel>;

Using custom spacings at custom breakpoints

Spacings and breakpoints can be customised usingThemeProvider. For example, to use the same breakpoints and spacings asBootstrap, you can do so like this:

importReactfrom'react';import{ThemeProvider}from'styled-components';import{Margin,Padding}from'styled-components-spacing';consttheme={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'}};<ThemeProvidertheme={theme}><HeroPanel><Paddingall={{sm:1,lg:2}}><Title>Hello World</Title><SubTitle>You are on earth!</SubTitle><Margintop={1}><Button>Blast off!</Button></Margin></Padding></HeroPanel></ThemeProvider>;

Using the mixins

importReactfrom'react';importstyledfrom'styled-components';import{my,px}from'styled-components-spacing';constPanel=styled.div`${my({mobile:2,tablet:4})}${px(6)};`;

Components

<Margin/>

all

Margin on all sides.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

horizontal

Margin on the left and right.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

vertical

Margin on the top and bottom.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

top

Margin on the top.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

bottom

Margin on the bottom.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

left

Margin on the left.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

right

Margin on the right.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

inline

Size the element to the width of its children.

Optional. Aboolean. Defaults tofalse.

<Padding/>

all

Padding on all sides.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

horizontal

Padding on the left and right.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

vertical

Padding on the top and bottom.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

top

Padding on the top.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

bottom

Padding on the bottom.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

left

Padding on the left.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

right

Padding on the right.

Optional. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

inline

Size the element to the width of its children.

Optional. Aboolean. Defaults tofalse.

Mixins

m(values)

Margin on all sides.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

mx(values)

Margin on the left and right.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

my(values)

Margin on the top and bottom.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

mt(values)

Margin on the top.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

mr(values)

Margin on the right.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

mb(values)

Margin on the bottom.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

ml(values)

Margin on the left.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

p(values)

Padding on all sides.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

px(values)

Padding on the left and right.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

py(values)

Padding on the top and bottom.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

pt(values)

Padding on the top.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

pr(values)

Padding on the right.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

pb(values)

Padding on the bottom.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject specifying spacing keys for multiple breakpoints.

pl(values)

Padding on the left.

Parameters:

  • values - Required. Astring ornumber specifying the spacing key. May be a keyedobject 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 thecomponent prop - if you wish to use a custom component with this library use.withComponent()

About

Responsive margin and padding components for styled-components 💅.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp