aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-shared/src/ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/react-shared/src/ts')
-rw-r--r--packages/react-shared/src/ts/components/anchor_title.tsx87
-rw-r--r--packages/react-shared/src/ts/constants.ts4
-rw-r--r--packages/react-shared/src/ts/globals.d.ts0
-rw-r--r--packages/react-shared/src/ts/index.ts6
-rw-r--r--packages/react-shared/src/ts/types.ts9
-rw-r--r--packages/react-shared/src/ts/utils.ts5
6 files changed, 111 insertions, 0 deletions
diff --git a/packages/react-shared/src/ts/components/anchor_title.tsx b/packages/react-shared/src/ts/components/anchor_title.tsx
new file mode 100644
index 000000000..9b8e6854f
--- /dev/null
+++ b/packages/react-shared/src/ts/components/anchor_title.tsx
@@ -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,
+ });
+ }
+}
diff --git a/packages/react-shared/src/ts/constants.ts b/packages/react-shared/src/ts/constants.ts
new file mode 100644
index 000000000..20d0c6e92
--- /dev/null
+++ b/packages/react-shared/src/ts/constants.ts
@@ -0,0 +1,4 @@
+export const constants = {
+ DOCS_SCROLL_DURATION_MS: 0,
+ DOCS_CONTAINER_ID: 'documentation',
+};
diff --git a/packages/react-shared/src/ts/globals.d.ts b/packages/react-shared/src/ts/globals.d.ts
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/packages/react-shared/src/ts/globals.d.ts
diff --git a/packages/react-shared/src/ts/index.ts b/packages/react-shared/src/ts/index.ts
new file mode 100644
index 000000000..d33638e62
--- /dev/null
+++ b/packages/react-shared/src/ts/index.ts
@@ -0,0 +1,6 @@
+export { AnchorTitle } from './components/anchor_title';
+
+export { HeaderSizes, Styles } from './types';
+
+export { utils } from './utils';
+export { constants } from './constants';
diff --git a/packages/react-shared/src/ts/types.ts b/packages/react-shared/src/ts/types.ts
new file mode 100644
index 000000000..e4fe7bff9
--- /dev/null
+++ b/packages/react-shared/src/ts/types.ts
@@ -0,0 +1,9 @@
+export interface Styles {
+ [name: string]: React.CSSProperties;
+}
+
+export enum HeaderSizes {
+ H1 = 'h1',
+ H2 = 'h2',
+ H3 = 'h3',
+}
diff --git a/packages/react-shared/src/ts/utils.ts b/packages/react-shared/src/ts/utils.ts
new file mode 100644
index 000000000..822b67496
--- /dev/null
+++ b/packages/react-shared/src/ts/utils.ts
@@ -0,0 +1,5 @@
+export const utils = {
+ setUrlHash(anchorId: string) {
+ window.location.hash = anchorId;
+ },
+};