@bwp-web/components 1.1.0 → 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.js CHANGED
@@ -2779,11 +2779,15 @@ var svgCache = /* @__PURE__ */ new Map();
2779
2779
  function clearDynamicSvgIconCache() {
2780
2780
  svgCache.clear();
2781
2781
  }
2782
+ function applyCurrentColor(svg) {
2783
+ return svg.replace(/fill="(?!none|currentColor)[^"]*"/g, 'fill="currentColor"').replace(/stroke="(?!none|currentColor)[^"]*"/g, 'stroke="currentColor"');
2784
+ }
2782
2785
  function useDynamicSvgIcon(url, options = {}) {
2783
- const { onLoad, onError } = options;
2786
+ const { replaceColors = false, onLoad, onError } = options;
2787
+ const transform = replaceColors ? applyCurrentColor : (s) => s;
2784
2788
  const [svgContent, setSvgContent] = useState6(() => {
2785
2789
  const cached = svgCache.get(url);
2786
- return cached ? cached.innerContent : null;
2790
+ return cached ? transform(cached.innerContent) : null;
2787
2791
  });
2788
2792
  const [svgViewBox, setSvgViewBox] = useState6(() => {
2789
2793
  const cached = svgCache.get(url);
@@ -2802,7 +2806,7 @@ function useDynamicSvgIcon(url, options = {}) {
2802
2806
  let cancelled = false;
2803
2807
  const cached = svgCache.get(url);
2804
2808
  if (cached) {
2805
- setSvgContent(cached.innerContent);
2809
+ setSvgContent(transform(cached.innerContent));
2806
2810
  setSvgViewBox(cached.viewBox);
2807
2811
  setLoading(false);
2808
2812
  setError(null);
@@ -2832,7 +2836,7 @@ function useDynamicSvgIcon(url, options = {}) {
2832
2836
  const innerContent = svgMatch ? svgMatch[1] : text;
2833
2837
  svgCache.set(url, { innerContent, viewBox });
2834
2838
  if (!cancelled) {
2835
- setSvgContent(innerContent);
2839
+ setSvgContent(transform(innerContent));
2836
2840
  setSvgViewBox(viewBox);
2837
2841
  setLoading(false);
2838
2842
  onLoad?.();
@@ -2858,6 +2862,7 @@ function DynamicSvgIcon({
2858
2862
  fallback,
2859
2863
  width = DEFAULT_SIZE2,
2860
2864
  height = DEFAULT_SIZE2,
2865
+ replaceColors,
2861
2866
  skeletonVariant = "circular",
2862
2867
  skeletonAnimation = "pulse",
2863
2868
  onLoad,
@@ -2866,6 +2871,7 @@ function DynamicSvgIcon({
2866
2871
  ...svgIconProps
2867
2872
  }) {
2868
2873
  const { loading, error, svgContent, svgViewBox } = useDynamicSvgIcon(url, {
2874
+ replaceColors,
2869
2875
  onLoad,
2870
2876
  onError
2871
2877
  });