Skip to content

Commit

Permalink
feat: external svg function
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Jun 13, 2021
1 parent 1543e3a commit b012325
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
@@ -1,5 +1,5 @@
import { createElement } from './createElement';
import { className, m, style, ns } from './m';
import { className, m, style, svg, VFlags } from './m';
import { patch, patchProps, patchChildren } from './patch';

/**
Expand All @@ -16,10 +16,11 @@ export {
className,
m,
style,
ns,
svg,
patch,
patchProps,
patchChildren,
_,
OLD_VNODE_FIELD,
VFlags,
};
11 changes: 8 additions & 3 deletions src/m.ts
Expand Up @@ -17,10 +17,15 @@ export enum VFlags {

/**
* Attaches ns props to svg element
* @param {string} tag - Tag of VNode
* @param {VProps} props - Props of VNode
* @param {VProps=} children - Children of VNode
* @param {VElement} vnode - SVG VNode
* @returns {VElement}
*/
export const svg = (vnode: VElement): VElement => {
if (!vnode.props) vnode.props = {};
ns(vnode.tag, vnode.props, vnode.children);
return vnode;
};

export const ns = (tag: string, props: VProps, children?: VNode[]): void => {
props.ns = 'http://www.w3.org/2000/svg';
if (children && tag !== 'foreignObject') {
Expand Down

0 comments on commit b012325

Please sign in to comment.