1- import { CSSProperties } from 'react' ;
1+ import { VFC , CSSProperties } from 'react' ;
2+
3+ type Position = {
4+ top ?: number ; // px
5+ right ?: number ; // px
6+ bottom ?: number ; // px
7+ left ?: number ; // px
8+ }
9+
10+ type TextWidgetProps = {
11+ text : string ;
12+ textColor ?: string ;
13+ backgroundColor ?: string ;
14+ edgeWeight ?: number ; // px
15+ edgeColor ?: string ;
16+ width ?: number ; // px
17+ height ?: number ; // px
18+ padding ?: string ; // px
19+ position ?: Position ;
20+ } ;
21+
22+
23+ const defaultStyle : CSSProperties = {
24+ boxSizing : 'border-box' ,
25+ whiteSpace : 'pre-wrap' ,
26+ overflow : 'hidden' ,
27+ textColor : 'white' ,
28+ backgroundColor : 'rgba(0, 0, 0 0.1)' ,
29+ edgeWeight : 1 ,
30+ edgeColor : 'black' ,
31+ width : 320 ,
32+ height : 540 ,
33+ padding : '4px 8px' ,
34+ position : 'absolute' ,
35+ } ;
36+
37+ const TextWidget : VFC < TextWidgetProps > = ( {
38+ text,
39+ textColor,
40+ backgroundColor,
41+ edgeWeight,
42+ edgeColor,
43+ width,
44+ height,
45+ padding,
46+ position,
47+ } ) => {
48+ const ew = edgeWeight || 1 ;
49+ const edge_color = edgeColor || 'black' ;
250
3- const TextWidget = ( { text } ) => {
4- const edge_color = 'black' ;
5- const ew = 1 ;
651 const edge = [
752 `${ ew } px ${ ew } px 0 ${ edge_color } ` ,
853 `-${ ew } px -${ ew } px 0 ${ edge_color } ` ,
@@ -15,18 +60,26 @@ const TextWidget = ({ text }) => {
1560 ] . join ( ', ' ) ;
1661
1762 const style : CSSProperties = {
18- boxSizing : 'border-box' ,
19- position : 'absolute' ,
20- right : 0 ,
21- width : '320px' ,
22- height : '540px' ,
23- padding : '4px 8px' ,
24- color : 'white' ,
63+ ...defaultStyle ,
64+ width : `${ width || 320 } px` ,
65+ height : `${ height | 540 } px` ,
66+ padding : padding || '4px 8px' ,
67+ color : textColor || 'white' ,
2568 textShadow : edge ,
26- backgroundColor : 'rgba(0, 0, 0, 0.1)' ,
27- whiteSpace : 'pre-wrap' ,
69+ backgroundColor : backgroundColor || 'rgba(0, 0, 0, 0.1)' ,
2870 } ;
2971
72+ if ( position ?. top || position ?. right || position ?. bottom || position ?. left ) {
73+ if ( position ?. top ) style . top = position . top ;
74+ if ( position ?. right ) style . right = position . right ;
75+ if ( position ?. bottom ) style . bottom = position . bottom ;
76+ if ( position ?. left ) style . left = position . left ;
77+ } else {
78+ style . right = 0 ;
79+ }
80+
81+ console . log ( style ) ;
82+
3083 return < div style = { style } > { text } </ div > ;
3184} ;
3285
0 commit comments