@open-mercato/ui 0.10.1-develop.8217.1.e0e2d14319 → 0.10.1-develop.8223.1.126ffb6379

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 (28) 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/package.json +3 -3
  17. package/src/backend/CrudForm.tsx +5 -1
  18. package/src/backend/__tests__/CrudForm.navigation.test.tsx +1 -1
  19. package/src/backend/__tests__/CrudForm.unsavedNavigation.test.tsx +9 -9
  20. package/src/backend/charts/BarChart.tsx +37 -19
  21. package/src/backend/charts/BarChartImpl.tsx +10 -1
  22. package/src/backend/charts/ChartUtils.tsx +7 -0
  23. package/src/backend/charts/LineChart.tsx +32 -12
  24. package/src/backend/charts/LineChartImpl.tsx +10 -1
  25. package/src/backend/charts/__tests__/KpiCard.test.tsx +12 -0
  26. package/src/backend/confirm-dialog/ConfirmDialog.tsx +43 -35
  27. package/src/backend/confirm-dialog/__tests__/ConfirmDialog.test.tsx +84 -0
  28. package/src/backend/confirm-dialog/useConfirmDialog.tsx +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/backend/confirm-dialog/useConfirmDialog.tsx"],
4
- "sourcesContent": ["\"use client\";\nimport * as React from \"react\";\nimport { ConfirmDialog } from \"./ConfirmDialog\";\nimport { createLogger } from \"@open-mercato/shared/lib/logger\";\n\nconst logger = createLogger(\"ui\");\n\nfunction DialogMountTracker({ trackerRef }: { trackerRef: React.MutableRefObject<boolean> }) {\n React.useEffect(() => {\n trackerRef.current = true;\n return () => {\n trackerRef.current = false;\n };\n }, [trackerRef]);\n return null;\n}\n\nexport type ConfirmDialogOptions = {\n title?: string;\n text?: string;\n description?: string;\n confirmText?: string | false;\n cancelText?: string | false;\n variant?: \"default\" | \"destructive\";\n};\n\nexport type UseConfirmDialogReturn = {\n /** Call this to show a confirmation dialog. Resolves `true` if confirmed, `false` if cancelled. */\n confirm: (options?: ConfirmDialogOptions) => Promise<boolean>;\n /** Render this in your component tree (renders the <dialog> element) */\n ConfirmDialogElement: React.ReactNode;\n};\n\nexport function useConfirmDialog(): UseConfirmDialogReturn {\n const [open, setOpen] = React.useState(false);\n const [options, setOptions] = React.useState<ConfirmDialogOptions>({});\n const [loading, setLoading] = React.useState(false);\n const resolveRef = React.useRef<((value: boolean) => void) | null>(null);\n const openRef = React.useRef(false);\n const isDialogElementRenderedRef = React.useRef(false);\n const queueRef = React.useRef<Array<{\n options?: ConfirmDialogOptions;\n resolve: (value: boolean) => void;\n }>>([]);\n\n const processQueue = React.useCallback(() => {\n if (openRef.current) return;\n const next = queueRef.current.shift();\n if (!next) return;\n // Reserve the open slot synchronously so a confirm() call dispatched\n // between this microtask scheduling and the actual setState cannot\n // race ahead and double-open the dialog.\n openRef.current = true;\n resolveRef.current = next.resolve;\n // Defer the React state writes to a microtask so they run after any\n // parent component's useInsertionEffect commit phase (Radix Dialog,\n // CSS-in-JS layer injection, etc.). React 18/19 rejects setState\n // scheduled during the insertion-effect phase with the warning\n // \"useInsertionEffect must not schedule updates\" \u2014 see #1810.\n queueMicrotask(() => {\n setOptions(next.options || {});\n setOpen(true);\n });\n }, []);\n const finalizeInteraction = React.useCallback(() => {\n // Reset openRef BEFORE scheduling queue work so a subsequent confirm()\n // call from the parent's onOpenChange propagation isn't dropped by the\n // openRef.current === true guard (#1804). The visible dialog still\n // closes via setOpen(false); only the internal lock flips early.\n openRef.current = false;\n setOpen(false);\n // Defer queue advancement to the next microtask so the parent's\n // onOpenChange / Promise resolution has a chance to propagate before\n // a queued request reopens the dialog with new options.\n queueMicrotask(() => {\n processQueue();\n });\n }, [processQueue]);\n\n const confirm = React.useCallback(\n (newOptions?: ConfirmDialogOptions): Promise<boolean> => {\n return new Promise<boolean>((resolve) => {\n // Development-mode guard: warn if dialog element is not mounted\n if (\n process.env.NODE_ENV === \"development\" &&\n !isDialogElementRenderedRef.current\n ) {\n logger.warn(\"useConfirmDialog: confirm() was called but ConfirmDialogElement is not rendered. Add {ConfirmDialogElement} to your JSX.\");\n }\n\n // If dialog is already open or a previous interaction is still\n // resolving, enqueue this request. processQueue() picks it up after\n // the in-flight interaction finalises.\n if (openRef.current || resolveRef.current) {\n queueRef.current.push({ options: newOptions, resolve });\n return;\n }\n\n // Otherwise, claim the open slot synchronously and defer the\n // actual setState writes to a microtask (same rationale as\n // processQueue \u2014 keeps us out of the parent's insertion-effect\n // commit phase).\n openRef.current = true;\n resolveRef.current = resolve;\n queueMicrotask(() => {\n setOptions(newOptions || {});\n setOpen(true);\n });\n });\n },\n []\n );\n\n const handleConfirm = React.useCallback(async () => {\n setLoading(true);\n try {\n // Resolve with true (confirmed)\n resolveRef.current?.(true);\n resolveRef.current = null;\n } finally {\n setLoading(false);\n finalizeInteraction();\n }\n }, [finalizeInteraction]);\n\n const handleCancel = React.useCallback(() => {\n // Resolve with false (cancelled)\n resolveRef.current?.(false);\n resolveRef.current = null;\n finalizeInteraction();\n }, [finalizeInteraction]);\n\n const handleOpenChange = React.useCallback(\n (newOpen: boolean) => {\n if (!newOpen && openRef.current) {\n handleCancel();\n }\n },\n [handleCancel]\n );\n\n const ConfirmDialogElement = React.useMemo(\n () => (\n <>\n <DialogMountTracker trackerRef={isDialogElementRenderedRef} />\n <ConfirmDialog\n open={open}\n onOpenChange={handleOpenChange}\n onConfirm={handleConfirm}\n title={options.title}\n text={options.text ?? options.description}\n confirmText={options.confirmText}\n cancelText={options.cancelText}\n variant={options.variant}\n loading={loading}\n />\n </>\n ),\n [\n open,\n handleOpenChange,\n handleConfirm,\n options,\n loading,\n ]\n );\n\n return {\n confirm,\n ConfirmDialogElement,\n };\n}\n"],
4
+ "sourcesContent": ["\"use client\";\nimport * as React from \"react\";\nimport { ConfirmDialog } from \"./ConfirmDialog\";\nimport { createLogger } from \"@open-mercato/shared/lib/logger\";\n\nconst logger = createLogger(\"ui\");\n\nfunction DialogMountTracker({ trackerRef }: { trackerRef: React.MutableRefObject<boolean> }) {\n React.useEffect(() => {\n trackerRef.current = true;\n return () => {\n trackerRef.current = false;\n };\n }, [trackerRef]);\n return null;\n}\n\nexport type ConfirmDialogOptions = {\n title?: string;\n text?: string;\n description?: string;\n confirmText?: string | false;\n cancelText?: string | false;\n variant?: \"default\" | \"warning\" | \"destructive\";\n};\n\nexport type UseConfirmDialogReturn = {\n /** Call this to show a confirmation dialog. Resolves `true` if confirmed, `false` if cancelled. */\n confirm: (options?: ConfirmDialogOptions) => Promise<boolean>;\n /** Render this in your component tree (renders the <dialog> element) */\n ConfirmDialogElement: React.ReactNode;\n};\n\nexport function useConfirmDialog(): UseConfirmDialogReturn {\n const [open, setOpen] = React.useState(false);\n const [options, setOptions] = React.useState<ConfirmDialogOptions>({});\n const [loading, setLoading] = React.useState(false);\n const resolveRef = React.useRef<((value: boolean) => void) | null>(null);\n const openRef = React.useRef(false);\n const isDialogElementRenderedRef = React.useRef(false);\n const queueRef = React.useRef<Array<{\n options?: ConfirmDialogOptions;\n resolve: (value: boolean) => void;\n }>>([]);\n\n const processQueue = React.useCallback(() => {\n if (openRef.current) return;\n const next = queueRef.current.shift();\n if (!next) return;\n // Reserve the open slot synchronously so a confirm() call dispatched\n // between this microtask scheduling and the actual setState cannot\n // race ahead and double-open the dialog.\n openRef.current = true;\n resolveRef.current = next.resolve;\n // Defer the React state writes to a microtask so they run after any\n // parent component's useInsertionEffect commit phase (Radix Dialog,\n // CSS-in-JS layer injection, etc.). React 18/19 rejects setState\n // scheduled during the insertion-effect phase with the warning\n // \"useInsertionEffect must not schedule updates\" \u2014 see #1810.\n queueMicrotask(() => {\n setOptions(next.options || {});\n setOpen(true);\n });\n }, []);\n const finalizeInteraction = React.useCallback(() => {\n // Reset openRef BEFORE scheduling queue work so a subsequent confirm()\n // call from the parent's onOpenChange propagation isn't dropped by the\n // openRef.current === true guard (#1804). The visible dialog still\n // closes via setOpen(false); only the internal lock flips early.\n openRef.current = false;\n setOpen(false);\n // Defer queue advancement to the next microtask so the parent's\n // onOpenChange / Promise resolution has a chance to propagate before\n // a queued request reopens the dialog with new options.\n queueMicrotask(() => {\n processQueue();\n });\n }, [processQueue]);\n\n const confirm = React.useCallback(\n (newOptions?: ConfirmDialogOptions): Promise<boolean> => {\n return new Promise<boolean>((resolve) => {\n // Development-mode guard: warn if dialog element is not mounted\n if (\n process.env.NODE_ENV === \"development\" &&\n !isDialogElementRenderedRef.current\n ) {\n logger.warn(\"useConfirmDialog: confirm() was called but ConfirmDialogElement is not rendered. Add {ConfirmDialogElement} to your JSX.\");\n }\n\n // If dialog is already open or a previous interaction is still\n // resolving, enqueue this request. processQueue() picks it up after\n // the in-flight interaction finalises.\n if (openRef.current || resolveRef.current) {\n queueRef.current.push({ options: newOptions, resolve });\n return;\n }\n\n // Otherwise, claim the open slot synchronously and defer the\n // actual setState writes to a microtask (same rationale as\n // processQueue \u2014 keeps us out of the parent's insertion-effect\n // commit phase).\n openRef.current = true;\n resolveRef.current = resolve;\n queueMicrotask(() => {\n setOptions(newOptions || {});\n setOpen(true);\n });\n });\n },\n []\n );\n\n const handleConfirm = React.useCallback(async () => {\n setLoading(true);\n try {\n // Resolve with true (confirmed)\n resolveRef.current?.(true);\n resolveRef.current = null;\n } finally {\n setLoading(false);\n finalizeInteraction();\n }\n }, [finalizeInteraction]);\n\n const handleCancel = React.useCallback(() => {\n // Resolve with false (cancelled)\n resolveRef.current?.(false);\n resolveRef.current = null;\n finalizeInteraction();\n }, [finalizeInteraction]);\n\n const handleOpenChange = React.useCallback(\n (newOpen: boolean) => {\n if (!newOpen && openRef.current) {\n handleCancel();\n }\n },\n [handleCancel]\n );\n\n const ConfirmDialogElement = React.useMemo(\n () => (\n <>\n <DialogMountTracker trackerRef={isDialogElementRenderedRef} />\n <ConfirmDialog\n open={open}\n onOpenChange={handleOpenChange}\n onConfirm={handleConfirm}\n title={options.title}\n text={options.text ?? options.description}\n confirmText={options.confirmText}\n cancelText={options.cancelText}\n variant={options.variant}\n loading={loading}\n />\n </>\n ),\n [\n open,\n handleOpenChange,\n handleConfirm,\n options,\n loading,\n ]\n );\n\n return {\n confirm,\n ConfirmDialogElement,\n };\n}\n"],
5
5
  "mappings": "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",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/ui",
3
- "version": "0.10.1-develop.8217.1.e0e2d14319",
3
+ "version": "0.10.1-develop.8223.1.126ffb6379",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -156,14 +156,14 @@
156
156
  "remark-gfm": "^4.0.1"
157
157
  },
158
158
  "peerDependencies": {
159
- "@open-mercato/shared": "0.10.1-develop.8217.1.e0e2d14319",
159
+ "@open-mercato/shared": "0.10.1-develop.8223.1.126ffb6379",
160
160
  "react": ">=18.0.0",
161
161
  "react-dom": ">=18.0.0",
162
162
  "react-is": ">=18.0.0"
163
163
  },
164
164
  "devDependencies": {
165
165
  "@figma/code-connect": "^1.3.4",
166
- "@open-mercato/shared": "0.10.1-develop.8217.1.e0e2d14319",
166
+ "@open-mercato/shared": "0.10.1-develop.8223.1.126ffb6379",
167
167
  "@testing-library/dom": "^10.4.1",
168
168
  "@testing-library/jest-dom": "^7.0.1",
169
169
  "@testing-library/react": "^16.3.3",
@@ -1157,7 +1157,11 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
1157
1157
  navigationConfirmPendingRef.current = true
1158
1158
  try {
1159
1159
  const confirmed = await confirm({
1160
- title: t('ui.forms.confirmUnsavedChanges', 'You have unsaved changes. Are you sure you want to leave?'),
1160
+ title: t('ui.forms.unsavedChangesTitle', 'Discard unsaved changes?'),
1161
+ description: t('ui.forms.unsavedChangesDescription', 'Your edits will be lost if you leave now.'),
1162
+ confirmText: t('ui.forms.unsavedChangesDiscard', 'Discard changes'),
1163
+ cancelText: t('ui.forms.unsavedChangesKeep', 'Keep editing'),
1164
+ variant: 'destructive',
1161
1165
  })
1162
1166
  if (confirmed) allowNextNavigation()
1163
1167
  return confirmed
@@ -206,7 +206,7 @@ describe('CrudForm unsaved navigation guard', () => {
206
206
  })
207
207
 
208
208
  expect(confirmDialogMock).toHaveBeenCalledWith(
209
- expect.objectContaining({ title: 'Unsaved changes' }),
209
+ expect.objectContaining({ title: 'Discard unsaved changes?' }),
210
210
  )
211
211
  expect(window.location.pathname).toBe('/')
212
212
 
@@ -65,7 +65,7 @@ describe('CrudForm unsaved navigation guard', () => {
65
65
  {
66
66
  dict: {
67
67
  'ui.forms.actions.save': 'Save',
68
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
68
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
69
69
  },
70
70
  },
71
71
  )
@@ -83,7 +83,7 @@ describe('CrudForm unsaved navigation guard', () => {
83
83
  })
84
84
 
85
85
  expect(confirmDialogMock).toHaveBeenCalledWith(
86
- expect.objectContaining({ title: 'You have unsaved changes. Are you sure you want to leave?' }),
86
+ expect.objectContaining({ title: 'Discard unsaved changes?', variant: 'destructive' }),
87
87
  )
88
88
  expect(window.location.pathname).toBe('/current')
89
89
  })
@@ -96,7 +96,7 @@ describe('CrudForm unsaved navigation guard', () => {
96
96
  {
97
97
  dict: {
98
98
  'ui.forms.actions.save': 'Save',
99
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
99
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
100
100
  },
101
101
  },
102
102
  )
@@ -119,7 +119,7 @@ describe('CrudForm unsaved navigation guard', () => {
119
119
  })
120
120
 
121
121
  expect(confirmDialogMock).toHaveBeenCalledWith(
122
- expect.objectContaining({ title: 'You have unsaved changes. Are you sure you want to leave?' }),
122
+ expect.objectContaining({ title: 'Discard unsaved changes?' }),
123
123
  )
124
124
  expect(event.defaultPrevented).toBe(true)
125
125
 
@@ -140,7 +140,7 @@ describe('CrudForm unsaved navigation guard', () => {
140
140
  {
141
141
  dict: {
142
142
  'ui.forms.actions.save': 'Save',
143
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
143
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
144
144
  },
145
145
  },
146
146
  )
@@ -184,7 +184,7 @@ describe('CrudForm unsaved navigation guard', () => {
184
184
  {
185
185
  dict: {
186
186
  'ui.forms.actions.save': 'Save',
187
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
187
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
188
188
  },
189
189
  },
190
190
  )
@@ -227,7 +227,7 @@ describe('CrudForm unsaved navigation guard', () => {
227
227
  {
228
228
  dict: {
229
229
  'ui.forms.actions.save': 'Save',
230
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
230
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
231
231
  },
232
232
  },
233
233
  )
@@ -255,7 +255,7 @@ describe('CrudForm unsaved navigation guard', () => {
255
255
  {
256
256
  dict: {
257
257
  'ui.forms.actions.save': 'Save',
258
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
258
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
259
259
  },
260
260
  },
261
261
  )
@@ -294,7 +294,7 @@ describe('CrudForm unsaved navigation guard', () => {
294
294
  {
295
295
  dict: {
296
296
  'ui.forms.actions.save': 'Save',
297
- 'ui.forms.confirmUnsavedChanges': 'You have unsaved changes. Are you sure you want to leave?',
297
+ 'ui.forms.unsavedChangesTitle': 'Discard unsaved changes?',
298
298
  },
299
299
  },
300
300
  )
@@ -21,6 +21,14 @@ export type BarChartProps = {
21
21
  className?: string
22
22
  emptyMessage?: string
23
23
  categoryLabels?: Record<string, string>
24
+ /** Render only the plot (no card border, padding or title) so a host card can own the chrome. */
25
+ bare?: boolean
26
+ /** Height utility for the plot area in bare mode; defaults to `h-52`. */
27
+ heightClassName?: string
28
+ /** Recharts draw-in animation; pass false for charts that re-render on interaction. */
29
+ animate?: boolean
30
+ /** Recharts keyboard/focus layer; pass false for decorative charts so the plot never takes focus. */
31
+ accessibilityLayer?: boolean
24
32
  }
25
33
 
26
34
  function defaultValueFormatter(value: number): string {
@@ -57,15 +65,20 @@ export function BarChart({
57
65
  className = '',
58
66
  emptyMessage = 'No data available',
59
67
  categoryLabels,
68
+ bare = false,
69
+ heightClassName = 'h-52',
70
+ animate = true,
71
+ accessibilityLayer = true,
60
72
  }: BarChartProps) {
61
- const hasWrapper = !!title
73
+ const hasWrapper = !!title && !bare
62
74
  const wrapperClass = hasWrapper ? `rounded-lg border bg-card p-4 ${className}` : className
75
+ const stateClassName = bare ? `flex items-center justify-center ${heightClassName}` : 'flex h-40 sm:h-48 items-center justify-center'
63
76
 
64
77
  if (error) {
65
78
  return (
66
79
  <div className={wrapperClass}>
67
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
68
- <div className="flex h-40 sm:h-48 items-center justify-center">
80
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
81
+ <div className={stateClassName}>
69
82
  <p className="text-sm text-destructive">{error}</p>
70
83
  </div>
71
84
  </div>
@@ -75,8 +88,8 @@ export function BarChart({
75
88
  if (loading) {
76
89
  return (
77
90
  <div className={wrapperClass}>
78
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
79
- <div className="flex h-40 sm:h-48 items-center justify-center">
91
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
92
+ <div className={stateClassName}>
80
93
  <Spinner className="h-6 w-6 text-muted-foreground" />
81
94
  </div>
82
95
  </div>
@@ -86,8 +99,8 @@ export function BarChart({
86
99
  if (!data || data.length === 0) {
87
100
  return (
88
101
  <div className={wrapperClass}>
89
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
90
- <div className="flex h-40 sm:h-48 items-center justify-center">
102
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
103
+ <div className={stateClassName}>
91
104
  <p className="text-sm text-muted-foreground">{emptyMessage}</p>
92
105
  </div>
93
106
  </div>
@@ -96,18 +109,23 @@ export function BarChart({
96
109
 
97
110
  return (
98
111
  <div className={wrapperClass}>
99
- {title && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
100
- <BarChartImpl
101
- data={data}
102
- index={index}
103
- categories={categories}
104
- colors={colors}
105
- layout={layout}
106
- valueFormatter={valueFormatter}
107
- showLegend={showLegend}
108
- showGridLines={showGridLines}
109
- categoryLabels={categoryLabels}
110
- />
112
+ {title && !bare && <h3 className="mb-4 text-base font-medium text-card-foreground">{title}</h3>}
113
+ <div className={bare ? `${heightClassName} w-full` : undefined}>
114
+ <BarChartImpl
115
+ data={data}
116
+ index={index}
117
+ categories={categories}
118
+ colors={colors}
119
+ layout={layout}
120
+ valueFormatter={valueFormatter}
121
+ showLegend={showLegend}
122
+ showGridLines={showGridLines}
123
+ categoryLabels={categoryLabels}
124
+ animate={animate}
125
+ accessibilityLayer={accessibilityLayer}
126
+ fillHeight={bare}
127
+ />
128
+ </div>
111
129
  </div>
112
130
  )
113
131
  }
@@ -25,8 +25,12 @@ type ImplProps = Pick<
25
25
  | 'showLegend'
26
26
  | 'showGridLines'
27
27
  | 'categoryLabels'
28
+ | 'animate'
29
+ | 'accessibilityLayer'
28
30
  > & {
29
31
  valueFormatter: (value: number) => string
32
+ /** Fill the host element instead of the fixed default height (bare mode). */
33
+ fillHeight?: boolean
30
34
  }
31
35
 
32
36
  export default function BarChartImpl({
@@ -39,17 +43,21 @@ export default function BarChartImpl({
39
43
  showLegend = true,
40
44
  showGridLines = true,
41
45
  categoryLabels,
46
+ animate = true,
47
+ accessibilityLayer = true,
48
+ fillHeight = false,
42
49
  }: ImplProps) {
43
50
  const isHorizontal = layout === 'horizontal'
44
51
  const chartHeight = isHorizontal ? Math.max(200, data.length * 28) : 200
45
52
  const getBarColor = (idx: number): string => resolveChartColor(colors?.[idx], idx)
46
53
 
47
54
  return (
48
- <ResponsiveContainer width="100%" height={chartHeight}>
55
+ <ResponsiveContainer width="100%" height={fillHeight ? '100%' : chartHeight}>
49
56
  <RechartsBarChart
50
57
  data={data}
51
58
  layout={isHorizontal ? 'vertical' : 'horizontal'}
52
59
  margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
60
+ accessibilityLayer={accessibilityLayer}
53
61
  >
54
62
  {showGridLines && (
55
63
  <CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
@@ -91,6 +99,7 @@ export default function BarChartImpl({
91
99
  dataKey={category}
92
100
  fill={getBarColor(idx)}
93
101
  radius={isHorizontal ? [0, 4, 4, 0] : [4, 4, 0, 0]}
102
+ isAnimationActive={animate}
94
103
  />
95
104
  ))}
96
105
  </RechartsBarChart>
@@ -172,9 +172,16 @@ export function getChartColor(index: number): string {
172
172
  return CHART_COLORS[index % CHART_COLORS.length]
173
173
  }
174
174
 
175
+ function isRawCssColor(color: string): boolean {
176
+ return color.startsWith('#') || color.startsWith('var(') || /^(rgb|hsl|oklch|oklab|color)\(/.test(color)
177
+ }
178
+
175
179
  export function resolveChartColor(color: string | undefined, index: number): string {
176
180
  if (color && NAMED_COLORS[color]) {
177
181
  return NAMED_COLORS[color]
178
182
  }
183
+ if (color && isRawCssColor(color)) {
184
+ return color
185
+ }
179
186
  return CHART_COLORS[index % CHART_COLORS.length]
180
187
  }
@@ -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
  );