diff --git a/ui/components/component-library/form-text-field/form-text-field.js b/ui/components/component-library/form-text-field/form-text-field.js index e99161e64..fbd14e261 100644 --- a/ui/components/component-library/form-text-field/form-text-field.js +++ b/ui/components/component-library/form-text-field/form-text-field.js @@ -5,14 +5,13 @@ import classnames from 'classnames'; import { Display, FlexDirection, - Severity, Size, } from '../../../helpers/constants/design-system'; import Box from '../../ui/box/box'; import { TextField } from '../text-field'; -import { HelpText } from '../help-text'; +import { HelpText, HelpTextSeverity } from '../help-text'; import { Label } from '../label'; export const FormTextField = ({ @@ -102,7 +101,7 @@ export const FormTextField = ({ /> {helpText && ( ` tag if the child is a `string` or a `
` if the child is an `object`. ```jsx -import { Size, IconColor } from '../../../helpers/constants/design-system'; +import { IconColor } from '../../../helpers/constants/design-system'; import { HelpText, Icon, IconName, IconSize } from '../../component-library'; Plain text // renders as

Plain text

@@ -44,41 +44,40 @@ import { HelpText, Icon, IconName, IconSize } from '../../component-library'; ### Severity -Use the `severity` prop and `SEVERITIES` object to change the severity of the `HelpText` +Use the `severity` prop and `HelpTextSeverity` enum to change the severity of the `HelpText` ```jsx -import { SEVERITIES } from '../../../helpers/constants/design-system'; -import { HelpText } from '../../component-library'; +import { HelpText, HelpTextSeverity } from '../../component-library'; HelpText without severity prop - + HelpText with severity: SEVERITY.DANGER - + HelpText with severity: SEVERITY.SUCCESS - + HelpText with severity: SEVERITY.WARNING - + HelpText with severity: SEVERITY.INFO ``` ### Color -It may be useful to change the color of the `HelpText`. Use the `color` prop and the `Color` object to change the color of the `HelpText`. Defaults to `Color.textDefault`. +It may be useful to change the color of the `HelpText`. Use the `color` prop and the `TextColor` enum to change the color of the `HelpText`. Defaults to `TextColor.textDefault`. ```jsx -import { Color } from '../../../helpers/constants/design-system'; +import { TextColor } from '../../../helpers/constants/design-system'; import { HelpText } from '../../component-library'; diff --git a/ui/components/component-library/help-text/__snapshots__/help-text.test.js.snap b/ui/components/component-library/help-text/__snapshots__/help-text.test.tsx.snap similarity index 100% rename from ui/components/component-library/help-text/__snapshots__/help-text.test.js.snap rename to ui/components/component-library/help-text/__snapshots__/help-text.test.tsx.snap diff --git a/ui/components/component-library/help-text/help-text.js b/ui/components/component-library/help-text/help-text.js deleted file mode 100644 index 354207d09..000000000 --- a/ui/components/component-library/help-text/help-text.js +++ /dev/null @@ -1,68 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classnames from 'classnames'; - -import { - Color, - TextVariant, - TextColor, - SEVERITIES, -} from '../../../helpers/constants/design-system'; - -import Box from '../../ui/box'; - -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 ( - - {children} - - ); -}; -HelpText.propTypes = { - /** - * The color of the HelpText will be overridden if there is a severity passed - * 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 Box props - */ - ...Box.propTypes, -}; diff --git a/ui/components/component-library/help-text/help-text.stories.js b/ui/components/component-library/help-text/help-text.stories.tsx similarity index 58% rename from ui/components/component-library/help-text/help-text.stories.js rename to ui/components/component-library/help-text/help-text.stories.tsx index e457bf6c6..da14d225a 100644 --- a/ui/components/component-library/help-text/help-text.stories.js +++ b/ui/components/component-library/help-text/help-text.stories.tsx @@ -1,23 +1,21 @@ import React from 'react'; +import { StoryFn, Meta } from '@storybook/react'; import { - DISPLAY, - FLEX_DIRECTION, + Display, + FlexDirection, IconColor, TextColor, - SEVERITIES, } from '../../../helpers/constants/design-system'; -import Box from '../../ui/box'; - -import { Icon, IconName, IconSize } from '..'; +import { Box, Icon, IconName, IconSize } from '..'; import { HelpText } from './help-text'; +import { HelpTextSeverity } from './help-text.types'; import README from './README.mdx'; export default { title: 'Components/ComponentLibrary/HelpText', - component: HelpText, parameters: { docs: { @@ -33,7 +31,7 @@ export default { }, severity: { control: 'select', - options: Object.values(SEVERITIES), + options: Object.values(HelpTextSeverity), }, color: { control: 'select', @@ -43,15 +41,15 @@ export default { args: { children: 'Help text', }, -}; +} as Meta; -const Template = (args) => ; +const Template: StoryFn = (args) => ; export const DefaultStory = Template.bind({}); DefaultStory.storyName = 'Default'; -export const Children = (args) => ( - +export const Children: StoryFn = (args) => ( + Plain text Text and icon @@ -66,28 +64,28 @@ export const Children = (args) => ( ); -export const SeverityStory = (args) => ( +export const SeverityStory: StoryFn = (args) => ( <> HelpText without severity prop - - HelpText with severity: SEVERITY.DANGER + + HelpText with severity: HelpTextSeverity.Danger - - HelpText with severity: SEVERITY.SUCCESS + + HelpText with severity: HelpTextSeverity.Success - - HelpText with severity: SEVERITY.WARNING + + HelpText with severity: HelpTextSeverity.Warning - - HelpText with severity: SEVERITY.INFO + + HelpText with severity: HelpTextSeverity.Info ); SeverityStory.storyName = 'Severity'; -export const ColorStory = (args) => ( - +export const ColorStory: StoryFn = (args) => ( + This HelpText default color is TextColor.textDefault diff --git a/ui/components/component-library/help-text/help-text.test.js b/ui/components/component-library/help-text/help-text.test.tsx similarity index 81% rename from ui/components/component-library/help-text/help-text.test.js rename to ui/components/component-library/help-text/help-text.test.tsx index e43fb54c5..29cd2e46a 100644 --- a/ui/components/component-library/help-text/help-text.test.js +++ b/ui/components/component-library/help-text/help-text.test.tsx @@ -1,10 +1,9 @@ /* eslint-disable jest/require-top-level-describe */ import { render } from '@testing-library/react'; import React from 'react'; -import { Color, SEVERITIES } from '../../../helpers/constants/design-system'; +import { TextColor } from '../../../helpers/constants/design-system'; import { Icon, IconName } from '..'; - -import { HelpText } from './help-text'; +import { HelpText, HelpTextSeverity } from '.'; describe('HelpText', () => { it('should render with text inside the HelpText', () => { @@ -34,10 +33,10 @@ describe('HelpText', () => { it('should render with severities', () => { const { getByText } = render( <> - error - success - warning - info + error + success + warning + info , ); expect(getByText('error')).toHaveClass('mm-box--color-error-default'); @@ -49,9 +48,9 @@ describe('HelpText', () => { const { getByText } = render( <> default - text default - text alternative - text muted + text default + text alternative + text muted , ); expect(getByText('default')).toHaveClass('mm-box--color-text-default'); diff --git a/ui/components/component-library/help-text/help-text.tsx b/ui/components/component-library/help-text/help-text.tsx new file mode 100644 index 000000000..4be242562 --- /dev/null +++ b/ui/components/component-library/help-text/help-text.tsx @@ -0,0 +1,53 @@ +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( + ( + { + severity, + color = TextColor.textDefault, + className, + children, + ...props + }: HelpTextProps, + ref?: PolymorphicRef, + ) => { + 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 ( + )} + > + {children} + + ); + }, +); diff --git a/ui/components/component-library/help-text/help-text.types.ts b/ui/components/component-library/help-text/help-text.types.ts new file mode 100644 index 000000000..1945fb67d --- /dev/null +++ b/ui/components/component-library/help-text/help-text.types.ts @@ -0,0 +1,35 @@ +import PropTypes from 'prop-types'; +import type { TextStyleUtilityProps } from '../text'; +import type { PolymorphicComponentPropWithRef } from '../box'; +import { Severity, TextColor } from '../../../helpers/constants/design-system'; + +export enum HelpTextSeverity { + Danger = Severity.Danger, + Warning = Severity.Warning, + Success = Severity.Success, + Info = Severity.Info, +} + +export interface HelpTextStyleUtilityProps extends TextStyleUtilityProps { + severity?: HelpTextSeverity | Severity; + /** + * The color of the HelpText will be overridden if there is a severity passed + * Defaults to Color.textDefault + */ + color?: TextColor; + /** + * The content of the help-text + */ + children: string | PropTypes.ReactNodeLike; + /** + * Additional classNames to be added to the HelpText component + */ + className?: string; +} + +export type HelpTextProps = + PolymorphicComponentPropWithRef; + +export type HelpTextComponent = ( + props: HelpTextProps, +) => React.ReactElement | null; diff --git a/ui/components/component-library/help-text/index.js b/ui/components/component-library/help-text/index.js deleted file mode 100644 index cbc88e159..000000000 --- a/ui/components/component-library/help-text/index.js +++ /dev/null @@ -1 +0,0 @@ -export { HelpText } from './help-text'; diff --git a/ui/components/component-library/help-text/index.ts b/ui/components/component-library/help-text/index.ts new file mode 100644 index 000000000..85fb7f700 --- /dev/null +++ b/ui/components/component-library/help-text/index.ts @@ -0,0 +1,3 @@ +export { HelpText } from './help-text'; +export { HelpTextSeverity } from './help-text.types'; +export type { HelpTextProps } from './help-text.types'; diff --git a/ui/components/component-library/index.js b/ui/components/component-library/index.js index 564643063..d225472e0 100644 --- a/ui/components/component-library/index.js +++ b/ui/components/component-library/index.js @@ -24,7 +24,7 @@ export { ButtonSecondary, BUTTON_SECONDARY_SIZES } from './button-secondary'; export { Checkbox } from './checkbox'; export { FormTextField } from './form-text-field'; export { HeaderBase } from './header-base'; -export { HelpText } from './help-text'; +export { HelpText, HelpTextSeverity } from './help-text'; export { Icon, IconName, IconSize } from './icon'; export { Label } from './label'; export { PickerNetwork } from './picker-network'; diff --git a/ui/pages/keychains/reveal-seed.js b/ui/pages/keychains/reveal-seed.js index 8484f201a..3dec64888 100644 --- a/ui/pages/keychains/reveal-seed.js +++ b/ui/pages/keychains/reveal-seed.js @@ -27,6 +27,7 @@ import { Button, TextField, HelpText, + HelpTextSeverity, BUTTON_VARIANT, TEXT_FIELD_SIZES, TEXT_FIELD_TYPES, @@ -143,7 +144,9 @@ const RevealSeedPage = () => { error={error} width={BLOCK_SIZES.FULL} /> - {error && {error}} + {error && ( + {error} + )} ); };