UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

34 lines (33 loc) 1.32 kB
/*! * 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 { getItemIndex } from "../pick-list/shared-list-logic"; export function getScreenReaderText(item, status, valueList) { const { items, messages } = valueList; const total = items.length; const position = getItemIndex(valueList, item) + 1; const template = status === "idle" ? messages.dragHandleIdle : status === "active" ? messages.dragHandleActive : status === "change" ? messages.dragHandleChange : messages.dragHandleCommit; return replacePlaceholders(template, item.label, position, total); } export function getHandleAndItemElement(event) { const handle = event .composedPath() .find((item) => item.dataset?.jsHandle !== undefined); const item = event .composedPath() .find((item) => item.tagName?.toLowerCase() === "calcite-value-list-item"); return { handle, item }; } export function replacePlaceholders(text, label, position, total) { const replacePosition = text.replace("${position}", position.toString()); const replaceLabel = replacePosition.replace("${itemLabel}", label); return replaceLabel.replace("${total}", total.toString()); }