Skip to content

Commit

Permalink
experimenting with blending phosphor/react vdom
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Oct 12, 2019
1 parent 0b464ed commit ef5fe63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
"@phosphor/virtualdom": "^1.2.0",
"@phosphor/widgets": "^1.9.0",
"react": "~16.8.4",
"react-dom": "~16.8.4",
"typestyle": "^2.0.1"
},
"devDependencies": {
"@types/react": "~16.8.18",
"@types/react-dom": "^16.8.4",
"@types/webpack-env": "^1.13.9",
"rimraf": "~2.6.2",
"typedoc": "^0.14.2",
Expand Down
17 changes: 15 additions & 2 deletions packages/ui-components/src/icon/jlicon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { classes } from 'typestyle';
import { iconStyle, IIconStyle } from '../style/icon';

Expand All @@ -10,10 +11,11 @@ export class JLIcon {
) {}

resolveSvg(title?: string): HTMLElement | null {
const svgElement = new DOMParser().parseFromString(
const svgDoc = new DOMParser().parseFromString(
this.svgstr,
'image/svg+xml'
).documentElement;
);
const svgElement = svgDoc.documentElement;

if (svgElement.getElementsByTagName('parsererror').length > 0) {
const errmsg = `SVG HTML was malformed for icon name: ${name}`;
Expand Down Expand Up @@ -61,6 +63,13 @@ export class JLIcon {
return container;
}

phosphor(props: JLIcon.IProps): JLIcon.IPhosphor {
return {
render: (host: HTMLElement) =>
ReactDOM.render(<this.react {...props} />, host)
};
}

protected _initReact() {
const component = React.forwardRef(
(
Expand Down Expand Up @@ -124,6 +133,10 @@ export namespace JLIcon {
*/
title?: string;
}

export interface IPhosphor {
render: (host: HTMLElement) => void;
}
}

namespace Private {
Expand Down

0 comments on commit ef5fe63

Please sign in to comment.