@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
75 lines (71 loc) • 2.76 kB
JavaScript
/*!
* All material copyright ESRI, All Rights Reserved, unless otherwise specified.
* See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
* v1.5.0-next.4
*/
import { Build } from '@stencil/core/internal/client';
const CSS = {
container: "container",
containerBorderSelected: "container--border-selected",
containerBorderUnselected: "container--border-unselected",
contentContainer: "content-container",
contentContainerSelectable: "content-container--selectable",
contentContainerHasCenterContent: "content-container--has-center-content",
nestedContainer: "nested-container",
nestedContainerHidden: "nested-container--hidden",
content: "content",
customContent: "custom-content",
actionsStart: "actions-start",
contentStart: "content-start",
label: "label",
description: "description",
contentEnd: "content-end",
actionsEnd: "actions-end",
selectionContainer: "selection-container",
openContainer: "open-container"
};
const SLOTS = {
actionsStart: "actions-start",
contentStart: "content-start",
content: "content",
contentEnd: "content-end",
actionsEnd: "actions-end"
};
const MAX_COLUMNS = 5;
const ICONS = {
selectedMultiple: "check-circle-f",
selectedSingle: "circle-f",
unselected: "blank",
closedLTR: "caret-right",
closedRTL: "caret-left",
open: "caret-down",
blank: "blank",
close: "x"
};
const listItemGroupSelector = "calcite-list-item-group";
const listItemSelector = "calcite-list-item";
function getListItemChildren(event) {
const assignedElements = event.target.assignedElements({ flatten: true });
const listItemGroupChildren = assignedElements.filter((el) => el?.matches(listItemGroupSelector))
.map((group) => Array.from(group.querySelectorAll(listItemSelector)))
.reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []);
const listItemChildren = assignedElements.filter((el) => el?.matches(listItemSelector));
return [...listItemGroupChildren, ...listItemChildren];
}
function updateListItemChildren(listItemChildren) {
listItemChildren.forEach((listItem) => {
listItem.setPosition = listItemChildren.indexOf(listItem) + 1;
listItem.setSize = listItemChildren.length;
});
}
function getDepth(element, includeGroup = false) {
if (!Build.isBrowser) {
return 0;
}
const expression = includeGroup
? "ancestor::calcite-list-item | ancestor::calcite-list-item-group"
: "ancestor::calcite-list-item";
const result = document.evaluate(expression, element, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
return result.snapshotLength;
}
export { CSS as C, ICONS as I, MAX_COLUMNS as M, SLOTS as S, getDepth as a, getListItemChildren as g, updateListItemChildren as u };