-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript] createStyles and improved WithStyles helpers (#11609)
* Add a createStyles function * Add createStyles documentation to TypeScript guide * Add InjectedStyles helper type * Wording tweak * Use createStyles and InjectedStyles in more tests * Get rid of InjectedStyles and overload WithStyles to handle style object types * Fill out missing text in typescript guide * Put styles before props * Restore visibility setting and use createStyles to fix type error * Make test code more idiomatic * Reverse order of type union so that error messages are clearer
- Loading branch information
Showing
13 changed files
with
228 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ export { | |
Theme, | ||
withStyles, | ||
WithStyles, | ||
createStyles, | ||
withTheme, | ||
WithTheme, | ||
} from './styles'; | ||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CSSProperties, StyleRules } from './withStyles'; | ||
|
||
/** | ||
* This function doesn't really "do anything" at runtime, it's just the identity | ||
* function. Its only purpose is to defeat TypeScript's type widening when providing | ||
* style rules to `withStyles` which are a function of the `Theme`. | ||
* | ||
* @param styles a set of style mappings | ||
* @returns the same styles that were passed in | ||
*/ | ||
export default function createStyles<S extends StyleRules>(styles: S): S; |
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 @@ | ||
// @flow | ||
|
||
export default function createStyles(s: Object) { | ||
return s; | ||
} |
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,9 @@ | ||
import { assert } from 'chai'; | ||
import { createStyles } from '.'; | ||
|
||
describe('createStyles', () => { | ||
it('is the identity function', () => { | ||
const styles = {}; | ||
assert.strictEqual(createStyles(styles), styles); | ||
}); | ||
}); |
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
Oops, something went wrong.