Skip to content

Commit 10ab8bd

Browse files
committed
feat: fixed issue with show outside of clipped area toggle not working
1 parent e6995a6 commit 10ab8bd

2 files changed

Lines changed: 38 additions & 46 deletions

File tree

components/core/CreateShape.js

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ const CreateShape = (props) => {
3838
]
3939
});
4040

41-
const handleFormChange = (event) => {
42-
const name = event.target.name || event.type;
43-
const value = event.target.value === "checkbox" ? event.target.checked : event.target.value;
41+
function handleChange(event, data, number) {
42+
const name = event.target.name || event.type;
43+
const value = event.target.type === "checkbox" ? event.target.checked : event.target.value;
4444

45-
console.log(event);
45+
console.log(event, data);
4646

4747
if (name === "name") {
4848
setShapeInformation({
49-
...shapeInformation,
50-
"name": value,
51-
"type": value.toLowerCase(),
49+
...shapeInformation,
50+
"name": value,
51+
"type": value.toLowerCase(),
5252
});
5353
} else if (name === "formula") {
54-
const edgeVerticeNumber = shapeInformation.clipPathType === "polygon" ? value.split(",").length : 0;
54+
const edgeVerticeNumber = shapeInformation.clipPathType === "polygon" ? value.split(",").length: 0;
5555

5656
if (value === "") {
5757
handleFormulaChange(shapeInformation.clipPathType + "()", edgeVerticeNumber)
@@ -64,65 +64,55 @@ const CreateShape = (props) => {
6464
} else {
6565
handleFormulaChange(value, edgeVerticeNumber);
6666
}
67-
} else if (name === "clipPathType") {
68-
handleClipPathChange(value);
69-
} else {
70-
setShapeInformation({
71-
...shapeInformation,
72-
[name]: value,
73-
});
74-
}
75-
}
76-
77-
function handlePreviewChange(event, data, number) {
78-
const name = event.target.name || event.type;
79-
80-
console.log(event, data);
81-
82-
if (name === "mousemove") {
67+
} else if (name === "mousemove") {
8368
const newVerticeCoordinates = addNewVerticeCoordinates(data.x, data.y, number);
8469
const newFormula = generateNewFormula(newVerticeCoordinates);
8570

8671
setShapeInformation({
87-
...shapeInformation,
88-
"verticeCoordinates": newVerticeCoordinates,
89-
"formula": newFormula,
72+
...shapeInformation,
73+
"verticeCoordinates": newVerticeCoordinates,
74+
"formula": newFormula,
9075
});
9176
} else if (name === "click" && event.target.id === "shapeShadow") {
9277
const newVerticeCoordinates = addNewVerticeCoordinates(event.nativeEvent.offsetX, event.nativeEvent.offsetY, shapeInformation.verticeCoordinates.length);
9378
const newFormula = generateNewFormula(newVerticeCoordinates);
9479

9580
setShapeInformation({
96-
...shapeInformation,
97-
"vertices": shapeInformation.vertices + 1,
98-
"edges": shapeInformation.edges + 1,
99-
"verticeCoordinates": newVerticeCoordinates,
100-
"formula": newFormula,
81+
...shapeInformation,
82+
"vertices": shapeInformation.vertices + 1,
83+
"edges": shapeInformation.edges + 1,
84+
"verticeCoordinates": newVerticeCoordinates,
85+
"formula": newFormula,
10186
});
10287
} else if ((event.target.id.includes("deleteButton") || event.target.localName === "line") && number !== undefined) {
10388

104-
console.log("worked");
105-
10689
let newVerticeCoordinates = [];
10790

10891
for (let i = 0; i < shapeInformation.verticeCoordinates.length; i++) {
109-
if (i !== number) {
110-
newVerticeCoordinates.push(shapeInformation.verticeCoordinates[i]);
111-
}
92+
if (i !== number) {
93+
newVerticeCoordinates.push(shapeInformation.verticeCoordinates[i]);
94+
}
11295
}
11396

11497
const newFormula = generateNewFormula(newVerticeCoordinates);
11598

11699
setShapeInformation({
117-
...shapeInformation,
118-
"vertices": shapeInformation.vertices - 1,
119-
"edges": shapeInformation.edges - 1,
120-
"verticeCoordinates": newVerticeCoordinates,
121-
"formula": newFormula,
100+
...shapeInformation,
101+
"vertices": shapeInformation.vertices - 1,
102+
"edges": shapeInformation.edges - 1,
103+
"verticeCoordinates": newVerticeCoordinates,
104+
"formula": newFormula,
122105
});
123106

107+
} else if (name === "clipPathType") {
108+
handleClipPathChange(value);
109+
} else {
110+
setShapeInformation({
111+
...shapeInformation,
112+
[name]: value,
113+
});
124114
}
125-
}
115+
}
126116

127117
function addNewVerticeCoordinates(x ,y, number) {
128118
const xPercentage = Math.round((x / 280.0) * 100.0);
@@ -232,7 +222,7 @@ const CreateShape = (props) => {
232222
<Modal
233223
show={props.show}
234224
centered
235-
size="xl"
225+
size="lg"
236226
onHide={props.handleClose}
237227
backdrop="static"
238228
>
@@ -245,15 +235,15 @@ const CreateShape = (props) => {
245235
<Col>
246236
<ShapeForm
247237
shapeInformation={shapeInformation}
248-
handleChange={handleFormChange}
238+
handleChange={handleChange}
249239
handleSubmit={handleSubmit}
250240
validated={validated}
251241
/>
252242
</Col>
253243
<Col>
254244
<ShapePreview
255245
shapeInformation={shapeInformation}
256-
handleChange={handlePreviewChange}
246+
handleChange={handleChange}
257247
/>
258248
</Col>
259249
</Row>

components/utils/ShapePreview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const ShapePreview = (props) => {
8585
name="showShadow"
8686
id="modal-custom-switch"
8787
label="Show Outside of the Clipped Area"
88+
checked={props.shapeInformation.showShadow}
89+
onChange={(e) => props.handleChange(e)}
8890
/>
8991
</Form>
9092

0 commit comments

Comments
 (0)