Loader

The Loader component is used to display visual loading indicators with various animation styles and configurations.

Installation

$ cbui-cli install @crossbuildui/loader

Import

index.tsx
1import Loader from '@/crossbuildui/loader';

Basic Usage

index.tsx
1<Loader isVisible text="Loading..." />

Using LoaderProvider (Optional)

Wrap your app in LoaderProvider to pass a global configuration for size, color, etc.

App.tsx
1<LoaderProvider globalConfig={{ size: 'sm', color: 'secondary' }}> 2 <App /> 3</LoaderProvider>

You can access theme, layout and loader config via useLoaderContext():

MyComponent.tsx
1const { themeColors, layoutConfig, globalLoaderConfig } = useLoaderContext();

Variants

Loader supports multiple animation variants:spinner, pulse, dots, bars, wave, skeleton, and custom.

index.tsx
1 2<Loader isVisible variant="spinner" text="Loading..." /> 3<Loader isVisible variant="pulse" /> 4<Loader isVisible variant="dots" elementCount={4} /> 5<Loader isVisible variant="bars" /> 6<Loader isVisible variant="wave" /> 7<Loader isVisible variant="skeleton" /> 8

Sizes

Choose from xs, sm, md, lg, or xl sizes.

index.tsx
1 2<Loader isVisible size="xs" /> 3<Loader isVisible size="sm" /> 4<Loader isVisible size="md" /> 5<Loader isVisible size="lg" /> 6<Loader isVisible size="xl" /> 7

Glass Mode

Enable glassmorphism using the isGlass prop along with glassTint and glassIntensity. Works best on images or textured backgrounds.

index.tsx
1<Loader 2 isVisible 3 isGlass 4 glassTint="light" 5 glassIntensity={40} 6 variant="pulse" 7 text="Glass Effect" 8 subtitle="Beautiful glassmorphism background" 9/>

Inline Toggle Example

You can use loaders in inline mode conditionally based on state:

index.tsx
1<Loader 2 isVisible={loading} 3 variant="dots" 4 position="inline" 5 text="Loading content..." 6/>

Props Overview

PROPTYPEDEFAULTDESCRIPTION
isVisiblebooleanfalseShow or hide the loader.
variant'spinner' | 'pulse' | 'dots' | 'bars' | 'wave' | 'skeleton' | 'custom''spinner'Loader animation style.
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Size of loader.
colorColorShade | string'primary'Color of loader elements.
position'top' | 'bottom' | 'center' | 'inline''center'Position of the loader within the screen.
textstring-Text below loader.
subtitlestring-Subtitle below text.
childrenReactNode-Custom loader element (for variant='custom').
elementCountnumber3Number of elements (dots, bars, etc).
disableAnimationbooleanfalseDisable animation.
animationDurationnumber1500Duration of animation in ms.
showOverlaybooleanfalseShow overlay background.
overlayOpacitynumber0.5Opacity for the overlay.
glassTint'default' | 'light' | 'dark'-Tint color for blur background (glass mode).
glassIntensitynumber30Blur intensity for glass mode.
isGlassbooleanfalseEnable glass (blur) background.
fullScreenbooleanfalseExpand loader to full screen.
iconReactNode-Custom icon for spinner variant.
onAnimationComplete() => void-Callback after animation ends.
stylesPartial<LoaderSlotStyles>-Custom style overrides per slot.
styleStyleProp<ViewStyle>-Style for the loader root container.

Styling

Customize the loader layout and appearance using:

  • style: to override the root container.
  • styles: an object to override slot styles like base, overlay, loader, text, subtitle, and element.

Accessibility

The Loader component is accessible by default and uses ActivityIndicator where possible. You can also set custom labels if needed using wrapping elements.

Custom Animations

You can disable animations using disableAnimation or configure duration using animationDuration. Each variant has unique native-driver-powered animations, including spin, pulse, and interpolated dots.