1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/ui/components/component-library/help-text/help-text.tsx
Garrett Bear e923110092
Fix/helptext to ts (#20108)
* migrate help-text to TS

delete story with js format

Update ui/components/component-library/help-text/help-text.types.ts

Co-authored-by: George Marshall <georgewrmarshall@gmail.com>

add forwardRef

add ref in forwardRef

final updates to HelpText to TS

update HelpText props

* form text field

* Removing some unused example code

---------

Co-authored-by: taeslee <64485716+taeslee@users.noreply.github.com>
Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
2023-07-21 10:11:35 -07:00

54 lines
1.5 KiB
TypeScript

import React, { forwardRef } from 'react';
import classnames from 'classnames';
import {
TextVariant,
TextColor,
} from '../../../helpers/constants/design-system';
import { Text } from '../text';
import type { PolymorphicRef } from '../box';
import type { TextProps } from '../text';
import type { HelpTextProps, HelpTextComponent } from './help-text.types';
import { HelpTextSeverity } from '.';
export const HelpText: HelpTextComponent = forwardRef(
<C extends React.ElementType = 'p'>(
{
severity,
color = TextColor.textDefault,
className,
children,
...props
}: HelpTextProps<C>,
ref?: PolymorphicRef<C>,
) => {
const severityColor = () => {
switch (severity) {
case HelpTextSeverity.Danger:
return TextColor.errorDefault;
case HelpTextSeverity.Warning:
return TextColor.warningDefault;
case HelpTextSeverity.Success:
return TextColor.successDefault;
case HelpTextSeverity.Info:
return TextColor.infoDefault;
// Defaults to HelpTextSeverity.Info
default:
return TextColor.textDefault;
}
};
return (
<Text
className={classnames('mm-help-text', className ?? '')}
ref={ref}
as={children && typeof children === 'object' ? 'div' : 'p'}
variant={TextVariant.bodyXs}
color={severity ? severityColor() : color}
{...(props as TextProps<C>)}
>
{children}
</Text>
);
},
);