@open-mercato/ui 0.10.1-develop.8218.1.21f44d4a6c → 0.10.1-develop.8225.1.1766b080b2

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 (32) hide show
  1. package/dist/backend/CrudForm.js +5 -1
  2. package/dist/backend/CrudForm.js.map +2 -2
  3. package/dist/backend/charts/BarChart.js +20 -12
  4. package/dist/backend/charts/BarChart.js.map +2 -2
  5. package/dist/backend/charts/BarChartImpl.js +8 -3
  6. package/dist/backend/charts/BarChartImpl.js.map +2 -2
  7. package/dist/backend/charts/ChartUtils.js +6 -0
  8. package/dist/backend/charts/ChartUtils.js.map +2 -2
  9. package/dist/backend/charts/LineChart.js +24 -14
  10. package/dist/backend/charts/LineChart.js.map +2 -2
  11. package/dist/backend/charts/LineChartImpl.js +8 -2
  12. package/dist/backend/charts/LineChartImpl.js.map +2 -2
  13. package/dist/backend/confirm-dialog/ConfirmDialog.js +19 -27
  14. package/dist/backend/confirm-dialog/ConfirmDialog.js.map +2 -2
  15. package/dist/backend/confirm-dialog/useConfirmDialog.js.map +1 -1
  16. package/dist/backend/detail/CustomDataSection.js +2 -8
  17. package/dist/backend/detail/CustomDataSection.js.map +2 -2
  18. package/package.json +3 -3
  19. package/src/backend/CrudForm.tsx +5 -1
  20. package/src/backend/__tests__/CrudForm.navigation.test.tsx +1 -1
  21. package/src/backend/__tests__/CrudForm.unsavedNavigation.test.tsx +9 -9
  22. package/src/backend/__tests__/CustomDataSection.test.tsx +45 -0
  23. package/src/backend/charts/BarChart.tsx +37 -19
  24. package/src/backend/charts/BarChartImpl.tsx +10 -1
  25. package/src/backend/charts/ChartUtils.tsx +7 -0
  26. package/src/backend/charts/LineChart.tsx +32 -12
  27. package/src/backend/charts/LineChartImpl.tsx +10 -1
  28. package/src/backend/charts/__tests__/KpiCard.test.tsx +12 -0
  29. package/src/backend/confirm-dialog/ConfirmDialog.tsx +43 -35
  30. package/src/backend/confirm-dialog/__tests__/ConfirmDialog.test.tsx +84 -0
  31. package/src/backend/confirm-dialog/useConfirmDialog.tsx +1 -1
  32. package/src/backend/detail/CustomDataSection.tsx +1 -7
@@ -23,6 +23,16 @@ export type LineChartProps = {
23
23
  className?: string
24
24
  emptyMessage?: string
25
25
  categoryLabels?: Record<string, string>
26
+ /** Render only the plot (no card border, padding or title) so a host card can own the chrome. */
27
+ bare?: boolean
28
+ /** Height utility for the plot area; defaults to `h-52`. */
29
+ heightClassName?: string
30
+ /** Recharts draw-in animation; pass false for charts that re-render on interaction. */
31
+ animate?: boolean
32
+ /** Fill opacity of the area under each line when `showArea` is on; defaults to 0.2. */
33
+ areaOpacity?: number
34
+ /** Recharts keyboard/focus layer; pass false for decorative charts so the plot never takes focus. */
35
+ accessibilityLayer?: boolean
26
36
  }
27
37
 
28
38
  function defaultValueFormatter(value: number): string {
@@ -61,12 +71,19 @@ export function LineChart({
61
71
  className = '',
62
72
  emptyMessage = 'No data available',
63
73
  categoryLabels,
74
+ bare = false,
75
+ heightClassName = 'h-52',
76
+ animate = true,
77
+ areaOpacity = 0.2,
78
+ accessibilityLayer = true,
64
79
  }: LineChartProps) {
80
+ const wrapperClassName = bare ? className : `rounded-lg border bg-card p-4 ${className}`
81
+ const stateClassName = bare ? `flex items-center justify-center ${heightClassName}` : 'flex h-48 items-center justify-center'
65
82
  if (error) {
66
83
  return (
67
- <div className={`rounded-lg border bg-card p-4 ${className}`}>
68
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
69
- <div className="flex h-48 items-center justify-center">
84
+ <div className={wrapperClassName}>
85
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
86
+ <div className={stateClassName}>
70
87
  <p className="text-sm text-destructive">{error}</p>
71
88
  </div>
72
89
  </div>
@@ -75,9 +92,9 @@ export function LineChart({
75
92
 
76
93
  if (loading) {
77
94
  return (
78
- <div className={`rounded-lg border bg-card p-4 ${className}`}>
79
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
80
- <div className="flex h-48 items-center justify-center">
95
+ <div className={wrapperClassName}>
96
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
97
+ <div className={stateClassName}>
81
98
  <Spinner className="h-6 w-6 text-muted-foreground" />
82
99
  </div>
83
100
  </div>
@@ -86,9 +103,9 @@ export function LineChart({
86
103
 
87
104
  if (!data || data.length === 0) {
88
105
  return (
89
- <div className={`rounded-lg border bg-card p-4 ${className}`}>
90
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
91
- <div className="flex h-48 items-center justify-center">
106
+ <div className={wrapperClassName}>
107
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
108
+ <div className={stateClassName}>
92
109
  <p className="text-sm text-muted-foreground">{emptyMessage}</p>
93
110
  </div>
94
111
  </div>
@@ -96,9 +113,9 @@ export function LineChart({
96
113
  }
97
114
 
98
115
  return (
99
- <div className={`rounded-lg border bg-card p-4 ${className}`}>
100
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
101
- <div className="h-52 w-full">
116
+ <div className={wrapperClassName}>
117
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
118
+ <div className={`${heightClassName} w-full`}>
102
119
  <LineChartImpl
103
120
  data={data}
104
121
  index={index}
@@ -111,6 +128,9 @@ export function LineChart({
111
128
  curveType={curveType}
112
129
  connectNulls={connectNulls}
113
130
  categoryLabels={categoryLabels}
131
+ animate={animate}
132
+ areaOpacity={areaOpacity}
133
+ accessibilityLayer={accessibilityLayer}
114
134
  />
115
135
  </div>
116
136
  </div>
@@ -29,6 +29,9 @@ type ImplProps = Pick<
29
29
  | 'curveType'
30
30
  | 'connectNulls'
31
31
  | 'categoryLabels'
32
+ | 'animate'
33
+ | 'areaOpacity'
34
+ | 'accessibilityLayer'
32
35
  > & {
33
36
  valueFormatter: (value: number) => string
34
37
  }
@@ -45,6 +48,9 @@ export default function LineChartImpl({
45
48
  curveType = 'monotone',
46
49
  connectNulls = true,
47
50
  categoryLabels,
51
+ animate = true,
52
+ areaOpacity = 0.2,
53
+ accessibilityLayer = true,
48
54
  }: ImplProps) {
49
55
  const getLineColor = (idx: number): string => resolveChartColor(colors?.[idx], idx)
50
56
  const ChartComponent = showArea ? RechartsAreaChart : RechartsLineChart
@@ -54,6 +60,7 @@ export default function LineChartImpl({
54
60
  <ChartComponent
55
61
  data={data}
56
62
  margin={{ top: 5, right: 10, left: 10, bottom: 5 }}
63
+ accessibilityLayer={accessibilityLayer}
57
64
  >
58
65
  {showGridLines && (
59
66
  <CartesianGrid
@@ -95,9 +102,10 @@ export default function LineChartImpl({
95
102
  dataKey={category}
96
103
  stroke={getLineColor(idx)}
97
104
  fill={getLineColor(idx)}
98
- fillOpacity={0.2}
105
+ fillOpacity={areaOpacity}
99
106
  strokeWidth={2}
100
107
  connectNulls={connectNulls}
108
+ isAnimationActive={animate}
101
109
  dot={false}
102
110
  activeDot={{ r: 4, strokeWidth: 0 }}
103
111
  />
@@ -110,6 +118,7 @@ export default function LineChartImpl({
110
118
  stroke={getLineColor(idx)}
111
119
  strokeWidth={2}
112
120
  connectNulls={connectNulls}
121
+ isAnimationActive={animate}
113
122
  dot={false}
114
123
  activeDot={{ r: 4, strokeWidth: 0 }}
115
124
  />
@@ -18,3 +18,15 @@ describe('KpiCard', () => {
18
18
  expect(screen.getByText('last 30 days')).toBeTruthy()
19
19
  })
20
20
  })
21
+
22
+ describe('resolveChartColor', () => {
23
+ it('maps named colours, passes raw CSS colours through and falls back to the palette', async () => {
24
+ const { resolveChartColor, CHART_COLORS } = await import('../ChartUtils')
25
+ expect(resolveChartColor('blue', 0)).toBe('var(--chart-blue)')
26
+ expect(resolveChartColor('var(--foreground)', 0)).toBe('var(--foreground)')
27
+ expect(resolveChartColor('#123456', 0)).toBe('#123456')
28
+ expect(resolveChartColor('oklch(0.5 0.1 200)', 0)).toBe('oklch(0.5 0.1 200)')
29
+ expect(resolveChartColor('nope', 1)).toBe(CHART_COLORS[1])
30
+ expect(resolveChartColor(undefined, 7)).toBe(CHART_COLORS[7 % CHART_COLORS.length])
31
+ })
32
+ })
@@ -3,9 +3,12 @@ import * as React from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import { useT } from "@open-mercato/shared/lib/i18n/context";
5
5
  import { Button } from "@open-mercato/ui/primitives/button";
6
+ import { DialogFooter, DialogHeader } from "@open-mercato/ui/primitives/dialog";
6
7
  import { IconButton } from "../../primitives/icon-button";
7
8
  import { cn } from "@open-mercato/shared/lib/utils";
8
- import { Loader2, X } from "lucide-react";
9
+ import { CircleHelp, Loader2, TriangleAlert, X } from "lucide-react";
10
+
11
+ const FOOTER_ACTION_CLASS_NAME = "h-auto min-h-9 whitespace-normal py-1.5 text-center";
9
12
 
10
13
  export type ConfirmDialogProps = {
11
14
  /** Whether the dialog is open (controlled mode — used by useConfirmDialog) */
@@ -26,8 +29,14 @@ export type ConfirmDialogProps = {
26
29
  /** Cancel button label. Defaults to i18n "ui.dialogs.confirm.cancelText" ("Cancel").
27
30
  * Pass `false` to hide the cancel button entirely. */
28
31
  cancelText?: string | false;
29
- /** Visual variant — "destructive" renders the confirm button in red */
30
- variant?: "default" | "destructive";
32
+ /** Visual variant per Figma `Status Modals [1.1]`:
33
+ * - "default": neutral help badge, primary confirm
34
+ * - "warning": amber warning badge, primary confirm — for risky actions that
35
+ * lose no data
36
+ * - "destructive": error badge and the `destructive-solid` confirm — the
37
+ * point of no return for anything that deletes or discards data, including
38
+ * unsaved edits */
39
+ variant?: "default" | "warning" | "destructive";
31
40
  /** Whether the confirm button shows a loading spinner.
32
41
  * Useful for async onConfirm handlers (e.g., waiting for API response before closing). */
33
42
  loading?: boolean;
@@ -229,7 +238,7 @@ export function ConfirmDialog({
229
238
  // Mobile: bottom sheet
230
239
  "fixed inset-x-0 bottom-0 top-auto w-full",
231
240
  // Desktop: centered
232
- "sm:inset-auto sm:mx-auto sm:my-auto sm:max-w-md sm:top-1/2 sm:left-1/2 sm:-translate-x-1/2 sm:-translate-y-1/2",
241
+ "sm:inset-auto sm:mx-auto sm:my-auto sm:max-w-sm sm:top-1/2 sm:left-1/2 sm:-translate-x-1/2 sm:-translate-y-1/2",
233
242
  // Animation with reduced motion support
234
243
  "motion-safe:open:animate-in motion-safe:open:fade-in-0 motion-safe:open:slide-in-from-bottom-4",
235
244
  "sm:motion-safe:open:slide-in-from-bottom-0 sm:motion-safe:open:zoom-in-95",
@@ -240,14 +249,12 @@ export function ConfirmDialog({
240
249
  <div
241
250
  role="document"
242
251
  className={cn(
243
- // Panel container
244
- "flex flex-col gap-4 rounded-t-2xl border-t bg-card p-6 text-foreground shadow-lg",
245
- "sm:rounded-xl sm:border",
246
- // Relative positioning for close button
247
- "relative"
252
+ // Same shell as DialogContent: card surface, p-6, sheet on mobile, card on desktop
253
+ "relative flex flex-col gap-4 rounded-t-xl border-t bg-card p-6 text-foreground shadow-lg",
254
+ "sm:rounded-xl sm:border"
248
255
  )}
249
256
  >
250
- {/* Close button */}
257
+ {/* Close button — mirrors DialogContent's auto close affordance */}
251
258
  <IconButton
252
259
  type="button"
253
260
  variant="ghost"
@@ -260,37 +267,38 @@ export function ConfirmDialog({
260
267
  <X className="h-4 w-4" />
261
268
  </IconButton>
262
269
 
263
- {/* Title */}
264
- <h2
265
- id={titleId}
266
- className={cn(
267
- "text-sm font-medium leading-snug tracking-tight pr-6",
268
- // Mobile: centered, Desktop: left-aligned
269
- "text-center sm:text-left"
270
- )}
270
+ {/* Header per Figma `Status Modals [1.1]`: status badge + title + description */}
271
+ <DialogHeader
272
+ className="pr-6"
273
+ leading={
274
+ variant === "default" ? (
275
+ <CircleHelp className="size-4" aria-hidden />
276
+ ) : (
277
+ <TriangleAlert className="size-4" aria-hidden />
278
+ )
279
+ }
280
+ leadingTone={variant === "destructive" ? "error" : variant === "warning" ? "warning" : "default"}
271
281
  >
272
- {resolvedTitle}
273
- </h2>
282
+ <h2 id={titleId} className="text-lg font-semibold leading-none tracking-tight">
283
+ {resolvedTitle}
284
+ </h2>
285
+ {text ? (
286
+ <p id={descriptionId} className="text-sm text-muted-foreground">
287
+ {text}
288
+ </p>
289
+ ) : null}
290
+ </DialogHeader>
274
291
 
275
- {/* Description (optional) */}
276
- {text && (
277
- <p
278
- id={descriptionId}
279
- className="text-sm font-medium leading-snug text-muted-foreground"
280
- >
281
- {text}
282
- </p>
283
- )}
284
-
285
- {/* Actions */}
286
- <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
292
+ {/* Footer per Figma `Modal Footer [1.1]` variant 1: 50/50 confirmation split,
293
+ stacked on phones, with labels that wrap instead of overflowing the card */}
294
+ <DialogFooter layout="equal" className="flex-col-reverse sm:flex-row">
287
295
  {resolvedCancelText !== false && (
288
296
  <Button
289
297
  ref={cancelButtonRef}
290
298
  variant="outline"
291
299
  onClick={handleCancel}
292
300
  disabled={loading}
293
- className="w-full sm:w-auto"
301
+ className={FOOTER_ACTION_CLASS_NAME}
294
302
  >
295
303
  {resolvedCancelText}
296
304
  </Button>
@@ -301,13 +309,13 @@ export function ConfirmDialog({
301
309
  variant={variant === "destructive" ? "destructive-solid" : "default"}
302
310
  onClick={handleConfirm}
303
311
  disabled={loading}
304
- className="w-full sm:w-auto"
312
+ className={FOOTER_ACTION_CLASS_NAME}
305
313
  >
306
314
  {loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
307
315
  {resolvedConfirmText}
308
316
  </Button>
309
317
  )}
310
- </div>
318
+ </DialogFooter>
311
319
  </div>
312
320
  </dialog>
313
321
  );
@@ -125,6 +125,90 @@ describe('ConfirmDialog', () => {
125
125
  expect(classNames).not.toContain('bg-status-error-solid')
126
126
  })
127
127
 
128
+ it('keeps the warning confirmation on the primary variant', () => {
129
+ renderWithProviders(
130
+ <ConfirmDialog
131
+ open
132
+ variant="warning"
133
+ onOpenChange={() => undefined}
134
+ onConfirm={() => undefined}
135
+ title="Send anyway?"
136
+ confirmText="Send"
137
+ cancelText="Cancel"
138
+ />,
139
+ )
140
+
141
+ const classNames = screen.getByRole('button', { name: 'Send' }).className.split(/\s+/)
142
+ expect(classNames).toContain('bg-primary')
143
+ expect(classNames).not.toContain('bg-status-error-solid')
144
+ })
145
+
146
+ it.each([
147
+ [undefined, 'default'],
148
+ ['default', 'default'],
149
+ ['warning', 'warning'],
150
+ ['destructive', 'error'],
151
+ ] as const)('maps variant %s to the %s header tone', (variant, tone) => {
152
+ renderWithProviders(
153
+ <ConfirmDialog
154
+ open
155
+ variant={variant}
156
+ onOpenChange={() => undefined}
157
+ onConfirm={() => undefined}
158
+ title="Continue?"
159
+ confirmText="Continue"
160
+ cancelText="Cancel"
161
+ />,
162
+ )
163
+
164
+ const leading = screen.getByRole('alertdialog').querySelector('[data-slot="dialog-header-leading"]')
165
+ expect(leading).toHaveAttribute('data-tone', tone)
166
+ })
167
+
168
+ it('stacks the footer on phones and splits it evenly from the sm breakpoint', () => {
169
+ renderWithProviders(
170
+ <ConfirmDialog
171
+ open
172
+ onOpenChange={() => undefined}
173
+ onConfirm={() => undefined}
174
+ title="Continue?"
175
+ confirmText="Continue"
176
+ cancelText="Cancel"
177
+ />,
178
+ )
179
+
180
+ const footer = screen.getByRole('alertdialog').querySelector('[data-slot="dialog-footer"]')
181
+ expect(footer).toHaveAttribute('data-layout', 'equal')
182
+ const classNames = (footer as HTMLElement).className.split(/\s+/)
183
+ expect(classNames).toContain('flex-col-reverse')
184
+ expect(classNames).toContain('sm:flex-row')
185
+ expect(classNames).not.toContain('flex-row')
186
+ })
187
+
188
+ it.each([
189
+ ['Weiter bearbeiten', 'Änderungen verwerfen'],
190
+ ['Abbrechen', 'Typ ändern und Werte löschen'],
191
+ ])('lets the long translated actions "%s" and "%s" wrap inside the card', (cancelText, confirmText) => {
192
+ renderWithProviders(
193
+ <ConfirmDialog
194
+ open
195
+ onOpenChange={() => undefined}
196
+ onConfirm={() => undefined}
197
+ title="Änderungen verwerfen?"
198
+ variant="destructive"
199
+ confirmText={confirmText}
200
+ cancelText={cancelText}
201
+ />,
202
+ )
203
+
204
+ for (const name of [cancelText, confirmText]) {
205
+ const classNames = screen.getByRole('button', { name }).className.split(/\s+/)
206
+ expect(classNames).toEqual(expect.arrayContaining(['whitespace-normal', 'h-auto', 'min-h-9', 'text-center']))
207
+ expect(classNames).not.toContain('whitespace-nowrap')
208
+ expect(classNames).not.toContain('h-9')
209
+ }
210
+ })
211
+
128
212
  it('closes only the confirmation that owns an Escape event', () => {
129
213
  const firstOpenChange = jest.fn()
130
214
  const secondOpenChange = jest.fn()
@@ -21,7 +21,7 @@ export type ConfirmDialogOptions = {
21
21
  description?: string;
22
22
  confirmText?: string | false;
23
23
  cancelText?: string | false;
24
- variant?: "default" | "destructive";
24
+ variant?: "default" | "warning" | "destructive";
25
25
  };
26
26
 
27
27
  export type UseConfirmDialogReturn = {
@@ -145,10 +145,7 @@ function formatFieldValue(
145
145
  key={`${field.id}-${entry}-${index}`}
146
146
  value={entry}
147
147
  map={dictionaryMap}
148
- className="inline-flex items-center gap-1 rounded-full border border-border bg-card px-2 py-1 text-xs"
149
- iconWrapperClassName="inline-flex h-4 w-4 items-center justify-center rounded-full border border-border bg-background"
150
- iconClassName="h-3 w-3"
151
- colorClassName="h-2.5 w-2.5 rounded-full"
148
+ appearance="pill"
152
149
  />
153
150
  ))}
154
151
  </div>
@@ -166,9 +163,6 @@ function formatFieldValue(
166
163
  map={dictionaryMap}
167
164
  className="inline-flex items-center gap-2 text-sm"
168
165
  fallback={<span className="text-muted-foreground">{emptyLabel}</span>}
169
- iconWrapperClassName="inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-card"
170
- iconClassName="h-4 w-4"
171
- colorClassName="h-3 w-3 rounded-full"
172
166
  />
173
167
  )
174
168
  }