@bwp-web/components 1.0.9 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export * from './BiampBanner';
7
7
  export * from './BiampSegmentedButton';
8
8
  export * from './BiampGlobalSearch';
9
9
  export * from './UserInitialsIcon';
10
+ export * from './DynamicSvgIcon';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -2770,6 +2770,156 @@ var getInitials = (name) => {
2770
2770
  const initials = words.filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join("");
2771
2771
  return initials;
2772
2772
  };
2773
+
2774
+ // src/DynamicSvgIcon/DynamicSvgIcon.tsx
2775
+ import { SvgIcon, Skeleton, Box as Box13 } from "@mui/material";
2776
+ import { useEffect as useEffect5, useState as useState6 } from "react";
2777
+ import { jsx as jsx25 } from "react/jsx-runtime";
2778
+ var svgCache = /* @__PURE__ */ new Map();
2779
+ function clearDynamicSvgIconCache() {
2780
+ svgCache.clear();
2781
+ }
2782
+ function applyCurrentColor(svg) {
2783
+ return svg.replace(/fill="(?!none|currentColor)[^"]*"/g, 'fill="currentColor"').replace(/stroke="(?!none|currentColor)[^"]*"/g, 'stroke="currentColor"');
2784
+ }
2785
+ function useDynamicSvgIcon(url, options = {}) {
2786
+ const { replaceColors = false, onLoad, onError } = options;
2787
+ const transform = replaceColors ? applyCurrentColor : (s) => s;
2788
+ const [svgContent, setSvgContent] = useState6(() => {
2789
+ const cached = svgCache.get(url);
2790
+ return cached ? transform(cached.innerContent) : null;
2791
+ });
2792
+ const [svgViewBox, setSvgViewBox] = useState6(() => {
2793
+ const cached = svgCache.get(url);
2794
+ return cached?.viewBox ?? null;
2795
+ });
2796
+ const [loading, setLoading] = useState6(() => !svgCache.has(url));
2797
+ const [error, setError] = useState6(null);
2798
+ useEffect5(() => {
2799
+ if (!url) {
2800
+ setLoading(false);
2801
+ setError("No URL provided");
2802
+ setSvgContent(null);
2803
+ setSvgViewBox(null);
2804
+ return;
2805
+ }
2806
+ let cancelled = false;
2807
+ const cached = svgCache.get(url);
2808
+ if (cached) {
2809
+ setSvgContent(transform(cached.innerContent));
2810
+ setSvgViewBox(cached.viewBox);
2811
+ setLoading(false);
2812
+ setError(null);
2813
+ onLoad?.();
2814
+ return;
2815
+ }
2816
+ setLoading(true);
2817
+ setError(null);
2818
+ setSvgContent(null);
2819
+ setSvgViewBox(null);
2820
+ (async () => {
2821
+ try {
2822
+ const response = await fetch(url);
2823
+ if (!response.ok) {
2824
+ throw new Error(
2825
+ `Failed to fetch SVG: ${response.status} ${response.statusText}`
2826
+ );
2827
+ }
2828
+ const contentType = response.headers.get("content-type") ?? "";
2829
+ const text = await response.text();
2830
+ if (!text.includes("<svg") && !contentType.includes("svg")) {
2831
+ throw new Error("Response is not an SVG");
2832
+ }
2833
+ const viewBoxMatch = text.match(/viewBox="([^"]*)"/);
2834
+ const viewBox = viewBoxMatch ? viewBoxMatch[1] : null;
2835
+ const svgMatch = text.match(/<svg[^>]*>([\s\S]*?)<\/svg>/);
2836
+ const innerContent = svgMatch ? svgMatch[1] : text;
2837
+ svgCache.set(url, { innerContent, viewBox });
2838
+ if (!cancelled) {
2839
+ setSvgContent(transform(innerContent));
2840
+ setSvgViewBox(viewBox);
2841
+ setLoading(false);
2842
+ onLoad?.();
2843
+ }
2844
+ } catch (err) {
2845
+ if (!cancelled) {
2846
+ const message = err instanceof Error ? err.message : "Failed to load SVG";
2847
+ setError(message);
2848
+ setLoading(false);
2849
+ onError?.(message);
2850
+ }
2851
+ }
2852
+ })();
2853
+ return () => {
2854
+ cancelled = true;
2855
+ };
2856
+ }, [url]);
2857
+ return { loading, error, svgContent, svgViewBox };
2858
+ }
2859
+ var DEFAULT_SIZE2 = 24;
2860
+ function DynamicSvgIcon({
2861
+ url,
2862
+ fallback,
2863
+ width = DEFAULT_SIZE2,
2864
+ height = DEFAULT_SIZE2,
2865
+ replaceColors,
2866
+ skeletonVariant = "circular",
2867
+ skeletonAnimation = "pulse",
2868
+ onLoad,
2869
+ onError,
2870
+ sx,
2871
+ ...svgIconProps
2872
+ }) {
2873
+ const { loading, error, svgContent, svgViewBox } = useDynamicSvgIcon(url, {
2874
+ replaceColors,
2875
+ onLoad,
2876
+ onError
2877
+ });
2878
+ if (loading) {
2879
+ return /* @__PURE__ */ jsx25(
2880
+ Skeleton,
2881
+ {
2882
+ variant: skeletonVariant,
2883
+ animation: skeletonAnimation,
2884
+ sx: { width, height }
2885
+ }
2886
+ );
2887
+ }
2888
+ if (error || !svgContent) {
2889
+ return /* @__PURE__ */ jsx25(
2890
+ Box13,
2891
+ {
2892
+ sx: {
2893
+ width,
2894
+ height,
2895
+ display: "inline-flex",
2896
+ alignItems: "center",
2897
+ justifyContent: "center",
2898
+ overflow: "hidden",
2899
+ flexShrink: 0,
2900
+ "& > svg, & > .MuiSvgIcon-root": {
2901
+ width: "100%",
2902
+ height: "100%"
2903
+ }
2904
+ },
2905
+ children: fallback
2906
+ }
2907
+ );
2908
+ }
2909
+ return /* @__PURE__ */ jsx25(
2910
+ SvgIcon,
2911
+ {
2912
+ ...svgIconProps,
2913
+ ...svgViewBox && { viewBox: svgViewBox },
2914
+ sx: {
2915
+ ...typeof sx === "object" && sx !== null && !Array.isArray(sx) ? sx : void 0,
2916
+ width,
2917
+ height
2918
+ },
2919
+ children: /* @__PURE__ */ jsx25("g", { dangerouslySetInnerHTML: { __html: svgContent } })
2920
+ }
2921
+ );
2922
+ }
2773
2923
  export {
2774
2924
  BIAMP_TABLE_DEBOUNCE_DELAY,
2775
2925
  BiampAppDialog,
@@ -2809,10 +2959,12 @@ export {
2809
2959
  BiampTableToolbarSearch,
2810
2960
  BiampTableTruncatedCell,
2811
2961
  BiampWrapper,
2962
+ DynamicSvgIcon,
2812
2963
  SegmentedButton,
2813
2964
  SegmentedButtonGroup,
2814
2965
  UserInitialsIcon,
2815
2966
  buildCsvString,
2967
+ clearDynamicSvgIconCache,
2816
2968
  exportToCsv,
2817
2969
  getColumnVisibilityDirtyCount,
2818
2970
  getDefaultColumnVisibility,
@@ -2825,6 +2977,7 @@ export {
2825
2977
  sortingToOrder,
2826
2978
  toVisibilityState,
2827
2979
  useBiampServerSideTable,
2828
- useDebouncedCallback
2980
+ useDebouncedCallback,
2981
+ useDynamicSvgIcon
2829
2982
  };
2830
2983
  //# sourceMappingURL=index.js.map