2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2021-10-27 20:20:47 +02:00
|
|
|
import 'easymde/dist/easymde.min.css';
|
2022-02-08 12:36:47 +01:00
|
|
|
|
2022-04-01 05:26:45 +02:00
|
|
|
import './plugins/inline-attachment/inline-attachment';
|
|
|
|
import './plugins/inline-attachment/codemirror-4.inline-attachment';
|
2022-03-31 21:55:00 +02:00
|
|
|
import { IMG_CDN_PUBLISH_URL, JSON_RESPONSE_KEYS, UPLOAD_CONFIG } from 'constants/cdn_urls';
|
2021-10-27 20:20:47 +02:00
|
|
|
import { FF_MAX_CHARS_DEFAULT } from 'constants/form-field';
|
|
|
|
import { openEditorMenu, stopContextMenu } from 'util/context-menu';
|
2021-12-14 14:24:58 +01:00
|
|
|
import { lazyImport } from 'util/lazyImport';
|
2021-10-27 20:20:47 +02:00
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
2019-05-08 03:42:56 +02:00
|
|
|
import React from 'react';
|
2018-06-10 23:57:46 +02:00
|
|
|
import ReactDOMServer from 'react-dom/server';
|
2019-05-08 03:42:56 +02:00
|
|
|
import SimpleMDE from 'react-simplemde-editor';
|
2022-02-08 12:36:47 +01:00
|
|
|
import type { ElementRef } from 'react';
|
|
|
|
import { InputSimple, BlockWrapWrapper } from './input-simple';
|
|
|
|
import { InputSelect } from './input-select';
|
|
|
|
import { CountInfo, QuickAction, Label } from './common';
|
|
|
|
import { TextareaWrapper } from './slim-input-field';
|
2019-04-03 07:56:58 +02:00
|
|
|
|
2021-12-14 14:24:58 +01:00
|
|
|
// prettier-ignore
|
|
|
|
const TextareaWithSuggestions = lazyImport(() => import('component/textareaWithSuggestions' /* webpackChunkName: "suggestions" */));
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
2022-01-26 12:50:43 +01:00
|
|
|
uri?: string,
|
2018-06-14 22:10:50 +02:00
|
|
|
affixClass?: string, // class applied to prefix/postfix label
|
2018-09-22 03:20:58 +02:00
|
|
|
autoFocus?: boolean,
|
2019-02-18 18:24:56 +01:00
|
|
|
blockWrap: boolean,
|
2019-09-30 23:16:46 +02:00
|
|
|
charCount?: number,
|
2021-12-02 17:49:13 +01:00
|
|
|
children?: React$Node,
|
|
|
|
defaultValue?: string | number,
|
|
|
|
disabled?: boolean,
|
|
|
|
error?: string | boolean,
|
|
|
|
helper?: string | React$Node,
|
|
|
|
hideSuggestions?: boolean,
|
|
|
|
inputButton?: React$Node,
|
|
|
|
isLivestream?: boolean,
|
2022-02-08 12:36:47 +01:00
|
|
|
label?: any,
|
2021-12-02 17:49:13 +01:00
|
|
|
labelOnLeft: boolean,
|
2020-03-25 04:15:05 +01:00
|
|
|
max?: number,
|
2021-12-02 17:49:13 +01:00
|
|
|
min?: number,
|
|
|
|
name: string,
|
|
|
|
placeholder?: string | number,
|
|
|
|
postfix?: string,
|
|
|
|
prefix?: string,
|
2020-05-21 09:25:37 +02:00
|
|
|
quickActionLabel?: string,
|
2021-12-02 17:49:13 +01:00
|
|
|
range?: number,
|
|
|
|
readOnly?: boolean,
|
|
|
|
stretch?: boolean,
|
|
|
|
textAreaMaxLength?: number,
|
|
|
|
type?: string,
|
2021-04-23 21:59:48 +02:00
|
|
|
value?: string | number,
|
2022-02-04 21:59:11 +01:00
|
|
|
slimInput?: boolean,
|
2022-02-07 20:30:42 +01:00
|
|
|
slimInputButtonRef?: any,
|
2022-02-04 21:59:11 +01:00
|
|
|
commentSelectorsProps?: any,
|
2022-02-07 20:30:42 +01:00
|
|
|
showSelectors?: any,
|
2022-02-04 21:59:11 +01:00
|
|
|
submitButtonRef?: any,
|
|
|
|
tipModalOpen?: boolean,
|
2022-02-07 14:37:19 +01:00
|
|
|
noticeLabel?: any,
|
2022-02-08 17:49:46 +01:00
|
|
|
onSlimInputClose?: () => void,
|
2021-10-27 20:20:47 +02:00
|
|
|
onChange?: (any) => any,
|
2022-02-07 20:30:42 +01:00
|
|
|
setShowSelectors?: ({ tab?: string, open: boolean }) => void,
|
2021-12-02 17:49:13 +01:00
|
|
|
quickActionHandler?: (any) => any,
|
|
|
|
render?: () => React$Node,
|
2022-02-02 13:47:04 +01:00
|
|
|
handleTip?: (isLBC: boolean) => any,
|
|
|
|
handleSubmit?: () => any,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2022-02-04 21:59:11 +01:00
|
|
|
type State = {
|
|
|
|
drawerOpen: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
export class FormField extends React.PureComponent<Props, State> {
|
2021-10-27 20:20:47 +02:00
|
|
|
static defaultProps = { labelOnLeft: false, blockWrap: true };
|
2019-02-13 17:27:20 +01:00
|
|
|
|
2019-04-24 16:02:08 +02:00
|
|
|
input: { current: ElementRef<any> };
|
2019-02-20 06:20:29 +01:00
|
|
|
|
2019-02-18 18:24:56 +01:00
|
|
|
constructor(props: Props) {
|
2018-09-22 03:20:58 +02:00
|
|
|
super(props);
|
|
|
|
this.input = React.createRef();
|
2022-02-04 21:59:11 +01:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
drawerOpen: false,
|
|
|
|
};
|
2018-09-22 03:20:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2022-02-07 21:37:22 +01:00
|
|
|
const { autoFocus, showSelectors, slimInput } = this.props;
|
2018-09-22 03:20:58 +02:00
|
|
|
const input = this.input.current;
|
|
|
|
|
2021-10-27 20:20:47 +02:00
|
|
|
if (input && autoFocus) input.focus();
|
2022-02-07 20:30:42 +01:00
|
|
|
if (slimInput && showSelectors && showSelectors.open && input) input.blur();
|
2022-02-04 21:59:11 +01:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
render() {
|
|
|
|
const {
|
2022-01-26 12:50:43 +01:00
|
|
|
uri,
|
2018-06-14 22:10:50 +02:00
|
|
|
affixClass,
|
2018-09-22 03:20:58 +02:00
|
|
|
autoFocus,
|
2019-02-18 18:24:56 +01:00
|
|
|
blockWrap,
|
2019-09-30 23:16:46 +02:00
|
|
|
charCount,
|
2021-12-02 17:49:13 +01:00
|
|
|
children,
|
|
|
|
error,
|
|
|
|
helper,
|
|
|
|
hideSuggestions,
|
|
|
|
inputButton,
|
|
|
|
isLivestream,
|
|
|
|
label,
|
|
|
|
labelOnLeft,
|
|
|
|
name,
|
|
|
|
postfix,
|
|
|
|
prefix,
|
|
|
|
quickActionLabel,
|
|
|
|
stretch,
|
|
|
|
textAreaMaxLength,
|
|
|
|
type,
|
2022-02-04 21:59:11 +01:00
|
|
|
slimInput,
|
2022-02-07 20:30:42 +01:00
|
|
|
slimInputButtonRef,
|
2022-02-04 21:59:11 +01:00
|
|
|
commentSelectorsProps,
|
|
|
|
showSelectors,
|
|
|
|
submitButtonRef,
|
|
|
|
tipModalOpen,
|
2022-02-07 14:37:19 +01:00
|
|
|
noticeLabel,
|
2022-02-08 17:49:46 +01:00
|
|
|
onSlimInputClose,
|
2021-12-02 17:49:13 +01:00
|
|
|
quickActionHandler,
|
2022-02-04 21:59:11 +01:00
|
|
|
setShowSelectors,
|
2021-12-02 17:49:13 +01:00
|
|
|
render,
|
2022-02-02 13:47:04 +01:00
|
|
|
handleTip,
|
|
|
|
handleSubmit,
|
2018-03-26 23:32:43 +02:00
|
|
|
...inputProps
|
|
|
|
} = this.props;
|
2021-10-27 20:20:47 +02:00
|
|
|
|
2018-04-05 23:26:20 +02:00
|
|
|
const errorMessage = typeof error === 'object' ? error.message : error;
|
2021-10-27 20:20:47 +02:00
|
|
|
|
2022-02-08 12:36:47 +01:00
|
|
|
const wrapperProps = { type, helper };
|
|
|
|
const labelProps = { name, label };
|
|
|
|
const countInfoProps = { charCount, textAreaMaxLength };
|
|
|
|
const quickActionProps = { label: quickActionLabel, quickActionHandler };
|
|
|
|
const inputSimpleProps = { name, label, ...inputProps };
|
|
|
|
const inputSelectProps = { name, error, label, children, ...inputProps };
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'radio':
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
|
|
|
<BlockWrapWrapper blockWrap={blockWrap}>
|
|
|
|
<InputSimple {...inputSimpleProps} type="radio" />
|
|
|
|
</BlockWrapWrapper>
|
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
case 'checkbox':
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
|
|
|
<div className="checkbox">
|
|
|
|
<InputSimple {...inputSimpleProps} type="checkbox" />
|
|
|
|
</div>
|
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
case 'range':
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
|
|
|
<div className="range">
|
|
|
|
<InputSimple {...inputSimpleProps} type="range" />
|
|
|
|
</div>
|
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
case 'select':
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
|
|
|
<InputSelect {...inputSelectProps} />
|
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
case 'select-tiny':
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
|
|
|
<InputSelect {...inputSelectProps} className="select--slim" />
|
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
case 'markdown':
|
|
|
|
const handleEvents = { contextmenu: openEditorMenu };
|
|
|
|
|
|
|
|
const getInstance = (editor) => {
|
|
|
|
// SimpleMDE max char check
|
|
|
|
editor.codemirror.on('beforeChange', (instance, changes) => {
|
|
|
|
if (textAreaMaxLength && changes.update) {
|
2022-03-31 21:55:00 +02:00
|
|
|
let str = changes.text.join('\n');
|
|
|
|
let delta = str.length - (instance.indexFromPos(changes.to) - instance.indexFromPos(changes.from));
|
2022-02-08 12:36:47 +01:00
|
|
|
|
|
|
|
if (delta <= 0) return;
|
|
|
|
|
|
|
|
delta = instance.getValue().length + delta - textAreaMaxLength;
|
|
|
|
if (delta > 0) {
|
|
|
|
str = str.substr(0, str.length - delta);
|
|
|
|
changes.update(changes.from, changes.to, str.split('\n'));
|
2021-02-26 08:38:33 +01:00
|
|
|
}
|
2022-02-08 12:36:47 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// "Create Link (Ctrl-K)": highlight URL instead of label:
|
|
|
|
editor.codemirror.on('changes', (instance, changes) => {
|
|
|
|
try {
|
|
|
|
// Grab the last change from the buffered list. I assume the
|
|
|
|
// buffered one ('changes', instead of 'change') is more efficient,
|
|
|
|
// and that "Create Link" will always end up last in the list.
|
|
|
|
const lastChange = changes[changes.length - 1];
|
|
|
|
if (lastChange.origin === '+input') {
|
|
|
|
// https://github.com/Ionaru/easy-markdown-editor/blob/8fa54c496f98621d5f45f57577ce630bee8c41ee/src/js/easymde.js#L765
|
|
|
|
const EASYMDE_URL_PLACEHOLDER = '(https://)';
|
|
|
|
|
|
|
|
// The URL placeholder is always placed last, so just look at the
|
|
|
|
// last text in the array to also cover the multi-line case:
|
|
|
|
const urlLineText = lastChange.text[lastChange.text.length - 1];
|
|
|
|
|
|
|
|
if (urlLineText.endsWith(EASYMDE_URL_PLACEHOLDER) && urlLineText !== '[]' + EASYMDE_URL_PLACEHOLDER) {
|
|
|
|
const from = lastChange.from;
|
|
|
|
const to = lastChange.to;
|
|
|
|
const isSelectionMultiline = lastChange.text.length > 1;
|
|
|
|
const baseIndex = isSelectionMultiline ? 0 : from.ch;
|
|
|
|
|
|
|
|
// Everything works fine for the [Ctrl-K] case, but for the
|
|
|
|
// [Button] case, this handler happens before the original
|
|
|
|
// code, thus our change got wiped out.
|
|
|
|
// Add a small delay to handle that case.
|
|
|
|
setTimeout(() => {
|
|
|
|
instance.setSelection(
|
|
|
|
{ line: to.line, ch: baseIndex + urlLineText.lastIndexOf('(') + 1 },
|
|
|
|
{ line: to.line, ch: baseIndex + urlLineText.lastIndexOf(')') }
|
|
|
|
);
|
|
|
|
}, 25);
|
2021-10-27 20:20:47 +02:00
|
|
|
}
|
2022-02-08 12:36:47 +01:00
|
|
|
}
|
|
|
|
} catch (e) {} // Do nothing (revert to original behavior)
|
|
|
|
});
|
2022-03-31 21:55:00 +02:00
|
|
|
|
|
|
|
// Add ability to upload pasted/dragged image (https://github.com/sparksuite/simplemde-markdown-editor/issues/328#issuecomment-227075500)
|
|
|
|
window.inlineAttachment.editors.codemirror4.attach(editor.codemirror, {
|
|
|
|
uploadUrl: IMG_CDN_PUBLISH_URL,
|
|
|
|
uploadFieldName: UPLOAD_CONFIG.BLOB_KEY,
|
|
|
|
extraParams: { [UPLOAD_CONFIG.ACTION_KEY]: UPLOAD_CONFIG.ACTION_VAL },
|
|
|
|
filenameTag: '{filename}',
|
|
|
|
urlText: '![image]({filename})',
|
|
|
|
jsonFieldName: JSON_RESPONSE_KEYS.UPLOADED_URL,
|
2022-04-01 05:26:45 +02:00
|
|
|
errorText: '![image]("failed to upload file")',
|
2022-03-31 21:55:00 +02:00
|
|
|
});
|
2022-02-08 12:36:47 +01:00
|
|
|
};
|
2021-10-27 20:20:47 +02:00
|
|
|
|
2022-02-08 12:36:47 +01:00
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
2021-10-27 20:20:47 +02:00
|
|
|
<div className="form-field--SimpleMDE" onContextMenu={stopContextMenu}>
|
|
|
|
<fieldset-section>
|
|
|
|
<div className="form-field__two-column">
|
|
|
|
<div>
|
2022-02-08 12:36:47 +01:00
|
|
|
<Label {...labelProps} />
|
2021-10-27 20:20:47 +02:00
|
|
|
</div>
|
2022-02-08 12:36:47 +01:00
|
|
|
|
|
|
|
<QuickAction {...quickActionProps} />
|
2021-10-27 20:20:47 +02:00
|
|
|
</div>
|
2022-02-08 12:36:47 +01:00
|
|
|
|
2021-10-27 20:20:47 +02:00
|
|
|
<SimpleMDE
|
|
|
|
{...inputProps}
|
|
|
|
id={name}
|
|
|
|
type="textarea"
|
|
|
|
events={handleEvents}
|
|
|
|
getMdeInstance={getInstance}
|
|
|
|
options={{
|
|
|
|
spellChecker: true,
|
|
|
|
hideIcons: ['heading', 'image', 'fullscreen', 'side-by-side'],
|
2022-03-31 21:55:00 +02:00
|
|
|
status: [
|
|
|
|
{
|
|
|
|
className: 'editor-statusbar__upload-hint',
|
|
|
|
defaultValue: (el) => {
|
|
|
|
el.innerHTML = __('Attach images by pasting or drag-and-drop.');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'lines',
|
|
|
|
'words',
|
|
|
|
'cursor',
|
|
|
|
],
|
2021-10-27 20:20:47 +02:00
|
|
|
previewRender(plainText) {
|
|
|
|
const preview = <MarkdownPreview content={plainText} noDataStore />;
|
|
|
|
return ReactDOMServer.renderToString(preview);
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
2022-02-08 12:36:47 +01:00
|
|
|
|
|
|
|
<CountInfo {...countInfoProps} />
|
2021-10-27 20:20:47 +02:00
|
|
|
</fieldset-section>
|
|
|
|
</div>
|
2022-02-08 12:36:47 +01:00
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
case 'textarea':
|
|
|
|
const closeSelector =
|
|
|
|
setShowSelectors && showSelectors
|
|
|
|
? () => setShowSelectors({ tab: showSelectors.tab || undefined, open: false })
|
|
|
|
: () => {};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
2019-02-13 17:27:20 +01:00
|
|
|
<fieldset-section>
|
2022-02-04 21:59:11 +01:00
|
|
|
<TextareaWrapper
|
|
|
|
isDrawerOpen={Boolean(this.state.drawerOpen)}
|
|
|
|
toggleDrawer={() => this.setState({ drawerOpen: !this.state.drawerOpen })}
|
2022-02-07 21:37:22 +01:00
|
|
|
closeSelector={closeSelector}
|
2022-02-04 21:59:11 +01:00
|
|
|
commentSelectorsProps={commentSelectorsProps}
|
2022-02-07 20:30:42 +01:00
|
|
|
showSelectors={Boolean(showSelectors && showSelectors.open)}
|
2022-02-04 21:59:11 +01:00
|
|
|
slimInput={slimInput}
|
2022-02-07 20:30:42 +01:00
|
|
|
slimInputButtonRef={slimInputButtonRef}
|
2022-02-08 17:49:46 +01:00
|
|
|
onSlimInputClose={onSlimInputClose}
|
2022-02-04 21:59:11 +01:00
|
|
|
tipModalOpen={tipModalOpen}
|
|
|
|
>
|
2022-02-08 12:36:47 +01:00
|
|
|
{(!slimInput || this.state.drawerOpen) && label && (
|
2022-02-04 21:59:11 +01:00
|
|
|
<div className="form-field__two-column">
|
2022-02-08 12:36:47 +01:00
|
|
|
<Label {...labelProps} />
|
|
|
|
|
|
|
|
<QuickAction {...quickActionProps} />
|
|
|
|
|
|
|
|
<CountInfo {...countInfoProps} />
|
2022-02-04 21:59:11 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2021-12-02 17:49:13 +01:00
|
|
|
|
2022-02-07 14:37:19 +01:00
|
|
|
{noticeLabel}
|
|
|
|
|
2022-02-04 21:59:11 +01:00
|
|
|
{hideSuggestions ? (
|
|
|
|
<textarea
|
2021-12-14 14:24:58 +01:00
|
|
|
type={type}
|
|
|
|
id={name}
|
|
|
|
maxLength={textAreaMaxLength || FF_MAX_CHARS_DEFAULT}
|
2022-02-04 21:59:11 +01:00
|
|
|
ref={this.input}
|
2021-12-14 14:24:58 +01:00
|
|
|
{...inputProps}
|
|
|
|
/>
|
2022-02-04 21:59:11 +01:00
|
|
|
) : (
|
|
|
|
<React.Suspense fallback={null}>
|
|
|
|
<TextareaWithSuggestions
|
|
|
|
uri={uri}
|
|
|
|
type={type}
|
|
|
|
id={name}
|
|
|
|
maxLength={textAreaMaxLength || FF_MAX_CHARS_DEFAULT}
|
|
|
|
inputRef={this.input}
|
|
|
|
isLivestream={isLivestream}
|
2022-02-07 20:30:42 +01:00
|
|
|
toggleSelectors={
|
|
|
|
setShowSelectors && showSelectors
|
2022-02-09 19:26:43 +01:00
|
|
|
? () => {
|
|
|
|
const input = this.input.current;
|
|
|
|
if (!showSelectors.open && input) input.blur();
|
|
|
|
setShowSelectors({ tab: showSelectors.tab || undefined, open: !showSelectors.open });
|
|
|
|
}
|
2022-02-07 20:30:42 +01:00
|
|
|
: undefined
|
|
|
|
}
|
2022-02-04 21:59:11 +01:00
|
|
|
handleTip={handleTip}
|
|
|
|
handleSubmit={() => {
|
|
|
|
if (handleSubmit) handleSubmit();
|
|
|
|
if (slimInput) this.setState({ drawerOpen: false });
|
2022-02-07 21:37:22 +01:00
|
|
|
closeSelector();
|
2022-02-04 21:59:11 +01:00
|
|
|
}}
|
|
|
|
claimIsMine={commentSelectorsProps && commentSelectorsProps.claimIsMine}
|
|
|
|
{...inputProps}
|
2022-02-07 20:30:42 +01:00
|
|
|
slimInput={slimInput}
|
2022-02-04 21:59:11 +01:00
|
|
|
handlePreventClick={
|
|
|
|
!this.state.drawerOpen ? () => this.setState({ drawerOpen: true }) : undefined
|
|
|
|
}
|
2022-02-09 19:26:43 +01:00
|
|
|
autoFocus={this.state.drawerOpen && (!showSelectors || !showSelectors.open)}
|
2022-02-04 21:59:11 +01:00
|
|
|
submitButtonRef={submitButtonRef}
|
|
|
|
/>
|
|
|
|
</React.Suspense>
|
|
|
|
)}
|
|
|
|
</TextareaWrapper>
|
2021-10-27 20:20:47 +02:00
|
|
|
</fieldset-section>
|
2022-02-08 12:36:47 +01:00
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
const inputElementProps = { type, name, ref: this.input, ...inputProps };
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormFieldWrapper {...wrapperProps}>
|
2019-02-13 17:27:20 +01:00
|
|
|
<fieldset-section>
|
2022-02-08 12:36:47 +01:00
|
|
|
{(label || errorMessage) && <Label {...labelProps} errorMessage={errorMessage} />}
|
|
|
|
|
2019-09-26 18:07:11 +02:00
|
|
|
{prefix && <label htmlFor={name}>{prefix}</label>}
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2022-02-08 12:36:47 +01:00
|
|
|
{inputButton ? (
|
|
|
|
<input-submit>
|
|
|
|
<input {...inputElementProps} />
|
|
|
|
{inputButton}
|
|
|
|
</input-submit>
|
|
|
|
) : (
|
|
|
|
<input {...inputElementProps} />
|
|
|
|
)}
|
|
|
|
</fieldset-section>
|
|
|
|
</FormFieldWrapper>
|
|
|
|
);
|
|
|
|
}
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FormField;
|
2022-02-04 21:59:11 +01:00
|
|
|
|
2022-02-08 12:36:47 +01:00
|
|
|
type WrapperProps = {
|
|
|
|
type?: string,
|
|
|
|
children?: any,
|
|
|
|
helper?: any,
|
2022-02-04 21:59:11 +01:00
|
|
|
};
|
|
|
|
|
2022-02-08 12:36:47 +01:00
|
|
|
const FormFieldWrapper = (wrapperProps: WrapperProps) => {
|
|
|
|
const { type, children, helper } = wrapperProps;
|
2022-02-04 21:59:11 +01:00
|
|
|
|
2022-02-08 12:36:47 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{type && children}
|
|
|
|
{helper && <div className="form-field__help">{helper}</div>}
|
|
|
|
</>
|
2022-02-04 21:59:11 +01:00
|
|
|
);
|
2022-02-08 12:36:47 +01:00
|
|
|
};
|