@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
30 lines • 2.76 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { ROLES } from '../../types/role/role';
//types
// styles
import { IconComplexStyled, IconSVGStyled, IconStyled } from './icon.styled';
const IconComplexComponent = ({ id, color, height, width, emptyAltText, altText, icon, dataTestId = 'icon', rotate, transitionDuration, twistAnimationTransformValue, customIconStyles, }, ref) => {
const [svgContent, setSvgContent] = React.useState('');
React.useEffect(() => {
(async () => {
const res = await fetch(icon);
let response = '';
if (res) {
response = await res?.text();
}
setSvgContent(response);
})();
}, [icon]);
return (_jsx(IconComplexStyled, { ref: ref, "$color": color, "$customIconStyles": customIconStyles, "$height": height, "$moveRound": rotate, "$srcImage": icon, "$transitionDuration": transitionDuration, "$width": width, "aria-hidden": emptyAltText, "aria-label": altText, dangerouslySetInnerHTML: { __html: svgContent }, "data-testid": dataTestId, id: id, role: emptyAltText ? ROLES.NONE : ROLES.IMG, twistAnimationTransformValue: twistAnimationTransformValue }));
};
export const IconComplex = React.forwardRef(IconComplexComponent);
const IconStandAloneComponent = ({ id, linearIcon, icon, altText, width, height, color, rotate = '0deg', transitionDuration = '0.2s', dataTestId = 'icon', twistAnimationTransformValue, complex = false, customIconStyles, }, ref) => {
const isEmptyAltText = !altText;
if (complex) {
return (_jsx(IconComplex, { ref: ref, altText: altText, color: color, customIconStyles: customIconStyles, dataTestId: dataTestId, emptyAltText: isEmptyAltText, height: height, icon: icon, id: id, moveRound: rotate, transitionDuration: transitionDuration, twistAnimationTransformValue: twistAnimationTransformValue, width: width }));
}
return !linearIcon ? (_jsx(IconStyled, { ref: ref, "$customIconStyles": customIconStyles, "$height": height, "$moveRound": rotate, "$transitionDuration": transitionDuration, "$width": width, alt: altText, "aria-hidden": isEmptyAltText, "data-testid": dataTestId, id: id, loading: "lazy", src: icon })) : (_jsx(IconSVGStyled, { ref: ref, "$color": color, "$customIconStyles": customIconStyles, "$height": height, "$moveRound": rotate, "$srcImage": icon, "$transitionDuration": transitionDuration, "$width": width, "aria-hidden": isEmptyAltText, "aria-label": altText, "data-testid": dataTestId, id: id, role: isEmptyAltText ? ROLES.NONE : ROLES.IMG, twistAnimationTransformValue: twistAnimationTransformValue }));
};
export const IconStandAlone = React.forwardRef(IconStandAloneComponent);
//# sourceMappingURL=iconStandAlone.js.map