Spinner
Visual indicators for loading states and processes in progress.
TailwindCSS
package showcase
import "github.com/axzilla/templui/internal/components/spinner"
templ SpinnerDefault() {
@spinner.Spinner(spinner.Props{
Size: spinner.SizeMd,
})
}
Installation
templui add spinner
Copy and paste the following code into your project:
package spinner import "github.com/axzilla/templui/internal/utils" type Size string const ( SizeSm Size = "sm" SizeMd Size = "md" SizeLg Size = "lg" ) type Props struct { ID string Class string Attributes templ.Attributes Size Size Color string } templ Spinner(props ...Props) { {{ var p Props }} if len(props) > 0 { {{ p = props[0] }} } <div if p.ID != "" { id={ p.ID } } class={ utils.TwMerge( "inline-flex flex-col items-center justify-center", p.Class, ), } aria-label="Loading" role="status" { p.Attributes... } > <div class={ utils.TwMerge( "animate-spin rounded-full", sizeClass(p.Size), borderSizeClass(p.Size), utils.IfElse( p.Color == "", "border-primary border-b-transparent", "border-current border-b-transparent", ), utils.IfElse( p.Color != "", p.Color, "", ), ), } ></div> </div> } func sizeClass(size Size) string { switch size { case SizeSm: return "w-6 h-6" case SizeLg: return "w-12 h-12" default: return "w-8 h-8" } } func borderSizeClass(size Size) string { switch size { case SizeSm: return "border-[3px]" case SizeLg: return "border-[5px]" default: return "border-4" } }
Update the import paths to match your project setup.
Examples
Sizes
package showcase
import "github.com/axzilla/templui/internal/components/spinner"
templ SpinnerSizes() {
<div class="flex flex-wrap items-end justify-center gap-8">
@spinner.Spinner(spinner.Props{
Size: spinner.SizeSm,
})
@spinner.Spinner(spinner.Props{
Size: spinner.SizeMd,
})
@spinner.Spinner(spinner.Props{
Size: spinner.SizeLg,
})
</div>
}
Colors
package showcase
import "github.com/axzilla/templui/internal/components/spinner"
templ SpinnerColors() {
<div class="flex flex-wrap items-end justify-center gap-8">
@spinner.Spinner(spinner.Props{
Size: spinner.SizeMd,
Color: "text-red-500",
})
@spinner.Spinner(spinner.Props{
Size: spinner.SizeMd,
Color: "text-green-500",
})
@spinner.Spinner(spinner.Props{
Size: spinner.SizeMd,
Color: "text-blue-500",
})
</div>
}
In Button
package showcase
import (
"github.com/axzilla/templui/internal/components/button"
"github.com/axzilla/templui/internal/components/spinner"
)
templ SpinnerInButton() {
@button.Button(button.Props{
Attributes: templ.Attributes{
"disabled": "true",
},
}) {
<div class="flex items-center gap-2">
@spinner.Spinner(spinner.Props{
Size: spinner.SizeSm,
Color: "text-primary-foreground",
})
<span>Loading</span>
</div>
}
}