Skip to content

Commit 8a8b5f3

Browse files
authored
Merge pull request #674 from hasparus/add-sx-prop-to-jsx-namespace
fix(@theme-ui/core) Add sx prop to jsx namespace
2 parents bdc7e80 + 7b7f889 commit 8a8b5f3

File tree

8 files changed

+192
-13
lines changed

8 files changed

+192
-13
lines changed

package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@babel/preset-typescript": "^7.8.3",
2626
"@babel/runtime": "^7.7.7",
2727
"@testing-library/react": "^9.1.3",
28+
"@types/jest": "^25.1.2",
2829
"babel-jest": "^24.9.0",
2930
"husky": ">=4.0.7",
3031
"jest": "^24.8.0",
@@ -35,12 +36,27 @@
3536
"lint-staged": "10",
3637
"microbundle": "^0.11.0",
3738
"prettier": "^1.18.2",
38-
"react-test-renderer": "^16.8.6"
39+
"react-test-renderer": "^16.8.6",
40+
"ts-jest": "^25.2.0"
3941
},
4042
"resolutions": {},
4143
"jest": {
44+
"preset": "ts-jest/presets/js-with-babel",
45+
"globals": {
46+
"ts-jest": {
47+
"tsConfig": {
48+
"module": "commonjs",
49+
"esModuleInterop": true,
50+
"resolveJsonModule": true,
51+
"jsx": "react",
52+
"strictFunctionTypes": true,
53+
"alwaysStrict": true,
54+
"noImplicitThis": true
55+
}
56+
}
57+
},
4258
"testMatch": [
43-
"**/packages/**/test/*.js"
59+
"**/packages/**/test/*.{js,ts,tsx}"
4460
],
4561
"testPathIgnorePatterns": [
4662
"/node_modules/",
@@ -55,7 +71,7 @@
5571
"html"
5672
],
5773
"collectCoverageFrom": [
58-
"packages/**/src/**/*.js",
74+
"packages/**/src/**/*.{js,ts,tsx}",
5975
"!packages/docs/**/*",
6076
"!packages/presets/**/*",
6177
"!packages/style-guide/**/*",

packages/core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"dependencies": {
2020
"@emotion/core": "^10.0.0",
2121
"@theme-ui/css": "^0.3.1",
22+
"@types/styled-system": "^5.1.6",
23+
"@types/styled-system__css": "^5.0.4",
2224
"deepmerge": "^4.2.2"
2325
},
2426
"peerDependencies": {

packages/core/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import {
33
ThemeContext as EmotionContext,
44
InterpolationWithTheme,
55
} from '@emotion/core'
6+
// @ts-ignore
67
import { css } from '@theme-ui/css'
78
import React from 'react'
89
import deepmerge from 'deepmerge'
910
import { version as __EMOTION_VERSION__ } from '@emotion/core/package.json'
1011
import { Theme } from './theme'
1112

13+
import './react-jsx'
14+
1215
export * from './theme'
1316

1417
const getCSS = props => {

packages/core/src/react-jsx.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { SxProps } from './theme'
2+
3+
declare module 'react' {
4+
// tslint:disable-next-line: no-empty-interface
5+
interface DOMAttributes<T> extends SxProps {}
6+
}
7+
8+
declare global {
9+
namespace JSX {
10+
// tslint:disable-next-line: no-empty-interface
11+
interface IntrinsicAttributes extends SxProps {}
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`JSX accepts sx prop 1`] = `
4+
.emotion-0 {
5+
margin-top: 10px;
6+
padding-left: 8px;
7+
padding-right: 8px;
8+
}
9+
10+
<div
11+
className="emotion-0"
12+
/>
13+
`;

packages/core/test/react-jsx.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** @jsx jsx */
2+
import { jsx } from '../src'
3+
import renderer from 'react-test-renderer'
4+
5+
const renderJSON = (el: React.ReactNode) => renderer.create(el).toJSON()
6+
7+
describe('JSX', () => {
8+
test('accepts sx prop', () => {
9+
expect(
10+
renderJSON(
11+
<div
12+
sx={{
13+
// TypeScript support should autocomplete keys here
14+
mt: 10,
15+
px: 2,
16+
}}
17+
/>
18+
)
19+
).toMatchSnapshot()
20+
})
21+
})

packages/core/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"compilerOptions": {
33
"resolveJsonModule": true,
44
"esModuleInterop": true,
5-
"moduleResolution": "node"
6-
}
5+
"moduleResolution": "node",
6+
"jsx": "react"
7+
},
8+
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
79
}

0 commit comments

Comments
 (0)