Skip to content

Commit

Permalink
Fixed component to re-render when the icon changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yzen90 committed Feb 25, 2023
1 parent 00be54b commit 4b411d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
46 changes: 23 additions & 23 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@ export const SVGIcon: JSXComponent<IconProps> = defineComponent({
inheritAttrs: false,
props: makeIconProps(),
setup(props: IconProps, { attrs }: any) {
const svgAttrs: Record<string, any> = {
class: 'v-icon__svg',
xmlns: 'http://www.w3.org/2000/svg',
viewBox: '0 0 24 24',
role: 'img',
'aria-hidden': 'true',
};
return () => {
const svgAttrs: Record<string, any> = {
class: 'v-icon__svg',
xmlns: 'http://www.w3.org/2000/svg',
viewBox: '0 0 24 24',
role: 'img',
'aria-hidden': 'true',
};

let d = props.icon as string;
let d = props.icon as string;

if (d.startsWith?.('SVG;')) {
const parts = d.split(';');
if (d.startsWith?.('SVG;')) {
const parts = d.split(';');

d = parts[2] ?? '';
d = parts[2] ?? '';

if (parts[1]?.length) svgAttrs['viewBox'] = parts[1];
if (parts[1]?.length) svgAttrs['viewBox'] = parts[1];

if (parts[3]?.length) {
svgAttrs['fill'] = parts[3];
svgAttrs['style'] = `fill: ${parts[3]};`;
}
if (parts[3]?.length) {
svgAttrs['fill'] = parts[3];
svgAttrs['style'] = `fill: ${parts[3]};`;
}

if (parts[4]?.length) {
svgAttrs['stroke-width'] = parts[4];
svgAttrs['stroke'] = 'currentColor';
}
if (parts[4]?.length) {
svgAttrs['stroke-width'] = parts[4];
svgAttrs['stroke'] = 'currentColor';
}

if (parts[5]?.length) svgAttrs['fill-rule'] = parts[5];
}
if (parts[5]?.length) svgAttrs['fill-rule'] = parts[5];
}

return () => {
return createVNode(props.tag, mergeProps(attrs, { style: null }), {
default: () => [createVNode('svg', svgAttrs, [createVNode('path', { d }, null)])],
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xrnoz/vuetify-svg-icons",
"version": "1.6.2",
"version": "1.6.3",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit 4b411d4

Please sign in to comment.