Setup initial react-shared sub-package
This commit is contained in:
		
							
								
								
									
										4
									
								
								packages/react-shared/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								packages/react-shared/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
node_modules
 | 
			
		||||
yarn.error
 | 
			
		||||
lib
 | 
			
		||||
src/public/bundle*
 | 
			
		||||
							
								
								
									
										5
									
								
								packages/react-shared/.npmignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								packages/react-shared/.npmignore
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
.*
 | 
			
		||||
yarn-error.log
 | 
			
		||||
/src/
 | 
			
		||||
/scripts/
 | 
			
		||||
tsconfig.json
 | 
			
		||||
							
								
								
									
										2
									
								
								packages/react-shared/.prettierignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								packages/react-shared/.prettierignore
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
lib
 | 
			
		||||
package.json
 | 
			
		||||
							
								
								
									
										6
									
								
								packages/react-shared/.prettierrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								packages/react-shared/.prettierrc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "tabWidth": 4,
 | 
			
		||||
    "printWidth": 120,
 | 
			
		||||
    "trailingComma": all,
 | 
			
		||||
    "singleQuote": true
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								packages/react-shared/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								packages/react-shared/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -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"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								packages/react-shared/scripts/postpublish.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								packages/react-shared/scripts/postpublish.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
const postpublish_utils = require('../../../scripts/postpublish_utils');
 | 
			
		||||
const packageJSON = require('../package.json');
 | 
			
		||||
 | 
			
		||||
const subPackageName = packageJSON.name;
 | 
			
		||||
postpublish_utils.standardPostPublishAsync(subPackageName);
 | 
			
		||||
							
								
								
									
										87
									
								
								packages/react-shared/src/ts/components/anchor_title.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								packages/react-shared/src/ts/components/anchor_title.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -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,
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										4
									
								
								packages/react-shared/src/ts/constants.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								packages/react-shared/src/ts/constants.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
export const constants = {
 | 
			
		||||
    DOCS_SCROLL_DURATION_MS: 0,
 | 
			
		||||
    DOCS_CONTAINER_ID: 'documentation',
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										0
									
								
								packages/react-shared/src/ts/globals.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								packages/react-shared/src/ts/globals.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										6
									
								
								packages/react-shared/src/ts/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								packages/react-shared/src/ts/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
export { AnchorTitle } from './components/anchor_title';
 | 
			
		||||
 | 
			
		||||
export { HeaderSizes, Styles } from './types';
 | 
			
		||||
 | 
			
		||||
export { utils } from './utils';
 | 
			
		||||
export { constants } from './constants';
 | 
			
		||||
							
								
								
									
										9
									
								
								packages/react-shared/src/ts/types.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								packages/react-shared/src/ts/types.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
export interface Styles {
 | 
			
		||||
    [name: string]: React.CSSProperties;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export enum HeaderSizes {
 | 
			
		||||
    H1 = 'h1',
 | 
			
		||||
    H2 = 'h2',
 | 
			
		||||
    H3 = 'h3',
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								packages/react-shared/src/ts/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								packages/react-shared/src/ts/utils.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
export const utils = {
 | 
			
		||||
    setUrlHash(anchorId: string) {
 | 
			
		||||
        window.location.hash = anchorId;
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										23
									
								
								packages/react-shared/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								packages/react-shared/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -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/**/*"]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								packages/react-shared/tslint.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								packages/react-shared/tslint.json
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user