diff --git a/plugins/carhop-blocks/src/chapter-section/block.json b/plugins/carhop-blocks/src/chapter-section/block.json index 5930feb..d83633b 100644 --- a/plugins/carhop-blocks/src/chapter-section/block.json +++ b/plugins/carhop-blocks/src/chapter-section/block.json @@ -9,7 +9,12 @@ "description": "Example block scaffolded with Create Block tool.", "example": {}, "supports": { - "html": false + "html": false, + "border": { + "color": true, + "style": true, + "width": true + } }, "textdomain": "carhop-blocks", "editorScript": "file:./index.js", @@ -65,10 +70,23 @@ "right" ] }, - "hasBackgroundColor": { + "hasBorder": { "type": "boolean", "default": false }, + "blockVariant": { + "type": "string", + "default": "framed", + "enum": [ + "framed", + "backgrounded", + "nude" + ] + }, + "borderColor": { + "type": "string", + "default": "#136f63" + }, "backgroundColor": { "type": "string", "default": "#ffffff" @@ -88,14 +106,6 @@ "variationA", "variationB" ] - }, - "backgroundOrientation": { - "type": "string", - "default": "left", - "enum": [ - "left", - "right" - ] } }, "usesContext": [ diff --git a/plugins/carhop-blocks/src/chapter-section/edit.js b/plugins/carhop-blocks/src/chapter-section/edit.js index 3b27613..fa6bf0c 100644 --- a/plugins/carhop-blocks/src/chapter-section/edit.js +++ b/plugins/carhop-blocks/src/chapter-section/edit.js @@ -7,6 +7,8 @@ import { MediaPlaceholder, useSetting, } from "@wordpress/block-editor"; +import shapeA from "./shapeA.jsx"; +import shapeB from "./shapeB.jsx"; import { lock, trash } from "@wordpress/icons"; import { ColorPalette } from "@wordpress/components"; import { @@ -19,6 +21,8 @@ import { import "./editor.scss"; import { isColorLight } from "../../_utilities/utilities"; +import ShapeA from "./shapeA.jsx"; +import ShapeB from "./shapeB.jsx"; export default function Edit({ attributes, setAttributes, ...props }) { const colors = useSetting("color.palette.theme"); @@ -30,12 +34,13 @@ export default function Edit({ attributes, setAttributes, ...props }) { coverAlt, coverId, coverSize, - hasBackgroundColor, backgroundColor, - backgroundOrientation, + blockWidth, textColor, shapeType, + blockVariant, + borderColor, } = attributes; function onDispositionChange(disposition) { @@ -61,34 +66,37 @@ export default function Edit({ attributes, setAttributes, ...props }) { setAttributes({ backgroundColor: value }); setHasLightBackground(value); } - function onHasBackgroundColorChange(value) { - setAttributes({ hasBackgroundColor: value }); - if (!value) { - setAttributes({ backgroundColor: null }); - } - } + function onCoverTypeChange(value) { setAttributes({ coverType: value }); } - function onBackgroundOrientationChange(value) { - setAttributes({ backgroundOrientation: value }); + function onBlockVariantChange(value) { + setAttributes({ blockVariant: value }); + + if (value === "framed" || value === "nude") { + setAttributes({ backgroundColor: "#fff" }); + setAttributes({ hasLightBackground: true }); + } } + function setHasLightBackground(backgroundColor) { if (!backgroundColor) return; const isLightBackgroundColor = isColorLight(backgroundColor); - console.log(isLightBackgroundColor); setAttributes({ hasLightBackground: isLightBackgroundColor }); } + console.log(backgroundColor); + console.log(isColorLight(backgroundColor)); return ( <> + {/* Largeur du bloc */} + {/* Modèle de bloc */} + + + + + + {/* Disposition */} + + + + + + {blockVariant === "backgrounded" && ( + + setAttributes({ shapeType: value })} + value={shapeType} + > + + + + + + )} + {blockVariant === "framed" && ( + + setAttributes({ shapeType: value })} + value={shapeType} + > + + + + setAttributes({ borderColor: value })} + /> + + )} + {coverUrl && {coverAlt}}
@@ -141,16 +234,7 @@ export default function Edit({ attributes, setAttributes, ...props }) { - - - - + - - - {hasBackgroundColor && ( - <> - setAttributes({ shapeType: value })} - value={shapeType} - > - - - - - - )} - -
- {hasBackgroundColor && + {blockVariant === "backgrounded" && backgroundColor && shapeType === "variationA" && ( - <> - - - - + )} - {hasBackgroundColor && + {blockVariant === "backgrounded" && backgroundColor && shapeType === "variationB" && ( - <> - - - - + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "variationA" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "variationB" && ( + )}
diff --git a/plugins/carhop-blocks/src/chapter-section/save.js b/plugins/carhop-blocks/src/chapter-section/save.js index 07c22a6..1dedf2e 100644 --- a/plugins/carhop-blocks/src/chapter-section/save.js +++ b/plugins/carhop-blocks/src/chapter-section/save.js @@ -1,4 +1,6 @@ import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor"; +import ShapeA from "./shapeA.jsx"; +import ShapeB from "./shapeB.jsx"; export default function save({ attributes }) { const { hasLightBackground, @@ -8,64 +10,57 @@ export default function save({ attributes }) { coverSize, coverType, backgroundColor, - hasBackgroundColor, - backgroundOrientation, blockWidth, textColor, shapeType, + blockVariant, + borderColor, } = attributes; return (
- {hasBackgroundColor && backgroundColor && shapeType === "variationA" && ( - <> - - - - - )} - {hasBackgroundColor && backgroundColor && shapeType === "variationB" && ( - <> - - - - - )} + {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "variationA" && ( + + )} + {blockVariant === "backgrounded" && + backgroundColor && + shapeType === "variationB" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "variationA" && ( + + )} + {blockVariant === "framed" && + backgroundColor && + shapeType === "variationB" && ( + + )}
diff --git a/plugins/carhop-blocks/src/chapter-section/shapeA.jsx b/plugins/carhop-blocks/src/chapter-section/shapeA.jsx new file mode 100644 index 0000000..466ef80 --- /dev/null +++ b/plugins/carhop-blocks/src/chapter-section/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/chapter-section/shapeB.jsx b/plugins/carhop-blocks/src/chapter-section/shapeB.jsx new file mode 100644 index 0000000..9821769 --- /dev/null +++ b/plugins/carhop-blocks/src/chapter-section/shapeB.jsx @@ -0,0 +1,30 @@ +import React from "react"; + +export default function ShapeB({ + backgroundOrientation, + backgroundColor, + borderColor, +}) { + return ( + + + + ); +}