-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!(styled-components): adopt styled-components v6
BREAKING CHANGE: Minimum version of styled-components is now 6.1.11. See the [migration guide](https://styled-components.com/docs/faqs#what-do-i-need-to-do-to-migrate-to-v6) for more information.
- Loading branch information
Showing
12 changed files
with
92 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
/* eslint-disable no-continue, no-loop-func, no-cond-assign */ | ||
import { | ||
css as scCss, | ||
FlattenSimpleInterpolation, | ||
ThemedCssFunction, | ||
} from 'styled-components' | ||
import { StyleGenerator, Theme } from '@xstyled/system' | ||
import { flattenStrings } from '@xstyled/util' | ||
import { createTransform } from '@xstyled/core' | ||
import { StyleGenerator } from '@xstyled/system' | ||
import { flattenStrings } from '@xstyled/util' | ||
import { css as scCss } from 'styled-components' | ||
|
||
export type XCSSFunction = ThemedCssFunction<Theme> | ||
export type XCSSFunction = typeof scCss | ||
|
||
export const createCssFunction = <TGen extends StyleGenerator>( | ||
generator: TGen, | ||
): XCSSFunction => { | ||
const transform = createTransform(generator) | ||
return ((...args: Parameters<XCSSFunction>) => { | ||
const scCssArgs = scCss(...args) | ||
|
||
return <Props extends object>(...args: Parameters<XCSSFunction>) => { | ||
const scCssArgs = scCss<Props>(...args) | ||
const flattenedArgs = flattenStrings(scCssArgs as any[]) | ||
return flattenedArgs.map(transform) as FlattenSimpleInterpolation | ||
}) as XCSSFunction | ||
return flattenedArgs.map(transform) as ReturnType<typeof scCss<Props>> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
/* eslint-disable no-continue, no-loop-func, no-cond-assign */ | ||
import { StyledComponent, DefaultTheme } from 'styled-components' | ||
import { scStyled } from './scStyled' | ||
import { StyleGenerator, StyleGeneratorProps } from '@xstyled/system' | ||
import { createBaseStyled } from './createStyled' | ||
import { | ||
FastOmit, | ||
SupportedHTMLElements, | ||
IStyledComponent, | ||
} from 'styled-components' | ||
import { createCssFunction } from './createCssFunction' | ||
|
||
type JSXElementKeys = keyof JSX.IntrinsicElements | ||
|
||
type SafeIntrinsicElement<T extends keyof JSX.IntrinsicElements> = ( | ||
props: Omit<JSX.IntrinsicElements[T], 'color'>, | ||
) => React.ReactElement<any, T> | ||
import { createBaseStyled } from './createStyled' | ||
import { scStyled } from './scStyled' | ||
|
||
export type X<TGen extends StyleGenerator> = { | ||
[Key in JSXElementKeys]: StyledComponent< | ||
SafeIntrinsicElement<Key>, | ||
DefaultTheme, | ||
StyleGeneratorProps<TGen>, | ||
'color' | ||
[Key in SupportedHTMLElements]: IStyledComponent< | ||
'web', | ||
FastOmit<JSX.IntrinsicElements[Key], keyof StyleGeneratorProps<TGen>> & | ||
StyleGeneratorProps<TGen> | ||
> | ||
} | ||
|
||
export const createX = <TGen extends StyleGenerator>( | ||
generator: TGen, | ||
): X<TGen> => { | ||
const xstyled = createBaseStyled(createCssFunction(generator), generator) | ||
const xstyled = createBaseStyled<TGen>( | ||
createCssFunction<TGen>(generator), | ||
generator, | ||
) | ||
const x = {} as X<TGen> | ||
Object.keys(scStyled).forEach((tag) => { | ||
// @ts-ignore | ||
x[tag] = xstyled(tag)`` | ||
// @ts-expect-error | ||
x[tag] = xstyled(tag)({}) | ||
}) | ||
return x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import styled from 'styled-components' | ||
import styled, { Styled } from 'styled-components' | ||
|
||
// Provide interop since `styled-components` does not work out of the box with ESM | ||
export const scStyled = | ||
// @ts-ignore | ||
typeof styled === 'function' ? styled : styled.default | ||
// @ts-expect-error | ||
(typeof styled === 'function' ? styled : styled.default) as Styled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters