Skip to content

Commit ef5fe63

Browse files
committed
experimenting with blending phosphor/react vdom
1 parent 0b464ed commit ef5fe63

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/ui-components/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
"@phosphor/virtualdom": "^1.2.0",
4242
"@phosphor/widgets": "^1.9.0",
4343
"react": "~16.8.4",
44+
"react-dom": "~16.8.4",
4445
"typestyle": "^2.0.1"
4546
},
4647
"devDependencies": {
4748
"@types/react": "~16.8.18",
49+
"@types/react-dom": "^16.8.4",
4850
"@types/webpack-env": "^1.13.9",
4951
"rimraf": "~2.6.2",
5052
"typedoc": "^0.14.2",

packages/ui-components/src/icon/jlicon.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
23
import { classes } from 'typestyle';
34
import { iconStyle, IIconStyle } from '../style/icon';
45

@@ -10,10 +11,11 @@ export class JLIcon {
1011
) {}
1112

1213
resolveSvg(title?: string): HTMLElement | null {
13-
const svgElement = new DOMParser().parseFromString(
14+
const svgDoc = new DOMParser().parseFromString(
1415
this.svgstr,
1516
'image/svg+xml'
16-
).documentElement;
17+
);
18+
const svgElement = svgDoc.documentElement;
1719

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

66+
phosphor(props: JLIcon.IProps): JLIcon.IPhosphor {
67+
return {
68+
render: (host: HTMLElement) =>
69+
ReactDOM.render(<this.react {...props} />, host)
70+
};
71+
}
72+
6473
protected _initReact() {
6574
const component = React.forwardRef(
6675
(
@@ -124,6 +133,10 @@ export namespace JLIcon {
124133
*/
125134
title?: string;
126135
}
136+
137+
export interface IPhosphor {
138+
render: (host: HTMLElement) => void;
139+
}
127140
}
128141

129142
namespace Private {

0 commit comments

Comments
 (0)