-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert
@emotion/styled
's source code to TypeScript (#3284)
* Convert `@emotion/styled`'s source code to TypeScript * fixed entrypoint extension * fix types reference * add changeset * more localized cast * remove redundant cast * organize imports
- Loading branch information
Showing
19 changed files
with
352 additions
and
393 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emotion/styled': minor | ||
--- | ||
|
||
Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written. |
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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Theme } from '@emotion/react' | ||
import styled from './base' | ||
import { ReactJSXIntrinsicElements } from './jsx-namespace' | ||
import { tags } from './tags' | ||
import { | ||
CreateStyledComponent, | ||
CreateStyled as BaseCreateStyled | ||
} from './types' | ||
export type { | ||
ArrayInterpolation, | ||
ComponentSelector, | ||
CSSObject, | ||
FunctionInterpolation, | ||
Interpolation | ||
} from '@emotion/serialize' | ||
export type { | ||
CreateStyledComponent, | ||
FilteringStyledOptions, | ||
StyledComponent, | ||
StyledOptions | ||
} from './types' | ||
|
||
export type StyledTags = { | ||
[Tag in keyof ReactJSXIntrinsicElements]: CreateStyledComponent< | ||
{ | ||
theme?: Theme | ||
as?: React.ElementType | ||
}, | ||
ReactJSXIntrinsicElements[Tag] | ||
> | ||
} | ||
|
||
export interface CreateStyled extends BaseCreateStyled, StyledTags {} | ||
|
||
// bind it to avoid mutating the original function | ||
const newStyled = styled.bind(null) as CreateStyled | ||
|
||
tags.forEach(tagName => { | ||
;(newStyled as any)[tagName] = newStyled(tagName as keyof typeof newStyled) | ||
}) | ||
|
||
export default newStyled |
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 |
---|---|---|
|
@@ -135,4 +135,4 @@ export const tags = [ | |
'svg', | ||
'text', | ||
'tspan' | ||
] | ||
] as const |
Oops, something went wrong.