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

34 lines 1.44 kB
import { jsx as _jsx, Fragment as _Fragment } 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 { isValidHttpUrl } from '../../utils/isValidUrl/isValidUrl'; import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary'; import { IconBasic } from './icon'; const IconWithProvider = (props) => { const { ICONS_STYLES } = useTheme(); const { assets } = useUtilsProvider(); const isUrl = isValidHttpUrl(props.icon); let hostIcon; let urlIcon = ''; if (ICONS_STYLES?.[props.icon]) { hostIcon = assets?.baseHost; } if (isUrl) { urlIcon = props.icon; } else if (props.icon && hostIcon) { urlIcon = `${hostIcon}${[ICONS_STYLES?.[props.icon]]}`; } return _jsx(IconBasic, { ...props, ref: props.ref, icon: urlIcon }); }; const IconHostComponent = ({ ...props }, ref) => { const myContext = React.useContext(UtilsContext); if (!myContext?.assets) { return _jsx(IconBasic, { ...props, ref: ref }); } return (_jsx(ErrorBoundary, { fallBackComponent: _jsx(_Fragment, {}), resetCondition: props.icon, children: _jsx(IconWithProvider, { ...props, ref: ref }) })); }; export const IconHost = React.forwardRef(IconHostComponent); //# sourceMappingURL=iconHost.js.map