# styled-components

Published articles for styled-components.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Theme with styled-components and Typescript

DevFeed: [Theme with styled-components and Typescript](<https://devfeed.tech/articles/theme-with-styled-components-and-typescript-19124.md>)

Original publisher: [Read original article](<https://medium.com/rbi-tech/theme-with-styled-components-and-typescript-209244ec15a3?source=rss----904782439303---4>)

Author: Ethan Nguyen

Published: 2020-07-14T12:58:19Z

Content type: tutorial

Language: en

Sources: [RBI Tech](<https://devfeed.tech/sources/rbi-tech.md>)

Topics: [styled-components](<https://devfeed.tech/topics/styled-components.md>), [TypeScript](<https://devfeed.tech/topics/typescript.md>), [CSS](<https://devfeed.tech/topics/css.md>), [Design system](<https://devfeed.tech/topics/design-system.md>), [modern web development](<https://devfeed.tech/topics/modern-web-development.md>)

Tags: [css](<https://devfeed.tech/tags/css.md>), [dark-mode](<https://devfeed.tech/tags/dark-mode.md>), [design-system](<https://devfeed.tech/tags/design-system.md>), [design-systems](<https://devfeed.tech/tags/design-systems.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [styled-components](<https://devfeed.tech/tags/styled-components.md>), [themes](<https://devfeed.tech/tags/themes.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [visual-studio-code](<https://devfeed.tech/tags/visual-studio-code.md>)

### AI overview

A tutorial on theming applications with styled-components and TypeScript. It covers installation, Visual Studio Code support, declaration files, theme interfaces, naming conventions, theme creation, ThemeProvider setup, and switching between themes.

### Source excerpt

What is styled-components? Styled-components is arguably the most common CSS-in-JS library out there (Don't trust me? Check out their site and their adoption from many organizations, 7.6M/month downloads on NPM 🔥). One of its advanced use cases for this library is theming. Theming in styled-components allows your app to support multiple design patterns within the same app. Imagine an amazing code editor with no dark mode! Having options to customize the look and feel of your app from the primary colour palette to the typography scale can help our system to capture more personas. This article will give some breakdown of the basic setup and naming convention for theming your app with styled-components, and how to setup Typescript with styled-components themes Installationyarn add styled-components yarn add @types/styled-components -DVSCode plugin If you are using Visual Studio Code, I highly recommend installing this helpful plugin. It will highlight and IntelliSense your syntax for styled-components Create a declaration file Firstly, we will need to define how our theme interface looks like. Inside src folder, create styled.d.ts file and extend the existing styled-component DefaultTheme. This will help with IntelliSense and ensure a contract for all available themes. // styled.d.ts import 'styled-components';interface IPalette { main: string contrastText: string }declare module 'styled-components' { export interface DefaultTheme { borderRadius: string palette: { common: { black: string white: string } primary: IPalette secondary: IPalette } } }Naming convention Let's break down some logic here for the naming convention of theming. As I mentioned earlier, our goal for theming a system is to be able to control the compactness and colour palette. Hence we should define our theme around these styles like border-radius font-weight font-size ... and all colour related. About colour naming, avoid naming variable with actual colour but do name with something likeprimary or sec

## Using Tailwind CSS with Gatsby, React & Emotion Styled Components

DevFeed: [Using Tailwind CSS with Gatsby, React & Emotion Styled Components](<https://devfeed.tech/articles/using-tailwind-css-with-gatsby-react-emotion-styled-components-31316.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/using-tailwind-css-with-gatsby-react-emotion-styled-components>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2019-10-20T14:08:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Tailwind CSS](<https://devfeed.tech/topics/tailwind.md>), [gatsby](<https://devfeed.tech/topics/gatsby.md>), [React](<https://devfeed.tech/topics/react.md>), [styled-components](<https://devfeed.tech/topics/styled-components.md>), [CSS](<https://devfeed.tech/topics/css.md>), [PostCSS](<https://devfeed.tech/topics/postcss.md>), [Babel](<https://devfeed.tech/topics/babel.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [babel](<https://devfeed.tech/tags/babel.md>), [components](<https://devfeed.tech/tags/components.md>), [css](<https://devfeed.tech/tags/css.md>), [css-in-js](<https://devfeed.tech/tags/css-in-js.md>), [emotion](<https://devfeed.tech/tags/emotion.md>), [gatsby](<https://devfeed.tech/tags/gatsby.md>), [insights](<https://devfeed.tech/tags/insights.md>), [learn](<https://devfeed.tech/tags/learn.md>), [postcss](<https://devfeed.tech/tags/postcss.md>), [project](<https://devfeed.tech/tags/project.md>), [react](<https://devfeed.tech/tags/react.md>), [styled](<https://devfeed.tech/tags/styled.md>), [styled-components](<https://devfeed.tech/tags/styled-components.md>), [tailwind](<https://devfeed.tech/tags/tailwind.md>), [tailwind-css](<https://devfeed.tech/tags/tailwind-css.md>), [utility-first](<https://devfeed.tech/tags/utility-first.md>)

### AI overview

A tutorial on combining Tailwind CSS with Gatsby and React through Emotion Styled Components. It explains a hybrid setup using twin.macro for component-level Tailwind styles and PostCSS for Tailwind's base and global styles.

### Source excerpt

Learn how to use the utility-first Tailwind CSS with Emotion "CSS-in-JS" Styled Components in a Gatsby JS + React project.

## Eschewing Shadow DOM

DevFeed: [Eschewing Shadow DOM](<https://devfeed.tech/articles/eschewing-shadow-dom-31224.md>)

Original publisher: [Read original article](<https://every-layout.dev/blog/eschewing-shadow-dom/>)

Author: Heydon Pickering

Published: 2019-06-14T00:00:00Z

Content type: article

Language: en

Sources: [The Every Layout Blog](<https://devfeed.tech/sources/the-every-layout-blog.md>)

Topics: [Web Components](<https://devfeed.tech/topics/web-components.md>), [CSS](<https://devfeed.tech/topics/css.md>), [modern web development](<https://devfeed.tech/topics/modern-web-development.md>), [React](<https://devfeed.tech/topics/react.md>), [styled-components](<https://devfeed.tech/topics/styled-components.md>)

Tags: [css](<https://devfeed.tech/tags/css.md>), [custom](<https://devfeed.tech/tags/custom.md>), [element](<https://devfeed.tech/tags/element.md>), [react](<https://devfeed.tech/tags/react.md>), [styled-components](<https://devfeed.tech/tags/styled-components.md>)

### AI overview

An examination of styling problems encountered with Shadow DOM, including inconsistent universal styles, limited inheritance, slot restrictions, and specificity issues. The author proposes an experimental alternative for web components that namespaces and embeds prop-derived instance styles in the document head.

### Source excerpt

Regarding styling, Shadow DOM is really good at one thing: preventing per-component styles from leaking out and affecting other parts of the document. Unfortunately, Shadow DOM also has a very opinionated way of preventing styles being applied from the parent document. Here is a roundup of the quirks and associated issues I've encountered: Shadow DOM styling issues Universal styles Some universal styles (using the * selector) are applied, and others are not. The color property appears to pierce shadow boundaries, but I've had no luck with box-sizing. Having to set box-sizing: border-box for each component is redundant. Inheritance Document styles are inherited in Shadow DOM. But inheritance only gets you so far, especially since not all properties are inheritable by default anyway. I've tried hacking things together with the explicit inherit keyword, but that seems to have no effect. Using the following is no good, because it forces every node to inherit every property from the parent. If <my-component> had display: flex applied, every one of the component's descendants would adopt it. * { all: inherit; /* yikes */ } Slot restrictions For performance reasons, the ::slotted() selector, which allows you to style the Light DOM content of your component from within your Shadow DOM, only lets you affect child elements and not descendants at depth. This is a bit restrictive. Worse, you cannot seem to use sibling combinators like + or ~. None of the following works: ::slotted(*) + * /* Nope */ ::slotted(* + *) /* Nope */ ::slotted(*) + ::slotted(*) /* Nope */ Specificity In making layout components, I like to take a progressive approach: style the component and its Light DOM nodes in my document stylesheet, then enhance with instance-specific styles via props (attributes) in Shadow DOM. For a component instance that looks like this... <my-component itemWidth="10rem"></my-component> ...I would apply the itemWidth value in the Shadow DOM using interpolation: ` <style> ::slot

## Screenshot testing with React and Storybook

DevFeed: [Screenshot testing with React and Storybook](<https://devfeed.tech/articles/screenshot-testing-with-react-and-storybook-24570.md>)

Original publisher: [Read original article](<https://medium.com/bleeding-edge/screenshot-testing-with-react-and-storybook-19ab7e49ec92?source=rss----d8ebe85cdc0f---4>)

Author: Jesse Pinho

Published: 2018-03-19T09:18:02Z

Content type: tutorial

Language: en

Sources: [Bleeding Edge - Medium](<https://devfeed.tech/sources/bleeding-edge-medium.md>)

Topics: [screenshot-testing](<https://devfeed.tech/topics/screenshot-testing.md>), [Storybook](<https://devfeed.tech/topics/storybook.md>), [React](<https://devfeed.tech/topics/react.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [styled-components](<https://devfeed.tech/topics/styled-components.md>), [Selenium](<https://devfeed.tech/topics/selenium.md>)

Tags: [continuous-integration](<https://devfeed.tech/tags/continuous-integration.md>), [react](<https://devfeed.tech/tags/react.md>), [screenshot-testing](<https://devfeed.tech/tags/screenshot-testing.md>), [selenium](<https://devfeed.tech/tags/selenium.md>), [storybook](<https://devfeed.tech/tags/storybook.md>), [styled-components](<https://devfeed.tech/tags/styled-components.md>), [testing](<https://devfeed.tech/tags/testing.md>), [visual-regression-testing](<https://devfeed.tech/tags/visual-regression-testing.md>)

### AI overview

The article explains why end-to-end UI tests can miss visual regressions and explores screenshot testing with React and Storybook to check component appearance across different states.

### Source excerpt

Visual regression testing for fun, profit, and peace of mind Illustration by Marta Pucci A friend of mine recently related a scary story about the lack of automated visual regression testing where he works--a huge international tech firm that you've heard of and probably use. He'd added a CSS class to an element to hide it from the user. Unbeknownst to him, and despite using BEM-style naming for CSS classes, this class name was already being used for an important checkbox in the user settings screen of his company's web app. The result? Users could no longer change the setting represented by the checkbox, because it was invisible! I asked him why that hadn't been caught by automated tests. He explained that, although they did have end-to-end tests in place that went through the UI and tested its functionality, the tests didn't catch the bug. Selenium was still able to check the original checkbox via its selector, so its visibility had no effect on the outcome of the test. The only way this could have been caught is via visual regression testing -- or, as it is sometimes called, screenshot testing. 💅 Switching to styled-components I recalled this story recently while working on a sizable project at Clue: converting all of our "native" CSS to use styled-components. The new helloclue.com website consists of dozens of components. An article page, for example, contains at least ten different React components, all of which have accompanying CSS files. Converting all of this CSS to styled-components means there's an enormous risk of bugs exactly like the one my friend experienced. So before the project began, I investigated setting up screenshot testing for the site. 📕 Enter Storybook (Note: if you're already familiar with Storybook and @storybook/react, feel free to skip to the next section.) We use Storybook when developing simple presentational components. This way, we can test them in every possible state, without having to reproduce all the logic and so forth required t