@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
34 lines • 1.82 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import React from 'react';
import { useTheme } from 'styled-components';
import { UtilsContext } from '../../provider/utils/context';
import { useUtilsProvider } from '../../provider/utils/provider';
import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary';
import { isValidHttpUrl } from '../../utils/isValidUrl/isValidUrl';
import { IllustrationBasic } from './illustration';
const IllustrationWithProvider = ({ ...props }) => {
const { ILLUSTRATIONS_STYLES } = useTheme();
const { assets } = useUtilsProvider();
const isUrl = 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 (_jsx(ErrorBoundary, { fallBackComponent: _jsx(_Fragment, {}), resetCondition: urlIllustration, children: _jsx(IllustrationBasic, { ...props, ref: props.ref, illustration: urlIllustration }) }));
};
const IllustrationHostComponent = ({ ...props }, ref) => {
const myContext = React.useContext(UtilsContext);
if (!myContext?.assets) {
return _jsx(IllustrationBasic, { ...props, ref: ref });
}
return (_jsxs(ErrorBoundary, { fallBackComponent: _jsx(_Fragment, {}), resetCondition: props.illustration, children: [_jsx(IllustrationWithProvider, { ...props, ref: ref }), ' '] }));
};
export const IllustrationHost = React.forwardRef(IllustrationHostComponent);
//# sourceMappingURL=illustrationHost.js.map