Setup initial react-shared sub-package

This commit is contained in:
Fabio Berger
2018-03-03 19:58:30 +01:00
parent 3592ebef08
commit b7d001da88
14 changed files with 197 additions and 0 deletions

4
packages/react-shared/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
node_modules
yarn.error
lib
src/public/bundle*

View File

@@ -0,0 +1,5 @@
.*
yarn-error.log
/src/
/scripts/
tsconfig.json

View File

@@ -0,0 +1,2 @@
lib
package.json

View File

@@ -0,0 +1,6 @@
{
"tabWidth": 4,
"printWidth": 120,
"trailingComma": all,
"singleQuote": true
}

View 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"
}
}

View 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);

View 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,
});
}
}

View File

@@ -0,0 +1,4 @@
export const constants = {
DOCS_SCROLL_DURATION_MS: 0,
DOCS_CONTAINER_ID: 'documentation',
};

View File

View File

@@ -0,0 +1,6 @@
export { AnchorTitle } from './components/anchor_title';
export { HeaderSizes, Styles } from './types';
export { utils } from './utils';
export { constants } from './constants';

View File

@@ -0,0 +1,9 @@
export interface Styles {
[name: string]: React.CSSProperties;
}
export enum HeaderSizes {
H1 = 'h1',
H2 = 'h2',
H3 = 'h3',
}

View File

@@ -0,0 +1,5 @@
export const utils = {
setUrlHash(anchorId: string) {
window.location.hash = anchorId;
},
};

View 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/**/*"]
}

View 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
}
}