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
-
Think of your post title as a super short (but compelling!)
description — like an overview of the actual post in one short
sentence.
-
Use keywords where appropriate to help ensure people can find your
post by search.
);
};
renderTagInputHelp = () => {
return (
Tagging Guidelines
- Tags help people find your post.
-
Think of tags as the topics or categories that best describe your
post.
-
Add up to four tags per post. Combine tags to reach the appropriate
subcommunities.
- Use existing tags whenever possible.
-
Some tags, such as “help” or “healthydebate”, have special posting
guidelines.
);
};
renderBasicEditorHelp = () => {
return (
);
};
renderFormatHelp = () => {
return (
Editor Basics
-
Use
{' '}
Markdown
{' '}
to write and format posts.
-
You can use
{' '}
Liquid tags
{' '}
to add rich content such as Tweets, YouTube videos, etc.
);
};
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';