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, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/loading.md.

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
import { Loading } from '@ifhover/leaf-ui';

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

Examples

Sizes

Use size to choose the loading indicator size.

Small
Medium (default)
Large
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>
  );
}

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.

Project overview

See project progress here.
Loading projects
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>
  );
}

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.

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>
  );
}

API

Loading API

Props for loading state, status content and delayed display.

PropertyTypeDefaultDescription
spinningbooleantrueWhether loading
size'sm' | 'md' | 'lg''md'Indicator size
tipReactNode—Hint text
delaynumber0Display delay in milliseconds
childrenReactNode—Content covered by the loading overlay.