import * as _ from 'lodash'; import * as React from 'react'; import * as ReactMarkdown from 'react-markdown'; import { Element as ScrollElement } from 'react-scroll'; import { HeaderSizes } from '../types'; import { colors } from '../utils/colors'; import { utils } from '../utils/utils'; import { AnchorTitle } from './anchor_title'; import { Container } from './container'; import { Link } from './link'; import { MarkdownCodeBlock } from './markdown_code_block'; import { MarkdownLinkBlock } from './markdown_link_block'; import { MarkdownParagraphBlock } from './markdown_paragraph_block'; export interface MarkdownSectionProps { sectionName: string; markdownContent: string; headerSize?: HeaderSizes; githubLink?: string; shouldReformatTitle?: boolean; alternativeSectionTitle?: string; } interface DefaultMarkdownSectionProps { headerSize: HeaderSizes; } type PropsWithDefaults = MarkdownSectionProps & DefaultMarkdownSectionProps; export interface MarkdownSectionState { shouldShowAnchor: boolean; } export class MarkdownSection extends React.Component { public static defaultProps: Partial = { headerSize: HeaderSizes.H3, shouldReformatTitle: true, }; constructor(props: MarkdownSectionProps) { super(props); this.state = { shouldShowAnchor: false, }; } public render(): React.ReactNode { const { sectionName, markdownContent, headerSize, githubLink } = this.props as PropsWithDefaults; const id = utils.getIdFromName(sectionName); const formattedSectionName = this.props.shouldReformatTitle ? utils.convertCamelCaseToSpaces(sectionName) : sectionName; const title = !_.isUndefined(this.props.alternativeSectionTitle) ? this.props.alternativeSectionTitle : formattedSectionName; return (
{!_.isUndefined(githubLink) && (
Edit on Github
)}
); } private _setAnchorVisibility(shouldShowAnchor: boolean): void { this.setState({ shouldShowAnchor, }); } }