Skip to content

Commit 4f2e3f2

Browse files
committed
Reformatting form components, drop redux-form dependency
1 parent 924f5e3 commit 4f2e3f2

File tree

9 files changed

+65
-64
lines changed

9 files changed

+65
-64
lines changed

src/Form/Field.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ function Field({ children, info, meta }) {
1616
return (
1717
<fieldset className="form-group">
1818
{children}
19-
{meta.error &&
20-
<div className="form-text text-danger">
21-
{meta.error}
22-
</div>}
23-
{info &&
24-
<div className="form-text text-muted">
25-
{info}
26-
</div>}
19+
{meta.error && <div className="form-text text-danger">{meta.error}</div>}
20+
{info && <div className="form-text text-muted">{info}</div>}
2721
</fieldset>
2822
);
2923
}

src/Form/Form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import cx from 'classnames';
4-
import { Field } from 'redux-form';
4+
import { Field } from 'formik';
55
import FormText from './FormText';
66
import FormInput from './FormInput';
77
import FormPicker from './FormPicker';

src/Form/FormCheckbox.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const defaultProps = {
1919
size: null,
2020
};
2121

22-
function FormCheckbox({ legend, label, info, size, input, meta }) {
22+
function FormCheckbox({
23+
legend, label, info, size, input, meta,
24+
}) {
2325
const classes = cx('custom-control custom-checkbox', {
2426
'custom-control-sm': size === 'sm',
2527
});
@@ -29,10 +31,7 @@ function FormCheckbox({ legend, label, info, size, input, meta }) {
2931

3032
return (
3133
<Field meta={meta} info={info}>
32-
{legend &&
33-
<legend className="form-group-legend">
34-
{legend}
35-
</legend>}
34+
{legend && <legend className="form-group-legend">{legend}</legend>}
3635
<label className={classes} htmlFor={`${meta.form}-${input.name}`}>
3736
<input
3837
type="checkbox"
@@ -47,9 +46,7 @@ function FormCheckbox({ legend, label, info, size, input, meta }) {
4746
className={inputClasses}
4847
/>
4948
<div className="custom-control-indicator" />
50-
<div className="custom-control-description">
51-
{label}
52-
</div>
49+
<div className="custom-control-description">{label}</div>
5350
</label>
5451
</Field>
5552
);

src/Form/FormChoice.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const defaultProps = {
2121
size: null,
2222
};
2323

24-
function FormChoice({ legend, options, info, multiple, size, input, meta }) {
24+
function FormChoice({
25+
legend, options, info, multiple, size, input, meta,
26+
}) {
2527
let index = 0;
2628

2729
const getIndex = () => index;
@@ -40,18 +42,15 @@ function FormChoice({ legend, options, info, multiple, size, input, meta }) {
4042

4143
return (
4244
<Field meta={meta} info={info}>
43-
{legend &&
44-
<legend className="form-group-legend">
45-
{legend}
46-
</legend>}
45+
{legend && <legend className="form-group-legend">{legend}</legend>}
4746
<div className="custom-controls-stacked">
48-
{options.map(option =>
49-
(<label
47+
{options.map(option => (
48+
<label
5049
key={getIndex()}
5150
className={classes}
5251
htmlFor={`${meta.form}-${input.name}-${getIndex()}`}
5352
>
54-
{!multiple &&
53+
{!multiple && (
5554
<input
5655
type="radio"
5756
id={`${meta.form}-${input.name}-${getIndex()}`}
@@ -67,8 +66,9 @@ function FormChoice({ legend, options, info, multiple, size, input, meta }) {
6766
input.onBlur(input.value);
6867
}}
6968
className={inputClasses}
70-
/>}
71-
{multiple &&
69+
/>
70+
)}
71+
{multiple && (
7272
<input
7373
type="checkbox"
7474
id={`${meta.form}-${input.name}-${getIndex()}`}
@@ -90,14 +90,13 @@ function FormChoice({ legend, options, info, multiple, size, input, meta }) {
9090
input.onBlur(input.value);
9191
}}
9292
className={inputClasses}
93-
/>}
93+
/>
94+
)}
9495
<div className="custom-control-indicator" />
95-
<div className="custom-control-description">
96-
{option.label}
97-
</div>
96+
<div className="custom-control-description">{option.label}</div>
9897
{increaseIndex()}
99-
</label>),
100-
)}
98+
</label>
99+
))}
101100
</div>
102101
</Field>
103102
);

src/Form/FormDatePicker.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ class FormDatePicker extends React.Component {
101101
};
102102

103103
render() {
104-
const { label, placeholder, info, size, input, meta } = this.props;
104+
const {
105+
label, placeholder, info, size, input, meta,
106+
} = this.props;
105107
const labelClasses = cx('form-control-label', { active: meta.active });
106108
const classes = cx('form-datepicker Select Select--single', {
107109
'is-invalid': meta.error,
@@ -118,27 +120,26 @@ class FormDatePicker extends React.Component {
118120

119121
return (
120122
<Field meta={meta} info={info}>
121-
{label &&
123+
{label && (
122124
<label htmlFor={`${meta.form}-${input.name}`} className={labelClasses}>
123125
{label}
124-
</label>}
126+
</label>
127+
)}
125128
<div className={classes}>
126129
<div
127130
className={controlClasses}
128131
onMouseDown={this.onToggleMouseDown}
129132
onKeyDown={this.onToggleKeyDown}
130133
>
131134
<span className="Select-multi-value-wrapper">
132-
{!input.value &&
133-
<div className="Select-placeholder">
134-
{placeholder}
135-
</div>}
136-
{input.value &&
135+
{!input.value && <div className="Select-placeholder">{placeholder}</div>}
136+
{input.value && (
137137
<div className="Select-value">
138138
<span className="Select-value-label" role="option" aria-selected="true">
139139
{input.value ? pickedDate.toLocaleDateString('en') : ''}
140140
</span>
141-
</div>}
141+
</div>
142+
)}
142143
{/* TODO
143144
* aria-owns should be the id of the date list element
144145
* aria-activedescendant should be the id of the currently selected day element
@@ -167,7 +168,7 @@ class FormDatePicker extends React.Component {
167168
/>
168169
</span>
169170
</div>
170-
{this.state.isOpen &&
171+
{this.state.isOpen && (
171172
<div
172173
ref={(menu) => {
173174
this.menu = menu;
@@ -188,7 +189,8 @@ class FormDatePicker extends React.Component {
188189
onDayKeyDown={() => {}}
189190
enableOutsideDays
190191
/>
191-
</div>}
192+
</div>
193+
)}
192194
</div>
193195
</Field>
194196
);

src/Form/FormInput.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const propTypes = {
1313
// redux form props
1414
input: PropTypes.object.isRequired,
1515
meta: PropTypes.object.isRequired,
16+
autoFocus: PropTypes.bool,
1617
};
1718

1819
const defaultProps = {
@@ -22,23 +23,28 @@ const defaultProps = {
2223
size: null,
2324
info: null,
2425
multiline: false,
26+
autoFocus: false,
2527
};
2628

27-
function FormInput({ label, placeholder, type, size, info, input, meta, multiline }) {
29+
function FormInput({
30+
label, placeholder, type, size, info, input, meta, multiline, autoFocus,
31+
}) {
2832
const labelClasses = cx('form-control-label', { active: meta.active });
2933

3034
const inputClasses = cx('form-control', {
3135
'is-invalid': meta.error,
3236
'form-control-sm': size === 'sm',
3337
});
3438

39+
/* eslint-disable jsx-a11y/no-autofocus */
3540
return (
3641
<Field meta={meta} info={info}>
37-
{label &&
42+
{label && (
3843
<label htmlFor={`${meta.form}-${input.name}`} className={labelClasses}>
3944
{label}
40-
</label>}
41-
{!multiline &&
45+
</label>
46+
)}
47+
{!multiline && (
4248
<input
4349
type={type}
4450
id={`${meta.form}-${input.name}`}
@@ -51,8 +57,10 @@ function FormInput({ label, placeholder, type, size, info, input, meta, multilin
5157
}}
5258
placeholder={placeholder}
5359
className={inputClasses}
54-
/>}
55-
{multiline &&
60+
autoFocus={autoFocus}
61+
/>
62+
)}
63+
{multiline && (
5664
<textarea
5765
id={`${meta.form}-${input.name}`}
5866
name={input.name}
@@ -65,9 +73,12 @@ function FormInput({ label, placeholder, type, size, info, input, meta, multilin
6573
placeholder={placeholder}
6674
rows="7"
6775
className={inputClasses}
68-
/>}
76+
autoFocus={autoFocus}
77+
/>
78+
)}
6979
</Field>
7080
);
81+
/* eslint-enable */
7182
}
7283

7384
FormInput.propTypes = propTypes;

src/Form/FormPicker.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const defaultProps = {
2626
multiple: false,
2727
};
2828

29-
function FormPicker({ label, size, options, info, input, meta, multiple, clearable, searchable }) {
29+
function FormPicker({
30+
label, size, options, info, input, meta, multiple, clearable, searchable,
31+
}) {
3032
const labelClasses = cx('form-control-label', { active: meta.active });
3133

3234
const classes = cx('form-picker', {
@@ -36,10 +38,11 @@ function FormPicker({ label, size, options, info, input, meta, multiple, clearab
3638

3739
return (
3840
<Field meta={meta} info={info}>
39-
{label &&
41+
{label && (
4042
<label htmlFor={`${meta.form}-${input.name}`} className={labelClasses}>
4143
{label}
42-
</label>}
44+
</label>
45+
)}
4346
<Select
4447
inputProps={{ id: `${meta.form}-${input.name}` }}
4548
instanceId={`${meta.form}-${input.name}`}

src/Form/FormSelect.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@ const defaultProps = {
1919
info: null,
2020
};
2121

22-
function FormSelect({ legend, size, info, input, meta, children }) {
22+
function FormSelect({
23+
legend, size, info, input, meta, children,
24+
}) {
2325
const selectClasses = cx('custom-select', {
2426
'is-invalid': meta.error,
2527
'custom-control-sm': size === 'sm',
2628
});
2729

2830
return (
2931
<Field meta={meta} info={info}>
30-
{legend &&
31-
<legend className="form-group-legend">
32-
{legend}
33-
</legend>}
32+
{legend && <legend className="form-group-legend">{legend}</legend>}
3433
<select {...input} className={selectClasses}>
3534
{children}
3635
</select>

src/Form/FormText.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ const defaultProps = {
2525
function FormText({ children, variant, className }) {
2626
const classes = cx('form-text', className, `text-${variant}`);
2727

28-
return (
29-
<p className={classes}>
30-
{children}
31-
</p>
32-
);
28+
return <p className={classes}>{children}</p>;
3329
}
3430

3531
FormText.propTypes = propTypes;

0 commit comments

Comments
 (0)