Created Label component

This commit is contained in:
cyril lopez 2018-02-01 11:03:44 +01:00
parent 65ed0d5641
commit a1e890f0e1
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,57 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { isFunction, isObject, upperFirst } from 'lodash';
import cn from 'classnames';
import styles from './styles.scss';
function Label(props) {
let content = props.children;
if (typeof(props.value) === 'string') {
content = props.value;
}
if (isObject(props.value) && props.value.id) {
content = <FormattedMessage id={props.value.id} defaultMessage=" " values={props.value.params} />;
}
if (isFunction(props.value)) {
content = props.value();
}
return (
<label
className={cn(styles.label, props.className)}
htmlFor={props.htmlFor}
style={props.style}
>
{content}
</label>
);
}
Label.defaultProps = {
children: '',
className: '',
style: {},
values: '',
};
Label.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
htmlFor: PropTypes.string.isRequired,
style: PropTypes.object,
values: PropTypes.oneOfType([
PropTypes.func,
PropTypes.string,
PropTypes.shape({
id: PropTypes.string,
params: PropTypes.object,
}),
]),
};
export default Label;

View File

@ -0,0 +1,4 @@
.label {
margin-bottom: 0;
font-weight: 500;
}