1.0.5 • Published 4 years ago

styled-kit v1.0.5

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

styled-kit

Installation

npm install styled-kit

styled-kit depends on styled-components, so make sure you have that installed

npm install styled-components

Usage

import Div from 'styled-kit/Div'

<Div column listTop={24}>
  <h1>Hello</h1>
  <h2>Hello</h2>
</Div>

Div is a helper wrapper component that makes it easy to position its children using flex attributes.

Live demo

🚧 In progress

Available props

Flex properties

PropCSS
rowflex-direction: row;
rowReverseflex-direction: row-reverse;
columnflex-direction: column;
columnReverseflex-direction: column-reverse;
wrapsflex-wrap: wrap;
justifyStartjustify-content: flex-start;
justifyEndjustify-content: flex-end;
justifyCenterjustify-content: center;
justifyBetweenjustify-content: space-between;
justifyAroundjustify-content: space-around;
justifyEvenlyjustify-content: space-evenly;
itemsStartalign-items: flex-start;
itemsEndalign-items: flex-end;
itemsCenteralign-items: center;
itemsBaselinealign-items: baseline;
itemsStretchalign-items: stretch;
contentStartalign-content: flex-start;
contentEndalign-content: flex-end;
contentCenteralign-content: center;
contentBetweenalign-content: space-between;
contentAroundalign-content: space-around;
contentStretchalign-content: stretch;

Self flex properties

PropCSS
flex={X}flex: X;
flexNoneflex: none;
selfAutoalign-self: auto;
selfStartalign-self: flex-start;
selfEndalign-self: flex-end;
selfCenteralign-self: center;
selfBaselinealign-self: baseline;
selfStretchalign-self: stretch;

Props that looks like name={X} accepts a value that is either number or string. If it's number and, it will be converted to pixels for props that require them, so:

width={100}: width: 100px; height="100": height: 100%; flex={5}: flex: 5;

Size

PropCSS
width={X}width: X;
height={X}height: X;
minWidth={X}min-width: X;
minHeight={X}min-height: X;
maxWidth={X}max-width: X;
maxHeight={X}max-height: X;
radius={X}border-radius: X;

Space

PropCSS
margin={X}margin: X;
marginTop={X}margin-top: X;
marginRight={X}margin-right: X;
marginBottom={X}margin-bottom: X;
marginLeft={X}margin-left: X;
padding={X}padding: X;
paddingTop={X}padding-top: X;
paddingRight={X}padding-right: X;
paddingBottom={X}padding-bottom: X;
paddingLeft={X}padding-left: X;

Instead of using paddingTop or marginLeft, you can also use abbreviated pTop, mLeft, and so on.

Position

PropCSS
relativeposition: relative;
absoluteposition: absolute;
fixedposition: fixed;
stickyposition: sticky;
top={X}top: {X};
right={X}right: {X};
bottom={X}bottom: {X};
left={X}left: {X};
z={X}z-index: {X};

Text

PropCSS
font={X}font: {X};
fontFamily={X}font-family: {X};
fontSize={X}font-size: {X};
fontWeight={X}font-weight: {X};
lineHeight={X}line-height: {X};
letterSpacing={X}letter-spacing: {X};
textAlign={X}text-align: {X};
color={X}color: {X};

Lists

Add margin to every child except first or last one, depending on the chosen direction. Used to add space between child items.

PropCSS
listLeft={X}> *:not(:first-child) { margin-left: {X}; }
listRight={X}> *:not(:last-child) { margin-right: {X}; }
listTop={X}> *:not(:first-child) { margin-top: {X}; }
listBottom={X}> *:not(:last-child) { margin-bottom: {X}; }

X is optional here and is 8px by default

You can also use columnTop and columnBottom. They work the same as listTop and listBottom, but also come with flex-direction: column;.

Other

PropCSS
overflow={X}overflow: {X};

Helpers

PropCSS
background={X}background: ${X};
backgroundImage={URL}background-image: url({URL});
coverbackground-size: cover;
containbackground-size: contain;
layerposition: absolute; top: 0; right: 0; bottom: 0; left: 0;
square={X}width: {X}; height: {X};
circleborder-radius: 50%;
fullHeightmin-height: 100vh;
hidedisplay: none;
clickablecursor: pointer;
noPointerEventspointer-events: none;
overlayCreates a semi-transparent red overlay over a <Div />, may come in useful when debugging layout. Accept a string with a color name if you want something other than red.

Media queries

You can use CSS media queries with <Div />

First, you need to import styled-components's ThemeProvider and pass it a theme with styledKitMediaQueries key where you put your media queries. Query needs to have a name and a valid value. Here's an example:

import { ThemeProvider } from 'styled-components'
import Div from 'styled-kit/Div'
import createQueries from 'styled-kit/utils/createQueries'

const styledKitMediaQueries = createQueries({
  mobile: '(max-width: 767px)',
  desktop: '(min-width: 768px)'
})

function App() {
  return (
    <ThemeProvider theme={{ styledKitMediaQueries }}>
      <Div mobile="color: pink;" desktop="color: powderblue;">
        Hello!
      </Div>
    </ThemeProvider>
  )
}

You can name your queries however you want. In this example, they're called "mobile" and "desktop", and now all Divs can accept props of the same names.

<Div desktop="flex-direction: column;" /> Simple CSS string <Div desktop={{ flexDirection: 'column' }} /> Object notation (the same that style prop accepts) <Div desktop={{ column: true }} /> Object notation unsing Div's properties <Div desktop={['column']} /> Array notation, works with Div's boolean properties only

All results in the same flex-direction: column; CSS getting attached to <Div /> on screens at least 768px wide

Enjoy! 💙

npm version GitHub license

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.5.6

4 years ago

0.5.4

4 years ago

0.5.5

4 years ago

0.5.3

4 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago