mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Created Label component
This commit is contained in:
parent
65ed0d5641
commit
a1e890f0e1
@ -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;
|
@ -0,0 +1,4 @@
|
||||
.label {
|
||||
margin-bottom: 0;
|
||||
font-weight: 500;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user