Spinner3.0
Ads by Tryg Careers
Installation
npm i @tryg/vue-ui-libraryUsage
Install the component library as a Vue plugin. This globally registers all Anchor components.
import { createApp } from 'vue';
import { ComponentLibrary } from '@tryg/vue-ui-library';
import App from './App.vue';
const app = createApp(App);
app.use(ComponentLibrary);
app.mount('#app');<template>
<anchor-spinner size="large"></anchor-spinner>
</template>Import only the components you need for optimal bundle size.
<script setup>
import { AnchorSpinner } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-spinner size="large"></anchor-spinner>
</template>Note: Spinner adds
Loadingasaria-labelby default. This is required for accessibility. You can change it by passing aloading-textoraria-labelprop.
Sizes
Pass the size prop with value xsmall, small, medium, large or xlarge to display the spinner with different sizes.
<template>
<anchor-spinner size="xsmall"></anchor-spinner>
<anchor-spinner size="small"></anchor-spinner>
<anchor-spinner size="medium"></anchor-spinner>
<anchor-spinner size="large"></anchor-spinner>
<anchor-spinner size="xlarge"></anchor-spinner>
</template>Colors
The spinner will be colored by 'currentColor' of its parent element. If you want to set the color of the spinner specifically, you can set the text color of the parent element or directly for the Spinner.
<style>
.color-item:nth-child(1) { color: red; }
.color-item:nth-child(2) { color: green; }
.color-item:nth-child(3) { color: blue; }
.color-item:nth-child(4) { color: yellow; }
.color-item:nth-child(5) { color: fuchsia; }
</style>
<template>
<div class="color-item"><anchor-spinner size="xsmall"></anchor-spinner></div>
<div class="color-item"><anchor-spinner size="small"></anchor-spinner></div>
<div class="color-item"><anchor-spinner size="medium"></anchor-spinner></div>
<div class="color-item"><anchor-spinner size="large"></anchor-spinner></div>
<div class="color-item"><anchor-spinner size="xlarge"></anchor-spinner></div>
</template>Stroke width
<template>
<anchor-spinner stroke-width="20"></anchor-spinner>
</template>You shouldn't change this from its default but we've included the option for the sake of flexibility.
Accessibility
- Uses
role="status"with anaria-liveregion (defaultpolite, configurable toassertiveoroff) to announce loading state to screen readers. - The spinner SVG itself is hidden from screen readers using
aria-hidden="true", with the loading announcement delivered through a visually hidden span element. - Defaults to
aria-label="Loading"for the loading announcement. Customize the announcement text using theloading-textprop. - The
aria-liveprop controls the politeness level, allowing urgent loading states to interrupt screen reader output when needed. - The visual-only animation does not interfere with screen reader users, as the spinning motion is not conveyed assistively.
API
Spinner
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
ariaLive | aria-live | Live region politeness. Default = 'polite' but can be overridden to 'assertive' or 'off'. | "assertive" | "off" | "polite" | 'polite' |
loadingText | loading-text | OPTIONAL loading text to announce when spinner is displayed. If not provided → no live region is rendered (no announcement). | string | undefined |
size | size | We recommend controlling the size of the Spinner with the parent container. Size option included for the sake of flexibility. | "large" | "medium" | "small" | "xlarge" | "xsmall" | undefined |
strokeWidth | stroke-width | You shouldn't change this from it's default but we've included the option for the sake of flexibility | number | 7 |
CSS Custom Properties
| Name | Description |
|---|---|
--animation | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--duration | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--end-rotation | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--path | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
--spinner-animation | Set the animation properties of the spinner. |
--spinner-color | Set the path color of the spinner. |
--spinner-duration | Set the duration of the spinner animation. |
--spinner-end-rotation | Set the ending rotation of the spinner. |
--spinner-start-rotation | Set the starting rotation of the spinner. |
--start-rotation | DEPRECATED: kept for backwards compatibility, but will be removed by April 2024 |
Dependencies
Used by
Graph
graph TD;
anchor-button --> anchor-spinner
style anchor-spinner fill:#f9f,stroke:#333,stroke-width:4pxBuilt with StencilJS
