@stamcat/craftsman 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stamcat/craftsman",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "A powerful, lightweight framework for design systems",
6
6
  "repository": {
@@ -33,6 +33,8 @@
33
33
  "@atlaskit/pragmatic-drag-and-drop": "^3.0.0",
34
34
  "@floating-ui/react-dom": "^2.1.0",
35
35
  "@wojtekmaj/react-daterange-picker": "^7.1.0",
36
+ "ag-grid-community": "^36.2.0",
37
+ "ag-grid-react": "^36.2.0",
36
38
  "chart.js": "^4.5.1",
37
39
  "dompurify": "^3.4.0",
38
40
  "embla-carousel-react": "^8.6.0",
@@ -133,7 +133,14 @@ toast.info("New version available.");
133
133
 
134
134
  Craftsman uses `react-chartjs-2` directly, without modification — there is no Craftsman `Chart` wrapper component. Consumers install `react-chartjs-2` and its `chart.js` peer dependency themselves and use the upstream API exactly as documented at https://react-chartjs-2.js.org/examples.
135
135
 
136
- Import:
136
+ Do this, in order, every time a chart is requested — do not stop after only picking a chart type:
137
+
138
+ 1. Confirm `chart.js` and `react-chartjs-2` are installed (`npm install chart.js react-chartjs-2` if missing — do not skip this because you "can't run commands"; ask the user to run it if you truly cannot).
139
+ 2. Import the chart component (`Bar`, `Line`, `Pie`, `Doughnut`, `PolarArea`, `Radar`, `Scatter`, `Bubble`, or `Chart` for mixed types) from `react-chartjs-2`.
140
+ 3. Import and `ChartJS.register(...)` only the `chart.js` pieces that chart type needs, once at module scope, before any render.
141
+ 4. Build a `data` object (`labels` + `datasets`) and an `options` object, then render `<ChartComponent data={data} options={options} />`.
142
+
143
+ Full minimal working example (bar chart) — use this shape as the template for any chart type:
137
144
 
138
145
  ```tsx
139
146
  import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Tooltip, Legend } from "chart.js";
@@ -141,13 +148,81 @@ import { Bar } from "react-chartjs-2";
141
148
 
142
149
  // Register only the controllers/elements/scales/plugins the chart type needs — chart.js is tree-shakeable.
143
150
  ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
151
+
152
+ function RevenueChart() {
153
+ return (
154
+ <Bar
155
+ data={{
156
+ labels: ["January", "February", "March"],
157
+ datasets: [{ label: "Revenue", data: [12, 19, 8], backgroundColor: "#3A70C2" }],
158
+ }}
159
+ options={{ responsive: true }}
160
+ />
161
+ );
162
+ }
144
163
  ```
145
164
 
146
- Usage:
165
+ Usage notes:
147
166
 
148
- - Every chart type used (`Bar`, `Line`, `Pie`, `Doughnut`, `PolarArea`, `Radar`, `Scatter`, `Bubble`, `Chart` for mixed types) must have its corresponding `chart.js` pieces registered once at module scope before render.
167
+ - Every chart type used (`Bar`, `Line`, `Pie`, `Doughnut`, `PolarArea`, `Radar`, `Scatter`, `Bubble`, `Chart` for mixed types) must have its corresponding `chart.js` pieces registered once at module scope before render — a missing registration is the most common cause of a blank canvas, not a bug in the library.
168
+ - "Donut" is just the common spelling of "doughnut" — chart.js and react-chartjs-2 only export `Doughnut`, so treat a request for a "donut chart" as a request for the `Doughnut` chart type. Do not ask the user to clarify or stall on this — just use `Doughnut`.
149
169
  - Dataset colors must be literal color values (hex/`rgba()`), not CSS variables (`var(--blue500)`) — chart.js draws to a `<canvas>` 2D context, which cannot resolve CSS custom properties. Use `colors` and `hexToRgba` from `@stamcat/craftsman/styles` (see the [craftsman-style-utilities skill](../craftsman-style-utilities/SKILL.md)) to stay on-palette instead of hard-coding hex strings inline.
150
- - See `src/stories/organisms/Charts.stories.tsx` in this repo for a full worked example of every chart type from the react-chartjs-2 examples page.
170
+ - Storybook story files are **not published in the npm package** (excluded from the build to reduce package size) — do not look for them in `node_modules/@stamcat/craftsman`. If you are working inside the craftsman source repo itself, `src/stories/organisms/Charts.stories.tsx` has a full worked example of every chart type from the react-chartjs-2 examples page; copy the closest matching example and adapt the data. If you are in a consuming application, follow the steps and minimal example above directly instead.
171
+
172
+ ## Tables (ag-grid-community)
173
+
174
+ Craftsman does not wrap `ag-grid-community`/`ag-grid-react` with a custom component. We use them directly, without modification, for advanced data visualization tables (large sortable/filterable datasets) — exactly as documented upstream at https://www.ag-grid.com/react-data-grid/.
175
+
176
+ Do this, in order, every time a table/grid is requested — do not stop after only picking column definitions:
177
+
178
+ 1. Confirm `ag-grid-community` and `ag-grid-react` are installed (`npm install ag-grid-community ag-grid-react` if missing — do not skip this because you "can't run commands"; ask the user to run it if you truly cannot).
179
+ 2. Call `ModuleRegistry.registerModules([AllCommunityModule])` once at module scope, before any grid renders. Without this call the grid renders blank/broken — this is expected AG Grid v33+ behavior, not a library bug.
180
+ 3. Define `columnDefs` (one entry per column) and `rowData` (your array of row objects).
181
+ 4. Render `<AgGridReact theme={themeQuartz} rowData={rowData} columnDefs={columnDefs} />` inside a container with an explicit height (AG Grid does not auto-size its container).
182
+ 5. Only reach for Community-safe options (see below). If the request needs row grouping, pivoting, master/detail, server-side row model, or Excel export, tell the user those are AG Grid Enterprise features requiring a separate commercial license — do not silently omit the feature or stall without explanation.
183
+
184
+ Full minimal working example — use this shape as the template for any table:
185
+
186
+ ```tsx
187
+ import { AllCommunityModule, ModuleRegistry, themeQuartz, type ColDef } from "ag-grid-community";
188
+ import { AgGridReact } from "ag-grid-react";
189
+
190
+ // Register only the Community module — do not register Enterprise modules without a license.
191
+ ModuleRegistry.registerModules([AllCommunityModule]);
192
+
193
+ type Product = { readonly name: string; readonly price: number };
194
+
195
+ const rowData: Product[] = [
196
+ { name: "Trail Runner Jacket", price: 129 },
197
+ { name: "Insulated Water Bottle", price: 32 },
198
+ ];
199
+
200
+ const columnDefs: ColDef<Product>[] = [{ field: "name", filter: true }, { field: "price" }];
201
+
202
+ function ProductTable() {
203
+ return (
204
+ <div style={{ height: 360 }}>
205
+ <AgGridReact<Product> theme={themeQuartz} rowData={rowData} columnDefs={columnDefs} pagination />
206
+ </div>
207
+ );
208
+ }
209
+ ```
210
+
211
+ Import reference:
212
+
213
+ ```tsx
214
+ import { AllCommunityModule, ModuleRegistry, themeQuartz } from "ag-grid-community";
215
+ import { AgGridReact } from "ag-grid-react";
216
+
217
+ // Register only the Community module — do not register Enterprise modules without a license.
218
+ ModuleRegistry.registerModules([AllCommunityModule]);
219
+ ```
220
+
221
+ Usage:
222
+
223
+ - Only the **free Community feature set** is used/showcased in this repo: client-side sorting, filtering, pagination, row selection, cell rendering/formatting, quick filter, and CSV export.
224
+ - AG Grid also sells **Enterprise-only** features (row grouping, pivoting, master/detail, server-side row model, Excel export, and others). These require registering separate Enterprise modules and a commercial license key. Do not enable or suggest Enterprise modules unless the consumer confirms they hold an AG Grid Enterprise license — it is the consumer's responsibility to obtain and configure that license.
225
+ - Storybook story files are **not published in the npm package** (excluded from the build to reduce package size) — do not look for them in `node_modules/@stamcat/craftsman`. If you are working inside the craftsman source repo itself, `src/stories/organisms/Tables.stories.tsx` has worked Community-only examples. If you are in a consuming application, follow the steps and minimal example above directly instead.
151
226
 
152
227
  ## Code Generation Patterns to Prefer
153
228