11import '../../dist/omi-component.es.js' ;
2+ import './omi-tree' ;
23import React , { useEffect , useRef , useState } from 'react' ;
34import { createRoot } from 'react-dom/client' ;
45import reactify from '../index' ;
56
67const OmiReactComponent = reactify ( 'omi-component-demo' ) as any ;
8+ const OmiTree = reactify ( 'omi-tree' ) as any ;
79
810class ClassComponent extends React . Component < any , any > {
911 constructor ( props ) {
@@ -13,7 +15,7 @@ class ClassComponent extends React.Component<any, any> {
1315 } ;
1416 }
1517
16- ref = null ;
18+ ref : HTMLHeadingElement | null = null ;
1719
1820 componentDidMount ( ) : void {
1921 console . log ( 'componentDidMount' , this . ref ) ;
@@ -79,21 +81,51 @@ const App = (): any => {
7981 console . log ( 'ref' , ref . current )
8082 } , [ ] )
8183 console . log ( '=====App render=====' ) ;
82- return < div >
83- < OmiReactComponent
84- show = { true }
85- label = 'React Component'
86- complex = { complex }
87- ref = { ref }
88- camelCase = "camelCase"
89- style = { { color : 'red' } }
90- onMockClick = { ( _e : React . MouseEvent ) => { setComplex ( { name : 'Omi' } ) } }
91- renderFunction = { MockComponent }
92- >
93- < span className = 'content' > content</ span >
94- </ OmiReactComponent >
95- < button className = 'content' onClick = { btnClick } > change name</ button >
96- </ div >
84+ const [ treeData ] = useState ( [
85+ {
86+ name : 'Root' ,
87+ children : [
88+ { name : 'Child 1' } ,
89+ {
90+ name : 'Child 2' ,
91+ children : [
92+ { name : 'Grandchild 1' } ,
93+ { name : 'Grandchild 2' }
94+ ]
95+ }
96+ ]
97+ }
98+ ] ) ;
99+
100+ const handleNodeClick = ( e : CustomEvent ) => {
101+ console . log ( 'Node clicked:' , e . detail ) ;
102+ } ;
103+
104+ return (
105+ < div style = { { padding : '20px' } } >
106+ < OmiReactComponent
107+ show = { true }
108+ label = 'React Component'
109+ complex = { complex }
110+ ref = { ref }
111+ camelCase = "camelCase"
112+ style = { { color : 'red' } }
113+ onMockClick = { ( _e : React . MouseEvent ) => { setComplex ( { name : 'Omi' } ) } }
114+ renderFunction = { MockComponent }
115+ >
116+ < span className = 'content' > content</ span >
117+ </ OmiReactComponent >
118+ < button className = 'content' onClick = { btnClick } > change name</ button >
119+
120+ < div style = { { marginTop : '20px' , padding : '20px' , border : '1px solid #eee' , borderRadius : '4px' } } >
121+ < h2 > Tree Demo</ h2 >
122+ < OmiTree
123+ nodes = { treeData }
124+ onNodeClick = { handleNodeClick }
125+ />
126+ </ div >
127+ </ div >
128+ )
97129}
98130
99- createRoot ( document . getElementById ( 'app' ) ! ) . render ( < App /> as any ) ;
131+ createRoot ( document . getElementById ( 'app' ) ! ) . render ( < App /> ) ;
0 commit comments