@bwp-web/components 1.0.8 → 1.1.0

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
@@ -2682,7 +2682,10 @@ function BiampGlobalSearch({
2682
2682
  fullWidth: true,
2683
2683
  sx: {
2684
2684
  "& .MuiOutlinedInput-root": { padding: "0px !important" },
2685
- "& .MuiInputBase-input": { paddingLeft: "8px !important" }
2685
+ "& .MuiInputBase-input": { paddingLeft: "8px !important" },
2686
+ "& .MuiOutlinedInput-root:not(:hover):not(.Mui-focused) .MuiOutlinedInput-notchedOutline": {
2687
+ border: "none"
2688
+ }
2686
2689
  },
2687
2690
  slotProps: {
2688
2691
  input: {
@@ -2767,6 +2770,150 @@ var getInitials = (name) => {
2767
2770
  const initials = words.filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join("");
2768
2771
  return initials;
2769
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 useDynamicSvgIcon(url, options = {}) {
2783
+ const { onLoad, onError } = options;
2784
+ const [svgContent, setSvgContent] = useState6(() => {
2785
+ const cached = svgCache.get(url);
2786
+ return cached ? cached.innerContent : null;
2787
+ });
2788
+ const [svgViewBox, setSvgViewBox] = useState6(() => {
2789
+ const cached = svgCache.get(url);
2790
+ return cached?.viewBox ?? null;
2791
+ });
2792
+ const [loading, setLoading] = useState6(() => !svgCache.has(url));
2793
+ const [error, setError] = useState6(null);
2794
+ useEffect5(() => {
2795
+ if (!url) {
2796
+ setLoading(false);
2797
+ setError("No URL provided");
2798
+ setSvgContent(null);
2799
+ setSvgViewBox(null);
2800
+ return;
2801
+ }
2802
+ let cancelled = false;
2803
+ const cached = svgCache.get(url);
2804
+ if (cached) {
2805
+ setSvgContent(cached.innerContent);
2806
+ setSvgViewBox(cached.viewBox);
2807
+ setLoading(false);
2808
+ setError(null);
2809
+ onLoad?.();
2810
+ return;
2811
+ }
2812
+ setLoading(true);
2813
+ setError(null);
2814
+ setSvgContent(null);
2815
+ setSvgViewBox(null);
2816
+ (async () => {
2817
+ try {
2818
+ const response = await fetch(url);
2819
+ if (!response.ok) {
2820
+ throw new Error(
2821
+ `Failed to fetch SVG: ${response.status} ${response.statusText}`
2822
+ );
2823
+ }
2824
+ const contentType = response.headers.get("content-type") ?? "";
2825
+ const text = await response.text();
2826
+ if (!text.includes("<svg") && !contentType.includes("svg")) {
2827
+ throw new Error("Response is not an SVG");
2828
+ }
2829
+ const viewBoxMatch = text.match(/viewBox="([^"]*)"/);
2830
+ const viewBox = viewBoxMatch ? viewBoxMatch[1] : null;
2831
+ const svgMatch = text.match(/<svg[^>]*>([\s\S]*?)<\/svg>/);
2832
+ const innerContent = svgMatch ? svgMatch[1] : text;
2833
+ svgCache.set(url, { innerContent, viewBox });
2834
+ if (!cancelled) {
2835
+ setSvgContent(innerContent);
2836
+ setSvgViewBox(viewBox);
2837
+ setLoading(false);
2838
+ onLoad?.();
2839
+ }
2840
+ } catch (err) {
2841
+ if (!cancelled) {
2842
+ const message = err instanceof Error ? err.message : "Failed to load SVG";
2843
+ setError(message);
2844
+ setLoading(false);
2845
+ onError?.(message);
2846
+ }
2847
+ }
2848
+ })();
2849
+ return () => {
2850
+ cancelled = true;
2851
+ };
2852
+ }, [url]);
2853
+ return { loading, error, svgContent, svgViewBox };
2854
+ }
2855
+ var DEFAULT_SIZE2 = 24;
2856
+ function DynamicSvgIcon({
2857
+ url,
2858
+ fallback,
2859
+ width = DEFAULT_SIZE2,
2860
+ height = DEFAULT_SIZE2,
2861
+ skeletonVariant = "circular",
2862
+ skeletonAnimation = "pulse",
2863
+ onLoad,
2864
+ onError,
2865
+ sx,
2866
+ ...svgIconProps
2867
+ }) {
2868
+ const { loading, error, svgContent, svgViewBox } = useDynamicSvgIcon(url, {
2869
+ onLoad,
2870
+ onError
2871
+ });
2872
+ if (loading) {
2873
+ return /* @__PURE__ */ jsx25(
2874
+ Skeleton,
2875
+ {
2876
+ variant: skeletonVariant,
2877
+ animation: skeletonAnimation,
2878
+ sx: { width, height }
2879
+ }
2880
+ );
2881
+ }
2882
+ if (error || !svgContent) {
2883
+ return /* @__PURE__ */ jsx25(
2884
+ Box13,
2885
+ {
2886
+ sx: {
2887
+ width,
2888
+ height,
2889
+ display: "inline-flex",
2890
+ alignItems: "center",
2891
+ justifyContent: "center",
2892
+ overflow: "hidden",
2893
+ flexShrink: 0,
2894
+ "& > svg, & > .MuiSvgIcon-root": {
2895
+ width: "100%",
2896
+ height: "100%"
2897
+ }
2898
+ },
2899
+ children: fallback
2900
+ }
2901
+ );
2902
+ }
2903
+ return /* @__PURE__ */ jsx25(
2904
+ SvgIcon,
2905
+ {
2906
+ ...svgIconProps,
2907
+ ...svgViewBox && { viewBox: svgViewBox },
2908
+ sx: {
2909
+ ...typeof sx === "object" && sx !== null && !Array.isArray(sx) ? sx : void 0,
2910
+ width,
2911
+ height
2912
+ },
2913
+ children: /* @__PURE__ */ jsx25("g", { dangerouslySetInnerHTML: { __html: svgContent } })
2914
+ }
2915
+ );
2916
+ }
2770
2917
  export {
2771
2918
  BIAMP_TABLE_DEBOUNCE_DELAY,
2772
2919
  BiampAppDialog,
@@ -2806,10 +2953,12 @@ export {
2806
2953
  BiampTableToolbarSearch,
2807
2954
  BiampTableTruncatedCell,
2808
2955
  BiampWrapper,
2956
+ DynamicSvgIcon,
2809
2957
  SegmentedButton,
2810
2958
  SegmentedButtonGroup,
2811
2959
  UserInitialsIcon,
2812
2960
  buildCsvString,
2961
+ clearDynamicSvgIconCache,
2813
2962
  exportToCsv,
2814
2963
  getColumnVisibilityDirtyCount,
2815
2964
  getDefaultColumnVisibility,
@@ -2822,6 +2971,7 @@ export {
2822
2971
  sortingToOrder,
2823
2972
  toVisibilityState,
2824
2973
  useBiampServerSideTable,
2825
- useDebouncedCallback
2974
+ useDebouncedCallback,
2975
+ useDynamicSvgIcon
2826
2976
  };
2827
2977
  //# sourceMappingURL=index.js.map