|
@@ -9,54 +9,78 @@ import {
|
|
|
} from 'reactstrap';
|
|
} from 'reactstrap';
|
|
|
|
|
|
|
|
|
|
|
|
|
-const presetA = {
|
|
|
|
|
- name: 'presetA',
|
|
|
|
|
- value: '## Preset',
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-const presetB = {
|
|
|
|
|
- name: 'presetB',
|
|
|
|
|
- value: '### Preset',
|
|
|
|
|
-};
|
|
|
|
|
|
|
+type ITemplate = {
|
|
|
|
|
+ name: string,
|
|
|
|
|
+ markdown: string,
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-const presetC = {
|
|
|
|
|
- name: 'presetC',
|
|
|
|
|
- value: '#### Preset',
|
|
|
|
|
|
|
+const templates: ITemplate[] = [
|
|
|
|
|
+ {
|
|
|
|
|
+ name: 'presetA',
|
|
|
|
|
+ markdown: '## Preset',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: 'presetB',
|
|
|
|
|
+ markdown: '### Preset',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: 'presetC',
|
|
|
|
|
+ markdown: '#### Preset',
|
|
|
|
|
+ },
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+const TemplateRadioButton = ({ template }: { template: ITemplate }): JSX.Element => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div key={template.name} className="custom-control custom-radio">
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="radio"
|
|
|
|
|
+ className="custom-control-input"
|
|
|
|
|
+ id="string"
|
|
|
|
|
+ defaultValue={template.markdown}
|
|
|
|
|
+ // checked={this.state.linkerType === template.value}
|
|
|
|
|
+ // onChange={this.handleSelecteLinkerType(template.value)}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="custom-control-label" htmlFor="string">
|
|
|
|
|
+ {template.name}
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const templates = [presetA, presetB, presetC];
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
|
- onSave: (markdown: string) => void,
|
|
|
|
|
|
|
+ isOpen: boolean,
|
|
|
|
|
+ onClose: () => void,
|
|
|
|
|
+ onSave?: (markdown: string) => void,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const TemplateModal = (props: Props): JSX.Element => {
|
|
export const TemplateModal = (props: Props): JSX.Element => {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
- const { onSave } = props;
|
|
|
|
|
-
|
|
|
|
|
- const [isOpen, setOpen] = useState(false);
|
|
|
|
|
|
|
+ const { isOpen, onClose, onSave } = props;
|
|
|
|
|
|
|
|
const submitHandler = useCallback(() => {
|
|
const submitHandler = useCallback(() => {
|
|
|
if (onSave == null) {
|
|
if (onSave == null) {
|
|
|
|
|
+ onClose();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const markdown = '(select one)';
|
|
const markdown = '(select one)';
|
|
|
onSave(markdown);
|
|
onSave(markdown);
|
|
|
- }, [onSave]);
|
|
|
|
|
|
|
+ onClose();
|
|
|
|
|
+ }, [onClose, onSave]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <Modal className="link-edit-modal" isOpen={isOpen} toggle={() => setOpen(false)} size="lg" autoFocus={false}>
|
|
|
|
|
- <ModalHeader tag="h4" toggle={() => setOpen(false)} className="bg-primary text-light">
|
|
|
|
|
|
|
+ <Modal className="link-edit-modal" isOpen={isOpen} toggle={onClose} size="lg" autoFocus={false}>
|
|
|
|
|
+ <ModalHeader tag="h4" toggle={onClose} className="bg-primary text-light">
|
|
|
Template
|
|
Template
|
|
|
</ModalHeader>
|
|
</ModalHeader>
|
|
|
|
|
|
|
|
<ModalBody className="container">
|
|
<ModalBody className="container">
|
|
|
<div className="row">
|
|
<div className="row">
|
|
|
<div className="col-12">
|
|
<div className="col-12">
|
|
|
- { templates.map(template => <TemplateRadioButton template={template} />) }
|
|
|
|
|
|
|
+ { templates.map(template => <TemplateRadioButton key={template.name} template={template} />) }
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
@@ -65,7 +89,7 @@ export const TemplateModal = (props: Props): JSX.Element => {
|
|
|
</div> */}
|
|
</div> */}
|
|
|
</ModalBody>
|
|
</ModalBody>
|
|
|
<ModalFooter>
|
|
<ModalFooter>
|
|
|
- <button type="button" className="btn btn-sm btn-outline-secondary mx-1" onClick={() => setOpen(false)}>
|
|
|
|
|
|
|
+ <button type="button" className="btn btn-sm btn-outline-secondary mx-1" onClick={onClose}>
|
|
|
{t('Cancel')}
|
|
{t('Cancel')}
|
|
|
</button>
|
|
</button>
|
|
|
<button type="submit" className="btn btn-sm btn-primary mx-1" onClick={submitHandler}>
|
|
<button type="submit" className="btn btn-sm btn-primary mx-1" onClick={submitHandler}>
|