UNPKG

@mui/x-tree-view

Version:

The community edition of the MUI X Tree View components.

34 lines (32 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateTreeItemIdAttribute = exports.createTreeViewDefaultId = void 0; let globalTreeViewDefaultId = 0; const createTreeViewDefaultId = () => { globalTreeViewDefaultId += 1; return `mui-tree-view-${globalTreeViewDefaultId}`; }; /** * Generate the id attribute (i.e.: the `id` attribute passed to the DOM element) of a Tree Item. * If the user explicitly defined an id attribute, it will be returned. * Otherwise, the method creates a unique id for the item based on the Tree View id attribute and the item `itemId` * @param {object} params The parameters to determine the id attribute of the item. * @param {TreeViewItemId} params.itemId The id of the item to get the id attribute of. * @param {string | undefined} params.idAttribute The id attribute of the item if explicitly defined by the user. * @param {string} params.treeId The id attribute of the Tree View. * @returns {string} The id attribute of the item. */ exports.createTreeViewDefaultId = createTreeViewDefaultId; const generateTreeItemIdAttribute = ({ id, treeId = '', itemId }) => { if (id != null) { return id; } return `${treeId}-${itemId}`; }; exports.generateTreeItemIdAttribute = generateTreeItemIdAttribute;