@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
51 lines (50 loc) • 1.98 kB
JavaScript
"use client";
import Skeleton from "../../base-ui/Skeleton/index.mjs";
import Surface from "../Surface/Surface.mjs";
import { styles } from "./style.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
import { cx } from "antd-style";
//#region src/dashboard/FilterStrip/FilterStrip.tsx
const countClass = {
danger: styles.countDanger,
warning: styles.countWarning
};
const integerFormat = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 });
const formatInteger = (count) => integerFormat.format(count);
/** One surface of selectable counts. Peer filters share a seam instead of a row of equal cards. */
const FilterStrip = ({ emptyText = "--", formatCount = formatInteger, items, label, onChange, value }) => /* @__PURE__ */ jsx(Surface, { children: /* @__PURE__ */ jsx("div", {
"aria-label": label,
className: styles.frame,
role: "radiogroup",
children: /* @__PURE__ */ jsx("div", {
className: styles.grid,
children: items.map((item) => {
const active = item.key === value;
const missing = item.count === void 0 || item.count === null;
const emphasize = item.tone && typeof item.count === "number" && item.count > 0;
return /* @__PURE__ */ jsxs("button", {
"aria-checked": active,
className: cx(styles.cell, active && styles.cellActive),
role: "radio",
title: item.hint,
type: "button",
onClick: () => onChange(item.key),
children: [/* @__PURE__ */ jsx("span", {
className: cx(styles.label, active && styles.labelActive),
children: item.label
}), /* @__PURE__ */ jsx("span", {
className: cx(styles.count, emphasize && countClass[item.tone]),
children: item.loading ? /* @__PURE__ */ jsx(Skeleton, {
height: 22,
radius: 6,
width: 48
}) : missing ? emptyText : formatCount(item.count)
})]
}, item.key);
})
})
}) });
FilterStrip.displayName = "FilterStrip";
//#endregion
export { FilterStrip as default, formatInteger };
//# sourceMappingURL=FilterStrip.mjs.map