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 5dfc6427d..e3c72eb8d 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,6 +5,7 @@ import classnames from 'classnames'; import { DISPLAY, FLEX_DIRECTION, + SEVERITIES, Size, } from '../../../helpers/constants/design-system'; @@ -103,6 +104,7 @@ export const FormTextField = ({ {helpText && ( @@ -24,40 +24,49 @@ The `HelpText` accepts all props below as well as all [Box](/docs/components-ui- ### Children -The `children` of the `HelpText` can be plain text or react nodes - - - - +`HelpText` renders as a `

` 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 { HelpText, Icon, ICON_NAMES } from '../../component-library'; -Plain text +Plain text // renders as

Plain text

- Text and icon - - + Text and icon + + // renders as
Text and icon
``` -### Error +### Severity -Use the `error` prop to show the `HelpText` in error state +Use the `severity` prop and `SEVERITIES` object to change the severity of the `HelpText` - + ```jsx +import { SEVERITIES } from '../../../helpers/constants/design-system'; import { HelpText } from '../../component-library'; -This HelpText in error state; +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 @@ -72,18 +81,13 @@ It may be useful to change the color of the `HelpText`. Use the `color` prop and import { Color } from '../../../helpers/constants/design-system'; import { HelpText } from '../../component-library'; - - - This HelpText default color is Color.textDefault - - - This HelpText color is Color.infoDefault - - - This HelpText color is Color.warningDefault - - - This HelpText color is Color.successDefault - -; + + This HelpText default color is TextColor.textDefault + + + This HelpText color is TextColor.textAlternative + + + This HelpText color is TextColor.textMuted + ``` 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.js.snap index d577153b0..ed326ae49 100644 --- a/ui/components/component-library/help-text/__snapshots__/help-text.test.js.snap +++ b/ui/components/component-library/help-text/__snapshots__/help-text.test.js.snap @@ -1,11 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`HelpText should render with text inside the HelpText 1`] = ` +exports[`HelpText should match snapshot 1`] = `
- help text - +

`; diff --git a/ui/components/component-library/help-text/help-text.js b/ui/components/component-library/help-text/help-text.js index c60f04fe3..a375e3228 100644 --- a/ui/components/component-library/help-text/help-text.js +++ b/ui/components/component-library/help-text/help-text.js @@ -6,34 +6,46 @@ import { Color, TextVariant, TextColor, + SEVERITIES, } from '../../../helpers/constants/design-system'; import { Text } from '../text'; export const HelpText = ({ - error, + severity, color = Color.textDefault, className, children, ...props -}) => ( - - {children} - -); - +}) => { + 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 = { - /** - * If the HelperText should display in error state - * Will override the color prop if true - */ - error: PropTypes.bool, /** * The color of the HelpText will be overridden if error is true * Defaults to Color.textDefault diff --git a/ui/components/component-library/help-text/help-text.stories.js b/ui/components/component-library/help-text/help-text.stories.js index 9284fe526..5f7a0d47f 100644 --- a/ui/components/component-library/help-text/help-text.stories.js +++ b/ui/components/component-library/help-text/help-text.stories.js @@ -2,9 +2,10 @@ import React from 'react'; import { DISPLAY, FLEX_DIRECTION, - Color, + IconColor, TextColor, Size, + SEVERITIES, } from '../../../helpers/constants/design-system'; import Box from '../../ui/box'; @@ -31,8 +32,9 @@ export default { className: { control: 'text', }, - error: { - control: 'boolean', + severity: { + control: 'select', + options: Object.values(SEVERITIES), }, color: { control: 'select', @@ -52,38 +54,49 @@ DefaultStory.storyName = 'Default'; export const Children = (args) => ( Plain text - - Text and icon + + Text and icon ); -export const ErrorStory = (args) => ( - - This HelpText in error state - +export const SeverityStory = (args) => ( + <> + HelpText without severity prop + + HelpText with severity: SEVERITY.DANGER + + + HelpText with severity: SEVERITY.SUCCESS + + + HelpText with severity: SEVERITY.WARNING + + + HelpText with severity: SEVERITY.INFO + + ); -ErrorStory.storyName = 'Error'; + +SeverityStory.storyName = 'Severity'; export const ColorStory = (args) => ( - - This HelpText default color is Color.textDefault + + This HelpText default color is TextColor.textDefault - - This HelpText color is Color.infoDefault + + This HelpText color is TextColor.textAlternative - - This HelpText color is Color.warningDefault - - - This HelpText color is Color.successDefault + + This HelpText color is TextColor.textMuted ); diff --git a/ui/components/component-library/help-text/help-text.test.js b/ui/components/component-library/help-text/help-text.test.js index d17c699b7..a57702c08 100644 --- a/ui/components/component-library/help-text/help-text.test.js +++ b/ui/components/component-library/help-text/help-text.test.js @@ -1,16 +1,19 @@ /* eslint-disable jest/require-top-level-describe */ import { render } from '@testing-library/react'; import React from 'react'; -import { Color } from '../../../helpers/constants/design-system'; +import { Color, SEVERITIES } from '../../../helpers/constants/design-system'; import { Icon, ICON_NAMES } from '../icon'; import { HelpText } from './help-text'; describe('HelpText', () => { it('should render with text inside the HelpText', () => { - const { getByText, container } = render(help text); + const { getByText } = render(help text); expect(getByText('help text')).toBeDefined(); expect(getByText('help text')).toHaveClass('mm-help-text'); + }); + it('should match snapshot', () => { + const { container } = render(help text); expect(container).toMatchSnapshot(); }); it('should render with and additional className', () => { @@ -29,22 +32,50 @@ describe('HelpText', () => { expect(getByText('help text')).toBeDefined(); expect(getByTestId('icon')).toBeDefined(); }); - it('should render with error state', () => { - const { getByText } = render(error); + it('should render with severities', () => { + const { getByText } = render( + <> + error + success + warning + info + , + ); expect(getByText('error')).toHaveClass('mm-text--color-error-default'); + expect(getByText('success')).toHaveClass('mm-text--color-success-default'); + expect(getByText('warning')).toHaveClass('mm-text--color-warning-default'); + expect(getByText('info')).toHaveClass('mm-text--color-info-default'); }); it('should render with different colors', () => { const { getByText } = render( <> default - warning - success - info + text default + text alternative + text muted , ); expect(getByText('default')).toHaveClass('mm-text--color-text-default'); - expect(getByText('warning')).toHaveClass('mm-text--color-warning-default'); - expect(getByText('success')).toHaveClass('mm-text--color-success-default'); - expect(getByText('info')).toHaveClass('mm-text--color-info-default'); + expect(getByText('text default')).toHaveClass( + 'mm-text--color-text-default', + ); + expect(getByText('text alternative')).toHaveClass( + 'mm-text--color-text-alternative', + ); + expect(getByText('text muted')).toHaveClass('mm-text--color-text-muted'); + }); + it('should render with a different html element if children is an object', () => { + const { getByText, getByTestId } = render( + <> + help text as p + + help text as div + + , + ); + expect(getByText('help text as p')).toBeDefined(); + expect(getByText('help text as p').tagName).toBe('P'); + expect(getByText('help text as div')).toBeDefined(); + expect(getByTestId('help-text-div').tagName).toBe('DIV'); }); }); diff --git a/ui/pages/keychains/reveal-seed.js b/ui/pages/keychains/reveal-seed.js index 93fa17bb8..82d4b90a5 100644 --- a/ui/pages/keychains/reveal-seed.js +++ b/ui/pages/keychains/reveal-seed.js @@ -138,7 +138,7 @@ const RevealSeedPage = () => { error={error} width={BLOCK_SIZES.FULL} /> - {error && {error}} + {error && {error}} ); };