# styled-units

> A unit helper for styled-components.

Latest version **1.1.3** (published 2017-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install styled-units
pnpm add styled-units
yarn add styled-units
bun add styled-units
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2017-07-11 |
| First published | 2017-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Donavon West |
| Maintainers | donavon |
| Keywords | react, css, css-in-js, styled-components |

## Links

- npm: https://www.npmjs.com/package/styled-units
- Repository: https://github.com/donavon/styled-units
- Homepage: https://github.com/donavon/styled-units#readme
- Issues: https://github.com/donavon/styled-units/issues
- npm.io page: https://npm.io/package/styled-units

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2017-07-11
- 1.1.2 — 2017-07-10
- 1.1.1 — 2017-07-10
- 1.1.0 — 2017-07-10
- 1.0.1 — 2017-07-10
- 1.0.0 — 2017-07-10
- 0.3.0 — 2017-07-10
- 0.2.2 — 2017-07-10
- 0.2.1 — 2017-07-10
- 0.2.0 — 2017-07-10
- 0.1.0 — 2017-07-09

## README

# styled-units 💅
[![Build Status](https://travis-ci.org/donavon/styled-units.svg?branch=master)](https://travis-ci.org/donavon/styled-units)
[![npm version](https://img.shields.io/npm/v/styled-units.svg)](https://www.npmjs.com/package/styled-units)
[![Coverage Status](https://coveralls.io/repos/github/donavon/styled-units/badge.svg?branch=master)](https://coveralls.io/github/donavon/styled-units?branch=master)

TL;DR

* Provides convenient unit property helper functions that go hand-in-hand with
[`styled-components`](https://www.npmjs.com/package/styled-components) 💅
* Small footprint with **No Dependencies**!
* For example, instead of doing this:
  ```js
  width: ${({ percent }) => `${percent}%`};
  ```
  you do this:
  ```js
  width: ${pct('percent')};
  ```

## Install
```bash
$ npm i --save styled-units
```

## Usage:

```js
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.
```js
<Button borderRadius={5} padding={3}>Press Me</Button>
```

## API

Supported "units":

| Function  | Description |
| --------- | ----------- |
| `px` |  Returns the property specified with the "px" suffix |
| `em` |  Returns the property specified with the "em" suffix |
| `rem` |  Returns the property specified with the "rem" suffix |
| `pct` |  Returns the property specified with the "%" suffix |
| `vw` |  Returns the property specified with the "vw" suffix |
| `vh` |  Returns the property specified with the "vh" suffix |
| `prop` | Returns the property specified "as-is" |

## Live

Check out this live example on [CodeSandbox](https://codesandbox.io/s/oYpNjXmWN).

---
_Source: https://npm.io/package/styled-units · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
