-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseFormControl.tsx
More file actions
52 lines (42 loc) · 1.45 KB
/
BaseFormControl.tsx
File metadata and controls
52 lines (42 loc) · 1.45 KB
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
48
49
50
51
52
import React from 'react';
import HelperText from '../../../HelperText';
import Label from '../../../Label';
import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';
import { BaseFormControlProps } from './BaseFormControl.types';
const BaseFormControl = ({ children, className = '', helperText, label, type }: BaseFormControlProps) => {
const classes = createCssClassNames({
'ids-form-control': true,
[`ids-form-control--${type}`]: true,
[className]: !!className,
});
const renderLabel = () => {
if (!label) {
return null;
}
const { children: labelContent, ...labelProps } = label;
return (
<div className="ids-form-control__label-wrapper">
<Label {...labelProps}>{labelContent}</Label>
</div>
);
};
const renderHelperText = () => {
if (!helperText) {
return null;
}
const { children: helperTextContent, ...helperTextProps } = helperText;
return (
<div className="ids-form-control__helper-text-wrapper">
<HelperText {...helperTextProps}>{helperTextContent}</HelperText>
</div>
);
};
return (
<div className={classes}>
{renderLabel()}
<div className="ids-form-control__source-wrapper">{children}</div>
{renderHelperText()}
</div>
);
};
export default BaseFormControl;