-
Notifications
You must be signed in to change notification settings - Fork 180
/
control-label.tsx
40 lines (32 loc) · 991 Bytes
/
control-label.tsx
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
import React, {ComponentType, LabelHTMLAttributes} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import styles from './control-label.css';
export enum LabelType {
SECONDARY = 'secondary',
FORM = 'form', // See RG-2291
}
const classNameByType: Record<LabelType, string> = {
[LabelType.SECONDARY]: styles.secondaryLabel,
[LabelType.FORM]: styles.formLabel
};
interface ControlLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
disabled?: boolean;
type?: LabelType;
}
export const ControlLabel: React.FC<ControlLabelProps> = (
{children, type = LabelType.SECONDARY, disabled, ...rest}
) => (
<label
className={classNames(styles.label, classNameByType[type], {
[styles.disabledLabel]: disabled
})}
{...rest}
>{children}</label>
);
(ControlLabel as ComponentType<unknown>).propTypes = {
label: PropTypes.node,
labelStyle: PropTypes.string,
disabled: PropTypes.bool
};
export default ControlLabel;