> Leaf UI 0.17.3 · Package: @ifhover/leaf-ui · Source: c3221834f84f2f48481a2054026b713456f8e5dc
> Browser documentation: https://ifhover.github.io/leaf-ui/en/components/loading.html

> For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt.

# Loading

Indicate that content is loading or an operation is in progress.


## Basic usage

Display a loading indicator while waiting for content or an operation to complete.


basic.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/loading/basic.tsx"
import { Loading } from '@ifhover/leaf-ui';

export function LoadingBasic() {
  return <Loading />;
}
```

Expand code


## Examples

### Sizes

Use `size` to choose the loading indicator size.


SmallMedium (default)Large

sizes.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/loading/sizes.tsx"
import { Flex, Grid, Loading, Text } from '@ifhover/leaf-ui';
import { Fragment } from 'react';

const sizes = [
  { value: 'sm', label: 'Small' },
  { value: 'md', label: 'Medium (default)' },
  { value: 'lg', label: 'Large' },
] as const;

export function LoadingSizes() {
  return (
    <Grid columns={{ xs: 1, sm: 2 }} gap={16} align="center">
      {sizes.map(({ value, label }) => (
        <Fragment key={value}>
          <Text tone="muted">{label}</Text>
          <Flex>
            <Loading size={value} />
          </Flex>
        </Fragment>
      ))}
    </Grid>
  );
}
```

Expand code

### Loading an area

With `children`, Loading covers the content and blocks interaction while the loading layer is visible. Use `spinning` to control loading and `tip` to add a message.


Finish loading

### Project overview

See project progress here.

Edit project

Loading projects

overlay.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/loading/overlay.tsx"
import { Button, Card, Flex, Loading, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function LoadingOverlay() {
  const [spinning, setSpinning] = useState(true);
  const [edited, setEdited] = useState(false);

  return (
    <Flex direction="column" gap="md">
      <Flex>
        <Button variant="outline" onClick={() => setSpinning((value) => !value)}>
          {spinning ? 'Finish loading' : 'Start loading'}
        </Button>
      </Flex>
      <Loading spinning={spinning} tip="Loading projects">
        <Card title="Project overview">
          <Flex direction="column" gap="md">
            <Text>See project progress here.</Text>
            <Flex>
              <Button variant="outline" onClick={() => setEdited(true)}>
                Edit project
              </Button>
            </Flex>
            {edited && <Text role="status">Project editor opened</Text>}
          </Flex>
        </Card>
      </Loading>
    </Flex>
  );
}
```

Expand code

### Delayed display

The indicator appears only if `spinning` is still `true` after `delay` milliseconds. Ending loading before then leaves it hidden.

`delay` does not delay your request or block interaction during the wait. Disable actions separately if they must be unavailable immediately.


Start loading

delay.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/loading/delay.tsx"
import { Button, Flex, Loading } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function LoadingDelay() {
  const [spinning, setSpinning] = useState(false);

  return (
    <Flex direction="column" gap="md" align="start">
      <Button onClick={() => setSpinning((value) => !value)}>
        {spinning ? 'Finish loading' : 'Start loading'}
      </Button>
      <Loading spinning={spinning} delay={600} tip="Loading" />
    </Flex>
  );
}
```

Expand code


## API

### Loading API

Props for loading state, status content and delayed display.

| Property   | Type                   | Default | Description                             |
| ---------- | ---------------------- | ------- | --------------------------------------- |
| `spinning` | `boolean`              | `true`  | Whether loading                         |
| `size`     | `'sm' \| 'md' \| 'lg'` | `'md'`  | Indicator size                          |
| `tip`      | `ReactNode`            | —       | Hint text                               |
| `delay`    | `number`               | `0`     | Display delay in milliseconds           |
| `children` | `ReactNode`            | —       | Content covered by the loading overlay. |
