polished
TypeScript icon, indicating that this package has built-in type declarations

4.3.1 • Public • Published
polished

A lightweight toolset for writing styles in JavaScript. ✨

Node CI Test codecov Github All Releases

npm install --save polished
# or if you're using yarn
yarn add polished

Want to write styles in JavaScript, but also want Sass-style helper functions and mixins? Need a consistent color palette throughout your app? ✨ polished is for you!

  • Make your app look great without stress
  • Cross framework compatible: No matter if you're using styled-components, emotion, jss, aphrodite, radium, or plain inline styles, as long as you're writing your styles in JavaScript you can use polished!
  • Switching from a pre-processor to styles in JS made easy

Docs

See the full documentation at polished.js.org!

Usage

✨ polished modules are meant to be used as stand-alone imports. You should avoid importing the entire library directly:

import { clearFix, animation } from 'polished' import * as polished from 'polished import polished from 'polished'

When ✨ polished modules are imported properly, tree shaking in webpack and Rollup can be leveraged to reduce your bundle size.

Browser Support

All Evergreen Browsers + IE11

As of v3.6.X we support >0.5%, not dead, ie >= 11, not op_mini all for all our builds.

Flow Type Definitions

✨ polished has first-class Flow support with zero configuration to assist you in finding type errors while using our modules.

Ignore ✨ polished source

Flow frequently updates and it is possible that the version you are running may cause you to run into errors coming from the polished package in your node_modules directory. You can add the following lines to your .flowconfig to ignore polished in those cases:

[ignore]
.*/node_modules/polished/.*

TypeScript Definitions

✨ polished has TypeScript definitions to allow the library to be used in any TypeScript project. You will need to set moduleResolution to node in your tsconfig.json in order to use ✨ polished with TypeScript.

Babel plugin

You can optionally also use babel-plugin-polished to compile the static function calls out and remove the (already tiny) runtime performance impact of using ✨ polished.

Object Spread Properties

In the documentation you will see examples using object spread properties ({ ...other }). To enable this syntax in your project add the transform-object-rest-spread plugin (or the stage-3 preset to enable all stage three features) to your Babel configuration.

Why?

When writing styles in JavaScript, many people need Sass-style helper functions to be productive. ✨ polished brings them to you in a nice, lightweight package tailor-made for styles in JavaScript.

The main difference with Sass is that it's written in a functional style and all color functions are curried. This means you can compose them together into your own reusable helpers with a compose function of your choice:

import { compose } from 'ramda' // Replace with any compose() function of your choice
import { lighten, desaturate } from 'polished'

// Create tone() helper
const tone = compose(lighten(0.1), desaturate(0.1))

Why not package-xyz?

First of all, we didn't find another library that had everything we needed, and we don't care about installing a dozen packages separately.

Specifically most other packages that provide color functions do so in an object-oriented style, often with a fluent API that's very different from the Sass-style helpers. This means people that aren't very familiar with JavaScript might shy away from using them.

✨ polished was made as a standard library for everybody, no matter if they know JS inside out or not.

Compatibility

✨ polished is compatible with any library that accepts styles as JS objects. This includes, but is by far not limited to, styled-components, radium, aphrodite, glamor, glamorous, jss and many more!

No matter if you're using inline styles or CSS-in-JS, polished is for you.

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

Copyright © 2016-2021 Brian Hough, Maximilian Stoiber, & Nik Graf. Licensed under the MIT License, see LICENSE.md for more information!

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.3.15,164,076latest
3.7.2362,155lts
4.0.0-beta.22next

Version History

VersionDownloads (Last 7 Days)Published
4.3.15,164,076
4.2.21,675,600
4.2.11,101
4.2.058
4.1.465,109
3.7.2362,155
4.1.3152,359
4.1.220,854
4.1.146,520
3.7.165,217
3.7.05,306
4.1.01,331
4.0.54,401
4.0.426
4.0.33,368
4.0.2146
4.0.140
4.0.0-beta.22
4.0.0-beta.12
3.6.727,599
3.6.68,567
3.6.523,595
3.6.41,708
3.6.32,273
3.6.23,569
3.6.1144
3.6.0105
3.5.21,647
3.5.110,656
3.5.0132
3.4.412,486
3.4.3237
3.4.221,036
3.4.119,776
3.4.01,472
3.3.22,806
3.3.14
3.3.0287
3.2.114
3.2.03,475
3.1.023
3.0.45
3.0.32,274
3.0.259
3.0.15
3.0.0146
3.0.0-beta.42
3.0.0-beta.33
3.0.0-beta.22
3.0.0-beta.11
3.0.0-beta.01
3.0.0-alpha.02
2.0.0-beta.13
2.0.0-beta.01
2.0.0-alpha.11
2.0.0-alpha.03

Package Sidebar

Install

npm i polished

Weekly Downloads

7,803,905

Version

4.3.1

License

MIT

Unpacked Size

2.8 MB

Total Files

330

Last publish

Collaborators

  • nikgraf
  • mxstbr
  • bhough