import { __ } from "@wordpress/i18n"; import { useBlockProps, InnerBlocks, useSetting, InspectorControls, MediaReplaceFlow, MediaPlaceholder, } from "@wordpress/block-editor"; import { Card, CardHeader, CardBody, Heading, Text, } from "@wordpress/components"; import { useSelect } from "@wordpress/data"; import "./editor.scss"; import { isColorLight } from "../../_utilities/utilities"; import { PanelBody, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, 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 }) { const colors = useSetting("color.palette.theme"); const { hasBackgroundColor, align, backgroundColor, textColor, hasLightBackground, blockVariant, shapeType, borderColor, } = attributes; // Détecter le type de post actuel const postType = useSelect((select) => { return select("core/editor").getCurrentPostType(); }, []); const filteredBgColors = filterBgColors(colors, postType); const filteredTextColors = filterTextColors( colors, postType, backgroundColor, ); function onBackgroundColorChange(value) { if (value === undefined) { setAttributes({ hasBackgroundColor: false }); setAttributes({ backgroundColor: "transparent" }); } const isLightBackgroundColor = isColorLight(value); setAttributes({ hasLightBackground: isLightBackgroundColor }); setAttributes({ backgroundColor: value }); if (!isLightBackgroundColor) { setAttributes({ textColor: "#fff" }); } else { setAttributes({ textColor: "inherit" }); } } function onHasBackgroundColorChange(value) { setAttributes({ hasBackgroundColor: value }); if (!value) { setAttributes({ backgroundColor: null }); } } function onTextColorChange(value) { setAttributes({ textColor: value }); } function onBlockVariantChange(value) { setAttributes({ blockVariant: value }); if (value === "framed" || value === "nude") { setAttributes({ backgroundColor: "#fff" }); setAttributes({ hasLightBackground: true }); } } const alignClass = align === "full" ? "alignfull" : align === "wide" ? "alignwide" : "aligncontained"; console.log(align); return ( <> setAttributes({ align: value })} isBlock __nextHasNoMarginBottom __next40pxDefaultSize > {blockVariant !== "nude" && ( 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 === "framed-backgrounded" && backgroundColor && shapeType === "shapeA" && ( )} {blockVariant === "framed-backgrounded" && backgroundColor && shapeType === "shapeB" && ( )} {blockVariant === "framed-backgrounded" && backgroundColor && shapeType === "shapeC" && ( )}
); }