diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-14 22:18:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 22:18:16 +0800 |
commit | e16feb27f4ec1987259a87f360824a0158bd8b10 (patch) | |
tree | e94cb3bc89e215c4df38ab161379023ab8e0c4e9 /packages/react-docs/src/components/event_definition.tsx | |
parent | 3f3e8be004818ddaa1921b3dff12bdd46052278b (diff) | |
parent | 83ae7ba08d55fa964bf7b7a985aea0fe1520c5c7 (diff) | |
download | dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.tar dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.gz dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.bz2 dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.lz dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.xz dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.zst dexon-sol-tools-e16feb27f4ec1987259a87f360824a0158bd8b10.zip |
Merge pull request #450 from 0xProject/convertScriptsToTs
Convert Scripts to TS & Other Misc. Fixes
Diffstat (limited to 'packages/react-docs/src/components/event_definition.tsx')
-rw-r--r-- | packages/react-docs/src/components/event_definition.tsx | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/packages/react-docs/src/components/event_definition.tsx b/packages/react-docs/src/components/event_definition.tsx new file mode 100644 index 000000000..67729ac87 --- /dev/null +++ b/packages/react-docs/src/components/event_definition.tsx @@ -0,0 +1,84 @@ +import { AnchorTitle, colors, HeaderSizes } from '@0xproject/react-shared'; +import * as _ from 'lodash'; +import * as React from 'react'; + +import { DocsInfo } from '../docs_info'; +import { Event, EventArg } from '../types'; + +import { Type } from './type'; + +export interface EventDefinitionProps { + event: Event; + sectionName: string; + docsInfo: DocsInfo; +} + +export interface EventDefinitionState { + shouldShowAnchor: boolean; +} + +export class EventDefinition extends React.Component<EventDefinitionProps, EventDefinitionState> { + constructor(props: EventDefinitionProps) { + super(props); + this.state = { + shouldShowAnchor: false, + }; + } + public render() { + const event = this.props.event; + const id = `${this.props.sectionName}-${event.name}`; + return ( + <div + id={id} + className="pb2" + style={{ overflow: 'hidden', width: '100%' }} + onMouseOver={this._setAnchorVisibility.bind(this, true)} + onMouseOut={this._setAnchorVisibility.bind(this, false)} + > + <AnchorTitle + headerSize={HeaderSizes.H3} + title={`Event ${event.name}`} + id={id} + shouldShowAnchor={this.state.shouldShowAnchor} + /> + <div style={{ fontSize: 16 }}> + <pre> + <code className="hljs solidity">{this._renderEventCode()}</code> + </pre> + </div> + </div> + ); + } + 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} sectionName={this.props.sectionName} docsInfo={this.props.docsInfo} /> + ); + return ( + <span key={`eventArg-${eventArg.name}`}> + {eventArg.name} + {eventArg.isIndexed ? indexed : ''}: {type}, + </span> + ); + }); + const argList = _.reduce(eventArgs, (prev: React.ReactNode, curr: React.ReactNode) => { + return [prev, '\n\t', curr]; + }); + return ( + <span> + {`{`} + <br /> + {'\t'} + {argList} + <br /> + {`}`} + </span> + ); + } + private _setAnchorVisibility(shouldShowAnchor: boolean) { + this.setState({ + shouldShowAnchor, + }); + } +} |