Astro
Add PanelUI web components to an Astro site with React.
For an Astro site with the React integration. The components are React, so they run as islands.
A new project
Create the project
The shadcn CLI creates the app, sets up Tailwind CSS and writes the theme tokens in one go:
npx shadcn@latest init -t astropnpm dlx shadcn@latest init -t astroyarn dlx shadcn@latest init -t astrobunx shadcn@latest init -t astroAdd a component
npx shadcn@latest add https://panelui.dev/r/web/rolling-number.jsonpnpm dlx shadcn@latest add https://panelui.dev/r/web/rolling-number.jsonyarn dlx shadcn@latest add https://panelui.dev/r/web/rolling-number.jsonbunx shadcn@latest add https://panelui.dev/r/web/rolling-number.jsonThe source is written to components/panelui/rolling-number.tsx, and the packages it uses are
installed for you.
Use it
---
import Layout from "@/layouts/main.astro"
import { RollingNumber } from "@/components/panelui/rolling-number"
---
<Layout>
<main class="flex min-h-svh items-center justify-center">
<RollingNumber client:load value={121} className="text-6xl font-semibold" />
</main>
</Layout>An existing project
The project needs the React integration and Tailwind CSS. Add React with npx astro add react if it is missing. Then:
npx shadcn@latest initpnpm dlx shadcn@latest inityarn dlx shadcn@latest initbunx shadcn@latest initThen add a component as in the steps above.
Islands
Astro renders a React component to HTML and sends no JavaScript for it unless told to. A
component that animates or responds to the pointer needs a client: directive: client:load
to start at once, or client:visible to wait until it is scrolled into view. Without one it is
drawn once and never moves.
From npm
To install the package instead of copying source, follow From npm once the project has its shadcn theme.