UNPKG

@eccenca/gui-elements

Version:

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

27 lines 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createNewItemRendererFactory = void 0; const react_1 = __importDefault(require("react")); const MenuItem_1 = __importDefault(require("../Menu/MenuItem")); const OverflowText_1 = __importDefault(require("../Typography/OverflowText")); /** * 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. */ const createNewItemRendererFactory = (itemTextRenderer, iconName) => { // Return custom render function return (query, modifiers, handleClick) => { let textElement = itemTextRenderer(query); if (typeof textElement === "string") { textElement = (react_1.default.createElement(OverflowText_1.default, null, textElement.trim() !== "" ? textElement : `Create option '${query}'`)); } return (react_1.default.createElement(MenuItem_1.default, { icon: iconName, active: modifiers.active, key: query, onClick: handleClick, text: textElement })); }; }; exports.createNewItemRendererFactory = createNewItemRendererFactory; //# sourceMappingURL=autoCompleteFieldUtils.js.map