)
}
```
**3. Update navigation:**
```tsx
// app/frontend/components/nav-main.tsx
const navItems = [
{ title: 'Dashboard', href: '/dashboard', icon: LayoutDashboard },
{ title: 'Products', href: '/products', icon: Package }, // Add this
// ...
]
```
**4. Add route:**
```ruby
# config/routes.rb
resources :products
```
### Adding New shadcn/ui Components
The starter kit includes many components, but you can add more:
```bash
# Add a specific component
npx shadcn@latest add toast
npx shadcn@latest add calendar
npx shadcn@latest add data-table
# See all available components
npx shadcn@latest add
```
### Customizing the Layout
**Switch between sidebar and header layouts:**
```tsx
// app/frontend/layouts/app-layout.tsx
import AppSidebarLayout from '@/layouts/app/app-sidebar-layout'
import AppHeaderLayout from '@/layouts/app/app-header-layout'
// Use sidebar (default)
export default function AppLayout({ children }: Props) {
return {children}
}
// Or use header layout
export default function AppLayout({ children }: Props) {
return {children}
}
```
### Extending Types
```tsx
// app/frontend/types/index.ts
export interface User {
id: number
name: string
email: string
avatar_url: string | null
}
// Add your own types
export interface Product {
id: number
name: string
description: string
price: number
created_at: string
}
export interface PageProps {
auth: {
user: User | null
}
flash: {
success?: string
error?: string
}
}
```
### Using the Flash Hook
The starter kit includes a flash message system with Sonner toasts:
```tsx
// Already set up in the layout, just use flash in your controller
class ProductsController < ApplicationController
def create
@product = Product.create(product_params)
redirect_to products_path, notice: 'Product created!'
end
end
```
The `use-flash` hook automatically displays flash messages as toasts.
### Removing Features You Don't Need
**Remove settings pages:**
```bash
rm -rf app/frontend/pages/settings
rm -rf app/controllers/settings
# Remove routes in config/routes.rb
```
**Remove authentication (for internal tools):**
```bash
rm -rf app/frontend/pages/sessions
rm -rf app/frontend/pages/users
rm -rf app/frontend/pages/identity
rm app/controllers/sessions_controller.rb
rm app/controllers/users_controller.rb
rm -rf app/controllers/identity
# Update routes and ApplicationController
```
---
## Layout Props (v3)
Share data between pages and their persistent layouts using `useLayoutProps`:
### Static Layout Props
```tsx
// app/frontend/pages/dashboard/index.tsx
import AppLayout from '@/layouts/app-layout'
export default function Dashboard({ stats }) {
return
Dashboard content
}
// Pass static props to the layout
Dashboard.layout = [AppLayout, { title: 'Dashboard', breadcrumbs: ['Home', 'Dashboard'] }]
```
### Dynamic Layout Props
```tsx
import { useLayoutProps } from '@inertiajs/react'
import AppLayout from '@/layouts/app-layout'
export default function UserProfile({ user }) {
// Set layout props dynamically
useLayoutProps({ title: user.name, breadcrumbs: ['Users', user.name] })
return
{user.name}'s profile
}
UserProfile.layout = AppLayout
```
### In the Layout
```tsx
// app/frontend/layouts/app-layout.tsx
import { useLayoutProps } from '@inertiajs/react'
export default function AppLayout({ children }) {
const { title, breadcrumbs } = useLayoutProps()
return (
{title}
{children}
)
}
```
---
## Inertia Modal - Render Pages as Dialogs
The `inertia_rails-contrib` gem and `@inertiaui/modal` package let you render any Inertia page as a modal dialog.
### Installation
```bash
# Ruby gem (optional, for base_url helper)
bundle add inertia_rails-contrib
# NPM package (Vue)
npm install @inertiaui/modal-vue
# NPM package (React)
npm install @inertiaui/modal-react
```
### Setup (React)
```javascript
// app/frontend/entrypoints/application.js
import { createInertiaApp } from '@inertiajs/react'
import { createRoot } from 'react-dom/client'
import { renderApp } from '@inertiaui/modal-react'
createInertiaApp({
resolve: (name) => {
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
return pages[`../pages/${name}.tsx`]
},
setup({ el, App, props }) {
createRoot(el).render(renderApp(App, props))
},
})
```
### Tailwind Configuration
```javascript
// tailwind.config.js (v3)
module.exports = {
content: [
// ... your content paths
'./node_modules/@inertiaui/modal-react/src/**/*.{js,jsx,ts,tsx}',
],
}
```
```css
/* For Tailwind v4 */
@import "tailwindcss";
@source '../../../node_modules/@inertiaui/modal-react';
```
### Basic Usage
**Open a page as modal:**
```jsx
import { ModalLink } from '@inertiaui/modal-react'
export default function UsersList() {
return (
Create User
)
}
```
**Wrap page content in Modal:**
```jsx
// pages/users/create.tsx
import { Modal } from '@inertiaui/modal-react'
export default function CreateUser({ roles }) {
return (
Create User
)
}
```
### Modal with Base URL
Enable URL updates and browser history:
**Controller:**
```ruby
class UsersController < ApplicationController
def create
render inertia_modal: {
roles: Role.all.as_json
}, base_url: users_path
end
end
```
**Link with navigation:**
```jsx
Create User
```
Now the URL changes to `/users/create` when opened, supports browser back button, and can be bookmarked.
### Slideover Variant
```jsx
User Details
{/* Content slides in from the side */}
```
### Nested Modals
```jsx
Edit User
{/* Open another modal from within */}
Add New Role
```
### Closing Modals
```jsx
import { Modal } from '@inertiaui/modal-react'
export default function EditUser({ onClose }) {
return (
)
}
```
---
## Integrating shadcn/ui
Use shadcn/ui components with Inertia Rails for a polished UI.
### Setup (React)
```bash
# Initialize shadcn/ui
npx shadcn@latest init
# Add components
npx shadcn@latest add button input card form
```
### Form with shadcn/ui
```jsx
import { useForm } from '@inertiajs/react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
export default function LoginForm() {
const { data, setData, post, processing, errors } = useForm({
email: '',
password: '',
})
function submit(e) {
e.preventDefault()
post('/login')
}
return (
Login
)
}
```
### Data Table with Sorting and Filtering
```jsx
import { router, usePage } from '@inertiajs/react'
import { useState, useCallback } from 'react'
import {
Table, TableBody, TableCell, TableHead, TableHeader, TableRow
} from '@/components/ui/table'
import { Input } from '@/components/ui/input'
import { Button } from '@/components/ui/button'
import { Link } from '@inertiajs/react'
import { useDebouncedCallback } from 'use-debounce'
export default function UsersTable({ users, filters }) {
const [search, setSearch] = useState(filters.search || '')
const [sort, setSort] = useState(filters.sort || 'name')
const [direction, setDirection] = useState(filters.direction || 'asc')
const debouncedSearch = useDebouncedCallback((value) => {
router.get('/users', { search: value, sort, direction }, {
preserveState: true,
replace: true,
})
}, 300)
function toggleSort(column) {
const newDirection = sort === column && direction === 'asc' ? 'desc' : 'asc'
setSort(column)
setDirection(newDirection)
router.get('/users', { search, sort: column, direction: newDirection }, {
preserveState: true,
replace: true,
})
}
return (