UNPKG

@anoki/fse-ui

Version:

FSE UI components library

3 lines (2 loc) 1.95 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./index.cjs237.js"),s=require("react"),H=({icon:t,className:r="",style:b={}})=>{var v,S,y,p,m,w,j,E,I,T,i,R,o,z,D,L;const[a,n]=s.useState(""),[G,l]=s.useState(!1),[g,u]=s.useState(!0),d=(y=(S=(v=t==null?void 0:t.data)==null?void 0:v.additionalInfo)==null?void 0:S.customData)==null?void 0:y.isDecorative,x=((E=(j=(w=(m=(p=t==null?void 0:t.data)==null?void 0:p.additionalInfo)==null?void 0:m.customData)==null?void 0:w.translations)==null?void 0:j.it)==null?void 0:E.altText)||"Icona";s.useEffect(()=>{if(!(t!=null&&t.url)){l(!0),u(!1);return}(async()=>{try{u(!0);const e=await fetch(t.url);if(!e.ok)throw new Error(`HTTP ${e.status}: Failed to fetch SVG`);const _=await e.text();if(!_.includes("<svg"))throw new Error("Response is not valid SVG content");n(_),l(!1)}catch(e){console.error("Error fetching SVG:",e),l(!0)}finally{u(!1)}})()},[t==null?void 0:t.url]);const h={width:((I=t==null?void 0:t.size)==null?void 0:I.width)??40,height:((T=t==null?void 0:t.size)==null?void 0:T.height)??40,...((i=t==null?void 0:t.position)==null?void 0:i.x)!==void 0||((R=t==null?void 0:t.position)==null?void 0:R.y)!==void 0?{transform:`translate(${((o=t==null?void 0:t.position)==null?void 0:o.x)??0}px, ${((z=t==null?void 0:t.position)==null?void 0:z.y)??0}px)`}:{},...b};return g||G||!a?f.jsxRuntimeExports.jsx("img",{src:(t==null?void 0:t.url)||"",alt:d?"":x,"aria-hidden":d,width:((D=t==null?void 0:t.size)==null?void 0:D.width)??40,height:((L=t==null?void 0:t.size)==null?void 0:L.height)??40,className:r,style:{opacity:g?.5:1,transition:"opacity 0.2s ease-in-out",...h}}):d?f.jsxRuntimeExports.jsx("div",{className:r,style:h,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:a}}):f.jsxRuntimeExports.jsx("div",{className:r,style:h,role:"img","aria-label":x,dangerouslySetInnerHTML:{__html:a}})};exports.SvgIcon=H; //# sourceMappingURL=index.cjs127.js.map