You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReactPDFfrom"@react-pdf/renderer";/** * If style does not validate replace incorrect values with undefined to keep the up running and throw console.error only */exportconstReactPDFStyleValidator=(style: ReactPDF.Style): ReactPDF.Style=>{constcopyStyle: ReactPDF.Style={};constvalidateNumberValue=(v: string)=>{constvalidatedNumber=parseFloat(v);if(!isNaN(validatedNumber)){returnv;}returnundefined;};constnumberKeys: Array<keyofReactPDF.Style>=["borderBottomLeftRadius","borderBottomRightRadius","borderBottomWidth","borderRadius","borderRightWidth","borderTopLeftRadius","borderTopRightRadius","borderTopWidth","borderWidth","bottom","fontSize","height","left","letterSpacing","lineHeight","margin","marginBottom","marginHorizontal","marginLeft","marginRight","marginTop","marginVertical","maxHeight","minHeight","minWidth","maxWidth","opacity","order","padding","paddingBottom","paddingHorizontal","paddingLeft","paddingRight","paddingTop","paddingVertical","right","width"];numberKeys.forEach(k=>{if(style[k]){constv=validateNumberValue(style[k]);if(v){copyStyle[k]=v;}else{console.error(`Key "${k}" has the incorrect value`);}}});returncopyStyle;};
Add style validator so you cannot pass incorrect values to React PDF Editor
The text was updated successfully, but these errors were encountered: