Skip to content

Customizing ​

Every indicator takes the same four kinds of settings: params, color, colors and size. Try them below, then copy the code for your platform.

Params
3
0.30
Color
1.00×
64px
import { LoaderKit } from '@loader-kit/web/react';

<LoaderKit
  indicator="BallPulse"
  size={64}
/>

Params ​

Some indicators declare params: named numbers with a default value. BallPulse has count (3) and minScale (0.3). Pass the values you want to change. The others keep their default.

html
<loader-kit indicator="BallPulse" params='{"count": 5, "minScale": 0.5}'></loader-kit>
ts
const view = new LoaderKitView(host, {
  indicator: 'BallPulse',
  params: { count: 5, minScale: 0.5 },
});
kotlin
loader.indicator = "BallPulse"
loader.params = mapOf("count" to 5.0, "minScale" to 0.5)
kotlin
LoaderKitIndicator(
    indicator = "BallPulse",
    params = mapOf("count" to 5.0, "minScale" to 0.5),
)
swift
let loader = LoaderKitView(indicator: "BallPulse")
loader.params = ["count": 5, "minScale": 0.5]
swift
LoaderKitIndicator("BallPulse", params: ["count": 5, "minScale": 0.5])
csharp
indicator.Indicator = "BallPulse";
indicator.Params = new Dictionary<string, double> { ["count"] = 5, ["minScale"] = 0.5 };

Rules that apply on every platform:

  • A param name the indicator does not declare is ignored. You can switch indicators and keep the same params.
  • Counts are rounded to the nearest integer and are at least 1.
  • Param values are not range-checked. Keep sizes, counts and stroke widths positive: what an engine draws for out-of-range values is not specified.
  • Changing params restarts the animation from the beginning of its cycle.

See Built-in indicators for the list of params, and Params to declare params in your own spec.

Color ​

One color paints every element. Opacity tracks multiply the alpha of this color.

html
<loader-kit indicator="BallPulse" color="#10b981"></loader-kit>

<!-- Without a color attribute, the indicator uses the CSS color of the element -->
<loader-kit indicator="BallPulse" style="color: var(--brand)"></loader-kit>
ts
view.color = '#10b981';   // any CSS color; null means currentColor
xml
<io.github.maitrungduc1410.loaderkit.LoaderKitView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:indicatorColor="?attr/colorPrimary" />
kotlin
loader.color = Color.MAGENTA
kotlin
LoaderKitIndicator("BallPulse", color = MaterialTheme.colorScheme.primary)
swift
loader.color = .systemBlue
swift
LoaderKitIndicator("BallPulse").color(.accentColor)
xml
<lk:LoaderKitIndicator Indicator="BallPulse" Color="MediumSeaGreen" />

Default colors:

PlatformDefault
Webthe CSS color of the host element (currentColor)
Android Viewthe theme attribute android:colorForeground
Composeblack, or white when the system is in dark mode
iOS, macOSsystemGray
Windowswhite

On Apple platforms, dynamic system colors such as .label follow the light and dark appearance.

Colors ​

colors gives each element its own color. Element i uses colors[i mod colors.length], so a short list repeats. When colors is set and not empty, it wins over color.

html
<loader-kit indicator="BallPulse" colors="#f43f5e, #f59e0b, #10b981"></loader-kit>
ts
view.colors = ['#f43f5e', '#f59e0b', '#10b981'];
kotlin
loader.colors = intArrayOf(Color.RED, Color.YELLOW, Color.GREEN)
kotlin
LoaderKitIndicator("BallPulse", colors = listOf(Color.Red, Color.Yellow, Color.Green))
swift
loader.colors = [.systemRed, .systemOrange, .systemGreen]
swift
LoaderKitIndicator("BallPulse").colors([.red, .orange, .green])
csharp
indicator.Colors = new[] { Colors.Tomato, Colors.Gold, Colors.MediumSeaGreen };

Element order

Elements are numbered in drawing order. For a row it is left to right, for a grid it is row by row, and for a ring it starts on the right and goes clockwise. In an indicator with several parts, the numbering continues from one part to the next.

Size ​

Size the view the usual way on each platform. The indicator is drawn in the largest square that fits, centered in the view, so it never stretches. Without a size, the view is 40 by 40.

html
<loader-kit indicator="BallPulse" style="width: 64px; height: 64px"></loader-kit>
xml
<io.github.maitrungduc1410.loaderkit.LoaderKitView
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:padding="8dp"
    app:indicator="BallPulse" />
kotlin
LoaderKitIndicator("BallPulse", Modifier.size(64.dp))
swift
loader.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    loader.widthAnchor.constraint(equalToConstant: 64),
    loader.heightAnchor.constraint(equalToConstant: 64),
])
swift
LoaderKitIndicator("BallPulse").frame(width: 64, height: 64)
xml
<lk:LoaderKitIndicator Indicator="BallPulse" Width="64" Height="64" />

On Android, the indicator is drawn inside the padding. In SwiftUI, apply the LoaderKit modifiers (color, speed, ...) before SwiftUI modifiers such as frame.

Changing colors or size never restarts the animation.

Released under the MIT License.