Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
start refactor core functions to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tol-is committed Mar 9, 2020
1 parent d88ea86 commit 3342434
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 132 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"scripts": {
"postinstall": "lerna bootstrap",
"lern": "lerna run watch --stream",
"start": "npm-run-all --parallel core:dev tailwind:plugin example:tlwd ",
"core": "lerna exec --scope @styled-rhythm/core -- yarn develop",
"start": "npm-run-all --parallel core tailwind:plugin example:tlwd ",
"test": "jest --watch --onlyChanged --watchman --forceExit --detectOpenHandles --notify --notifyMode=failure",
"docs": "lerna exec --scope @styled-rhythm/docs -- yarn start",
"tailwind:plugin": "lerna exec --scope @styled-rhythm/tailwindcss -- yarn start",
Expand Down
25 changes: 20 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@
"author": "Apostolos Christodoulou <[email protected]>",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.es.js",
"files": [
"dist"
],
"types": "dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"tdd": "jest --watchAll --watchman --forceExit --detectOpenHandles --notify --notifyMode=failure",
"start": "node ../../scripts/parcel-start.js",
"build": "node ../../scripts/parcel-build.js"
"build": "rollup -c",
"develop": "rollup -cw"
},
"devDependencies": {
"parcel": "^1.12.4",
"parcel-bundler": "^1.12.4"
"@babel/core": "^7.6.0",
"@types/node": "^12.0.10",
"babel-loader": "8.0.6",
"rollup": "^1.19.4",
"rollup-plugin-typescript2": "^0.24.0",
"rollup-plugin-url": "^2.2.2",
"typescript": "3.6.2"
},
"dependencies": {
"csstype": "^2.6.9"
}
}
4 changes: 4 additions & 0 deletions packages/core/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createRollupConfig } from '../rollup.base';
import pkg from './package.json';

export default createRollupConfig(pkg);
34 changes: 0 additions & 34 deletions packages/core/src/columns.js

This file was deleted.

39 changes: 39 additions & 0 deletions packages/core/src/columns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as CSS from 'csstype';

interface Style extends CSS.Properties {
[key: string]: any;
}
export const columns = ({ count }: { count: Number }): Style => {
return {
display: 'grid',
gridTemplateColumns: `repeat(${count}, minmax(0,1fr))`,
[`& > * `]: {
gridColumn: 'span 1',
},
};
};

export const column = ({ start, span }: { start: Number; span: Number }): Style => {
return {
gridColumn: `${start} / span ${span}`,
};
};

export const gap = ({ space }: { space: string }): Style => {
return {
gridRowGap: space,
gridColumnGap: space,
};
};

export const gapX = ({ space }: { space: string }): Style => {
return {
gridColumnGap: space,
};
};

export const gapY = ({ space }: { space: string }): Style => {
return {
gridRowGap: space,
};
};
31 changes: 0 additions & 31 deletions packages/core/src/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './measure';
export * from './rhythm';
export * from './columns';

export * from './style-baseline-rel';
17 changes: 0 additions & 17 deletions packages/core/src/measure.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/core/src/measure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Properties } from 'csstype';

export const measure = ({ length }: { length: Number }): Properties => {
return {
maxWidth: `${length}ch`,
};
};

export const measureMin = ({ length }: { length: Number }): Properties => {
return {
minWidth: `${length}ch`,
};
};

export const measureMax = ({ length }: { length: Number }): Properties => {
return {
maxWidth: `${length}ch`,
};
};
23 changes: 0 additions & 23 deletions packages/core/src/rhythm.js

This file was deleted.

29 changes: 29 additions & 0 deletions packages/core/src/rhythm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as CSS from 'csstype';

interface Style extends CSS.Properties {
[key: string]: any;
}

export const rhythm = ({ space }: { space: string }): Style => {
return {
[`& > * + * `]: {
marginTop: space,
},
};
};

export const rhythmY = ({ space }: { space: string }): Style => {
return {
[`& > * + * `]: {
marginTop: space,
},
};
};

export const rhythmX = ({ space }: { space: string }): Style => {
return {
[`& > * + * `]: {
marginLeft: space,
},
};
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
import * as CSS from 'csstype';

interface IFont {
upm: number;
capHeight: number;
ascent: number;
descent: number;
weight: CSS.FontWeightProperty;
italic: boolean;
familyName: CSS.FontFamilyProperty;
fallback: CSS.FontFamilyProperty;
}

interface ITypeStyleBaselineParams {
font: IFont;
baseline: number;
root: number;
fontSize: number;
leading: number;
}

type TypeStyleBaseline = {
fontFamily: CSS.FontFamilyProperty;
fontWeight: CSS.FontWeightProperty;
fontStyle: CSS.FontStyleProperty;
display: CSS.DisplayProperty;
fontSize: CSS.FontSizeProperty<string>;
lineHeight: CSS.LineHeightProperty<string | number>;
transform: CSS.TransformProperty;
paddingTop: CSS.PaddingTopProperty<string>;
'&:before': {
content: string;
marginTop: CSS.MarginProperty<string>;
display: CSS.DisplayProperty;
height: CSS.HeightProperty<string | number>;
};
};

/**
*
*
*/
const styleBaseline = ({ font, baseline, root, fontSize, leading = 0 }) => {
export const styleBaselineRel = (params: ITypeStyleBaselineParams): TypeStyleBaseline => {
//
const { font, baseline, root, fontSize, leading = 0 } = params;
//
const preventCollapse = 1;

Expand Down Expand Up @@ -53,5 +93,3 @@ const styleBaseline = ({ font, baseline, root, fontSize, leading = 0 }) => {
},
};
};

module.exports = styleBaseline;
8 changes: 8 additions & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./"
},
"include": ["src/**/*"]
}
Empty file added packages/core/types.d.ts
Empty file.
25 changes: 25 additions & 0 deletions packages/rollup.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import typescript from 'rollup-plugin-typescript2';
import url from 'rollup-plugin-url';

export const createRollupConfig = pkg => ({
input: ['src/index.ts'],
output: [
{
file: pkg.main,
format: 'cjs',
exports: 'named',
},
{
file: pkg.module,
format: 'es',
exports: 'named',
},
],
external: [...Object.keys(pkg.peerDependencies || {})],
plugins: [
typescript({
clean: true,
typescript: require('typescript'),
}),
],
});
4 changes: 4 additions & 0 deletions packages/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const __DEV__: boolean;
declare const __PROD__: boolean;
declare const __BROWSER__: boolean;
declare const __SERVER__: boolean;
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"files": [], // do not remove!
"extends": "./tsconfig.settings.json"
}
24 changes: 24 additions & 0 deletions tsconfig.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"outDir": "./dist",
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": false,
"target": "es5",
"baseUrl": "./",
"noErrorTruncation": true,
"lib": ["es6", "dom"]
},
"module": "commonjs",
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["tslint:latest", "tslint-react"],
"rules": {
"quotemark": [true, "single"],
"no-submodule-imports": false,
"object-literal-sort-keys": false,
"jsx-no-multiline-js": false
}
}
Loading

0 comments on commit 3342434

Please sign in to comment.