@salesforce/webapp-template-app-react-template-b2e-experimental 1.112.5 → 1.112.7

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.
Files changed (49) hide show
  1. package/dist/.a4drules/webapp-data.md +5 -5
  2. package/dist/.a4drules/webapp-ui.md +2 -2
  3. package/dist/AGENT.md +6 -10
  4. package/dist/CHANGELOG.md +16 -0
  5. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package.json +3 -3
  6. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/graphqlClient.ts +25 -0
  7. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/__examples__/pages/AccountSearch.tsx +82 -54
  8. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/FilterContext.tsx +73 -0
  9. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/PaginationControls.tsx +45 -87
  10. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/BooleanFilter.tsx +16 -36
  11. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/DateFilter.tsx +33 -77
  12. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/DateRangeFilter.tsx +14 -23
  13. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/MultiSelectFilter.tsx +18 -26
  14. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/NumericRangeFilter.tsx +22 -39
  15. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/SearchFilter.tsx +12 -15
  16. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/SelectFilter.tsx +30 -34
  17. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/filters/TextFilter.tsx +27 -30
  18. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/hooks/useAsyncData.ts +1 -0
  19. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/hooks/useCachedAsyncData.ts +1 -0
  20. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/hooks/useObjectSearchParams.ts +22 -0
  21. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/routes.tsx +0 -17
  22. package/dist/package-lock.json +2 -2
  23. package/dist/package.json +1 -1
  24. package/dist/{.a4drules/skills/using-salesforce-data → scripts}/graphql-search.sh +4 -4
  25. package/package.json +1 -1
  26. package/dist/.a4drules/skills/building-data-visualization/SKILL.md +0 -72
  27. package/dist/.a4drules/skills/building-data-visualization/implementation/bar-line-chart.md +0 -316
  28. package/dist/.a4drules/skills/building-data-visualization/implementation/dashboard-layout.md +0 -189
  29. package/dist/.a4drules/skills/building-data-visualization/implementation/donut-chart.md +0 -181
  30. package/dist/.a4drules/skills/building-data-visualization/implementation/stat-card.md +0 -150
  31. package/dist/.a4drules/skills/building-react-components/SKILL.md +0 -96
  32. package/dist/.a4drules/skills/building-react-components/implementation/component.md +0 -78
  33. package/dist/.a4drules/skills/building-react-components/implementation/header-footer.md +0 -132
  34. package/dist/.a4drules/skills/building-react-components/implementation/page.md +0 -93
  35. package/dist/.a4drules/skills/configuring-csp-trusted-sites/SKILL.md +0 -90
  36. package/dist/.a4drules/skills/configuring-csp-trusted-sites/implementation/metadata-format.md +0 -281
  37. package/dist/.a4drules/skills/configuring-webapp-metadata/SKILL.md +0 -158
  38. package/dist/.a4drules/skills/creating-webapp/SKILL.md +0 -140
  39. package/dist/.a4drules/skills/deploying-to-salesforce/SKILL.md +0 -226
  40. package/dist/.a4drules/skills/implementing-file-upload/SKILL.md +0 -396
  41. package/dist/.a4drules/skills/installing-webapp-features/SKILL.md +0 -210
  42. package/dist/.a4drules/skills/managing-agentforce-conversation-client/SKILL.md +0 -186
  43. package/dist/.a4drules/skills/managing-agentforce-conversation-client/references/constraints.md +0 -134
  44. package/dist/.a4drules/skills/managing-agentforce-conversation-client/references/examples.md +0 -132
  45. package/dist/.a4drules/skills/managing-agentforce-conversation-client/references/style-tokens.md +0 -101
  46. package/dist/.a4drules/skills/managing-agentforce-conversation-client/references/troubleshooting.md +0 -57
  47. package/dist/.a4drules/skills/using-salesforce-data/SKILL.md +0 -363
  48. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/features/object-search/components/FilterPanel.tsx +0 -127
  49. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/TestAccPage.tsx +0 -19
@@ -1,41 +1,36 @@
1
1
  import { Input } from "../../../../components/ui/input";
2
2
  import { Label } from "../../../../components/ui/label";
3
3
  import { cn } from "../../../../lib/utils";
4
- import type { FilterFieldConfig, ActiveFilterValue } from "../../utils/filterUtils";
4
+ import { useFilterField } from "../FilterContext";
5
+ import type { ActiveFilterValue } from "../../utils/filterUtils";
5
6
 
6
7
  interface TextFilterProps extends Omit<React.ComponentProps<"div">, "onChange"> {
7
- config: FilterFieldConfig;
8
- value: ActiveFilterValue | undefined;
9
- onChange: (value: ActiveFilterValue | undefined) => void;
10
- labelProps?: React.ComponentProps<typeof Label>;
11
- inputProps?: Omit<React.ComponentProps<typeof TextFilterInput>, "config" | "value" | "onChange">;
12
- helpTextProps?: React.ComponentProps<"p">;
8
+ field: string;
9
+ label: string;
10
+ placeholder?: string;
11
+ helpText?: string;
13
12
  }
14
13
 
15
14
  export function TextFilter({
16
- config,
17
- value,
18
- onChange,
15
+ field,
16
+ label,
17
+ placeholder,
18
+ helpText,
19
19
  className,
20
- labelProps,
21
- inputProps,
22
- helpTextProps,
23
20
  ...props
24
21
  }: TextFilterProps) {
22
+ const { value, onChange } = useFilterField(field);
25
23
  return (
26
24
  <div className={cn("space-y-1.5", className)} {...props}>
27
- <Label htmlFor={`filter-${config.field}`} {...labelProps}>
28
- {labelProps?.children ?? config.label}
29
- </Label>
30
- <TextFilterInput config={config} value={value} onChange={onChange} {...inputProps} />
31
- {config.helpText && (
32
- <p
33
- {...helpTextProps}
34
- className={cn("text-xs text-muted-foreground", helpTextProps?.className)}
35
- >
36
- {helpTextProps?.children ?? config.helpText}
37
- </p>
38
- )}
25
+ <Label htmlFor={`filter-${field}`}>{label}</Label>
26
+ <TextFilterInput
27
+ field={field}
28
+ label={label}
29
+ placeholder={placeholder}
30
+ value={value}
31
+ onChange={onChange}
32
+ />
33
+ {helpText && <p className="text-xs text-muted-foreground">{helpText}</p>}
39
34
  </div>
40
35
  );
41
36
  }
@@ -44,13 +39,15 @@ interface TextFilterInputProps extends Omit<
44
39
  React.ComponentProps<typeof Input>,
45
40
  "onChange" | "value"
46
41
  > {
47
- config: FilterFieldConfig;
42
+ field: string;
43
+ label: string;
48
44
  value: ActiveFilterValue | undefined;
49
45
  onChange: (value: ActiveFilterValue | undefined) => void;
50
46
  }
51
47
 
52
48
  export function TextFilterInput({
53
- config,
49
+ field,
50
+ label,
54
51
  value,
55
52
  onChange,
56
53
  className,
@@ -58,14 +55,14 @@ export function TextFilterInput({
58
55
  }: TextFilterInputProps) {
59
56
  return (
60
57
  <Input
61
- id={`filter-${config.field}`}
58
+ id={`filter-${field}`}
62
59
  type="text"
63
- placeholder={config.placeholder ?? `Filter by ${config.label.toLowerCase()}...`}
60
+ placeholder={props.placeholder ?? `Filter by ${label.toLowerCase()}...`}
64
61
  value={value?.value ?? ""}
65
62
  onChange={(e) => {
66
63
  const v = e.target.value;
67
64
  if (v) {
68
- onChange({ field: config.field, label: config.label, type: "text", value: v });
65
+ onChange({ field, label, type: "text", value: v });
69
66
  } else {
70
67
  onChange(undefined);
71
68
  }
@@ -38,6 +38,7 @@ export function useAsyncData<T>(
38
38
  if (!cancelled) setData(result);
39
39
  })
40
40
  .catch((err) => {
41
+ console.error(err);
41
42
  if (!cancelled) setError(err instanceof Error ? err.message : "An error occurred");
42
43
  })
43
44
  .finally(() => {
@@ -166,6 +166,7 @@ export function useCachedAsyncData<T>(
166
166
  }
167
167
  })
168
168
  .catch((err) => {
169
+ console.error(err);
169
170
  if (!cancelled) setError(err instanceof Error ? err.message : "An error occurred");
170
171
  })
171
172
  .finally(() => {
@@ -14,6 +14,28 @@ export interface PaginationConfig {
14
14
  validPageSizes: number[];
15
15
  }
16
16
 
17
+ export interface UseObjectSearchParamsReturn<TFilter, TOrderBy> {
18
+ filters: {
19
+ active: ActiveFilterValue[];
20
+ set: (field: string, value: ActiveFilterValue | undefined) => void;
21
+ remove: (field: string) => void;
22
+ };
23
+ sort: {
24
+ current: SortState | null;
25
+ set: (sort: SortState | null) => void;
26
+ };
27
+ query: { where: TFilter; orderBy: TOrderBy };
28
+ pagination: {
29
+ pageSize: number;
30
+ pageIndex: number;
31
+ afterCursor: string | undefined;
32
+ setPageSize: (size: number) => void;
33
+ goToNextPage: (cursor: string) => void;
34
+ goToPreviousPage: () => void;
35
+ };
36
+ resetAll: () => void;
37
+ }
38
+
17
39
  /**
18
40
  * Manages filter, sort, and cursor-based pagination state for an object search page.
19
41
  *
@@ -2,10 +2,6 @@ import type { RouteObject } from 'react-router';
2
2
  import AppLayout from './appLayout';
3
3
  import Home from './features/object-search/__examples__/pages/Home';
4
4
  import NotFound from './pages/NotFound';
5
- import TestAccPage from "./pages/TestAccPage";
6
- import AccountSearch from "./features/object-search/__examples__/pages/AccountSearch";
7
- import AccountObjectDetail from "./features/object-search/__examples__/pages/AccountObjectDetailPage";
8
-
9
5
  export const routes: RouteObject[] = [
10
6
  {
11
7
  path: "/",
@@ -19,19 +15,6 @@ export const routes: RouteObject[] = [
19
15
  {
20
16
  path: '*',
21
17
  element: <NotFound />
22
- },
23
- {
24
- path: "test-acc",
25
- element: <TestAccPage />,
26
- handle: { showInNavigation: true, label: "Test ACC" }
27
- },
28
- {
29
- path: "accounts/:recordId",
30
- element: <AccountObjectDetail />
31
- },
32
- {
33
- path: "accounts",
34
- element: <AccountSearch />
35
18
  }
36
19
  ]
37
20
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
3
- "version": "1.112.5",
3
+ "version": "1.112.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
9
- "version": "1.112.5",
9
+ "version": "1.112.7",
10
10
  "license": "SEE LICENSE IN LICENSE.txt",
11
11
  "devDependencies": {
12
12
  "@lwc/eslint-plugin-lwc": "^3.3.0",
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
3
- "version": "1.112.5",
3
+ "version": "1.112.7",
4
4
  "description": "Base SFDX project template",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "publishConfig": {
@@ -2,12 +2,12 @@
2
2
  # graphql-search.sh — Look up one or more Salesforce entities in schema.graphql.
3
3
  #
4
4
  # Run from the SFDX project root (where schema.graphql lives):
5
- # bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account
6
- # bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account Contact Opportunity
5
+ # bash scripts/graphql-search.sh Account
6
+ # bash scripts/graphql-search.sh Account Contact Opportunity
7
7
  #
8
8
  # Pass a custom schema path with -s / --schema:
9
- # bash .a4drules/skills/using-salesforce-data/graphql-search.sh -s /path/to/schema.graphql Account
10
- # bash .a4drules/skills/using-salesforce-data/graphql-search.sh --schema ./other/schema.graphql Account Contact
9
+ # bash scripts/graphql-search.sh -s /path/to/schema.graphql Account
10
+ # bash scripts/graphql-search.sh --schema ./other/schema.graphql Account Contact
11
11
  #
12
12
  # Output sections per entity:
13
13
  # 1. Type definition — all fields and relationships
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-app-react-template-b2e-experimental",
3
- "version": "1.112.5",
3
+ "version": "1.112.7",
4
4
  "description": "B2E template app (from BYO)",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "",
@@ -1,72 +0,0 @@
1
- ---
2
- name: building-data-visualization
3
- description: Adds data visualization components (charts, stat cards, KPI metrics) to React pages using Recharts. Use when the user asks to add a chart, graph, donut chart, pie chart, bar chart, stat card, KPI metric, dashboard visualization, or analytics component to the web application.
4
- ---
5
-
6
- # Data Visualization
7
-
8
- ## When to Use
9
-
10
- Use this skill when:
11
- - Adding charts (donut, pie, bar, line, area) to a dashboard or analytics page
12
- - Displaying KPI/metric stat cards with trend indicators
13
- - Building a dashboard layout with mixed chart types and summary cards
14
-
15
- ---
16
-
17
- ## Step 1 — Determine the visualization type
18
-
19
- Identify what the user needs:
20
-
21
- - **Donut / pie chart** — categorical breakdown (e.g. issue types, status distribution)
22
- - **Bar chart** — comparison across categories or time periods
23
- - **Line / area chart** — trends over time
24
- - **Stat card** — single KPI metric with optional trend indicator
25
- - **Combined dashboard** — stat cards + one or more charts
26
-
27
- If unclear, ask:
28
-
29
- > "What data should the chart display, and would a donut chart, bar chart, line chart, or stat cards work best?"
30
-
31
- ---
32
-
33
- ## Step 2 — Install dependencies
34
-
35
- All chart types in this skill use **recharts**. Install once from the web app directory:
36
-
37
- ```bash
38
- npm install recharts
39
- ```
40
-
41
- Recharts is built on D3 and provides declarative React components. No additional CSS is needed.
42
-
43
- ---
44
-
45
- ## Step 3 — Choose implementation path
46
-
47
- Read the corresponding guide:
48
-
49
- - **Bar chart** — read `implementation/bar-line-chart.md` (categorical data)
50
- - **Line / area chart** — read `implementation/bar-line-chart.md` (time-series data)
51
- - **Donut / pie chart** — read `implementation/donut-chart.md`
52
- - **Stat card with trend** — read `implementation/stat-card.md`
53
- - **Dashboard layout** — read `implementation/dashboard-layout.md`
54
-
55
- ---
56
-
57
- ## Verification
58
-
59
- Before completing:
60
-
61
- 1. Chart renders with correct data and colors.
62
- 2. Chart is responsive (resizes with container).
63
- 3. Legend labels match the data categories.
64
- 4. Stat card trends display correct positive/negative indicators.
65
- 5. Run from the web app directory:
66
-
67
- ```bash
68
- cd force-app/main/default/webapplications/<appName> && npm run lint && npm run build
69
- ```
70
-
71
- - **Lint:** MUST result in 0 errors.
72
- - **Build:** MUST succeed.
@@ -1,316 +0,0 @@
1
- # Bar & Line / Area Chart — Implementation Guide
2
-
3
- Requires **recharts** (install from the web app directory; see SKILL.md Step 2).
4
-
5
- ---
6
-
7
- ## Data shapes
8
-
9
- ### Time-series (line / area chart)
10
-
11
- Use when data represents a trend over time or ordered sequence.
12
-
13
- ```ts
14
- interface TimeSeriesDataPoint {
15
- x: string; // date or label on the x-axis
16
- y: number; // numeric value
17
- }
18
- ```
19
-
20
- Map raw fields to this shape: e.g. `date` → `x`, `revenue` → `y`.
21
-
22
- ### Categorical (bar chart)
23
-
24
- Use when data compares discrete categories.
25
-
26
- ```ts
27
- interface CategoricalDataPoint {
28
- name: string; // category label
29
- value: number; // numeric value
30
- }
31
- ```
32
-
33
- Map raw fields to this shape: e.g. `product` → `name`, `sales` → `value`.
34
-
35
- ### How to decide
36
-
37
- | Signal | Type |
38
- |--------|------|
39
- | "over time", "trend", date-like keys | Time-series → line chart |
40
- | "by category", "by X", label-like keys | Categorical → bar chart |
41
-
42
- ---
43
-
44
- ## Theme colors
45
-
46
- Pick a theme based on the data's sentiment:
47
-
48
- | Theme | Stroke / Fill | When to use |
49
- |-------|---------------|-------------|
50
- | `green` | `#22c55e` | Growth, gain, positive trend |
51
- | `red` | `#ef4444` | Decline, loss, negative trend |
52
- | `neutral` | `#6366f1` | Default or mixed data |
53
-
54
- Define colors as constants — do not use inline hex values.
55
-
56
- ```ts
57
- const THEME_COLORS = {
58
- red: "#ef4444",
59
- green: "#22c55e",
60
- neutral: "#6366f1",
61
- } as const;
62
-
63
- type ChartTheme = keyof typeof THEME_COLORS;
64
- ```
65
-
66
- ---
67
-
68
- ## Line chart component
69
-
70
- Create at `components/LineChart.tsx` (or colocate with the page):
71
-
72
- ```tsx
73
- import React from "react";
74
- import {
75
- LineChart as RechartsLineChart,
76
- Line,
77
- XAxis,
78
- YAxis,
79
- CartesianGrid,
80
- Tooltip,
81
- Legend,
82
- ResponsiveContainer,
83
- } from "recharts";
84
-
85
- const THEME_COLORS = {
86
- red: "#ef4444",
87
- green: "#22c55e",
88
- neutral: "#6366f1",
89
- } as const;
90
-
91
- type ChartTheme = keyof typeof THEME_COLORS;
92
-
93
- interface TimeSeriesDataPoint {
94
- x: string;
95
- y: number;
96
- }
97
-
98
- interface TimeSeriesChartProps {
99
- data: TimeSeriesDataPoint[];
100
- theme?: ChartTheme;
101
- title?: string;
102
- className?: string;
103
- }
104
-
105
- export function TimeSeriesChart({
106
- data,
107
- theme = "neutral",
108
- title,
109
- className = "",
110
- }: TimeSeriesChartProps) {
111
- if (data.length === 0) {
112
- return <p className="text-muted-foreground text-center py-8">No data to display</p>;
113
- }
114
-
115
- const color = THEME_COLORS[theme];
116
-
117
- return (
118
- <div className={className}>
119
- {title && (
120
- <h3 className="text-sm font-medium text-primary mb-2 uppercase tracking-wide">
121
- {title}
122
- </h3>
123
- )}
124
- <ResponsiveContainer width="100%" height={300}>
125
- <RechartsLineChart data={data}>
126
- <CartesianGrid strokeDasharray="3 3" />
127
- <XAxis dataKey="x" />
128
- <YAxis />
129
- <Tooltip />
130
- <Legend />
131
- <Line type="monotone" dataKey="y" stroke={color} strokeWidth={2} dot={false} />
132
- </RechartsLineChart>
133
- </ResponsiveContainer>
134
- </div>
135
- );
136
- }
137
- ```
138
-
139
- ---
140
-
141
- ## Bar chart component
142
-
143
- Create at `components/BarChart.tsx` (or colocate with the page):
144
-
145
- ```tsx
146
- import React from "react";
147
- import {
148
- BarChart as RechartsBarChart,
149
- Bar,
150
- XAxis,
151
- YAxis,
152
- CartesianGrid,
153
- Tooltip,
154
- Legend,
155
- ResponsiveContainer,
156
- } from "recharts";
157
-
158
- const THEME_COLORS = {
159
- red: "#ef4444",
160
- green: "#22c55e",
161
- neutral: "#6366f1",
162
- } as const;
163
-
164
- type ChartTheme = keyof typeof THEME_COLORS;
165
-
166
- interface CategoricalDataPoint {
167
- name: string;
168
- value: number;
169
- }
170
-
171
- interface CategoricalChartProps {
172
- data: CategoricalDataPoint[];
173
- theme?: ChartTheme;
174
- title?: string;
175
- className?: string;
176
- }
177
-
178
- export function CategoricalChart({
179
- data,
180
- theme = "neutral",
181
- title,
182
- className = "",
183
- }: CategoricalChartProps) {
184
- if (data.length === 0) {
185
- return <p className="text-muted-foreground text-center py-8">No data to display</p>;
186
- }
187
-
188
- const color = THEME_COLORS[theme];
189
-
190
- return (
191
- <div className={className}>
192
- {title && (
193
- <h3 className="text-sm font-medium text-primary mb-2 uppercase tracking-wide">
194
- {title}
195
- </h3>
196
- )}
197
- <ResponsiveContainer width="100%" height={300}>
198
- <RechartsBarChart data={data}>
199
- <CartesianGrid strokeDasharray="3 3" />
200
- <XAxis dataKey="name" />
201
- <YAxis />
202
- <Tooltip />
203
- <Legend />
204
- <Bar dataKey="value" fill={color} radius={[4, 4, 0, 0]} />
205
- </RechartsBarChart>
206
- </ResponsiveContainer>
207
- </div>
208
- );
209
- }
210
- ```
211
-
212
- ---
213
-
214
- ## Area chart variant
215
-
216
- For a filled area chart (useful for volume-over-time), swap `Line` for `Area`:
217
-
218
- ```tsx
219
- import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from "recharts";
220
-
221
- <ResponsiveContainer width="100%" height={300}>
222
- <AreaChart data={data}>
223
- <CartesianGrid strokeDasharray="3 3" />
224
- <XAxis dataKey="x" />
225
- <YAxis />
226
- <Tooltip />
227
- <Area type="monotone" dataKey="y" stroke={color} fill={color} fillOpacity={0.2} />
228
- </AreaChart>
229
- </ResponsiveContainer>
230
- ```
231
-
232
- ---
233
-
234
- ## Chart container wrapper
235
-
236
- Wrap any chart in a styled card for consistent spacing:
237
-
238
- ```tsx
239
- import { Card } from "@/components/ui/card";
240
-
241
- interface ChartContainerProps {
242
- children: React.ReactNode;
243
- className?: string;
244
- }
245
-
246
- export function ChartContainer({ children, className = "" }: ChartContainerProps) {
247
- return (
248
- <Card className={`p-4 border-gray-200 shadow-sm ${className}`}>
249
- {children}
250
- </Card>
251
- );
252
- }
253
- ```
254
-
255
- Usage:
256
-
257
- ```tsx
258
- <ChartContainer>
259
- <TimeSeriesChart data={monthlyData} theme="green" title="Monthly Revenue" />
260
- </ChartContainer>
261
- ```
262
-
263
- ---
264
-
265
- ## Preparing raw data
266
-
267
- Map API responses to the expected shape before passing to the chart:
268
-
269
- ```tsx
270
- const timeSeriesData = useMemo(
271
- () => apiRecords.map((r) => ({ x: r.date, y: r.revenue })),
272
- [apiRecords],
273
- );
274
-
275
- const categoricalData = useMemo(
276
- () => apiRecords.map((r) => ({ name: r.product, value: r.sales })),
277
- [apiRecords],
278
- );
279
- ```
280
-
281
- ---
282
-
283
- ## Key Recharts concepts
284
-
285
- | Component | Purpose |
286
- |-----------|---------|
287
- | `ResponsiveContainer` | Wraps chart to fill parent width |
288
- | `CartesianGrid` | Background grid lines |
289
- | `XAxis` / `YAxis` | Axis labels; `dataKey` maps to the data field |
290
- | `Tooltip` | Hover info |
291
- | `Legend` | Series labels |
292
- | `Line` | Line series; `type="monotone"` for smooth curves |
293
- | `Bar` | Bar series; `radius` rounds top corners |
294
- | `Area` | Filled area; `fillOpacity` controls transparency |
295
-
296
- ---
297
-
298
- ## Accessibility
299
-
300
- - Always include a text legend (not just colors).
301
- - Chart should be wrapped in a section with a visible heading.
302
- - For critical data, provide a text summary or table alternative.
303
- - Use sufficient color contrast between the chart stroke/fill and background.
304
- - Consider `prefers-reduced-motion` for chart animations.
305
-
306
- ---
307
-
308
- ## Common mistakes
309
-
310
- | Mistake | Fix |
311
- |---------|-----|
312
- | Missing `ResponsiveContainer` | Chart won't resize; always wrap |
313
- | Fixed width/height on chart | Let `ResponsiveContainer` control sizing |
314
- | No empty-data handling | Show "No data" message when `data.length === 0` |
315
- | Inline colors | Extract to `THEME_COLORS` constant |
316
- | Using raw Recharts for every chart type | Use `DonutChart` (see `donut-chart.md`) for pie/donut |