aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs/example/ts/docs.tsx
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-03-09 00:43:16 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-03-09 00:43:16 +0800
commit098dae9a7e57385505f0f272fd76d44f43fa1e34 (patch)
treebcd47532910e5804746ec88c8d9f6b85c157d6e1 /packages/react-docs/example/ts/docs.tsx
parent5b5037a844f49c17deeaf695fc8ed57832038da6 (diff)
parentaaa7affa46450bb48639e9b90c2a2e8adb28826c (diff)
downloaddexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.tar
dexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.tar.gz
dexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.tar.bz2
dexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.tar.lz
dexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.tar.xz
dexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.tar.zst
dexon-sol-tools-098dae9a7e57385505f0f272fd76d44f43fa1e34.zip
Merge branch 'development' into feature/sra-reporter
* development: (68 commits) Update list of packages and organize them alphabetically Fix prettier issues Add support for going back to previous hashes via the browser back button to wiki Scroll to previous hashed elements when user clicks back button Add back strict null checks to react-shared package and fix issues remove ability to have implicit dependencies and add missing deps update license remove no-implicit-this Add example & screenshot to npmignore Remove `;` to be nice to windows users Use unencoded @ symbol, browser will fix Fix external type links Add comment about commented out CSS exception Update prettier since the previous version had a bug when dealing with css files Fix css files with prettier Added base-contract package to README Prettify test jsons Update yarn.lock Improve README Feedback ...
Diffstat (limited to 'packages/react-docs/example/ts/docs.tsx')
-rw-r--r--packages/react-docs/example/ts/docs.tsx122
1 files changed, 122 insertions, 0 deletions
diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx
new file mode 100644
index 000000000..7d3e3f5b6
--- /dev/null
+++ b/packages/react-docs/example/ts/docs.tsx
@@ -0,0 +1,122 @@
+import * as _ from 'lodash';
+import * as React from 'react';
+
+import { Documentation } from '../../src/ts/components/documentation';
+import { DocsInfo } from '../../src/ts/docs_info';
+import { DocAgnosticFormat, DocsInfoConfig, SupportedDocJson, TypeDocNode } from '../../src/ts/types';
+import { constants } from '../../src/ts/utils/constants';
+
+import * as v0TypeDocJson from './json/0.1.12.json';
+import * as v2TypeDocJson from './json/0.2.0.json';
+
+/* tslint:disable:no-var-requires */
+const IntroMarkdown = require('md/introduction');
+/* tslint:enable:no-var-requires */
+
+const docSections = {
+ introduction: 'introduction',
+ web3Wrapper: 'web3Wrapper',
+ types: constants.TYPES_SECTION_NAME,
+};
+
+const docsInfoConfig: DocsInfoConfig = {
+ id: 'web3Wrapper',
+ type: SupportedDocJson.TypeDoc,
+ displayName: 'Web3 Wrapper',
+ packageUrl: 'https://github.com/0xProject/0x-monorepo',
+ menu: {
+ introduction: [docSections.introduction],
+ web3Wrapper: [docSections.web3Wrapper],
+ types: [docSections.types],
+ },
+ sectionNameToMarkdown: {
+ [docSections.introduction]: IntroMarkdown,
+ },
+ sectionNameToModulePath: {
+ [docSections.web3Wrapper]: ['"web3-wrapper/src/index"'],
+ [docSections.types]: ['"types/src/index"'],
+ },
+ menuSubsectionToVersionWhenIntroduced: {},
+ sections: docSections,
+ visibleConstructors: [docSections.web3Wrapper],
+ typeConfigs: {
+ // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is
+ // currently no way to extract the re-exported types from index.ts via TypeDoc :(
+ publicTypes: ['TxData', 'TransactionReceipt', 'RawLogEntry'],
+ typeNameToExternalLink: {
+ Web3: 'https://github.com/ethereum/wiki/wiki/JavaScript-API',
+ Provider: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L150',
+ BigNumber: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L127',
+ LogEntryEvent: 'http://mikemcl.github.io/bignumber.js',
+ CallData: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L348',
+ BlockWithoutTransactionData:
+ 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L314',
+ LogEntry: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L366',
+ FilterObject: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L109',
+ ['Web3.BlockParam']: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L278',
+ ['Web3.ContractAbi']: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L47',
+ },
+ typeNameToPrefix: {
+ Provider: 'Web3',
+ CallData: 'Web3',
+ BlockWithoutTransactionData: 'Web3',
+ LogEntry: 'Web3',
+ FilterObject: 'Web3',
+ },
+ typeNameToDocSection: {
+ Web3Wrapper: docSections.web3Wrapper,
+ },
+ },
+};
+const docsInfo = new DocsInfo(docsInfoConfig);
+
+const availableVersions = ['0.1.12', '0.2.0'];
+const versionToDocJSON: { [semver: string]: object } = {
+ [availableVersions[0]]: v0TypeDocJson,
+ [availableVersions[1]]: v2TypeDocJson,
+};
+
+export interface DocsProps {}
+
+interface DocsState {
+ selectedVersion: string;
+ docAgnosticFormat?: DocAgnosticFormat;
+}
+
+export class Docs extends React.Component<DocsProps, DocsState> {
+ constructor(props: DocsProps) {
+ super(props);
+ this.state = {
+ selectedVersion: availableVersions[1],
+ docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(v2TypeDocJson),
+ };
+ }
+ public render() {
+ const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat)
+ ? {}
+ : docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
+ return (
+ <Documentation
+ selectedVersion={this.state.selectedVersion}
+ availableVersions={availableVersions}
+ docsInfo={docsInfo}
+ docAgnosticFormat={this.state.docAgnosticFormat}
+ sourceUrl={this._getSourceUrl()}
+ onVersionSelected={this._onVersionSelected.bind(this)}
+ />
+ );
+ }
+ private _onVersionSelected(semver: string) {
+ const selectedDocJSON = versionToDocJSON[semver];
+ this.setState({
+ selectedVersion: semver,
+ docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(selectedDocJSON as TypeDocNode),
+ });
+ }
+ private _getSourceUrl() {
+ const sourceUrl = `${docsInfoConfig.packageUrl}/blob/@0xproject/web3-wrapper@${
+ this.state.selectedVersion
+ }/packages`;
+ return sourceUrl;
+ }
+}