11import type { IBrickBlock } from '@/@types/brick' ;
2- import { useEffect , useRef , useState } from 'react' ;
32
43// -------------------------------------------------------------------------------------------------
54
65export default function ( props : { instance : IBrickBlock } ) : JSX . Element {
76 const { instance } = props ;
8- const [ svgString , setSvgString ] = useState < string > ( '' ) ;
9- const label = useRef < SVGTextElement > ( null ) ;
10- const [ argLabels , setArgLabels ] = useState < string [ ] > ( [ ] ) ;
11-
12- useEffect ( ( ) => {
13- const labelWidth = label . current ?. getBBox ( ) ;
14- const args = instance . args ;
15- let argMaxWidth = 0 ;
16- for ( let arg in args ) {
17- setArgLabels ( ( argLabels ) => [ ...argLabels , args [ arg ] . label ] ) ;
18- argMaxWidth = Math . max ( argMaxWidth , args [ arg ] . label . length ) ;
19- }
20- const width = ( labelWidth ?. width as number ) + argMaxWidth * 12.8 + 40 ;
21- instance . labelWidth = width ;
22- setSvgString ( instance . SVGpaths [ 0 ] ) ;
23- } , [ ] ) ;
247
258 return (
26- < g transform = { `scale(${ instance . scale } )` } id = "svg1" >
9+ < g transform = { `scale(${ instance . scale } )` } >
2710 < path
28- d = { svgString }
11+ d = { instance . SVGpaths [ 0 ] }
2912 style = { {
3013 fill : instance . colorBg as string ,
3114 fillOpacity : 1 ,
@@ -35,30 +18,6 @@ export default function (props: { instance: IBrickBlock }): JSX.Element {
3518 strokeOpacity : 1 ,
3619 } }
3720 />
38- < text
39- ref = { label }
40- x = "12%"
41- y = "8%"
42- dominantBaseline = "middle"
43- style = { {
44- fontSize : '0.8em' ,
45- } }
46- >
47- { instance . label }
48- </ text >
49- { argLabels . map ( ( argLabel , index ) => (
50- < text
51- key = { index }
52- x = { `${ ( label . current ?. getBBox ( ) . width as number ) + ( index + 1 ) } %` }
53- y = "8%"
54- dominantBaseline = "middle"
55- style = { {
56- fontSize : '0.8em' ,
57- } }
58- >
59- { argLabel }
60- </ text >
61- ) ) }
6221 </ g >
6322 ) ;
6423}
0 commit comments