-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated types to support global Theme definition #1609
Merged
Andarist
merged 19 commits into
emotion-js:next
from
tomsseisums:topics/global-theme-type
Dec 7, 2019
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
07a70a4
Updated types to support global Theme definition
3ad510f
Updated documentation to reflect new theme typings
c55d448
Simplified MuiTheme import syntax in docs
7be6f64
Use previous theme declaration in docs
353dc2e
Update Button.tsx import declaration for styled
358c12d
Updated type definitions to default to any if not defined
tomsseisums 23717d4
Quick pass at removing theme generic param
36ea5ee
Fixed issue with Global
1c0d7c3
Fixed most of the test issues
tomsseisums 84bab57
Updated global Theme type declaration to module specific
tomsseisums 44adafb
Removed exports from test files
tomsseisums 2e8b12b
Use the incomplete theme prop testcase
tomsseisums bef05bd
Added note about where styled tests get their theme declaration from
tomsseisums 2025fa2
Merge branch 'next' into topics/global-theme-type
Andarist f9ff2b2
tweak docs
Andarist 4649226
Remove InterpolationWithTheme type
Andarist 94d0d1f
Move adding Theme to Styled interpolations inline (and not as part of…
Andarist c2fb7f1
Cleanup Interpolation-related types
Andarist f391e6c
Add changeset
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ | ||
--- | ||
'@emotion/core': major | ||
'@emotion/styled': major | ||
--- | ||
|
||
Reworked TypeScript definitions so it's easier to provide a type for Theme. Instead of creating custom instances (like before) you can augment builtin Theme interface like this: | ||
|
||
```ts | ||
declare module '@emotion/core' { | ||
export interface Theme { | ||
primaryColor: string | ||
secondaryColor: string | ||
} | ||
} | ||
``` |
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/serialize': minor | ||
--- | ||
|
||
Reworked Interpolation-related types. Correct types should now be provided to all flavours of emotion. |
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 |
---|---|---|
|
@@ -10,7 +10,6 @@ import { | |
FunctionInterpolation, | ||
Interpolation, | ||
Keyframes, | ||
ObjectInterpolation, | ||
SerializedStyles | ||
} from '@emotion/serialize' | ||
import { | ||
|
@@ -32,13 +31,15 @@ export { | |
EmotionCache, | ||
FunctionInterpolation, | ||
Interpolation, | ||
ObjectInterpolation, | ||
SerializedStyles | ||
} | ||
|
||
export * from './theming' | ||
export * from './helper' | ||
|
||
// tslint:disable-next-line: no-empty-interface | ||
export interface Theme {} | ||
|
||
export const ThemeContext: Context<object> | ||
export const CacheProvider: Provider<EmotionCache> | ||
export function withEmotionCache<Props, RefType = any>( | ||
|
@@ -53,26 +54,21 @@ export function css( | |
): SerializedStyles | ||
export function css(...args: Array<CSSInterpolation>): SerializedStyles | ||
|
||
export type InterpolationWithTheme<Theme> = | ||
| Interpolation | ||
| ((theme: Theme) => Interpolation) | ||
|
||
export interface GlobalProps<Theme> { | ||
styles: InterpolationWithTheme<Theme> | ||
export interface GlobalProps { | ||
styles: Interpolation<Theme> | ||
} | ||
|
||
/** | ||
* @desc | ||
* JSX generic are supported only after [email protected] | ||
*/ | ||
export function Global<Theme extends {} = any>( | ||
props: GlobalProps<Theme> | ||
): ReactElement | ||
export function Global(props: GlobalProps): ReactElement | ||
|
||
export function keyframes( | ||
template: TemplateStringsArray, | ||
...args: Array<Interpolation> | ||
...args: Array<CSSInterpolation> | ||
): Keyframes | ||
export function keyframes(...args: Array<Interpolation>): Keyframes | ||
export function keyframes(...args: Array<CSSInterpolation>): Keyframes | ||
|
||
export interface ArrayClassNamesArg extends Array<ClassNamesArg> {} | ||
export type ClassNamesArg = | ||
|
@@ -83,26 +79,24 @@ export type ClassNamesArg = | |
| { [className: string]: boolean | null | undefined } | ||
| ArrayClassNamesArg | ||
|
||
export interface ClassNamesContent<Theme> { | ||
css(template: TemplateStringsArray, ...args: Array<Interpolation>): string | ||
css(...args: Array<Interpolation>): string | ||
export interface ClassNamesContent { | ||
css(template: TemplateStringsArray, ...args: Array<CSSInterpolation>): string | ||
css(...args: Array<CSSInterpolation>): string | ||
cx(...args: Array<ClassNamesArg>): string | ||
theme: Theme | ||
} | ||
export interface ClassNamesProps<Theme> { | ||
children(content: ClassNamesContent<Theme>): ReactNode | ||
export interface ClassNamesProps { | ||
children(content: ClassNamesContent): ReactNode | ||
} | ||
/** | ||
* @desc | ||
* JSX generic are supported only after [email protected] | ||
*/ | ||
export function ClassNames<Theme extends {} = any>( | ||
props: ClassNamesProps<Theme> | ||
): ReactElement | ||
export function ClassNames(props: ClassNamesProps): ReactElement | ||
|
||
declare module 'react' { | ||
interface DOMAttributes<T> { | ||
css?: InterpolationWithTheme<any> | ||
css?: Interpolation<Theme> | ||
} | ||
} | ||
|
||
|
@@ -114,7 +108,7 @@ declare global { | |
*/ | ||
|
||
interface IntrinsicAttributes { | ||
css?: InterpolationWithTheme<any> | ||
css?: Interpolation<Theme> | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole docs on Theme usage with TS feels massively outdated now, and I feel like it should be reworded altogether.
Exposing for discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right - I feel like we can handle it in a separate PR though. Ideally, such docs would present the current solution with its tradeoffs and incorporate stuff from this #973
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not in this PR, it should definitely be a blocker for releasing v11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is crucial and I plan to get this done before v11 👍