Skip to content

Commit 1b72aef

Browse files
authored
Merge pull request #686 from joestrouth1/ts-tailwind
Convert tailwind package to TypeScript
2 parents 3e975e5 + 314f825 commit 1b72aef

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

packages/tailwind/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
"version": "0.3.0",
55
"main": "dist/index.js",
66
"module": "dist/index.esm.js",
7+
"source": "src/index.ts",
8+
"types": "dist/index.d.ts",
79
"author": "John Otander <[email protected]>",
810
"license": "MIT",
911
"scripts": {
10-
"prepare": "microbundle --no-compress",
11-
"watch": "microbundle watch --no-compress"
12+
"prepare": "microbundle --no-compress --tsconfig tsconfig.json",
13+
"watch": "microbundle watch --no-compress --tsconfig tsconfig.json"
1214
},
1315
"devDependencies": {
1416
"babel-polyfill": "^6.26.0",
1517
"execa": "^4.0.0",
16-
"tailwindcss": "^1.0.4"
18+
"tailwindcss": "^1.0.4",
19+
"@theme-ui/css": "^0.3.1"
1720
},
1821
"publishConfig": {
1922
"access": "public"

packages/tailwind/src/index.js renamed to packages/tailwind/src/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const KEY_MAPPING = {
1+
import { Theme } from '@theme-ui/css'
2+
3+
const KEY_MAPPING: {
4+
readonly [Key: string]: string | string[]
5+
} = {
26
space: 'spacing',
37
radii: 'borderRadius',
48
fonts: 'fontFamily',
@@ -12,23 +16,26 @@ const KEY_MAPPING = {
1216
zIndices: 'zIndex',
1317
}
1418

15-
export default (theme, config = {}) => {
16-
const transformedTheme = Object.entries(theme).reduce((acc, [key, value]) => {
17-
if (!KEY_MAPPING[key]) {
19+
export default (theme: Theme, config: { [Key: string]: unknown } = {}) => {
20+
const transformedTheme = Object.entries(theme).reduce<{
21+
[Key: string]: unknown
22+
}>((acc, [key, value]) => {
23+
const matchingKey = KEY_MAPPING[key]
24+
if (!matchingKey) {
1825
return {
1926
...acc,
2027
[key]: value,
2128
}
22-
} else if (Array.isArray(KEY_MAPPING[key])) {
23-
KEY_MAPPING[key].forEach(twKey => {
29+
} else if (Array.isArray(matchingKey)) {
30+
matchingKey.forEach(twKey => {
2431
acc[twKey] = value
2532
})
2633

2734
return acc
2835
} else {
2936
return {
3037
...acc,
31-
[KEY_MAPPING[key]]: value,
38+
[matchingKey]: value,
3239
}
3340
}
3441
}, {})

packages/tailwind/test/test.js renamed to packages/tailwind/test/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const theme = {
3535
size: ['10em', '20em', '30em', '40em'],
3636
}
3737

38-
const toJS = theme => `
38+
const toJS = (theme: { [Key: string]: unknown }) => `
3939
module.exports = ${JSON.stringify(theme, null, 2)}
4040
`
4141

packages/tailwind/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"resolveJsonModule": true,
4+
"esModuleInterop": true,
5+
"moduleResolution": "node",
6+
"strict": true
7+
},
8+
"exclude": ["test"]
9+
}

0 commit comments

Comments
 (0)