astro-loading-indicator
This is an Astro integration that displays a progress bar between page navigations when using View Transitions.
Usage
Prerequisites
- View Transitions enabled on the whole site, view docs.
Installation
This package can be used in 2 ways:
- As an integration
- As a component
Scroll down if you want to see how to use the component!
Integration
Install the integration automatically using the Astro CLI:
pnpm astro add astro-loading-indicator
npm astro add astro-loading-indicator
yarn astro add astro-loading-indicator
Or install it manually:
- Install the required dependencies
pnpm add astro-loading-indicator
npm install astro-loading-indicator
yarn add astro-loading-indicator
- Add the integration to your astro config
+import astroLoadingIndicator from "astro-loading-indicator";
export default defineConfig({
integrations: [
+ astroLoadingIndicator({ ... }),
],
});
Component
Install the package manually:
- Install the required dependencies
pnpm add astro-loading-indicator
npm install astro-loading-indicator
yarn add astro-loading-indicator
- Add the component to your main layout:
import { ViewTransitions } from "astro:transitions";
+import { LoadingIndicator } from "astro-loading-indicator"
<!doctype html>
<html>
<head>
<ViewTransitions />
+ <LoadingIndicator />
</head>
</html>
Configuration
Here is the TypeScript type:
export type Options = {
color: string;
height?: string;
}
color
The indicator background color. Can be any valid CSS property.
import { defineConfig } from "astro/config";
import astroLoadingIndicator from "astro-loading-indicator";
export default defineConfig({
integrations: [
astroLoadingIndicator({
color: "#7e22ce",
}),
],
});
<LoadingIndicator
color="#7e22ce"
/>
height
The indicator height. Can be any valid CSS property. Defaults to "2px"
.
import { defineConfig } from "astro/config";
import astroLoadingIndicator from "astro-loading-indicator";
export default defineConfig({
integrations: [
astroLoadingIndicator({
height: "1rem",
}),
],
});
<LoadingIndicator
color="..."
height="1rem"
/>
Contributing
This package is structured as a monorepo:
playground
contains code for testing the packagepackage
contains the actual package
Install dependencies using pnpm:
pnpm i --frozen-lockfile
Start the playground:
pnpm playground:dev
You can now edit files in package
. Please note that making changes to those files may require restarting the playground dev server.
Licensing
MIT Licensed. Made with ❤️ by Florian Lefebvre.
Acknowledgements