Skip to content

Commit 3e975e5

Browse files
authored
Merge pull request #691 from joestrouth1/ts-tachyons
Convert tachyons package to TS
2 parents 325e449 + e9bcd8a commit 3e975e5

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"/fixtures/",
6464
"/presets/",
6565
"/style-guide/",
66-
"tailwind.config.js"
66+
"tailwind.config.js",
67+
"/dist/"
6768
],
6869
"coverageReporters": [
6970
"lcov",

packages/tachyons/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
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",
15-
"execa": "^4.0.0"
17+
"execa": "^4.0.0",
18+
"@theme-ui/css": "^0.3.1"
1619
},
1720
"publishConfig": {
1821
"access": "public"

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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',
3-
radii: 'borderRadius',
47
fonts: 'fontFamily',
58
borderStyles: 'borderStyle',
69
radii: 'borderRadius',
@@ -13,23 +16,26 @@ const KEY_MAPPING = {
1316
zIndices: 'zIndex',
1417
}
1518

16-
export default theme => {
17-
const transformedTheme = Object.entries(theme).reduce((acc, [key, value]) => {
18-
if (!KEY_MAPPING[key]) {
19+
export default (theme: Theme) => {
20+
const transformedTheme = Object.entries(theme).reduce<{
21+
[Key: string]: unknown
22+
}>((acc, [key, value]) => {
23+
const matchingKey = KEY_MAPPING[key]
24+
if (!matchingKey) {
1925
return {
2026
...acc,
2127
[key]: value,
2228
}
23-
} else if (Array.isArray(KEY_MAPPING[key])) {
24-
KEY_MAPPING[key].forEach(tachyonsKey => {
29+
} else if (Array.isArray(matchingKey)) {
30+
matchingKey.forEach(tachyonsKey => {
2531
acc[tachyonsKey] = value
2632
})
2733

2834
return acc
2935
} else {
3036
return {
3137
...acc,
32-
[KEY_MAPPING[key]]: value,
38+
[matchingKey]: value,
3339
}
3440
}
3541
}, {})
File renamed without changes.

packages/tachyons/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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'tachyons-generator' {
2+
export default function(config: {
3+
[TachyonsKey: string]: unknown
4+
}): {
5+
generate(): Promise<{ css: string }>
6+
}
7+
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3524,7 +3524,7 @@
35243524
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
35253525
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
35263526

3527-
3527+
"@types/pluralize@^0.0.29":
35283528
version "0.0.29"
35293529
resolved "https://registry.yarnpkg.com/@types/pluralize/-/pluralize-0.0.29.tgz#6ffa33ed1fc8813c469b859681d09707eb40d03c"
35303530
integrity sha512-BYOID+l2Aco2nBik+iYS4SZX0Lf20KPILP5RGmM1IgzdwNdTs0eebiFriOPcej1sX9mLnSoiNte5zcFxssgpGA==

0 commit comments

Comments
 (0)