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>
<Story id="ui-components-component-library-help-text-help-text-stories-js--default-story" />
</Canvas>
## Props
2022-11-29 22:00:51 +01:00
The `HelpText` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props
2022-11-03 18:09:09 +01:00
<ArgsTable of={HelpText} />
2022-11-29 22:00:51 +01:00
`HelpText` accepts all [Text](/docs/ui-components-component-library-text-text-stories-js--default-story#props) component props
<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>
<Story id="ui-components-component-library-help-text-help-text-stories-js--children" />
</Canvas>
```jsx
import { SIZES, COLORS } 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
<Icon
marginLeft={1}
color={COLORS.INHERIT}
name={ICON_NAMES.WARNING_FILLED}
size={SIZES.AUTO}
/>
</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>
<Story id="ui-components-component-library-help-text-help-text-stories-js--error-story" />
</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
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';
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}>
<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>;
```