@rise-x/apps-sdk 0.9.0 → 0.11.1

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 (92) hide show
  1. package/README.md +117 -32
  2. package/build/rsbuild/index.d.ts +6 -1
  3. package/build/rsbuild/index.js +24 -3
  4. package/build/ui/classes.json +209 -0
  5. package/build/ui/components/ai.d.ts +33 -1
  6. package/build/ui/components/app-frame.d.ts +16 -10
  7. package/build/ui/components/chat-input.d.ts +28 -0
  8. package/build/ui/components/message-scroller.d.ts +34 -10
  9. package/build/ui/components/sheet.d.ts +10 -0
  10. package/build/ui/components/thinking-rings.d.ts +4 -0
  11. package/build/ui/demo.html +26794 -0
  12. package/build/ui/index.d.ts +2 -0
  13. package/build/ui/standalone.js +60 -58
  14. package/build/ui/styles.css +1 -1
  15. package/package.json +4 -3
  16. package/template/AGENTS.md +3 -3
  17. package/template/README.md +5 -5
  18. package/template/package.json +8 -9
  19. package/template/rsbuild.config.mts +17 -0
  20. package/template/src/App.tsx +4 -1
  21. package/template/tsconfig.json +3 -1
  22. package/build/ui/reference/README.md +0 -11
  23. package/build/ui/reference/components/accordion.tsx +0 -85
  24. package/build/ui/reference/components/ai.tsx +0 -293
  25. package/build/ui/reference/components/alert-dialog.tsx +0 -207
  26. package/build/ui/reference/components/alert.tsx +0 -112
  27. package/build/ui/reference/components/app-frame.tsx +0 -71
  28. package/build/ui/reference/components/aspect-ratio.tsx +0 -28
  29. package/build/ui/reference/components/avatar.tsx +0 -158
  30. package/build/ui/reference/components/badge.tsx +0 -160
  31. package/build/ui/reference/components/button-group.tsx +0 -77
  32. package/build/ui/reference/components/button.tsx +0 -109
  33. package/build/ui/reference/components/calendar.tsx +0 -119
  34. package/build/ui/reference/components/card.tsx +0 -144
  35. package/build/ui/reference/components/carousel.tsx +0 -248
  36. package/build/ui/reference/components/chart.tsx +0 -704
  37. package/build/ui/reference/components/checkbox.tsx +0 -44
  38. package/build/ui/reference/components/collapsible.tsx +0 -43
  39. package/build/ui/reference/components/combobox.tsx +0 -146
  40. package/build/ui/reference/components/command.tsx +0 -181
  41. package/build/ui/reference/components/context-menu.tsx +0 -243
  42. package/build/ui/reference/components/data-table.tsx +0 -650
  43. package/build/ui/reference/components/date-picker.tsx +0 -218
  44. package/build/ui/reference/components/dialog.tsx +0 -172
  45. package/build/ui/reference/components/direction.tsx +0 -22
  46. package/build/ui/reference/components/dropdown-menu.tsx +0 -245
  47. package/build/ui/reference/components/empty-state.tsx +0 -63
  48. package/build/ui/reference/components/field.tsx +0 -252
  49. package/build/ui/reference/components/file-upload.tsx +0 -116
  50. package/build/ui/reference/components/hover-card.tsx +0 -64
  51. package/build/ui/reference/components/input-group.tsx +0 -157
  52. package/build/ui/reference/components/input-otp.tsx +0 -106
  53. package/build/ui/reference/components/input.tsx +0 -86
  54. package/build/ui/reference/components/item.tsx +0 -188
  55. package/build/ui/reference/components/kbd.tsx +0 -43
  56. package/build/ui/reference/components/label.tsx +0 -19
  57. package/build/ui/reference/components/list.tsx +0 -191
  58. package/build/ui/reference/components/map.css +0 -251
  59. package/build/ui/reference/components/map.tsx +0 -294
  60. package/build/ui/reference/components/menubar.tsx +0 -275
  61. package/build/ui/reference/components/message-scroller.tsx +0 -141
  62. package/build/ui/reference/components/message.tsx +0 -177
  63. package/build/ui/reference/components/nav.tsx +0 -127
  64. package/build/ui/reference/components/navigation-menu.tsx +0 -191
  65. package/build/ui/reference/components/page-header.tsx +0 -245
  66. package/build/ui/reference/components/popover.tsx +0 -76
  67. package/build/ui/reference/components/progress.tsx +0 -31
  68. package/build/ui/reference/components/radio.tsx +0 -65
  69. package/build/ui/reference/components/resizable.tsx +0 -40
  70. package/build/ui/reference/components/scroll-area.tsx +0 -55
  71. package/build/ui/reference/components/segmented.tsx +0 -45
  72. package/build/ui/reference/components/select.tsx +0 -188
  73. package/build/ui/reference/components/separator.tsx +0 -26
  74. package/build/ui/reference/components/sheet.tsx +0 -184
  75. package/build/ui/reference/components/skeleton.tsx +0 -15
  76. package/build/ui/reference/components/slider.tsx +0 -161
  77. package/build/ui/reference/components/snackbar.tsx +0 -27
  78. package/build/ui/reference/components/sonner.tsx +0 -43
  79. package/build/ui/reference/components/spinner.tsx +0 -27
  80. package/build/ui/reference/components/statistic.tsx +0 -122
  81. package/build/ui/reference/components/stepper.tsx +0 -138
  82. package/build/ui/reference/components/switch.tsx +0 -47
  83. package/build/ui/reference/components/table.tsx +0 -246
  84. package/build/ui/reference/components/textarea.tsx +0 -28
  85. package/build/ui/reference/components/timeline.tsx +0 -101
  86. package/build/ui/reference/components/toggle-group.tsx +0 -86
  87. package/build/ui/reference/components/toggle.tsx +0 -46
  88. package/build/ui/reference/components/tooltip.tsx +0 -53
  89. package/build/ui/reference/index.ts +0 -69
  90. package/build/ui/reference/lib/utils.ts +0 -34
  91. package/template/webpack.config.js +0 -112
  92. package/template/webpack.local.config.js +0 -68
@@ -1,704 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import * as RechartsPrimitive from 'recharts';
5
- import type { TooltipValueType } from 'recharts';
6
-
7
- import { cn } from '@rise-x/ui/lib/utils';
8
-
9
- /*
10
- * CHARTS ARE THE REAL SHADCN LAYER over Recharts — ChartContainer + ChartConfig
11
- * + ChartTooltipContent + ChartLegendContent, so any shadcn chart example
12
- * pastes in working. Call sites compose Recharts primitives; there is no
13
- * LineChart/BarChart kit component to outgrow. Two visual tokens are swapped
14
- * to the kit's surfaces (tooltip on bg-popover with shadow-pop instead of
15
- * bg-background with shadow-xl); everything else is upstream verbatim.
16
- *
17
- * TWO HOUSE RULES SURVIVE THE SWITCH:
18
- *
19
- * · THE PALETTE IS ITS OWN FAMILY — --chart-1..6, sequenced so adjacent series
20
- * sit far apart in hue. Brand green, berry and pure red are all EXCLUDED, so
21
- * a chart can never imply success, AI or failure by accident. When the
22
- * series ARE statuses (matched / in review / failed), use the semantic
23
- * tokens via `seriesColor(i, tone)` — a failed slice must be red.
24
- *
25
- * · PASS type="monotone", NOT "natural", to Line/Area. Recharts' natural cubic
26
- * overshoots local extrema and can carry a strictly-positive series below
27
- * zero — a data error to the reader. The demo's specimens all do this.
28
- *
29
- * ALSO PASS isAnimationActive={false} TO EVERY <Line>. Recharts draws a line's
30
- * entry animation as a dash sweep, and after ChartContainer's initialDimension
31
- * resize the sweep can be left parked at `stroke-dasharray: 0px, N` — the line
32
- * is in the DOM, correct, and invisible until something forces a redraw. It
33
- * reproduces on 3.8 and 3.10 alike, so it is not version drift. Areas, bars and
34
- * pies animate normally and need nothing.
35
- *
36
- * EVERY CHART SHIPS IN A ChartCard. A chart without a title is a decoration:
37
- * the reader has to infer what is being measured and over what period, and two
38
- * charts side by side become indistinguishable.
39
- *
40
- * Sparkline and ProgressRing stay hand-rolled SVG below — they are micro-
41
- * visuals for table cells and stat tiles, where a responsive Recharts mount
42
- * per row would be weight without benefit.
43
- */
44
-
45
- const CHART_SERIES = [
46
- 'var(--chart-1)',
47
- 'var(--chart-2)',
48
- 'var(--chart-3)',
49
- 'var(--chart-4)',
50
- 'var(--chart-5)',
51
- 'var(--chart-6)',
52
- ] as const;
53
-
54
- const SEMANTIC_SERIES = {
55
- success: 'var(--success)',
56
- warning: 'var(--warning)',
57
- error: 'var(--error)',
58
- info: 'var(--info)',
59
- neutral: 'var(--neutral)',
60
- } as const;
61
-
62
- type SemanticTone = keyof typeof SEMANTIC_SERIES;
63
-
64
- function seriesColor(index: number, tone?: SemanticTone) {
65
- return tone ? SEMANTIC_SERIES[tone] : CHART_SERIES[index % CHART_SERIES.length];
66
- }
67
-
68
- /* ---- the shadcn chart layer (upstream new-york-v4) ----------------------- */
69
-
70
- // Format: { THEME_NAME: CSS_SELECTOR }
71
- const THEMES = { light: '', dark: '.dark' } as const;
72
-
73
- const INITIAL_DIMENSION = { width: 320, height: 200 } as const;
74
- type TooltipNameType = number | string;
75
-
76
- export type ChartConfig = Record<
77
- string,
78
- {
79
- label?: React.ReactNode;
80
- icon?: React.ComponentType;
81
- } & (
82
- | { color?: string; theme?: never }
83
- | { color?: never; theme: Record<keyof typeof THEMES, string> }
84
- )
85
- >;
86
-
87
- type ChartContextProps = {
88
- config: ChartConfig;
89
- };
90
-
91
- const ChartContext = React.createContext<ChartContextProps | null>(null);
92
-
93
- function useChart() {
94
- const context = React.useContext(ChartContext);
95
-
96
- if (!context) {
97
- throw new Error('useChart must be used within a <ChartContainer />');
98
- }
99
-
100
- return context;
101
- }
102
-
103
- function ChartContainer({
104
- id,
105
- className,
106
- children,
107
- config,
108
- initialDimension = INITIAL_DIMENSION,
109
- ...props
110
- }: React.ComponentProps<'div'> & {
111
- config: ChartConfig;
112
- children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];
113
- initialDimension?: {
114
- width: number;
115
- height: number;
116
- };
117
- }) {
118
- const uniqueId = React.useId();
119
- const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;
120
-
121
- return (
122
- <ChartContext.Provider value={{ config }}>
123
- <div
124
- data-slot="chart"
125
- data-chart={chartId}
126
- className={cn(
127
- "flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
128
- className,
129
- )}
130
- {...props}
131
- >
132
- <ChartStyle id={chartId} config={config} />
133
- <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>
134
- {children}
135
- </RechartsPrimitive.ResponsiveContainer>
136
- </div>
137
- </ChartContext.Provider>
138
- );
139
- }
140
-
141
- const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
142
- const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);
143
-
144
- if (!colorConfig.length) {
145
- return null;
146
- }
147
-
148
- return (
149
- <style
150
- dangerouslySetInnerHTML={{
151
- __html: Object.entries(THEMES)
152
- .map(
153
- ([theme, prefix]) => `
154
- ${prefix} [data-chart=${id}] {
155
- ${colorConfig
156
- .map(([key, itemConfig]) => {
157
- const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;
158
- return color ? ` --color-${key}: ${color};` : null;
159
- })
160
- .join('\n')}
161
- }
162
- `,
163
- )
164
- .join('\n'),
165
- }}
166
- />
167
- );
168
- };
169
-
170
- const ChartTooltip = RechartsPrimitive.Tooltip;
171
-
172
- function ChartTooltipContent({
173
- active,
174
- payload,
175
- className,
176
- indicator = 'dot',
177
- hideLabel = false,
178
- hideIndicator = false,
179
- label,
180
- labelFormatter,
181
- labelClassName,
182
- formatter,
183
- color,
184
- nameKey,
185
- labelKey,
186
- }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
187
- React.ComponentProps<'div'> & {
188
- hideLabel?: boolean;
189
- hideIndicator?: boolean;
190
- indicator?: 'line' | 'dot' | 'dashed';
191
- nameKey?: string;
192
- labelKey?: string;
193
- } & Omit<
194
- RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>,
195
- 'accessibilityLayer'
196
- >) {
197
- const { config } = useChart();
198
-
199
- const tooltipLabel = React.useMemo(() => {
200
- if (hideLabel || !payload?.length) {
201
- return null;
202
- }
203
-
204
- const [item] = payload;
205
- const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;
206
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
207
- const value =
208
- !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;
209
-
210
- if (labelFormatter) {
211
- return (
212
- <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>
213
- );
214
- }
215
-
216
- if (!value) {
217
- return null;
218
- }
219
-
220
- return <div className={cn('font-medium', labelClassName)}>{value}</div>;
221
- }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
222
-
223
- if (!active || !payload?.length) {
224
- return null;
225
- }
226
-
227
- const nestLabel = payload.length === 1 && indicator !== 'dot';
228
-
229
- return (
230
- <div
231
- className={cn(
232
- // kit pop surface instead of upstream's bg-background + shadow-xl
233
- 'grid min-w-[128px] items-start gap-1.5 rounded-lg border border-border/50 bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-pop',
234
- className,
235
- )}
236
- >
237
- {!nestLabel ? tooltipLabel : null}
238
- <div className="grid gap-1.5">
239
- {payload
240
- .filter((item) => item.type !== 'none')
241
- .map((item, index) => {
242
- const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;
243
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
244
- const indicatorColor = color ?? item.payload?.fill ?? item.color;
245
-
246
- return (
247
- <div
248
- key={index}
249
- className={cn(
250
- 'flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground',
251
- indicator === 'dot' && 'items-center',
252
- )}
253
- >
254
- {formatter && item?.value !== undefined && item.name ? (
255
- formatter(item.value, item.name, item, index, item.payload)
256
- ) : (
257
- <>
258
- {itemConfig?.icon ? (
259
- <itemConfig.icon />
260
- ) : (
261
- !hideIndicator && (
262
- <div
263
- className={cn(
264
- 'shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)',
265
- {
266
- 'h-2.5 w-2.5': indicator === 'dot',
267
- 'w-1': indicator === 'line',
268
- 'w-0 border-[1.5px] border-dashed bg-transparent':
269
- indicator === 'dashed',
270
- 'my-0.5': nestLabel && indicator === 'dashed',
271
- },
272
- )}
273
- style={
274
- {
275
- '--color-bg': indicatorColor,
276
- '--color-border': indicatorColor,
277
- } as React.CSSProperties
278
- }
279
- />
280
- )
281
- )}
282
- <div
283
- className={cn(
284
- 'flex flex-1 justify-between leading-none',
285
- nestLabel ? 'items-end' : 'items-center',
286
- )}
287
- >
288
- <div className="grid gap-1.5">
289
- {nestLabel ? tooltipLabel : null}
290
- <span className="text-muted-foreground">
291
- {itemConfig?.label ?? item.name}
292
- </span>
293
- </div>
294
- {item.value != null && (
295
- <span className="font-mono font-medium text-foreground tabular-nums">
296
- {typeof item.value === 'number'
297
- ? item.value.toLocaleString()
298
- : String(item.value)}
299
- </span>
300
- )}
301
- </div>
302
- </>
303
- )}
304
- </div>
305
- );
306
- })}
307
- </div>
308
- </div>
309
- );
310
- }
311
-
312
- const ChartLegend = RechartsPrimitive.Legend;
313
-
314
- function ChartLegendContent({
315
- className,
316
- hideIcon = false,
317
- payload,
318
- verticalAlign = 'bottom',
319
- nameKey,
320
- }: React.ComponentProps<'div'> & {
321
- hideIcon?: boolean;
322
- nameKey?: string;
323
- } & RechartsPrimitive.DefaultLegendContentProps) {
324
- const { config } = useChart();
325
-
326
- if (!payload?.length) {
327
- return null;
328
- }
329
-
330
- return (
331
- <div
332
- className={cn(
333
- 'flex items-center justify-center gap-4',
334
- verticalAlign === 'top' ? 'pb-3' : 'pt-3',
335
- className,
336
- )}
337
- >
338
- {payload
339
- .filter((item) => item.type !== 'none')
340
- .map((item, index) => {
341
- const key = `${nameKey ?? item.dataKey ?? 'value'}`;
342
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
343
-
344
- return (
345
- <div
346
- key={index}
347
- className={cn(
348
- 'flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground',
349
- )}
350
- >
351
- {itemConfig?.icon && !hideIcon ? (
352
- <itemConfig.icon />
353
- ) : (
354
- <div
355
- className="h-2 w-2 shrink-0 rounded-[2px]"
356
- style={{
357
- backgroundColor: item.color,
358
- }}
359
- />
360
- )}
361
- {itemConfig?.label}
362
- </div>
363
- );
364
- })}
365
- </div>
366
- );
367
- }
368
-
369
- // Helper to extract item config from a payload.
370
- function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {
371
- if (typeof payload !== 'object' || payload === null) {
372
- return undefined;
373
- }
374
-
375
- const payloadPayload =
376
- 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null
377
- ? payload.payload
378
- : undefined;
379
-
380
- let configLabelKey: string = key;
381
-
382
- if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {
383
- configLabelKey = payload[key as keyof typeof payload] as string;
384
- } else if (
385
- payloadPayload &&
386
- key in payloadPayload &&
387
- typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'
388
- ) {
389
- configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
390
- }
391
-
392
- return configLabelKey in config ? config[configLabelKey] : config[key];
393
- }
394
-
395
- /* ---- the card every chart ships in --------------------------------------- */
396
-
397
- function ChartCard({ className, ...props }: React.ComponentProps<'div'>) {
398
- return (
399
- <div
400
- data-slot="chart-card"
401
- className={cn('flex flex-col rounded-xl bg-card p-3.5 shadow-card', className)}
402
- {...props}
403
- />
404
- );
405
- }
406
-
407
- function ChartCardHeader({ className, ...props }: React.ComponentProps<'div'>) {
408
- return (
409
- <div
410
- data-slot="chart-card-header"
411
- className={cn(
412
- 'mb-3 flex items-start gap-3 [&>[data-slot=chart-card-actions]]:ml-auto',
413
- className,
414
- )}
415
- {...props}
416
- />
417
- );
418
- }
419
-
420
- function ChartCardTitle({ className, ...props }: React.ComponentProps<'div'>) {
421
- return (
422
- <div
423
- data-slot="chart-card-title"
424
- className={cn('text-ui leading-tight font-medium', className)}
425
- {...props}
426
- />
427
- );
428
- }
429
-
430
- /*
431
- * A SUBTITLE, so it is explicitly regular weight in the secondary tone. It was
432
- * already computing to 400 — nothing was setting a weight — but it read as heavy
433
- * because `--muted-foreground` is the BODY tone (#5c5c5c, 6.69:1), the same
434
- * darkness as the copy it sits above, at only 1px less than the title. Weight
435
- * pinned here so a caller's `font-medium` cannot leak in by inheritance.
436
- */
437
- function ChartCardDescription({ className, ...props }: React.ComponentProps<'div'>) {
438
- return (
439
- <div
440
- data-slot="chart-card-description"
441
- className={cn('mt-0.5 text-xs font-normal text-subtle', className)}
442
- {...props}
443
- />
444
- );
445
- }
446
-
447
- function ChartCardActions({ className, ...props }: React.ComponentProps<'div'>) {
448
- return (
449
- <div
450
- data-slot="chart-card-actions"
451
- className={cn('flex shrink-0 items-center gap-2', className)}
452
- {...props}
453
- />
454
- );
455
- }
456
-
457
- /* Footer carries the takeaway, not a repeat of the axis labels. */
458
- function ChartCardFooter({ className, ...props }: React.ComponentProps<'div'>) {
459
- return (
460
- <div
461
- data-slot="chart-card-footer"
462
- className={cn('mt-3 flex flex-col gap-1 text-xs', className)}
463
- {...props}
464
- />
465
- );
466
- }
467
-
468
- /* ---- micro-visuals (hand-rolled SVG on purpose) --------------------------- */
469
-
470
- /*
471
- * Monotone cubic (Fritsch–Carlson) through the points — the tangent is zeroed
472
- * at a local extremum so the curve cannot sail past a peak or trough, and
473
- * elsewhere clamped to 3× the smaller neighbouring slope.
474
- */
475
- function monotonePath(points: Array<[number, number]>) {
476
- if (points.length < 2) return '';
477
- const n = points.length;
478
- const slope = (i: number) =>
479
- (points[i + 1][1] - points[i][1]) / (points[i + 1][0] - points[i][0] || 1);
480
-
481
- const m: number[] = [];
482
- for (let i = 0; i < n; i += 1) {
483
- if (i === 0) {
484
- m.push(slope(0));
485
- continue;
486
- }
487
- if (i === n - 1) {
488
- m.push(slope(n - 2));
489
- continue;
490
- }
491
- const s0 = slope(i - 1);
492
- const s1 = slope(i);
493
- if (s0 * s1 <= 0) {
494
- m.push(0);
495
- continue;
496
- }
497
- const avg = (s0 + s1) / 2;
498
- const limit = 3 * Math.min(Math.abs(s0), Math.abs(s1));
499
- m.push(Math.sign(avg) * Math.min(Math.abs(avg), limit));
500
- }
501
-
502
- const d: string[] = [`M ${points[0][0]} ${points[0][1]}`];
503
- for (let i = 0; i < n - 1; i += 1) {
504
- const [x1, y1] = points[i];
505
- const [x2, y2] = points[i + 1];
506
- const dx = (x2 - x1) / 3;
507
- d.push(`C ${x1 + dx} ${y1 + m[i] * dx}, ${x2 - dx} ${y2 - m[i + 1] * dx}, ${x2} ${y2}`);
508
- }
509
- return d.join(' ');
510
- }
511
-
512
- function Sparkline({
513
- values,
514
- width = 88,
515
- height = 24,
516
- tone,
517
- className,
518
- ...props
519
- }: Omit<React.ComponentProps<'div'>, 'children'> & {
520
- values: number[];
521
- width?: number;
522
- height?: number;
523
- tone?: SemanticTone;
524
- }) {
525
- const max = Math.max(...values, 1);
526
- const min = Math.min(...values, 0);
527
- const span = max - min || 1;
528
- const pts = values.map(
529
- (v, i) =>
530
- [
531
- (i / Math.max(1, values.length - 1)) * (width - 2) + 1,
532
- height - 2 - ((v - min) / span) * (height - 4),
533
- ] as [number, number],
534
- );
535
- return (
536
- <div
537
- data-slot="chart"
538
- className={cn('inline-block shrink-0 leading-none', className)}
539
- {...props}
540
- >
541
- <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} role="img">
542
- <title>{`Trend, ${values[0]} to ${values[values.length - 1]}`}</title>
543
- <path
544
- d={monotonePath(pts)}
545
- fill="none"
546
- stroke={seriesColor(0, tone)}
547
- strokeWidth="1.5"
548
- strokeLinecap="round"
549
- />
550
- </svg>
551
- </div>
552
- );
553
- }
554
-
555
- function ProgressRing({
556
- value,
557
- size = 44,
558
- thickness = 4,
559
- tone,
560
- showValue = true,
561
- className,
562
- ...props
563
- }: Omit<React.ComponentProps<'div'>, 'children'> & {
564
- value: number;
565
- size?: number;
566
- thickness?: number;
567
- tone?: SemanticTone;
568
- showValue?: boolean;
569
- }) {
570
- const r = (size - thickness) / 2;
571
- const C = 2 * Math.PI * r;
572
- const len = (Math.max(0, Math.min(100, value)) / 100) * C;
573
- return (
574
- <div
575
- data-slot="chart"
576
- style={{ width: size, height: size }}
577
- className={cn('relative shrink-0', className)}
578
- {...props}
579
- >
580
- <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} role="img">
581
- <title>{`${Math.round(value)}%`}</title>
582
- <circle
583
- cx={size / 2}
584
- cy={size / 2}
585
- r={r}
586
- fill="none"
587
- stroke="var(--fill-2)"
588
- strokeWidth={thickness}
589
- />
590
- <g transform={`rotate(-90 ${size / 2} ${size / 2})`}>
591
- <circle
592
- cx={size / 2}
593
- cy={size / 2}
594
- r={r}
595
- fill="none"
596
- stroke={seriesColor(0, tone)}
597
- strokeWidth={thickness}
598
- strokeLinecap="round"
599
- strokeDasharray={`${len} ${C - len}`}
600
- />
601
- </g>
602
- </svg>
603
- {showValue ? (
604
- <span className="absolute inset-0 grid place-content-center text-micro font-medium tabular-nums">
605
- {Math.round(value)}%
606
- </span>
607
- ) : null}
608
- </div>
609
- );
610
- }
611
-
612
- /*
613
- * THE RECHARTS PRIMITIVES ARE RE-EXPORTED FROM HERE, and a consumer must take
614
- * them from the kit rather than importing 'recharts' itself.
615
- *
616
- * This is a federation constraint, not a style preference. A federated app
617
- * takes @rise-x/ui from the host share scope (`singleton: true, import: false`),
618
- * so ChartContainer and ChartTooltip come from the HOST's recharts. An app that
619
- * also writes `import { BarChart } from 'recharts'` bundles a SECOND copy into
620
- * its remote, and recharts 3 wires chart state through React context plus an
621
- * internal store — a Tooltip from one instance is never registered with a chart
622
- * from the other, so it silently does nothing (and the remote ships a few
623
- * hundred KB twice). Standalone dev makes it certain: webpack.local.config.js
624
- * aliases @rise-x/ui to the prebuilt standalone bundle, which has its own copy.
625
- *
626
- * Re-exporting keeps every chart on one instance and keeps apps inside the
627
- * @rise-x/apps-sdk-only contract in AGENTS.md. `no-restricted-imports` in
628
- * Shell/eslint.config.js enforces it, because a comment did not.
629
- *
630
- * THIS LIST IS THE CEILING, so treat it as one. It is everything a caller can
631
- * draw, and the answer when a primitive is missing is to ADD IT HERE — one line
632
- * plus a version bump — never to reach for 'recharts' in the app. Recharts'
633
- * `Label`, `Tooltip` and `Legend` are the only names that cannot come through
634
- * under their own names: the kit already exports a form `Label`, and `Tooltip`/`Legend`
635
- * are re-exported ABOVE as `ChartTooltip`/`ChartLegend` — bare aliases, not
636
- * wrappers. The wrapped pieces are `ChartTooltipContent`/`ChartLegendContent`,
637
- * which you pass to them as `content`.
638
- */
639
- /* Recharts' Label is aliased: the kit already exports a form Label, and a
640
- * barrel cannot carry both names. ChartLabel is the one that goes inside a
641
- * chart (a donut's centre figure, an axis caption). */
642
- export { Label as ChartLabel } from 'recharts';
643
-
644
- export {
645
- Area,
646
- AreaChart,
647
- Bar,
648
- BarChart,
649
- Brush,
650
- CartesianGrid,
651
- Cell,
652
- /* bars and a line on one axis pair — the first thing a mixed chart needs */
653
- ComposedChart,
654
- Customized,
655
- ErrorBar,
656
- Funnel,
657
- FunnelChart,
658
- LabelList,
659
- Line,
660
- LineChart,
661
- Pie,
662
- PieChart,
663
- PolarAngleAxis,
664
- PolarGrid,
665
- PolarRadiusAxis,
666
- Radar,
667
- RadarChart,
668
- RadialBar,
669
- RadialBarChart,
670
- /* Rectangle and Sector carry shadcn's own activeBar / activeShape examples,
671
- * so "any example from ui.shadcn.com/charts pastes in" needs them. */
672
- Rectangle,
673
- ReferenceArea,
674
- ReferenceDot,
675
- ReferenceLine,
676
- ResponsiveContainer,
677
- Scatter,
678
- ScatterChart,
679
- Sector,
680
- Treemap,
681
- XAxis,
682
- YAxis,
683
- ZAxis,
684
- } from 'recharts';
685
-
686
- export {
687
- ChartContainer,
688
- ChartTooltip,
689
- ChartTooltipContent,
690
- ChartLegend,
691
- ChartLegendContent,
692
- ChartStyle,
693
- ChartCard,
694
- ChartCardHeader,
695
- ChartCardTitle,
696
- ChartCardDescription,
697
- ChartCardActions,
698
- ChartCardFooter,
699
- Sparkline,
700
- ProgressRing,
701
- CHART_SERIES,
702
- seriesColor,
703
- type SemanticTone,
704
- };