import React, { useState } from 'react'; import { useTranslation } from 'next-i18next'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import ReactMarkdown from 'react-markdown'; import { Collapse, UncontrolledTooltip, } from 'reactstrap'; import { useDraftOptions } from '~/stores/renderer'; type DraftProps = { path: string, isExist: boolean, index: number, markdown: string, clearDraft: (path: string) => void, } export const Draft = (props: DraftProps): JSX.Element => { const { path, isExist, index, markdown, clearDraft, } = props; const { t } = useTranslation(); const { data: rendererOptions } = useDraftOptions(); const [isPanelExpanded, setIsPanelExpanded] = useState(false); const [showCopiedMessage, setShowCopiedMessage] = useState(false); const changeToolTipLabel = () => { setShowCopiedMessage(true); setTimeout(() => { setShowCopiedMessage(false); }, 1000); }; const collapsePanelHandler = () => { setIsPanelExpanded(false); }; const expandPanelHandler = () => { setIsPanelExpanded(true); }; const Controls = () => { const tooltipTargetId = `draft-copied-tooltip_${index}`; return (
{isExist ? null : ( ) } { showCopiedMessage && ( copied! ) } { !showCopiedMessage && ( {t('Copy')} ) } { return clearDraft(path) }} >
); }; const AccordionTitle = () => { const iconClass = isPanelExpanded ? 'fa-rotate-90' : ''; return ( setIsPanelExpanded(!isPanelExpanded)}> {path} { isExist && ( {t('page exists')} ) } { !isExist && ( draft ) } ); }; return (
{ isPanelExpanded && ( {markdown} ) }
); };