|
| 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