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
2022-11-29 22:01:05 +01:00
The `Label` is a component used to label form inputs
2022-11-03 18:09:54 +01:00
<Canvas>
<Story id="ui-components-component-library-label-label-stories-js--default-story" />
</Canvas>
## Props
2022-11-29 22:01:05 +01:00
The `Label` 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:54 +01:00
<ArgsTable of={Label} />
2022-11-29 22:01:05 +01:00
`Label` 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: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>
<Story id="ui-components-component-library-label-label-stories-js--children" />
</Canvas>
```jsx
import { DISPLAY, ALIGN_ITEMS, FLEX_DIRECTION, SIZES, COLORS } from '../../../helpers/constants/design-system';
2022-11-29 22:01:05 +01:00
import { Label, TextField, Icon, ICON_NAMES } from '../../component-library';
2022-11-03 18:09:54 +01:00
<Label>Plain text</Label>
<Label display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.FLEX_START}>
Text and icon
<Icon
color={COLORS.ICON_ALTERNATIVE}
name={ICON_NAMES.INFO_FILLED}
size={SIZES.AUTO}
/>
</Label>
<Label
display={DISPLAY.INLINE_FLEX}
flexDirection={FLEX_DIRECTION.COLUMN}
alignItems={ALIGN_ITEMS.FLEX_START}
>
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>
<Story id="ui-components-component-library-label-label-stories-js--html-for" />
</Canvas>
```jsx
2022-11-29 22:01:05 +01:00
import { Label, TextFieldBase } 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
```
### Required
Use the `required` prop to add a required red asterisk next to the `children` of the `Label`. Note the required asterisk will always render after the `children`.
<Canvas>
<Story id="ui-components-component-library-label-label-stories-js--required" />
</Canvas>
```jsx
2022-11-29 22:01:05 +01:00
import { Label } from '../../component-library';
2022-11-03 18:09:54 +01:00
<Label required>Label</Label>;
```
### Disabled
Use the `disabled` prop to set the `Label` in disabled state
<Canvas>
<Story id="ui-components-component-library-label-label-stories-js--disabled" />
</Canvas>
```jsx
2022-11-29 22:01:05 +01:00
import { Label } from '../../component-library';
2022-11-03 18:09:54 +01:00
<Label disabled>Label</Label>;
```