1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/components/component-library/help-text
George Marshall 23b412c13f
Component library adding global index and other housekeeping (#16441)
* Adding global index.js file

* Removing style prop from button base

* Fixing comment on generate-icon-names.js file

* Re-ordering sass imports to atomic structure

* Updating component paths code examples of MDX docs
2022-11-16 14:15:08 -08:00
..
help-text.js HelpText propType fix (#16402) 2022-11-07 14:34:18 -08:00
help-text.stories.js Adding HelpText component (#16293) 2022-11-03 10:09:09 -07:00
help-text.test.js Adding HelpText component (#16293) 2022-11-03 10:09:09 -07:00
index.js Adding HelpText component (#16293) 2022-11-03 10:09:09 -07:00
README.mdx Component library adding global index and other housekeeping (#16441) 2022-11-16 14:15:08 -08:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';

import { HelpText } from './help-text';

# HelpText

The `HelpText` is intended to be used as the help or error text under a form element

<Canvas>
  <Story id="ui-components-component-library-help-text-help-text-stories-js--default-story" />
</Canvas>

## Props

The `HelpText` accepts all props below as well as all [Text](/docs/ui-components-component-library-text-text-stories-js--default-story#props) and [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props.

<ArgsTable of={HelpText} />

### Children

The `children` of the `HelpText` can be plain text or react nodes.

<Canvas>
  <Story id="ui-components-component-library-help-text-help-text-stories-js--children" />
</Canvas>

```jsx
import { SIZES, COLORS } from '../../../helpers/constants/design-system';
import { Icon, ICON_NAMES } from '../../ui/components/component-library';
import { HelpText } from '../../ui/components/component-library';

<HelpText>Plain text</HelpText>
<HelpText>
  Text and icon
  <Icon
    marginLeft={1}
    color={COLORS.INHERIT}
    name={ICON_NAMES.WARNING_FILLED}
    size={SIZES.AUTO}
  />
</HelpText>
```

### Error

Use the `error` prop to show the `HelpText` in error state.

<Canvas>
  <Story id="ui-components-component-library-help-text-help-text-stories-js--error-story" />
</Canvas>

```jsx
import { HelpText } from '../../ui/components/component-library';

<HelpText error>This HelpText in error state</HelpText>;
```

### Color

It may be useful to change the color of the `HelpText`. Use the `color` prop and the `COLORS` object to change the color of the `HelpText`. Defaults to `COLORS.TEXT_DEFAULT`.

<Canvas>
  <Story id="ui-components-component-library-help-text-help-text-stories-js--color" />
</Canvas>

```jsx
import { COLORS } from '../../../helpers/constants/design-system';
import { HelpText } from '../../ui/components/component-library';

<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.COLUMN} gap={2}>
  <HelpText color={COLORS.TEXT_DEFAULT}>
    The HelpText default color is COLORS.TEXT_DEFAULT
  </HelpText>
  <HelpText color={COLORS.INFO_DEFAULT}>
    This HelpText color is COLORS.INFO_DEFAULT
  </HelpText>
  <HelpText color={COLORS.WARNING_DEFAULT}>
    This HelpText color is COLORS.WARNING_DEFAULT
  </HelpText>
  <HelpText color={COLORS.SUCCESS_DEFAULT}>
    This HelpText color is COLORS.SUCCESS_DEFAULT
  </HelpText>
</Box>;
```