blob: 4d86f23f747ada210fc04f28ede2db90256959bc (
plain) (
blame)
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 classnames from 'classnames';
import { Classes } from 'jss';
import { Component, LabelHTMLAttributes } from 'react';
import injectSheet from 'react-jss';
import { IFormField } from '../typings/generic';
import styles from './styles';
interface ILabel extends IFormField, LabelHTMLAttributes<HTMLLabelElement> {
classes: Classes;
isRequired: boolean;
}
class LabelComponent extends Component<ILabel> {
static defaultProps = {
showLabel: true,
};
render() {
const {
title,
showLabel,
classes,
className,
children,
htmlFor,
isRequired,
} = this.props;
if (!showLabel) return children;
return (
<label
className={classnames({
[`${className}`]: className,
})}
htmlFor={htmlFor}
>
{showLabel && (
<span className={classes.label}>
{title}
{isRequired && ' *'}
</span>
)}
<div className={classes.content}>{children}</div>
</label>
);
}
}
export const Label = injectSheet(styles)(LabelComponent);
|