Docs / Frameworks
Astro
Add UI Loft items to an Astro site. Astro needs React and Tailwind added first, and an item that moves needs a client directive.
- Version
- React
- Needs
- React + Tailwind 4 + shadcn
- Setup time
- About 5 minutes
Set up
Create the site
Skip this if you already have one.
Terminalnpm create astro@latest my-site -- --template minimal --install --no-git --yes cd my-siteAdd React and Tailwind
Astro's own command installs both and updates
astro.config.mjs. It also makessrc/styles/global.css.Terminalnpx astro add react tailwind --yesAdd the @ alias
Add
pathsundercompilerOptionsintsconfig.json.tsconfig.json{ "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }Set up shadcn
It makes a
components.jsonand fillssrc/styles/global.csswith the theme.-dtakes the defaults.Terminalnpx shadcn@latest init -dAdd an item
Copy the command from any item page. The file lands in
src/components/.Terminalnpx shadcn@latest add https://uiloft.dev/r/glow-button.jsonUse it
Import the styles once and the item, then give the item
client:loadso it runs in the browser.src/pages/index.astro--- import "@/styles/global.css" import { GlowButton } from "@/components/glow-button" --- <html lang="en"> <body> <GlowButton client:load>Get started</GlowButton> </body> </html>
Good to know
- Without a client directive, Astro sends the item as plain HTML: it shows, but doesn't move or react.
client:visibleinstead ofclient:loadwaits until the item scrolls into view.- With a layout, import
@/styles/global.cssthere once instead of in each page.