From d3ad12d6537168b5aa88cac02d2e35dffcbbd9dc Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 25 Mar 2026 16:02:08 +0100 Subject: [PATCH] FEATURE refactoriong component to handle background shapes --- .../carhop-blocks/src/content-box/block.json | 14 ++ plugins/carhop-blocks/src/content-box/edit.js | 148 +++++++++++++----- plugins/carhop-blocks/src/content-box/save.js | 40 ++++- .../carhop-blocks/src/content-box/shapeA.jsx | 32 ++++ .../carhop-blocks/src/content-box/shapeB.jsx | 30 ++++ .../carhop-blocks/src/content-box/shapeC.jsx | 32 ++++ 6 files changed, 257 insertions(+), 39 deletions(-) create mode 100644 plugins/carhop-blocks/src/content-box/shapeA.jsx create mode 100644 plugins/carhop-blocks/src/content-box/shapeB.jsx create mode 100644 plugins/carhop-blocks/src/content-box/shapeC.jsx diff --git a/plugins/carhop-blocks/src/content-box/block.json b/plugins/carhop-blocks/src/content-box/block.json index a2d2b5c..c316772 100644 --- a/plugins/carhop-blocks/src/content-box/block.json +++ b/plugins/carhop-blocks/src/content-box/block.json @@ -38,10 +38,24 @@ "type": "string", "default": "inherit" }, + "borderColor": { + "type": "string", + "default": null + }, "blockVariant": { "type": "string", "default": "framed" }, + "shapeType": { + "type": "string", + "default": "straight", + "enum": [ + "straight", + "shapeA", + "shapeB", + "shapeC" + ] + }, "blockWidth": { "type": "string", "default": "full", diff --git a/plugins/carhop-blocks/src/content-box/edit.js b/plugins/carhop-blocks/src/content-box/edit.js index fe658f1..ead398c 100644 --- a/plugins/carhop-blocks/src/content-box/edit.js +++ b/plugins/carhop-blocks/src/content-box/edit.js @@ -24,8 +24,12 @@ import { Button, CheckboxControl, ColorPalette, + SelectControl, } from "@wordpress/components"; +import ShapeA from "./shapeA.jsx"; +import ShapeB from "./shapeB.jsx"; +import ShapeC from "./shapeC.jsx"; import { filterBgColors, filterTextColors } from "./utilities"; export default function Edit({ attributes, setAttributes, ...props }) { @@ -38,6 +42,8 @@ export default function Edit({ attributes, setAttributes, ...props }) { hasLightBackground, blockVariant, blockWidth, + shapeType, + borderColor, } = attributes; // Détecter le type de post actuel @@ -84,6 +90,9 @@ export default function Edit({ attributes, setAttributes, ...props }) { setAttributes({ hasLightBackground: true }); } } + + console.log(shapeType); + console.log(blockVariant); return ( <> @@ -119,48 +128,85 @@ export default function Edit({ attributes, setAttributes, ...props }) { - - {blockVariant === "backgrounded" || - (blockVariant === "framed-backgrounded" && ( - - -

Couleur de fond

-
- - <> - - - -
- ))} - - {(blockVariant === "backgrounded" || - blockVariant === "framed-backgrounded") && - postType !== "articles" && ( - - -

Couleur du texte

-
- - - -
- )} + + {(blockVariant === "backgrounded" || + blockVariant === "framed-backgrounded") && ( + + setAttributes({ shapeType: value })} + value={shapeType} + > + + + + + + + setAttributes({ shapeType: value })} + value={shapeType} + options={[ + { + disabled: true, + label: "Type de forme", + value: "", + }, + { + label: "Droite", + value: "straight", + }, + { + label: "Forme A", + value: "shapeA", + }, + { + label: "Forme B", + value: "shapeB", + }, + { + label: "Forme C", + value: "shapeC", + }, + ]} + /> + + + + )} + + {(blockVariant === "backgrounded" || + blockVariant === "framed-backgrounded") && + postType !== "articles" && ( + + + + )}
+ {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "shapeA" && ( + + )} + {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "shapeB" && ( + + )} + {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "shapeC" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "shapeA" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "shapeB" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "shapeC" && ( + + )}
+ {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "shapeA" && ( + + )} + {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "shapeB" && ( + + )} + {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "shapeC" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "shapeA" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "shapeB" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "shapeC" && ( + + )}
diff --git a/plugins/carhop-blocks/src/content-box/shapeA.jsx b/plugins/carhop-blocks/src/content-box/shapeA.jsx new file mode 100644 index 0000000..f92f323 --- /dev/null +++ b/plugins/carhop-blocks/src/content-box/shapeA.jsx @@ -0,0 +1,32 @@ +import React from "react"; + +export default function ShapeA({ + backgroundOrientation, + backgroundColor, + borderColor, +}) { + return ( + + + + ); +} diff --git a/plugins/carhop-blocks/src/content-box/shapeB.jsx b/plugins/carhop-blocks/src/content-box/shapeB.jsx new file mode 100644 index 0000000..560d1d6 --- /dev/null +++ b/plugins/carhop-blocks/src/content-box/shapeB.jsx @@ -0,0 +1,30 @@ +import React from "react"; + +export default function ShapeB({ + backgroundOrientation, + backgroundColor, + borderColor, +}) { + return ( + + + + ); +} diff --git a/plugins/carhop-blocks/src/content-box/shapeC.jsx b/plugins/carhop-blocks/src/content-box/shapeC.jsx new file mode 100644 index 0000000..8725dc9 --- /dev/null +++ b/plugins/carhop-blocks/src/content-box/shapeC.jsx @@ -0,0 +1,32 @@ +import React from "react"; + +export default function ShapeB({ + backgroundOrientation, + backgroundColor, + borderColor, +}) { + return ( + <> + + + + + ); +}