This video is available to students only

Using Svelte to Show and Hide Loading Spinner Icons

Using Svelte to Show and Hide Loading Spinner Icons

Loading Spinner Icons#

To improve our user experience, we can toggle loading icons while the Svelte client-side application is making network calls. For the purposes of this course, we are going to use a library called svelte-awesome.

Svelte-awesome is a Svelte component library based on the popular open-source project Font Awesome. With Svelte-awesome, you have the opportunity to import only the icons you need, which reduces the JavaScript and CSS bundle size of your application.

We'll start with the refresh icon as our loading spinner, but we will probably use more icons later to make the application more intuitive.

To get going, install svelte-awesome in the frontend project.

Then we need to import the main Icon component and the required icon and add the markup to the template.

Try it out by putting the refresh icon above the table in the LunchMenuAdmin component. We can add the spin property to make it an animated spinner and add scale="3" to make it bigger. To give it a little padding, we wrap the Icon component with a <div class="section">.

Here's an abbreviation of what to do:

This lesson preview is part of the Fullstack Svelte course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

Unlock This Course

Get unlimited access to Fullstack Svelte, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Fullstack Svelte