安装
npm install polished
yarn add polished
pnpm add polished
bun add polished
README
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!

版本列表
4.3.1 2024-02-01
4.3.0 2024-02-01
4.2.2 2022-04-06
4.2.1 2022-04-04
4.2.0 2022-04-03
4.1.4 2022-01-22
4.1.3 2021-05-31
4.1.2 2021-04-25
4.1.1 2021-02-17
4.1.0 2021-01-24
4.0.5 2020-11-25
4.0.4 2020-11-21
4.0.3 2020-10-15
4.0.2 2020-10-08
4.0.1 2020-10-04
4.0.0-beta.2 2020-09-21
4.0.0-beta.1 2020-09-20
3.7.2 2021-05-31
3.7.1 2021-02-17
3.7.0 2021-02-06
3.6.7 2020-09-19
3.6.6 2020-08-30
3.6.5 2020-06-11
3.6.4 2020-05-29
3.6.3 2020-05-10
3.6.2 2020-05-06
3.6.1 2020-05-05
3.6.0 2020-05-02
3.5.2 2020-04-19
3.5.1 2020-03-22
3.5.0 2020-03-20
3.4.4 2020-01-28
3.4.3 2020-01-26
3.4.2 2019-10-30
3.4.1 2019-06-15
3.4.0 2019-05-25
3.3.2 2019-05-18
3.3.1 2019-05-18
3.3.0 2019-05-05
3.2.1 2019-05-05
3.2.0 2019-03-30
3.1.0 2019-03-23
3.0.4 2019-03-22
3.0.3 2019-03-02
3.0.2 2019-03-01
3.0.1 2019-03-01
3.0.0-beta.4 2019-02-14
3.0.0-beta.3 2019-02-12
3.0.0-beta.2 2019-02-07
3.0.0-beta.1 2019-02-02
3.0.0-beta.0 2019-02-02
3.0.0-alpha.0 2019-01-31
3.0.0 2019-02-16
2.3.3 2019-01-09
2.3.2 2019-01-09
2.3.1 2018-12-01
2.3.0 2018-10-21
2.2.0 2018-09-29
2.1.1 2018-09-21
2.0.3 2018-08-26
2.0.2 2018-08-22
2.0.1 2018-08-22
2.0.0-beta.1 2018-08-10
2.0.0-beta.0 2018-08-03
2.0.0-alpha.1 2018-07-31
2.0.0-alpha.0 2018-07-29
2.0.0 2018-08-22
1.9.3 2018-06-28
1.9.2 2018-02-05
1.9.1 2018-02-04
1.9.0 2017-11-08
1.8.2 2017-11-06
1.8.1 2017-10-16
1.8.0 2017-10-08
1.7.0 2017-08-31
1.6.2 2017-08-30
1.6.1 2017-08-26
1.6.0 2017-08-26
1.5.0 2017-08-26
1.4.1 2017-08-18
1.4.0 2017-08-08
1.3.0 2017-07-12
1.2.1 2017-06-23
1.2.0 2017-06-21
1.1.3 2017-05-31
1.1.2 2017-05-10
1.1.1 2017-05-02
1.1.0 2017-04-30
1.0.4 2017-04-25
1.0.3 2017-04-16
1.0.2 2017-03-31
1.0.1 2017-03-30
1.0.0 2017-03-28
0.0.0 2016-11-07