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
The `HelpText` is intended to be used as the help or error text under a form element
<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
2022-11-29 22:00:51 +01:00
The `children` of the `HelpText` can be plain text or react nodes
2022-11-03 18:09:09 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-helptext--children" />
2022-11-03 18:09:09 +01:00
</Canvas>
```jsx
2023-02-02 21:15:26 +01:00
import { Size, IconColor } from '../../../helpers/constants/design-system';
2022-11-29 22:00:51 +01:00
import { HelpText, Icon, ICON_NAMES } from '../../component-library';
2022-11-03 18:09:09 +01:00
<HelpText>Plain text</HelpText>
<HelpText>
Text and icon
2023-02-02 21:15:26 +01:00
<Icon
marginLeft={1}
color={IconColor.inherit}
name={ICON_NAMES.WARNING}
size={Size.inherit}
/>
2022-11-03 18:09:09 +01:00
</HelpText>
```
### Error
2022-11-29 22:00:51 +01:00
Use the `error` prop to show the `HelpText` in error state
2022-11-03 18:09:09 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-helptext--error-story" />
2022-11-03 18:09:09 +01:00
</Canvas>
```jsx
2022-11-29 22:00:51 +01:00
import { HelpText } from '../../component-library';
2022-11-03 18:09:09 +01:00
<HelpText error>This HelpText in error state</HelpText>;
```
### 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
<Box display={DISPLAY.FLEX} flexDirection={FLEX_DIRECTION.COLUMN} gap={2}>
2023-02-02 21:15:26 +01:00
<HelpText color={Color.textDefault} {...args}>
This HelpText default color is Color.textDefault
2022-11-03 18:09:09 +01:00
</HelpText>
2023-02-02 21:15:26 +01:00
<HelpText color={Color.infoDefault} {...args}>
This HelpText color is Color.infoDefault
2022-11-03 18:09:09 +01:00
</HelpText>
2023-02-02 21:15:26 +01:00
<HelpText color={Color.warningDefault} {...args}>
This HelpText color is Color.warningDefault
2022-11-03 18:09:09 +01:00
</HelpText>
2023-02-02 21:15:26 +01:00
<HelpText color={Color.successDefault} {...args}>
This HelpText color is Color.successDefault
2022-11-03 18:09:09 +01:00
</HelpText>
</Box>;
```