refactor: convert function expressions to declarations (#4926)
This commit is contained in:
committed by
GitHub
parent
c0236536dd
commit
141a2eba56
@ -4,7 +4,7 @@ import { Map } from 'immutable';
|
||||
import { isString } from 'lodash';
|
||||
import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
|
||||
|
||||
const toValue = (value, field) => {
|
||||
function toValue(value, field) {
|
||||
if (isString(value)) {
|
||||
return value;
|
||||
}
|
||||
@ -12,15 +12,17 @@ const toValue = (value, field) => {
|
||||
return value.get(field.getIn(['keys', 'code'], 'code'), '');
|
||||
}
|
||||
return '';
|
||||
};
|
||||
}
|
||||
|
||||
const CodePreview = props => (
|
||||
<WidgetPreviewContainer>
|
||||
<pre>
|
||||
<code>{toValue(props.value, props.field)}</code>
|
||||
</pre>
|
||||
</WidgetPreviewContainer>
|
||||
);
|
||||
function CodePreview(props) {
|
||||
return (
|
||||
<WidgetPreviewContainer>
|
||||
<pre>
|
||||
<code>{toValue(props.value, props.field)}</code>
|
||||
</pre>
|
||||
</WidgetPreviewContainer>
|
||||
);
|
||||
}
|
||||
|
||||
CodePreview.propTypes = {
|
||||
value: PropTypes.node,
|
||||
|
@ -22,10 +22,12 @@ const StyledSettingsButton = styled.button`
|
||||
}
|
||||
`;
|
||||
|
||||
const SettingsButton = ({ showClose, onClick }) => (
|
||||
<StyledSettingsButton onClick={onClick}>
|
||||
<Icon type={showClose ? 'close' : 'settings'} size="small" />
|
||||
</StyledSettingsButton>
|
||||
);
|
||||
function SettingsButton({ showClose, onClick }) {
|
||||
return (
|
||||
<StyledSettingsButton onClick={onClick}>
|
||||
<Icon type={showClose ? 'close' : 'settings'} size="small" />
|
||||
</StyledSettingsButton>
|
||||
);
|
||||
}
|
||||
|
||||
export default SettingsButton;
|
||||
|
@ -38,20 +38,22 @@ const SettingsSectionTitle = styled.h3`
|
||||
}
|
||||
`;
|
||||
|
||||
const SettingsSelect = ({ value, options, onChange, forID, type, autoFocus }) => (
|
||||
<Select
|
||||
inputId={`${forID}-select-${type}`}
|
||||
styles={languageSelectStyles}
|
||||
value={value}
|
||||
options={options}
|
||||
onChange={opt => onChange(opt.value)}
|
||||
menuPlacement="auto"
|
||||
captureMenuScroll={false}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
);
|
||||
function SettingsSelect({ value, options, onChange, forID, type, autoFocus }) {
|
||||
return (
|
||||
<Select
|
||||
inputId={`${forID}-select-${type}`}
|
||||
styles={languageSelectStyles}
|
||||
value={value}
|
||||
options={options}
|
||||
onChange={opt => onChange(opt.value)}
|
||||
menuPlacement="auto"
|
||||
captureMenuScroll={false}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const SettingsPane = ({
|
||||
function SettingsPane({
|
||||
hideSettings,
|
||||
forID,
|
||||
modes,
|
||||
@ -64,48 +66,50 @@ const SettingsPane = ({
|
||||
onChangeLang,
|
||||
onChangeTheme,
|
||||
onChangeKeyMap,
|
||||
}) => (
|
||||
<SettingsPaneContainer onKeyDown={e => isHotkey('esc', e) && hideSettings()}>
|
||||
<SettingsButton onClick={hideSettings} showClose={true} />
|
||||
{allowLanguageSelection && (
|
||||
<>
|
||||
<SettingsSectionTitle>Field Settings</SettingsSectionTitle>
|
||||
<SettingsFieldLabel htmlFor={`${forID}-select-mode`}>Mode</SettingsFieldLabel>
|
||||
<SettingsSelect
|
||||
type="mode"
|
||||
forID={forID}
|
||||
value={mode}
|
||||
options={modes}
|
||||
onChange={onChangeLang}
|
||||
autoFocus
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<>
|
||||
<SettingsSectionTitle>Global Settings</SettingsSectionTitle>
|
||||
{themes && (
|
||||
}) {
|
||||
return (
|
||||
<SettingsPaneContainer onKeyDown={e => isHotkey('esc', e) && hideSettings()}>
|
||||
<SettingsButton onClick={hideSettings} showClose={true} />
|
||||
{allowLanguageSelection && (
|
||||
<>
|
||||
<SettingsFieldLabel htmlFor={`${forID}-select-theme`}>Theme</SettingsFieldLabel>
|
||||
<SettingsSectionTitle>Field Settings</SettingsSectionTitle>
|
||||
<SettingsFieldLabel htmlFor={`${forID}-select-mode`}>Mode</SettingsFieldLabel>
|
||||
<SettingsSelect
|
||||
type="theme"
|
||||
type="mode"
|
||||
forID={forID}
|
||||
value={{ value: theme, label: theme }}
|
||||
options={themes.map(t => ({ value: t, label: t }))}
|
||||
onChange={onChangeTheme}
|
||||
autoFocus={!allowLanguageSelection}
|
||||
value={mode}
|
||||
options={modes}
|
||||
onChange={onChangeLang}
|
||||
autoFocus
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<SettingsFieldLabel htmlFor={`${forID}-select-keymap`}>KeyMap</SettingsFieldLabel>
|
||||
<SettingsSelect
|
||||
type="keymap"
|
||||
forID={forID}
|
||||
value={keyMap}
|
||||
options={keyMaps}
|
||||
onChange={onChangeKeyMap}
|
||||
/>
|
||||
</>
|
||||
</SettingsPaneContainer>
|
||||
);
|
||||
<>
|
||||
<SettingsSectionTitle>Global Settings</SettingsSectionTitle>
|
||||
{themes && (
|
||||
<>
|
||||
<SettingsFieldLabel htmlFor={`${forID}-select-theme`}>Theme</SettingsFieldLabel>
|
||||
<SettingsSelect
|
||||
type="theme"
|
||||
forID={forID}
|
||||
value={{ value: theme, label: theme }}
|
||||
options={themes.map(t => ({ value: t, label: t }))}
|
||||
onChange={onChangeTheme}
|
||||
autoFocus={!allowLanguageSelection}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<SettingsFieldLabel htmlFor={`${forID}-select-keymap`}>KeyMap</SettingsFieldLabel>
|
||||
<SettingsSelect
|
||||
type="keymap"
|
||||
forID={forID}
|
||||
value={keyMap}
|
||||
options={keyMaps}
|
||||
onChange={onChangeKeyMap}
|
||||
/>
|
||||
</>
|
||||
</SettingsPaneContainer>
|
||||
);
|
||||
}
|
||||
|
||||
export default SettingsPane;
|
||||
|
@ -2,15 +2,17 @@ import controlComponent from './CodeControl';
|
||||
import previewComponent from './CodePreview';
|
||||
import schema from './schema';
|
||||
|
||||
const Widget = (opts = {}) => ({
|
||||
name: 'code',
|
||||
controlComponent,
|
||||
previewComponent,
|
||||
schema,
|
||||
allowMapValue: true,
|
||||
codeMirrorConfig: {},
|
||||
...opts,
|
||||
});
|
||||
function Widget(opts = {}) {
|
||||
return {
|
||||
name: 'code',
|
||||
controlComponent,
|
||||
previewComponent,
|
||||
schema,
|
||||
allowMapValue: true,
|
||||
codeMirrorConfig: {},
|
||||
...opts,
|
||||
};
|
||||
}
|
||||
|
||||
export const NetlifyCmsWidgetCode = { Widget, controlComponent, previewComponent };
|
||||
export default NetlifyCmsWidgetCode;
|
||||
|
Reference in New Issue
Block a user