What is polished?
Polished is a lightweight toolset for writing styles in JavaScript. It provides a variety of utility functions to help with common CSS-in-JS tasks, such as color manipulation, media queries, and more.
What are polished's main functionalities?
Color Manipulation
Polished provides functions like `lighten` and `darken` to manipulate colors easily. This is useful for creating color schemes and ensuring accessibility.
const { lighten, darken } = require('polished');
const lightenedColor = lighten(0.2, '#ff0000'); // '#ff6666'
const darkenedColor = darken(0.2, '#ff0000'); // '#cc0000'
Mixing Colors
The `mix` function allows you to blend two colors together. This can be useful for creating gradients or finding intermediary colors.
const { mix } = require('polished');
const mixedColor = mix(0.5, '#ff0000', '#0000ff'); // '#800080'
Media Queries
Polished includes utilities for generating media queries, such as the `between` function, which helps in creating responsive designs.
const { between } = require('polished');
const mediaQuery = between('400px', '1000px'); // '@media (min-width: 400px) and (max-width: 1000px)'
Math Functions
Polished offers math functions like `stripUnit` to remove units from values and `modularScale` to generate values based on a modular scale.
const { stripUnit, modularScale } = require('polished');
const value = stripUnit('16px'); // 16
const scaleValue = modularScale(2, '1em', 1.25); // '1.5625em'
Other packages similar to polished
color
The `color` package is a comprehensive library for color manipulation. It offers a wide range of color operations similar to polished but focuses solely on color manipulation.
styled-components
Styled-components is a library for writing CSS in JS. While it doesn't offer the same utility functions as polished, it integrates well with polished for styling React components.
emotion
Emotion is another library for writing CSS in JS. It provides a similar feature set to styled-components and can be used in conjunction with polished for additional utility functions.
A lightweight toolset for writing styles in Javascript. ✨
npm install --save polished
- Make your app look great without stress
- Cross framework compatible: No matter if you're using
styled-components
, 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!
ToC
Mixins
Color
Shorthands
Helpers
Types
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, jss and many more!
No matter if you're using inline styles or CSS-in-JS, polished is for you.
License
Copyright © 2016 Maximilian Stoiber. Licensed under the MIT License, see LICENSE.md for more information!