@@ -125,95 +125,95 @@ const CreateShape = (props) => {
125125 }
126126
127127 function addNewVerticeCoordinates ( x , y , number ) {
128- const xPercentage = Math . round ( ( x / 280.0 ) * 100.0 ) ;
129- const yPercentage = Math . round ( ( y / 280.0 ) * 100.0 ) ;
128+ const xPercentage = Math . round ( ( x / 280.0 ) * 100.0 ) ;
129+ const yPercentage = Math . round ( ( y / 280.0 ) * 100.0 ) ;
130130
131- let newVerticeCoordinates = shapeInformation . verticeCoordinates ;
132- newVerticeCoordinates [ number ] = {
133- "x" : xPercentage + "%" ,
134- "y" : yPercentage + "%"
135- }
131+ let newVerticeCoordinates = shapeInformation . verticeCoordinates ;
132+ newVerticeCoordinates [ number ] = {
133+ "x" : xPercentage + "%" ,
134+ "y" : yPercentage + "%"
135+ }
136136
137- return newVerticeCoordinates ;
137+ return newVerticeCoordinates ;
138138 }
139139
140140 function generateNewFormula ( newVerticeCoordinates ) {
141- let newFormula = shapeInformation . clipPathType + "(" ;
141+ let newFormula = shapeInformation . clipPathType + "(" ;
142142
143- for ( let i = 0 ; i < newVerticeCoordinates . length ; i ++ ) {
144- let newX = newVerticeCoordinates [ i ] . x ;
145- let newY = newVerticeCoordinates [ i ] . y ;
143+ for ( let i = 0 ; i < newVerticeCoordinates . length ; i ++ ) {
144+ let newX = newVerticeCoordinates [ i ] . x ;
145+ let newY = newVerticeCoordinates [ i ] . y ;
146146
147- i === newVerticeCoordinates . length - 1 ? newFormula = newFormula + newX + " " + newY + ")" : newFormula = newFormula + newX + " " + newY + ", " ;
148- }
147+ i === newVerticeCoordinates . length - 1 ? newFormula = newFormula + newX + " " + newY + ")" : newFormula = newFormula + newX + " " + newY + ", " ;
148+ }
149149
150- return newFormula ;
150+ return newFormula ;
151151 }
152152
153153 function handleFormulaChange ( formula , edgeVerticeNumber , clipPathType ) {
154- let newVerticeCoordinates = [ ] ;
155-
156- if ( clipPathType === "polygon" ) {
157- let formulaNumbers = formula . slice ( formula . indexOf ( "(" ) + 1 , formula . indexOf ( ")" ) ) ;
158- formulaNumbers = formulaNumbers . split ( ", " ) ;
159- newVerticeCoordinates = formulaNumbers . map ( x => {
160- let percentageArray = x . split ( " " ) ;
161- return {
162- "x" : percentageArray [ 0 ] ,
163- "y" : percentageArray [ 1 ] ,
164- }
165- } ) ;
166- }
167-
168- setShapeInformation ( prevState => {
169- return {
170- ...prevState ,
171- "formula" : formula . includes ( "(" ) && formula . includes ( ")" ) ? formula : prevState . formula ,
172- "clipPathType" : clipPathType === null ? prevState . clipPathType : clipPathType ,
173- "vertices" : edgeVerticeNumber ,
174- "edges" : edgeVerticeNumber ,
175- "verticeCoordinates" : newVerticeCoordinates ,
154+ let newVerticeCoordinates = [ ] ;
155+
156+ if ( clipPathType === "polygon" ) {
157+ let formulaNumbers = formula . slice ( formula . indexOf ( "(" ) + 1 , formula . indexOf ( ")" ) ) ;
158+ formulaNumbers = formulaNumbers . split ( ", " ) ;
159+ newVerticeCoordinates = formulaNumbers . map ( x => {
160+ let percentageArray = x . split ( " " ) ;
161+ return {
162+ "x" : percentageArray [ 0 ] ,
163+ "y" : percentageArray [ 1 ] ,
164+ }
165+ } ) ;
176166 }
177- } ) ;
178- }
179167
180- function handleClipPathChange ( clipPathType ) {
181- if ( clipPathType === "polygon" ) {
182- setShapeInformation ( {
183- ...shapeInformation ,
184- "name" : "Tilted Square" ,
185- "type" : "tiltedSquare" ,
186- "formula" : "polygon(10% 10%, 90% 10%, 90% 90%, 10% 80%)" ,
168+ setShapeInformation ( prevState => {
169+ return {
170+ ...prevState ,
171+ "formula" : formula . includes ( "(" ) && formula . includes ( ")" ) ? formula : prevState . formula ,
172+ "clipPathType" : clipPathType === null ? prevState . clipPathType : clipPathType ,
173+ "vertices" : edgeVerticeNumber ,
174+ "edges" : edgeVerticeNumber ,
175+ "verticeCoordinates" : newVerticeCoordinates ,
176+ }
187177 } ) ;
188- }
178+ }
189179
190- if ( clipPathType === "circle" ) {
191- setShapeInformation ( {
192- ...shapeInformation ,
193- "name" : "Circle" ,
194- "type" : "circle" ,
195- "formula" : "circle(50% at 50% 50%)" ,
196- } ) ;
197- }
180+ function handleClipPathChange ( clipPathType ) {
181+ if ( clipPathType === "polygon" ) {
182+ setShapeInformation ( {
183+ ...shapeInformation ,
184+ "name" : "Tilted Square" ,
185+ "type" : "tiltedSquare" ,
186+ "formula" : "polygon(10% 10%, 90% 10%, 90% 90%, 10% 80%)" ,
187+ } ) ;
188+ }
198189
199- if ( clipPathType === "ellipse " ) {
200- setShapeInformation ( {
201- ...shapeInformation ,
202- "name" : "Ellipse " ,
203- "type" : "ellipse " ,
204- "formula" : "ellipse(25% 40 % at 50% 50%)" ,
205- } ) ;
206- }
190+ if ( clipPathType === "circle " ) {
191+ setShapeInformation ( {
192+ ...shapeInformation ,
193+ "name" : "Circle " ,
194+ "type" : "circle " ,
195+ "formula" : "circle(50 % at 50% 50%)" ,
196+ } ) ;
197+ }
207198
208- setShapeInformation ( prevState => {
209- return {
210- ...prevState ,
211- "clipPathType " : clipPathType ,
212- "edges" : clipPathType === "polygon" ? 4 : 0 ,
213- "vertices" : clipPathType === "polygon" ? 4 : 0 ,
214- "notes" : "" ,
199+ if ( clipPathType === "ellipse" ) {
200+ setShapeInformation ( {
201+ ...shapeInformation ,
202+ "name " : "Ellipse" ,
203+ "type" : "ellipse" ,
204+ "formula" : "ellipse(25% 40% at 50% 50%)" ,
205+ } ) ;
215206 }
216- } )
207+
208+ setShapeInformation ( prevState => {
209+ return {
210+ ...prevState ,
211+ "clipPathType" : clipPathType ,
212+ "edges" : clipPathType === "polygon" ? 4 : 0 ,
213+ "vertices" : clipPathType === "polygon" ? 4 : 0 ,
214+ "notes" : "" ,
215+ }
216+ } )
217217 }
218218
219219 const [ validated , setValidated ] = useState ( false ) ;
@@ -236,25 +236,36 @@ const CreateShape = (props) => {
236236 onHide = { props . handleClose }
237237 backdrop = "static"
238238 >
239- < Modal . Header >
239+ < Modal . Header closeButton >
240240 < Modal . Title > Create Shape</ Modal . Title >
241241 </ Modal . Header >
242242 < Modal . Body >
243243 < Container fluid >
244244 < Row lg = { 2 } md = { 1 } sm = { 1 } xs = { 1 } >
245245 < Col >
246- < ShapeForm shapeInformation = { shapeInformation } handleChange = { handleFormChange } handleSubmit = { handleSubmit } validated = { validated } />
246+ < ShapeForm
247+ shapeInformation = { shapeInformation }
248+ handleChange = { handleFormChange }
249+ handleSubmit = { handleSubmit }
250+ validated = { validated }
251+ />
247252 </ Col >
248253 < Col >
249- < ShapePreview shapeInformation = { shapeInformation } handleChange = { handlePreviewChange } />
254+ < ShapePreview
255+ shapeInformation = { shapeInformation }
256+ handleChange = { handlePreviewChange }
257+ />
250258 </ Col >
251259 </ Row >
252260 </ Container >
253261 </ Modal . Body >
254262 < Modal . Footer >
255- < Button onClick = { ( ) => props . handleClose ( ) } >
263+ < Button onClick = { ( ) => props . handleClose ( ) } variant = "outline-info" >
256264 Close
257265 </ Button >
266+ < Button variant = "secondary" type = "submit" form = "createShapeForm" >
267+ Save
268+ </ Button >
258269 </ Modal . Footer >
259270 </ Modal >
260271 </ >
0 commit comments