import { h, Component } from 'preact'; import PropTypes from 'prop-types'; import { Modal } from '@crayons'; export class Help extends Component { constructor(props) { super(props); this.state = { liquidHelpHTML: document.getElementById('editor-liquid-help') && document.getElementById('editor-liquid-help').innerHTML, markdownHelpHTML: document.getElementById('editor-markdown-help') && document.getElementById('editor-markdown-help').innerHTML, frontmatterHelpHTML: document.getElementById('editor-frontmatter-help') && document.getElementById('editor-frontmatter-help').innerHTML, }; } setCommonProps = ({ liquidShowing = false, markdownShowing = false, frontmatterShowing = false, }) => { return { liquidShowing, markdownShowing, frontmatterShowing, }; }; toggleModal = (varShowing) => (e) => { e.preventDefault(); this.setState((prevState) => ({ ...this.setCommonProps({ [varShowing]: !prevState[varShowing], }), })); }; renderArticleFormTitleHelp = () => { return (

Writing a Great Post Title

); }; renderTagInputHelp = () => { return (

Tagging Guidelines

); }; renderBasicEditorHelp = () => { return (
You are currently using the basic markdown editor that uses {' '} Jekyll front matter . You can also use the {' '} rich+markdown {' '} editor you can find in {' '} UX settings Open UX settings .
); }; renderFormatHelp = () => { return (

Editor Basics

); }; renderModal = (onClose, title, helpHtml) => { return (
); }; render() { const { previewShowing, helpFor, helpPosition, version } = this.props; const { liquidHelpHTML, markdownHelpHTML, frontmatterHelpHTML, liquidShowing, markdownShowing, frontmatterShowing, } = this.state; return (
{!previewShowing && (
{helpFor === 'article-form-title' && this.renderArticleFormTitleHelp()} {helpFor === 'tag-input' && this.renderTagInputHelp()} {version === 'v1' && this.renderBasicEditorHelp()} {(helpFor === 'article_body_markdown' || version === 'v1') && this.renderFormatHelp()}
)} {liquidShowing && this.renderModal( this.toggleModal('liquidShowing'), '🌊 Liquid Tags', liquidHelpHTML, )} {markdownShowing && this.renderModal( this.toggleModal('markdownShowing'), '✍️ Markdown', markdownHelpHTML, )} {frontmatterShowing && this.renderModal( this.toggleModal('frontmatterShowing'), 'Jekyll Front Matter', frontmatterHelpHTML, )}
); } } Help.propTypes = { previewShowing: PropTypes.bool.isRequired, helpFor: PropTypes.string.isRequired, helpPosition: PropTypes.string.isRequired, version: PropTypes.string.isRequired, }; Help.displayName = 'Help';