suiss/ui · Component
Spinner
An eight-spoke activity indicator that shows an indeterminate wait.
Spinner is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Spinner is an SVG of eight fading spokes that rotates in steps, like the system activity indicator. It draws in currentColor and is size-4 by default, so it inherits the surrounding text color.
Use it for short waits whose length is unknown, such as saving or loading more. For a placeholder that previews the shape of content, use Skeleton.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
Sizes
Change the size with a size-* class, from size-3 to size-8.
Colors
Change the color with a text-* class.
In button
Place a spinner in a busy Button with disabled, and give it data-icon="inline-start" to place it before the label.
Accessibility
- Renders with the
statusrole and the accessible nameLoading. Overridearia-labelto describe the specific task.
API Reference
Spinner
The animated activity indicator.
Also accepts the props of React.ComponentProps<"svg">.
The rotation lasts 0.8s and moves in eight steps, so one spoke advances at a time. Style it through data-slot="spinner".
Web preview
Spinner wraps the native ActivityIndicator in a square View. The indicator is scaled from its native small size to the size you pass, so it can match text and icon sizes. Its color is set through a class.
Installation
- Install the following dependencies:
- Copy and paste the following code into
components/ui/spinner.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy and paste the following code into
components/ui/spinner.tsx:
- Update the import paths to match your project setup.
- Copy and paste the following code into
components/ui/spinner.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Sizes
Spinners at 12, 16, 24 and 32 points, set with size.
Web preview
Colors
Spinners in the foreground, primary and destructive colors.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
In button
Spinners inside disabled buttons next to a label.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Accessibility
- The wrapper has
role="progressbar", isaccessible, and setsbusy: trueinaccessibilityState. - It is announced as
"Loading"unless you pass anotheraccessibilityLabel.
API Reference
Spinner
The animated activity indicator.
| Prop | Type | Default |
|---|---|---|
size | number | 16 |
colorClassName | string | "accent-muted-foreground" |
Also accepts the props of React.ComponentProps<typeof ActivityIndicator>.
size sets the width and height in points. colorClassName sets the indicator color with an accent-* class, such as accent-primary or accent-destructive. Inside a button, use accent-primary-foreground on the default variant so the spinner matches the label. The look of the indicator comes from the platform's native activity indicator, so it differs between iOS and Android.
Spinner
The animated activity indicator.
| Parameter | Type | Default |
|---|---|---|
_Â size | Size: .sm | .default | .lg | .xl | .default |
label | LocalizedStringKey | "Loading" |
dimension | CGFloat | - |
Overloads: init(_:label:), init(dimension:label:).
Spinner
The animated activity indicator.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
size | Dp | 16.dp |
color | Color | Color.Unspecified |
contentDescription | String | "Loading" |