@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.
- package/dist/backend/CrudForm.js +5 -1
- package/dist/backend/CrudForm.js.map +2 -2
- package/dist/backend/charts/BarChart.js +20 -12
- package/dist/backend/charts/BarChart.js.map +2 -2
- package/dist/backend/charts/BarChartImpl.js +8 -3
- package/dist/backend/charts/BarChartImpl.js.map +2 -2
- package/dist/backend/charts/ChartUtils.js +6 -0
- package/dist/backend/charts/ChartUtils.js.map +2 -2
- package/dist/backend/charts/LineChart.js +24 -14
- package/dist/backend/charts/LineChart.js.map +2 -2
- package/dist/backend/charts/LineChartImpl.js +8 -2
- package/dist/backend/charts/LineChartImpl.js.map +2 -2
- package/dist/backend/confirm-dialog/ConfirmDialog.js +19 -27
- package/dist/backend/confirm-dialog/ConfirmDialog.js.map +2 -2
- package/dist/backend/confirm-dialog/useConfirmDialog.js.map +1 -1
- package/dist/backend/detail/CustomDataSection.js +2 -8
- package/dist/backend/detail/CustomDataSection.js.map +2 -2
- package/package.json +3 -3
- package/src/backend/CrudForm.tsx +5 -1
- package/src/backend/__tests__/CrudForm.navigation.test.tsx +1 -1
- package/src/backend/__tests__/CrudForm.unsavedNavigation.test.tsx +9 -9
- package/src/backend/__tests__/CustomDataSection.test.tsx +45 -0
- package/src/backend/charts/BarChart.tsx +37 -19
- package/src/backend/charts/BarChartImpl.tsx +10 -1
- package/src/backend/charts/ChartUtils.tsx +7 -0
- package/src/backend/charts/LineChart.tsx +32 -12
- package/src/backend/charts/LineChartImpl.tsx +10 -1
- package/src/backend/charts/__tests__/KpiCard.test.tsx +12 -0
- package/src/backend/confirm-dialog/ConfirmDialog.tsx +43 -35
- package/src/backend/confirm-dialog/__tests__/ConfirmDialog.test.tsx +84 -0
- package/src/backend/confirm-dialog/useConfirmDialog.tsx +1 -1
- package/src/backend/detail/CustomDataSection.tsx +1 -7
|
@@ -29,31 +29,36 @@ function BarChart({
|
|
|
29
29
|
showGridLines = true,
|
|
30
30
|
className = "",
|
|
31
31
|
emptyMessage = "No data available",
|
|
32
|
-
categoryLabels
|
|
32
|
+
categoryLabels,
|
|
33
|
+
bare = false,
|
|
34
|
+
heightClassName = "h-52",
|
|
35
|
+
animate = true,
|
|
36
|
+
accessibilityLayer = true
|
|
33
37
|
}) {
|
|
34
|
-
const hasWrapper = !!title;
|
|
38
|
+
const hasWrapper = !!title && !bare;
|
|
35
39
|
const wrapperClass = hasWrapper ? `rounded-lg border bg-card p-4 ${className}` : className;
|
|
40
|
+
const stateClassName = bare ? `flex items-center justify-center ${heightClassName}` : "flex h-40 sm:h-48 items-center justify-center";
|
|
36
41
|
if (error) {
|
|
37
42
|
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
38
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
39
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
43
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
44
|
+
/* @__PURE__ */ jsx("div", { className: stateClassName, children: /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }) })
|
|
40
45
|
] });
|
|
41
46
|
}
|
|
42
47
|
if (loading) {
|
|
43
48
|
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
44
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
45
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
49
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
50
|
+
/* @__PURE__ */ jsx("div", { className: stateClassName, children: /* @__PURE__ */ jsx(Spinner, { className: "h-6 w-6 text-muted-foreground" }) })
|
|
46
51
|
] });
|
|
47
52
|
}
|
|
48
53
|
if (!data || data.length === 0) {
|
|
49
54
|
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
50
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
51
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
55
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
56
|
+
/* @__PURE__ */ jsx("div", { className: stateClassName, children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: emptyMessage }) })
|
|
52
57
|
] });
|
|
53
58
|
}
|
|
54
59
|
return /* @__PURE__ */ jsxs("div", { className: wrapperClass, children: [
|
|
55
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
56
|
-
/* @__PURE__ */ jsx(
|
|
60
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
61
|
+
/* @__PURE__ */ jsx("div", { className: bare ? `${heightClassName} w-full` : void 0, children: /* @__PURE__ */ jsx(
|
|
57
62
|
BarChartImpl,
|
|
58
63
|
{
|
|
59
64
|
data,
|
|
@@ -64,9 +69,12 @@ function BarChart({
|
|
|
64
69
|
valueFormatter,
|
|
65
70
|
showLegend,
|
|
66
71
|
showGridLines,
|
|
67
|
-
categoryLabels
|
|
72
|
+
categoryLabels,
|
|
73
|
+
animate,
|
|
74
|
+
accessibilityLayer,
|
|
75
|
+
fillHeight: bare
|
|
68
76
|
}
|
|
69
|
-
)
|
|
77
|
+
) })
|
|
70
78
|
] });
|
|
71
79
|
}
|
|
72
80
|
var BarChart_default = BarChart;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/charts/BarChart.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport type BarChartDataItem = Record<string, string | number | null | undefined>\n\nexport type BarChartProps = {\n title?: string\n data: BarChartDataItem[]\n index: string\n categories: string[]\n loading?: boolean\n error?: string | null\n colors?: string[]\n layout?: 'vertical' | 'horizontal'\n valueFormatter?: (value: number) => string\n showLegend?: boolean\n showGridLines?: boolean\n className?: string\n emptyMessage?: string\n categoryLabels?: Record<string, string>\n}\n\nfunction defaultValueFormatter(value: number): string {\n if (Math.abs(value) >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(1)}M`\n }\n if (Math.abs(value) >= 1_000) {\n return `${(value / 1_000).toFixed(1)}K`\n }\n return value.toLocaleString(undefined, { maximumFractionDigits: 2 })\n}\n\nconst BarChartImpl = dynamic(() => import('./BarChartImpl'), {\n ssr: false,\n loading: () => (\n <div className=\"flex h-40 sm:h-48 items-center justify-center\">\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n ),\n})\n\nexport function BarChart({\n title,\n data,\n index,\n categories,\n loading,\n error,\n colors,\n layout = 'vertical',\n valueFormatter = defaultValueFormatter,\n showLegend = true,\n showGridLines = true,\n className = '',\n emptyMessage = 'No data available',\n categoryLabels,\n}: BarChartProps) {\n const hasWrapper = !!title\n const wrapperClass = hasWrapper ? `rounded-lg border bg-card p-4 ${className}` : className\n\n if (error) {\n return (\n <div className={wrapperClass}>\n {title && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport type BarChartDataItem = Record<string, string | number | null | undefined>\n\nexport type BarChartProps = {\n title?: string\n data: BarChartDataItem[]\n index: string\n categories: string[]\n loading?: boolean\n error?: string | null\n colors?: string[]\n layout?: 'vertical' | 'horizontal'\n valueFormatter?: (value: number) => string\n showLegend?: boolean\n showGridLines?: boolean\n className?: string\n emptyMessage?: string\n categoryLabels?: Record<string, string>\n /** Render only the plot (no card border, padding or title) so a host card can own the chrome. */\n bare?: boolean\n /** Height utility for the plot area in bare mode; defaults to `h-52`. */\n heightClassName?: string\n /** Recharts draw-in animation; pass false for charts that re-render on interaction. */\n animate?: boolean\n /** Recharts keyboard/focus layer; pass false for decorative charts so the plot never takes focus. */\n accessibilityLayer?: boolean\n}\n\nfunction defaultValueFormatter(value: number): string {\n if (Math.abs(value) >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(1)}M`\n }\n if (Math.abs(value) >= 1_000) {\n return `${(value / 1_000).toFixed(1)}K`\n }\n return value.toLocaleString(undefined, { maximumFractionDigits: 2 })\n}\n\nconst BarChartImpl = dynamic(() => import('./BarChartImpl'), {\n ssr: false,\n loading: () => (\n <div className=\"flex h-40 sm:h-48 items-center justify-center\">\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n ),\n})\n\nexport function BarChart({\n title,\n data,\n index,\n categories,\n loading,\n error,\n colors,\n layout = 'vertical',\n valueFormatter = defaultValueFormatter,\n showLegend = true,\n showGridLines = true,\n className = '',\n emptyMessage = 'No data available',\n categoryLabels,\n bare = false,\n heightClassName = 'h-52',\n animate = true,\n accessibilityLayer = true,\n}: BarChartProps) {\n const hasWrapper = !!title && !bare\n const wrapperClass = hasWrapper ? `rounded-lg border bg-card p-4 ${className}` : className\n const stateClassName = bare ? `flex items-center justify-center ${heightClassName}` : 'flex h-40 sm:h-48 items-center justify-center'\n\n if (error) {\n return (\n <div className={wrapperClass}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={stateClassName}>\n <p className=\"text-sm text-destructive\">{error}</p>\n </div>\n </div>\n )\n }\n\n if (loading) {\n return (\n <div className={wrapperClass}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={stateClassName}>\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n </div>\n )\n }\n\n if (!data || data.length === 0) {\n return (\n <div className={wrapperClass}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={stateClassName}>\n <p className=\"text-sm text-muted-foreground\">{emptyMessage}</p>\n </div>\n </div>\n )\n }\n\n return (\n <div className={wrapperClass}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={bare ? `${heightClassName} w-full` : undefined}>\n <BarChartImpl\n data={data}\n index={index}\n categories={categories}\n colors={colors}\n layout={layout}\n valueFormatter={valueFormatter}\n showLegend={showLegend}\n showGridLines={showGridLines}\n categoryLabels={categoryLabels}\n animate={animate}\n accessibilityLayer={accessibilityLayer}\n fillHeight={bare}\n />\n </div>\n </div>\n )\n}\n\nexport default BarChart\n"],
|
|
5
|
+
"mappings": ";AA+CM,cA+BA,YA/BA;AA5CN,OAAO,aAAa;AACpB,SAAS,eAAe;AA6BxB,SAAS,sBAAsB,OAAuB;AACpD,MAAI,KAAK,IAAI,KAAK,KAAK,KAAW;AAChC,WAAO,IAAI,QAAQ,KAAW,QAAQ,CAAC,CAAC;AAAA,EAC1C;AACA,MAAI,KAAK,IAAI,KAAK,KAAK,KAAO;AAC5B,WAAO,IAAI,QAAQ,KAAO,QAAQ,CAAC,CAAC;AAAA,EACtC;AACA,SAAO,MAAM,eAAe,QAAW,EAAE,uBAAuB,EAAE,CAAC;AACrE;AAEA,MAAM,eAAe,QAAQ,MAAM,OAAO,gBAAgB,GAAG;AAAA,EAC3D,KAAK;AAAA,EACL,SAAS,MACP,oBAAC,SAAI,WAAU,iDACb,8BAAC,WAAQ,WAAU,iCAAgC,GACrD;AAEJ,CAAC;AAEM,SAAS,SAAS;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,iBAAiB;AA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ACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,YAAY;AAAA;AAAA,IACd,GACF;AAAA,KACF;AAEJ;AAEA,IAAO,mBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -20,17 +20,21 @@ function BarChartImpl({
|
|
|
20
20
|
valueFormatter,
|
|
21
21
|
showLegend = true,
|
|
22
22
|
showGridLines = true,
|
|
23
|
-
categoryLabels
|
|
23
|
+
categoryLabels,
|
|
24
|
+
animate = true,
|
|
25
|
+
accessibilityLayer = true,
|
|
26
|
+
fillHeight = false
|
|
24
27
|
}) {
|
|
25
28
|
const isHorizontal = layout === "horizontal";
|
|
26
29
|
const chartHeight = isHorizontal ? Math.max(200, data.length * 28) : 200;
|
|
27
30
|
const getBarColor = (idx) => resolveChartColor(colors?.[idx], idx);
|
|
28
|
-
return /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: chartHeight, children: /* @__PURE__ */ jsxs(
|
|
31
|
+
return /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: fillHeight ? "100%" : chartHeight, children: /* @__PURE__ */ jsxs(
|
|
29
32
|
RechartsBarChart,
|
|
30
33
|
{
|
|
31
34
|
data,
|
|
32
35
|
layout: isHorizontal ? "vertical" : "horizontal",
|
|
33
36
|
margin: { top: 5, right: 30, left: 20, bottom: 5 },
|
|
37
|
+
accessibilityLayer,
|
|
34
38
|
children: [
|
|
35
39
|
showGridLines && /* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: "hsl(var(--border))" }),
|
|
36
40
|
/* @__PURE__ */ jsx(
|
|
@@ -77,7 +81,8 @@ function BarChartImpl({
|
|
|
77
81
|
{
|
|
78
82
|
dataKey: category,
|
|
79
83
|
fill: getBarColor(idx),
|
|
80
|
-
radius: isHorizontal ? [0, 4, 4, 0] : [4, 4, 0, 0]
|
|
84
|
+
radius: isHorizontal ? [0, 4, 4, 0] : [4, 4, 0, 0],
|
|
85
|
+
isAnimationActive: animate
|
|
81
86
|
},
|
|
82
87
|
category
|
|
83
88
|
))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/charts/BarChartImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport {\n BarChart as RechartsBarChart,\n Bar,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n Legend,\n ResponsiveContainer,\n} from 'recharts'\nimport { ChartTooltipContent, resolveChartColor } from './ChartUtils'\nimport type { BarChartDataItem, BarChartProps } from './BarChart'\n\ntype ImplProps = Pick<\n BarChartProps,\n | 'data'\n | 'index'\n | 'categories'\n | 'colors'\n | 'layout'\n | 'valueFormatter'\n | 'showLegend'\n | 'showGridLines'\n | 'categoryLabels'\n> & {\n valueFormatter: (value: number) => string\n}\n\nexport default function BarChartImpl({\n data,\n index,\n categories,\n colors,\n layout = 'vertical',\n valueFormatter,\n showLegend = true,\n showGridLines = true,\n categoryLabels,\n}: ImplProps) {\n const isHorizontal = layout === 'horizontal'\n const chartHeight = isHorizontal ? Math.max(200, data.length * 28) : 200\n const getBarColor = (idx: number): string => resolveChartColor(colors?.[idx], idx)\n\n return (\n <ResponsiveContainer width=\"100%\" height={chartHeight}>\n <RechartsBarChart\n data={data}\n layout={isHorizontal ? 'vertical' : 'horizontal'}\n margin={{ top: 5, right: 30, left: 20, bottom: 5 }}\n >\n {showGridLines && (\n <CartesianGrid strokeDasharray=\"3 3\" stroke=\"hsl(var(--border))\" />\n )}\n <XAxis\n type={isHorizontal ? 'number' : 'category'}\n dataKey={isHorizontal ? undefined : index}\n tickFormatter={isHorizontal ? valueFormatter : undefined}\n tick={{ fontSize: 11 }}\n />\n <YAxis\n type={isHorizontal ? 'category' : 'number'}\n dataKey={isHorizontal ? index : undefined}\n tickFormatter={isHorizontal ? undefined : valueFormatter}\n width={isHorizontal ? 90 : 50}\n interval={0}\n tick={{ fontSize: 10 }}\n />\n <Tooltip\n content={\n <ChartTooltipContent\n valueFormatter={valueFormatter}\n categoryLabels={categoryLabels}\n labelFormatter={(label, payload) => {\n const entry = payload?.[0] as { payload?: BarChartDataItem } | undefined\n const item = entry?.payload\n return item?.[index] ? String(item[index]) : label\n }}\n />\n }\n cursor={{ fill: 'hsl(var(--muted))', opacity: 0.2 }}\n />\n {showLegend && categories.length > 1 && (\n <Legend verticalAlign=\"top\" height={36} />\n )}\n {categories.map((category, idx) => (\n <Bar\n key={category}\n dataKey={category}\n fill={getBarColor(idx)}\n radius={isHorizontal ? [0, 4, 4, 0] : [4, 4, 0, 0]}\n />\n ))}\n </RechartsBarChart>\n </ResponsiveContainer>\n )\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport {\n BarChart as RechartsBarChart,\n Bar,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n Legend,\n ResponsiveContainer,\n} from 'recharts'\nimport { ChartTooltipContent, resolveChartColor } from './ChartUtils'\nimport type { BarChartDataItem, BarChartProps } from './BarChart'\n\ntype ImplProps = Pick<\n BarChartProps,\n | 'data'\n | 'index'\n | 'categories'\n | 'colors'\n | 'layout'\n | 'valueFormatter'\n | 'showLegend'\n | 'showGridLines'\n | 'categoryLabels'\n | 'animate'\n | 'accessibilityLayer'\n> & {\n valueFormatter: (value: number) => string\n /** Fill the host element instead of the fixed default height (bare mode). */\n fillHeight?: boolean\n}\n\nexport default function BarChartImpl({\n data,\n index,\n categories,\n colors,\n layout = 'vertical',\n valueFormatter,\n showLegend = true,\n showGridLines = true,\n categoryLabels,\n animate = true,\n accessibilityLayer = true,\n fillHeight = false,\n}: ImplProps) {\n const isHorizontal = layout === 'horizontal'\n const chartHeight = isHorizontal ? Math.max(200, data.length * 28) : 200\n const getBarColor = (idx: number): string => resolveChartColor(colors?.[idx], idx)\n\n return (\n <ResponsiveContainer width=\"100%\" height={fillHeight ? '100%' : chartHeight}>\n <RechartsBarChart\n data={data}\n layout={isHorizontal ? 'vertical' : 'horizontal'}\n margin={{ top: 5, right: 30, left: 20, bottom: 5 }}\n accessibilityLayer={accessibilityLayer}\n >\n {showGridLines && (\n <CartesianGrid strokeDasharray=\"3 3\" stroke=\"hsl(var(--border))\" />\n )}\n <XAxis\n type={isHorizontal ? 'number' : 'category'}\n dataKey={isHorizontal ? undefined : index}\n tickFormatter={isHorizontal ? valueFormatter : undefined}\n tick={{ fontSize: 11 }}\n />\n <YAxis\n type={isHorizontal ? 'category' : 'number'}\n dataKey={isHorizontal ? index : undefined}\n tickFormatter={isHorizontal ? undefined : valueFormatter}\n width={isHorizontal ? 90 : 50}\n interval={0}\n tick={{ fontSize: 10 }}\n />\n <Tooltip\n content={\n <ChartTooltipContent\n valueFormatter={valueFormatter}\n categoryLabels={categoryLabels}\n labelFormatter={(label, payload) => {\n const entry = payload?.[0] as { payload?: BarChartDataItem } | undefined\n const item = entry?.payload\n return item?.[index] ? String(item[index]) : label\n }}\n />\n }\n cursor={{ fill: 'hsl(var(--muted))', opacity: 0.2 }}\n />\n {showLegend && categories.length > 1 && (\n <Legend verticalAlign=\"top\" height={36} />\n )}\n {categories.map((category, idx) => (\n <Bar\n key={category}\n dataKey={category}\n fill={getBarColor(idx)}\n radius={isHorizontal ? [0, 4, 4, 0] : [4, 4, 0, 0]}\n isAnimationActive={animate}\n />\n ))}\n </RechartsBarChart>\n </ResponsiveContainer>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAuDM,SAOI,KAPJ;AApDN;AAAA,EACE,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB,yBAAyB;AAsBxC,SAAR,aAA8B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB;A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AAA,QACpD;AAAA,QACC,cAAc,WAAW,SAAS,KACjC,oBAAC,UAAO,eAAc,OAAM,QAAQ,IAAI;AAAA,QAEzC,WAAW,IAAI,CAAC,UAAU,QACzB;AAAA,UAAC;AAAA;AAAA,YAEC,SAAS;AAAA,YACT,MAAM,YAAY,GAAG;AAAA,YACrB,QAAQ,eAAe,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;AAAA,YACjD,mBAAmB;AAAA;AAAA,UAJd;AAAA,QAKP,CACD;AAAA;AAAA;AAAA,EACH,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -115,10 +115,16 @@ const NAMED_COLORS = {
|
|
|
115
115
|
function getChartColor(index) {
|
|
116
116
|
return CHART_COLORS[index % CHART_COLORS.length];
|
|
117
117
|
}
|
|
118
|
+
function isRawCssColor(color) {
|
|
119
|
+
return color.startsWith("#") || color.startsWith("var(") || /^(rgb|hsl|oklch|oklab|color)\(/.test(color);
|
|
120
|
+
}
|
|
118
121
|
function resolveChartColor(color, index) {
|
|
119
122
|
if (color && NAMED_COLORS[color]) {
|
|
120
123
|
return NAMED_COLORS[color];
|
|
121
124
|
}
|
|
125
|
+
if (color && isRawCssColor(color)) {
|
|
126
|
+
return color;
|
|
127
|
+
}
|
|
122
128
|
return CHART_COLORS[index % CHART_COLORS.length];
|
|
123
129
|
}
|
|
124
130
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/charts/ChartUtils.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { createContext, useContext } from 'react'\n\nexport type ChartConfig = {\n [key: string]: {\n label?: string\n color?: string\n }\n}\n\ntype ChartContextProps = {\n config: ChartConfig\n}\n\nconst ChartContext = createContext<ChartContextProps | null>(null)\n\nexport function useChart() {\n const context = useContext(ChartContext)\n if (!context) {\n throw new Error('useChart must be used within a ChartContainer')\n }\n return context\n}\n\ninterface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {\n config: ChartConfig\n children: React.ReactNode\n}\n\nexport function ChartContainer({\n config,\n children,\n className,\n ...props\n}: ChartContainerProps) {\n const configId = React.useId()\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-chart={configId}\n className={className}\n {...props}\n style={\n {\n ...props.style,\n '--color-chart-1': 'var(--chart-1)',\n '--color-chart-2': 'var(--chart-2)',\n '--color-chart-3': 'var(--chart-3)',\n '--color-chart-4': 'var(--chart-4)',\n '--color-chart-5': 'var(--chart-5)',\n ...Object.entries(config).reduce(\n (acc, [key, value]) => {\n if (value.color) {\n acc[`--color-${key}`] = value.color\n }\n return acc\n },\n {} as Record<string, string>\n ),\n } as React.CSSProperties\n }\n >\n {children}\n </div>\n </ChartContext.Provider>\n )\n}\n\ninterface ChartTooltipContentProps {\n active?: boolean\n payload?: Array<{\n name: string\n value: number\n color?: string\n dataKey?: string\n payload?: Record<string, unknown>\n }>\n label?: string\n labelFormatter?: (label: string, payload: unknown[]) => React.ReactNode\n valueFormatter?: (value: number) => string\n hideLabel?: boolean\n indicator?: 'line' | 'dot' | 'dashed'\n nameKey?: string\n categoryLabels?: Record<string, string>\n}\n\nexport function ChartTooltipContent({\n active,\n payload,\n label,\n labelFormatter,\n valueFormatter = (value) => value.toLocaleString(),\n hideLabel = false,\n indicator = 'dot',\n nameKey,\n categoryLabels,\n}: ChartTooltipContentProps) {\n if (!active || !payload?.length) {\n return null\n }\n\n return (\n <div className=\"rounded-lg border bg-popover px-3 py-2 text-popover-foreground shadow-md\">\n {!hideLabel && label && (\n <div className=\"mb-1 text-sm font-medium\">\n {labelFormatter ? labelFormatter(label, payload) : label}\n </div>\n )}\n <div className=\"flex flex-col gap-1\">\n {payload.map((item, index) => {\n const rawName = nameKey && item.payload ? String(item.payload[nameKey]) : item.name\n const name = categoryLabels?.[rawName] ?? rawName\n return (\n <div key={index} className=\"flex items-center justify-between gap-8\">\n <div className=\"flex items-center gap-2\">\n {indicator === 'dot' && (\n <span\n className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n style={{ backgroundColor: item.color }}\n />\n )}\n {indicator === 'line' && (\n <span\n className=\"h-0.5 w-3 shrink-0 rounded-full\"\n style={{ backgroundColor: item.color }}\n />\n )}\n {indicator === 'dashed' && (\n <span\n className=\"h-0.5 w-3 shrink-0 rounded-full border-t-2 border-dashed\"\n style={{ borderColor: item.color }}\n />\n )}\n <span className=\"text-sm text-muted-foreground\">{name}</span>\n </div>\n <span className=\"text-sm font-medium tabular-nums\">\n {valueFormatter(item.value)}\n </span>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n\nexport const CHART_COLORS = [\n 'var(--chart-1)',\n 'var(--chart-2)',\n 'var(--chart-3)',\n 'var(--chart-4)',\n 'var(--chart-5)',\n] as const\n\nexport const NAMED_COLORS: Record<string, string> = {\n blue: 'var(--chart-blue)',\n emerald: 'var(--chart-emerald)',\n amber: 'var(--chart-amber)',\n rose: 'var(--chart-rose)',\n violet: 'var(--chart-violet)',\n cyan: 'var(--chart-cyan)',\n indigo: 'var(--chart-indigo)',\n pink: 'var(--chart-pink)',\n teal: 'var(--chart-teal)',\n orange: 'var(--chart-orange)',\n}\n\nexport function getChartColor(index: number): string {\n return CHART_COLORS[index % CHART_COLORS.length]\n}\n\nexport function resolveChartColor(color: string | undefined, index: number): string {\n if (color && NAMED_COLORS[color]) {\n return NAMED_COLORS[color]\n }\n return CHART_COLORS[index % CHART_COLORS.length]\n}\n"],
|
|
5
|
-
"mappings": ";AAyCM,cA4EQ,YA5ER;AAvCN,YAAY,WAAW;AACvB,SAAS,eAAe,kBAAkB;AAa1C,MAAM,eAAe,cAAwC,IAAI;AAE1D,SAAS,WAAW;AACzB,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;AAOO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SAAgB,WAAU,2CACzB;AAAA,6BAAC,SAAI,WAAU,2BACZ;AAAA,wBAAc,SACb;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,OAAO,EAAE,iBAAiB,KAAK,MAAM;AAAA;AAAA,UACvC;AAAA,UAED,cAAc,UACb;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,OAAO,EAAE,iBAAiB,KAAK,MAAM;AAAA;AAAA,UACvC;AAAA,UAED,cAAc,YACb;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,OAAO,EAAE,aAAa,KAAK,MAAM;AAAA;AAAA,UACnC;AAAA,UAEF,oBAAC,UAAK,WAAU,iCAAiC,gBAAK;AAAA,WACxD;AAAA,QACA,oBAAC,UAAK,WAAU,oCACb,yBAAe,KAAK,KAAK,GAC5B;AAAA,WAxBQ,KAyBV;AAAA,IAEJ,CAAC,GACH;AAAA,KACF;AAEJ;AAEO,MAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,eAAuC;AAAA,EAClD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AACV;AAEO,SAAS,cAAc,OAAuB;AACnD,SAAO,aAAa,QAAQ,aAAa,MAAM;AACjD;AAEO,SAAS,kBAAkB,OAA2B,OAAuB;AAClF,MAAI,SAAS,aAAa,KAAK,GAAG;AAChC,WAAO,aAAa,KAAK;AAAA,EAC3B;AACA,SAAO,aAAa,QAAQ,aAAa,MAAM;AACjD;",
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { createContext, useContext } from 'react'\n\nexport type ChartConfig = {\n [key: string]: {\n label?: string\n color?: string\n }\n}\n\ntype ChartContextProps = {\n config: ChartConfig\n}\n\nconst ChartContext = createContext<ChartContextProps | null>(null)\n\nexport function useChart() {\n const context = useContext(ChartContext)\n if (!context) {\n throw new Error('useChart must be used within a ChartContainer')\n }\n return context\n}\n\ninterface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {\n config: ChartConfig\n children: React.ReactNode\n}\n\nexport function ChartContainer({\n config,\n children,\n className,\n ...props\n}: ChartContainerProps) {\n const configId = React.useId()\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-chart={configId}\n className={className}\n {...props}\n style={\n {\n ...props.style,\n '--color-chart-1': 'var(--chart-1)',\n '--color-chart-2': 'var(--chart-2)',\n '--color-chart-3': 'var(--chart-3)',\n '--color-chart-4': 'var(--chart-4)',\n '--color-chart-5': 'var(--chart-5)',\n ...Object.entries(config).reduce(\n (acc, [key, value]) => {\n if (value.color) {\n acc[`--color-${key}`] = value.color\n }\n return acc\n },\n {} as Record<string, string>\n ),\n } as React.CSSProperties\n }\n >\n {children}\n </div>\n </ChartContext.Provider>\n )\n}\n\ninterface ChartTooltipContentProps {\n active?: boolean\n payload?: Array<{\n name: string\n value: number\n color?: string\n dataKey?: string\n payload?: Record<string, unknown>\n }>\n label?: string\n labelFormatter?: (label: string, payload: unknown[]) => React.ReactNode\n valueFormatter?: (value: number) => string\n hideLabel?: boolean\n indicator?: 'line' | 'dot' | 'dashed'\n nameKey?: string\n categoryLabels?: Record<string, string>\n}\n\nexport function ChartTooltipContent({\n active,\n payload,\n label,\n labelFormatter,\n valueFormatter = (value) => value.toLocaleString(),\n hideLabel = false,\n indicator = 'dot',\n nameKey,\n categoryLabels,\n}: ChartTooltipContentProps) {\n if (!active || !payload?.length) {\n return null\n }\n\n return (\n <div className=\"rounded-lg border bg-popover px-3 py-2 text-popover-foreground shadow-md\">\n {!hideLabel && label && (\n <div className=\"mb-1 text-sm font-medium\">\n {labelFormatter ? labelFormatter(label, payload) : label}\n </div>\n )}\n <div className=\"flex flex-col gap-1\">\n {payload.map((item, index) => {\n const rawName = nameKey && item.payload ? String(item.payload[nameKey]) : item.name\n const name = categoryLabels?.[rawName] ?? rawName\n return (\n <div key={index} className=\"flex items-center justify-between gap-8\">\n <div className=\"flex items-center gap-2\">\n {indicator === 'dot' && (\n <span\n className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n style={{ backgroundColor: item.color }}\n />\n )}\n {indicator === 'line' && (\n <span\n className=\"h-0.5 w-3 shrink-0 rounded-full\"\n style={{ backgroundColor: item.color }}\n />\n )}\n {indicator === 'dashed' && (\n <span\n className=\"h-0.5 w-3 shrink-0 rounded-full border-t-2 border-dashed\"\n style={{ borderColor: item.color }}\n />\n )}\n <span className=\"text-sm text-muted-foreground\">{name}</span>\n </div>\n <span className=\"text-sm font-medium tabular-nums\">\n {valueFormatter(item.value)}\n </span>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n\nexport const CHART_COLORS = [\n 'var(--chart-1)',\n 'var(--chart-2)',\n 'var(--chart-3)',\n 'var(--chart-4)',\n 'var(--chart-5)',\n] as const\n\nexport const NAMED_COLORS: Record<string, string> = {\n blue: 'var(--chart-blue)',\n emerald: 'var(--chart-emerald)',\n amber: 'var(--chart-amber)',\n rose: 'var(--chart-rose)',\n violet: 'var(--chart-violet)',\n cyan: 'var(--chart-cyan)',\n indigo: 'var(--chart-indigo)',\n pink: 'var(--chart-pink)',\n teal: 'var(--chart-teal)',\n orange: 'var(--chart-orange)',\n}\n\nexport function getChartColor(index: number): string {\n return CHART_COLORS[index % CHART_COLORS.length]\n}\n\nfunction isRawCssColor(color: string): boolean {\n return color.startsWith('#') || color.startsWith('var(') || /^(rgb|hsl|oklch|oklab|color)\\(/.test(color)\n}\n\nexport function resolveChartColor(color: string | undefined, index: number): string {\n if (color && NAMED_COLORS[color]) {\n return NAMED_COLORS[color]\n }\n if (color && isRawCssColor(color)) {\n return color\n }\n return CHART_COLORS[index % CHART_COLORS.length]\n}\n"],
|
|
5
|
+
"mappings": ";AAyCM,cA4EQ,YA5ER;AAvCN,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iC,KAAK,KAAK;AACzG;AAEO,SAAS,kBAAkB,OAA2B,OAAuB;AAClF,MAAI,SAAS,aAAa,KAAK,GAAG;AAChC,WAAO,aAAa,KAAK;AAAA,EAC3B;AACA,MAAI,SAAS,cAAc,KAAK,GAAG;AACjC,WAAO;AAAA,EACT;AACA,SAAO,aAAa,QAAQ,aAAa,MAAM;AACjD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -31,29 +31,36 @@ function LineChart({
|
|
|
31
31
|
connectNulls = true,
|
|
32
32
|
className = "",
|
|
33
33
|
emptyMessage = "No data available",
|
|
34
|
-
categoryLabels
|
|
34
|
+
categoryLabels,
|
|
35
|
+
bare = false,
|
|
36
|
+
heightClassName = "h-52",
|
|
37
|
+
animate = true,
|
|
38
|
+
areaOpacity = 0.2,
|
|
39
|
+
accessibilityLayer = true
|
|
35
40
|
}) {
|
|
41
|
+
const wrapperClassName = bare ? className : `rounded-lg border bg-card p-4 ${className}`;
|
|
42
|
+
const stateClassName = bare ? `flex items-center justify-center ${heightClassName}` : "flex h-48 items-center justify-center";
|
|
36
43
|
if (error) {
|
|
37
|
-
return /* @__PURE__ */ jsxs("div", { className:
|
|
38
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
39
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
44
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClassName, children: [
|
|
45
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
46
|
+
/* @__PURE__ */ jsx("div", { className: stateClassName, children: /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }) })
|
|
40
47
|
] });
|
|
41
48
|
}
|
|
42
49
|
if (loading) {
|
|
43
|
-
return /* @__PURE__ */ jsxs("div", { className:
|
|
44
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
45
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
50
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClassName, children: [
|
|
51
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
52
|
+
/* @__PURE__ */ jsx("div", { className: stateClassName, children: /* @__PURE__ */ jsx(Spinner, { className: "h-6 w-6 text-muted-foreground" }) })
|
|
46
53
|
] });
|
|
47
54
|
}
|
|
48
55
|
if (!data || data.length === 0) {
|
|
49
|
-
return /* @__PURE__ */ jsxs("div", { className:
|
|
50
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
51
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
56
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClassName, children: [
|
|
57
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
58
|
+
/* @__PURE__ */ jsx("div", { className: stateClassName, children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: emptyMessage }) })
|
|
52
59
|
] });
|
|
53
60
|
}
|
|
54
|
-
return /* @__PURE__ */ jsxs("div", { className:
|
|
55
|
-
title && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
56
|
-
/* @__PURE__ */ jsx("div", { className:
|
|
61
|
+
return /* @__PURE__ */ jsxs("div", { className: wrapperClassName, children: [
|
|
62
|
+
title && !bare && /* @__PURE__ */ jsx("h3", { className: "mb-4 text-base font-medium text-card-foreground", children: title }),
|
|
63
|
+
/* @__PURE__ */ jsx("div", { className: `${heightClassName} w-full`, children: /* @__PURE__ */ jsx(
|
|
57
64
|
LineChartImpl,
|
|
58
65
|
{
|
|
59
66
|
data,
|
|
@@ -66,7 +73,10 @@ function LineChart({
|
|
|
66
73
|
showGridLines,
|
|
67
74
|
curveType,
|
|
68
75
|
connectNulls,
|
|
69
|
-
categoryLabels
|
|
76
|
+
categoryLabels,
|
|
77
|
+
animate,
|
|
78
|
+
areaOpacity,
|
|
79
|
+
accessibilityLayer
|
|
70
80
|
}
|
|
71
81
|
) })
|
|
72
82
|
] });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/charts/LineChart.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport type LineChartDataItem = Record<string, string | number | null | undefined>\n\nexport type LineChartProps = {\n title?: string\n data: LineChartDataItem[]\n index: string\n categories: string[]\n loading?: boolean\n error?: string | null\n colors?: string[]\n showArea?: boolean\n valueFormatter?: (value: number) => string\n showLegend?: boolean\n showGridLines?: boolean\n curveType?: 'linear' | 'natural' | 'monotone' | 'step'\n connectNulls?: boolean\n className?: string\n emptyMessage?: string\n categoryLabels?: Record<string, string>\n}\n\nfunction defaultValueFormatter(value: number): string {\n if (Math.abs(value) >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(1)}M`\n }\n if (Math.abs(value) >= 1_000) {\n return `${(value / 1_000).toFixed(1)}K`\n }\n return value.toLocaleString(undefined, { maximumFractionDigits: 2 })\n}\n\nconst LineChartImpl = dynamic(() => import('./LineChartImpl'), {\n ssr: false,\n loading: () => (\n <div className=\"flex h-48 items-center justify-center\">\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n ),\n})\n\nexport function LineChart({\n title,\n data,\n index,\n categories,\n loading,\n error,\n colors,\n showArea = false,\n valueFormatter = defaultValueFormatter,\n showLegend = true,\n showGridLines = true,\n curveType = 'monotone',\n connectNulls = true,\n className = '',\n emptyMessage = 'No data available',\n categoryLabels,\n}: LineChartProps) {\n
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport type LineChartDataItem = Record<string, string | number | null | undefined>\n\nexport type LineChartProps = {\n title?: string\n data: LineChartDataItem[]\n index: string\n categories: string[]\n loading?: boolean\n error?: string | null\n colors?: string[]\n showArea?: boolean\n valueFormatter?: (value: number) => string\n showLegend?: boolean\n showGridLines?: boolean\n curveType?: 'linear' | 'natural' | 'monotone' | 'step'\n connectNulls?: boolean\n className?: string\n emptyMessage?: string\n categoryLabels?: Record<string, string>\n /** Render only the plot (no card border, padding or title) so a host card can own the chrome. */\n bare?: boolean\n /** Height utility for the plot area; defaults to `h-52`. */\n heightClassName?: string\n /** Recharts draw-in animation; pass false for charts that re-render on interaction. */\n animate?: boolean\n /** Fill opacity of the area under each line when `showArea` is on; defaults to 0.2. */\n areaOpacity?: number\n /** Recharts keyboard/focus layer; pass false for decorative charts so the plot never takes focus. */\n accessibilityLayer?: boolean\n}\n\nfunction defaultValueFormatter(value: number): string {\n if (Math.abs(value) >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(1)}M`\n }\n if (Math.abs(value) >= 1_000) {\n return `${(value / 1_000).toFixed(1)}K`\n }\n return value.toLocaleString(undefined, { maximumFractionDigits: 2 })\n}\n\nconst LineChartImpl = dynamic(() => import('./LineChartImpl'), {\n ssr: false,\n loading: () => (\n <div className=\"flex h-48 items-center justify-center\">\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n ),\n})\n\nexport function LineChart({\n title,\n data,\n index,\n categories,\n loading,\n error,\n colors,\n showArea = false,\n valueFormatter = defaultValueFormatter,\n showLegend = true,\n showGridLines = true,\n curveType = 'monotone',\n connectNulls = true,\n className = '',\n emptyMessage = 'No data available',\n categoryLabels,\n bare = false,\n heightClassName = 'h-52',\n animate = true,\n areaOpacity = 0.2,\n accessibilityLayer = true,\n}: LineChartProps) {\n const wrapperClassName = bare ? className : `rounded-lg border bg-card p-4 ${className}`\n const stateClassName = bare ? `flex items-center justify-center ${heightClassName}` : 'flex h-48 items-center justify-center'\n if (error) {\n return (\n <div className={wrapperClassName}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={stateClassName}>\n <p className=\"text-sm text-destructive\">{error}</p>\n </div>\n </div>\n )\n }\n\n if (loading) {\n return (\n <div className={wrapperClassName}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={stateClassName}>\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n </div>\n )\n }\n\n if (!data || data.length === 0) {\n return (\n <div className={wrapperClassName}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={stateClassName}>\n <p className=\"text-sm text-muted-foreground\">{emptyMessage}</p>\n </div>\n </div>\n )\n }\n\n return (\n <div className={wrapperClassName}>\n {title && !bare && <h3 className=\"mb-4 text-base font-medium text-card-foreground\">{title}</h3>}\n <div className={`${heightClassName} w-full`}>\n <LineChartImpl\n data={data}\n index={index}\n categories={categories}\n colors={colors}\n showArea={showArea}\n valueFormatter={valueFormatter}\n showLegend={showLegend}\n showGridLines={showGridLines}\n curveType={curveType}\n connectNulls={connectNulls}\n categoryLabels={categoryLabels}\n animate={animate}\n areaOpacity={areaOpacity}\n accessibilityLayer={accessibilityLayer}\n />\n </div>\n </div>\n )\n}\n\nexport default LineChart\n"],
|
|
5
|
+
"mappings": ";AAmDM,cAgCA,YAhCA;AAhDN,OAAO,aAAa;AACpB,SAAS,eAAe;AAiCxB,SAAS,sBAAsB,OAAuB;AACpD,MAAI,KAAK,IAAI,KAAK,KAAK,KAAW;AAChC,WAAO,IAAI,QAAQ,KAAW,QAAQ,CAAC,CAAC;AAAA,EAC1C;AACA,MAAI,KAAK,IAAI,KAAK,KAAK,KAAO;AAC5B,WAAO,IAAI,QAAQ,KAAO,QAAQ,CAAC,CAAC;AAAA,EACtC;AACA,SAAO,MAAM,eAAe,QAAW,EAAE,uBAA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WAAW,gBACd,8BAAC,OAAE,WAAU,iCAAiC,wBAAa,GAC7D;AAAA,OACF;AAAA,EAEJ;AAEA,SACE,qBAAC,SAAI,WAAW,kBACb;AAAA,aAAS,CAAC,QAAQ,oBAAC,QAAG,WAAU,mDAAmD,iBAAM;AAAA,IAC1F,oBAAC,SAAI,WAAW,GAAG,eAAe,WAChC;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF,GACF;AAAA,KACF;AAEJ;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,7 +24,10 @@ function LineChartImpl({
|
|
|
24
24
|
showGridLines = true,
|
|
25
25
|
curveType = "monotone",
|
|
26
26
|
connectNulls = true,
|
|
27
|
-
categoryLabels
|
|
27
|
+
categoryLabels,
|
|
28
|
+
animate = true,
|
|
29
|
+
areaOpacity = 0.2,
|
|
30
|
+
accessibilityLayer = true
|
|
28
31
|
}) {
|
|
29
32
|
const getLineColor = (idx) => resolveChartColor(colors?.[idx], idx);
|
|
30
33
|
const ChartComponent = showArea ? RechartsAreaChart : RechartsLineChart;
|
|
@@ -33,6 +36,7 @@ function LineChartImpl({
|
|
|
33
36
|
{
|
|
34
37
|
data,
|
|
35
38
|
margin: { top: 5, right: 10, left: 10, bottom: 5 },
|
|
39
|
+
accessibilityLayer,
|
|
36
40
|
children: [
|
|
37
41
|
showGridLines && /* @__PURE__ */ jsx(
|
|
38
42
|
CartesianGrid,
|
|
@@ -82,9 +86,10 @@ function LineChartImpl({
|
|
|
82
86
|
dataKey: category,
|
|
83
87
|
stroke: getLineColor(idx),
|
|
84
88
|
fill: getLineColor(idx),
|
|
85
|
-
fillOpacity:
|
|
89
|
+
fillOpacity: areaOpacity,
|
|
86
90
|
strokeWidth: 2,
|
|
87
91
|
connectNulls,
|
|
92
|
+
isAnimationActive: animate,
|
|
88
93
|
dot: false,
|
|
89
94
|
activeDot: { r: 4, strokeWidth: 0 }
|
|
90
95
|
},
|
|
@@ -97,6 +102,7 @@ function LineChartImpl({
|
|
|
97
102
|
stroke: getLineColor(idx),
|
|
98
103
|
strokeWidth: 2,
|
|
99
104
|
connectNulls,
|
|
105
|
+
isAnimationActive: animate,
|
|
100
106
|
dot: false,
|
|
101
107
|
activeDot: { r: 4, strokeWidth: 0 }
|
|
102
108
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/charts/LineChartImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport {\n LineChart as RechartsLineChart,\n AreaChart as RechartsAreaChart,\n Line,\n Area,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n ResponsiveContainer,\n Legend,\n} from 'recharts'\nimport { ChartTooltipContent, resolveChartColor } from './ChartUtils'\nimport type { LineChartProps } from './LineChart'\n\ntype ImplProps = Pick<\n LineChartProps,\n | 'data'\n | 'index'\n | 'categories'\n | 'colors'\n | 'showArea'\n | 'valueFormatter'\n | 'showLegend'\n | 'showGridLines'\n | 'curveType'\n | 'connectNulls'\n | 'categoryLabels'\n> & {\n valueFormatter: (value: number) => string\n}\n\nexport default function LineChartImpl({\n data,\n index,\n categories,\n colors,\n showArea = false,\n valueFormatter,\n showLegend = true,\n showGridLines = true,\n curveType = 'monotone',\n connectNulls = true,\n categoryLabels,\n}: ImplProps) {\n const getLineColor = (idx: number): string => resolveChartColor(colors?.[idx], idx)\n const ChartComponent = showArea ? RechartsAreaChart : RechartsLineChart\n\n return (\n <ResponsiveContainer width=\"100%\" height=\"100%\">\n <ChartComponent\n data={data}\n margin={{ top: 5, right: 10, left: 10, bottom: 5 }}\n >\n {showGridLines && (\n <CartesianGrid\n strokeDasharray=\"3 3\"\n stroke=\"hsl(var(--border))\"\n />\n )}\n <XAxis\n dataKey={index}\n tick={{ fontSize: 12 }}\n tickLine={false}\n axisLine={false}\n />\n <YAxis\n tickFormatter={valueFormatter}\n tick={{ fontSize: 12 }}\n tickLine={false}\n axisLine={false}\n width={56}\n />\n <Tooltip\n content={<ChartTooltipContent valueFormatter={valueFormatter} categoryLabels={categoryLabels} />}\n cursor={{ stroke: 'hsl(var(--muted-foreground))', strokeDasharray: '3 3' }}\n />\n {showLegend && categories.length > 1 && (\n <Legend\n verticalAlign=\"top\"\n height={36}\n formatter={(value) => (\n <span style={{ color: 'hsl(var(--muted-foreground))', fontSize: '12px' }}>{value}</span>\n )}\n />\n )}\n {showArea\n ? categories.map((category, idx) => (\n <Area\n key={category}\n type={curveType}\n dataKey={category}\n stroke={getLineColor(idx)}\n fill={getLineColor(idx)}\n fillOpacity={
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport {\n LineChart as RechartsLineChart,\n AreaChart as RechartsAreaChart,\n Line,\n Area,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n ResponsiveContainer,\n Legend,\n} from 'recharts'\nimport { ChartTooltipContent, resolveChartColor } from './ChartUtils'\nimport type { LineChartProps } from './LineChart'\n\ntype ImplProps = Pick<\n LineChartProps,\n | 'data'\n | 'index'\n | 'categories'\n | 'colors'\n | 'showArea'\n | 'valueFormatter'\n | 'showLegend'\n | 'showGridLines'\n | 'curveType'\n | 'connectNulls'\n | 'categoryLabels'\n | 'animate'\n | 'areaOpacity'\n | 'accessibilityLayer'\n> & {\n valueFormatter: (value: number) => string\n}\n\nexport default function LineChartImpl({\n data,\n index,\n categories,\n colors,\n showArea = false,\n valueFormatter,\n showLegend = true,\n showGridLines = true,\n curveType = 'monotone',\n connectNulls = true,\n categoryLabels,\n animate = true,\n areaOpacity = 0.2,\n accessibilityLayer = true,\n}: ImplProps) {\n const getLineColor = (idx: number): string => resolveChartColor(colors?.[idx], idx)\n const ChartComponent = showArea ? RechartsAreaChart : RechartsLineChart\n\n return (\n <ResponsiveContainer width=\"100%\" height=\"100%\">\n <ChartComponent\n data={data}\n margin={{ top: 5, right: 10, left: 10, bottom: 5 }}\n accessibilityLayer={accessibilityLayer}\n >\n {showGridLines && (\n <CartesianGrid\n strokeDasharray=\"3 3\"\n stroke=\"hsl(var(--border))\"\n />\n )}\n <XAxis\n dataKey={index}\n tick={{ fontSize: 12 }}\n tickLine={false}\n axisLine={false}\n />\n <YAxis\n tickFormatter={valueFormatter}\n tick={{ fontSize: 12 }}\n tickLine={false}\n axisLine={false}\n width={56}\n />\n <Tooltip\n content={<ChartTooltipContent valueFormatter={valueFormatter} categoryLabels={categoryLabels} />}\n cursor={{ stroke: 'hsl(var(--muted-foreground))', strokeDasharray: '3 3' }}\n />\n {showLegend && categories.length > 1 && (\n <Legend\n verticalAlign=\"top\"\n height={36}\n formatter={(value) => (\n <span style={{ color: 'hsl(var(--muted-foreground))', fontSize: '12px' }}>{value}</span>\n )}\n />\n )}\n {showArea\n ? categories.map((category, idx) => (\n <Area\n key={category}\n type={curveType}\n dataKey={category}\n stroke={getLineColor(idx)}\n fill={getLineColor(idx)}\n fillOpacity={areaOpacity}\n strokeWidth={2}\n connectNulls={connectNulls}\n isAnimationActive={animate}\n dot={false}\n activeDot={{ r: 4, strokeWidth: 0 }}\n />\n ))\n : categories.map((category, idx) => (\n <Line\n key={category}\n type={curveType}\n dataKey={category}\n stroke={getLineColor(idx)}\n strokeWidth={2}\n connectNulls={connectNulls}\n isAnimationActive={animate}\n dot={false}\n activeDot={{ r: 4, strokeWidth: 0 }}\n />\n ))}\n </ChartComponent>\n </ResponsiveContainer>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA2DM,SAMI,KANJ;AAxDN;AAAA,EACE,aAAa;AAAA,EACb,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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E,OAAO,gCAAgC,UAAU,OAAO,GAAI,iBAAM;AAAA;AAAA,QAErF;AAAA,QAED,WACG,WAAW,IAAI,CAAC,UAAU,QACxB;AAAA,UAAC;AAAA;AAAA,YAEC,MAAM;AAAA,YACN,SAAS;AAAA,YACT,QAAQ,aAAa,GAAG;AAAA,YACxB,MAAM,aAAa,GAAG;AAAA,YACtB,aAAa;AAAA,YACb,aAAa;AAAA,YACb;AAAA,YACA,mBAAmB;AAAA,YACnB,KAAK;AAAA,YACL,WAAW,EAAE,GAAG,GAAG,aAAa,EAAE;AAAA;AAAA,UAV7B;AAAA,QAWP,CACD,IACD,WAAW,IAAI,CAAC,UAAU,QACxB;AAAA,UAAC;AAAA;AAAA,YAEC,MAAM;AAAA,YACN,SAAS;AAAA,YACT,QAAQ,aAAa,GAAG;AAAA,YACxB,aAAa;AAAA,YACb;AAAA,YACA,mBAAmB;AAAA,YACnB,KAAK;AAAA,YACL,WAAW,EAAE,GAAG,GAAG,aAAa,EAAE;AAAA;AAAA,UAR7B;AAAA,QASP,CACD;AAAA;AAAA;AAAA,EACP,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,9 +4,11 @@ import * as React from "react";
|
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
6
|
import { Button } from "@open-mercato/ui/primitives/button";
|
|
7
|
+
import { DialogFooter, DialogHeader } from "@open-mercato/ui/primitives/dialog";
|
|
7
8
|
import { IconButton } from "../../primitives/icon-button.js";
|
|
8
9
|
import { cn } from "@open-mercato/shared/lib/utils";
|
|
9
|
-
import { Loader2, X } from "lucide-react";
|
|
10
|
+
import { CircleHelp, Loader2, TriangleAlert, X } from "lucide-react";
|
|
11
|
+
const FOOTER_ACTION_CLASS_NAME = "h-auto min-h-9 whitespace-normal py-1.5 text-center";
|
|
10
12
|
function ConfirmDialog({
|
|
11
13
|
open: controlledOpen,
|
|
12
14
|
onOpenChange,
|
|
@@ -149,7 +151,7 @@ function ConfirmDialog({
|
|
|
149
151
|
// Mobile: bottom sheet
|
|
150
152
|
"fixed inset-x-0 bottom-0 top-auto w-full",
|
|
151
153
|
// Desktop: centered
|
|
152
|
-
"sm:inset-auto sm:mx-auto sm:my-auto sm:max-w-
|
|
154
|
+
"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",
|
|
153
155
|
// Animation with reduced motion support
|
|
154
156
|
"motion-safe:open:animate-in motion-safe:open:fade-in-0 motion-safe:open:slide-in-from-bottom-4",
|
|
155
157
|
"sm:motion-safe:open:slide-in-from-bottom-0 sm:motion-safe:open:zoom-in-95",
|
|
@@ -161,11 +163,9 @@ function ConfirmDialog({
|
|
|
161
163
|
{
|
|
162
164
|
role: "document",
|
|
163
165
|
className: cn(
|
|
164
|
-
//
|
|
165
|
-
"flex flex-col gap-4 rounded-t-
|
|
166
|
-
"sm:rounded-xl sm:border"
|
|
167
|
-
// Relative positioning for close button
|
|
168
|
-
"relative"
|
|
166
|
+
// Same shell as DialogContent: card surface, p-6, sheet on mobile, card on desktop
|
|
167
|
+
"relative flex flex-col gap-4 rounded-t-xl border-t bg-card p-6 text-foreground shadow-lg",
|
|
168
|
+
"sm:rounded-xl sm:border"
|
|
169
169
|
),
|
|
170
170
|
children: [
|
|
171
171
|
/* @__PURE__ */ jsx(
|
|
@@ -181,27 +181,19 @@ function ConfirmDialog({
|
|
|
181
181
|
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
182
182
|
}
|
|
183
183
|
),
|
|
184
|
-
/* @__PURE__ */
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
id: titleId,
|
|
188
|
-
className: cn(
|
|
189
|
-
"text-sm font-medium leading-snug tracking-tight pr-6",
|
|
190
|
-
// Mobile: centered, Desktop: left-aligned
|
|
191
|
-
"text-center sm:text-left"
|
|
192
|
-
),
|
|
193
|
-
children: resolvedTitle
|
|
194
|
-
}
|
|
195
|
-
),
|
|
196
|
-
text && /* @__PURE__ */ jsx(
|
|
197
|
-
"p",
|
|
184
|
+
/* @__PURE__ */ jsxs(
|
|
185
|
+
DialogHeader,
|
|
198
186
|
{
|
|
199
|
-
|
|
200
|
-
className: "
|
|
201
|
-
|
|
187
|
+
className: "pr-6",
|
|
188
|
+
leading: variant === "default" ? /* @__PURE__ */ jsx(CircleHelp, { className: "size-4", "aria-hidden": true }) : /* @__PURE__ */ jsx(TriangleAlert, { className: "size-4", "aria-hidden": true }),
|
|
189
|
+
leadingTone: variant === "destructive" ? "error" : variant === "warning" ? "warning" : "default",
|
|
190
|
+
children: [
|
|
191
|
+
/* @__PURE__ */ jsx("h2", { id: titleId, className: "text-lg font-semibold leading-none tracking-tight", children: resolvedTitle }),
|
|
192
|
+
text ? /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-sm text-muted-foreground", children: text }) : null
|
|
193
|
+
]
|
|
202
194
|
}
|
|
203
195
|
),
|
|
204
|
-
/* @__PURE__ */ jsxs("
|
|
196
|
+
/* @__PURE__ */ jsxs(DialogFooter, { layout: "equal", className: "flex-col-reverse sm:flex-row", children: [
|
|
205
197
|
resolvedCancelText !== false && /* @__PURE__ */ jsx(
|
|
206
198
|
Button,
|
|
207
199
|
{
|
|
@@ -209,7 +201,7 @@ function ConfirmDialog({
|
|
|
209
201
|
variant: "outline",
|
|
210
202
|
onClick: handleCancel,
|
|
211
203
|
disabled: loading,
|
|
212
|
-
className:
|
|
204
|
+
className: FOOTER_ACTION_CLASS_NAME,
|
|
213
205
|
children: resolvedCancelText
|
|
214
206
|
}
|
|
215
207
|
),
|
|
@@ -220,7 +212,7 @@ function ConfirmDialog({
|
|
|
220
212
|
variant: variant === "destructive" ? "destructive-solid" : "default",
|
|
221
213
|
onClick: handleConfirm,
|
|
222
214
|
disabled: loading,
|
|
223
|
-
className:
|
|
215
|
+
className: FOOTER_ACTION_CLASS_NAME,
|
|
224
216
|
children: [
|
|
225
217
|
loading && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }),
|
|
226
218
|
resolvedConfirmText
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/confirm-dialog/ConfirmDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useT } from \"@open-mercato/shared/lib/i18n/context\";\nimport { Button } from \"@open-mercato/ui/primitives/button\";\nimport { IconButton } from \"../../primitives/icon-button\";\nimport { cn } from \"@open-mercato/shared/lib/utils\";\nimport { Loader2, X } from \"lucide-react\";\n\nexport type ConfirmDialogProps = {\n /** Whether the dialog is open (controlled mode \u2014 used by useConfirmDialog) */\n open?: boolean;\n /** Callback when open state changes (controlled mode) */\n onOpenChange?: (open: boolean) => void;\n /** Callback when user confirms */\n onConfirm: () => void | Promise<void>;\n /** Callback when user cancels (optional, defaults to closing) */\n onCancel?: () => void;\n /** Dialog title. Defaults to i18n key \"ui.dialogs.confirm.defaultTitle\" (\"Are you sure?\") */\n title?: string;\n /** Dialog body text / description */\n text?: string;\n /** Confirm button label. Defaults to i18n \"ui.dialogs.confirm.confirmText\" (\"Confirm\").\n * Pass `false` to hide the confirm button entirely. */\n confirmText?: string | false;\n /** Cancel button label. Defaults to i18n \"ui.dialogs.confirm.cancelText\" (\"Cancel\").\n * Pass `false` to hide the cancel button entirely. */\n cancelText?: string | false;\n /** Visual variant \u2014 \"destructive\" renders the confirm button in red */\n variant?: \"default\" | \"destructive\";\n /** Whether the confirm button shows a loading spinner.\n * Useful for async onConfirm handlers (e.g., waiting for API response before closing). */\n loading?: boolean;\n /** Trigger element \u2014 when provided, component manages its own open state (declarative mode).\n * Clicking the trigger opens the dialog. */\n trigger?: React.ReactNode;\n};\n\nexport function ConfirmDialog({\n open: controlledOpen,\n onOpenChange,\n onConfirm,\n onCancel,\n title,\n text,\n confirmText,\n cancelText,\n variant = \"default\",\n loading = false,\n trigger,\n}: ConfirmDialogProps) {\n const t = useT();\n const dialogRef = React.useRef<HTMLDialogElement>(null);\n const [internalOpen, setInternalOpen] = React.useState(false);\n const cancelButtonRef = React.useRef<HTMLButtonElement>(null);\n const confirmButtonRef = React.useRef<HTMLButtonElement>(null);\n const restoreAriaHiddenRef = React.useRef(false);\n const [portalTarget, setPortalTarget] = React.useState<HTMLElement | null>(null);\n // Unique IDs so multiple ConfirmDialog instances on the same page don't\n // collide and make `aria-labelledby` resolve to the wrong dialog's title.\n const reactId = React.useId();\n const titleId = `confirm-dialog-title-${reactId}`;\n const descriptionId = `confirm-dialog-description-${reactId}`;\n\n // Determine if we're in controlled mode (open prop provided) or declarative mode (trigger provided)\n const isControlled = controlledOpen !== undefined;\n const open = isControlled ? controlledOpen : internalOpen;\n const setOpen = isControlled\n ? onOpenChange || (() => {})\n : setInternalOpen;\n const handleCancelCallback = React.useCallback(() => {\n if (!isControlled) {\n onCancel?.();\n }\n }, [isControlled, onCancel]);\n\n // Default text values from i18n\n const resolvedTitle =\n title ?? t(\"ui.dialogs.confirm.defaultTitle\", \"Are you sure?\");\n const resolvedConfirmText =\n confirmText === false\n ? false\n : confirmText ?? t(\"ui.dialogs.confirm.confirmText\", \"Confirm\");\n const resolvedCancelText =\n cancelText === false\n ? false\n : cancelText ?? t(\"ui.dialogs.confirm.cancelText\", \"Cancel\");\n const closeAriaLabel = t(\"ui.dialog.close.ariaLabel\", \"Close\");\n const requestClose = React.useCallback(() => {\n setOpen(false);\n handleCancelCallback();\n }, [setOpen, handleCancelCallback]);\n\n React.useLayoutEffect(() => {\n setPortalTarget(document.body);\n }, []);\n\n // Handle dialog open/close with native showModal/close\n React.useLayoutEffect(() => {\n const dialog = dialogRef.current;\n if (!dialog) return;\n\n if (open) {\n if (!dialog.open) {\n dialog.showModal();\n // Focus cancel button (safe default) or confirm if no cancel\n setTimeout(() => {\n if (resolvedCancelText !== false && cancelButtonRef.current) {\n cancelButtonRef.current.focus();\n } else if (confirmButtonRef.current) {\n confirmButtonRef.current.focus();\n }\n }, 0);\n }\n // A modal opened underneath (e.g. a Radix Dialog) marks every sibling in\n // <body> `aria-hidden`, including this portalled element. Shown on top\n // of that modal it must stay reachable for assistive technology.\n if (dialog.getAttribute(\"aria-hidden\") === \"true\") {\n dialog.removeAttribute(\"aria-hidden\");\n restoreAriaHiddenRef.current = true;\n }\n } else {\n if (dialog.open) {\n dialog.close();\n }\n if (restoreAriaHiddenRef.current) {\n restoreAriaHiddenRef.current = false;\n // Hand the attribute back only while the modal that hid us is still\n // open; its own cleanup has otherwise already removed the marker.\n if (dialog.hasAttribute(\"data-aria-hidden\")) {\n dialog.setAttribute(\"aria-hidden\", \"true\");\n }\n }\n }\n }, [open, resolvedCancelText, portalTarget]);\n\n // Handle native cancel event (Escape key)\n React.useEffect(() => {\n const dialog = dialogRef.current;\n if (!dialog) return;\n\n const handleCancel = (e: Event) => {\n // Always prevent the native default action so the dialog's own\n // open/closed state is only ever driven by our `open`-state effect \u2014\n // otherwise the browser closes the <dialog> on its own, desyncing it\n // from React and leaving a later showModal() unable to reopen it.\n e.preventDefault();\n if (loading) return;\n requestClose();\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n return () => dialog.removeEventListener(\"cancel\", handleCancel);\n // `portalTarget` is included because the dialog only mounts into the\n // portal once `portalTarget` is set (second render) \u2014 without it in the\n // deps, this effect's first run captures a null `dialogRef.current` and\n // never re-attaches the listener once the dialog actually exists.\n }, [loading, requestClose, portalTarget]);\n\n React.useEffect(() => {\n if (!open) return;\n\n const handleEscape = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n if (!(event.target instanceof Node) || !dialogRef.current?.contains(event.target)) return;\n event.preventDefault();\n event.stopPropagation();\n if (!loading) requestClose();\n };\n\n window.addEventListener(\"keydown\", handleEscape, true);\n return () => window.removeEventListener(\"keydown\", handleEscape, true);\n }, [loading, open, requestClose]);\n\n // Handle backdrop click\n const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => {\n // Only close if clicking directly on the dialog (backdrop), not its children\n if (e.target === dialogRef.current && !loading) {\n requestClose();\n }\n };\n\n // Handle keyboard shortcuts\n React.useEffect(() => {\n if (!open) return;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n // Cmd/Ctrl+Enter confirms\n if ((e.metaKey || e.ctrlKey) && e.key === \"Enter\" && !loading) {\n e.preventDefault();\n handleConfirm();\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => window.removeEventListener(\"keydown\", handleKeyDown);\n }, [open, loading]);\n\n const handleConfirm = async () => {\n await onConfirm();\n // Don't auto-close if loading \u2014 let the parent control when to close\n if (!loading) {\n setOpen(false);\n }\n };\n\n const handleCancel = () => {\n requestClose();\n };\n\n const handleTriggerClick = () => {\n if (trigger) {\n setOpen(true);\n }\n };\n\n const dialogElement = (\n <dialog\n ref={dialogRef}\n role=\"alertdialog\"\n aria-labelledby={titleId}\n aria-describedby={text ? descriptionId : undefined}\n onClick={handleBackdropClick}\n className={cn(\n // Reset dialog defaults\n \"m-0 p-0 max-w-none bg-transparent border-none pointer-events-auto\",\n // Backdrop styling\n \"backdrop:bg-black/50 backdrop:backdrop-blur-sm backdrop:transition-opacity\",\n // Mobile: bottom sheet\n \"fixed inset-x-0 bottom-0 top-auto w-full\",\n // Desktop: centered\n \"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\",\n // Animation with reduced motion support\n \"motion-safe:open:animate-in motion-safe:open:fade-in-0 motion-safe:open:slide-in-from-bottom-4\",\n \"sm:motion-safe:open:slide-in-from-bottom-0 sm:motion-safe:open:zoom-in-95\",\n // Duration\n \"motion-safe:open:duration-300\"\n )}\n >\n <div\n role=\"document\"\n className={cn(\n // Panel container\n \"flex flex-col gap-4 rounded-t-2xl border-t bg-card p-6 text-foreground shadow-lg\",\n \"sm:rounded-xl sm:border\",\n // Relative positioning for close button\n \"relative\"\n )}\n >\n {/* Close button */}\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={handleCancel}\n disabled={loading}\n aria-label={closeAriaLabel}\n className=\"absolute right-4 top-4 opacity-70 hover:opacity-100\"\n >\n <X className=\"h-4 w-4\" />\n </IconButton>\n\n {/* Title */}\n <h2\n id={titleId}\n className={cn(\n \"text-sm font-medium leading-snug tracking-tight pr-6\",\n // Mobile: centered, Desktop: left-aligned\n \"text-center sm:text-left\"\n )}\n >\n {resolvedTitle}\n </h2>\n\n {/* Description (optional) */}\n {text && (\n <p\n id={descriptionId}\n className=\"text-sm font-medium leading-snug text-muted-foreground\"\n >\n {text}\n </p>\n )}\n\n {/* Actions */}\n <div className=\"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\">\n {resolvedCancelText !== false && (\n <Button\n ref={cancelButtonRef}\n variant=\"outline\"\n onClick={handleCancel}\n disabled={loading}\n className=\"w-full sm:w-auto\"\n >\n {resolvedCancelText}\n </Button>\n )}\n {resolvedConfirmText !== false && (\n <Button\n ref={confirmButtonRef}\n variant={variant === \"destructive\" ? \"destructive-solid\" : \"default\"}\n onClick={handleConfirm}\n disabled={loading}\n className=\"w-full sm:w-auto\"\n >\n {loading && <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />}\n {resolvedConfirmText}\n </Button>\n )}\n </div>\n </div>\n </dialog>\n );\n\n return (\n <>\n {trigger && (\n <div onClick={handleTriggerClick} className=\"inline-block\" role=\"presentation\">\n {trigger}\n </div>\n )}\n\n {portalTarget ? createPortal(dialogElement, portalTarget) : null}\n </>\n );\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\";\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useT } from \"@open-mercato/shared/lib/i18n/context\";\nimport { Button } from \"@open-mercato/ui/primitives/button\";\nimport { DialogFooter, DialogHeader } from \"@open-mercato/ui/primitives/dialog\";\nimport { IconButton } from \"../../primitives/icon-button\";\nimport { cn } from \"@open-mercato/shared/lib/utils\";\nimport { CircleHelp, Loader2, TriangleAlert, X } from \"lucide-react\";\n\nconst FOOTER_ACTION_CLASS_NAME = \"h-auto min-h-9 whitespace-normal py-1.5 text-center\";\n\nexport type ConfirmDialogProps = {\n /** Whether the dialog is open (controlled mode \u2014 used by useConfirmDialog) */\n open?: boolean;\n /** Callback when open state changes (controlled mode) */\n onOpenChange?: (open: boolean) => void;\n /** Callback when user confirms */\n onConfirm: () => void | Promise<void>;\n /** Callback when user cancels (optional, defaults to closing) */\n onCancel?: () => void;\n /** Dialog title. Defaults to i18n key \"ui.dialogs.confirm.defaultTitle\" (\"Are you sure?\") */\n title?: string;\n /** Dialog body text / description */\n text?: string;\n /** Confirm button label. Defaults to i18n \"ui.dialogs.confirm.confirmText\" (\"Confirm\").\n * Pass `false` to hide the confirm button entirely. */\n confirmText?: string | false;\n /** Cancel button label. Defaults to i18n \"ui.dialogs.confirm.cancelText\" (\"Cancel\").\n * Pass `false` to hide the cancel button entirely. */\n cancelText?: string | false;\n /** Visual variant per Figma `Status Modals [1.1]`:\n * - \"default\": neutral help badge, primary confirm\n * - \"warning\": amber warning badge, primary confirm \u2014 for risky actions that\n * lose no data\n * - \"destructive\": error badge and the `destructive-solid` confirm \u2014 the\n * point of no return for anything that deletes or discards data, including\n * unsaved edits */\n variant?: \"default\" | \"warning\" | \"destructive\";\n /** Whether the confirm button shows a loading spinner.\n * Useful for async onConfirm handlers (e.g., waiting for API response before closing). */\n loading?: boolean;\n /** Trigger element \u2014 when provided, component manages its own open state (declarative mode).\n * Clicking the trigger opens the dialog. */\n trigger?: React.ReactNode;\n};\n\nexport function ConfirmDialog({\n open: controlledOpen,\n onOpenChange,\n onConfirm,\n onCancel,\n title,\n text,\n confirmText,\n cancelText,\n variant = \"default\",\n loading = false,\n trigger,\n}: ConfirmDialogProps) {\n const t = useT();\n const dialogRef = React.useRef<HTMLDialogElement>(null);\n const [internalOpen, setInternalOpen] = React.useState(false);\n const cancelButtonRef = React.useRef<HTMLButtonElement>(null);\n const confirmButtonRef = React.useRef<HTMLButtonElement>(null);\n const restoreAriaHiddenRef = React.useRef(false);\n const [portalTarget, setPortalTarget] = React.useState<HTMLElement | null>(null);\n // Unique IDs so multiple ConfirmDialog instances on the same page don't\n // collide and make `aria-labelledby` resolve to the wrong dialog's title.\n const reactId = React.useId();\n const titleId = `confirm-dialog-title-${reactId}`;\n const descriptionId = `confirm-dialog-description-${reactId}`;\n\n // Determine if we're in controlled mode (open prop provided) or declarative mode (trigger provided)\n const isControlled = controlledOpen !== undefined;\n const open = isControlled ? controlledOpen : internalOpen;\n const setOpen = isControlled\n ? onOpenChange || (() => {})\n : setInternalOpen;\n const handleCancelCallback = React.useCallback(() => {\n if (!isControlled) {\n onCancel?.();\n }\n }, [isControlled, onCancel]);\n\n // Default text values from i18n\n const resolvedTitle =\n title ?? t(\"ui.dialogs.confirm.defaultTitle\", \"Are you sure?\");\n const resolvedConfirmText =\n confirmText === false\n ? false\n : confirmText ?? t(\"ui.dialogs.confirm.confirmText\", \"Confirm\");\n const resolvedCancelText =\n cancelText === false\n ? false\n : cancelText ?? t(\"ui.dialogs.confirm.cancelText\", \"Cancel\");\n const closeAriaLabel = t(\"ui.dialog.close.ariaLabel\", \"Close\");\n const requestClose = React.useCallback(() => {\n setOpen(false);\n handleCancelCallback();\n }, [setOpen, handleCancelCallback]);\n\n React.useLayoutEffect(() => {\n setPortalTarget(document.body);\n }, []);\n\n // Handle dialog open/close with native showModal/close\n React.useLayoutEffect(() => {\n const dialog = dialogRef.current;\n if (!dialog) return;\n\n if (open) {\n if (!dialog.open) {\n dialog.showModal();\n // Focus cancel button (safe default) or confirm if no cancel\n setTimeout(() => {\n if (resolvedCancelText !== false && cancelButtonRef.current) {\n cancelButtonRef.current.focus();\n } else if (confirmButtonRef.current) {\n confirmButtonRef.current.focus();\n }\n }, 0);\n }\n // A modal opened underneath (e.g. a Radix Dialog) marks every sibling in\n // <body> `aria-hidden`, including this portalled element. Shown on top\n // of that modal it must stay reachable for assistive technology.\n if (dialog.getAttribute(\"aria-hidden\") === \"true\") {\n dialog.removeAttribute(\"aria-hidden\");\n restoreAriaHiddenRef.current = true;\n }\n } else {\n if (dialog.open) {\n dialog.close();\n }\n if (restoreAriaHiddenRef.current) {\n restoreAriaHiddenRef.current = false;\n // Hand the attribute back only while the modal that hid us is still\n // open; its own cleanup has otherwise already removed the marker.\n if (dialog.hasAttribute(\"data-aria-hidden\")) {\n dialog.setAttribute(\"aria-hidden\", \"true\");\n }\n }\n }\n }, [open, resolvedCancelText, portalTarget]);\n\n // Handle native cancel event (Escape key)\n React.useEffect(() => {\n const dialog = dialogRef.current;\n if (!dialog) return;\n\n const handleCancel = (e: Event) => {\n // Always prevent the native default action so the dialog's own\n // open/closed state is only ever driven by our `open`-state effect \u2014\n // otherwise the browser closes the <dialog> on its own, desyncing it\n // from React and leaving a later showModal() unable to reopen it.\n e.preventDefault();\n if (loading) return;\n requestClose();\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n return () => dialog.removeEventListener(\"cancel\", handleCancel);\n // `portalTarget` is included because the dialog only mounts into the\n // portal once `portalTarget` is set (second render) \u2014 without it in the\n // deps, this effect's first run captures a null `dialogRef.current` and\n // never re-attaches the listener once the dialog actually exists.\n }, [loading, requestClose, portalTarget]);\n\n React.useEffect(() => {\n if (!open) return;\n\n const handleEscape = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n if (!(event.target instanceof Node) || !dialogRef.current?.contains(event.target)) return;\n event.preventDefault();\n event.stopPropagation();\n if (!loading) requestClose();\n };\n\n window.addEventListener(\"keydown\", handleEscape, true);\n return () => window.removeEventListener(\"keydown\", handleEscape, true);\n }, [loading, open, requestClose]);\n\n // Handle backdrop click\n const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => {\n // Only close if clicking directly on the dialog (backdrop), not its children\n if (e.target === dialogRef.current && !loading) {\n requestClose();\n }\n };\n\n // Handle keyboard shortcuts\n React.useEffect(() => {\n if (!open) return;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n // Cmd/Ctrl+Enter confirms\n if ((e.metaKey || e.ctrlKey) && e.key === \"Enter\" && !loading) {\n e.preventDefault();\n handleConfirm();\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => window.removeEventListener(\"keydown\", handleKeyDown);\n }, [open, loading]);\n\n const handleConfirm = async () => {\n await onConfirm();\n // Don't auto-close if loading \u2014 let the parent control when to close\n if (!loading) {\n setOpen(false);\n }\n };\n\n const handleCancel = () => {\n requestClose();\n };\n\n const handleTriggerClick = () => {\n if (trigger) {\n setOpen(true);\n }\n };\n\n const dialogElement = (\n <dialog\n ref={dialogRef}\n role=\"alertdialog\"\n aria-labelledby={titleId}\n aria-describedby={text ? descriptionId : undefined}\n onClick={handleBackdropClick}\n className={cn(\n // Reset dialog defaults\n \"m-0 p-0 max-w-none bg-transparent border-none pointer-events-auto\",\n // Backdrop styling\n \"backdrop:bg-black/50 backdrop:backdrop-blur-sm backdrop:transition-opacity\",\n // Mobile: bottom sheet\n \"fixed inset-x-0 bottom-0 top-auto w-full\",\n // Desktop: centered\n \"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\",\n // Animation with reduced motion support\n \"motion-safe:open:animate-in motion-safe:open:fade-in-0 motion-safe:open:slide-in-from-bottom-4\",\n \"sm:motion-safe:open:slide-in-from-bottom-0 sm:motion-safe:open:zoom-in-95\",\n // Duration\n \"motion-safe:open:duration-300\"\n )}\n >\n <div\n role=\"document\"\n className={cn(\n // Same shell as DialogContent: card surface, p-6, sheet on mobile, card on desktop\n \"relative flex flex-col gap-4 rounded-t-xl border-t bg-card p-6 text-foreground shadow-lg\",\n \"sm:rounded-xl sm:border\"\n )}\n >\n {/* Close button \u2014 mirrors DialogContent's auto close affordance */}\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={handleCancel}\n disabled={loading}\n aria-label={closeAriaLabel}\n className=\"absolute right-4 top-4 opacity-70 hover:opacity-100\"\n >\n <X className=\"h-4 w-4\" />\n </IconButton>\n\n {/* Header per Figma `Status Modals [1.1]`: status badge + title + description */}\n <DialogHeader\n className=\"pr-6\"\n leading={\n variant === \"default\" ? (\n <CircleHelp className=\"size-4\" aria-hidden />\n ) : (\n <TriangleAlert className=\"size-4\" aria-hidden />\n )\n }\n leadingTone={variant === \"destructive\" ? \"error\" : variant === \"warning\" ? \"warning\" : \"default\"}\n >\n <h2 id={titleId} className=\"text-lg font-semibold leading-none tracking-tight\">\n {resolvedTitle}\n </h2>\n {text ? (\n <p id={descriptionId} className=\"text-sm text-muted-foreground\">\n {text}\n </p>\n ) : null}\n </DialogHeader>\n\n {/* Footer per Figma `Modal Footer [1.1]` variant 1: 50/50 confirmation split,\n stacked on phones, with labels that wrap instead of overflowing the card */}\n <DialogFooter layout=\"equal\" className=\"flex-col-reverse sm:flex-row\">\n {resolvedCancelText !== false && (\n <Button\n ref={cancelButtonRef}\n variant=\"outline\"\n onClick={handleCancel}\n disabled={loading}\n className={FOOTER_ACTION_CLASS_NAME}\n >\n {resolvedCancelText}\n </Button>\n )}\n {resolvedConfirmText !== false && (\n <Button\n ref={confirmButtonRef}\n variant={variant === \"destructive\" ? \"destructive-solid\" : \"default\"}\n onClick={handleConfirm}\n disabled={loading}\n className={FOOTER_ACTION_CLASS_NAME}\n >\n {loading && <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />}\n {resolvedConfirmText}\n </Button>\n )}\n </DialogFooter>\n </div>\n </dialog>\n );\n\n return (\n <>\n {trigger && (\n <div onClick={handleTriggerClick} className=\"inline-block\" role=\"presentation\">\n {trigger}\n </div>\n )}\n\n {portalTarget ? createPortal(dialogElement, portalTarget) : null}\n </>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AA0QU,SAyDN,UAzDM,KAIF,YAJE;A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