diff --git a/dotcom-rendering/src/components/CarouselCount.tsx b/dotcom-rendering/src/components/CarouselCount.tsx new file mode 100644 index 00000000000..c44eb061c7c --- /dev/null +++ b/dotcom-rendering/src/components/CarouselCount.tsx @@ -0,0 +1,33 @@ +import { useEffect, useState } from 'react'; +import { createPortal } from 'react-dom'; + +export const CarouselCount = ({ + sectionId, + count, + total, +}: { + sectionId: string; + count: number; + total: number; +}) => { + const [portalNode, setPortalNode] = useState(null); + + useEffect(() => { + const node = document.getElementById(`${sectionId}-carousel-count`); + if (!node) { + console.warn( + `Portal node with ID "${sectionId}-carousel-count" not found.`, + ); + } + setPortalNode(node); + }, [sectionId]); + + if (!portalNode) return null; + + return createPortal( +
+ {count} of {total} +
, + portalNode, + ); +}; diff --git a/dotcom-rendering/src/components/CarouselNavigationButtons.tsx b/dotcom-rendering/src/components/CarouselNavigationButtons.tsx index 4450bb52276..48854cde99d 100644 --- a/dotcom-rendering/src/components/CarouselNavigationButtons.tsx +++ b/dotcom-rendering/src/components/CarouselNavigationButtons.tsx @@ -19,6 +19,7 @@ type CarouselNavigationProps = { dataLinkNamePreviousButton: string; /** Unique identifier for the carousel navigation container. */ sectionId: string; + showFromTabletOnly?: boolean; }; const themeButton: Partial = { @@ -33,7 +34,7 @@ const themeButtonDisabled: Partial = { backgroundTertiaryHover: 'transparent', }; -const buttonStyles = css` +const showFromTablet = css` display: none; ${from.tablet} { display: flex; @@ -42,6 +43,15 @@ const buttonStyles = css` } `; +/** + * In the Articles we will control the visibility in the portal node + */ +const showAlways = css` + display: flex; + gap: ${space[1]}px; + margin-left: auto; +`; + /** * * Navigation buttons for a carousel-like component. @@ -68,6 +78,7 @@ export const CarouselNavigationButtons = ({ dataLinkNamePreviousButton, dataLinkNameNextButton, sectionId, + showFromTabletOnly = true, }: CarouselNavigationProps) => { const [portalNode, setPortalNode] = useState(null); useEffect(() => { @@ -88,7 +99,7 @@ export const CarouselNavigationButtons = ({