2022-11-03 18:09:09 +01:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
2022-11-29 22:00:51 +01:00
import { Text } from '..';
2022-11-03 18:09:09 +01:00
import { HelpText } from './help-text';
# HelpText
2023-02-16 21:42:15 +01:00
The `HelpText` is used as feedback text under a form field including error, success, warning or info messages
2022-11-03 18:09:09 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-helptext--default-story" />
2022-11-03 18:09:09 +01:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `HelpText` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2022-11-03 18:09:09 +01:00
<ArgsTable of={HelpText} />
2023-01-20 20:27:46 +01:00
`HelpText` accepts all [Text](/docs/components-componentlibrary-text--default-story#props) component props
2022-11-29 22:00:51 +01:00
<ArgsTable of={Text} />
2022-11-03 18:09:09 +01:00
### Children
2023-02-16 21:42:15 +01:00
`HelpText` renders as a `<p>` tag if the child is a `string` or a `<div>` if the child is an `object`.
2022-11-03 18:09:09 +01:00
```jsx
2023-02-02 21:15:26 +01:00
import { Size, IconColor } from '../../../helpers/constants/design-system';
2023-04-05 18:11:10 +02:00
import { HelpText, Icon, IconName, IconSize } from '../../component-library';
2022-11-03 18:09:09 +01:00
2023-02-16 21:42:15 +01:00
<HelpText>Plain text</HelpText> // renders as <p>Plain text</p>
2022-11-03 18:09:09 +01:00
<HelpText>
2023-02-16 21:42:15 +01:00
<span>Text and icon</span>
<Icon
marginLeft={1}
color={IconColor.iconAlternative}
2023-04-05 18:11:10 +02:00
name={IconName.Warning}
size={IconSize.Inherit}
2023-02-16 21:42:15 +01:00
/>
</HelpText> // renders as <div><span>Text and icon</span> <div style={{background: icon/warning.svg}} /></div>
2022-11-03 18:09:09 +01:00
```
2023-02-16 21:42:15 +01:00
### Severity
2022-11-03 18:09:09 +01:00
2023-02-16 21:42:15 +01:00
Use the `severity` prop and `SEVERITIES` object to change the severity of the `HelpText`
2022-11-03 18:09:09 +01:00
<Canvas>
2023-02-16 21:42:15 +01:00
<Story id="components-componentlibrary-helptext--severity-story" />
2022-11-03 18:09:09 +01:00
</Canvas>
```jsx
2023-02-16 21:42:15 +01:00
import { SEVERITIES } from '../../../helpers/constants/design-system';
2022-11-29 22:00:51 +01:00
import { HelpText } from '../../component-library';
2022-11-03 18:09:09 +01:00
2023-02-16 21:42:15 +01:00
<HelpText>HelpText without severity prop</HelpText>
<HelpText severity={SEVERITIES.DANGER}>
HelpText with severity: SEVERITY.DANGER
</HelpText>
<HelpText severity={SEVERITIES.SUCCESS}>
HelpText with severity: SEVERITY.SUCCESS
</HelpText>
<HelpText severity={SEVERITIES.WARNING}>
HelpText with severity: SEVERITY.WARNING
</HelpText>
<HelpText severity={SEVERITIES.INFO}>
HelpText with severity: SEVERITY.INFO
</HelpText>
2022-11-03 18:09:09 +01:00
```
### Color
2023-02-14 18:33:04 +01:00
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`.
2022-11-03 18:09:09 +01:00
<Canvas>
2023-02-14 18:33:04 +01:00
<Story id="components-componentlibrary-helptext--color-story" />
2022-11-03 18:09:09 +01:00
</Canvas>
```jsx
2023-02-02 21:15:26 +01:00
import { Color } from '../../../helpers/constants/design-system';
2022-11-29 22:00:51 +01:00
import { HelpText } from '../../component-library';
2022-11-03 18:09:09 +01:00
2023-02-16 21:42:15 +01:00
<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>
2022-11-03 18:09:09 +01:00
```