aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/pages/documentation/event_definition.tsx
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-28 00:05:47 +0800
committerGitHub <noreply@github.com>2017-11-28 00:05:47 +0800
commit48b3d8526560d389e74beb12bbd64b7be6e9268f (patch)
tree00ae6e24314793cd303b154ede4fe4f55c654e84 /packages/website/ts/pages/documentation/event_definition.tsx
parentb5ce876327fe6443364837ea65cf28ec0e371949 (diff)
parentecfee00feca331ee1efa55165471d79774cb03d2 (diff)
downloaddexon-0x-contracts-48b3d8526560d389e74beb12bbd64b7be6e9268f.tar.gz
dexon-0x-contracts-48b3d8526560d389e74beb12bbd64b7be6e9268f.tar.zst
dexon-0x-contracts-48b3d8526560d389e74beb12bbd64b7be6e9268f.zip
Merge pull request #237 from 0xProject/addWebsite
Add Website to Mono Repo
Diffstat (limited to 'packages/website/ts/pages/documentation/event_definition.tsx')
-rw-r--r--packages/website/ts/pages/documentation/event_definition.tsx80
1 files changed, 80 insertions, 0 deletions
diff --git a/packages/website/ts/pages/documentation/event_definition.tsx b/packages/website/ts/pages/documentation/event_definition.tsx
new file mode 100644
index 000000000..58271e98f
--- /dev/null
+++ b/packages/website/ts/pages/documentation/event_definition.tsx
@@ -0,0 +1,80 @@
+import * as _ from 'lodash';
+import * as React from 'react';
+import {constants} from 'ts/utils/constants';
+import {utils} from 'ts/utils/utils';
+import {Event, EventArg, HeaderSizes} from 'ts/types';
+import {Type} from 'ts/pages/documentation/type';
+import {AnchorTitle} from 'ts/pages/shared/anchor_title';
+
+const KEYWORD_COLOR = '#a81ca6';
+const CUSTOM_GREEN = 'rgb(77, 162, 75)';
+
+interface EventDefinitionProps {
+ event: Event;
+}
+
+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;
+ return (
+ <div
+ id={event.name}
+ 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={event.name}
+ shouldShowAnchor={this.state.shouldShowAnchor}
+ />
+ <div style={{fontSize: 16}}>
+ <pre>
+ <code className="hljs">
+ {this.renderEventCode()}
+ </code>
+ </pre>
+ </div>
+ </div>
+ );
+ }
+ private renderEventCode() {
+ const indexed = <span style={{color: CUSTOM_GREEN}}> indexed</span>;
+ const eventArgs = _.map(this.props.event.eventArgs, (eventArg: EventArg) => {
+ return (
+ <span key={`eventArg-${eventArg.name}`}>
+ {eventArg.name}{eventArg.isIndexed ? indexed : ''}: <Type type={eventArg.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,
+ });
+ }
+}