UNPKG

@veracity/vui

Version:

Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.

48 lines (46 loc) 1.7 kB
import { isReactText, isString } from "../utils/assertion.js"; import { ButtonIcon } from "./buttonIcon.js"; import { ButtonText } from "./buttonText.js"; import { loadingIconProps } from "./consts.js"; import { jsx } from "react/jsx-runtime"; //#region src/button/buttonHelpers.tsx /** * Unified icon renderer for all button icon positions. * Converts string icon names to ButtonIcon components with appropriate margins. * * @param iconProp - Icon name string or React element * @param position - Icon position: 'main' (center), 'left', or 'right' * @param isLoading - Whether to show loading spinner (only applies to left position) * @returns Rendered icon or null */ const renderButtonIcon = (iconProp, position, isLoading = false) => { if (position === "left" && isLoading) return /* @__PURE__ */ jsx(ButtonIcon, { ...loadingIconProps }); if (!iconProp) return null; if (!isString(iconProp)) return iconProp; return /* @__PURE__ */ jsx(ButtonIcon, { name: iconProp }); }; /** * Renders the button content (text or children). * Wraps text strings in ButtonText component with optional truncation. * * @param children - React children content * @param text - Text string to render * @param isTruncated - Whether to enable text truncation * @returns Rendered content */ const renderContent = (children, text, isTruncated) => { if (children) return children; if (isReactText(text)) return /* @__PURE__ */ jsx(ButtonText, { isTruncated, text }); if (text) return /* @__PURE__ */ jsx(ButtonText, { isTruncated, children: text }); return null; }; //#endregion export { renderButtonIcon, renderContent }; globalThis.__vuiVersion__ = "5.3.1" //# sourceMappingURL=buttonHelpers.js.map