FEATURE Add block width option to content box with full and contained variants
This commit is contained in:
parent
a9f613d8cb
commit
c456d7c999
|
|
@ -37,6 +37,14 @@
|
|||
"blockVariant": {
|
||||
"type": "string",
|
||||
"default": "framed"
|
||||
},
|
||||
"blockWidth": {
|
||||
"type": "string",
|
||||
"default": "full",
|
||||
"enum": [
|
||||
"full",
|
||||
"contained"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ export default function Edit({ attributes, setAttributes, ...props }) {
|
|||
textColor,
|
||||
hasLightBackground,
|
||||
blockVariant,
|
||||
blockWidth,
|
||||
} = attributes;
|
||||
|
||||
// Détecter le type de post actuel
|
||||
|
|
@ -77,6 +78,11 @@ export default function Edit({ attributes, setAttributes, ...props }) {
|
|||
}
|
||||
function onBlockVariantChange(value) {
|
||||
setAttributes({ blockVariant: value });
|
||||
|
||||
if (value === "framed" || value === "nude") {
|
||||
setAttributes({ backgroundColor: "#fff" });
|
||||
setAttributes({ hasLightBackground: true });
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
|
|
@ -90,12 +96,24 @@ export default function Edit({ attributes, setAttributes, ...props }) {
|
|||
__nextHasNoMarginBottom
|
||||
__next40pxDefaultSize
|
||||
>
|
||||
<ToggleGroupControlOption value="nude" label="Nu" />
|
||||
<ToggleGroupControlOption value="framed" label="Encadré" />
|
||||
<ToggleGroupControlOption
|
||||
value="backgrounded"
|
||||
label="Fond coloré"
|
||||
/>
|
||||
</ToggleGroupControl>
|
||||
<ToggleGroupControl
|
||||
label="Largeur du bloc"
|
||||
value={blockWidth}
|
||||
onChange={(value) => setAttributes({ blockWidth: value })}
|
||||
isBlock
|
||||
__nextHasNoMarginBottom
|
||||
__next40pxDefaultSize
|
||||
>
|
||||
<ToggleGroupControlOption value="full" label="Pleine largeur" />
|
||||
<ToggleGroupControlOption value="contained" label="Contenue" />
|
||||
</ToggleGroupControl>
|
||||
|
||||
{blockVariant === "backgrounded" && (
|
||||
<Card>
|
||||
|
|
@ -138,7 +156,8 @@ export default function Edit({ attributes, setAttributes, ...props }) {
|
|||
hasLightBackground
|
||||
? "content-box--bg-light"
|
||||
: "content-box--bg-dark"
|
||||
}`,
|
||||
}
|
||||
${blockWidth === "contained" ? "alignwide" : "alignfull"}`,
|
||||
style: {
|
||||
"--content-box-text-color": textColor ?? "inherit",
|
||||
"--content-box-background-color":
|
||||
|
|
|
|||
|
|
@ -8,13 +8,15 @@ export default function save({ attributes }) {
|
|||
hasLightBackground,
|
||||
hasBackgroundColor,
|
||||
blockVariant,
|
||||
blockWidth,
|
||||
} = attributes;
|
||||
return (
|
||||
<section
|
||||
{...useBlockProps.save({
|
||||
className: `content-box content-box--variant-${blockVariant} ${
|
||||
hasLightBackground ? "content-box--bg-light" : "content-box--bg-dark"
|
||||
}`,
|
||||
}
|
||||
${blockWidth === "contained" ? "alignwide" : "alignfull"}`,
|
||||
style: {
|
||||
"--content-box-text-color": textColor ?? "inherit",
|
||||
"--content-box-background-color":
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user