2022-11-03 18:09:54 +01:00
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
2022-11-29 22:01:05 +01:00
import { Text } from '..';
2022-11-03 18:09:54 +01:00
import { Label } from './label';
# Label
2023-03-17 18:24:07 +01:00
`Label` is used to describe the purpose of a form field
2022-11-03 18:09:54 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-label--default-story" />
2022-11-03 18:09:54 +01:00
</Canvas>
## Props
2023-01-20 20:27:46 +01:00
The `Label` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
2022-11-03 18:09:54 +01:00
<ArgsTable of={Label} />
2023-01-20 20:27:46 +01:00
`Label` accepts all [Text](/docs/components-componentlibrary-text--default-story#props) component props
2022-11-29 22:01:05 +01:00
<ArgsTable of={Text} />
2022-11-03 18:09:54 +01:00
### Children
2022-11-29 22:01:05 +01:00
The `children` of the label can be text or a react node
2022-11-03 18:09:54 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-label--children" />
2022-11-03 18:09:54 +01:00
</Canvas>
```jsx
2023-02-02 21:15:26 +01:00
import { DISPLAY, AlignItems, FLEX_DIRECTION, Size, IconColor } from '../../../helpers/constants/design-system';
2023-04-05 18:11:10 +02:00
import { Label, TextField, Icon, IconName, IconSize } from '../../component-library';
2022-11-03 18:09:54 +01:00
<Label>Plain text</Label>
2023-02-02 21:15:26 +01:00
<Label display={DISPLAY.FLEX} alignItems={AlignItems.flexStart}>
2022-11-03 18:09:54 +01:00
Text and icon
2023-02-02 21:15:26 +01:00
<Icon
color={IconColor.iconAlternative}
2023-04-05 18:11:10 +02:00
name={IconName.Info}
size={IconSize.Inherit}
2023-02-02 21:15:26 +01:00
/>
2022-11-03 18:09:54 +01:00
</Label>
<Label
2023-02-02 21:15:26 +01:00
display={DISPLAY.INLINE_FLEX}
flexDirection={FLEX_DIRECTION.COLUMN}
alignItems={AlignItems.flexStart}
2022-11-03 18:09:54 +01:00
>
Label that wraps an input
2022-11-29 22:01:05 +01:00
<TextField placeholder="Click label to focus" />
2022-11-03 18:09:54 +01:00
</Label>
```
### Html For
2022-11-29 22:01:05 +01:00
Use the `htmlFor` prop to allow the `Label` to focus on an input with the same id when clicked. The cursor will also change to a `pointer` when the `htmlFor` has a value.
2022-11-03 18:09:54 +01:00
<Canvas>
2023-01-20 20:27:46 +01:00
<Story id="components-componentlibrary-label--html-for" />
2022-11-03 18:09:54 +01:00
</Canvas>
```jsx
2023-02-16 00:43:51 +01:00
import { Label, TextField } from '../../component-library';
2022-11-03 18:09:54 +01:00
<Label htmlFor="add-network">Add network</Label>
2022-11-29 22:01:05 +01:00
<TextField id="add-network" placeholder="Enter network name" />
2022-11-03 18:09:54 +01:00
```
2023-03-17 18:24:07 +01:00
### Internal Resources
2022-11-03 18:09:54 +01:00
2023-03-17 18:24:07 +01:00
- [Figma component](https://www.figma.com/file/HKpPKij9V3TpsyMV1TpV7C/branch/7uyrueQIFQBLqo9uzkxclr/DS-Components?node-id=13879%3A38076&t=dBHjnJTMSVE8N2UP-1)
- [Insight report](https://www.figma.com/file/aGW8sk6X6Jf9ac0MRMD4kX/TextField-Audit?node-id=282%3A22&t=ZgCGFwGOBmOwQR5c-1)