1.1.3 • Published 7 years ago

styled-units v1.1.3

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

styled-units 💅

Build Status npm version Coverage Status

TL;DR

  • Provides convenient unit property helper functions that go hand-in-hand with styled-components 💅
  • Small footprint with No Dependencies!
  • For example, instead of doing this:
    width: ${({ percent }) => `${percent}%`};
    you do this:
    width: ${pct('percent')};

Install

$ npm i --save styled-units

Usage:

import styled from 'styled-components';
import { em, px, pct } from 'styled-units';

const Button = styled.button`
  padding: ${em('padding')};
  border-radius: ${px('borderRadius')};
  width: ${pct('width')};
`;

Button.defaultProps = {
  padding: 1,
  borderRadius: 4,
  width: 100,
};

Then use it like this.

<Button borderRadius={5} padding={3}>Press Me</Button>

API

Supported "units":

FunctionDescription
pxReturns the property specified with the "px" suffix
emReturns the property specified with the "em" suffix
remReturns the property specified with the "rem" suffix
pctReturns the property specified with the "%" suffix
vwReturns the property specified with the "vw" suffix
vhReturns the property specified with the "vh" suffix
propReturns the property specified "as-is"

Live

Check out this live example on CodeSandbox.

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago