-
-
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.
- Loading branch information
Showing
6 changed files
with
253 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun> | ||
// TypeScript Version: 2.3 | ||
|
||
import * as CSS from 'csstype'; | ||
|
||
export interface MultiDimensionalArray<T> extends Array<T | MultiDimensionalArray<T>> {} | ||
|
||
export type CSSBaseObject = CSS.PropertiesFallback<number | string>; | ||
export type CSSPseudoObject<C> = { [K in CSS.Pseudos]?: CSSObject<C> }; | ||
export interface CSSOthersObject<C> { | ||
[propertiesName: string]: Interpolation<C>; | ||
} | ||
export interface CSSObject<C> extends CSSBaseObject, CSSPseudoObject<C>, CSSOthersObject<C> {} | ||
|
||
export type FunctionInterpolation<C> = (mergedProps: any, context: C) => Interpolation<C> | void; | ||
|
||
export interface ArrayInterpolation<C> extends Array<Interpolation<C>> {} | ||
|
||
export type Interpolation<C> = | ||
| undefined | null | boolean | string | number | ||
| CSSObject<C> | ||
| ArrayInterpolation<C> | ||
| FunctionInterpolation<C> | ||
; | ||
|
||
export type FunctionClassNameArg = () => ClassNameArg | void; | ||
export interface ArrayClassNameArg extends Array<ClassNameArg> {} | ||
|
||
export type ClassNameArg = | ||
| undefined | null | boolean | string | ||
| { [key: string]: boolean } | ||
| FunctionClassNameArg | ||
| ArrayClassNameArg | ||
; | ||
|
||
export interface StyleSheet { | ||
inject(): void; | ||
speedy(bool: boolean): void; | ||
insert(rule: string, sourceMap?: string): void; | ||
flush(): void; | ||
} | ||
|
||
export interface EmotionCache { | ||
registered: { | ||
[key: string]: string; | ||
}; | ||
inserted: { | ||
[key: string]: string; | ||
}; | ||
nonce?: string; | ||
key: string; | ||
} | ||
|
||
export interface Emotion<C> { | ||
flush(): void; | ||
hydrate(ids: Array<string>): void; | ||
cx(...classNames: Array<ClassNameArg>): string; | ||
merge(className: string, sourceMap?: string): string; | ||
getRegisteredStyles(registeredStyles: Array<string>, classNames: string): string; | ||
css(...args: Array<Interpolation<C>>): string; | ||
injectGlobal(...args: Array<Interpolation<C>>): void; | ||
keyframes(...args: Array<Interpolation<C>>): string; | ||
sheet: StyleSheet; | ||
caches: EmotionCache; | ||
} | ||
|
||
export interface EmotionBaseContext<C> { | ||
__SECRET_EMOTION__?: Emotion<C>; | ||
} | ||
|
||
export type StylisPlugins = | ||
| null | ||
| ((...args: Array<any>) => any) | ||
| Array<(...args: Array<any>) => any> | ||
; | ||
|
||
export interface EmotionOption { | ||
nonce?: string; | ||
stylisPlugins?: StylisPlugins; | ||
prefix?: boolean | ((key: string, value: string, context: 1 | 2 | 3) => boolean); | ||
key?: string; | ||
container?: HTMLElement; | ||
} | ||
|
||
export default function createEmotion<C extends EmotionBaseContext<C>>(context: C, options?: EmotionOption): Emotion<C>; |
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,127 @@ | ||
import createEmotion from '../'; | ||
|
||
const { | ||
flush, | ||
hydrate, | ||
cx, | ||
merge, | ||
getRegisteredStyles, | ||
css, | ||
injectGlobal, | ||
keyframes, | ||
sheet, | ||
caches, | ||
} = createEmotion({}); | ||
|
||
flush(); | ||
|
||
hydrate([]); | ||
hydrate(['123']); | ||
|
||
cx(); | ||
cx(undefined); | ||
cx(null); | ||
cx(true); | ||
cx('123'); | ||
cx('123', null, 'pf'); | ||
cx({ | ||
abc: false, | ||
fp: true, | ||
}); | ||
cx([]); | ||
cx(['cl', { | ||
fp: true, | ||
}]); | ||
|
||
merge('abc def fpfp'); | ||
|
||
getRegisteredStyles([], 'abc'); | ||
getRegisteredStyles(['abc'], 'bcd'); | ||
getRegisteredStyles([], 'abc def fpfw'); | ||
|
||
css(); | ||
css(1); | ||
css('abc'); | ||
css(true); | ||
|
||
css([]); | ||
css([1]); | ||
css([['abc', 'asdf'], 'efw']); | ||
|
||
css(() => { | ||
return 1; | ||
}); | ||
css((a: number, b: {}) => { | ||
return 1; | ||
}); | ||
|
||
css({ | ||
':active': { | ||
borderRadius: '2px', | ||
overflowAnchor: 'none', | ||
clear: ['both', 'left'], | ||
}, | ||
'::before': { | ||
borderRadius: '2px', | ||
}, | ||
}); | ||
|
||
css(true, true); | ||
css('fa', 1123); | ||
css(['123'], 'asdf'); | ||
css('fa', () => { | ||
}); | ||
css('pa--emp', () => { | ||
return null; | ||
}); | ||
css('squid', () => { | ||
return ['other-squid', { | ||
alignSelf: 'middle', | ||
}]; | ||
}); | ||
|
||
injectGlobal(); | ||
injectGlobal(30); | ||
injectGlobal('this-is-class'); | ||
injectGlobal({}); | ||
injectGlobal([{ | ||
animationDelay: '200ms', | ||
}]); | ||
|
||
keyframes(); | ||
keyframes({ | ||
from: { | ||
marginLeft: '100%', | ||
}, | ||
to: { | ||
marginLeft: '50%', | ||
}, | ||
}); | ||
keyframes([{ | ||
from: { | ||
marginLeft: '100%', | ||
}, | ||
to: { | ||
marginLeft: '50%', | ||
}, | ||
}, { | ||
'0%': { | ||
width: '100px', | ||
}, | ||
'50%': { | ||
width: '50px', | ||
}, | ||
'100%': { | ||
width: '120px', | ||
}, | ||
}]); | ||
|
||
sheet.flush(); | ||
sheet.inject(); | ||
sheet.insert(''); | ||
sheet.speedy(false); | ||
|
||
caches.inserted; | ||
caches.key; | ||
caches.nonce; | ||
caches.registered; |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "../", | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"target": "es5", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [] | ||
}, | ||
"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,7 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"no-relative-import-in-test": false, | ||
"array-type": [true, "generic"] | ||
} | ||
} |
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