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
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
..
__snapshots__ Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
help-text.stories.tsx Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
help-text.test.tsx Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
help-text.tsx Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
help-text.types.ts Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
index.ts Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
README.mdx Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00

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

import { Text } from '..';

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

# HelpText

The `HelpText` is used as feedback text under a form field including error, success, warning or info messages

<Canvas>
  <Story id="components-componentlibrary-helptext--default-story" />
</Canvas>

## Props

The `HelpText` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props

<ArgsTable of={HelpText} />

`HelpText` accepts all [Text](/docs/components-componentlibrary-text--default-story#props) component props

<ArgsTable of={Text} />

### Children

`HelpText` renders as a `<p>` tag if the child is a `string` or a `<div>` if the child is an `object`.

```jsx
import { IconColor } from '../../../helpers/constants/design-system';
import { HelpText, Icon, IconName, IconSize } from '../../component-library';

<HelpText>Plain text</HelpText> // renders as <p>Plain text</p>
<HelpText>
  <span>Text and icon</span>
  <Icon
    marginLeft={1}
    color={IconColor.iconAlternative}
    name={IconName.Warning}
    size={IconSize.Inherit}
  />
</HelpText> // renders as <div><span>Text and icon</span> <div style={{background: icon/warning.svg}} /></div>
```

### Severity

Use the `severity` prop and `HelpTextSeverity` enum to change the severity of the `HelpText`

<Canvas>
  <Story id="components-componentlibrary-helptext--severity-story" />
</Canvas>

```jsx
import { HelpText, HelpTextSeverity } from '../../component-library';

<HelpText>HelpText without severity prop</HelpText>
<HelpText severity={HelpTextSeverity.Danger}>
  HelpText with severity: SEVERITY.DANGER
</HelpText>
<HelpText severity={HelpTextSeverity.Success}>
  HelpText with severity: SEVERITY.SUCCESS
</HelpText>
<HelpText severity={HelpTextSeverity.Warning}>
  HelpText with severity: SEVERITY.WARNING
</HelpText>
<HelpText severity={HelpTextSeverity.Info}>
  HelpText with severity: SEVERITY.INFO
</HelpText>
```

### Color

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`.

<Canvas>
  <Story id="components-componentlibrary-helptext--color-story" />
</Canvas>

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

<HelpText color={TextColor.textDefault}>
  This HelpText default color is TextColor.textDefault
</HelpText>
<HelpText color={TextColor.textAlternative}>
  This HelpText color is TextColor.textAlternative
</HelpText>
<HelpText color={TextColor.textMuted}>
  This HelpText color is TextColor.textMuted
</HelpText>
```