Skip to content

Commit

Permalink
Add support for styled-components v6 (#818)
Browse files Browse the repository at this point in the history
This PR adds support for styled-components v6 by setting the
`sassyPseudo` option to true for the styled-components preset.
Prefixing selectors like hover with an ampersand (eg: `&:hover`) were
made a requirement in the latest version.

Another change is that when using styled, all props will be added to the
element and you'll likely see a console warning. This isn't handled by
twin so we'll need to use [transient
props](https://styled-components.com/docs/api#transient-props) to get
around that.

Related #805
  • Loading branch information
ben-rogerson committed Jul 25, 2023
1 parent 45ff6ad commit 0404da6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/lib/twinConfig.ts
Expand Up @@ -25,6 +25,11 @@ const TWIN_CONFIG_DEFAULTS = {
} as const

// Defaults for different css-in-js libraries

const configDefaultsStyledComponents = {
sassyPseudo: true, // Sets selectors like hover to &:hover
} as const

const configDefaultsGoober = {
sassyPseudo: true, // Sets selectors like hover to &:hover
} as const
Expand All @@ -47,13 +52,15 @@ const configDefaultsStitches = {

function configDefaultsTwin({
isSolid,
isStyledComponents,
isGoober,
isStitches,
isDev,
}: GetPackageUsed & { isDev: boolean }): TwinConfigAll {
return {
...TWIN_CONFIG_DEFAULTS,
...(isSolid && configDefaultsSolid),
...(isStyledComponents && configDefaultsStyledComponents),
...(isGoober && configDefaultsGoober),
...(isStitches && configDefaultsStitches),
dataTwProp: isDev,
Expand Down

0 comments on commit 0404da6

Please sign in to comment.