Skip to content

Commit

Permalink
added new prop to change the search url (#62)
Browse files Browse the repository at this point in the history
* added new prop to change the search url
* Update README.md

---------

Co-authored-by: Jack Pettit [SSW] <[email protected]>
  • Loading branch information
BrookJeynes and JackDevAU authored Feb 12, 2024
1 parent 03c447e commit f9cfd51
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function getStaticProps() {
| `title` | `string` | The title text displayed next to the SSW logo. | Yes (If there is no `tagline` provided) |
| `subtitle` | `string` | The text displayed underneath the SSW logo | No |
| `tagline` | `string` | The URL of the menu bar item. | No |
| `searchUrl` | `string` | The absolute URL the search takes you to. If not provided, will default to the host address. i.e. for SSW <www.ssw.com.au> | No |
| `rightSideActionsOverride` | `() => JSX.Element` | The component to replace the "Call Us" and search buttons that are displayed by default on the right side of the menu. | No |


Expand Down
12 changes: 9 additions & 3 deletions lib/components/DesktopMenu/DesktopMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface DesktopMenuProps {
menuGroups: NavMenuGroup[];
sideActionsOverride?: () => JSX.Element;
hidePhone?: boolean;
searchUrl?: string;
}

export const ClosePopoverContext = createContext<(() => void) | null>(null);
Expand All @@ -19,6 +20,7 @@ const DesktopMenu: React.FC<DesktopMenuProps> = ({
menuGroups,
sideActionsOverride,
hidePhone,
searchUrl,
}) => {
const SideActions = sideActionsOverride;

Expand Down Expand Up @@ -73,7 +75,7 @@ const DesktopMenu: React.FC<DesktopMenuProps> = ({
{SideActions ? (
<SideActions />
) : (
<DefaultSideActions hidePhone={hidePhone} />
<DefaultSideActions hidePhone={hidePhone} searchUrl={searchUrl} />
)}
</div>
</>
Expand All @@ -82,13 +84,17 @@ const DesktopMenu: React.FC<DesktopMenuProps> = ({

type DefaultSideActionsProps = {
hidePhone?: boolean;
searchUrl?: string;
};

const DefaultSideActions = ({ hidePhone }: DefaultSideActionsProps) => {
const DefaultSideActions = ({
hidePhone,
searchUrl,
}: DefaultSideActionsProps) => {
return (
<>
{!hidePhone && <PhoneButton hideMobile />}
<Search />
<Search url={searchUrl} />
<Divider />
<CountryDropdown />
</>
Expand Down
5 changes: 4 additions & 1 deletion lib/components/MegaMenuLayout/MegaMenuLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Search } from "../Search";
export type MegaMenuWrapperProps = {
menuBarItems?: NavMenuGroup[];
subtitle?: string;
searchUrl?: string;
rightSideActionsOverride?: () => JSX.Element;
} & React.PropsWithChildren &
(Tagline | Title);
Expand All @@ -30,6 +31,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
tagline,
title,
subtitle,
searchUrl,
menuBarItems,
rightSideActionsOverride,
}) => {
Expand Down Expand Up @@ -77,7 +79,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
) : (
<PhoneButton className="max-sm:hidden" />
)}
<Search />
<Search url={searchUrl} />
<Divider />
<button
type="button"
Expand All @@ -89,6 +91,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
</button>
</div>
<DesktopMenu
searchUrl={searchUrl}
menuGroups={menuItems}
sideActionsOverride={rightSideActionsOverride}
/>
Expand Down
8 changes: 6 additions & 2 deletions lib/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { useHotkeys } from "react-hotkeys-hook";
import { useLocation } from "react-use";
import { MegaIcon } from "../MegaIcon";

export const Search: React.FC = () => {
export interface SearchProps {
url?: string;
}

export const Search: React.FC<SearchProps> = ({ url }) => {
const searchRef = useRef(null);
const location = useLocation();
const [isOpen, setIsOpen] = useState(false);
Expand All @@ -30,7 +34,7 @@ export const Search: React.FC = () => {
const performSearch = () => {
if (searchTerm) {
const searchUrl = `https://www.google.com.au/search?q=site:${
location.hostname
url || location.hostname
}%20${encodeURIComponent(searchTerm)}`;
window.open(searchUrl, "_blank");
}
Expand Down

0 comments on commit f9cfd51

Please sign in to comment.