@schandlergarcia/sf-web-components 1.9.37 → 1.9.39
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/package.json +4 -1
- package/scripts/postinstall.mjs +116 -65
- package/src/components/library/cards/ActionList.jsx +38 -0
- package/src/components/library/cards/ActivityCard.jsx +56 -0
- package/src/components/library/cards/BaseCard.jsx +109 -0
- package/src/components/library/cards/CalloutCard.jsx +37 -0
- package/src/components/library/cards/ChartCard.jsx +105 -0
- package/src/components/library/cards/FeedPanel.jsx +39 -0
- package/src/components/library/cards/ListCard.jsx +193 -0
- package/src/components/library/cards/MetricCard.jsx +109 -0
- package/src/components/library/cards/MetricsStrip.jsx +78 -0
- package/src/components/library/cards/SectionCard.jsx +83 -0
- package/src/components/library/cards/SemanticMetricCard.jsx +52 -0
- package/src/components/library/cards/SemanticMetricCardWithLoading.jsx +23 -0
- package/src/components/library/cards/SemanticTableCard.jsx +48 -0
- package/src/components/library/cards/SemanticTableCardWithLoading.jsx +22 -0
- package/src/components/library/cards/StatusCard.jsx +220 -0
- package/src/components/library/cards/TableCard.jsx +337 -0
- package/src/components/library/cards/WidgetCard.jsx +90 -0
- package/src/components/library/charts/D3Chart.jsx +109 -0
- package/src/components/library/charts/D3ChartTemplates.jsx +126 -0
- package/src/components/library/charts/GeoMap.jsx +293 -0
- package/src/components/library/chat/ChatBar.jsx +256 -0
- package/src/components/library/chat/ChatInput.jsx +89 -0
- package/src/components/library/chat/ChatMessage.jsx +178 -0
- package/src/components/library/chat/ChatMessageList.jsx +73 -0
- package/src/components/library/chat/ChatPanel.jsx +97 -0
- package/src/components/library/chat/ChatSuggestions.jsx +28 -0
- package/src/components/library/chat/ChatToolCall.jsx +100 -0
- package/src/components/library/chat/ChatTypingIndicator.jsx +23 -0
- package/src/components/library/chat/ChatWelcome.jsx +43 -0
- package/src/components/library/chat/index.jsx +10 -0
- package/src/components/library/chat/useChatState.jsx +130 -0
- package/src/components/library/data/DataModeProvider.jsx +67 -0
- package/src/components/library/data/DataModeToggle.jsx +36 -0
- package/src/components/library/data/chartDataProvider.jsx +61 -0
- package/src/components/library/data/filterUtils.jsx +141 -0
- package/src/components/library/data/useDataSource.jsx +33 -0
- package/src/components/library/data/usePageFilters.jsx +99 -0
- package/src/components/library/filters/FilterBar.jsx +95 -0
- package/src/components/library/filters/SearchFilter.jsx +36 -0
- package/src/components/library/filters/SelectFilter.jsx +55 -0
- package/src/components/library/filters/ToggleFilter.jsx +52 -0
- package/src/components/library/filters/index.jsx +4 -0
- package/src/components/library/forms/FormField.jsx +291 -0
- package/src/components/library/forms/FormModal.jsx +201 -0
- package/src/components/library/forms/FormRenderer.jsx +46 -0
- package/src/components/library/forms/FormSection.jsx +69 -0
- package/src/components/library/forms/index.jsx +5 -0
- package/src/components/library/forms/useFormState.jsx +165 -0
- package/src/components/library/heroui/Accordion.jsx +26 -0
- package/src/components/library/heroui/Alert.jsx +8 -0
- package/src/components/library/heroui/Badge.jsx +8 -0
- package/src/components/library/heroui/Breadcrumbs.jsx +22 -0
- package/src/components/library/heroui/Button.jsx +58 -0
- package/src/components/library/heroui/Card.jsx +8 -0
- package/src/components/library/heroui/Collapsible.jsx +42 -0
- package/src/components/library/heroui/DatePicker.jsx +34 -0
- package/src/components/library/heroui/Dialog.jsx +37 -0
- package/src/components/library/heroui/Drawer.jsx +32 -0
- package/src/components/library/heroui/Dropdown.jsx +28 -0
- package/src/components/library/heroui/Field.jsx +51 -0
- package/src/components/library/heroui/Input.jsx +6 -0
- package/src/components/library/heroui/Kbd.jsx +8 -0
- package/src/components/library/heroui/Meter.jsx +8 -0
- package/src/components/library/heroui/Modal.jsx +32 -0
- package/src/components/library/heroui/Pagination.jsx +8 -0
- package/src/components/library/heroui/Popover.jsx +64 -0
- package/src/components/library/heroui/ProgressBar.jsx +8 -0
- package/src/components/library/heroui/ProgressCircle.jsx +8 -0
- package/src/components/library/heroui/ScrollShadow.jsx +8 -0
- package/src/components/library/heroui/Select.jsx +37 -0
- package/src/components/library/heroui/Separator.jsx +8 -0
- package/src/components/library/heroui/Skeleton.jsx +8 -0
- package/src/components/library/heroui/Tabs.jsx +26 -0
- package/src/components/library/heroui/Toast.jsx +25 -0
- package/src/components/library/heroui/Toggle.jsx +14 -0
- package/src/components/library/heroui/Tooltip.jsx +21 -0
- package/src/components/library/index.jsx +146 -0
- package/src/components/library/layout/PageContainer.jsx +11 -0
- package/src/components/library/skeletons/CardSkeleton.jsx +30 -0
- package/src/components/library/theme/AppThemeProvider.jsx +67 -0
- package/src/components/library/theme/tokens.jsx +72 -0
- package/src/components/library/ui/Alert.jsx +80 -0
- package/src/components/library/ui/Avatar.jsx +44 -0
- package/src/components/library/ui/BreadcrumbExtras.tsx +120 -0
- package/src/components/library/ui/Button.jsx +61 -0
- package/src/components/library/ui/Card.jsx +117 -0
- package/src/components/library/ui/Checkbox.jsx +17 -0
- package/src/components/library/ui/Chip.jsx +38 -0
- package/src/components/library/ui/Collapsible.tsx +31 -0
- package/src/components/library/ui/Container.jsx +56 -0
- package/src/components/library/ui/DatePicker.tsx +34 -0
- package/src/components/library/ui/Dialog.tsx +141 -0
- package/src/components/library/ui/EmptyState.jsx +46 -0
- package/src/components/library/ui/Field.tsx +82 -0
- package/src/components/library/ui/FieldGroup.jsx +17 -0
- package/src/components/library/ui/Input.jsx +21 -0
- package/src/components/library/ui/Label.jsx +22 -0
- package/src/components/library/ui/PaginationExtras.tsx +142 -0
- package/src/components/library/ui/Popover.tsx +39 -0
- package/src/components/library/ui/Select.tsx +113 -0
- package/src/components/library/ui/Spinner.d.ts +10 -0
- package/src/components/library/ui/Spinner.jsx +64 -0
- package/src/components/library/ui/Text.jsx +46 -0
- package/src/components/library/ui/Toggle.jsx +42 -0
- package/src/components/workspace/ComponentRegistry.jsx +297 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils.ts +6 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import BaseCard from "./BaseCard";
|
|
3
|
+
import UIText from "../ui/Text";
|
|
4
|
+
import UIChip from "../ui/Chip";
|
|
5
|
+
|
|
6
|
+
function formatTimestamp(ts) {
|
|
7
|
+
if (!ts) return "";
|
|
8
|
+
try {
|
|
9
|
+
const d = ts instanceof Date ? ts : new Date(ts);
|
|
10
|
+
if (Number.isNaN(d.getTime())) return String(ts);
|
|
11
|
+
return d.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
|
|
12
|
+
} catch {
|
|
13
|
+
return String(ts);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function Avatar({ item }) {
|
|
18
|
+
const avatar = item?.avatar;
|
|
19
|
+
const name = item?.title ?? item?.name ?? "Item";
|
|
20
|
+
if (!avatar) return null;
|
|
21
|
+
if (typeof avatar === "string") {
|
|
22
|
+
return (
|
|
23
|
+
<img
|
|
24
|
+
src={avatar}
|
|
25
|
+
alt=""
|
|
26
|
+
className="h-9 w-9 rounded-full border border-slate-200 object-cover dark:border-slate-800"
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (React.isValidElement(avatar)) {
|
|
31
|
+
return (
|
|
32
|
+
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-slate-200 bg-slate-50 dark:border-slate-800 dark:bg-slate-800">
|
|
33
|
+
{avatar}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return (
|
|
38
|
+
<div className="h-9 w-9 rounded-full border border-slate-200 bg-slate-100 text-xs font-semibold text-slate-700 dark:border-slate-800 dark:bg-slate-800 dark:text-slate-200 grid place-items-center">
|
|
39
|
+
{String(name).slice(0, 2).toUpperCase()}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default function ListCard({
|
|
45
|
+
items = [],
|
|
46
|
+
title,
|
|
47
|
+
subtitle,
|
|
48
|
+
showAvatars = true,
|
|
49
|
+
showStatus = true,
|
|
50
|
+
showActions = true,
|
|
51
|
+
showTimestamp = true,
|
|
52
|
+
dense = false,
|
|
53
|
+
divided = true,
|
|
54
|
+
actions,
|
|
55
|
+
itemActions,
|
|
56
|
+
onItemClick,
|
|
57
|
+
loading = false,
|
|
58
|
+
error,
|
|
59
|
+
emptyMessage = "No items.",
|
|
60
|
+
emptyIcon,
|
|
61
|
+
maxBodyHeight,
|
|
62
|
+
...cardProps
|
|
63
|
+
}) {
|
|
64
|
+
const header = (
|
|
65
|
+
<div className="flex items-start justify-between gap-3">
|
|
66
|
+
<div className="min-w-0">
|
|
67
|
+
{title ? (
|
|
68
|
+
<UIText as="div" size="sm" weight="medium">
|
|
69
|
+
{title}
|
|
70
|
+
</UIText>
|
|
71
|
+
) : null}
|
|
72
|
+
{subtitle ? (
|
|
73
|
+
<UIText as="div" size="xs" muted className="mt-1">
|
|
74
|
+
{subtitle}
|
|
75
|
+
</UIText>
|
|
76
|
+
) : null}
|
|
77
|
+
</div>
|
|
78
|
+
{actions ? <div className="shrink-0">{actions}</div> : null}
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (error) {
|
|
83
|
+
return (
|
|
84
|
+
<BaseCard
|
|
85
|
+
variant="widget"
|
|
86
|
+
header={header}
|
|
87
|
+
body={
|
|
88
|
+
<div className="mt-4 rounded-xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-900 dark:border-rose-900/40 dark:bg-rose-950/30 dark:text-rose-100">
|
|
89
|
+
{String(error)}
|
|
90
|
+
</div>
|
|
91
|
+
}
|
|
92
|
+
{...cardProps}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const padY = dense ? "py-2" : "py-3";
|
|
98
|
+
|
|
99
|
+
const scrollStyle = maxBodyHeight ? { maxHeight: maxBodyHeight, overflowY: "auto" } : {};
|
|
100
|
+
|
|
101
|
+
const body =
|
|
102
|
+
loading ? (
|
|
103
|
+
<div className="mt-4 space-y-3">
|
|
104
|
+
{Array.from({ length: 4 }).map((_, i) => (
|
|
105
|
+
<div key={i} className="flex items-center gap-3 rounded-xl border border-slate-200 bg-white p-3 dark:border-slate-800 dark:bg-slate-900">
|
|
106
|
+
{showAvatars ? <div className="h-9 w-9 animate-pulse rounded-full bg-slate-200 dark:bg-slate-800" /> : null}
|
|
107
|
+
<div className="flex-1 space-y-2">
|
|
108
|
+
<div className="h-4 w-1/3 animate-pulse rounded bg-slate-200 dark:bg-slate-800" />
|
|
109
|
+
<div className="h-3 w-2/3 animate-pulse rounded bg-slate-200 dark:bg-slate-800" />
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
</div>
|
|
114
|
+
) : items.length === 0 ? (
|
|
115
|
+
<div className="mt-4 rounded-xl border border-dashed border-slate-300 bg-slate-50 p-6 text-center dark:border-slate-700 dark:bg-slate-950/30">
|
|
116
|
+
{emptyIcon ? <div className="mb-2">{emptyIcon}</div> : null}
|
|
117
|
+
<UIText size="sm" muted>
|
|
118
|
+
{emptyMessage}
|
|
119
|
+
</UIText>
|
|
120
|
+
</div>
|
|
121
|
+
) : (
|
|
122
|
+
<div className="mt-4 overflow-hidden rounded-xl border border-slate-200 bg-white dark:border-slate-800 dark:bg-slate-900">
|
|
123
|
+
<ul className={divided ? "divide-y divide-slate-200 dark:divide-slate-800" : ""} style={scrollStyle}>
|
|
124
|
+
{items.map((item, idx) => {
|
|
125
|
+
const key = item?.id ?? idx;
|
|
126
|
+
const name = item?.title ?? item?.name ?? "Item";
|
|
127
|
+
const desc = item?.description;
|
|
128
|
+
const status = item?.status;
|
|
129
|
+
const ts = item?.timestamp;
|
|
130
|
+
const itemValue = item?.value;
|
|
131
|
+
const itemUnit = item?.unit;
|
|
132
|
+
const right = showActions ? itemActions?.(item, idx) : null;
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<li
|
|
136
|
+
key={key}
|
|
137
|
+
className={[
|
|
138
|
+
"group flex items-start justify-between gap-3 px-4",
|
|
139
|
+
padY,
|
|
140
|
+
onItemClick ? "cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-950/30" : ""
|
|
141
|
+
]
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.join(" ")}
|
|
144
|
+
onClick={() => onItemClick?.(item, idx)}
|
|
145
|
+
>
|
|
146
|
+
<div className="flex min-w-0 items-start gap-3">
|
|
147
|
+
{showAvatars ? <Avatar item={item} /> : null}
|
|
148
|
+
<div className="min-w-0">
|
|
149
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
150
|
+
<div className="text-sm font-semibold text-slate-900 dark:text-slate-50">
|
|
151
|
+
{name}
|
|
152
|
+
</div>
|
|
153
|
+
{showStatus && status ? (
|
|
154
|
+
<UIChip>{String(status)}</UIChip>
|
|
155
|
+
) : null}
|
|
156
|
+
</div>
|
|
157
|
+
{desc ? (
|
|
158
|
+
<div className="mt-1 text-sm text-slate-600 dark:text-slate-300">{desc}</div>
|
|
159
|
+
) : null}
|
|
160
|
+
{showTimestamp && ts ? (
|
|
161
|
+
<div className="mt-1 text-xs text-slate-500 dark:text-slate-400">
|
|
162
|
+
{formatTimestamp(ts)}
|
|
163
|
+
</div>
|
|
164
|
+
) : null}
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
169
|
+
{itemValue != null ? (
|
|
170
|
+
<div className="text-right">
|
|
171
|
+
<div className="text-sm font-semibold text-slate-900 dark:text-slate-50">
|
|
172
|
+
{String(itemValue)}
|
|
173
|
+
{itemUnit ? <span className="ml-1 text-xs font-medium text-slate-500 dark:text-slate-400">{itemUnit}</span> : null}
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
) : null}
|
|
177
|
+
{right ? (
|
|
178
|
+
<div className="opacity-100 sm:opacity-0 sm:group-hover:opacity-100">
|
|
179
|
+
{right}
|
|
180
|
+
</div>
|
|
181
|
+
) : null}
|
|
182
|
+
</div>
|
|
183
|
+
</li>
|
|
184
|
+
);
|
|
185
|
+
})}
|
|
186
|
+
</ul>
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return <BaseCard variant="widget" header={header} body={body} isLoading={false} {...cardProps} />;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import BaseCard from "./BaseCard";
|
|
3
|
+
|
|
4
|
+
const CHANGE_STYLES = {
|
|
5
|
+
positive: "text-emerald-700 dark:text-emerald-400",
|
|
6
|
+
negative: "text-rose-700 dark:text-rose-400",
|
|
7
|
+
neutral: "text-slate-600 dark:text-slate-300"
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const COLOR_STYLES = {
|
|
11
|
+
default: "bg-slate-100 text-slate-800 dark:bg-slate-800 dark:text-slate-100",
|
|
12
|
+
primary: "bg-brand-100 text-brand-800 dark:bg-brand-950/40 dark:text-brand-200",
|
|
13
|
+
success: "bg-emerald-100 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-200",
|
|
14
|
+
warning: "bg-amber-100 text-amber-900 dark:bg-amber-950/40 dark:text-amber-200",
|
|
15
|
+
danger: "bg-rose-100 text-rose-800 dark:bg-rose-950/40 dark:text-rose-200"
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default function MetricCard({
|
|
19
|
+
title,
|
|
20
|
+
value,
|
|
21
|
+
subtitle,
|
|
22
|
+
change,
|
|
23
|
+
changeType = "neutral",
|
|
24
|
+
icon,
|
|
25
|
+
color = "default",
|
|
26
|
+
trend,
|
|
27
|
+
trendIcon,
|
|
28
|
+
layout = "default",
|
|
29
|
+
footer,
|
|
30
|
+
actions,
|
|
31
|
+
loading = false,
|
|
32
|
+
error,
|
|
33
|
+
...cardProps
|
|
34
|
+
}) {
|
|
35
|
+
const changeClass = CHANGE_STYLES[changeType] ?? CHANGE_STYLES.neutral;
|
|
36
|
+
const pillClass = COLOR_STYLES[color] ?? COLOR_STYLES.default;
|
|
37
|
+
|
|
38
|
+
if (error) {
|
|
39
|
+
return (
|
|
40
|
+
<BaseCard
|
|
41
|
+
variant="metric"
|
|
42
|
+
body={
|
|
43
|
+
<div className="rounded-xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-900 dark:border-rose-900/40 dark:bg-rose-950/30 dark:text-rose-100">
|
|
44
|
+
{String(error)}
|
|
45
|
+
</div>
|
|
46
|
+
}
|
|
47
|
+
{...cardProps}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const header = (
|
|
53
|
+
<div className="flex items-start justify-between gap-3">
|
|
54
|
+
<div className="min-w-0">
|
|
55
|
+
<div className="text-sm font-medium text-slate-600 dark:text-slate-300">{title}</div>
|
|
56
|
+
{subtitle ? (
|
|
57
|
+
<div className="mt-1 text-xs text-slate-500 dark:text-slate-400">{subtitle}</div>
|
|
58
|
+
) : null}
|
|
59
|
+
</div>
|
|
60
|
+
{actions ? <div className="shrink-0">{actions}</div> : null}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const body = (
|
|
65
|
+
<div className={["mt-2", layout === "compact" ? "space-y-1" : "space-y-2"].join(" ")}>
|
|
66
|
+
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
|
67
|
+
<div className="flex items-center gap-2">
|
|
68
|
+
{icon ? (
|
|
69
|
+
<span
|
|
70
|
+
className={[
|
|
71
|
+
"inline-flex h-8 w-8 items-center justify-center rounded-lg",
|
|
72
|
+
pillClass
|
|
73
|
+
].join(" ")}
|
|
74
|
+
aria-hidden="true"
|
|
75
|
+
>
|
|
76
|
+
{icon}
|
|
77
|
+
</span>
|
|
78
|
+
) : null}
|
|
79
|
+
<div className="text-2xl font-semibold tracking-tight text-slate-900 dark:text-slate-50">
|
|
80
|
+
{value}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
{(change || trend) && (
|
|
85
|
+
<div className={["flex items-center gap-1.5 text-xs font-medium", changeClass].join(" ")}>
|
|
86
|
+
{trendIcon ? <span aria-hidden="true">{trendIcon}</span> : null}
|
|
87
|
+
{change ? <span>{change}</span> : null}
|
|
88
|
+
{trend ? <span className="text-[11px] font-normal text-slate-500 dark:text-slate-400">{trend}</span> : null}
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<BaseCard
|
|
97
|
+
variant="metric"
|
|
98
|
+
padding="sm"
|
|
99
|
+
size="sm"
|
|
100
|
+
header={header}
|
|
101
|
+
body={body}
|
|
102
|
+
footer={footer ? <div className="mt-3">{footer}</div> : null}
|
|
103
|
+
isLoading={loading}
|
|
104
|
+
{...cardProps}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
|
|
3
|
+
const PLACEHOLDER_METRICS = [
|
|
4
|
+
{ label: "Metric A", value: "—", trend: null },
|
|
5
|
+
{ label: "Metric B", value: "—", trend: null },
|
|
6
|
+
{ label: "Metric C", value: "—", trend: null },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Horizontal strip of KPI metrics — compact alternative to a row of MetricCards.
|
|
11
|
+
*
|
|
12
|
+
* @param {{ label: string, value: string|number, trend?: string|number }[]} metrics
|
|
13
|
+
* @param {string} title
|
|
14
|
+
* @param {boolean} collapsible Allow collapsing into a single-line summary
|
|
15
|
+
* @param {boolean} collapsed Initial collapsed state
|
|
16
|
+
*/
|
|
17
|
+
export default function MetricsStrip({
|
|
18
|
+
metrics = [],
|
|
19
|
+
title,
|
|
20
|
+
collapsible = false,
|
|
21
|
+
collapsed: initialCollapsed = false,
|
|
22
|
+
className = "",
|
|
23
|
+
}) {
|
|
24
|
+
const [collapsed, setCollapsed] = useState(initialCollapsed);
|
|
25
|
+
const items = metrics.length ? metrics : PLACEHOLDER_METRICS;
|
|
26
|
+
|
|
27
|
+
if (collapsible && collapsed) {
|
|
28
|
+
return (
|
|
29
|
+
<button
|
|
30
|
+
type="button"
|
|
31
|
+
onClick={() => setCollapsed(false)}
|
|
32
|
+
className={`flex w-full items-center justify-between rounded-lg border border-slate-200 bg-white px-3 py-2 text-left text-xs text-slate-500 hover:bg-slate-50 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-400 dark:hover:bg-slate-800 ${className}`}
|
|
33
|
+
>
|
|
34
|
+
<span>{title ?? "Metrics"}: {items.map((m) => `${m.label} ${m.value}`).join(" · ")}</span>
|
|
35
|
+
<span>▸</span>
|
|
36
|
+
</button>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className={`rounded-xl border border-slate-200 bg-white p-3 dark:border-slate-800 dark:bg-slate-900 ${className}`}>
|
|
42
|
+
{(title || collapsible) && (
|
|
43
|
+
<div className="mb-2 flex items-center justify-between">
|
|
44
|
+
<span className="text-xs font-medium text-slate-500 dark:text-slate-400">{title ?? "Metrics"}</span>
|
|
45
|
+
{collapsible && (
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
onClick={() => setCollapsed(true)}
|
|
49
|
+
className="text-xs text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300"
|
|
50
|
+
>
|
|
51
|
+
Collapse
|
|
52
|
+
</button>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
<div className="flex flex-wrap gap-4">
|
|
57
|
+
{items.map((m) => (
|
|
58
|
+
<div key={m.label} className="min-w-[80px]">
|
|
59
|
+
<div className="text-xs text-slate-400 dark:text-slate-500">{m.label}</div>
|
|
60
|
+
<div className="flex items-baseline gap-1.5">
|
|
61
|
+
<span className="text-sm font-semibold text-slate-700 dark:text-slate-200">{m.value}</span>
|
|
62
|
+
{m.trend != null && (
|
|
63
|
+
<TrendBadge trend={m.trend} />
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
))}
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function TrendBadge({ trend }) {
|
|
74
|
+
const isPositive = String(trend).startsWith?.("+") || trend > 0;
|
|
75
|
+
const color = isPositive ? "text-red-500" : "text-emerald-500";
|
|
76
|
+
const label = typeof trend === "number" ? (trend > 0 ? `+${trend}` : trend) : trend;
|
|
77
|
+
return <span className={`text-xs ${color}`}>{label}</span>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import BaseCard from "./BaseCard";
|
|
3
|
+
import UIText from "../ui/Text";
|
|
4
|
+
|
|
5
|
+
const VARIANT_STYLES = {
|
|
6
|
+
default: "bg-white dark:bg-slate-900",
|
|
7
|
+
primary: "bg-brand-50 dark:bg-brand-950/30",
|
|
8
|
+
secondary: "bg-slate-50 dark:bg-slate-950/30",
|
|
9
|
+
accent: "bg-emerald-50 dark:bg-emerald-950/25"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const SIZE_STYLES = {
|
|
13
|
+
sm: { title: "text-lg", desc: "text-sm", pad: "p-4" },
|
|
14
|
+
md: { title: "text-xl", desc: "text-sm", pad: "p-5" },
|
|
15
|
+
lg: { title: "text-2xl", desc: "text-base", pad: "p-6" },
|
|
16
|
+
xl: { title: "text-3xl", desc: "text-base", pad: "p-7" }
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ALIGN_STYLES = {
|
|
20
|
+
left: "text-left items-start",
|
|
21
|
+
center: "text-center items-center",
|
|
22
|
+
right: "text-right items-end"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function SectionCard({
|
|
26
|
+
title,
|
|
27
|
+
description,
|
|
28
|
+
label,
|
|
29
|
+
variant = "default",
|
|
30
|
+
showDivider = true,
|
|
31
|
+
alignment = "left",
|
|
32
|
+
size = "md",
|
|
33
|
+
isDark = false,
|
|
34
|
+
className = "",
|
|
35
|
+
...cardProps
|
|
36
|
+
}) {
|
|
37
|
+
const s = SIZE_STYLES[size] ?? SIZE_STYLES.md;
|
|
38
|
+
const align = ALIGN_STYLES[alignment] ?? ALIGN_STYLES.left;
|
|
39
|
+
const variantClass = VARIANT_STYLES[variant] ?? VARIANT_STYLES.default;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<BaseCard
|
|
43
|
+
variant="widget"
|
|
44
|
+
padding="none"
|
|
45
|
+
className={[
|
|
46
|
+
variantClass,
|
|
47
|
+
isDark ? "dark" : "",
|
|
48
|
+
"overflow-hidden",
|
|
49
|
+
className
|
|
50
|
+
]
|
|
51
|
+
.filter(Boolean)
|
|
52
|
+
.join(" ")}
|
|
53
|
+
{...cardProps}
|
|
54
|
+
body={
|
|
55
|
+
<div className={s.pad}>
|
|
56
|
+
<div className={["flex flex-col gap-2", align].join(" ")}>
|
|
57
|
+
{label ? (
|
|
58
|
+
<span className="inline-flex rounded-full bg-slate-900 px-2 py-1 text-[11px] font-semibold text-white dark:bg-slate-100 dark:text-slate-900">
|
|
59
|
+
{label}
|
|
60
|
+
</span>
|
|
61
|
+
) : null}
|
|
62
|
+
{title ? (
|
|
63
|
+
<UIText as="h2" weight="bold" className={["tracking-tight", s.title].join(" ")}>
|
|
64
|
+
{title}
|
|
65
|
+
</UIText>
|
|
66
|
+
) : null}
|
|
67
|
+
{description ? (
|
|
68
|
+
<UIText as="p" muted className={[s.desc, "max-w-3xl"].join(" ")}>
|
|
69
|
+
{description}
|
|
70
|
+
</UIText>
|
|
71
|
+
) : null}
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
{showDivider ? (
|
|
75
|
+
<div className="mt-4 h-px w-full bg-slate-200 dark:bg-slate-800" />
|
|
76
|
+
) : null}
|
|
77
|
+
</div>
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import MetricCard from "./MetricCard";
|
|
3
|
+
import { getSemanticMetric } from "../data/chartDataProvider";
|
|
4
|
+
|
|
5
|
+
export default function SemanticMetricCard({
|
|
6
|
+
semanticId,
|
|
7
|
+
metricId,
|
|
8
|
+
title,
|
|
9
|
+
subtitle,
|
|
10
|
+
value,
|
|
11
|
+
unit,
|
|
12
|
+
format,
|
|
13
|
+
trend,
|
|
14
|
+
change,
|
|
15
|
+
changeLabel,
|
|
16
|
+
description,
|
|
17
|
+
seriesName,
|
|
18
|
+
availableFilters,
|
|
19
|
+
showFilters,
|
|
20
|
+
compact,
|
|
21
|
+
className,
|
|
22
|
+
loading = false,
|
|
23
|
+
...rest
|
|
24
|
+
}) {
|
|
25
|
+
const metric = React.useMemo(() => getSemanticMetric(semanticId, metricId), [semanticId, metricId]);
|
|
26
|
+
|
|
27
|
+
const resolvedTitle = title ?? metric?.title ?? metricId ?? "Metric";
|
|
28
|
+
const resolvedSubtitle = subtitle ?? metric?.subtitle;
|
|
29
|
+
const resolvedValue = value ?? metric?.value ?? "";
|
|
30
|
+
const resolvedTrend = trend ?? metric?.trend;
|
|
31
|
+
const resolvedChange = change ?? metric?.change;
|
|
32
|
+
const resolvedChangeType = metric?.changeType ?? "neutral";
|
|
33
|
+
const resolvedColor = metric?.color ?? "default";
|
|
34
|
+
|
|
35
|
+
// Note: unit/format/etc. are accepted for forward compatibility; basic rendering is handled by MetricCard for now.
|
|
36
|
+
return (
|
|
37
|
+
<MetricCard
|
|
38
|
+
title={resolvedTitle}
|
|
39
|
+
subtitle={resolvedSubtitle}
|
|
40
|
+
value={resolvedValue}
|
|
41
|
+
change={resolvedChangeLabel ? `${resolvedChangeLabel} ${resolvedChange ?? ""}`.trim() : resolvedChange}
|
|
42
|
+
changeType={resolvedChangeType}
|
|
43
|
+
color={resolvedColor}
|
|
44
|
+
trend={resolvedTrend}
|
|
45
|
+
layout={compact ? "compact" : "default"}
|
|
46
|
+
loading={loading}
|
|
47
|
+
className={className}
|
|
48
|
+
{...rest}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import SemanticMetricCard from "./SemanticMetricCard";
|
|
3
|
+
|
|
4
|
+
export default function SemanticMetricCardWithLoading({
|
|
5
|
+
simulateInitialLoad = true,
|
|
6
|
+
minInitialDelayMs = 350,
|
|
7
|
+
maxInitialDelayMs = 900,
|
|
8
|
+
loading: loadingProp,
|
|
9
|
+
...props
|
|
10
|
+
}) {
|
|
11
|
+
const [loading, setLoading] = React.useState(Boolean(simulateInitialLoad));
|
|
12
|
+
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
if (!simulateInitialLoad) return;
|
|
15
|
+
const delay =
|
|
16
|
+
Math.floor(Math.random() * (maxInitialDelayMs - minInitialDelayMs + 1)) + minInitialDelayMs;
|
|
17
|
+
const t = setTimeout(() => setLoading(false), delay);
|
|
18
|
+
return () => clearTimeout(t);
|
|
19
|
+
}, [simulateInitialLoad, minInitialDelayMs, maxInitialDelayMs]);
|
|
20
|
+
|
|
21
|
+
return <SemanticMetricCard loading={loadingProp ?? loading} {...props} />;
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import TableCard from "./TableCard";
|
|
3
|
+
import { getSemanticDataset } from "../data/chartDataProvider";
|
|
4
|
+
|
|
5
|
+
export default function SemanticTableCard({
|
|
6
|
+
semanticId,
|
|
7
|
+
dataOverride,
|
|
8
|
+
columnsOverride,
|
|
9
|
+
title,
|
|
10
|
+
subtitle,
|
|
11
|
+
searchable = true,
|
|
12
|
+
sortable = true,
|
|
13
|
+
paginated = true,
|
|
14
|
+
pageSize = 10,
|
|
15
|
+
compact,
|
|
16
|
+
striped,
|
|
17
|
+
isDark,
|
|
18
|
+
simulateInitialLoad,
|
|
19
|
+
minInitialDelayMs,
|
|
20
|
+
maxInitialDelayMs,
|
|
21
|
+
...rest
|
|
22
|
+
}) {
|
|
23
|
+
const ds = React.useMemo(() => getSemanticDataset(semanticId), [semanticId]);
|
|
24
|
+
const table = ds?.table;
|
|
25
|
+
|
|
26
|
+
const resolvedColumns = columnsOverride ?? table?.columns ?? [];
|
|
27
|
+
const resolvedData = dataOverride ?? table?.rows ?? [];
|
|
28
|
+
const resolvedTitle = title ?? table?.title ?? ds?.title ?? "Table";
|
|
29
|
+
const resolvedSubtitle = subtitle ?? table?.subtitle;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<TableCard
|
|
33
|
+
title={resolvedTitle}
|
|
34
|
+
subtitle={resolvedSubtitle}
|
|
35
|
+
columns={resolvedColumns}
|
|
36
|
+
data={resolvedData}
|
|
37
|
+
searchable={searchable}
|
|
38
|
+
sortable={sortable}
|
|
39
|
+
paginated={paginated}
|
|
40
|
+
pageSize={pageSize}
|
|
41
|
+
simulateInitialLoad={simulateInitialLoad}
|
|
42
|
+
minInitialDelayMs={minInitialDelayMs}
|
|
43
|
+
maxInitialDelayMs={maxInitialDelayMs}
|
|
44
|
+
{...rest}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import SemanticTableCard from "./SemanticTableCard";
|
|
3
|
+
|
|
4
|
+
export default function SemanticTableCardWithLoading({
|
|
5
|
+
simulateInitialLoad = true,
|
|
6
|
+
minInitialDelayMs = 350,
|
|
7
|
+
maxInitialDelayMs = 900,
|
|
8
|
+
loading: loadingProp,
|
|
9
|
+
...props
|
|
10
|
+
}) {
|
|
11
|
+
// Leverage TableCard's simulateInitialLoad by default; also allow explicit loading override.
|
|
12
|
+
return (
|
|
13
|
+
<SemanticTableCard
|
|
14
|
+
{...props}
|
|
15
|
+
loading={loadingProp}
|
|
16
|
+
simulateInitialLoad={simulateInitialLoad}
|
|
17
|
+
minInitialDelayMs={minInitialDelayMs}
|
|
18
|
+
maxInitialDelayMs={maxInitialDelayMs}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|