import { __ } from "@wordpress/i18n"; import "./editor.scss"; import { useSelect } from "@wordpress/data"; import { useBlockProps, RichText, BlockControls, InspectorControls, __experimentalLinkControl as LinkControl, } from "@wordpress/block-editor"; import { PanelBody, TextControl, ToggleControl } from "@wordpress/components"; import { Tip } from "@wordpress/components"; export default function Edit({ attributes, setAttributes }) { const { blockCustomTitle, hasCustomTitle, pageHeaderTitle, pageHeaderDescription, hasCta, cta, } = attributes; const pageTitle = useSelect((select) => { const { getEditedPostAttribute } = select("core/editor"); return getEditedPostAttribute("title"); }); const pageIcon = useSelect((select) => { const currentPost = select("core/editor").getCurrentPost(); if (currentPost && currentPost.acf && currentPost.acf.page_icon) { let cover = select("core").getMedia(currentPost.acf.page_icon); return cover; } }); function onChangeBlockCustomTitle(blockCustomTitle) { setAttributes({ blockCustomTitle }); } function onChangeTitle(newTitle) { setAttributes({ pageHeaderTitle: newTitle }); } function onChangeHasCustomTitle(newHasAutoTitle) { setAttributes({ hasCustomTitle: !hasCustomTitle }); if (newHasAutoTitle) { setAttributes({ blockCustomTitle: undefined }); } } function onChangeHasCta(newHasCta) { setAttributes({ hasCta: !hasCta }); if (!newHasCta) { setAttributes({ cta: undefined }); } } function onChangeDescription(newDescription) { setAttributes({ pageHeaderDescription: newDescription }); } function onChangeCTA(newCtaValue) { setAttributes({ cta: { title: !cta || !cta.title ? newCtaValue.title : cta.title, id: newCtaValue.id, kind: newCtaValue.kind, type: newCtaValue.type, url: newCtaValue.url, }, }); } function onChangeTextControl(newCtaTitle) { setAttributes({ cta: { ...cta, title: newCtaTitle, }, }); } console.log(blockCustomTitle); return ( <> {!hasCustomTitle && ( Le titre est automatiquement généré à partir du titre de la page )} {hasCta && ( <> )}
{!hasCustomTitle &&

{pageTitle}

} {hasCustomTitle && ( )} {cta && cta.title && cta.url && {cta.title}}
{pageIcon && ( )}
); }