diff options
Diffstat (limited to 'packages/react-shared')
-rw-r--r-- | packages/react-shared/.gitignore | 4 | ||||
-rw-r--r-- | packages/react-shared/.npmignore | 5 | ||||
-rw-r--r-- | packages/react-shared/.prettierignore | 2 | ||||
-rw-r--r-- | packages/react-shared/.prettierrc | 6 | ||||
-rw-r--r-- | packages/react-shared/package.json | 32 | ||||
-rw-r--r-- | packages/react-shared/scripts/postpublish.js | 5 | ||||
-rw-r--r-- | packages/react-shared/src/ts/components/anchor_title.tsx | 87 | ||||
-rw-r--r-- | packages/react-shared/src/ts/constants.ts | 4 | ||||
-rw-r--r-- | packages/react-shared/src/ts/globals.d.ts | 0 | ||||
-rw-r--r-- | packages/react-shared/src/ts/index.ts | 6 | ||||
-rw-r--r-- | packages/react-shared/src/ts/types.ts | 9 | ||||
-rw-r--r-- | packages/react-shared/src/ts/utils.ts | 5 | ||||
-rw-r--r-- | packages/react-shared/tsconfig.json | 23 | ||||
-rw-r--r-- | packages/react-shared/tslint.json | 9 |
14 files changed, 197 insertions, 0 deletions
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<AnchorTitleProps, AnchorTitleState> { + 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 ( + <div className="relative flex" style={{ ...styles[this.props.headerSize], ...styles.headers }}> + <div className="inline-block" style={{ paddingRight: 4 }}> + {this.props.title} + </div> + <ScrollLink + to={this.props.id} + offset={headerSizeToScrollOffset[this.props.headerSize]} + duration={constants.DOCS_SCROLL_DURATION_MS} + containerId={constants.DOCS_CONTAINER_ID} + > + <i + className="zmdi zmdi-link" + onClick={utils.setUrlHash.bind(utils, this.props.id)} + style={{ ...styles.anchor, opacity }} + onMouseOver={this._setHoverState.bind(this, true)} + onMouseOut={this._setHoverState.bind(this, false)} + /> + </ScrollLink> + </div> + ); + } + 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 --- /dev/null +++ b/packages/react-shared/src/ts/globals.d.ts 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 + } +} |