-
-
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.
Added TypeScript types and tests for the emotion package.
- Loading branch information
1 parent
74cc4fa
commit 789431a
Showing
5 changed files
with
118 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "es2015", | ||
"strict": true, | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "node" | ||
}, | ||
"include": [ | ||
"./*.ts", | ||
"./*.tsx" | ||
] | ||
} |
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,51 @@ | ||
import { | ||
sheet, | ||
useStylisPlugin, | ||
injectGlobal, | ||
flush, | ||
css, | ||
fontFace, | ||
hydrate | ||
} from '../'; | ||
|
||
sheet.speedy(true); | ||
sheet.inject(); | ||
sheet.insert('.foo { font-size: 1 };', 'some source map'); | ||
sheet.flush(); | ||
|
||
useStylisPlugin(() => {})([() => {}, () => {}])(null); | ||
|
||
flush(); | ||
|
||
const cssObject = { | ||
height: 100, | ||
width: '100%', | ||
display: (true as boolean) && 'block', | ||
position: undefined, | ||
color: null, | ||
':hover': { | ||
display: 'block' | ||
} | ||
}; | ||
|
||
const className: string = css` | ||
${(true as boolean) && ''} | ||
${'bar'} | ||
${css``} | ||
${1} | ||
${cssObject} | ||
`; | ||
|
||
const className2: string = css(cssObject); | ||
|
||
fontFace` | ||
font-family: 'Foo'; | ||
`; | ||
|
||
injectGlobal` | ||
#foo { | ||
font-face: 'Foo'; | ||
} | ||
`; | ||
|
||
hydrate(['css-123', 'css-456']); |
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,47 @@ | ||
export type Interpolation = string | number | false | undefined | CSSObject; | ||
|
||
export type CreateStyles<TRet> = ((cssObject: CSSObject) => TRet) | ||
& ((strings: TemplateStringsArray, ...vars: Interpolation[]) => TRet); | ||
|
||
export interface StylisUse { | ||
// TODO: Make this more precise than just Function | ||
(plugin: Function | Function[] | null): StylisUse; | ||
} | ||
|
||
// Ideally, boolean here would just be false but it would be very inconvenient | ||
// due to the way type inference works for object values. | ||
export type CSSObject = Record<string, boolean | undefined | null | string | number | _CSSObject>; | ||
|
||
// HACK: See https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540 | ||
interface _CSSObject extends CSSObject {} | ||
|
||
export interface StyleSheet { | ||
inject(): void; | ||
speedy(bool: boolean): void; | ||
insert(rule: string, sourceMap: string): void; | ||
flush(): void; | ||
} | ||
|
||
export const sheet: StyleSheet; | ||
|
||
export const useStylisPlugin: StylisUse; | ||
|
||
export const inserted: Record<string, boolean | undefined>; | ||
|
||
export const registered: Record<string, string | undefined>; | ||
|
||
export function flush(): void; | ||
|
||
export function values(cls: string, vars: Interpolation[]): string; | ||
|
||
export const css: CreateStyles<string>; | ||
|
||
export const injectGlobal: CreateStyles<void>; | ||
|
||
export const keyframes: CreateStyles<string>; | ||
|
||
export const fontFace: CreateStyles<void>; | ||
|
||
export function getRegisteredStyles(registeredStyles: string[], classNames: string): string; | ||
|
||
export function hydrate(ids: string[]): void; |