Skip to content

Commit f9cfd51

Browse files
added new prop to change the search url (#62)
* added new prop to change the search url * Update README.md --------- Co-authored-by: Jack Pettit [SSW] <[email protected]>
1 parent 03c447e commit f9cfd51

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export function getStaticProps() {
102102
| `title` | `string` | The title text displayed next to the SSW logo. | Yes (If there is no `tagline` provided) |
103103
| `subtitle` | `string` | The text displayed underneath the SSW logo | No |
104104
| `tagline` | `string` | The URL of the menu bar item. | No |
105+
| `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 |
105106
| `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 |
106107

107108

lib/components/DesktopMenu/DesktopMenu.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface DesktopMenuProps {
1111
menuGroups: NavMenuGroup[];
1212
sideActionsOverride?: () => JSX.Element;
1313
hidePhone?: boolean;
14+
searchUrl?: string;
1415
}
1516

1617
export const ClosePopoverContext = createContext<(() => void) | null>(null);
@@ -19,6 +20,7 @@ const DesktopMenu: React.FC<DesktopMenuProps> = ({
1920
menuGroups,
2021
sideActionsOverride,
2122
hidePhone,
23+
searchUrl,
2224
}) => {
2325
const SideActions = sideActionsOverride;
2426

@@ -73,7 +75,7 @@ const DesktopMenu: React.FC<DesktopMenuProps> = ({
7375
{SideActions ? (
7476
<SideActions />
7577
) : (
76-
<DefaultSideActions hidePhone={hidePhone} />
78+
<DefaultSideActions hidePhone={hidePhone} searchUrl={searchUrl} />
7779
)}
7880
</div>
7981
</>
@@ -82,13 +84,17 @@ const DesktopMenu: React.FC<DesktopMenuProps> = ({
8284

8385
type DefaultSideActionsProps = {
8486
hidePhone?: boolean;
87+
searchUrl?: string;
8588
};
8689

87-
const DefaultSideActions = ({ hidePhone }: DefaultSideActionsProps) => {
90+
const DefaultSideActions = ({
91+
hidePhone,
92+
searchUrl,
93+
}: DefaultSideActionsProps) => {
8894
return (
8995
<>
9096
{!hidePhone && <PhoneButton hideMobile />}
91-
<Search />
97+
<Search url={searchUrl} />
9298
<Divider />
9399
<CountryDropdown />
94100
</>

lib/components/MegaMenuLayout/MegaMenuLayout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Search } from "../Search";
1212
export type MegaMenuWrapperProps = {
1313
menuBarItems?: NavMenuGroup[];
1414
subtitle?: string;
15+
searchUrl?: string;
1516
rightSideActionsOverride?: () => JSX.Element;
1617
} & React.PropsWithChildren &
1718
(Tagline | Title);
@@ -30,6 +31,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
3031
tagline,
3132
title,
3233
subtitle,
34+
searchUrl,
3335
menuBarItems,
3436
rightSideActionsOverride,
3537
}) => {
@@ -77,7 +79,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
7779
) : (
7880
<PhoneButton className="max-sm:hidden" />
7981
)}
80-
<Search />
82+
<Search url={searchUrl} />
8183
<Divider />
8284
<button
8385
type="button"
@@ -89,6 +91,7 @@ const MegaMenuLayout: React.FC<MegaMenuWrapperProps> = ({
8991
</button>
9092
</div>
9193
<DesktopMenu
94+
searchUrl={searchUrl}
9295
menuGroups={menuItems}
9396
sideActionsOverride={rightSideActionsOverride}
9497
/>

lib/components/Search/Search.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { useHotkeys } from "react-hotkeys-hook";
44
import { useLocation } from "react-use";
55
import { MegaIcon } from "../MegaIcon";
66

7-
export const Search: React.FC = () => {
7+
export interface SearchProps {
8+
url?: string;
9+
}
10+
11+
export const Search: React.FC<SearchProps> = ({ url }) => {
812
const searchRef = useRef(null);
913
const location = useLocation();
1014
const [isOpen, setIsOpen] = useState(false);
@@ -30,7 +34,7 @@ export const Search: React.FC = () => {
3034
const performSearch = () => {
3135
if (searchTerm) {
3236
const searchUrl = `https://www.google.com.au/search?q=site:${
33-
location.hostname
37+
url || location.hostname
3438
}%20${encodeURIComponent(searchTerm)}`;
3539
window.open(searchUrl, "_blank");
3640
}

0 commit comments

Comments
 (0)