Skip to content

Commit 17d84fc

Browse files
authored
Merge pull request #14 from jschuler/main
Add app folder for component dev and demos
2 parents 44fabf8 + 594c743 commit 17d84fc

File tree

17 files changed

+6584
-0
lines changed

17 files changed

+6584
-0
lines changed

.github/workflows/deploy-demo.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Deploy Demo App to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
# Allow only one concurrent deployment
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version-file: '.nvmrc'
31+
cache: npm
32+
cache-dependency-path: |
33+
package-lock.json
34+
app/package-lock.json
35+
36+
- name: Install root dependencies
37+
run: npm ci
38+
39+
- name: Build library
40+
run: npm run build
41+
42+
- name: Install app dependencies
43+
working-directory: ./app
44+
run: npm ci
45+
46+
- name: Build demo app
47+
working-directory: ./app
48+
run: npm run build
49+
50+
- name: Setup Pages
51+
uses: actions/configure-pages@v4
52+
53+
- name: Upload artifact
54+
uses: actions/upload-pages-artifact@v3
55+
with:
56+
path: ./app/dist
57+
58+
deploy:
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}
62+
runs-on: ubuntu-latest
63+
needs: build
64+
steps:
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v4
68+

app/.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Build outputs
5+
dist
6+
build
7+
8+
# Logs
9+
*.log
10+
11+
# OS
12+
.DS_Store
13+

app/.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": false,
5+
"printWidth": 80,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"arrowParens": "always",
9+
"endOfLine": "lf"
10+
}
11+

app/README.md

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
# Next Gen UI — Demo App
2+
3+
This demo app loads the local `next-gen-ui-react` components for development and testing.
4+
5+
## 🌐 Live Demo
6+
7+
The demo app is automatically deployed to GitHub Pages:
8+
**https://redhat-ux.github.io/next-gen-ui-react/**
9+
10+
The deployment happens automatically on every push to the `main` branch.
11+
12+
## Quick Start
13+
14+
1. From the repo root, install dependencies for the demo:
15+
16+
```bash
17+
cd app
18+
npm install
19+
```
20+
21+
2. Start the dev server:
22+
23+
```bash
24+
npm run dev
25+
```
26+
27+
3. Open the app at http://localhost:5176
28+
29+
## Architecture
30+
31+
The demo app uses a **component registry pattern** to make it easy to add and manage component demonstrations.
32+
33+
### Key Files
34+
35+
- **`src/config/componentRegistry.ts`** - Central registry of all components
36+
- **`src/demo/demoData.ts`** - Demo data for all components
37+
- **`src/pages/`** - Individual component demo pages
38+
- **`src/layout/Sidebar.tsx`** - Auto-generated navigation
39+
- **`src/App.tsx`** - Routes and layout
40+
41+
### How It Works
42+
43+
The component registry (`componentRegistry.ts`) is the single source of truth for:
44+
- Component names and paths
45+
- GitHub source code links
46+
- Demo examples and data
47+
- Navigation structure
48+
49+
When you add a component to the registry, it automatically appears in:
50+
- ✅ Sidebar navigation
51+
- ✅ Home page links
52+
- ✅ Page titles
53+
- ✅ Source code links
54+
55+
## Adding a New Component Demo
56+
57+
To add a new component to the demo app, follow these **3 simple steps**:
58+
59+
### Step 1: Add Demo Data
60+
61+
In `src/demo/demoData.ts`, add your demo data:
62+
63+
```typescript
64+
export const myNewComponentDemo = {
65+
component: "my-component" as const,
66+
id: "demo-1",
67+
title: "Example Title",
68+
// ... your component props
69+
};
70+
71+
// Add variations if you want multiple examples
72+
export const myNewComponentDemoVariation = {
73+
component: "my-component" as const,
74+
id: "demo-2",
75+
title: "Variation Example",
76+
// ... variant props
77+
};
78+
```
79+
80+
**Important:** Always add `as const` to the `component` property.
81+
82+
### Step 2: Register in Component Registry
83+
84+
In `src/config/componentRegistry.ts`:
85+
86+
1. **Import your demo data** at the top:
87+
```typescript
88+
import { myNewComponentDemo, myNewComponentDemoVariation } from "../demo/demoData";
89+
```
90+
91+
2. **Add an entry** to the `componentRegistry` array:
92+
```typescript
93+
{
94+
id: "mynewcomponent", // Unique ID (used in URL and componentMap)
95+
name: "MyNewComponent", // Display name
96+
path: "/component/mynewcomponent", // Route path (must follow /component/:id pattern)
97+
sourceUrl: "https://github.com/RedHat-UX/next-gen-ui-react/blob/main/src/components/MyNewComponent.tsx",
98+
componentImportPath: "@local-lib/components/MyNewComponent",
99+
examples: [
100+
{ title: "Basic Example", data: myNewComponentDemo },
101+
{ title: "Variation", data: myNewComponentDemoVariation },
102+
],
103+
}
104+
```
105+
106+
### Step 3: Map Component in ComponentDemo
107+
108+
In `src/pages/ComponentDemo.tsx`:
109+
110+
1. **Import your component** at the top:
111+
```typescript
112+
import MyNewComponent from "@local-lib/components/MyNewComponent";
113+
```
114+
115+
2. **Add it to the `componentMap`**:
116+
```typescript
117+
const componentMap: Record<string, React.ComponentType<Record<string, unknown>>> = {
118+
// ... existing components
119+
mynewcomponent: MyNewComponent, // key must match the id from registry
120+
};
121+
```
122+
123+
**That's it!** 🎉 The component will now **automatically**:
124+
- ✅ Appear in the sidebar navigation
125+
- ✅ Have its own page at `/component/mynewcomponent`
126+
- ✅ Display all examples with their props
127+
- ✅ Show page title and "View Source" link
128+
- ✅ Include dividers between examples
129+
130+
### Architecture Benefits
131+
132+
This design uses a **component registry pattern** that:
133+
- Eliminates the need to create individual page files
134+
- Automatically generates navigation and routes
135+
- Makes it easy to add multiple examples per component
136+
- Keeps all configuration centralized
137+
138+
## Project Structure
139+
140+
```
141+
app/
142+
├── src/
143+
│ ├── config/
144+
│ │ └── componentRegistry.ts ← Register components here
145+
│ ├── demo/
146+
│ │ └── demoData.ts ← Add demo data here
147+
│ ├── layout/
148+
│ │ └── Sidebar.tsx ← Auto-generated from registry
149+
│ ├── pages/
150+
│ │ ├── Home.tsx ← Auto-generated links
151+
│ │ ├── DynamicComponents.tsx ← Example page
152+
│ │ └── ... ← Add new pages here
153+
│ ├── App.tsx ← Add routes here
154+
│ └── main.tsx
155+
├── package.json
156+
├── vite.config.ts
157+
└── README.md ← You are here
158+
```
159+
160+
## Available Scripts
161+
162+
```bash
163+
npm run dev # Start development server
164+
npm run build # Build for production (GitHub Pages)
165+
npm run build:netlify # Build for Netlify/Vercel (root path)
166+
npm run preview # Preview production build
167+
npm run lint # Run ESLint
168+
npm run lint:fix # Auto-fix ESLint issues
169+
npm run format # Format with Prettier
170+
npm run format:check # Check formatting
171+
```
172+
173+
## Deployment
174+
175+
The demo app can be deployed to multiple platforms.
176+
177+
### GitHub Pages (Automatic)
178+
179+
The demo app is automatically deployed to GitHub Pages via GitHub Actions.
180+
181+
**Deployment happens automatically when:**
182+
- Code is pushed to the `main` branch
183+
- The workflow can also be triggered manually from the Actions tab
184+
185+
**Manual Deployment:**
186+
1. Go to the repository's **Actions** tab on GitHub
187+
2. Select the **Deploy Demo App to GitHub Pages** workflow
188+
3. Click **Run workflow**
189+
190+
**How It Works:**
191+
192+
The deployment workflow (`.github/workflows/deploy-demo.yml`):
193+
1. Builds the library (`npm run build` in root)
194+
2. Installs app dependencies
195+
3. Builds the demo app with production settings
196+
4. Deploys the `app/dist` folder to GitHub Pages
197+
198+
**GitHub Pages Settings:**
199+
200+
To enable GitHub Pages for the first time:
201+
1. Go to repository **Settings****Pages**
202+
2. Under **Source**, select **GitHub Actions**
203+
3. The app will be available at `https://redhat-ux.github.io/next-gen-ui-react/`
204+
205+
### Netlify/Vercel (Manual)
206+
207+
For one-time or manual deployments to Netlify, Vercel, or similar platforms:
208+
209+
**Build for Netlify/Vercel:**
210+
```bash
211+
cd app
212+
npm run build:netlify
213+
```
214+
215+
**Deploy the `dist` folder:**
216+
- **Netlify Drop:** Drag `app/dist` to https://app.netlify.com/drop
217+
- **Vercel CLI:** Run `npx vercel dist --prod` from the `app` directory
218+
219+
**Note:** Use `build:netlify` instead of `build` when deploying to platforms that serve from the root path (not a subdirectory).
220+
221+
## Linting and Formatting
222+
223+
This project uses:
224+
- **ESLint** for code quality and catching bugs
225+
- **Prettier** for code formatting
226+
- Import ordering rules for consistent imports
227+
228+
All code is automatically checked and formatted. The linter enforces:
229+
- TypeScript best practices
230+
- React hooks rules
231+
- Import ordering (external → internal → relative)
232+
- No unused variables
233+
234+
## Development Notes
235+
236+
- The demo imports components directly from the parent package source using a Vite alias `@local-lib`
237+
- Changes to library code in `../src/components` will hot-reload automatically
238+
- If you run into duplicate React instances or hooks errors, set `resolve.preserveSymlinks = true` in your Vite config
239+
- The app runs on port 5176 by default (configured in `vite.config.ts`)
240+
241+
## Component Demo Best Practices
242+
243+
1. **Multiple Examples** - Show different variations and use cases
244+
2. **Descriptive Titles** - Use clear, specific titles for each example
245+
3. **Props Display** - Always show the props JSON for reference
246+
4. **Visual Separation** - Use `Divider` between multiple examples
247+
5. **Realistic Data** - Use meaningful, realistic demo data
248+
6. **Type Safety** - Use `as const` for literal types
249+
250+
## Tips
251+
252+
- Keep demo data in `demoData.ts` separate from page components
253+
- Use the registry pattern - don't hardcode navigation or links
254+
- Follow the established page component pattern for consistency
255+
- Test your component in different scenarios (with/without optional props)
256+
- Add comments to complex demo data explaining what it demonstrates
257+
258+
## Need Help?
259+
260+
- Check existing component pages for patterns to follow
261+
- Look at `src/config/componentRegistry.ts` to see how other components are registered
262+
- Run `npm run lint` before committing to catch issues early

0 commit comments

Comments
 (0)