From 66a996a43a6e0e0ce6267226c45800f2377879ea Mon Sep 17 00:00:00 2001 From: Parthiv Date: Thu, 29 Feb 2024 17:34:01 +0530 Subject: [PATCH] Add tooltip beside city refinement search box --- components/search/bills/BillSearch.tsx | 42 +++++++++++++++- .../search/bills/useBillRefinements.tsx | 1 + components/tooltip.tsx | 49 +++++++++++++------ 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/components/search/bills/BillSearch.tsx b/components/search/bills/BillSearch.tsx index 9513b3365..abf2de89e 100644 --- a/components/search/bills/BillSearch.tsx +++ b/components/search/bills/BillSearch.tsx @@ -22,7 +22,8 @@ import { useBillRefinements } from "./useBillRefinements" import { SortBy, SortByWithConfigurationItem } from "../SortBy" import { getServerConfig } from "../common" import { useBillSort } from "./useBillSort" -import { FC } from "react" +import { FC, RefObject, useEffect, useRef } from "react" +import { QuestionTooltip } from "components/tooltip" const searchClient = new TypesenseInstantSearchAdapter({ server: getServerConfig(), @@ -73,13 +74,52 @@ const useSearchStatus = () => { } } +const addToolTipForCity = (nodeRef: RefObject) => { + // fetch the city search refinement form + const citySearch = document.querySelector(".city-search form")!; + citySearch?.setAttribute("style", "gap: 5px;"); + // fetch the city search refinement form input + const input = document.querySelector(".city-search form .ais-SearchBox-input")!; + input?.setAttribute("style", "padding-right: 0"); + // create the tool tip div to be added beside the input + const toolTip = document.createElement("div")!; + toolTip.classList.add(".city-tooltip"); + toolTip.style.margin = "auto 0"; + // add the tooltip div at the beginning of the form + citySearch?.prepend(toolTip); + // add the component to the div using the ref + toolTip.append(nodeRef?.current!); +} + const Layout: FC< React.PropsWithChildren<{ items: SortByWithConfigurationItem[] }> > = ({ items }) => { const refinements = useBillRefinements() const status = useSearchStatus() + const nodeRef = useRef(null); + + // add the tooltip beside city refinement box on page load + useEffect(() => { + addToolTipForCity(nodeRef); + }, []); + return ( + +

+ This filter only captures bills submitted via the + {" "} + + home rule + + {" "} + petition; not every bill that concerns a city +

+
diff --git a/components/search/bills/useBillRefinements.tsx b/components/search/bills/useBillRefinements.tsx index 74c7a7b1f..5f13b1f03 100644 --- a/components/search/bills/useBillRefinements.tsx +++ b/components/search/bills/useBillRefinements.tsx @@ -30,6 +30,7 @@ export const useBillRefinements = () => { useRefinementListUiProps({ attribute: "city", searchablePlaceholder: "City", + className: "city-search", ...baseProps }), useRefinementListUiProps({ diff --git a/components/tooltip.tsx b/components/tooltip.tsx index 24602a0c0..5c01a6c8f 100644 --- a/components/tooltip.tsx +++ b/components/tooltip.tsx @@ -1,22 +1,43 @@ import "@fortawesome/fontawesome-svg-core/styles.css" import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" -import React from "react" +import React, { FC, RefObject, useState } from "react" import { OverlayTrigger, Tooltip } from "react-bootstrap" +import { Placement } from "react-bootstrap/esm/types" -export const QuestionTooltip = ({ text }: { text: string }) => { +export const QuestionTooltip: FC< + React.PropsWithChildren<{ + placement: Placement, + nodeRef: RefObject + }> +> = ({ placement, nodeRef, children }) => { + const [show, setShow] = useState(false); + const onMouseOver = (s: boolean) => setShow(s); return ( - -

{text}

- - } - > - - - -
+
+ onMouseOver(true)} + onMouseLeave={() => onMouseOver(false)} + id="tooltip-text" + > + {children} + + } + > + + onMouseOver(true)} + onMouseLeave={() => onMouseOver(false)} + size={"lg"} + icon={faQuestionCircle} + className="text-secondary" + /> + + +
) }