FEATURE Handling TextColor variable and behaviours

This commit is contained in:
Antoine M 2025-07-03 17:02:38 +02:00
parent 7d773401ed
commit 7d6d758b46
7 changed files with 59 additions and 43 deletions

View File

@ -65,6 +65,10 @@
"type": "string", "type": "string",
"default": "#ffffff" "default": "#ffffff"
}, },
"textColor": {
"type": "string",
"default": "#136f63"
},
"backgroundOrientation": { "backgroundOrientation": {
"type": "string", "type": "string",
"default": "left", "default": "left",

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-primitives'), 'version' => '62a57819a79c88fe5e2d'); <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-primitives'), 'version' => 'd0e3316a30114b6e5e46');

View File

@ -41,7 +41,7 @@ const trash = /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx
\************************/ \************************/
/***/ ((module) => { /***/ ((module) => {
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"carhop-blocks/chapter-section","version":"0.1.0","title":" Section Chapitre","category":"carhop-blocks","icon":"smiley","description":"Example block scaffolded with Create Block tool.","example":{},"supports":{"html":false},"textdomain":"carhop-blocks","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","viewScript":"file:./view.js","render":"file:./render.php","attributes":{"align":{"type":"string","default":"full"},"blockWidth":{"type":"string","default":"full","enum":["full","contained"]},"coverUrl":{"type":"string"},"coverAlt":{"type":"string"},"coverId":{"type":"number"},"coverSize":{"type":"string","default":"large","enum":["small","medium","grande","large"]},"disposition":{"type":"string","default":"left","enum":["left","right"]},"hasBackgroundColor":{"type":"boolean","default":false},"backgroundColor":{"type":"string","default":"#ffffff"},"backgroundOrientation":{"type":"string","default":"left","enum":["left","right"]}},"usesContext":["postType","postId"]}'); module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"carhop-blocks/chapter-section","version":"0.1.0","title":" Section Chapitre","category":"carhop-blocks","icon":"smiley","description":"Example block scaffolded with Create Block tool.","example":{},"supports":{"html":false},"textdomain":"carhop-blocks","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","viewScript":"file:./view.js","render":"file:./render.php","attributes":{"align":{"type":"string","default":"full"},"blockWidth":{"type":"string","default":"full","enum":["full","contained"]},"coverUrl":{"type":"string"},"coverAlt":{"type":"string"},"coverId":{"type":"number"},"coverSize":{"type":"string","default":"large","enum":["small","medium","grande","large"]},"disposition":{"type":"string","default":"left","enum":["left","right"]},"hasBackgroundColor":{"type":"boolean","default":false},"backgroundColor":{"type":"string","default":"#ffffff"},"textColor":{"type":"string","default":"#136f63"},"backgroundOrientation":{"type":"string","default":"left","enum":["left","right"]}},"usesContext":["postType","postId"]}');
/***/ }), /***/ }),
@ -87,18 +87,14 @@ function Edit({
hasBackgroundColor, hasBackgroundColor,
backgroundColor, backgroundColor,
backgroundOrientation, backgroundOrientation,
blockWidth blockWidth,
textColor
} = attributes; } = attributes;
function onDispositionChange(disposition) { function onDispositionChange(disposition) {
setAttributes({ setAttributes({
disposition disposition
}); });
} }
function onCoverSizeChange(coverSize) {
setAttributes({
coverSize
});
}
function setCoverAttributes(cover) { function setCoverAttributes(cover) {
setAttributes({ setAttributes({
coverId: cover.id, coverId: cover.id,
@ -195,7 +191,9 @@ function Edit({
className: "deligraph-blocks__variant", className: "deligraph-blocks__variant",
isBlock: true, isBlock: true,
label: "Taille de l'image", label: "Taille de l'image",
onChange: onCoverSizeChange, onChange: coverSize => setAttributes({
coverSize
}),
value: coverSize, value: coverSize,
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.__experimentalToggleGroupControlOption, { children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.__experimentalToggleGroupControlOption, {
label: "Big", label: "Big",
@ -218,32 +216,32 @@ function Edit({
label: "Arri\xE8re plan color\xE9", label: "Arri\xE8re plan color\xE9",
checked: hasBackgroundColor, checked: hasBackgroundColor,
onChange: onHasBackgroundColorChange onChange: onHasBackgroundColorChange
}), hasBackgroundColor && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.Fragment, { }), hasBackgroundColor && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.Fragment, {
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.ColorPalette, { children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.ColorPalette, {
colors: colors, colors: colors,
value: backgroundColor, value: backgroundColor,
onChange: onBackgroundColorChange onChange: onBackgroundColorChange
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.__experimentalToggleGroupControl, { })
className: "deligraph-blocks__variant",
isBlock: true,
label: "Disposition",
onChange: onBackgroundOrientationChange,
value: backgroundOrientation,
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.__experimentalToggleGroupControlOption, {
label: "Gauche",
value: "left"
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.__experimentalToggleGroupControlOption, {
label: "Droite",
value: "right"
})]
})]
})] })]
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.PanelBody, {
className: "deligraph-blocks-components-image__panel-body",
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Couleur du texte", "deligraph-blocks"),
children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.ColorPalette, {
colors: colors,
value: textColor,
onChange: value => setAttributes({
textColor: value
})
})
})] })]
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsxs)("section", { }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsxs)("section", {
...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps)({ ...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps)({
className: `deligraph-blocks-chapter-section chapter-section chapter-section--${disposition} className: `deligraph-blocks-chapter-section chapter-section chapter-section--${disposition}
${blockWidth === "full" ? "chapter-section--width-full" : "chapter-section--width-contained"} ${blockWidth === "full" ? "chapter-section--width-full" : "chapter-section--width-contained"}
${hasBackgroundColor && backgroundColor ? "chapter-section--has-background" : ""}` ${hasBackgroundColor && backgroundColor ? "chapter-section--has-background" : ""}`,
style: {
"--chapter-section-text-color": textColor ? textColor : "#136f63"
}
}), }),
children: [hasBackgroundColor && backgroundColor && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)("svg", { children: [hasBackgroundColor && backgroundColor && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)("svg", {
className: `chapter-section__background chapter-section__background--${backgroundOrientation}`, className: `chapter-section__background chapter-section__background--${backgroundOrientation}`,
@ -366,11 +364,15 @@ function save({
backgroundColor, backgroundColor,
hasBackgroundColor, hasBackgroundColor,
backgroundOrientation, backgroundOrientation,
blockWidth blockWidth,
textColor
} = attributes; } = attributes;
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsxs)("section", { return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsxs)("section", {
..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_0__.useBlockProps.save({ ..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_0__.useBlockProps.save({
className: `deligraph-blocks-chapter-section chapter-section chapter-section--${disposition} ${backgroundColor ? "chapter-section--has-background" : ""} ${blockWidth === "full" ? "chapter-section--width-full" : "chapter-section--width-contained"}` className: `deligraph-blocks-chapter-section chapter-section chapter-section--${disposition} ${backgroundColor ? "chapter-section--has-background" : ""} ${blockWidth === "full" ? "chapter-section--width-full" : "chapter-section--width-contained"}`,
style: {
"--chapter-section-text-color": textColor
}
}), }),
children: [hasBackgroundColor && backgroundColor && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)("svg", { children: [hasBackgroundColor && backgroundColor && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)("svg", {
className: `chapter-section__background chapter-section__background--${backgroundOrientation}`, className: `chapter-section__background chapter-section__background--${backgroundOrientation}`,

File diff suppressed because one or more lines are too long

View File

@ -65,6 +65,10 @@
"type": "string", "type": "string",
"default": "#ffffff" "default": "#ffffff"
}, },
"textColor": {
"type": "string",
"default": "#136f63"
},
"backgroundOrientation": { "backgroundOrientation": {
"type": "string", "type": "string",
"default": "left", "default": "left",

View File

@ -30,14 +30,12 @@ export default function Edit({ attributes, setAttributes, ...props }) {
backgroundColor, backgroundColor,
backgroundOrientation, backgroundOrientation,
blockWidth, blockWidth,
textColor,
} = attributes; } = attributes;
function onDispositionChange(disposition) { function onDispositionChange(disposition) {
setAttributes({ disposition }); setAttributes({ disposition });
} }
function onCoverSizeChange(coverSize) {
setAttributes({ coverSize });
}
function setCoverAttributes(cover) { function setCoverAttributes(cover) {
setAttributes({ setAttributes({
@ -129,7 +127,7 @@ export default function Edit({ attributes, setAttributes, ...props }) {
className="deligraph-blocks__variant" className="deligraph-blocks__variant"
isBlock isBlock
label="Taille de l'image" label="Taille de l'image"
onChange={onCoverSizeChange} onChange={(coverSize) => setAttributes({ coverSize })}
value={coverSize} value={coverSize}
> >
<ToggleGroupControlOption label="Big" value="large" /> <ToggleGroupControlOption label="Big" value="large" />
@ -155,19 +153,20 @@ export default function Edit({ attributes, setAttributes, ...props }) {
value={backgroundColor} value={backgroundColor}
onChange={onBackgroundColorChange} onChange={onBackgroundColorChange}
/> />
<ToggleGroupControl
className="deligraph-blocks__variant"
isBlock
label="Disposition"
onChange={onBackgroundOrientationChange}
value={backgroundOrientation}
>
<ToggleGroupControlOption label="Gauche" value="left" />
<ToggleGroupControlOption label="Droite" value="right" />
</ToggleGroupControl>
</> </>
)} )}
</PanelBody> </PanelBody>
<PanelBody
className="deligraph-blocks-components-image__panel-body"
title={__("Couleur du texte", "deligraph-blocks")}
>
<ColorPalette
colors={colors}
value={textColor}
onChange={(value) => setAttributes({ textColor: value })}
/>
</PanelBody>
</InspectorControls> </InspectorControls>
<section <section
{...useBlockProps({ {...useBlockProps({
@ -182,6 +181,9 @@ export default function Edit({ attributes, setAttributes, ...props }) {
? "chapter-section--has-background" ? "chapter-section--has-background"
: "" : ""
}`, }`,
style: {
"--chapter-section-text-color": textColor ? textColor : "#136f63",
},
})} })}
> >
{hasBackgroundColor && backgroundColor && ( {hasBackgroundColor && backgroundColor && (

View File

@ -9,6 +9,7 @@ export default function save({ attributes }) {
hasBackgroundColor, hasBackgroundColor,
backgroundOrientation, backgroundOrientation,
blockWidth, blockWidth,
textColor,
} = attributes; } = attributes;
return ( return (
<section <section
@ -20,6 +21,9 @@ export default function save({ attributes }) {
? "chapter-section--width-full" ? "chapter-section--width-full"
: "chapter-section--width-contained" : "chapter-section--width-contained"
}`, }`,
style: {
"--chapter-section-text-color": textColor,
},
})} })}
> >
{hasBackgroundColor && backgroundColor && ( {hasBackgroundColor && backgroundColor && (