@carbon/react
Version:
React components for the Carbon Design System
76 lines (74 loc) • 3.04 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { usePrefix } from "../../internal/usePrefix.js";
import classNames from "classnames";
import "react";
import PropTypes from "prop-types";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/components/DataTableSkeleton/DataTableSkeleton.tsx
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const DataTableSkeleton = ({ headers, rowCount = 5, columnCount = 5, zebra = false, className, showHeader = true, showToolbar = true, size = "lg", ...rest }) => {
const prefix = usePrefix();
const dataTableSkeletonClasses = classNames(className, {
[`${prefix}--skeleton`]: true,
[`${prefix}--data-table`]: true,
[`${prefix}--data-table--${size}`]: size,
[`${prefix}--data-table--zebra`]: zebra
});
const rowRepeat = rowCount;
const rows = Array(rowRepeat);
const columnsArray = Array.from({ length: columnCount }, (_, index) => index);
for (let i = 0; i < rowRepeat; i++) rows[i] = /* @__PURE__ */ jsx("tr", { children: columnsArray.map((j) => /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx("span", {}) }, j)) }, i);
return /* @__PURE__ */ jsxs("div", {
className: `${prefix}--skeleton ${prefix}--data-table-container`,
children: [
showHeader ? /* @__PURE__ */ jsxs("div", {
className: `${prefix}--data-table-header`,
children: [/* @__PURE__ */ jsx("div", { className: `${prefix}--data-table-header__title` }), /* @__PURE__ */ jsx("div", { className: `${prefix}--data-table-header__description` })]
}) : null,
showToolbar ? /* @__PURE__ */ jsx("section", {
"aria-label": "data table toolbar",
className: `${prefix}--table-toolbar`,
children: /* @__PURE__ */ jsx("div", {
className: `${prefix}--toolbar-content`,
children: /* @__PURE__ */ jsx("span", { className: `${prefix}--skeleton ${prefix}--btn ${prefix}--btn--sm` })
})
}) : null,
/* @__PURE__ */ jsxs("table", {
className: dataTableSkeletonClasses,
...rest,
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columnsArray.map((i) => /* @__PURE__ */ jsx("th", { children: headers ? /* @__PURE__ */ jsx("div", {
className: `${prefix}--table-header-label`,
children: headers[i]?.header
}) : /* @__PURE__ */ jsx("span", {}) }, i)) }) }), /* @__PURE__ */ jsx("tbody", { children: rows })]
})
]
});
};
DataTableSkeleton.propTypes = {
className: PropTypes.string,
columnCount: PropTypes.number,
headers: PropTypes.arrayOf(PropTypes.shape({ header: PropTypes.node.isRequired }).isRequired),
rowCount: PropTypes.number,
showHeader: PropTypes.bool,
showToolbar: PropTypes.bool,
size: PropTypes.oneOf([
"xs",
"sm",
"md",
"lg",
"xl"
]),
zebra: PropTypes.bool
};
//#endregion
export { DataTableSkeleton as default };