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-bar.md.

LoadingBar

Show page or task loading progress.

Basic usage

basic.tsx
import { Button, useLoadingBar } from '@ifhover/leaf-ui';

export function LoadingBarBasic() {
  const bar = useLoadingBar();
  return (
    <Button
      onClick={() => {
        const done = bar.start();
        setTimeout(done, 1600);
      }}
    >
      Simulate page loading
    </Button>
  );
}

More examples

advanced.tsx
import { Button, Space, useLoadingBar } from '@ifhover/leaf-ui';

export function LoadingBarProgress() {
  const bar = useLoadingBar();
  return (
    <Space>
      <Button
        variant="outline"
        onClick={() => {
          bar.reset();
          bar.start();
          bar.set(40);
        }}
      >
        40% progress
      </Button>
      <Button onClick={() => bar.finish()}>Finish</Button>
      <Button variant="soft" onClick={() => bar.reset()}>
        Reset
      </Button>
    </Space>
  );
}

Usage

ConfigProvider provides the bar. start() returns the completion function for that task; call it in finally. Concurrent tasks keep the bar active until all finish.

Types

Import these types for data, callbacks and refs.

import type { LoadingBarApi, LoadingBarProps, LoadingBarProviderProps } from '@ifhover/leaf-ui';

LoadingBarApi API

PropertyTypeDefaultDescription
start() => () => voidRequiredStart a task; returns its completion function
finish() => voidRequiredFinish one task; hide after all finish
set(progress: number) => voidRequiredSet displayed progress
reset() => voidRequiredReset or retry

LoadingBarProps API

PropertyTypeDefaultDescription
activebooleanfalseLoading is active
progressnumber—Progress 0–100; omitted estimates progress
colorstring—Color
heightnumber3Height, numbers are in pixels
position'top' | 'bottom''top'Display or insertion position
classNamestring—Container class name
styleCSSProperties—Container inline styles

LoadingBarProviderProps API

PropertyTypeDefaultDescription
colorstring—Color
heightnumber3Height, numbers are in pixels
position'top' | 'bottom''top'Display or insertion position
classNamestring—Container class name
styleCSSProperties—Container inline styles
childrenReactNode—Content or child items