Skip to content

Commit

Permalink
Merge pull request #691 from joestrouth1/ts-tachyons
Browse files Browse the repository at this point in the history
Convert tachyons package to TS
  • Loading branch information
mxstbr authored Feb 19, 2020
2 parents 325e449 + e9bcd8a commit 3e975e5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"/fixtures/",
"/presets/",
"/style-guide/",
"tailwind.config.js"
"tailwind.config.js",
"/dist/"
],
"coverageReporters": [
"lcov",
Expand Down
9 changes: 6 additions & 3 deletions packages/tachyons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
"version": "0.3.0",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"author": "John Otander <johnotander@gmail.com>",
"license": "MIT",
"scripts": {
"prepare": "microbundle --no-compress",
"watch": "microbundle watch --no-compress"
"prepare": "microbundle --no-compress --tsconfig tsconfig.json",
"watch": "microbundle watch --no-compress --tsconfig tsconfig.json"
},
"devDependencies": {
"babel-polyfill": "^6.26.0",
"execa": "^4.0.0"
"execa": "^4.0.0",
"@theme-ui/css": "^0.3.1"
},
"publishConfig": {
"access": "public"
Expand Down
22 changes: 14 additions & 8 deletions packages/tachyons/src/index.js → packages/tachyons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const KEY_MAPPING = {
import { Theme } from '@theme-ui/css'

const KEY_MAPPING: {
readonly [Key: string]: string | string[]
} = {
space: 'spacing',
radii: 'borderRadius',
fonts: 'fontFamily',
borderStyles: 'borderStyle',
radii: 'borderRadius',
Expand All @@ -13,23 +16,26 @@ const KEY_MAPPING = {
zIndices: 'zIndex',
}

export default theme => {
const transformedTheme = Object.entries(theme).reduce((acc, [key, value]) => {
if (!KEY_MAPPING[key]) {
export default (theme: Theme) => {
const transformedTheme = Object.entries(theme).reduce<{
[Key: string]: unknown
}>((acc, [key, value]) => {
const matchingKey = KEY_MAPPING[key]
if (!matchingKey) {
return {
...acc,
[key]: value,
}
} else if (Array.isArray(KEY_MAPPING[key])) {
KEY_MAPPING[key].forEach(tachyonsKey => {
} else if (Array.isArray(matchingKey)) {
matchingKey.forEach(tachyonsKey => {
acc[tachyonsKey] = value
})

return acc
} else {
return {
...acc,
[KEY_MAPPING[key]]: value,
[matchingKey]: value,
}
}
}, {})
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions packages/tachyons/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
"moduleResolution": "node",
"strict": true
}
}
7 changes: 7 additions & 0 deletions packages/tachyons/types/tachyons-generator/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module 'tachyons-generator' {
export default function(config: {
[TachyonsKey: string]: unknown
}): {
generate(): Promise<{ css: string }>
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3524,7 +3524,7 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

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

0 comments on commit 3e975e5

Please sign in to comment.