Skip to content

Commit aa43267

Browse files
committed
Add app folder for component dev and demos
1 parent 44fabf8 commit aa43267

23 files changed

+6850
-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: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
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+
### Step 1: Add Demo Data
58+
59+
In `src/demo/demoData.ts`, add your demo data:
60+
61+
```typescript
62+
export const myNewComponentDemo = {
63+
component: "my-component" as const,
64+
id: "demo-1",
65+
title: "Example Title",
66+
// ... your component props
67+
};
68+
69+
// Add variations if you want multiple examples
70+
export const myNewComponentDemoVariation = {
71+
component: "my-component" as const,
72+
id: "demo-2",
73+
title: "Variation Example",
74+
// ... variant props
75+
};
76+
```
77+
78+
### Step 2: Register in Component Registry
79+
80+
In `src/config/componentRegistry.ts`, add an entry to the `componentRegistry` array:
81+
82+
```typescript
83+
{
84+
id: "mynewcomponent", // Unique ID
85+
name: "MyNewComponent", // Display name
86+
path: "/mynewcomponent", // Route path
87+
sourceUrl: "https://github.com/RedHat-UX/next-gen-ui-react/blob/main/src/components/MyNewComponent.tsx",
88+
componentImportPath: "@local-lib/components/MyNewComponent",
89+
examples: [
90+
{ title: "Basic Example", data: myNewComponentDemo },
91+
{ title: "Variation", data: myNewComponentDemoVariation },
92+
],
93+
}
94+
```
95+
96+
### Step 3: Create Component Page
97+
98+
Create `src/pages/MyNewComponent.tsx`:
99+
100+
```typescript
101+
import MyNewComponent from "@local-lib/components/MyNewComponent";
102+
import {
103+
CodeBlock,
104+
CodeBlockCode,
105+
Content,
106+
ContentVariants,
107+
Divider,
108+
} from "@patternfly/react-core";
109+
110+
import { myNewComponentDemo, myNewComponentDemoVariation } from "../demo/demoData";
111+
112+
export default function MyNewComponentPage() {
113+
return (
114+
<div>
115+
{/* First Example */}
116+
<Content component={ContentVariants.h3}>Basic Example</Content>
117+
<MyNewComponent {...myNewComponentDemo} />
118+
<Content component={ContentVariants.h4} style={{ marginTop: 16 }}>
119+
Props
120+
</Content>
121+
<CodeBlock>
122+
<CodeBlockCode>
123+
{JSON.stringify(myNewComponentDemo, null, 2)}
124+
</CodeBlockCode>
125+
</CodeBlock>
126+
127+
{/* Divider between examples */}
128+
<Divider style={{ marginTop: 32, marginBottom: 32 }} />
129+
130+
{/* Second Example */}
131+
<Content component={ContentVariants.h3}>Variation</Content>
132+
<MyNewComponent {...myNewComponentDemoVariation} />
133+
<Content component={ContentVariants.h4} style={{ marginTop: 16 }}>
134+
Props
135+
</Content>
136+
<CodeBlock>
137+
<CodeBlockCode>
138+
{JSON.stringify(myNewComponentDemoVariation, null, 2)}
139+
</CodeBlockCode>
140+
</CodeBlock>
141+
</div>
142+
);
143+
}
144+
```
145+
146+
### Step 4: Add Route
147+
148+
In `src/App.tsx`, import and add the route:
149+
150+
```typescript
151+
// Add import
152+
import MyNewComponentPage from "./pages/MyNewComponent";
153+
154+
// Add route in the Routes section
155+
<Route path="/mynewcomponent" element={<MyNewComponentPage />} />
156+
```
157+
158+
**That's it!** The component will automatically appear in:
159+
- Sidebar navigation
160+
- Home page links
161+
- Page title header
162+
- Source code link
163+
164+
## Project Structure
165+
166+
```
167+
app/
168+
├── src/
169+
│ ├── config/
170+
│ │ └── componentRegistry.ts ← Register components here
171+
│ ├── demo/
172+
│ │ └── demoData.ts ← Add demo data here
173+
│ ├── layout/
174+
│ │ └── Sidebar.tsx ← Auto-generated from registry
175+
│ ├── pages/
176+
│ │ ├── Home.tsx ← Auto-generated links
177+
│ │ ├── DynamicComponents.tsx ← Example page
178+
│ │ └── ... ← Add new pages here
179+
│ ├── App.tsx ← Add routes here
180+
│ └── main.tsx
181+
├── package.json
182+
├── vite.config.ts
183+
└── README.md ← You are here
184+
```
185+
186+
## Available Scripts
187+
188+
```bash
189+
npm run dev # Start development server
190+
npm run build # Build for production (GitHub Pages)
191+
npm run build:netlify # Build for Netlify/Vercel (root path)
192+
npm run preview # Preview production build
193+
npm run lint # Run ESLint
194+
npm run lint:fix # Auto-fix ESLint issues
195+
npm run format # Format with Prettier
196+
npm run format:check # Check formatting
197+
```
198+
199+
## Deployment
200+
201+
The demo app can be deployed to multiple platforms.
202+
203+
### GitHub Pages (Automatic)
204+
205+
The demo app is automatically deployed to GitHub Pages via GitHub Actions.
206+
207+
**Deployment happens automatically when:**
208+
- Code is pushed to the `main` branch
209+
- The workflow can also be triggered manually from the Actions tab
210+
211+
**Manual Deployment:**
212+
1. Go to the repository's **Actions** tab on GitHub
213+
2. Select the **Deploy Demo App to GitHub Pages** workflow
214+
3. Click **Run workflow**
215+
216+
**How It Works:**
217+
218+
The deployment workflow (`.github/workflows/deploy-demo.yml`):
219+
1. Builds the library (`npm run build` in root)
220+
2. Installs app dependencies
221+
3. Builds the demo app with production settings
222+
4. Deploys the `app/dist` folder to GitHub Pages
223+
224+
**GitHub Pages Settings:**
225+
226+
To enable GitHub Pages for the first time:
227+
1. Go to repository **Settings****Pages**
228+
2. Under **Source**, select **GitHub Actions**
229+
3. The app will be available at `https://redhat-ux.github.io/next-gen-ui-react/`
230+
231+
### Netlify/Vercel (Manual)
232+
233+
For one-time or manual deployments to Netlify, Vercel, or similar platforms:
234+
235+
**Build for Netlify/Vercel:**
236+
```bash
237+
cd app
238+
npm run build:netlify
239+
```
240+
241+
**Deploy the `dist` folder:**
242+
- **Netlify Drop:** Drag `app/dist` to https://app.netlify.com/drop
243+
- **Vercel CLI:** Run `npx vercel dist --prod` from the `app` directory
244+
245+
**Note:** Use `build:netlify` instead of `build` when deploying to platforms that serve from the root path (not a subdirectory).
246+
247+
## Linting and Formatting
248+
249+
This project uses:
250+
- **ESLint** for code quality and catching bugs
251+
- **Prettier** for code formatting
252+
- Import ordering rules for consistent imports
253+
254+
All code is automatically checked and formatted. The linter enforces:
255+
- TypeScript best practices
256+
- React hooks rules
257+
- Import ordering (external → internal → relative)
258+
- No unused variables
259+
260+
## Development Notes
261+
262+
- The demo imports components directly from the parent package source using a Vite alias `@local-lib`
263+
- Changes to library code in `../src/components` will hot-reload automatically
264+
- If you run into duplicate React instances or hooks errors, set `resolve.preserveSymlinks = true` in your Vite config
265+
- The app runs on port 5176 by default (configured in `vite.config.ts`)
266+
267+
## Component Demo Best Practices
268+
269+
1. **Multiple Examples** - Show different variations and use cases
270+
2. **Descriptive Titles** - Use clear, specific titles for each example
271+
3. **Props Display** - Always show the props JSON for reference
272+
4. **Visual Separation** - Use `Divider` between multiple examples
273+
5. **Realistic Data** - Use meaningful, realistic demo data
274+
6. **Type Safety** - Use `as const` for literal types
275+
276+
## Tips
277+
278+
- Keep demo data in `demoData.ts` separate from page components
279+
- Use the registry pattern - don't hardcode navigation or links
280+
- Follow the established page component pattern for consistency
281+
- Test your component in different scenarios (with/without optional props)
282+
- Add comments to complex demo data explaining what it demonstrates
283+
284+
## Need Help?
285+
286+
- Check existing component pages for patterns to follow
287+
- Look at `src/config/componentRegistry.ts` to see how other components are registered
288+
- Run `npm run lint` before committing to catch issues early

0 commit comments

Comments
 (0)