UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

20 lines 1.06 kB
import React from "react"; import MenuItem from "../Menu/MenuItem.js"; import OverflowText from "../Typography/OverflowText.js"; /** * Returns a function to be used in an AutoComplete widget for rendering custom elements based on the query string. * * @param itemTextRenderer The text or element that should be displayed for the new custom item suggestion. * @param iconName Optional icon to show left to the text. */ export var createNewItemRendererFactory = function (itemTextRenderer, iconName) { // Return custom render function return function (query, modifiers, handleClick) { var textElement = itemTextRenderer(query); if (typeof textElement === "string") { textElement = (React.createElement(OverflowText, null, textElement.trim() !== "" ? textElement : "Create option '".concat(query, "'"))); } return (React.createElement(MenuItem, { icon: iconName, active: modifiers.active, key: query, onClick: handleClick, text: textElement })); }; }; //# sourceMappingURL=autoCompleteFieldUtils.js.map