-
-
Notifications
You must be signed in to change notification settings - Fork 55
docs(guides): add framework usage examples for Vite, Next.js, and Remix #1959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+194
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| # Framework usage | ||
|
|
||
| Minimal setup patterns for using Rad UI in **Vite**, **Next.js App Router**, and **Remix**. | ||
|
|
||
| For SSR pitfalls, see [Troubleshooting](/docs/guides/troubleshooting). | ||
|
|
||
| ## Shared setup | ||
|
|
||
| Install the package: | ||
|
|
||
| ```bash | ||
| npm install @radui/ui | ||
| ``` | ||
|
|
||
| Import components from per-component entrypoints: | ||
|
|
||
| ```tsx | ||
| import Button from '@radui/ui/Button' | ||
| import Theme from '@radui/ui/Theme' | ||
| ``` | ||
|
|
||
| Optional default theme styles: | ||
|
|
||
| ```tsx | ||
| import '@radui/ui/themes/default.css' | ||
| ``` | ||
|
|
||
| Wrap interactive UI with `Theme` when you use Rad UI's tokenized styles or generated `classNamespace` classes. | ||
|
|
||
| ## Vite + React | ||
|
|
||
| Vite works with Rad UI out of the box. No special SSR configuration is required for a client-rendered SPA. | ||
|
|
||
| ```tsx | ||
| // src/main.tsx | ||
| import React from 'react' | ||
| import ReactDOM from 'react-dom/client' | ||
| import App from './App' | ||
| import '@radui/ui/themes/default.css' | ||
|
|
||
| ReactDOM.createRoot(document.getElementById('root')!).render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode> | ||
| ) | ||
| ``` | ||
|
|
||
| ```tsx | ||
| // src/App.tsx | ||
| import Theme from '@radui/ui/Theme' | ||
| import Button from '@radui/ui/Button' | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <Theme appearance="light" accentColor="indigo"> | ||
| <Button>Get started</Button> | ||
| </Theme> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| **Notes** | ||
|
|
||
| - Prefer per-component imports for tree-shaking. | ||
| - Add your own global styles or Tailwind preset alongside the optional Rad UI theme CSS. | ||
|
|
||
| ## Next.js App Router | ||
|
|
||
| Rad UI components are client-side interaction primitives. Place them in a **Client Component** file. | ||
|
|
||
| ```tsx | ||
| // app/providers.tsx | ||
| 'use client' | ||
|
|
||
| import Theme from '@radui/ui/Theme' | ||
|
|
||
| export function Providers({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <Theme appearance="system" accentColor="gray"> | ||
| {children} | ||
| </Theme> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ```tsx | ||
| // app/layout.tsx | ||
| import { Providers } from './providers' | ||
| import '@radui/ui/themes/default.css' | ||
|
|
||
| export default function RootLayout({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <body> | ||
| <Providers>{children}</Providers> | ||
| </body> | ||
| </html> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ```tsx | ||
| // app/page.tsx | ||
| 'use client' | ||
|
|
||
| import Button from '@radui/ui/Button' | ||
|
|
||
| export default function HomePage() { | ||
| return <Button>Save</Button> | ||
| } | ||
| ``` | ||
|
|
||
| **Notes** | ||
|
|
||
| - Import Rad UI only from files marked with `'use client'` when they use state, effects, or event handlers. | ||
| - Keep server components free of interactive Rad UI imports unless they only re-export static markup wrappers you control. | ||
| - The docs app in this repository is a Next.js App Router consumer and is built in CI for compatibility smoke coverage. | ||
|
|
||
| ## Remix | ||
|
|
||
| Remix can SSR Rad UI markup, but interactive behavior still hydrates on the client. | ||
|
|
||
| ```tsx | ||
| // app/root.tsx | ||
| import type { LinksFunction } from '@remix-run/node' | ||
| import { Links, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react' | ||
| import themeStyles from '@radui/ui/themes/default.css?url' | ||
|
|
||
| export const links: LinksFunction = () => [{ rel: 'stylesheet', href: themeStyles }] | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <html lang="en"> | ||
| <head> | ||
| <Meta /> | ||
| <Links /> | ||
| </head> | ||
| <body> | ||
| <Outlet /> | ||
| <ScrollRestoration /> | ||
| <Scripts /> | ||
| </body> | ||
| </html> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ```tsx | ||
| // app/routes/_index.tsx | ||
| import Theme from '@radui/ui/Theme' | ||
| import Button from '@radui/ui/Button' | ||
|
|
||
| export default function Index() { | ||
| return ( | ||
| <Theme appearance="light"> | ||
| <Button>Continue</Button> | ||
| </Theme> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| **Notes** | ||
|
|
||
| - Load theme CSS through Remix `links` so styles are present on the first server render. | ||
| - Avoid reading browser-only APIs during the initial render path. | ||
|
|
||
| ## Choosing a pattern | ||
|
|
||
| | Framework | Rad UI entry | Theme CSS | Client boundary | | ||
| | --- | --- | --- | --- | | ||
| | Vite SPA | `main.tsx` | import in entry | not required for SPA | | ||
| | Next.js App Router | `providers.tsx` + route components | `layout.tsx` | `'use client'` for interactive components | | ||
| | Remix | `root.tsx` + routes | `links` export | route components hydrate automatically | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { createDocsPage } from '@/components/docsPage/createDocsPage' | ||
| import metadata from './seo' | ||
| import Content from './content.mdx' | ||
|
|
||
| export { metadata } | ||
|
|
||
| export default createDocsPage(Content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import generateSeoMetadata from '@/utils/seo/generateSeoMetadata' | ||
|
|
||
| const frameworkUsageGuideMetadata = generateSeoMetadata({ | ||
| title: 'Framework usage | Rad UI', | ||
| description: 'Minimal Rad UI setup examples for Vite, Next.js App Router, and Remix.' | ||
| }) | ||
|
|
||
| export default frameworkUsageGuideMetadata |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: rad-ui/ui
Length of output: 175
🏁 Script executed:
Repository: rad-ui/ui
Length of output: 12558
🏁 Script executed:
Repository: rad-ui/ui
Length of output: 5113
Add
classNamespace="rad-ui"to eachThemewrapper used with@radui/ui/themes/default.css.In
docs/app/docs/guides/framework-usage/content.mdx(Vite, Next.js App Router, and Remix), the examples import/link@radui/ui/themes/default.css, but the<Theme>components omitclassNamespace. TheThemedocs state that the default theme stylesheet expects generated namespaced classes (e.g.rad-ui-*), andThemedoes not add them by default—so the rendered components won’t match the CSS selectors as described. AddclassNamespace="rad-ui"to the<Theme>in each snippet (ViteApp.tsx, Nextproviders.tsx, Remix route component).🤖 Prompt for AI Agents