-
Notifications
You must be signed in to change notification settings - Fork 37
/
sharedInputStylesHelper.js
47 lines (43 loc) · 1.29 KB
/
sharedInputStylesHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Shared Input Style Helper
*
* A shared input classes helper for adding
* common input class names across input, textarea and select fields.
*
*/
import classNames from 'classnames';
import formStyles from './form.css';
export default (props) => {
// Validation classes
let validationClasses = null;
const {
dirty,
error,
marginBottom0,
noBorder,
valid,
validationEnabled,
validStylesEnabled,
warning
} = props;
const hasError = validationEnabled && error;
const isValid = validationEnabled && validStylesEnabled && valid;
const hasWarning = validationEnabled && warning;
const hasFeedback = validationEnabled && (error || warning);
validationClasses = classNames(
{ [`${formStyles.isChanged}`]: dirty && !hasError && !hasWarning && !isValid },
{ [`${formStyles.hasWarning}`]: hasWarning },
{ [`${formStyles.hasError}`]: hasError },
{ [`${formStyles.isValid}`]: isValid },
{ [`${formStyles.hasFeedback}`]: hasFeedback },
{ [`${formStyles.readOnly}`]: props.readOnly },
{ [`${formStyles.disabled}`]: props.disabled },
);
// Other input classes
return classNames(
formStyles.formControl,
{ [`${formStyles.noBorder}`]: noBorder },
{ [`${formStyles.marginBottom0}`]: marginBottom0 },
validationClasses,
);
};