From b7d001da88ab604762ddf9df8abcf956d4c2de7f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sat, 3 Mar 2018 19:58:30 +0100 Subject: Setup initial react-shared sub-package --- packages/react-shared/.gitignore | 4 + packages/react-shared/.npmignore | 5 ++ packages/react-shared/.prettierignore | 2 + packages/react-shared/.prettierrc | 6 ++ packages/react-shared/package.json | 32 ++++++++ packages/react-shared/scripts/postpublish.js | 5 ++ .../src/ts/components/anchor_title.tsx | 87 ++++++++++++++++++++++ packages/react-shared/src/ts/constants.ts | 4 + packages/react-shared/src/ts/globals.d.ts | 0 packages/react-shared/src/ts/index.ts | 6 ++ packages/react-shared/src/ts/types.ts | 9 +++ packages/react-shared/src/ts/utils.ts | 5 ++ packages/react-shared/tsconfig.json | 23 ++++++ packages/react-shared/tslint.json | 9 +++ 14 files changed, 197 insertions(+) create mode 100644 packages/react-shared/.gitignore create mode 100644 packages/react-shared/.npmignore create mode 100644 packages/react-shared/.prettierignore create mode 100644 packages/react-shared/.prettierrc create mode 100644 packages/react-shared/package.json create mode 100644 packages/react-shared/scripts/postpublish.js create mode 100644 packages/react-shared/src/ts/components/anchor_title.tsx create mode 100644 packages/react-shared/src/ts/constants.ts create mode 100644 packages/react-shared/src/ts/globals.d.ts create mode 100644 packages/react-shared/src/ts/index.ts create mode 100644 packages/react-shared/src/ts/types.ts create mode 100644 packages/react-shared/src/ts/utils.ts create mode 100644 packages/react-shared/tsconfig.json create mode 100644 packages/react-shared/tslint.json (limited to 'packages') diff --git a/packages/react-shared/.gitignore b/packages/react-shared/.gitignore new file mode 100644 index 000000000..380bff9bb --- /dev/null +++ b/packages/react-shared/.gitignore @@ -0,0 +1,4 @@ +node_modules +yarn.error +lib +src/public/bundle* diff --git a/packages/react-shared/.npmignore b/packages/react-shared/.npmignore new file mode 100644 index 000000000..87bc30436 --- /dev/null +++ b/packages/react-shared/.npmignore @@ -0,0 +1,5 @@ +.* +yarn-error.log +/src/ +/scripts/ +tsconfig.json diff --git a/packages/react-shared/.prettierignore b/packages/react-shared/.prettierignore new file mode 100644 index 000000000..7349ffb70 --- /dev/null +++ b/packages/react-shared/.prettierignore @@ -0,0 +1,2 @@ +lib +package.json diff --git a/packages/react-shared/.prettierrc b/packages/react-shared/.prettierrc new file mode 100644 index 000000000..58a17fac2 --- /dev/null +++ b/packages/react-shared/.prettierrc @@ -0,0 +1,6 @@ +{ + "tabWidth": 4, + "printWidth": 120, + "trailingComma": all, + "singleQuote": true +} diff --git a/packages/react-shared/package.json b/packages/react-shared/package.json new file mode 100644 index 000000000..69d298559 --- /dev/null +++ b/packages/react-shared/package.json @@ -0,0 +1,32 @@ +{ + "name": "@0xproject/react-shared", + "version": "0.0.1", + "description": "0x shared react components", + "main": "lib/index.js", + "scripts": { + "lint": "tslint --project . 'src/ts/**/*.ts' 'src/ts/**/*.tsx'", + "build": "tsc" + }, + "author": "Fabio Berger", + "license": "MIT", + "devDependencies": { + "@0xproject/tslint-config": "^0.4.9", + "@types/lodash": "^4.14.86", + "@types/node": "^8.0.53", + "@types/material-ui": "0.18.0", + "@types/react": "^15.0.15", + "@types/react-dom": "^0.14.23", + "shx": "^0.2.2", + "tslint": "^5.9.1", + "typescript": "2.7.1" + }, + "dependencies": { + "basscss": "^8.0.3", + "material-ui": "^0.17.1", + "react": "15.6.1", + "react-dom": "15.6.1", + "lodash": "^4.17.4", + "react-scroll": "^1.5.2", + "react-tap-event-plugin": "^2.0.1" + } +} diff --git a/packages/react-shared/scripts/postpublish.js b/packages/react-shared/scripts/postpublish.js new file mode 100644 index 000000000..639656c7e --- /dev/null +++ b/packages/react-shared/scripts/postpublish.js @@ -0,0 +1,5 @@ +const postpublish_utils = require('../../../scripts/postpublish_utils'); +const packageJSON = require('../package.json'); + +const subPackageName = packageJSON.name; +postpublish_utils.standardPostPublishAsync(subPackageName); diff --git a/packages/react-shared/src/ts/components/anchor_title.tsx b/packages/react-shared/src/ts/components/anchor_title.tsx new file mode 100644 index 000000000..9b8e6854f --- /dev/null +++ b/packages/react-shared/src/ts/components/anchor_title.tsx @@ -0,0 +1,87 @@ +import * as React from 'react'; +import { Link as ScrollLink } from 'react-scroll'; + +import { constants } from '../constants'; +import { HeaderSizes, Styles } from '../types'; +import { utils } from '../utils'; + +const headerSizeToScrollOffset: { [headerSize: string]: number } = { + h2: -20, + h3: 0, +}; + +interface AnchorTitleProps { + title: string | React.ReactNode; + id: string; + headerSize: HeaderSizes; + shouldShowAnchor: boolean; +} + +interface AnchorTitleState { + isHovering: boolean; +} + +const styles: Styles = { + anchor: { + fontSize: 20, + transform: 'rotate(45deg)', + cursor: 'pointer', + }, + headers: { + WebkitMarginStart: 0, + WebkitMarginEnd: 0, + fontWeight: 'bold', + display: 'block', + }, + h1: { + fontSize: '1.8em', + }, + h2: { + fontSize: '1.5em', + fontWeight: 400, + }, + h3: { + fontSize: '1.17em', + }, +}; + +export class AnchorTitle extends React.Component { + constructor(props: AnchorTitleProps) { + super(props); + this.state = { + isHovering: false, + }; + } + public render() { + let opacity = 0; + if (this.props.shouldShowAnchor) { + opacity = this.state.isHovering ? 0.6 : 1; + } + return ( +
+
+ {this.props.title} +
+ + + +
+ ); + } + private _setHoverState(isHovering: boolean) { + this.setState({ + isHovering, + }); + } +} diff --git a/packages/react-shared/src/ts/constants.ts b/packages/react-shared/src/ts/constants.ts new file mode 100644 index 000000000..20d0c6e92 --- /dev/null +++ b/packages/react-shared/src/ts/constants.ts @@ -0,0 +1,4 @@ +export const constants = { + DOCS_SCROLL_DURATION_MS: 0, + DOCS_CONTAINER_ID: 'documentation', +}; diff --git a/packages/react-shared/src/ts/globals.d.ts b/packages/react-shared/src/ts/globals.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/react-shared/src/ts/index.ts b/packages/react-shared/src/ts/index.ts new file mode 100644 index 000000000..d33638e62 --- /dev/null +++ b/packages/react-shared/src/ts/index.ts @@ -0,0 +1,6 @@ +export { AnchorTitle } from './components/anchor_title'; + +export { HeaderSizes, Styles } from './types'; + +export { utils } from './utils'; +export { constants } from './constants'; diff --git a/packages/react-shared/src/ts/types.ts b/packages/react-shared/src/ts/types.ts new file mode 100644 index 000000000..e4fe7bff9 --- /dev/null +++ b/packages/react-shared/src/ts/types.ts @@ -0,0 +1,9 @@ +export interface Styles { + [name: string]: React.CSSProperties; +} + +export enum HeaderSizes { + H1 = 'h1', + H2 = 'h2', + H3 = 'h3', +} diff --git a/packages/react-shared/src/ts/utils.ts b/packages/react-shared/src/ts/utils.ts new file mode 100644 index 000000000..822b67496 --- /dev/null +++ b/packages/react-shared/src/ts/utils.ts @@ -0,0 +1,5 @@ +export const utils = { + setUrlHash(anchorId: string) { + window.location.hash = anchorId; + }, +}; diff --git a/packages/react-shared/tsconfig.json b/packages/react-shared/tsconfig.json new file mode 100644 index 000000000..69e8cdc20 --- /dev/null +++ b/packages/react-shared/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "lib": ["es2017", "dom"], + "sourceMap": true, + "noImplicitReturns": true, + "allowSyntheticDefaultImports": true, + "outDir": "./lib/", + "jsx": "react", + "baseUrl": "./", + "allowJs": true, + "strictNullChecks": false, + "noImplicitThis": false, + "declaration": false, + "paths": { + "*": ["node_modules/@types/*", "*"] + }, + "pretty": true, + "strict": true + }, + "include": ["./src/ts/**/*"] +} diff --git a/packages/react-shared/tslint.json b/packages/react-shared/tslint.json new file mode 100644 index 000000000..d6a5f5031 --- /dev/null +++ b/packages/react-shared/tslint.json @@ -0,0 +1,9 @@ +{ + "extends": ["@0xproject/tslint-config"], + "rules": { + "no-implicit-dependencies": false, + "no-object-literal-type-assertion": false, + "completed-docs": false, + "prefer-function-over-method": false + } +} -- cgit v1.2.3