aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/pages/documentation
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/ts/pages/documentation')
-rw-r--r--packages/website/ts/pages/documentation/comment.tsx9
-rw-r--r--packages/website/ts/pages/documentation/custom_enum.tsx9
-rw-r--r--packages/website/ts/pages/documentation/docs_info.ts31
-rw-r--r--packages/website/ts/pages/documentation/documentation.tsx288
-rw-r--r--packages/website/ts/pages/documentation/enum.tsx10
-rw-r--r--packages/website/ts/pages/documentation/event_definition.tsx50
-rw-r--r--packages/website/ts/pages/documentation/interface.tsx32
-rw-r--r--packages/website/ts/pages/documentation/method_block.tsx128
-rw-r--r--packages/website/ts/pages/documentation/method_signature.tsx58
-rw-r--r--packages/website/ts/pages/documentation/source_link.tsx18
-rw-r--r--packages/website/ts/pages/documentation/type.tsx134
-rw-r--r--packages/website/ts/pages/documentation/type_definition.tsx82
12 files changed, 393 insertions, 456 deletions
diff --git a/packages/website/ts/pages/documentation/comment.tsx b/packages/website/ts/pages/documentation/comment.tsx
index 78bbdc069..23cfd96bd 100644
--- a/packages/website/ts/pages/documentation/comment.tsx
+++ b/packages/website/ts/pages/documentation/comment.tsx
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import * as React from 'react';
import * as ReactMarkdown from 'react-markdown';
-import {MarkdownCodeBlock} from 'ts/pages/shared/markdown_code_block';
+import { MarkdownCodeBlock } from 'ts/pages/shared/markdown_code_block';
interface CommentProps {
comment: string;
@@ -15,10 +15,9 @@ const defaultProps = {
export const Comment: React.SFC<CommentProps> = (props: CommentProps) => {
return (
<div className={`${props.className} comment`}>
- <ReactMarkdown
- source={props.comment}
- renderers={{CodeBlock: MarkdownCodeBlock}}
- />
+ <ReactMarkdown source={props.comment} renderers={{ CodeBlock: MarkdownCodeBlock }} />
</div>
);
};
+
+Comment.defaultProps = defaultProps;
diff --git a/packages/website/ts/pages/documentation/custom_enum.tsx b/packages/website/ts/pages/documentation/custom_enum.tsx
index 7dced9b60..8d50a2f52 100644
--- a/packages/website/ts/pages/documentation/custom_enum.tsx
+++ b/packages/website/ts/pages/documentation/custom_enum.tsx
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import * as React from 'react';
-import {CustomType} from 'ts/types';
-import {utils} from 'ts/utils/utils';
+import { CustomType } from 'ts/types';
+import { utils } from 'ts/utils/utils';
const STRING_ENUM_CODE_PREFIX = ' strEnum(';
@@ -23,8 +23,9 @@ export function CustomEnum(props: CustomEnumProps) {
return (
<span>
{`{`}
- {'\t'}{enumValues}
- <br />
+ {'\t'}
+ {enumValues}
+ <br />
{`}`}
</span>
);
diff --git a/packages/website/ts/pages/documentation/docs_info.ts b/packages/website/ts/pages/documentation/docs_info.ts
index 1afcf8aaf..4b1ec122a 100644
--- a/packages/website/ts/pages/documentation/docs_info.ts
+++ b/packages/website/ts/pages/documentation/docs_info.ts
@@ -18,8 +18,8 @@ export class DocsInfo {
public docsJsonRoot: string;
public menu: DocsMenu;
public sections: SectionsMap;
- public sectionNameToMarkdown: {[sectionName: string]: string};
- private docsInfo: DocsInfoConfig;
+ public sectionNameToMarkdown: { [sectionName: string]: string };
+ private _docsInfo: DocsInfoConfig;
constructor(config: DocsInfoConfig) {
this.displayName = config.displayName;
this.packageUrl = config.packageUrl;
@@ -28,35 +28,34 @@ export class DocsInfo {
this.docsJsonRoot = config.docsJsonRoot;
this.sections = config.sections;
this.sectionNameToMarkdown = config.sectionNameToMarkdown;
- this.docsInfo = config;
+ this._docsInfo = config;
}
public isPublicType(typeName: string): boolean {
- if (_.isUndefined(this.docsInfo.publicTypes)) {
+ if (_.isUndefined(this._docsInfo.publicTypes)) {
return false;
}
- const isPublic = _.includes(this.docsInfo.publicTypes, typeName);
+ const isPublic = _.includes(this._docsInfo.publicTypes, typeName);
return isPublic;
}
public getModulePathsIfExists(sectionName: string): string[] {
- const modulePathsIfExists = this.docsInfo.sectionNameToModulePath[sectionName];
+ const modulePathsIfExists = this._docsInfo.sectionNameToModulePath[sectionName];
return modulePathsIfExists;
}
- public getMenu(selectedVersion?: string): {[section: string]: string[]} {
- if (_.isUndefined(selectedVersion) || _.isUndefined(this.docsInfo.menuSubsectionToVersionWhenIntroduced)) {
- return this.docsInfo.menu;
+ public getMenu(selectedVersion?: string): { [section: string]: string[] } {
+ if (_.isUndefined(selectedVersion) || _.isUndefined(this._docsInfo.menuSubsectionToVersionWhenIntroduced)) {
+ return this._docsInfo.menu;
}
- const finalMenu = _.cloneDeep(this.docsInfo.menu);
+ const finalMenu = _.cloneDeep(this._docsInfo.menu);
if (_.isUndefined(finalMenu.contracts)) {
return finalMenu;
}
// TODO: refactor to include more sections then simply the `contracts` section
finalMenu.contracts = _.filter(finalMenu.contracts, (contractName: string) => {
- const versionIntroducedIfExists = this.docsInfo.menuSubsectionToVersionWhenIntroduced[contractName];
+ const versionIntroducedIfExists = this._docsInfo.menuSubsectionToVersionWhenIntroduced[contractName];
if (!_.isUndefined(versionIntroducedIfExists)) {
- const existsInSelectedVersion = compareVersions(selectedVersion,
- versionIntroducedIfExists) >= 0;
+ const existsInSelectedVersion = compareVersions(selectedVersion, versionIntroducedIfExists) >= 0;
return existsInSelectedVersion;
} else {
return true;
@@ -104,9 +103,9 @@ export class DocsInfo {
return typeDefinitionByName;
}
public isVisibleConstructor(sectionName: string): boolean {
- return _.includes(this.docsInfo.visibleConstructors, sectionName);
+ return _.includes(this._docsInfo.visibleConstructors, sectionName);
}
- public convertToDocAgnosticFormat(docObj: DoxityDocObj|TypeDocNode): DocAgnosticFormat {
- return this.docsInfo.convertToDocAgnosticFormatFn(docObj, this);
+ public convertToDocAgnosticFormat(docObj: DoxityDocObj | TypeDocNode): DocAgnosticFormat {
+ return this._docsInfo.convertToDocAgnosticFormatFn(docObj, this);
}
}
diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx
index be99e77a2..2315847ad 100644
--- a/packages/website/ts/pages/documentation/documentation.tsx
+++ b/packages/website/ts/pages/documentation/documentation.tsx
@@ -1,60 +1,48 @@
import findVersions = require('find-versions');
import * as _ from 'lodash';
import CircularProgress from 'material-ui/CircularProgress';
-import {colors} from 'material-ui/styles';
import * as React from 'react';
import DocumentTitle = require('react-document-title');
-import {
- scroller,
-} from 'react-scroll';
+import { scroller } from 'react-scroll';
import semverSort = require('semver-sort');
-import {TopBar} from 'ts/components/top_bar';
-import {Badge} from 'ts/components/ui/badge';
-import {Comment} from 'ts/pages/documentation/comment';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {EventDefinition} from 'ts/pages/documentation/event_definition';
-import {MethodBlock} from 'ts/pages/documentation/method_block';
-import {SourceLink} from 'ts/pages/documentation/source_link';
-import {Type} from 'ts/pages/documentation/type';
-import {TypeDefinition} from 'ts/pages/documentation/type_definition';
-import {AnchorTitle} from 'ts/pages/shared/anchor_title';
-import {MarkdownSection} from 'ts/pages/shared/markdown_section';
-import {NestedSidebarMenu} from 'ts/pages/shared/nested_sidebar_menu';
-import {SectionHeader} from 'ts/pages/shared/section_header';
-import {Dispatcher} from 'ts/redux/dispatcher';
+import { TopBar } from 'ts/components/top_bar';
+import { Badge } from 'ts/components/ui/badge';
+import { Comment } from 'ts/pages/documentation/comment';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { EventDefinition } from 'ts/pages/documentation/event_definition';
+import { MethodBlock } from 'ts/pages/documentation/method_block';
+import { SourceLink } from 'ts/pages/documentation/source_link';
+import { Type } from 'ts/pages/documentation/type';
+import { TypeDefinition } from 'ts/pages/documentation/type_definition';
+import { MarkdownSection } from 'ts/pages/shared/markdown_section';
+import { NestedSidebarMenu } from 'ts/pages/shared/nested_sidebar_menu';
+import { SectionHeader } from 'ts/pages/shared/section_header';
+import { Dispatcher } from 'ts/redux/dispatcher';
import {
AddressByContractName,
- CustomType,
DocAgnosticFormat,
- Docs,
- DocsInfoConfig,
DoxityDocObj,
EtherscanLinkSuffixes,
Event,
- MenuSubsectionsBySection,
Networks,
Property,
SolidityMethod,
Styles,
TypeDefinitionByName,
- TypeDocNode,
TypescriptMethod,
- WebsitePaths,
} from 'ts/types';
-import {constants} from 'ts/utils/constants';
-import {docUtils} from 'ts/utils/doc_utils';
-import {utils} from 'ts/utils/utils';
+import { colors } from 'ts/utils/colors';
+import { configs } from 'ts/utils/configs';
+import { constants } from 'ts/utils/constants';
+import { docUtils } from 'ts/utils/doc_utils';
+import { utils } from 'ts/utils/utils';
-const SCROLL_TO_TIMEOUT = 500;
const SCROLL_TOP_ID = 'docsScrollTop';
-const CUSTOM_PURPLE = '#690596';
-const CUSTOM_RED = '#e91751';
-const CUSTOM_TURQUOIS = '#058789';
-const networkNameToColor: {[network: string]: string} = {
- [Networks.kovan]: CUSTOM_PURPLE,
- [Networks.ropsten]: CUSTOM_RED,
- [Networks.mainnet]: CUSTOM_TURQUOIS,
+const networkNameToColor: { [network: string]: string } = {
+ [Networks.kovan]: colors.purple,
+ [Networks.ropsten]: colors.red,
+ [Networks.mainnet]: colors.turquois,
};
export interface DocumentationAllProps {
@@ -73,13 +61,13 @@ interface DocumentationState {
const styles: Styles = {
mainContainers: {
position: 'absolute',
- top: 60,
+ top: 1,
left: 0,
bottom: 0,
right: 0,
overflowZ: 'hidden',
overflowY: 'scroll',
- minHeight: 'calc(100vh - 60px)',
+ minHeight: 'calc(100vh - 1px)',
WebkitOverflowScrolling: 'touch',
},
menuContainer: {
@@ -89,8 +77,7 @@ const styles: Styles = {
},
};
-export class Documentation extends
- React.Component<DocumentationAllProps, DocumentationState> {
+export class Documentation extends React.Component<DocumentationAllProps, DocumentationState> {
constructor(props: DocumentationAllProps) {
super(props);
this.state = {
@@ -103,15 +90,15 @@ export class Documentation extends
const versions = findVersions(lastSegment);
const preferredVersionIfExists = versions.length > 0 ? versions[0] : undefined;
// tslint:disable-next-line:no-floating-promises
- this.fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists);
+ this._fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists);
}
public render() {
- const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat) ?
- {} :
- this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
+ const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat)
+ ? {}
+ : this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
return (
<div>
- <DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`}/>
+ <DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`} />
<TopBar
blockchainIsLoaded={false}
location={this.props.location}
@@ -122,29 +109,26 @@ export class Documentation extends
shouldFullWidth={true}
docsInfo={this.props.docsInfo}
/>
- {_.isUndefined(this.state.docAgnosticFormat) ?
- <div
- className="col col-12"
- style={styles.mainContainers}
- >
+ {_.isUndefined(this.state.docAgnosticFormat) ? (
+ <div className="col col-12" style={styles.mainContainers}>
<div
className="relative sm-px2 sm-pt2 sm-m1"
- style={{height: 122, top: '50%', transform: 'translateY(-50%)'}}
+ style={{ height: 122, top: '50%', transform: 'translateY(-50%)' }}
>
<div className="center pb2">
<CircularProgress size={40} thickness={5} />
</div>
- <div className="center pt2" style={{paddingBottom: 11}}>Loading documentation...</div>
+ <div className="center pt2" style={{ paddingBottom: 11 }}>
+ Loading documentation...
+ </div>
</div>
- </div> :
- <div
- className="mx-auto flex"
- style={{color: colors.grey800, height: 43}}
- >
+ </div>
+ ) : (
+ <div className="mx-auto flex" style={{ color: colors.grey800, height: 43 }}>
<div className="relative col md-col-3 lg-col-3 lg-pl0 md-pl1 sm-hide xs-hide">
<div
className="border-right absolute"
- style={{...styles.menuContainer, ...styles.mainContainers}}
+ style={{ ...styles.menuContainer, ...styles.mainContainers }}
>
<NestedSidebarMenu
selectedVersion={this.props.docsVersion}
@@ -156,35 +140,31 @@ export class Documentation extends
</div>
</div>
<div className="relative col lg-col-9 md-col-9 sm-col-12 col-12">
- <div
- id="documentation"
- style={styles.mainContainers}
- className="absolute"
- >
+ <div id="documentation" style={styles.mainContainers} className="absolute">
<div id={SCROLL_TOP_ID} />
<h1 className="md-pl2 sm-pl3">
<a href={this.props.docsInfo.packageUrl} target="_blank">
{this.props.docsInfo.displayName}
</a>
</h1>
- {this.renderDocumentation()}
+ {this._renderDocumentation()}
</div>
</div>
</div>
- }
+ )}
</div>
);
}
- private renderDocumentation(): React.ReactNode {
+ private _renderDocumentation(): React.ReactNode {
const subMenus = _.values(this.props.docsInfo.getMenu());
const orderedSectionNames = _.flatten(subMenus);
const typeDefinitionByName = this.props.docsInfo.getTypeDefinitionsByName(this.state.docAgnosticFormat);
- const renderedSections = _.map(orderedSectionNames, this.renderSection.bind(this, typeDefinitionByName));
+ const renderedSections = _.map(orderedSectionNames, this._renderSection.bind(this, typeDefinitionByName));
return renderedSections;
}
- private renderSection(typeDefinitionByName: TypeDefinitionByName, sectionName: string): React.ReactNode {
+ private _renderSection(typeDefinitionByName: TypeDefinitionByName, sectionName: string): React.ReactNode {
const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdown[sectionName];
if (!_.isUndefined(markdownFileIfExists)) {
return (
@@ -205,6 +185,7 @@ export class Documentation extends
const typeDefs = _.map(sortedTypes, customType => {
return (
<TypeDefinition
+ sectionName={sectionName}
key={`type-${customType.name}`}
customType={customType}
docsInfo={this.props.docsInfo}
@@ -213,12 +194,12 @@ export class Documentation extends
});
const sortedProperties = _.sortBy(docSection.properties, 'name');
- const propertyDefs = _.map(sortedProperties, this.renderProperty.bind(this));
+ const propertyDefs = _.map(sortedProperties, this._renderProperty.bind(this, sectionName));
const sortedMethods = _.sortBy(docSection.methods, 'name');
const methodDefs = _.map(sortedMethods, method => {
const isConstructor = false;
- return this.renderMethodBlocks(method, sectionName, isConstructor, typeDefinitionByName);
+ return this._renderMethodBlocks(method, sectionName, isConstructor, typeDefinitionByName);
});
const sortedEvents = _.sortBy(docSection.events, 'name');
@@ -227,148 +208,143 @@ export class Documentation extends
<EventDefinition
key={`event-${event.name}-${i}`}
event={event}
+ sectionName={sectionName}
docsInfo={this.props.docsInfo}
/>
);
});
return (
- <div
- key={`section-${sectionName}`}
- className="py2 pr3 md-pl2 sm-pl3"
- >
+ <div key={`section-${sectionName}`} className="py2 pr3 md-pl2 sm-pl3">
<div className="flex">
- <div style={{marginRight: 7}}>
- <SectionHeader sectionName={sectionName} />
- </div>
- {this.renderNetworkBadgesIfExists(sectionName)}
+ <div style={{ marginRight: 7 }}>
+ <SectionHeader sectionName={sectionName} />
+ </div>
+ {this._renderNetworkBadgesIfExists(sectionName)}
</div>
- {docSection.comment &&
- <Comment
- comment={docSection.comment}
- />
- }
+ {docSection.comment && <Comment comment={docSection.comment} />}
{docSection.constructors.length > 0 &&
- this.props.docsInfo.isVisibleConstructor(sectionName) &&
- <div>
- <h2 className="thin">Constructor</h2>
- {this.renderConstructors(docSection.constructors, sectionName, typeDefinitionByName)}
- </div>
- }
- {docSection.properties.length > 0 &&
+ this.props.docsInfo.isVisibleConstructor(sectionName) && (
+ <div>
+ <h2 className="thin">Constructor</h2>
+ {this._renderConstructors(docSection.constructors, sectionName, typeDefinitionByName)}
+ </div>
+ )}
+ {docSection.properties.length > 0 && (
<div>
<h2 className="thin">Properties</h2>
<div>{propertyDefs}</div>
</div>
- }
- {docSection.methods.length > 0 &&
+ )}
+ {docSection.methods.length > 0 && (
<div>
<h2 className="thin">Methods</h2>
<div>{methodDefs}</div>
</div>
- }
- {!_.isUndefined(docSection.events) && docSection.events.length > 0 &&
- <div>
- <h2 className="thin">Events</h2>
- <div>{eventDefs}</div>
- </div>
- }
- {!_.isUndefined(typeDefs) && typeDefs.length > 0 &&
- <div>
- <div>{typeDefs}</div>
- </div>
- }
+ )}
+ {!_.isUndefined(docSection.events) &&
+ docSection.events.length > 0 && (
+ <div>
+ <h2 className="thin">Events</h2>
+ <div>{eventDefs}</div>
+ </div>
+ )}
+ {!_.isUndefined(typeDefs) &&
+ typeDefs.length > 0 && (
+ <div>
+ <div>{typeDefs}</div>
+ </div>
+ )}
</div>
);
}
- private renderNetworkBadgesIfExists(sectionName: string) {
- const networkToAddressByContractName = constants.contractAddresses[this.props.docsVersion];
- const badges = _.map(networkToAddressByContractName,
+ private _renderNetworkBadgesIfExists(sectionName: string) {
+ const networkToAddressByContractName = configs.CONTRACT_ADDRESS[this.props.docsVersion];
+ const badges = _.map(
+ networkToAddressByContractName,
(addressByContractName: AddressByContractName, networkName: string) => {
const contractAddress = addressByContractName[sectionName];
if (_.isUndefined(contractAddress)) {
return null;
}
const linkIfExists = utils.getEtherScanLinkIfExists(
- contractAddress, constants.networkIdByName[networkName], EtherscanLinkSuffixes.address,
+ contractAddress,
+ constants.NETWORK_ID_BY_NAME[networkName],
+ EtherscanLinkSuffixes.Address,
);
return (
<a
key={`badge-${networkName}-${sectionName}`}
href={linkIfExists}
target="_blank"
- style={{color: 'white', textDecoration: 'none'}}
+ style={{ color: colors.white, textDecoration: 'none' }}
>
- <Badge
- title={networkName}
- backgroundColor={networkNameToColor[networkName]}
- />
+ <Badge title={networkName} backgroundColor={networkNameToColor[networkName]} />
</a>
);
- });
+ },
+ );
return badges;
}
- private renderConstructors(constructors: SolidityMethod[]|TypescriptMethod[],
- sectionName: string,
- typeDefinitionByName: TypeDefinitionByName): React.ReactNode {
+ private _renderConstructors(
+ constructors: SolidityMethod[] | TypescriptMethod[],
+ sectionName: string,
+ typeDefinitionByName: TypeDefinitionByName,
+ ): React.ReactNode {
const constructorDefs = _.map(constructors, constructor => {
- return this.renderMethodBlocks(
- constructor, sectionName, constructor.isConstructor, typeDefinitionByName,
- );
+ return this._renderMethodBlocks(constructor, sectionName, constructor.isConstructor, typeDefinitionByName);
});
- return (
- <div>
- {constructorDefs}
- </div>
- );
+ return <div>{constructorDefs}</div>;
}
- private renderProperty(property: Property): React.ReactNode {
+ private _renderProperty(sectionName: string, property: Property): React.ReactNode {
return (
- <div
- key={`property-${property.name}-${property.type.name}`}
- className="pb3"
- >
+ <div key={`property-${property.name}-${property.type.name}`} className="pb3">
<code className="hljs">
- {property.name}: <Type type={property.type} docsInfo={this.props.docsInfo} />
+ {property.name}:
+ <Type type={property.type} sectionName={sectionName} docsInfo={this.props.docsInfo} />
</code>
- {property.source &&
+ {property.source && (
<SourceLink
version={this.props.docsVersion}
source={property.source}
baseUrl={this.props.docsInfo.packageUrl}
subPackageName={this.props.docsInfo.subPackageName}
/>
- }
- {property.comment &&
- <Comment
- comment={property.comment}
- className="py2"
- />
- }
+ )}
+ {property.comment && <Comment comment={property.comment} className="py2" />}
</div>
);
}
- private renderMethodBlocks(method: SolidityMethod|TypescriptMethod, sectionName: string,
- isConstructor: boolean, typeDefinitionByName: TypeDefinitionByName): React.ReactNode {
+ private _renderMethodBlocks(
+ method: SolidityMethod | TypescriptMethod,
+ sectionName: string,
+ isConstructor: boolean,
+ typeDefinitionByName: TypeDefinitionByName,
+ ): React.ReactNode {
return (
<MethodBlock
- key={`method-${method.name}-${sectionName}`}
- method={method}
- typeDefinitionByName={typeDefinitionByName}
- libraryVersion={this.props.docsVersion}
- docsInfo={this.props.docsInfo}
+ key={`method-${method.name}-${sectionName}`}
+ sectionName={sectionName}
+ method={method}
+ typeDefinitionByName={typeDefinitionByName}
+ libraryVersion={this.props.docsVersion}
+ docsInfo={this.props.docsInfo}
/>
);
}
- private scrollToHash(): void {
+ private _scrollToHash(): void {
const hashWithPrefix = this.props.location.hash;
let hash = hashWithPrefix.slice(1);
if (_.isEmpty(hash)) {
hash = SCROLL_TOP_ID; // scroll to the top
}
- scroller.scrollTo(hash, {duration: 0, offset: 0, containerId: 'documentation'});
+ scroller.scrollTo(hash, {
+ duration: 0,
+ offset: 0,
+ containerId: 'documentation',
+ });
}
- private async fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists?: string): Promise<void> {
+ private async _fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists?: string): Promise<void> {
const versionToFileName = await docUtils.getVersionToFileNameAsync(this.props.docsInfo.docsJsonRoot);
const versions = _.keys(versionToFileName);
this.props.dispatcher.updateAvailableDocVersions(versions);
@@ -386,14 +362,18 @@ export class Documentation extends
const versionFileNameToFetch = versionToFileName[versionToFetch];
const versionDocObj = await docUtils.getJSONDocFileAsync(
- versionFileNameToFetch, this.props.docsInfo.docsJsonRoot,
+ versionFileNameToFetch,
+ this.props.docsInfo.docsJsonRoot,
);
const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj as DoxityDocObj);
- this.setState({
- docAgnosticFormat,
- }, () => {
- this.scrollToHash();
- });
+ this.setState(
+ {
+ docAgnosticFormat,
+ },
+ () => {
+ this._scrollToHash();
+ },
+ );
}
}
diff --git a/packages/website/ts/pages/documentation/enum.tsx b/packages/website/ts/pages/documentation/enum.tsx
index 8fcd2c252..7dfdee771 100644
--- a/packages/website/ts/pages/documentation/enum.tsx
+++ b/packages/website/ts/pages/documentation/enum.tsx
@@ -1,9 +1,6 @@
import * as _ from 'lodash';
import * as React from 'react';
-import {EnumValue, TypeDocNode} from 'ts/types';
-import {utils} from 'ts/utils/utils';
-
-const STRING_ENUM_CODE_PREFIX = ' strEnum(';
+import { EnumValue } from 'ts/types';
interface EnumProps {
values: EnumValue[];
@@ -11,15 +8,14 @@ interface EnumProps {
export function Enum(props: EnumProps) {
const values = _.map(props.values, (value, i) => {
- const isLast = i === props.values.length - 1;
const defaultValueIfAny = !_.isUndefined(value.defaultValue) ? ` = ${value.defaultValue}` : '';
return `\n\t${value.name}${defaultValueIfAny},`;
});
return (
<span>
{`{`}
- {values}
- <br />
+ {values}
+ <br />
{`}`}
</span>
);
diff --git a/packages/website/ts/pages/documentation/event_definition.tsx b/packages/website/ts/pages/documentation/event_definition.tsx
index 469e6bb37..0e53e38e7 100644
--- a/packages/website/ts/pages/documentation/event_definition.tsx
+++ b/packages/website/ts/pages/documentation/event_definition.tsx
@@ -1,17 +1,14 @@
import * as _ from 'lodash';
import * as React from 'react';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {Type} from 'ts/pages/documentation/type';
-import {AnchorTitle} from 'ts/pages/shared/anchor_title';
-import {Event, EventArg, HeaderSizes} from 'ts/types';
-import {constants} from 'ts/utils/constants';
-import {utils} from 'ts/utils/utils';
-
-const KEYWORD_COLOR = '#a81ca6';
-const CUSTOM_GREEN = 'rgb(77, 162, 75)';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { Type } from 'ts/pages/documentation/type';
+import { AnchorTitle } from 'ts/pages/shared/anchor_title';
+import { Event, EventArg, HeaderSizes } from 'ts/types';
+import { colors } from 'ts/utils/colors';
interface EventDefinitionProps {
event: Event;
+ sectionName: string;
docsInfo: DocsInfo;
}
@@ -30,11 +27,11 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
const event = this.props.event;
return (
<div
- id={event.name}
+ id={`${this.props.sectionName}-${event.name}`}
className="pb2"
- style={{overflow: 'hidden', width: '100%'}}
- onMouseOver={this.setAnchorVisibility.bind(this, true)}
- onMouseOut={this.setAnchorVisibility.bind(this, false)}
+ style={{ overflow: 'hidden', width: '100%' }}
+ onMouseOver={this._setAnchorVisibility.bind(this, true)}
+ onMouseOut={this._setAnchorVisibility.bind(this, false)}
>
<AnchorTitle
headerSize={HeaderSizes.H3}
@@ -42,28 +39,24 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
id={event.name}
shouldShowAnchor={this.state.shouldShowAnchor}
/>
- <div style={{fontSize: 16}}>
+ <div style={{ fontSize: 16 }}>
<pre>
- <code className="hljs">
- {this.renderEventCode()}
- </code>
+ <code className="hljs">{this._renderEventCode()}</code>
</pre>
</div>
</div>
);
}
- private renderEventCode() {
- const indexed = <span style={{color: CUSTOM_GREEN}}> indexed</span>;
+ private _renderEventCode() {
+ const indexed = <span style={{ color: colors.green }}> indexed</span>;
const eventArgs = _.map(this.props.event.eventArgs, (eventArg: EventArg) => {
const type = (
- <Type
- type={eventArg.type}
- docsInfo={this.props.docsInfo}
- />
+ <Type type={eventArg.type} sectionName={this.props.sectionName} docsInfo={this.props.docsInfo} />
);
return (
<span key={`eventArg-${eventArg.name}`}>
- {eventArg.name}{eventArg.isIndexed ? indexed : ''}: {type},
+ {eventArg.name}
+ {eventArg.isIndexed ? indexed : ''}: {type},
</span>
);
});
@@ -73,14 +66,15 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
return (
<span>
{`{`}
- <br />
- {'\t'}{argList}
- <br />
+ <br />
+ {'\t'}
+ {argList}
+ <br />
{`}`}
</span>
);
}
- private setAnchorVisibility(shouldShowAnchor: boolean) {
+ private _setAnchorVisibility(shouldShowAnchor: boolean) {
this.setState({
shouldShowAnchor,
});
diff --git a/packages/website/ts/pages/documentation/interface.tsx b/packages/website/ts/pages/documentation/interface.tsx
index e671db2b8..16a772125 100644
--- a/packages/website/ts/pages/documentation/interface.tsx
+++ b/packages/website/ts/pages/documentation/interface.tsx
@@ -1,12 +1,13 @@
import * as _ from 'lodash';
import * as React from 'react';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {MethodSignature} from 'ts/pages/documentation/method_signature';
-import {Type} from 'ts/pages/documentation/type';
-import {CustomType, TypeDocTypes} from 'ts/types';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { MethodSignature } from 'ts/pages/documentation/method_signature';
+import { Type } from 'ts/pages/documentation/type';
+import { CustomType, TypeDocTypes } from 'ts/types';
interface InterfaceProps {
type: CustomType;
+ sectionName: string;
docsInfo: DocsInfo;
}
@@ -16,15 +17,17 @@ export function Interface(props: InterfaceProps) {
return (
<span key={`property-${property.name}-${property.type}-${type.name}`}>
{property.name}:{' '}
- {property.type.typeDocType !== TypeDocTypes.Reflection ?
- <Type type={property.type} docsInfo={props.docsInfo} /> :
+ {property.type.typeDocType !== TypeDocTypes.Reflection ? (
+ <Type type={property.type} sectionName={props.sectionName} docsInfo={props.docsInfo} />
+ ) : (
<MethodSignature
method={property.type.method}
+ sectionName={props.sectionName}
shouldHideMethodName={true}
shouldUseArrowSyntax={true}
docsInfo={props.docsInfo}
/>
- },
+ )},
</span>
);
});
@@ -33,14 +36,14 @@ export function Interface(props: InterfaceProps) {
const is = type.indexSignature;
const param = (
<span key={`indexSigParams-${is.keyName}-${is.keyType}-${type.name}`}>
- {is.keyName}: <Type type={is.keyType} docsInfo={props.docsInfo} />
+ {is.keyName}: <Type type={is.keyType} sectionName={props.sectionName} docsInfo={props.docsInfo} />
</span>
);
- properties.push((
+ properties.push(
<span key={`indexSignature-${type.name}-${is.keyType.name}`}>
[{param}]: {is.valueName},
- </span>
- ));
+ </span>,
+ );
}
const propertyList = _.reduce(properties, (prev: React.ReactNode, curr: React.ReactNode) => {
return [prev, '\n\t', curr];
@@ -48,9 +51,10 @@ export function Interface(props: InterfaceProps) {
return (
<span>
{`{`}
- <br />
- {'\t'}{propertyList}
- <br />
+ <br />
+ {'\t'}
+ {propertyList}
+ <br />
{`}`}
</span>
);
diff --git a/packages/website/ts/pages/documentation/method_block.tsx b/packages/website/ts/pages/documentation/method_block.tsx
index 44e549211..dfde5931b 100644
--- a/packages/website/ts/pages/documentation/method_block.tsx
+++ b/packages/website/ts/pages/documentation/method_block.tsx
@@ -1,27 +1,17 @@
import * as _ from 'lodash';
-import {Chip} from 'material-ui/Chip';
-import {colors} from 'material-ui/styles';
import * as React from 'react';
-import * as ReactMarkdown from 'react-markdown';
-import {Comment} from 'ts/pages/documentation/comment';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {MethodSignature} from 'ts/pages/documentation/method_signature';
-import {SourceLink} from 'ts/pages/documentation/source_link';
-import {AnchorTitle} from 'ts/pages/shared/anchor_title';
-import {
- HeaderSizes,
- Parameter,
- SolidityMethod,
- Styles,
- TypeDefinitionByName,
- TypeDocNode,
- TypescriptMethod,
-} from 'ts/types';
-import {typeDocUtils} from 'ts/utils/typedoc_utils';
-import {utils} from 'ts/utils/utils';
+import { Comment } from 'ts/pages/documentation/comment';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { MethodSignature } from 'ts/pages/documentation/method_signature';
+import { SourceLink } from 'ts/pages/documentation/source_link';
+import { AnchorTitle } from 'ts/pages/shared/anchor_title';
+import { HeaderSizes, Parameter, SolidityMethod, Styles, TypeDefinitionByName, TypescriptMethod } from 'ts/types';
+import { colors } from 'ts/utils/colors';
+import { typeDocUtils } from 'ts/utils/typedoc_utils';
interface MethodBlockProps {
- method: SolidityMethod|TypescriptMethod;
+ method: SolidityMethod | TypescriptMethod;
+ sectionName: string;
libraryVersion: string;
typeDefinitionByName: TypeDefinitionByName;
docsInfo: DocsInfo;
@@ -35,7 +25,7 @@ const styles: Styles = {
chip: {
fontSize: 13,
backgroundColor: colors.lightBlueA700,
- color: 'white',
+ color: colors.white,
height: 11,
borderRadius: 14,
marginTop: 19,
@@ -58,119 +48,93 @@ export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockSt
return (
<div
- id={method.name}
- style={{overflow: 'hidden', width: '100%'}}
+ id={`${this.props.sectionName}-${method.name}`}
+ style={{ overflow: 'hidden', width: '100%' }}
className="pb4"
- onMouseOver={this.setAnchorVisibility.bind(this, true)}
- onMouseOut={this.setAnchorVisibility.bind(this, false)}
+ onMouseOver={this._setAnchorVisibility.bind(this, true)}
+ onMouseOut={this._setAnchorVisibility.bind(this, false)}
>
- {!method.isConstructor &&
+ {!method.isConstructor && (
<div className="flex">
- {(method as TypescriptMethod).isStatic &&
- this.renderChip('Static')
- }
- {(method as SolidityMethod).isConstant &&
- this.renderChip('Constant')
- }
- {(method as SolidityMethod).isPayable &&
- this.renderChip('Payable')
- }
+ {(method as TypescriptMethod).isStatic && this._renderChip('Static')}
+ {(method as SolidityMethod).isConstant && this._renderChip('Constant')}
+ {(method as SolidityMethod).isPayable && this._renderChip('Payable')}
<AnchorTitle
headerSize={HeaderSizes.H3}
title={method.name}
- id={method.name}
+ id={`${this.props.sectionName}-${method.name}`}
shouldShowAnchor={this.state.shouldShowAnchor}
/>
</div>
- }
+ )}
<code className="hljs">
<MethodSignature
method={method}
+ sectionName={this.props.sectionName}
typeDefinitionByName={this.props.typeDefinitionByName}
docsInfo={this.props.docsInfo}
/>
</code>
- {(method as TypescriptMethod).source &&
+ {(method as TypescriptMethod).source && (
<SourceLink
version={this.props.libraryVersion}
source={(method as TypescriptMethod).source}
baseUrl={this.props.docsInfo.packageUrl}
subPackageName={this.props.docsInfo.subPackageName}
/>
- }
- {method.comment &&
- <Comment
- comment={method.comment}
- className="py2"
- />
- }
- {method.parameters && !_.isEmpty(method.parameters) &&
- <div>
- <h4
- className="pb1 thin"
- style={{borderBottom: '1px solid #e1e8ed'}}
- >
- ARGUMENTS
- </h4>
- {this.renderParameterDescriptions(method.parameters)}
- </div>
- }
- {method.returnComment &&
+ )}
+ {method.comment && <Comment comment={method.comment} className="py2" />}
+ {method.parameters &&
+ !_.isEmpty(method.parameters) && (
+ <div>
+ <h4 className="pb1 thin" style={{ borderBottom: '1px solid #e1e8ed' }}>
+ ARGUMENTS
+ </h4>
+ {this._renderParameterDescriptions(method.parameters)}
+ </div>
+ )}
+ {method.returnComment && (
<div className="pt1 comment">
- <h4
- className="pb1 thin"
- style={{borderBottom: '1px solid #e1e8ed'}}
- >
+ <h4 className="pb1 thin" style={{ borderBottom: '1px solid #e1e8ed' }}>
RETURNS
</h4>
- <Comment
- comment={method.returnComment}
- />
+ <Comment comment={method.returnComment} />
</div>
- }
+ )}
</div>
);
}
- private renderChip(text: string) {
+ private _renderChip(text: string) {
return (
- <div
- className="p1 mr1"
- style={styles.chip}
- >
+ <div className="p1 mr1" style={styles.chip}>
{text}
</div>
);
}
- private renderParameterDescriptions(parameters: Parameter[]) {
+ private _renderParameterDescriptions(parameters: Parameter[]) {
const descriptions = _.map(parameters, parameter => {
const isOptional = parameter.isOptional;
return (
<div
key={`param-description-${parameter.name}`}
className="flex pb1 mb2"
- style={{borderBottom: '1px solid #f0f4f7'}}
+ style={{ borderBottom: '1px solid #f0f4f7' }}
>
<div className="pl2 col lg-col-4 md-col-4 sm-col-12 col-12">
- <div className="bold">
- {parameter.name}
- </div>
- <div className="pt1" style={{color: colors.grey500, fontSize: 14}}>
+ <div className="bold">{parameter.name}</div>
+ <div className="pt1" style={{ color: colors.grey, fontSize: 14 }}>
{isOptional && 'optional'}
</div>
</div>
<div className="col lg-col-8 md-col-8 sm-col-12 col-12">
- {parameter.comment &&
- <Comment
- comment={parameter.comment}
- />
- }
+ {parameter.comment && <Comment comment={parameter.comment} />}
</div>
</div>
);
});
return descriptions;
}
- private setAnchorVisibility(shouldShowAnchor: boolean) {
+ private _setAnchorVisibility(shouldShowAnchor: boolean) {
this.setState({
shouldShowAnchor,
});
diff --git a/packages/website/ts/pages/documentation/method_signature.tsx b/packages/website/ts/pages/documentation/method_signature.tsx
index 846c9fa4f..041dcd093 100644
--- a/packages/website/ts/pages/documentation/method_signature.tsx
+++ b/packages/website/ts/pages/documentation/method_signature.tsx
@@ -1,11 +1,13 @@
import * as _ from 'lodash';
import * as React from 'react';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {Type} from 'ts/pages/documentation/type';
-import {Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod} from 'ts/types';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { Type } from 'ts/pages/documentation/type';
+import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from 'ts/types';
+import { constants } from 'ts/utils/constants';
interface MethodSignatureProps {
- method: TypescriptMethod|SolidityMethod;
+ method: TypescriptMethod | SolidityMethod;
+ sectionName: string;
shouldHideMethodName?: boolean;
shouldUseArrowSyntax?: boolean;
typeDefinitionByName?: TypeDefinitionByName;
@@ -18,32 +20,40 @@ const defaultProps = {
};
export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSignatureProps) => {
- const parameters = renderParameters(props.method, props.docsInfo, props.typeDefinitionByName);
+ const sectionName = constants.TYPES_SECTION_NAME;
+ const parameters = renderParameters(props.method, props.docsInfo, sectionName, props.typeDefinitionByName);
const paramString = _.reduce(parameters, (prev: React.ReactNode, curr: React.ReactNode) => {
return [prev, ', ', curr];
});
const methodName = props.shouldHideMethodName ? '' : props.method.name;
- const typeParameterIfExists = _.isUndefined((props.method as TypescriptMethod).typeParameter) ?
- undefined :
- renderTypeParameter(props.method, props.docsInfo, props.typeDefinitionByName);
+ const typeParameterIfExists = _.isUndefined((props.method as TypescriptMethod).typeParameter)
+ ? undefined
+ : renderTypeParameter(props.method, props.docsInfo, sectionName, props.typeDefinitionByName);
return (
<span>
- {props.method.callPath}{methodName}{typeParameterIfExists}({paramString})
- {props.shouldUseArrowSyntax ? ' => ' : ': '}
- {' '}
- {props.method.returnType &&
+ {props.method.callPath}
+ {methodName}
+ {typeParameterIfExists}({paramString})
+ {props.shouldUseArrowSyntax ? ' => ' : ': '}{' '}
+ {props.method.returnType && (
<Type
type={props.method.returnType}
+ sectionName={sectionName}
typeDefinitionByName={props.typeDefinitionByName}
docsInfo={props.docsInfo}
/>
- }
+ )}
</span>
);
};
+MethodSignature.defaultProps = defaultProps;
+
function renderParameters(
- method: TypescriptMethod|SolidityMethod, docsInfo: DocsInfo, typeDefinitionByName?: TypeDefinitionByName,
+ method: TypescriptMethod | SolidityMethod,
+ docsInfo: DocsInfo,
+ sectionName: string,
+ typeDefinitionByName?: TypeDefinitionByName,
) {
const parameters = method.parameters;
const params = _.map(parameters, (p: Parameter) => {
@@ -51,13 +61,15 @@ function renderParameters(
const type = (
<Type
type={p.type}
+ sectionName={sectionName}
typeDefinitionByName={typeDefinitionByName}
docsInfo={docsInfo}
/>
);
return (
<span key={`param-${p.type}-${p.name}`}>
- {p.name}{isOptional && '?'}: {type}
+ {p.name}
+ {isOptional && '?'}: {type}
</span>
);
});
@@ -65,17 +77,21 @@ function renderParameters(
}
function renderTypeParameter(
- method: TypescriptMethod, docsInfo: DocsInfo, typeDefinitionByName?: TypeDefinitionByName,
+ method: TypescriptMethod,
+ docsInfo: DocsInfo,
+ sectionName: string,
+ typeDefinitionByName?: TypeDefinitionByName,
) {
const typeParameter = method.typeParameter;
const typeParam = (
<span>
{`<${typeParameter.name} extends `}
- <Type
- type={typeParameter.type}
- typeDefinitionByName={typeDefinitionByName}
- docsInfo={docsInfo}
- />
+ <Type
+ type={typeParameter.type}
+ sectionName={sectionName}
+ typeDefinitionByName={typeDefinitionByName}
+ docsInfo={docsInfo}
+ />
{`>`}
</span>
);
diff --git a/packages/website/ts/pages/documentation/source_link.tsx b/packages/website/ts/pages/documentation/source_link.tsx
index 74fc6d4d5..6588ee39e 100644
--- a/packages/website/ts/pages/documentation/source_link.tsx
+++ b/packages/website/ts/pages/documentation/source_link.tsx
@@ -1,8 +1,7 @@
import * as _ from 'lodash';
-import {colors} from 'material-ui/styles';
import * as React from 'react';
-import {Source} from 'ts/types';
-import {constants} from 'ts/utils/constants';
+import { Source } from 'ts/types';
+import { colors } from 'ts/utils/colors';
interface SourceLinkProps {
source: Source;
@@ -11,9 +10,7 @@ interface SourceLinkProps {
subPackageName: string;
}
-const packagesWithNamespace = [
- 'connect',
-];
+const packagesWithNamespace = ['connect'];
export function SourceLink(props: SourceLinkProps) {
const src = props.source;
@@ -25,13 +22,8 @@ export function SourceLink(props: SourceLinkProps) {
}
const sourceCodeUrl = `${url}/blob/${tagPrefix}%40${props.version}/packages/${pkg}/${src.fileName}#L${src.line}`;
return (
- <div className="pt2" style={{fontSize: 14}}>
- <a
- href={sourceCodeUrl}
- target="_blank"
- className="underline"
- style={{color: colors.grey500}}
- >
+ <div className="pt2" style={{ fontSize: 14 }}>
+ <a href={sourceCodeUrl} target="_blank" className="underline" style={{ color: colors.grey }}>
Source
</a>
</div>
diff --git a/packages/website/ts/pages/documentation/type.tsx b/packages/website/ts/pages/documentation/type.tsx
index c564429d0..e989e7129 100644
--- a/packages/website/ts/pages/documentation/type.tsx
+++ b/packages/website/ts/pages/documentation/type.tsx
@@ -1,34 +1,30 @@
import * as _ from 'lodash';
-import {colors} from 'material-ui/styles';
import * as React from 'react';
-import {Link as ScrollLink} from 'react-scroll';
+import { Link as ScrollLink } from 'react-scroll';
import * as ReactTooltip from 'react-tooltip';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {TypeDefinition} from 'ts/pages/documentation/type_definition';
-import {Type as TypeDef, TypeDefinitionByName, TypeDocTypes} from 'ts/types';
-import {constants} from 'ts/utils/constants';
-import {typeDocUtils} from 'ts/utils/typedoc_utils';
-import {utils} from 'ts/utils/utils';
-
-const BUILT_IN_TYPE_COLOR = '#e69d00';
-const STRING_LITERAL_COLOR = '#4da24b';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { TypeDefinition } from 'ts/pages/documentation/type_definition';
+import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from 'ts/types';
+import { colors } from 'ts/utils/colors';
+import { constants } from 'ts/utils/constants';
+import { utils } from 'ts/utils/utils';
// Some types reference other libraries. For these types, we want to link the user to the relevant documentation.
-const typeToUrl: {[typeName: string]: string} = {
- Web3: constants.WEB3_DOCS_URL,
- Provider: constants.WEB3_PROVIDER_DOCS_URL,
- BigNumber: constants.BIGNUMBERJS_GITHUB_URL,
- DecodedLogEntryEvent: constants.WEB3_DECODED_LOG_ENTRY_EVENT_URL,
- LogEntryEvent: constants.WEB3_LOG_ENTRY_EVENT_URL,
+const typeToUrl: { [typeName: string]: string } = {
+ Web3: constants.URL_WEB3_DOCS,
+ Provider: constants.URL_WEB3_PROVIDER_DOCS,
+ BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
+ DecodedLogEntryEvent: constants.URL_WEB3_DECODED_LOG_ENTRY_EVENT,
+ LogEntryEvent: constants.URL_WEB3_LOG_ENTRY_EVENT,
};
-const typePrefix: {[typeName: string]: string} = {
+const typePrefix: { [typeName: string]: string } = {
Provider: 'Web3',
DecodedLogEntryEvent: 'Web3',
LogEntryEvent: 'Web3',
};
-const typeToSection: {[typeName: string]: string} = {
+const typeToSection: { [typeName: string]: string } = {
ExchangeWrapper: 'exchange',
TokenWrapper: 'token',
TokenRegistryWrapper: 'tokenRegistry',
@@ -41,6 +37,7 @@ const typeToSection: {[typeName: string]: string} = {
interface TypeProps {
type: TypeDef;
docsInfo: DocsInfo;
+ sectionName: string;
typeDefinitionByName?: TypeDefinitionByName;
}
@@ -48,18 +45,16 @@ interface TypeProps {
// <Type /> components (e.g when rendering the union type).
export function Type(props: TypeProps): any {
const type = props.type;
- const isIntrinsic = type.typeDocType === TypeDocTypes.Intrinsic;
const isReference = type.typeDocType === TypeDocTypes.Reference;
const isArray = type.typeDocType === TypeDocTypes.Array;
- const isStringLiteral = type.typeDocType === TypeDocTypes.StringLiteral;
let typeNameColor = 'inherit';
- let typeName: string|React.ReactNode;
+ let typeName: string | React.ReactNode;
let typeArgs: React.ReactNode[] = [];
switch (type.typeDocType) {
case TypeDocTypes.Intrinsic:
case TypeDocTypes.Unknown:
typeName = type.name;
- typeNameColor = BUILT_IN_TYPE_COLOR;
+ typeNameColor = colors.orange;
break;
case TypeDocTypes.Reference:
@@ -72,6 +67,7 @@ export function Type(props: TypeProps): any {
<Type
key={key}
type={arg.elementType}
+ sectionName={props.sectionName}
typeDefinitionByName={props.typeDefinitionByName}
docsInfo={props.docsInfo}
/>[]
@@ -82,6 +78,7 @@ export function Type(props: TypeProps): any {
<Type
key={`type-${arg.name}-${arg.value}-${arg.typeDocType}`}
type={arg}
+ sectionName={props.sectionName}
typeDefinitionByName={props.typeDefinitionByName}
docsInfo={props.docsInfo}
/>
@@ -93,7 +90,7 @@ export function Type(props: TypeProps): any {
case TypeDocTypes.StringLiteral:
typeName = `'${type.value}'`;
- typeNameColor = STRING_LITERAL_COLOR;
+ typeNameColor = colors.green;
break;
case TypeDocTypes.Array:
@@ -106,6 +103,7 @@ export function Type(props: TypeProps): any {
<Type
key={`type-${t.name}-${t.value}-${t.typeDocType}`}
type={t}
+ sectionName={props.sectionName}
typeDefinitionByName={props.typeDefinitionByName}
docsInfo={props.docsInfo}
/>
@@ -132,25 +130,29 @@ export function Type(props: TypeProps): any {
return [prev, ', ', curr];
});
- const typeNameUrlIfExists = typeToUrl[(typeName as string)];
- const typePrefixIfExists = typePrefix[(typeName as string)];
- const sectionNameIfExists = typeToSection[(typeName as string)];
+ const typeNameUrlIfExists = typeToUrl[typeName as string];
+ const typePrefixIfExists = typePrefix[typeName as string];
+ const sectionNameIfExists = typeToSection[typeName as string];
if (!_.isUndefined(typeNameUrlIfExists)) {
typeName = (
<a
href={typeNameUrlIfExists}
target="_blank"
className="text-decoration-none"
- style={{color: colors.lightBlueA700}}
+ style={{ color: colors.lightBlueA700 }}
>
- {!_.isUndefined(typePrefixIfExists) ? `${typePrefixIfExists}.` : ''}{typeName}
+ {!_.isUndefined(typePrefixIfExists) ? `${typePrefixIfExists}.` : ''}
+ {typeName}
</a>
);
- } else if ((isReference || isArray) &&
- (props.docsInfo.isPublicType(typeName as string) ||
- !_.isUndefined(sectionNameIfExists))) {
+ } else if (
+ (isReference || isArray) &&
+ (props.docsInfo.isPublicType(typeName as string) || !_.isUndefined(sectionNameIfExists))
+ ) {
const id = Math.random().toString();
- const typeDefinitionAnchorId = _.isUndefined(sectionNameIfExists) ? typeName : sectionNameIfExists;
+ const typeDefinitionAnchorId = _.isUndefined(sectionNameIfExists)
+ ? `${props.sectionName}-${typeName}`
+ : sectionNameIfExists;
let typeDefinition;
if (props.typeDefinitionByName) {
typeDefinition = props.typeDefinitionByName[typeName as string];
@@ -162,45 +164,49 @@ export function Type(props: TypeProps): any {
duration={constants.DOCS_SCROLL_DURATION_MS}
containerId={constants.DOCS_CONTAINER_ID}
>
- {_.isUndefined(typeDefinition) || utils.isUserOnMobile() ?
- <span
- onClick={utils.setUrlHash.bind(null, typeDefinitionAnchorId)}
- style={{color: colors.lightBlueA700, cursor: 'pointer'}}
- >
- {typeName}
- </span> :
- <span
- data-tip={true}
- data-for={id}
- onClick={utils.setUrlHash.bind(null, typeDefinitionAnchorId)}
- style={{color: colors.lightBlueA700, cursor: 'pointer', display: 'inline-block'}}
- >
- {typeName}
- <ReactTooltip
- type="light"
- effect="solid"
- id={id}
- className="typeTooltip"
+ {_.isUndefined(typeDefinition) || utils.isUserOnMobile() ? (
+ <span
+ onClick={utils.setUrlHash.bind(null, typeDefinitionAnchorId)}
+ style={{ color: colors.lightBlueA700, cursor: 'pointer' }}
>
- <TypeDefinition
- customType={typeDefinition}
- shouldAddId={false}
- docsInfo={props.docsInfo}
- />
- </ReactTooltip>
- </span>
- }
+ {typeName}
+ </span>
+ ) : (
+ <span
+ data-tip={true}
+ data-for={id}
+ onClick={utils.setUrlHash.bind(null, typeDefinitionAnchorId)}
+ style={{
+ color: colors.lightBlueA700,
+ cursor: 'pointer',
+ display: 'inline-block',
+ }}
+ >
+ {typeName}
+ <ReactTooltip type="light" effect="solid" id={id} className="typeTooltip">
+ <TypeDefinition
+ sectionName={props.sectionName}
+ customType={typeDefinition}
+ shouldAddId={false}
+ docsInfo={props.docsInfo}
+ />
+ </ReactTooltip>
+ </span>
+ )}
</ScrollLink>
);
}
return (
<span>
- <span style={{color: typeNameColor}}>{typeName}</span>
- {isArray && '[]'}{!_.isEmpty(typeArgs) &&
+ <span style={{ color: typeNameColor }}>{typeName}</span>
+ {isArray && '[]'}
+ {!_.isEmpty(typeArgs) && (
<span>
- {'<'}{commaSeparatedTypeArgs}{'>'}
+ {'<'}
+ {commaSeparatedTypeArgs}
+ {'>'}
</span>
- }
+ )}
</span>
);
}
diff --git a/packages/website/ts/pages/documentation/type_definition.tsx b/packages/website/ts/pages/documentation/type_definition.tsx
index 17b182c70..d46eec76c 100644
--- a/packages/website/ts/pages/documentation/type_definition.tsx
+++ b/packages/website/ts/pages/documentation/type_definition.tsx
@@ -1,21 +1,19 @@
import * as _ from 'lodash';
import * as React from 'react';
-import {Comment} from 'ts/pages/documentation/comment';
-import {CustomEnum} from 'ts/pages/documentation/custom_enum';
-import {DocsInfo} from 'ts/pages/documentation/docs_info';
-import {Enum} from 'ts/pages/documentation/enum';
-import {Interface} from 'ts/pages/documentation/interface';
-import {MethodSignature} from 'ts/pages/documentation/method_signature';
-import {Type} from 'ts/pages/documentation/type';
-import {AnchorTitle} from 'ts/pages/shared/anchor_title';
-import {CustomType, CustomTypeChild, HeaderSizes, KindString, TypeDocTypes} from 'ts/types';
-import {constants} from 'ts/utils/constants';
-import {typeDocUtils} from 'ts/utils/typedoc_utils';
-import {utils} from 'ts/utils/utils';
-
-const KEYWORD_COLOR = '#a81ca6';
+import { Comment } from 'ts/pages/documentation/comment';
+import { CustomEnum } from 'ts/pages/documentation/custom_enum';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { Enum } from 'ts/pages/documentation/enum';
+import { Interface } from 'ts/pages/documentation/interface';
+import { MethodSignature } from 'ts/pages/documentation/method_signature';
+import { Type } from 'ts/pages/documentation/type';
+import { AnchorTitle } from 'ts/pages/shared/anchor_title';
+import { CustomType, CustomTypeChild, HeaderSizes, KindString, TypeDocTypes } from 'ts/types';
+import { colors } from 'ts/utils/colors';
+import { utils } from 'ts/utils/utils';
interface TypeDefinitionProps {
+ sectionName: string;
customType: CustomType;
shouldAddId?: boolean;
docsInfo: DocsInfo;
@@ -47,20 +45,13 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
case KindString.Interface:
typePrefix = 'Interface';
codeSnippet = (
- <Interface
- type={customType}
- docsInfo={this.props.docsInfo}
- />
+ <Interface type={customType} sectionName={this.props.sectionName} docsInfo={this.props.docsInfo} />
);
break;
case KindString.Variable:
typePrefix = 'Enum';
- codeSnippet = (
- <CustomEnum
- type={customType}
- />
- );
+ codeSnippet = <CustomEnum type={customType} />;
break;
case KindString.Enumeration:
@@ -71,27 +62,29 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
defaultValue: c.defaultValue,
};
});
- codeSnippet = (
- <Enum
- values={enumValues}
- />
- );
+ codeSnippet = <Enum values={enumValues} />;
break;
- case KindString['Type alias']:
+ case KindString.TypeAlias:
typePrefix = 'Type Alias';
codeSnippet = (
<span>
- <span style={{color: KEYWORD_COLOR}}>type</span> {customType.name} ={' '}
- {customType.type.typeDocType !== TypeDocTypes.Reflection ?
- <Type type={customType.type} docsInfo={this.props.docsInfo} /> :
+ <span style={{ color: colors.lightPurple }}>type</span> {customType.name} ={' '}
+ {customType.type.typeDocType !== TypeDocTypes.Reflection ? (
+ <Type
+ type={customType.type}
+ sectionName={this.props.sectionName}
+ docsInfo={this.props.docsInfo}
+ />
+ ) : (
<MethodSignature
method={customType.type.method}
+ sectionName={this.props.sectionName}
shouldHideMethodName={true}
shouldUseArrowSyntax={true}
docsInfo={this.props.docsInfo}
/>
- }
+ )}
</span>
);
break;
@@ -100,14 +93,14 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
throw utils.spawnSwitchErr('type.kindString', customType.kindString);
}
- const typeDefinitionAnchorId = customType.name;
+ const typeDefinitionAnchorId = `${this.props.sectionName}-${customType.name}`;
return (
<div
id={this.props.shouldAddId ? typeDefinitionAnchorId : ''}
className="pb2"
- style={{overflow: 'hidden', width: '100%'}}
- onMouseOver={this.setAnchorVisibility.bind(this, true)}
- onMouseOut={this.setAnchorVisibility.bind(this, false)}
+ style={{ overflow: 'hidden', width: '100%' }}
+ onMouseOver={this._setAnchorVisibility.bind(this, true)}
+ onMouseOut={this._setAnchorVisibility.bind(this, false)}
>
<AnchorTitle
headerSize={HeaderSizes.H3}
@@ -115,23 +108,16 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
id={this.props.shouldAddId ? typeDefinitionAnchorId : ''}
shouldShowAnchor={this.state.shouldShowAnchor}
/>
- <div style={{fontSize: 16}}>
+ <div style={{ fontSize: 16 }}>
<pre>
- <code className="hljs">
- {codeSnippet}
- </code>
+ <code className="hljs">{codeSnippet}</code>
</pre>
</div>
- {customType.comment &&
- <Comment
- comment={customType.comment}
- className="py2"
- />
- }
+ {customType.comment && <Comment comment={customType.comment} className="py2" />}
</div>
);
}
- private setAnchorVisibility(shouldShowAnchor: boolean) {
+ private _setAnchorVisibility(shouldShowAnchor: boolean) {
this.setState({
shouldShowAnchor,
});