Skip to content

Commit 6c28455

Browse files
author
Joe Strouth
committed
Convert tailwind package to TypeScript
1 parent 11a3024 commit 6c28455

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

packages/tailwind/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
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",
@@ -27,5 +29,8 @@
2729
"style"
2830
],
2931
"repository": "system-ui/theme-ui",
30-
"gitHead": "5681b24d36f81fddd0d1d82cbb85136cc15dcd4c"
32+
"gitHead": "5681b24d36f81fddd0d1d82cbb85136cc15dcd4c",
33+
"dependencies": {
34+
"@theme-ui/core": "^0.3.1"
35+
}
3136
}

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/core'
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/tsconfig.json

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

0 commit comments

Comments
 (0)