All Projects → styled-components → Styled Theming

styled-components / Styled Theming

Licence: mit
Create themes for your app using styled-components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Styled Theming

tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-95.13%)
Mutual labels:  styled-components, css-in-js, theming
Styled System
⬢ Style props for rapid UI development
Stars: ✭ 7,126 (+567.85%)
Mutual labels:  theming, styled-components, css-in-js
Styled Components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
Stars: ✭ 35,473 (+3224.55%)
Mutual labels:  styled-components, css-in-js
Glamorous
DEPRECATED: 💄 Maintainable CSS with React
Stars: ✭ 3,681 (+244.99%)
Mutual labels:  styled-components, css-in-js
Design System Utils
👩‍🎨 Access your design tokens with ease
Stars: ✭ 465 (-56.42%)
Mutual labels:  styled-components, css-in-js
Reactackle
Open-source components library built with React and Styled-Components.
Stars: ✭ 278 (-73.95%)
Mutual labels:  styled-components, css-in-js
Css In Js Benchmarks
Stars: ✭ 360 (-66.26%)
Mutual labels:  styled-components, css-in-js
Styled Breakpoints
Simple and powerful tool for creating breakpoints in styled components and emotion. 💅
Stars: ✭ 428 (-59.89%)
Mutual labels:  styled-components, css-in-js
styled-components-docs-zh
💅 styled-components 中文文档翻译 🏇持续施工中
Stars: ✭ 160 (-85%)
Mutual labels:  styled-components, css-in-js
Cattous
CSS in JSX for lazy developers, built using styled-components and styled-system
Stars: ✭ 38 (-96.44%)
Mutual labels:  styled-components, css-in-js
Glamorous Native
React Native component styling solved💄
Stars: ✭ 566 (-46.95%)
Mutual labels:  styled-components, css-in-js
Design System
Priceline.com Design System
Stars: ✭ 604 (-43.39%)
Mutual labels:  styled-components, css-in-js
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (-75.63%)
Mutual labels:  styled-components, css-in-js
react-native-css-in-js-benchmarks
CSS in JS Benchmarks for React Native
Stars: ✭ 46 (-95.69%)
Mutual labels:  styled-components, css-in-js
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-96.25%)
Mutual labels:  styled-components, css-in-js
satchel
The little bag of CSS-in-JS superpowers
Stars: ✭ 14 (-98.69%)
Mutual labels:  styled-components, css-in-js
Twin.macro
🦹‍♂️ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, stitches and goober) at build time.
Stars: ✭ 5,137 (+381.44%)
Mutual labels:  styled-components, css-in-js
mugiwara
fast minimal CSS-in-JS created to reduce size of CSS injected
Stars: ✭ 11 (-98.97%)
Mutual labels:  styled-components, css-in-js
adonis
Adonis ❤️ Aphrodite
Stars: ✭ 44 (-95.88%)
Mutual labels:  css-in-js, theming
React Redux Saga Boilerplate
Starter kit with react-router, react-helmet, redux, redux-saga and styled-components
Stars: ✭ 535 (-49.86%)
Mutual labels:  styled-components, css-in-js

styled-theming

Create themes for your app using styled-components

Read the introductory blog post

Installation

yarn add styled-components styled-theming

Example

import React from 'react';
import styled, {ThemeProvider} from 'styled-components';
import theme from 'styled-theming';

const boxBackgroundColor = theme('mode', {
  light: '#fff',
  dark: '#000',
});

const Box = styled.div`
  background-color: ${boxBackgroundColor};
`;

export default function App() {
  return (
    <ThemeProvider theme={{ mode: 'light' }}>
      <Box>
        Hello World
      </Box>
    </ThemeProvider>
  );
}

API

<ThemeProvider>

See styled-components docs

<ThemeProvider> is part of styled-components, but is required for styled-theming.

import {ThemeProvider} from 'styled-components';

<ThemeProvider> accepts a single prop theme which you should pass an object with either strings or getter functions. For example:

<ThemeProvider theme={{ mode: 'dark', size: 'large' }}>
<ThemeProvider theme={{ mode: modes => modes.dark, size: sizes => sizes.large }}>

You should generally set up a <ThemeProvider> at the root of your app:

function App() {
  return (
    <ThemeProvider theme={...}>
      {/* rest of your app */}
    </ThemeProvider>
  );
}

theme(name, values)

Most of your theming will be done with this function.

name should match one of the keys in your <ThemeProvider> theme.

<ThemeProvider theme={{ whatever: '...' }}/>

theme('whatever', {...});

values should be an object where one of the keys will be selected by the value provided to <ThemeProvider> theme.

<ThemeProvider theme={{ mode: 'light' }}/>
<ThemeProvider theme={{ mode: 'dark' }}/>

theme('mode', {
  light: '...',
  dark: '...',
});

The values of this object can be any CSS value.

theme('mode', {
  light: '#fff',
  dark: '#000',
});

theme('font', {
  sansSerif: '"Helvetica Neue", Helvetica, Arial, sans-serif',
  serif: 'Georgia, Times, "Times New Roman", serif',
  monoSpaced: 'Consolas, monaco, monospace',
});

These values can also be functions that return CSS values.

theme('mode', {
  light: props => props.theme.userProfileAccentColor.light,
  dark: props => props.theme.userProfileAccentColor.dark,
});

theme will create a function that you can use as a value in styled-component's styled function.

import styled from 'styled-components';
import theme from 'styled-theming';

const backgroundColor = theme('mode', {
  light: '#fff',
  dark: '#000',
});

const Box = styled.div`
  background-color: ${backgroundColor}
`;

The values will be passed through like any other interpolation in styled-components. You can use the css helper to add entire blocks of styles, including their own interpolations.

import styled, {css} from 'styled-components';
import theme from 'styled-theming';

const white = "#fff";
const black = "#000";

const boxStyles = theme('mode', {
  light: css`
    background: ${white};
    color: ${black};
  `,
  dark: css`
    background: ${black};
    color: ${white};
  `,
});

const Box = styled.div`
  ${boxStyles}
`;

theme.variants(name, prop, themes)

It's often useful to create variants of the same component that are selected via an additional prop.

To make this easier with theming, styled-theming provides a theme.variants function.

import styled from 'styled-components';
import theme from 'styled-theming';

const backgroundColor = theme.variants('mode', 'variant', {
  default: { light: 'gray', dark: 'darkgray' },
  primary: { light: 'blue', dark: 'darkblue' },
  success: { light: 'green', dark: 'darkgreen' },
  warning: { light: 'orange', dark: 'darkorange' },
});

const Button = styled.button`
  background-color: ${backgroundColor};
`;

Button.propTypes = {
  variant: PropTypes.oneOf(['default', 'primary', 'success', 'warning'])
};

Button.defaultProps = {
  variant: 'default',
};

<Button/>
<Button variant="primary"/>
<Button variant="success"/>
<Button variant="warning"/>
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].