@progress/kendo-react-treelist
Version:
React TreeList enables the display of self-referencing tabular data. KendoReact TreeList package
67 lines (66 loc) • 2.62 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as l from "react";
import { useInternationalization as N } from "@progress/kendo-react-intl";
import { getNestedValue as k, Keys as C, IconWrap as b, classNames as w } from "@progress/kendo-react-common";
import { useTableKeyboardNavigation as y } from "@progress/kendo-react-data-tools";
import { caretAltDownIcon as v, caretAltRightIcon as R } from "@progress/kendo-svg-icons";
import { TREELIST_PREVENT_SELECTION_ELEMENT as S, TREELIST_COL_INDEX_ATTRIBUTE as L } from "../constants/index.mjs";
const _ = (e) => {
const { hasChildren: d, level: i = [0], expanded: r, dataItem: o, format: s, id: f, ariaColumnIndex: u, isSelected: m } = e, c = k(e.field, o), x = N(), h = y(f);
let g = "";
const I = l.useCallback(
(a) => {
a.isDefaultPrevented() || a.keyCode === C.enter && e.expandable && (a.preventDefault(), e.onExpandChange(a, o, i));
},
[e.expandable, o, i]
);
c != null && (g = s ? x.format(s, c) : c.toString());
const t = [];
if (e.expandable) {
const a = (n) => /* @__PURE__ */ l.createElement("span", { key: n, className: "k-treelist-toggle k-icon k-svg-icon" }, /* @__PURE__ */ l.createElement("svg", { "aria-hidden": "true", focusable: "false", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" }));
t.push(...i.slice(1).map((n, T) => a(T))), d ? t.push(
/* @__PURE__ */ l.createElement(
b,
{
className: "k-treelist-toggle",
name: r ? "caret-alt-down" : "caret-alt-right",
icon: r ? v : R,
key: "expand-collapse",
onClick: (n) => e.onExpandChange(n.syntheticEvent || n, o, i),
[S]: !0
}
)
) : t.push(a(t.length));
}
const E = /* @__PURE__ */ l.createElement(
"td",
{
style: e.style,
className: w("k-table-td", e.className, {
"k-text-nowrap": e.expandable,
"k-selected": m
}),
colSpan: e.colSpan,
"aria-colindex": u,
"aria-expanded": d ? r : void 0,
"aria-selected": m,
role: "gridcell",
onKeyDown: I,
[L]: e.colIndex,
...h
},
t,
g
);
return e.render ? e.render.call(void 0, E, e) : E;
};
_.displayName = "KendoReactTreeListCell";
export {
_ as TreeListCell
};