@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
36 lines • 3.21 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IconStandAlone = exports.IconComplex = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const role_1 = require("../../types/role/role");
//types
// styles
const icon_styled_1 = require("./icon.styled");
const IconComplexComponent = ({ id, color, height, width, emptyAltText, altText, icon, dataTestId = 'icon', rotate, transitionDuration, twistAnimationTransformValue, customIconStyles, }, ref) => {
const [svgContent, setSvgContent] = react_1.default.useState('');
react_1.default.useEffect(() => {
(async () => {
const res = await fetch(icon);
let response = '';
if (res) {
response = await res?.text();
}
setSvgContent(response);
})();
}, [icon]);
return ((0, jsx_runtime_1.jsx)(icon_styled_1.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 ? role_1.ROLES.NONE : role_1.ROLES.IMG, twistAnimationTransformValue: twistAnimationTransformValue }));
};
exports.IconComplex = react_1.default.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 ((0, jsx_runtime_1.jsx)(exports.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 ? ((0, jsx_runtime_1.jsx)(icon_styled_1.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 })) : ((0, jsx_runtime_1.jsx)(icon_styled_1.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 ? role_1.ROLES.NONE : role_1.ROLES.IMG, twistAnimationTransformValue: twistAnimationTransformValue }));
};
exports.IconStandAlone = react_1.default.forwardRef(IconStandAloneComponent);
//# sourceMappingURL=iconStandAlone.js.map