import * as React from 'react'; import { Link as ScrollLink } from 'react-scroll'; import { HeaderSizes, Styles } from 'ts/types'; import { constants } from 'ts/utils/constants'; import { utils } from 'ts/utils/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', WebkitMarginBefore: '0.83em', WebkitMarginAfter: '0.83em', }, h2: { fontSize: '1.5em', WebkitMarginBefore: '0.83em', WebkitMarginAfter: '0.83em', }, h3: { fontSize: '1.17em', WebkitMarginBefore: '1em', WebkitMarginAfter: '1em', }, }; export class AnchorTitle extends React.Component { 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 (
{this.props.title}
); } private _setHoverState(isHovering: boolean) { this.setState({ isHovering, }); } }