coles-solid-library 0.4.0 → 0.4.2

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.
Files changed (2) hide show
  1. package/dist/index.esm.js +31 -6
  2. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -2874,6 +2874,7 @@ const icons = import.meta.glob('/node_modules/@material-symbols/svg-400/**/*.svg
2874
2874
  import: 'default'
2875
2875
  });
2876
2876
  const Icon = props => {
2877
+ const [rawSvg, setRawSvg] = createSignal("");
2877
2878
  const [svg, setSvg] = createSignal("");
2878
2879
  const sizeMap = {
2879
2880
  small: 16,
@@ -2889,14 +2890,33 @@ const Icon = props => {
2889
2890
  }
2890
2891
  return 24;
2891
2892
  });
2892
- const color = props.color ?? "currentColor";
2893
+ const color = createMemo(() => props.color ?? "currentColor");
2893
2894
  const variant = props.variant ?? "outlined";
2894
2895
  const key = `/node_modules/@material-symbols/svg-400/${variant}/${props.name}.svg`;
2895
2896
  if (!icons[key]) throw new Error(`Icon not found: ${key}`);
2896
2897
  icons[key]().then(raw => {
2897
- setSvg(raw.replace(/fill=".*?"/g, 'fill="currentColor"').replace(/width=".*?"/g, `width="${untrack(size)}"`).replace(/height=".*?"/g, `height="${untrack(size)}"`));
2898
+ setRawSvg(raw);
2898
2899
  }).catch(console.error);
2899
2900
  const [iconRef, setIconRef] = createSignal();
2901
+ createEffect(() => {
2902
+ const markup = rawSvg();
2903
+ if (!markup) return;
2904
+ const nextColor = color();
2905
+ const nextSize = size();
2906
+ let nextMarkup = markup.replace(/width=".*?"/g, `width="${nextSize}"`).replace(/height=".*?"/g, `height="${nextSize}"`);
2907
+ if (/fill="/.test(nextMarkup)) {
2908
+ nextMarkup = nextMarkup.replace(/fill=".*?"/g, `fill="${nextColor}"`);
2909
+ } else {
2910
+ nextMarkup = nextMarkup.replace(/<svg([^>]*)>/, (match, attrs) => {
2911
+ if (/fill=/.test(attrs)) {
2912
+ return `<svg${attrs}>`;
2913
+ }
2914
+ const spacer = attrs && attrs.endsWith(" ") ? "" : attrs ? " " : " ";
2915
+ return `<svg${attrs}${spacer}fill="${nextColor}">`;
2916
+ });
2917
+ }
2918
+ setSvg(nextMarkup);
2919
+ });
2900
2920
  return (() => {
2901
2921
  var _el$ = _tmpl$$8();
2902
2922
  use(ref => {
@@ -2905,22 +2925,27 @@ const Icon = props => {
2905
2925
  props?.ref?.(ref);
2906
2926
  }, _el$);
2907
2927
  _el$.style.setProperty("display", "inline-block");
2908
- color != null ? _el$.style.setProperty("color", color) : _el$.style.removeProperty("color");
2909
2928
  createRenderEffect(_p$ => {
2910
2929
  var _v$ = styles$5.icon,
2911
2930
  _v$2 = `${size()}px`,
2912
2931
  _v$3 = `${size()}px`,
2913
- _v$4 = svg();
2932
+ _v$4 = color(),
2933
+ _v$5 = color(),
2934
+ _v$6 = svg();
2914
2935
  _v$ !== _p$.e && className(_el$, _p$.e = _v$);
2915
2936
  _v$2 !== _p$.t && ((_p$.t = _v$2) != null ? _el$.style.setProperty("width", _v$2) : _el$.style.removeProperty("width"));
2916
2937
  _v$3 !== _p$.a && ((_p$.a = _v$3) != null ? _el$.style.setProperty("height", _v$3) : _el$.style.removeProperty("height"));
2917
- _v$4 !== _p$.o && (_el$.innerHTML = _p$.o = _v$4);
2938
+ _v$4 !== _p$.o && ((_p$.o = _v$4) != null ? _el$.style.setProperty("color", _v$4) : _el$.style.removeProperty("color"));
2939
+ _v$5 !== _p$.i && ((_p$.i = _v$5) != null ? _el$.style.setProperty("fill", _v$5) : _el$.style.removeProperty("fill"));
2940
+ _v$6 !== _p$.n && (_el$.innerHTML = _p$.n = _v$6);
2918
2941
  return _p$;
2919
2942
  }, {
2920
2943
  e: undefined,
2921
2944
  t: undefined,
2922
2945
  a: undefined,
2923
- o: undefined
2946
+ o: undefined,
2947
+ i: undefined,
2948
+ n: undefined
2924
2949
  });
2925
2950
  return _el$;
2926
2951
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coles-solid-library",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "A SolidJS mostly UI library",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",