1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/components/component-library/label/label.js
2023-02-15 08:29:26 -06:00

60 lines
1.3 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Text } from '../text';
import {
Color,
FONT_WEIGHT,
TextVariant,
DISPLAY,
AlignItems,
} from '../../../helpers/constants/design-system';
export const Label = ({ htmlFor, required, className, children, ...props }) => (
<Text
className={classnames(
'mm-label',
{ 'mm-label--html-for': htmlFor },
className,
)}
as="label"
htmlFor={htmlFor}
variant={TextVariant.bodyMd}
fontWeight={FONT_WEIGHT.BOLD}
display={DISPLAY.INLINE_FLEX}
alignItems={AlignItems.center}
{...props}
>
{children}
{required && (
<Text
as="span"
className="mm-label__required-asterisk"
aria-hidden="true"
color={Color.errorDefault}
>
*
</Text>
)}
</Text>
);
Label.propTypes = {
/**
* The content of the label
*/
children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* The id of the input associated with the label
*/
htmlFor: PropTypes.string,
/**
* If true the label will display as required
*/
required: PropTypes.bool,
/**
* Additional classNames to be added to the label component
*/
className: PropTypes.string,
};