@llamaindex/ui
Version:
A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications
67 lines (63 loc) • 2.69 kB
JavaScript
'use strict';
var chunkFOE2DPSM_js = require('./chunk-FOE2DPSM.js');
var chunkHK7TFVDA_js = require('./chunk-HK7TFVDA.js');
var react = require('react');
var jsxRuntime = require('react/jsx-runtime');
var variantStyles = {
total: {
dot: "bg-gray-800",
subtitle: "text-gray-600"
},
awaiting: {
dot: "bg-orange-500"
},
approved: {
dot: "bg-green-500"
},
rejected: {
dot: "bg-red-500"
}
};
async function fetchCountData(params) {
var _a;
const data = await params.client.search({
pageSize: 0,
filter: params.filter,
includeTotal: true
});
return (_a = data.totalSize) != null ? _a : 0;
}
function ItemCount({
title,
filter = {},
variant = "total",
subtitle,
client
}) {
const [count, setCount] = react.useState(null);
const [loading, setLoading] = react.useState(true);
const [error, setError] = react.useState(null);
const styles = variantStyles[variant];
react.useEffect(() => {
fetchCountData({ filter, client }).then(setCount).catch((err) => setError(err.message)).finally(() => setLoading(false));
}, [filter, client]);
return /* @__PURE__ */ jsxRuntime.jsx(chunkFOE2DPSM_js.Card, { className: "p-6 bg-white border border-gray-200 hover:shadow-md transition-shadow", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-start justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkHK7TFVDA_js.cn("w-2 h-2 rounded-full", styles.dot) }),
/* @__PURE__ */ jsxRuntime.jsx("h4", { className: chunkHK7TFVDA_js.cn("text-md font-medium"), children: title })
] }),
loading && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center space-x-2", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-8 h-8 border-2 border-gray-300 border-t-gray-600 rounded-full animate-spin" }),
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500 text-sm", children: "Loading..." })
] }),
error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-red-500 text-sm", children: [
"Error: ",
error
] }),
count !== null && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
subtitle && /* @__PURE__ */ jsxRuntime.jsx("p", { className: chunkHK7TFVDA_js.cn("text-sm", "text-zinc-500"), children: subtitle }),
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-3xl font-bold text-gray-900 mt-3", children: count.toLocaleString() })
] })
] }) }) });
}
exports.ItemCount = ItemCount;