diff --git a/imports/client/components/PuzzlePage.tsx b/imports/client/components/PuzzlePage.tsx index 3cb503b7a..088e30bef 100644 --- a/imports/client/components/PuzzlePage.tsx +++ b/imports/client/components/PuzzlePage.tsx @@ -309,6 +309,13 @@ const PuzzleMetadataExternalLink = styled.a` white-space: nowrap; `; +const SecondaryMetadataContainer = styled.div` + // To ensure this div covers the google doc when shown, we set a white background + background-color: #fff; + padding-left: 8px; + padding-right: 8px; +`; + const StyledTagList = styled(TagList)` display: contents; `; @@ -1005,6 +1012,23 @@ const InsertImage = ({ documentId }: { documentId: string }) => { ); }; +// A popper modifier that ensures that the width of the popover matches the +// width of the reference element. +const sameWidth = { + name: 'sameWidth', + enabled: true, + phase: 'beforeWrite' as const, + requires: ['computeStyles'], + fn: ({ state }: { state: any }) => { + state.styles.popper.width = `${state.rects.reference.width}px`; + }, + effect: ({ state }: { state: any }) => { + state.elements.popper.style.width = `${ + state.elements.reference.offsetWidth + }px`; + }, +}; + const PuzzlePageMetadata = ({ puzzle, displayNames, document, isDesktop, }: { @@ -1065,6 +1089,16 @@ const PuzzlePageMetadata = ({ } }, []); + const mainMetadataRef = useRef(null); + const [showSecondaryMetadata, setShowSecondaryMetadata] = useState(false); + const [mouseOverSecondaryMetadata, setMouseOverSecondaryMetadata] = useState(false); + const secondaryMetadataMouseOver = useCallback(() => { + setMouseOverSecondaryMetadata(true); + }, [setMouseOverSecondaryMetadata]); + const secondaryMetadataMouseLeave = useCallback(() => { + setMouseOverSecondaryMetadata(false); + }, [setMouseOverSecondaryMetadata]); + const tagsById = indexedById(allTags); const maybeTags: (TagType | undefined)[] = puzzle.tags.map((tagId) => { return tagsById.get(tagId); }); const tags: TagType[] = maybeTags.filter((t): t is TagType => t !== undefined); @@ -1148,26 +1182,12 @@ const PuzzlePageMetadata = ({ ); } - return ( - - - - {puzzleLink} - {documentLink} - {editButton} - {imageInsert} - {guessButton} - - - {answersElement} - + const secondaryMetadata = ( + - + + ); + + const modifiers = [ + { + name: 'preventOverflow', + enabled: true, + options: { + boundary: mainMetadataRef.current, + padding: 0, + }, + }, + sameWidth, + ]; + + return ( + + + + + {puzzleLink} + {documentLink} + {editButton} + {imageInsert} + {guessButton} + + + {answersElement} + + + ); };