-
Notifications
You must be signed in to change notification settings - Fork 37
/
Label.js
46 lines (41 loc) · 1.04 KB
/
Label.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
/**
* Label
*/
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { FormattedMessage } from 'react-intl';
import Icon from '../Icon';
import Asterisk from './components/Asterisk';
import css from './Label.css';
const Label = ({ children, className, htmlFor, id, readOnly, required, tagName = 'label', ...rest }) => {
const Element = tagName;
return (
<Element
htmlFor={htmlFor}
id={id}
{...rest}
className={classnames(css.label, className)}
>
{children}
{required && <Asterisk />}
{readOnly && (
<Icon size="small" icon="lock">
<span className="sr-only">
<FormattedMessage id="stripes-components.readonly" />
</span>
</Icon>
)}
</Element>
);
};
Label.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
htmlFor: PropTypes.string,
id: PropTypes.string,
readOnly: PropTypes.bool,
required: PropTypes.bool,
tagName: PropTypes.string,
};
export default Label;