1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 04:20:53 +01:00
metamask-extension/ui/components/component-library/label
George Marshall 5d17f86e02
Update Text import paths: component library/ (#19987)
* Updating component-librar import paths

* Updating snapshots

* Updates to AvatarBase story

* Updates to avatar and checkbox

* Updating last of the deprecated import paths

* Updating component-library snapshots from button-base

* Updating snapshots from rest of codebase to do with button-base

* Removing unneeded CSS

* Updating snapshots
2023-07-17 14:00:16 -07:00
..
__snapshots__ Update Text import paths: component library/ (#19987) 2023-07-17 14:00:16 -07:00
index.js Adding Label component (#16203) 2022-11-03 10:09:54 -07:00
label.js Update Text import paths: component library/ (#19987) 2023-07-17 14:00:16 -07:00
label.scss Updating Label component (#17731) 2023-02-15 08:29:26 -06:00
label.stories.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
label.test.js Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00
README.mdx Updating icon imports to TS version in component-library folder (#18449) 2023-04-05 09:11:10 -07:00

import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';

import { Text } from '..';

import { Label } from './label';

# Label

`Label` is used to describe the purpose of a form field

<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, IconName, IconSize } from '../../component-library';

<Label>Plain text</Label>
<Label display={DISPLAY.FLEX} alignItems={AlignItems.flexStart}>
  Text and icon
      <Icon
        color={IconColor.iconAlternative}
        name={IconName.Info}
        size={IconSize.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" />
```

### Internal Resources

- [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)