Skip to content

Commit b709a1f

Browse files
committed
Redesign examples
1 parent fa154ec commit b709a1f

65 files changed

Lines changed: 1688 additions & 1618 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Examples
2+
3+
This directory contains example applications demonstrating different ways to use AppShell. All examples implement the same **Project Manager** application with identical screens, but use different AppShell APIs for routing and navigation.
4+
5+
## Directory Structure
6+
7+
```
8+
examples/
9+
├── shared-pages/ # Shared React components (page UIs)
10+
├── file-based/ # File-based routing API (Vite)
11+
└── legacy-declarative/ # Declarative API with defineModule/defineResource (Next.js)
12+
```
13+
14+
## Examples Overview
15+
16+
### `shared-pages` — Shared Page Components
17+
18+
A standalone package that exports pure React components used by both example apps. This demonstrates how to create a **shared UI library** consumed by multiple host applications.
19+
20+
- **No routing logic** — components don't use `defineModule` or `defineResource`
21+
- **Framework-agnostic** — works with any React setup
22+
- **Exports**: `ProjectListPage`, `ProjectDetailPage`, `TaskListPage`, `DescriptionCardDemoPage`, layout demos, `ProfileSettingsPage`, plus shared context (`RoleSwitcherProvider`, `SidebarMenu`)
23+
24+
### `file-based` — File-Based Routing (Vite)
25+
26+
Demonstrates the **file-based routing API** using the AppShell Vite plugin. Routes are automatically generated from the `src/pages/` directory structure.
27+
28+
**Key patterns shown:**
29+
- `appShellPageProps` static field for page metadata (title, icon, guards)
30+
- Type-safe navigation with auto-generated `paths.for()`
31+
- Manual sidebar composition with `SidebarItem`, `SidebarGroup`, `WithGuard`
32+
- `CommandPalette` for keyboard navigation (Cmd+K)
33+
34+
```bash
35+
cd examples/file-based && pnpm dev
36+
```
37+
38+
### `legacy-declarative` — Declarative API (Next.js)
39+
40+
Demonstrates the **declarative API** using `defineModule()` and `defineResource()`. The module tree is explicitly constructed in code and passed to `AppShell` via the `modules` prop.
41+
42+
**Key patterns shown:**
43+
- `defineModule()` / `defineResource()` for module hierarchy
44+
- `modules` and `settingsResources` props on `AppShell`
45+
- Auto-generated sidebar navigation from module definitions
46+
- `basePath` for mounting AppShell under a sub-route
47+
- `guards` on modules for access control
48+
49+
```bash
50+
cd examples/legacy-declarative && pnpm dev
51+
```
52+
53+
## Screen Set
54+
55+
Both examples render the same screens for comparison:
56+
57+
| Module | Screen | Path | Features Demonstrated |
58+
|--------|--------|------|----------------------|
59+
| **Projects** | Project List | `/projects` | List UI, `Link`, nested routing |
60+
| | Project Detail | `/projects/:id` | Dynamic routes, `useParams`, `DescriptionCard` |
61+
| **Tasks** | Task List | `/tasks` | `Guard` (admin-only), role-based access control |
62+
| **Components** | DescriptionCard Demo | `/components/description-card` | Field types: badge, money, date, address, copyable |
63+
| | Layout 1 Column | `/components/layout-1-column` | `Layout` component, single column |
64+
| | Layout 2 Columns | `/components/layout-2-columns` | `Layout` with actions (buttons) |
65+
| | Layout 3 Columns | `/components/layout-3-columns` | `Layout` three-column responsive |
66+
| **Settings** | Profile | `/settings/profile` | `settingsResources` |
67+
68+
> **Note:** In the `legacy-declarative` example, all paths are prefixed with `/dashboard/` (e.g., `/dashboard/projects`) because AppShell is mounted under a Next.js catch-all route with `basePath: "dashboard"`.
69+
70+
## Role Switching
71+
72+
Both examples include a role switcher in the sidebar footer. Toggle between **Admin** and **Staff** roles to see:
73+
- The **Tasks** page appears/disappears based on the admin-only guard
74+
- `contextData.role` flowing through to guard functions

0 commit comments

Comments
 (0)