From 18b721fa5a96f1e65f44c2ca0a68b021dad7be3f Mon Sep 17 00:00:00 2001 From: Giulia Ghisini Date: Mon, 20 Nov 2023 14:10:05 +0100 Subject: [PATCH] fix: create new blockss --- src/components/Image/Image.jsx | 168 +++++++++--------- .../Blocks/Accordion/Block/EditBlock.jsx | 6 +- .../ItaliaTheme/Blocks/Accordion/Edit.jsx | 39 +++- .../ItaliaTheme/Blocks/Alert/Edit.jsx | 165 +++++++---------- .../Blocks/ArgumentsInEvidence/Edit.jsx | 39 +++- .../ItaliaTheme/Blocks/CTABlock/Block.jsx | 36 ++-- .../ItaliaTheme/Blocks/Callout/Edit.jsx | 47 ++--- .../Blocks/ContactsBlock/Block/EditBlock.jsx | 12 +- .../ItaliaTheme/Blocks/ContactsBlock/Edit.jsx | 50 +++++- .../ItaliaTheme/Blocks/CountDown/Edit.jsx | 31 +--- .../Blocks/IconBlocks/Block/EditBlock.jsx | 8 +- .../ItaliaTheme/Blocks/IconBlocks/Edit.jsx | 34 +++- .../Blocks/NumbersBlock/Block/EditBlock.jsx | 8 +- .../ItaliaTheme/Blocks/NumbersBlock/Edit.jsx | 30 +++- .../Blocks/TextCard/CardWithImage/Block.jsx | 47 ++--- .../Blocks/TextCard/CardWithImage/Edit.jsx | 2 +- .../TextCard/SimpleCard/BodyWrapper.jsx | 1 + .../Blocks/TextCard/SimpleCard/Edit.jsx | 54 +++--- .../manage/Widgets/SimpleTextEditorWidget.jsx | 18 +- .../manage/Widgets/TextEditorWidget.jsx | 11 +- src/config/Slate/handlers.js | 46 +++-- src/config/italiaConfig.js | 1 + .../manage/Blocks/HeroImageLeft/Edit.jsx | 39 +++- src/helpers/blocks.js | 81 ++++++++- src/theme/ItaliaTheme/_main.scss | 4 +- src/theme/_cms-ui.scss | 2 +- 26 files changed, 580 insertions(+), 399 deletions(-) diff --git a/src/components/Image/Image.jsx b/src/components/Image/Image.jsx index 4e62c5f65..c49faa9c6 100644 --- a/src/components/Image/Image.jsx +++ b/src/components/Image/Image.jsx @@ -38,90 +38,91 @@ const Image = ({ sizes = '100vw', ...imageProps }) => { - const { src, srcSet, width, height, aspectRatio } = getImageAttributes( - image, - { - itemUrl, - imageField, - maxSize, - useOriginal, - minSize, - }, - ); - const imageRef = useRef(); - const [actualSrcSet, setActualSrcSet] = useState( - critical && srcSet ? srcSet.join(', ') : null, - ); - // TODO: serve a qualcuno questo? - const imageHasLoaded = imageRef?.current?.complete; + if (image) { + const { src, srcSet, width, height, aspectRatio } = getImageAttributes( + image, + { + itemUrl, + imageField, + maxSize, + useOriginal, + minSize, + }, + ); + const imageRef = useRef(); + const [actualSrcSet, setActualSrcSet] = useState( + critical && srcSet ? srcSet.join(', ') : null, + ); + // TODO: serve a qualcuno questo? + const imageHasLoaded = imageRef?.current?.complete; - //picture classname - let pictureClassName = `volto-image${ - containerClassName ? ` ${containerClassName}` : '' - }`; - if (floated) { - pictureClassName = `${pictureClassName} floated ${floated}`; - } - if (size) { - pictureClassName = `${pictureClassName} ${size}`; - } + //picture classname + let pictureClassName = `volto-image${ + containerClassName ? ` ${containerClassName}` : '' + }`; + if (floated) { + pictureClassName = `${pictureClassName} floated ${floated}`; + } + if (size) { + pictureClassName = `${pictureClassName} ${size}`; + } - if (responsive) { - pictureClassName = `${pictureClassName} responsive`; - } + if (responsive) { + pictureClassName = `${pictureClassName} responsive`; + } - //intersection observer - useEffect(() => { - const applySrcSet = () => { - setActualSrcSet(srcSet.join(', ')); - }; + //intersection observer + useEffect(() => { + const applySrcSet = () => { + setActualSrcSet(srcSet.join(', ')); + }; - if (srcSet && !critical) { - if ('IntersectionObserver' in window) { - const observer = new IntersectionObserver( - (entries) => { - entries.forEach((entry) => { - if (entry.isIntersecting && !actualSrcSet) { - applySrcSet(); - if (imageRef.current instanceof Element) { - observer.unobserve(imageRef.current); + if (srcSet && !critical) { + if ('IntersectionObserver' in window) { + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting && !actualSrcSet) { + applySrcSet(); + if (imageRef.current instanceof Element) { + observer.unobserve(imageRef.current); + } } - } - }); - }, - { threshold: [0], rootMargin: '100px' }, - ); - observer.observe(imageRef.current); - } else { - applySrcSet(); + }); + }, + { threshold: [0], rootMargin: '100px' }, + ); + observer.observe(imageRef.current); + } else { + applySrcSet(); + } } - } - }, [imageHasLoaded, srcSet, actualSrcSet, critical]); + }, [imageHasLoaded, srcSet, actualSrcSet, critical]); - return ( - <> - - {actualSrcSet?.length > 0 && ( - - )} - {alt} - - {!critical && ( -