Skip to content

Commit 0f02d19

Browse files
authored
Merge branch 'master' into master
2 parents 9232090 + f70f205 commit 0f02d19

File tree

4 files changed

+97
-74
lines changed

4 files changed

+97
-74
lines changed

packages/emotion/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"babel-cli": "^6.24.1",
2828
"babel-plugin-transform-define": "^1.3.0",
2929
"cross-env": "^5.0.5",
30-
"dtslint": "^0.2.0",
30+
"dtslint": "^0.3.0",
3131
"npm-run-all": "^4.0.2",
3232
"rimraf": "^2.6.1",
3333
"rollup": "^0.51.3"

packages/emotion/types/index.d.ts

+17-42
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,20 @@
1-
// TypeScript Version: 2.2
2-
export type Interpolation = string | number | boolean | null | undefined | _Interpolation1 | _Interpolation2 | (() => Interpolation);
3-
4-
// HACK: See https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
5-
export interface _Interpolation1 extends Record<string, Interpolation> {}
6-
export interface _Interpolation2 extends Array<Interpolation> {}
7-
8-
export type CreateStyles<TRet> = ((...values: Interpolation[]) => TRet)
9-
& ((strings: TemplateStringsArray, ...vars: Interpolation[]) => TRet);
10-
11-
// TODO: Make this more precise than just Function
12-
// tslint:disable-next-line:ban-types
13-
export type StylisUse = (plugin: Function | Function[] | null) => StylisUse;
14-
15-
export interface StyleSheet {
16-
inject(): void;
17-
speedy(bool: boolean): void;
18-
insert(rule: string, sourceMap: string): void;
19-
flush(): void;
20-
}
21-
22-
export const sheet: StyleSheet;
23-
24-
export const useStylisPlugin: StylisUse;
25-
26-
export const inserted: Record<string, boolean | undefined>;
27-
28-
export const registered: Record<string, string | undefined>;
29-
30-
export function flush(): void;
31-
32-
export const css: CreateStyles<string>;
33-
34-
export const injectGlobal: CreateStyles<void>;
35-
36-
export const keyframes: CreateStyles<string>;
37-
38-
export function getRegisteredStyles(registeredStyles: string[], classNames: string): string;
39-
40-
export function cx(...interpolations: Interpolation[]): string;
41-
42-
export function hydrate(ids: string[]): void;
1+
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
2+
// TypeScript Version: 2.3
3+
4+
import { Emotion, Interpolation } from 'create-emotion';
5+
6+
export { Interpolation };
7+
8+
export const flush: Emotion['flush'];
9+
export const hydrate: Emotion['hydrate'];
10+
export const cx: Emotion['cx'];
11+
export const merge: Emotion['merge'];
12+
export const getRegisteredStyles: Emotion['getRegisteredStyles'];
13+
export const css: Emotion['css'];
14+
export const injectGlobal: Emotion['injectGlobal'];
15+
export const keyframes: Emotion['keyframes'];
16+
export const sheet: Emotion['sheet'];
17+
export const caches: Emotion['caches'];
4318

4419
declare module 'react' {
4520
interface HTMLAttributes<T> {

packages/emotion/types/tests.tsx

+63-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
import {
2-
sheet,
3-
useStylisPlugin,
4-
injectGlobal,
52
flush,
6-
css,
73
hydrate,
8-
cx
4+
cx,
5+
merge,
6+
getRegisteredStyles,
7+
css,
8+
injectGlobal,
9+
keyframes,
10+
sheet,
11+
caches,
912
} from '../';
1013
// tslint:disable-next-line:no-implicit-dependencies
1114
import React from 'react';
1215

13-
sheet.speedy(true);
14-
sheet.inject();
15-
sheet.insert('.foo { font-size: 1 };', 'some source map');
16-
sheet.flush();
17-
18-
useStylisPlugin(() => {})([() => {}, () => {}])(null);
19-
2016
flush();
2117

18+
hydrate(['css-123', 'css-456']);
19+
2220
const cssObject = {
2321
height: 100,
2422
width: '100%',
25-
display: (true as boolean) && 'block',
23+
display: 'block',
2624
position: undefined,
27-
color: null,
2825
':hover': {
2926
display: 'block'
3027
}
@@ -40,22 +37,18 @@ const className: string = css`
4037

4138
const className2: string = css(cssObject);
4239

43-
css(() => ({
44-
height: 100
45-
}));
46-
4740
css([
4841
{ display: 'none' },
4942
[
50-
{ position: false },
43+
{ position: 'relative' },
5144
{ width: 100 }
5245
]
5346
]);
5447

5548
css(
5649
{ display: 'none' },
5750
[
58-
{ position: false },
51+
{ position: 'relative' },
5952
{ width: 100 }
6053
]
6154
);
@@ -68,12 +61,58 @@ injectGlobal`
6861
}
6962
`;
7063

71-
const cxResult: string = cx(() => () => [
72-
() => [className, false && className2, 'modal'],
73-
() => [() => [className, () => ({ [className2]: true }), 'profile']]
64+
injectGlobal({
65+
html: {
66+
width: '100vw',
67+
height: '100vh',
68+
},
69+
'#root': {
70+
fontWeight: 'bold',
71+
},
72+
});
73+
74+
keyframes({
75+
'0%': {
76+
transform: 'scaleY(0.5)',
77+
},
78+
to: {
79+
transform: 'scaleY(1)',
80+
},
81+
});
82+
83+
keyframes`
84+
0% {
85+
transform: translateX(100%);
86+
}
87+
40% {
88+
transform: translateX(50%);
89+
}
90+
60% {
91+
transform: translateX(30%);
92+
}
93+
100% {
94+
transform: translateX(100%);
95+
}
96+
`;
97+
98+
const cxResult: string = cx([
99+
[className, false && className2, 'modal'],
100+
[[className, { [className2]: true }, 'profile']]
74101
]);
75102

76-
hydrate(['css-123', 'css-456']);
103+
merge(`class1 class2 ${className}`);
104+
105+
getRegisteredStyles([], className);
106+
107+
sheet.speedy(true);
108+
sheet.inject();
109+
sheet.insert('.foo { font-size: 1 };', 'some source map');
110+
sheet.flush();
111+
112+
caches.inserted;
113+
caches.key;
114+
caches.nonce;
115+
caches.registered;
77116

78117
/*
79118
* Can use css prop, transpiled by babel plugin

packages/emotion/types/tsconfig.json

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"module": "es2015",
5-
"strict": true,
63
"allowSyntheticDefaultImports": true,
7-
"moduleResolution": "node",
4+
"baseUrl": "../",
5+
"forceConsistentCasingInFileNames": true,
86
"jsx": "react",
9-
"lib": ["es6"],
7+
"lib": [
8+
"es6",
9+
"dom"
10+
],
11+
"module": "commonjs",
12+
"noEmit": true,
1013
"noImplicitAny": true,
1114
"noImplicitThis": true,
15+
"strict": true,
1216
"strictNullChecks": true,
13-
"strictFunctionTypes": true
17+
"strictFunctionTypes": true,
18+
"target": "es5",
19+
"typeRoots": [
20+
"../"
21+
],
22+
"types": []
1423
},
1524
"include": [
1625
"./*.ts",
1726
"./*.tsx"
1827
]
19-
}
28+
}

0 commit comments

Comments
 (0)