1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/components/component-library/label/README.mdx
George Marshall f6ee35b6e3
Updating TextField component (#17732)
* Removing TextFieldBase and updating TextField and TextFieldSearch

* Removing autoFocus from MDX so it's not annoying
2023-02-15 15:43:51 -08:00

90 lines
2.2 KiB
Plaintext

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Text } from '..';
import { Label } from './label';
# Label
The `Label` is a component used to label form inputs
<Canvas>
<Story id="components-componentlibrary-label--default-story" />
</Canvas>
## Props
The `Label` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
<ArgsTable of={Label} />
`Label` accepts all [Text](/docs/components-componentlibrary-text--default-story#props) component props
<ArgsTable of={Text} />
### Children
The `children` of the label can be text or a react node
<Canvas>
<Story id="components-componentlibrary-label--children" />
</Canvas>
```jsx
import { DISPLAY, AlignItems, FLEX_DIRECTION, Size, IconColor } from '../../../helpers/constants/design-system';
import { Label, TextField, Icon, ICON_NAMES } from '../../component-library';
<Label>Plain text</Label>
<Label display={DISPLAY.FLEX} alignItems={AlignItems.flexStart}>
Text and icon
<Icon
color={IconColor.iconAlternative}
name={ICON_NAMES.INFO}
size={Size.inherit}
/>
</Label>
<Label
display={DISPLAY.INLINE_FLEX}
flexDirection={FLEX_DIRECTION.COLUMN}
alignItems={AlignItems.flexStart}
>
Label that wraps an input
<TextField placeholder="Click label to focus" />
</Label>
```
### Html For
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.
<Canvas>
<Story id="components-componentlibrary-label--html-for" />
</Canvas>
```jsx
import { Label, TextField } from '../../component-library';
<Label htmlFor="add-network">Add network</Label>
<TextField id="add-network" placeholder="Enter network name" />
```
### 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="components-componentlibrary-label--required" />
</Canvas>
```jsx
import { Label } from '../../component-library';
<Label required>Label</Label>;
```
```jsx
import { Label } from '../../component-library';
<Label disabled>Label</Label>;
```