@@ -23,6 +23,7 @@ const PropertiesBar = () => {
23
23
24
24
const [ stroke , setStroke ] = useState ( "#000000" ) ;
25
25
const [ background , setBackground ] = useState ( null ) ;
26
+ const [ fillStyle , setFillStyle ] = useState ( 'solid' ) ;
26
27
const [ strokeStyle , setStrokeStyle ] = useState ( [ ] ) ;
27
28
const [ strokeWidth , setStrokeWidth ] = useState ( 2 ) ;
28
29
const [ sharp , setSharp ] = useState ( false ) ;
@@ -51,10 +52,20 @@ const PropertiesBar = () => {
51
52
'#09203f' ,
52
53
]
53
54
55
+ const fillStyles = [
56
+ 'solid' ,
57
+ 'zigzag' ,
58
+ 'cross-hatch' ,
59
+ // 'dots',
60
+ 'sunburst' ,
61
+ 'dashed' ,
62
+ 'zigzag-line'
63
+ ]
64
+
54
65
// useEffect used to preload the already applied properties on the elements
55
66
useEffect ( ( ) => {
56
67
57
- if ( selectedElement != null ) {
68
+ if ( selectedElement !== null ) {
58
69
element = elements [ parseInt ( selectedElement . id . split ( "#" ) [ 1 ] ) ] ;
59
70
if ( element === null || element === undefined ) {
60
71
@@ -67,8 +78,10 @@ const PropertiesBar = () => {
67
78
const currentSharp = GlobalProps . sharp ;
68
79
const bowing = GlobalProps . bowing ;
69
80
const currentFontSize = GlobalProps . fontSize ;
81
+ const currentFillStyle = GlobalProps . fillStyle ;
70
82
71
83
setBackground ( currentBackground ) ;
84
+ setFillStyle ( currentFillStyle ) ;
72
85
setStrokeStyle ( currentStrokeStyle ) ;
73
86
setStrokeWidth ( currentStrokeWidth ) ;
74
87
setSharp ( currentSharp ) ;
@@ -80,14 +93,16 @@ const PropertiesBar = () => {
80
93
81
94
const currentStroke = element . stroke
82
95
83
- if ( element . type != "text" ) {
96
+ if ( element . type !== "text" ) {
84
97
const currentBackground = element . fill ;
98
+ const currentFillStyle = element . fillStyle ;
85
99
const currentStrokeStyle = element . strokeStyle ;
86
100
const currentStrokeWidth = element . strokeWidth ;
87
101
const currentSharp = element . sharp ;
88
102
const bowing = element . bowing ;
89
103
90
104
setBackground ( currentBackground ) ;
105
+ setFillStyle ( currentFillStyle ) ;
91
106
setStrokeStyle ( currentStrokeStyle ) ;
92
107
setStrokeWidth ( currentStrokeWidth ) ;
93
108
setSharp ( currentSharp ) ;
@@ -103,13 +118,15 @@ const PropertiesBar = () => {
103
118
104
119
const currentStroke = GlobalProps . stroke
105
120
const currentBackground = GlobalProps . fill ;
121
+ const currentFillStyle = GlobalProps . fillStyle ;
106
122
const currentStrokeStyle = GlobalProps . strokeStyle ;
107
123
const currentStrokeWidth = GlobalProps . strokeWidth ;
108
124
const currentSharp = GlobalProps . sharp ;
109
125
const bowing = GlobalProps . bowing ;
110
126
const currentFontSize = GlobalProps . fontSize ;
111
127
112
128
setBackground ( currentBackground ) ;
129
+ setFillStyle ( currentFillStyle ) ;
113
130
setStrokeStyle ( currentStrokeStyle ) ;
114
131
setStrokeWidth ( currentStrokeWidth ) ;
115
132
setSharp ( currentSharp ) ;
@@ -132,6 +149,7 @@ const PropertiesBar = () => {
132
149
if ( selectedElement === null || tool !== 'selection' ) {
133
150
GlobalProps . stroke = stroke ;
134
151
GlobalProps . fill = background ;
152
+ GlobalProps . fillStyle = fillStyle ;
135
153
GlobalProps . strokeStyle = strokeStyle ;
136
154
GlobalProps . strokeWidth = strokeWidth ;
137
155
GlobalProps . sharp = sharp ;
@@ -163,7 +181,7 @@ const PropertiesBar = () => {
163
181
case "rectangle" :
164
182
case "diamond" :
165
183
case "ellipse" :
166
- options = { stroke : stroke , fill : background , strokeStyle : strokeStyle , strokeWidth : strokeWidth , sharp : sharp , bowing : bowing } ;
184
+ options = { stroke : stroke , fill : background , fillStyle : fillStyle , strokeStyle : strokeStyle , strokeWidth : strokeWidth , sharp : sharp , bowing : bowing } ;
167
185
break ;
168
186
case "text" :
169
187
options = { stroke : stroke , fontSize : fontSize } ;
@@ -228,7 +246,7 @@ const PropertiesBar = () => {
228
246
229
247
230
248
setChangedByUser ( false ) ;
231
- } , [ firstEffectCompleted , stroke , background , strokeStyle , strokeWidth , sharp , bowing , fontSize ] )
249
+ } , [ firstEffectCompleted , stroke , background , fillStyle , strokeStyle , strokeWidth , sharp , bowing , fontSize ] )
232
250
233
251
234
252
if ( tool === "eraser" ) {
@@ -299,6 +317,26 @@ const PropertiesBar = () => {
299
317
300
318
< SimpleColorPicker stroke = { background } setStroke = { setBackground } setChangedByUser = { setChangedByUser } > </ SimpleColorPicker > </ div >
301
319
320
+ </ CardContent >
321
+
322
+ : null }
323
+
324
+ { ( tool != 'pencil' && tool != 'text' && tool != 'line' && selectedElement === null ) || ( selectedElement != null && selectedElement . type != "pencil" && selectedElement . type != 'text' && selectedElement . type != "line" === true ) ? < CardContent >
325
+ < span className = 'text-xs' > Fill style</ span >
326
+ < div className = "flex flex-wrap max-w-[230px] gap-2 mt-1" >
327
+ { fillStyles . map ( ( style ) => (
328
+ < div key = { style } className = { `border border-1 cursor-pointer active:scale-105 inline-flex items-center rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10 ${ fillStyle === style ? 'border-2 border-black ' : null } ` }
329
+ onClick = { ( ) => {
330
+ setChangedByUser ( true ) ;
331
+ setFillStyle ( style ) ;
332
+ } } >
333
+ < p className = "text-xs rounded-md " >
334
+ { style }
335
+ </ p >
336
+ </ div >
337
+ ) ) }
338
+ </ div >
339
+
302
340
</ CardContent >
303
341
304
342
: null }
0 commit comments