Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
- name: npm ci
run: npm ci

# Sample package.json files must match scripts/lib/versions.js;
# a hand-edited version would silently drift from every other sample.
# The root package.json must match scripts/lib/versions.js; the
# StackBlitz projects of the samples take their versions from both.
- name: Package versions in sync
run: |
npm run update:ig
git diff --exit-code -- package.json 'samples/**/package.json'
git diff --exit-code -- package.json

- name: Type check
run: npm run check
Expand Down
30 changes: 21 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Instructions for coding agents working in this repository. Setup and contributor

## What this repo is

About 990 standalone React samples for Ignite UI for React, plus an Astro site (the samples browser) that builds them all into one static site. The site is deployed to https://www.infragistics.com/react-demos, and the product docs embed its pages and read its code-viewer JSON, so URLs and output files are a public contract.
About 1,040 React samples for Ignite UI for React, plus an Astro site (the samples browser) that builds them all into one static site. The site is deployed to https://www.infragistics.com/react-demos, and the product docs embed its pages and read its code-viewer JSON, so URLs and output files are a public contract.

Branch from and target `vnext`, which deploys to staging. `master` deploys to production.

## Layout

| Path | Contents |
|------|----------|
| `samples/<group>/<component>/<name>/` | One sample, a standalone Vite project. Its `package.json` is what makes it a sample. |
| `samples/<group>/<component>/<name>/` | One sample: `src/index.tsx`, which is what makes it a sample, and the files it imports. No `package.json`, `tsconfig.json` or `README.md`; see [Project files](#project-files). |
| `src/pages/[...slug].astro` | The page for each sample: puts its CSS in `<head>`, then lazy-loads and mounts its default export |
| `src/pages/index.astro`, `src/pages/nav.json.ts`, `src/scripts/nav.ts` | Index and sidebar, built from folder names (there is no registry) |
| `src/pages/samples/[...slug].astro` | Redirects old `/samples/<slug>` URLs |
Expand All @@ -23,6 +23,16 @@ Branch from and target `vnext`, which deploys to staging. `master` deploys to pr

Build output is git-ignored and regenerated: `dist/`, `public/code-viewer/`, `public/ig-themes/`, `.astro/`. Don't edit or commit it.

## Project files

A sample runs in the samples browser (`npm run dev`), which needs no per-sample project files. The docs open it in StackBlitz as a standalone Vite project, built from the code-viewer JSON. `npm run generate:code-viewer` creates that project's files:

- `package.json`: the packages the sample imports, plus the Ignite UI packages they need alongside (declared peers, and the optional peers listed in `SUBPATH_PEERS`). Versions come from `scripts/lib/versions.js` and the root `package.json`, so a package a sample imports must be a root dependency.
- `tsconfig.json`: the compiler options of `tsconfig.samples.json`, which `check:samples` uses.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS Code now shows false errors in every sample file (vnext is fine).
Steps: open samples/inputs/checkbox/overview/src/index.tsx in VS Code → "'React' refers to a UMD global" and "Cannot find module or type declarations for side-effect import of './index.css'".
The root tsconfig.json excludes samples/, so the editor falls back to its defaults. Maybe add samples/tsconfig.json with { "extends": "../tsconfig.samples.json" }?

- `index.html` and `vite.config.js`: the templates in `scripts/lib/templates.js`, or the sample's own copy when it has one. Keep an own copy only when the sample needs a different one: a Tailwind or Sass `vite.config.js`, or an `index.html` with an extra stylesheet or attribute.

`npm run check:samples` fails when a sample folder holds anything else, or an `index.html` or `vite.config.js` that matches the template.

## Generated and hand-maintained samples

About 560 samples, mostly charts, gauges, maps and grids, are exported from [igniteui-xplat-examples](https://github.com/IgniteUI/igniteui-xplat-examples). The next export overwrites edits made here. Check before editing a sample:
Expand All @@ -34,7 +44,9 @@ curl -s -o /dev/null -w "%{http_code}\n" \
```

- **Generated**: change the source in igniteui-xplat-examples (the sample's JSON, or `code-gen-library` for data sources and handlers). Patch the sample here as well only when the fix can't wait for the next export, and say so in the PR. Don't restyle generated code (class components, `IgrXxxModule.register()`, `render(): JSX.Element`); it is the generator's output.
- **Hand-maintained**: function components with hooks, the strict `tsconfig.json` from `npm run add:sample`, and no `register()` calls for `igniteui-react` components, which no longer need them.
- **Hand-maintained**: function components with hooks, and no `register()` calls for `igniteui-react` components, which no longer need them.

An export brings only the sample's `src/`. The xplat React template is a full project, so if an export adds `package.json`, `tsconfig.json`, `index.html` or `vite.config.js` to a sample folder, delete them (`check:samples` lists them) and keep only a real override.

## The sample contract

Expand All @@ -51,25 +63,25 @@ curl -s -o /dev/null -w "%{http_code}\n" \

## Changing things

- Start a new sample with `npm run add:sample <group>/<component>/<name>`, not by copying a folder; the templates in `scripts/lib/templates.js` are current, and old folders carry outdated config.
- Never edit versions in a `package.json` by hand. Change `scripts/lib/versions.js`, then run `npm run update:ig && npm install` and commit every changed `package.json` and `package-lock.json`.
- Don't add `.eslintrc.js`, `sandbox.config.json` or `.devcontainer/` to samples, and don't add CodeSandbox links to READMEs. They were removed on purpose.
- Start a new sample with `npm run add:sample <group>/<component>/<name>`, not by copying a folder; it creates `src/index.tsx` and `src/index.css` from the templates in `scripts/lib/templates.js`.
- Never edit versions in the root `package.json` by hand. Change `scripts/lib/versions.js`, then run `npm run update:ig && npm install` and commit `package.json` and `package-lock.json`.
- Don't add `package.json`, `tsconfig.json`, `README.md`, `.eslintrc.js`, `sandbox.config.json` or `.devcontainer/` to samples. They were removed on purpose.
- Files use LF line endings (`.gitattributes`). Match the indentation of the file you edit: most samples use 4 spaces; the site, scripts and tests use 2.

## Checks

CI ([.github/workflows/ci.yml](.github/workflows/ci.yml)) runs these on every PR to `vnext` and `master`. Run them before you call a change done:

```bash
npm run update:ig && git diff --exit-code -- package.json 'samples/**/package.json' # versions in sync
npm run update:ig && git diff --exit-code -- package.json # versions in sync
npm run check # astro check of src/ and tests/
npm run check:samples # type-check every sample, ~30 s
npm run check:samples # sample folders, then type-check every sample, ~30 s
BASE_PATH=/react-demos npm run build # the deployed shape, ~2 min
BASE_PATH=/react-demos npm run test:smoke
```

- For a change confined to samples, the quick loop is `npm run check:samples`, then `npm run dev` and opening `http://localhost:4200/<group>/<component>/<name>` with no console errors. Run the full build and smoke tests before opening the PR, and always when you touch `src/`, `astro.config.mjs`, `public/` or `scripts/`.
- `check:samples` fails on any type error in a published sample. Fix the error; don't unpublish a sample to silence it. The one exception is a generated sample: fix it in igniteui-xplat-examples, and list it with its error in `scripts/lib/skip-type-check.json` until the export brings the fix, then remove it.
- `check:samples` fails on project files in a sample folder (see [Project files](#project-files)), and on any type error in a published sample. Fix the error; don't unpublish a sample to silence it. The one exception is a generated sample: fix it in igniteui-xplat-examples, and list it with its error in `scripts/lib/skip-type-check.json` until the export brings the fix, then remove it.
- The smoke tests need a build made with the same `BASE_PATH`, and Chromium: `npx playwright install --only-shell chromium`.
- In Git Bash on Windows, `BASE_PATH=/react-demos` is rewritten into a Windows path and the build fails. Prefix the command with `MSYS_NO_PATHCONV=1`, or set the variable in PowerShell.

Expand Down
36 changes: 13 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This repository contains over 900 examples on how to use [Ignite UI for React](h

Browse all samples in the [React Samples Browser](https://www.infragistics.com/react-demos/samples/), or with documentation in the [React Help](https://infragistics.com/reactsite/components/general-getting-started.html).

Each sample folder is also a standalone project with its own README, e.g. [./samples/charts/category-chart/overview/README.md](./samples/charts/category-chart/overview/README.md).
To edit a sample in your browser, open it in the documentation and select **Edit in StackBlitz** under it.

## Setup

Expand All @@ -70,17 +70,7 @@ npm run dev

Open [http://localhost:4200](http://localhost:4200). The index lists every component; the sidebar lists every sample. Samples compile on demand, so there is no copy or full build step, and edits to `samples/` reload in place.

## Running an Individual Sample

Every sample under `samples/{group}/{component}/{name}/` runs on its own:

```bash
cd samples/charts/category-chart/overview
npm install
npm start
```

Then open [http://localhost:4200](http://localhost:4200).
To open one sample, go to its path, e.g. [http://localhost:4200/charts/category-chart/overview](http://localhost:4200/charts/category-chart/overview). Sample folders are not standalone projects; they hold only the sample's own files.

## Building for Production

Expand All @@ -89,7 +79,7 @@ npm run build
npm run preview
```

`npm run build` first copies the Ignite UI theme sheets to `public/ig-themes/` and generates `public/code-viewer/**/*.json` (the source tabs of the docs code viewer), then builds every sample page into `dist/`. `npm run preview` serves `dist/` on [http://localhost:4200](http://localhost:4200).
`npm run build` first copies the Ignite UI theme sheets to `public/ig-themes/` and generates `public/code-viewer/**/*.json` (the source tabs of the docs code viewer, and the files of the StackBlitz project the docs open), then builds every sample page into `dist/`. `npm run preview` serves `dist/` on [http://localhost:4200](http://localhost:4200).

The deployed site lives under a sub-path. Set `BASE_PATH` for both commands to reproduce it:

Expand Down Expand Up @@ -119,12 +109,13 @@ Use the same `BASE_PATH` for the build and the tests. CI builds and tests with `
npm run add:sample inputs/button/new-thing
```
The folder must be exactly `samples/{group}/{component}/{name}/`, with:
- `src/index.tsx`: `export default` the sample component, and end with the standalone mount (`root.render(<Sample />)`). The samples browser strips that mount and renders the default export itself; the build fails if either is missing.
- `index.html`: the standalone entry, `<div id="root">` only.
- `package.json`: dependencies for running standalone. Its presence is what adds the sample to the browser.
- `src/index.tsx`: `export default` the sample component, and end with the standalone mount (`root.render(<Sample />)`). The samples browser strips that mount and renders the default export itself; the build fails if either is missing. This file is what adds the sample to the browser.
- `src/index.css`, and any data or helper files the sample imports.

Import theme and sample CSS from `src/index.tsx` (e.g. `import './index.css';`) so the page puts it in `<head>` at first paint.

Don't add `package.json`, `tsconfig.json`, `index.html` or `vite.config.js`. The StackBlitz project's files are generated with the code-viewer JSON, and `package.json` lists the packages the sample imports. A sample keeps its own `vite.config.js` or `index.html` only when it needs a different one, such as a Tailwind sample's `vite.config.js`.

3. Start the dev server and verify:
```bash
npm run dev
Expand All @@ -141,16 +132,15 @@ Use the same `BASE_PATH` for the build and the tests. CI builds and tests with `

## Updating Ignite UI Package Versions

Do **not** edit version strings in `package.json` files by hand; CI fails when a sample's versions drift from the list.
Do **not** edit version strings in `package.json` by hand; CI fails when the root versions drift from the list.

1. Update the versions in [./scripts/lib/versions.js](./scripts/lib/versions.js): `SHARED` applies to the root and every sample, `TOOLING` to samples only.
1. Update the versions in [./scripts/lib/versions.js](./scripts/lib/versions.js): `SHARED` applies to the root `package.json` and the samples' StackBlitz projects, `TOOLING` to the StackBlitz projects only.
2. Run from the repo root:
```bash
npm run update:ig
npm install
```
3. Create and merge a pull request with the updated `package.json` files.
4. Create a second pull request with the same versions in `/editor-templates/react/main-template/package.json` of the [igniteui-xplat-examples](https://github.com/IgniteUI/igniteui-xplat-examples) repository.
3. Create and merge a pull request with the updated `package.json` and `package-lock.json`.

## Scripts Reference

Expand All @@ -161,10 +151,10 @@ Do **not** edit version strings in `package.json` files by hand; CI fails when a
| `npm run preview` | Serve `dist/` on port 4200 |
| `npm run test:smoke` | Run the Playwright smoke tests against the production build |
| `npm run check` | Type-check `src/` and `tests/` with `astro check` |
| `npm run check:samples` | Type-check every published sample, except the generated ones listed in `scripts/lib/skip-type-check.json` |
| `npm run check:samples` | Fail on project files in sample folders, then type-check every published sample, except the generated ones listed in `scripts/lib/skip-type-check.json` |
| `npm run add:sample` | Scaffold `samples/{group}/{component}/{name}/` |
| `npm run update:ig` | Apply `scripts/lib/versions.js` to every `package.json` |
| `npm run generate:code-viewer` | Regenerate `public/code-viewer/**/*.json` |
| `npm run update:ig` | Apply `scripts/lib/versions.js` to the root `package.json` |
| `npm run generate:code-viewer` | Regenerate `public/code-viewer/**/*.json`, including each sample's StackBlitz project files |
| `npm run copy:themes` | Copy Ignite UI theme sheets to `public/ig-themes/` |

## Learn More
Expand Down
7 changes: 4 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ const SAMPLE_SOURCE_RE = /[\\/]samples[\\/].+[\\/]src[\\/][^\\/]+\.[jt]sx?$/;
* const root = ReactDOM.createRoot(document.getElementById('root'));
* root.render(<Sample/>);
*
* so it runs standalone. The `[...slug].astro` loader mounts the module's
* so it runs standalone, as the StackBlitz project the docs build from the
* code-viewer JSON. The `[...slug].astro` loader mounts the module's
* default export itself, after the dynamic import resolves, so the page
* controls when (and whether) a sample renders. Keeping the module-level
* mount would render every sample twice into the same container. Stripping
* it here (instead of editing 950+ samples, which igniteui-xplat-examples
* generates) keeps each sample runnable standalone.
* it here, instead of removing it from 1,000+ samples, keeps each sample
* runnable standalone.
*
* A sample that does not match the contract fails the build: a silent miss
* would be a double render or a blank page.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"preview": "astro preview --port 4200",
"build:preview": "npm run build && npm run preview",
"check": "astro check",
"check:samples": "node scripts/check-samples.js",
"check:samples": "node scripts/check-sample-files.js && node scripts/check-samples.js",
"generate:code-viewer": "node scripts/generate-code-viewer.js",
"update:ig": "node scripts/update-ig.js",
"test:smoke": "playwright test"
Expand Down
50 changes: 0 additions & 50 deletions samples/charts/category-chart/annotations-all/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions samples/charts/category-chart/annotations-all/index.html

This file was deleted.

50 changes: 0 additions & 50 deletions samples/charts/category-chart/annotations-all/package.json

This file was deleted.

Loading
Loading