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/help-text/help-text.js
George Marshall cf487b8f97
Update HelpText component (#17705)
* Updating HelpText component

* Updating logic for html element depending on children

* Adding span to story to reflect docs

* Updating reveal seed instance
2023-02-16 12:42:15 -08:00

67 lines
1.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import {
Color,
TextVariant,
TextColor,
SEVERITIES,
} from '../../../helpers/constants/design-system';
import { Text } from '../text';
export const HelpText = ({
severity,
color = Color.textDefault,
className,
children,
...props
}) => {
const severityColor = () => {
switch (severity) {
case SEVERITIES.DANGER:
return TextColor.errorDefault;
case SEVERITIES.WARNING:
return TextColor.warningDefault;
case SEVERITIES.SUCCESS:
return TextColor.successDefault;
case SEVERITIES.INFO:
return TextColor.infoDefault;
// Defaults to SEVERITIES.INFO
default:
return TextColor.textDefault;
}
};
return (
<Text
className={classnames('mm-help-text', className)}
as={children && typeof children === 'object' ? 'div' : 'p'}
variant={TextVariant.bodyXs}
color={severity ? severityColor() : color}
{...props}
>
{children}
</Text>
);
};
HelpText.propTypes = {
/**
* The color of the HelpText will be overridden if error is true
* Defaults to Color.textDefault
*/
color: PropTypes.oneOf(Object.values(TextColor)),
/**
* The content of the help-text
*/
children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Additional classNames to be added to the HelpText component
*/
className: PropTypes.string,
/**
* HelpText also accepts all Text and Box props
*/
...Text.propTypes,
};