🌐
styled-components
styled-components.com › docs › advanced
styled-components
A theme can also be passed down to a component using the theme prop. This is useful to circumvent a missing ThemeProvider or to override it. // Define our button const Button = styled.button` font-size: 1em; margin: 1em; padding: 0.25em 1em; border-radius: 3px; /* Color the border and text with theme.main */ color: ${props => props.theme.main}; border: 2px solid ${props => props.theme.main}; `; // Define what main theme will look like const theme = { main: "mediumseagreen" }; render( <div> <Button theme={{ main: "royalblue" }}>Ad hoc theme</Button> <ThemeProvider theme={theme}> <div> <Button>Themed</Button> <Button theme={{ main: "darkorange" }}>Overridden</Button> </div> </ThemeProvider> </div> );
🌐
GitHub
github.com › styled-components › styled-theming
GitHub - styled-components/styled-theming: Create themes for your app using styled-components
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} `;
Starred by 1.2K users
Forked by 25 users
Languages   JavaScript 97.6% | HTML 2.4% | JavaScript 97.6% | HTML 2.4%
🌐
npm
npmjs.com › package › styled-components-theme-connector
styled-components-theme-connector - npm
November 6, 2022 - import React from 'react'; import { withDefaultTheme, connectTheme } from 'styled-components-theme-connector'; import theme from 'styled-theming'; import StyledItem from './Item'; // styled component // Wire component style using string selector const Container = connectTheme('list.container')('div'); const List = connectTheme('list.ul')(({ className, label, children }) => ( <Container> <p>{label}</p> <ul className={className}>{children}</ul> </Container> )); export const Item = connectTheme('list.li')(StyledItem); // With styled-theming (optional): const boxBackgroundColor = theme('mode', { light: '#fff', dark: '#000', }); const textColor = theme('mode', { light: '#000', dark: '#fff', }); // Wrap root component with a default theme config: const theme = { mode: 'light', list: { container: css` background-color: ${boxBackgroundColor}; /* styles...
      » npm install styled-components-theme-connector
    
Published   Nov 06, 2022
Version   0.1.8
🌐
Emotion
emotion.sh › docs › styled
Emotion – Styled Components
Component selectors can also be used with object styles. ... This API was inspired by glamorous. ❤️ · By default, Emotion passes all props (except for theme) to custom components and only props that are valid html attributes for string tags. You can customize this by passing a custom ...
🌐
DEV Community
dev.to › aromanarguello › how-to-use-themes-in-styled-components-49h
How to use Themes in styled-components - DEV Community
November 26, 2022 - I love the fact that I can embed and treat styles as if they were components. It gives me the ability to use maximum reusability. Additionally, I can pass props to these and make really cool conditional styles with minimum effort. Theming is a great tool to use within front-end applications. It also allows me to write way less code and be more consistent with my styling. By leveraging the theme provider in styled-components I only need to write my main styles and rules in one single object and invoke them in any component that is a descendant of that provider.
🌐
Medium
medium.com › @akbar123jason › styling-in-react-with-styled-components-a-guide-to-implementing-themes-e5f6ae375371
Styling in React with Styled-Components: A Guide to Implementing Themes | by Akbarjason | Medium
September 21, 2023 - Now, the Button component can access the theme's properties for styling. This simplifies theme management and ensures a consistent look and feel across your application. Styled-Components encourages writing cleaner and more readable code.
🌐
Scott Spence
scottspence.com › home › posts › styled-components 💅 getting started
styled-components 💅 getting started - Scott Spence
April 3, 2018 - Now say we want to have several components in our app that use a CSS colour property color: #6e27c5 instead of hard coding it through the app for every component that uses it we can use the styled-components ThemeProvider.
Find elsewhere
🌐
egghead.io
egghead.io › lessons › react-create-and-use-a-theme-in-styled-components
Create and use a Theme in Styled Components | egghead.io
In the index.js file, where you have your App component being rendered, we will wrap it with the ThemeProvider. We can set some colors to an object and call it theme.
🌐
Storybook
storybook.js.org › recipes › styled-components
Styled Components | Storybook recipes
This will run a configuration script that will walk you through setting up the addon. When prompted, select styled-components from the configuration options. ... Under the hood, this runs npx @storybook/auto-config themes, which should read your project and try to configure your Storybook with the correct decorator.
🌐
Theme-ui
theme-ui.com › guides › styled-components
Styled Components – Theme UI
Instead of using the ThemeProvider component from @emotion/react, import and use the Theme UI provider at your app’s root level. ... If you’re using the Styled Components library, these can usually be converted to use Emotion with a single line change to the import statement.
🌐
Josh W. Comeau
joshwcomeau.com › css › styled-components
The styled-components Happy Path: my personal suite of “best practices” • Josh W. Comeau
January 25, 2021 - styled-components is a wonderfully powerful styling library for React, and over the years I've learned a lot about how to use it effectively. This article shares my personal “best practices”.
🌐
LogRocket
blog.logrocket.com › home › build a react theme switcher app with styled-components
Build a React theme switcher app with styled-components - LogRocket Blog
June 4, 2024 - Full theming support: the ThemeProvider ... styled-components uses the React Context API which offers a Theme Context that we can pass a theme into as a prop, allowing it to be dynamically accessed within every component – even those that ...
🌐
Pieces
pieces.app › home
Styling Components with React Themes
Pieces for Developers – Long-Term Memory Agent
Learn how to implement styling components in your React projects with the styled-components library. Pieces is your AI long-term memory agent that captures live context from browsers to IDEs and tools, manages snippets, and supports multiple LLMs. This app has dramatically improved my workflow!
Rating: 5 ​
🌐
GitHub
github.com › erikras › styled-components-theme
GitHub - erikras/styled-components-theme: Defines themes via flexible color selectors for use with styled-components
Defines themes via flexible color selectors for use with styled-components - erikras/styled-components-theme
Starred by 306 users
Forked by 17 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
freeCodeCamp
freecodecamp.org › news › styled-components-in-react
How to Use Styled Components in Your React Apps
October 16, 2024 - Styled-components is a library that allows you to write CSS in JS while building custom components in Reactjs. There are multiple options you can go with to style a React application.
🌐
Agney
agney.dev › blog › theming-on-styled-components
Theming with Styled Components | Blog
March 3, 2020 - Styled Components delivers the current theme that it receives from it's parent as an argument which you can use to manipulate or add values to the theme.
🌐
JavaScript in Plain English
javascript.plainenglish.io › themes-within-themes-with-react-typescript-and-styled-components-e65491e45f5e
Themes within themes with React, TypeScript and Styled Components ✨ | by Catherine Oxley | JavaScript in Plain English
September 8, 2022 - We’re now successfully passing the demoContainer theme to our DemoContainer component. To use the theme variables, let’s create our first styled component that will wrap all the content inside the container.
🌐
GitHub
github.com › styled-components › styled-components › issues › 1589
Strongly typed theme property · Issue #1589 · styled-components/styled-components
March 8, 2018 - Hi, I am using TypeScript and ThemeProvider for my components, and I had a couple of questions: First of all, my components are created using map, so I used to assign a key to each one, now I have put ThemeProvider to be the top parent c...
Author   farzadmf
🌐
Reddit
reddit.com › r/reactjs › using styled-components with a theme provider. how should i organize my colors?
r/reactjs on Reddit: Using Styled-Components with a theme provider. How should I organize my colors?
June 3, 2022 -

I'm making a design system for our company using Styled Components. I can create a theme and use that theme for any component that needs to reuse padding, colors, etc.

export const Theme = (props) => (
  <ThemeProvider theme={{
    fontWeights: {
      bold: 700;
      normal: 400,
      light: 100
    },
    ...
  }}>{props.children}</ThemeProvider>
);

export const Button = styled.button(props => `
  font-weight: props.theme.fontWeight.normal,
  ...
`);

The problem I'm having is colors. I don't want to specify the same HTML color codes everywhere, so I want to have them in the theme. But how do I organize them?

If I try this solution, then when I find a new situation I need to amend the color object, and it grows out of control with duplicated values and inconsistent variable names:

theme = {
  colors: {
    success: {
      font: "#2dce89",
      disabledBackground: "#abebd0",
      glow: ...
      active: ...
      borderDisabled: ...
      ...
    }
  }
}

Design sites suggest using numbers. But if I have to style a button, how do I know which color weight to use? And where do greyed versions for disabled go? What about other variants?

success: {
  100: "#d5f5e7",
  200: "#abebd0",
  300: "#81e2b8",
  400: "#57d8a1",
  500: "#2dce89",
  600: "#24a56e",
  700: "#1b7c52",
  800: "#125237",
  900: "#09291b",
},

Is there a better way to organize my colors so it is easy to be consistent across multiple components without having an explosion of one-off variables or duplicated values?