UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

40 lines 2.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.IllustrationHost = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const styled_components_1 = require("styled-components"); const context_1 = require("../../provider/utils/context"); const provider_1 = require("../../provider/utils/provider"); const errorBoundary_1 = require("../../provider/errorBoundary/errorBoundary"); const isValidUrl_1 = require("../../utils/isValidUrl/isValidUrl"); const illustration_1 = require("./illustration"); const IllustrationWithProvider = ({ ...props }) => { const { ILLUSTRATIONS_STYLES } = (0, styled_components_1.useTheme)(); const { assets } = (0, provider_1.useUtilsProvider)(); const isUrl = (0, isValidUrl_1.isValidHttpUrl)(props.illustration); let hostIllustration; let urlIllustration = ''; if (ILLUSTRATIONS_STYLES?.[props.illustration]) { hostIllustration = assets?.illutrationsBaseHost; } if (isUrl) { urlIllustration = props.illustration; } else if (props.illustration && hostIllustration) { urlIllustration = `${hostIllustration}${[ILLUSTRATIONS_STYLES?.[props.illustration]]}`; } return ((0, jsx_runtime_1.jsx)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), resetCondition: urlIllustration, children: (0, jsx_runtime_1.jsx)(illustration_1.IllustrationBasic, { ...props, ref: props.ref, illustration: urlIllustration }) })); }; const IllustrationHostComponent = ({ ...props }, ref) => { const myContext = react_1.default.useContext(context_1.UtilsContext); if (!myContext?.assets) { return (0, jsx_runtime_1.jsx)(illustration_1.IllustrationBasic, { ...props, ref: ref }); } return ((0, jsx_runtime_1.jsxs)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), resetCondition: props.illustration, children: [(0, jsx_runtime_1.jsx)(IllustrationWithProvider, { ...props, ref: ref }), ' '] })); }; exports.IllustrationHost = react_1.default.forwardRef(IllustrationHostComponent); //# sourceMappingURL=illustrationHost.js.map