From 6a2d5d9881cd1eb4e3e25ce8f17dfef8b5d21e7e Mon Sep 17 00:00:00 2001 From: Walter Buczacka Date: Fri, 19 Apr 2024 13:42:00 -0300 Subject: [PATCH] add open controlled prop --- .../next/cms/components/ProfileRenderer.js | 8 ++++++- packages/next/cms/components/sections/Hero.js | 23 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/next/cms/components/ProfileRenderer.js b/packages/next/cms/components/ProfileRenderer.js index 89da451a7..c121f1df7 100644 --- a/packages/next/cms/components/ProfileRenderer.js +++ b/packages/next/cms/components/ProfileRenderer.js @@ -44,6 +44,8 @@ function ProfileRenderer({ customSections = {}, relatedTile, t, + opened, + handlers, }) { const router = useRouter(); const {query} = router; @@ -109,7 +111,7 @@ function ProfileRenderer({ return ( -
+
{ !hideHero ? ( @@ -121,6 +123,8 @@ function ProfileRenderer({ }} > l.type === "Hero") || null} diff --git a/packages/next/cms/components/sections/Hero.js b/packages/next/cms/components/sections/Hero.js index 2dd821fe2..4f19c7f1e 100644 --- a/packages/next/cms/components/sections/Hero.js +++ b/packages/next/cms/components/sections/Hero.js @@ -43,18 +43,32 @@ function Hero({ profile, sources, type, + defaultOpened, + opened, + handlers = {}, }) { // NOTE: using color scheme here asumes there is theme switch enabled // const {colorScheme} = useMantineColorScheme(); - const [clickedIndex, setClickedIndex] = useState(undefined); + + const [clickedIndex, setClickedIndex] = useState(defaultOpened || undefined); + const [creditsVisible, setCreditsVisible] = useState(false); + const { formatters, searchProps, linkify, t, } = useContext(ProfileContext); const {stripHTML = (d) => d} = formatters || {}; + const isOpenControlled = () => opened != null; + const titleClick = (index) => { - setClickedIndex(index); + if (typeof handlers.toggle === "function") { + handlers.toggle(); + } + + if (!isOpenControlled()) { + setClickedIndex(index); + } setTimeout(() => { document.querySelector(".cp-hero-search .cp-input input").focus(); }, 300); @@ -138,7 +152,6 @@ function Hero({ } // heading & subhead(s) - const heading = (

@@ -311,8 +324,8 @@ function Hero({ ...searchProps?.modalProps || {}, // not-overridable className: "cp-hero-search", - opened: clickedIndex !== undefined, - onClose: () => setClickedIndex(undefined), + opened: isOpenControlled() ? opened : clickedIndex !== undefined, + onClose: isOpenControlled() ? () => handlers.close() : () => setClickedIndex(undefined), }} />