All Projects → erikras → Styled Components Theme

erikras / Styled Components Theme

Licence: mit
Defines themes via flexible color selectors for use with styled-components

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Styled Components Theme

Vertical Rhythm
Put some typographical vertical rhythm in your CSS. LESS, Stylus and SCSS/SASS versions included.
Stars: ✭ 83 (-72.52%)
Mutual labels:  styles, scss, sass
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (-13.91%)
Mutual labels:  scss, sass, styled-components
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-82.78%)
Mutual labels:  styled-components, styling, styles
Rollup Plugin Styles
🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
Stars: ✭ 116 (-61.59%)
Mutual labels:  styles, scss, sass
Prejss
Get the power of PostCSS with plugins in your JSS styles. 🎨 Just put CSS into JS and get it as JSS object.
Stars: ✭ 238 (-21.19%)
Mutual labels:  scss, sass, styled-components
Tabler
Tabler is free and open-source HTML Dashboard UI Kit built on Bootstrap
Stars: ✭ 24,611 (+8049.34%)
Mutual labels:  themes, scss, sass
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-95.03%)
Mutual labels:  styled-components, styles
highcharts-themes-collection
Highcharts themes collection
Stars: ✭ 30 (-90.07%)
Mutual labels:  themes, styles
ModernWpf
Modern styles and controls for your WPF applications without need WinRT
Stars: ✭ 65 (-78.48%)
Mutual labels:  styled-components, styles
Css
Believe in Better CSS
Stars: ✭ 262 (-13.25%)
Mutual labels:  scss, sass
Stylesheet
The GTK Stylesheet for elementary OS
Stars: ✭ 260 (-13.91%)
Mutual labels:  scss, sass
Docsify Themeable
A delightfully simple theme system for docsify.js. Features multiple themes with rich customization options, an improved desktop and mobile experience, and legacy browser support (IE10+).
Stars: ✭ 299 (-0.99%)
Mutual labels:  themes, scss
Themify
👨‍🎨 CSS Themes Made Easy. A robust, opinionated solution to manage themes in your web application
Stars: ✭ 218 (-27.81%)
Mutual labels:  themes, sass
nextjs-admin-template
Free admin dashboard template based on Next.Js with @paljs/ui component package
Stars: ✭ 266 (-11.92%)
Mutual labels:  styled-components, themes
Gatsby Admin Template
Free admin dashboard template based on Gatsby with @paljs/ui component package
Stars: ✭ 124 (-58.94%)
Mutual labels:  themes, styled-components
Bulmaswatch
Themes for Bulma
Stars: ✭ 1,525 (+404.97%)
Mutual labels:  themes, sass
Modular Admin Html
ModularAdmin - Free Dashboard Theme Built On Bootstrap 4 | HTML Version
Stars: ✭ 2,875 (+851.99%)
Mutual labels:  themes, sass
Sass Deprecate
Let Sass warn you about the pieces of your UI that are deprecated, providing a clear upgrade path for developers
Stars: ✭ 265 (-12.25%)
Mutual labels:  scss, sass
Input Range Scss
Styling Cross-Browser Compatible Range Inputs with Sass
Stars: ✭ 272 (-9.93%)
Mutual labels:  scss, sass
Almace Scaffolding
AMSF, a.k.a. Almace Scaffolding, a super-fast Jekyll framework fighting against the website obesity.
Stars: ✭ 275 (-8.94%)
Mutual labels:  scss, sass

styled-components-theme


NPM Version NPM Downloads Build Status codecov.io styled with prettier

styled-components-theme generates selectors for colors in your styled-components theme that allows color manipulation, using the color library via calls on the selectors themselves.

A selector, in this context, is defined as a function that looks like (props) => props.theme.myColor that the styled-components library accepts as a template variable.


Why?

styled-components is an awesome library, and their React context-based theming scheme is great, but:

  1. Having ${(props) => props.theme.highlight} functions all over your template literals to use any of your theme colors is both hard to read and cumbersome to type.

  2. In migrating from SASS and CSS Modules, I missed the ability to lighten() or darken() or transparentize() a theme color at will to make subtle gradients or overlays.


Installation

Using npm:

  $ npm install --save styled-components-theme

Using yarn:

  $ yarn add styled-components-theme

Usage

1) Define your theme colors

// colors.js

const colors = {
  main:  '#393276',
  dark:  '#0D083B',
  light: '#837EB1'
}

export default colors

2) Apply your theme with ThemeProvider

import { ThemeProvider } from 'styled-components';
import colors from './colors' // from Step #1

const App = props =>
  <ThemeProvider theme={colors}>
    {props.children}
  </ThemeProvider>

3) Create an importable theme object using styled-components-theme

// theme.js

import createTheme from 'styled-components-theme';
import colors from './colors' // from Step #1

const theme = createTheme(...Object.keys(colors))
export default theme

4) Use the theme colors in your components

import styled from 'styled-components'
import theme from './theme' // from Step #3

const Header = styled.div`
  background: ${theme.dark};
  color: ${theme.light};
`

const Button = styled.button`
  background-image: linear-gradient(${theme.light}, ${theme.light.darken(0.3)});
  color: ${theme.dark};
  padding: 10px;
`

Available manipulation functions

This library uses the color manipulation provided by the color library.

theme.color.negate()         // rgb(0, 100, 255) -> rgb(255, 155, 0)

theme.color.lighten(0.5)     // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%)
theme.color.darken(0.5)      // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%)

theme.color.saturate(0.5)    // hsl(100, 50%, 50%) -> hsl(100, 75%, 50%)
theme.color.desaturate(0.5)  // hsl(100, 50%, 50%) -> hsl(100, 25%, 50%)
theme.color.greyscale()      // #5CBF54 -> #969696

theme.color.whiten(0.5)      // hwb(100, 50%, 50%) -> hwb(100, 75%, 50%)
theme.color.blacken(0.5)     // hwb(100, 50%, 50%) -> hwb(100, 50%, 75%)

theme.color.fade(0.5)        // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 0.4)
theme.color.opaquer(0.5)     // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 1.0)

theme.color.rotate(180)      // hsl(60, 20%, 20%) -> hsl(240, 20%, 20%)
theme.color.rotate(-90)      // hsl(60, 20%, 20%) -> hsl(330, 20%, 20%)

theme.color.mix(theme.otherColor, 0.2) // rgb(0, 0, 255) * 0.8 + rgb(0, 255, 0) * 0.2 -> rgb(0, 51, 204)

FAQ

Why use color? Why not [other color manipulation library]?

Because color's manipulation methods were so influenced by SASS, LESS and Stylus, they are already familiar to CSS coders.

Isn't Color mutable? Don't I need to clone()?

Yes, Color is mutable, but this library handles the cloning for you, so you can chain the manipulation methods together to your heart's content without mutating the original theme color. e.g. theme.primary.saturate(0.3).lighten(0.2).fade(0.4).

The manipulation methods in styled-components-theme are immutable.


Made with ❤️ in 🇪🇸 by @erikras.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].