ActivityIndicator
ActivityIndicator is a spinner component that displays a loading state. It uses CSS animations on web and native platform spinners on React Native.
Installation
npm install @cleartrip/ct-design-activity-indicator
# or
pnpm add @cleartrip/ct-design-activity-indicator
Peer dependencies
# Required for all targets
npm install react
# Web only
npm install react-dom
# React Native only
npm install react-native
Usage
Basic
import { ActivityIndicator } from '@cleartrip/ct-design-activity-indicator';
function Example() {
return (
<ActivityIndicator />
);
}
With custom properties
<ActivityIndicator
size="large"
color="#007bff"
animating={true}
/>
Conditional display
<ActivityIndicator
animating={isLoading}
hidesWhenStopped={true}
size="small"
/>
Style overrides
<ActivityIndicator
styleConfig={{
root: [{ backgroundColor: '#f0f0f0', padding: 20 }],
spinner: [{ borderWidth: 3 }],
}}
/>
Props
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
animating | boolean | true | No | Whether the spinner should be animating. |
color | string | — | No | The foreground color of the spinner. Falls back to the current |
hidesWhenStopped | boolean | true | No | Whether the indicator should hide when animating is false. |
size | `'small' | 'large' | number` | 'small' |
styleConfig | ActivityIndicatorStyleConfigProps | — | No | Optional style overrides applied after the computed styles so |
Size Options
'small'— 20px spinner'large'— 36px spinnernumber— Custom pixel size
styleConfig
The styleConfig interface allows fine-grained style customization:
interface ActivityIndicatorStyleConfigProps {
root?: Styles[] | Styles[];
spinner?: Styles[] | Styles[];
}
Slots
| Slot | Description |
|---|---|
root | Styles applied to the root wrapper element (centering container) |
spinner | Styles applied to the spinning element itself |
Platform Differences
Web
- Uses CSS animations with
@keyframes - Renders as a CSS-based spinner with customizable colors and sizes
React Native
- Uses the platform's native ActivityIndicator
- Inherits platform-specific styling and behavior
Accessibility
- The spinner is automatically hidden from screen readers when not animating
- Consider adding
aria-labeloraria-describedbyto parent elements when appropriate - Use alongside proper loading states and announcements for better UX
Migration
If migrating from yagami or previous versions:
- import { ActivityIndicator } from 'yagami/core/components';
+ import { ActivityIndicator } from '@cleartrip/ct-design-activity-indicator';