mirror of
https://github.com/plankanban/planka.git
synced 2025-08-09 07:25:24 +02:00
Use Markdown Editor in card description when editting
Since the card support markdown render, it'd be great if we also had markdown editor so for those who doesn't understand a lot about markdown could use this feature. With this new feature, there also a drawbacks such as no longer saving when input are onBlur since if we still using this `blur` callback, it'd be called when user trying to click at the editor toolbar such as **Bold** button.
This commit is contained in:
parent
e5bb502a60
commit
2fead013b3
1 changed files with 16 additions and 20 deletions
|
@ -1,19 +1,19 @@
|
||||||
import React, { useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
import React, { useCallback, useImperativeHandle, useState, useMemo } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import TextareaAutosize from 'react-textarea-autosize';
|
import TextareaAutosize from 'react-textarea-autosize';
|
||||||
import { Button, Form, TextArea } from 'semantic-ui-react';
|
import { Button, Form } from 'semantic-ui-react';
|
||||||
|
import SimpleMDE from 'react-simplemde-editor';
|
||||||
|
|
||||||
import { useClosableForm, useField } from '../../hooks';
|
import { useClosableForm, useField } from '../../hooks';
|
||||||
|
|
||||||
import styles from './DescriptionEdit.module.scss';
|
import styles from './DescriptionEdit.module.scss';
|
||||||
|
import 'easymde/dist/easymde.min.css';
|
||||||
|
|
||||||
const DescriptionEdit = React.forwardRef(({ children, defaultValue, onUpdate }, ref) => {
|
const DescriptionEdit = React.forwardRef(({ children, defaultValue, onUpdate }, ref) => {
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const [isOpened, setIsOpened] = useState(false);
|
const [isOpened, setIsOpened] = useState(false);
|
||||||
const [value, handleFieldChange, setValue] = useField(null);
|
const [value, , setValue] = useField(null);
|
||||||
|
|
||||||
const field = useRef(null);
|
|
||||||
|
|
||||||
const open = useCallback(() => {
|
const open = useCallback(() => {
|
||||||
setIsOpened(true);
|
setIsOpened(true);
|
||||||
|
@ -55,20 +55,18 @@ const DescriptionEdit = React.forwardRef(({ children, defaultValue, onUpdate },
|
||||||
[close],
|
[close],
|
||||||
);
|
);
|
||||||
|
|
||||||
const [handleFieldBlur, handleControlMouseOver, handleControlMouseOut] = useClosableForm(
|
const [, handleControlMouseOver, handleControlMouseOut] = useClosableForm(close, isOpened);
|
||||||
close,
|
|
||||||
isOpened,
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleSubmit = useCallback(() => {
|
const handleSubmit = useCallback(() => {
|
||||||
close();
|
close();
|
||||||
}, [close]);
|
}, [close]);
|
||||||
|
|
||||||
useEffect(() => {
|
const mdEditorOptions = useMemo(() => {
|
||||||
if (isOpened) {
|
return {
|
||||||
field.current.ref.current.focus();
|
autofocus: true,
|
||||||
}
|
spellChecker: false,
|
||||||
}, [isOpened]);
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!isOpened) {
|
if (!isOpened) {
|
||||||
return React.cloneElement(children, {
|
return React.cloneElement(children, {
|
||||||
|
@ -78,18 +76,16 @@ const DescriptionEdit = React.forwardRef(({ children, defaultValue, onUpdate },
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit}>
|
<Form onSubmit={handleSubmit}>
|
||||||
<TextArea
|
<SimpleMDE
|
||||||
ref={field}
|
|
||||||
as={TextareaAutosize}
|
as={TextareaAutosize}
|
||||||
value={value}
|
value={value}
|
||||||
placeholder={t('common.enterDescription')}
|
placeholder={t('common.enterDescription')}
|
||||||
minRows={3}
|
|
||||||
spellCheck={false}
|
|
||||||
className={styles.field}
|
className={styles.field}
|
||||||
|
options={mdEditorOptions}
|
||||||
onKeyDown={handleFieldKeyDown}
|
onKeyDown={handleFieldKeyDown}
|
||||||
onChange={handleFieldChange}
|
onChange={setValue}
|
||||||
onBlur={handleFieldBlur}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className={styles.controls}>
|
<div className={styles.controls}>
|
||||||
{/* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */}
|
{/* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */}
|
||||||
<Button
|
<Button
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue