@vectara/vectara-ui
Version:
Vectara's design system, codified as a React and Sass component library
39 lines (38 loc) • 2.22 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import classNames from "classnames";
function normalizeItems(items) {
if (Array.isArray(items))
return items;
return Object.entries(items).map(([key, value]) => ({
key,
value: value == null ? "" : String(value)
}));
}
const paddingToClassMap = {
xxs: "vuiKvTable--paddingXxs",
xs: "vuiKvTable--paddingXs",
s: "vuiKvTable--paddingS"
};
const alignToClassMap = {
top: "vuiKvTable--alignTop",
middle: "vuiKvTable--alignMiddle",
bottom: "vuiKvTable--alignBottom"
};
export const VuiKvTable = (_a) => {
var { items, keyHeader, valueHeader, label, padding = "xs", align = "middle" } = _a, rest = __rest(_a, ["items", "keyHeader", "valueHeader", "label", "padding", "align"]);
const hasHeader = keyHeader !== undefined || valueHeader !== undefined;
const classes = classNames("vuiKvTable", paddingToClassMap[padding], alignToClassMap[align]);
const normalizedItems = normalizeItems(items);
return (_jsxs("dl", Object.assign({ className: classes, "aria-label": label }, rest, { children: [hasHeader && (_jsxs("div", Object.assign({ className: "vuiKvTableRow vuiKvTableRow--header" }, { children: [_jsx("dt", Object.assign({ className: "vuiKvTableCell--key" }, { children: keyHeader })), _jsx("dd", Object.assign({ className: "vuiKvTableCell--value" }, { children: valueHeader }))] }))), normalizedItems.map((item, i) => (_jsxs("div", Object.assign({ className: "vuiKvTableRow" }, { children: [_jsx("dt", Object.assign({ className: "vuiKvTableCell--key" }, { children: item.key })), _jsx("dd", Object.assign({ className: "vuiKvTableCell--value" }, { children: item.value }))] }), i)))] })));
};