From a4e5c2ba8836139af750b65a61c0e3e016bf4295 Mon Sep 17 00:00:00 2001 From: Alexander Doroshenko Date: Mon, 16 Dec 2024 11:56:29 -0500 Subject: [PATCH 1/9] Added Search icon/box and indexing updates --- .../search/_preview-search-icon.scss | 3 + .../components/search/_preview-search.scss | 7 +- .../assets/sass/components/search/index.scss | 1 + src/sxastarter/src/components/Navigation.tsx | 97 +++++++++++++++---- .../components/PageContent/ArticleDetails.tsx | 2 + .../components/PageContent/AuthorDetails.tsx | 82 +++++++++------- .../src/components/PageContent/HeadingCta.tsx | 1 + .../components/PageContent/PageBackground.tsx | 1 + .../components/PageContent/ProjectDetails.tsx | 1 + .../src/components/Search/ClickOutside.tsx | 39 ++++++++ .../Search/PreviewSearch/PreviewSearch.tsx | 6 +- .../PreviewSearch/PreviewSearchIcon.tsx | 22 +++++ 12 files changed, 203 insertions(+), 59 deletions(-) create mode 100644 src/sxastarter/src/assets/sass/components/search/_preview-search-icon.scss create mode 100644 src/sxastarter/src/components/Search/ClickOutside.tsx create mode 100644 src/sxastarter/src/components/Search/PreviewSearch/PreviewSearchIcon.tsx diff --git a/src/sxastarter/src/assets/sass/components/search/_preview-search-icon.scss b/src/sxastarter/src/assets/sass/components/search/_preview-search-icon.scss new file mode 100644 index 00000000..f02f9d95 --- /dev/null +++ b/src/sxastarter/src/assets/sass/components/search/_preview-search-icon.scss @@ -0,0 +1,3 @@ +.preview-search-content-icon { + cursor: pointer; +} \ No newline at end of file diff --git a/src/sxastarter/src/assets/sass/components/search/_preview-search.scss b/src/sxastarter/src/assets/sass/components/search/_preview-search.scss index f28e3a55..b6fc0975 100644 --- a/src/sxastarter/src/assets/sass/components/search/_preview-search.scss +++ b/src/sxastarter/src/assets/sass/components/search/_preview-search.scss @@ -4,13 +4,18 @@ .sitecore-preview-search-input { width: 800px; box-sizing: border-box; - padding: var(--sdc-spacing-xs); + padding: .6rem 2rem .6rem 3rem; + text-align: left !important; &:focus { outline: 1px solid var(--sdc-palette-grey-800); } } +.search-input-container-hidden { + display: none; +} + /* PreviewSearchContent */ .sitecore-preview-search-content { animation-duration: 500ms; diff --git a/src/sxastarter/src/assets/sass/components/search/index.scss b/src/sxastarter/src/assets/sass/components/search/index.scss index e10994e1..f15548e3 100644 --- a/src/sxastarter/src/assets/sass/components/search/index.scss +++ b/src/sxastarter/src/assets/sass/components/search/index.scss @@ -1,2 +1,3 @@ @import 'components'; @import 'preview-search'; +@import 'preview-search-icon'; diff --git a/src/sxastarter/src/components/Navigation.tsx b/src/sxastarter/src/components/Navigation.tsx index bfa95c73..404a2d1e 100644 --- a/src/sxastarter/src/components/Navigation.tsx +++ b/src/sxastarter/src/components/Navigation.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useCallback, useRef, useState } from 'react'; import { Link, LinkField, @@ -6,6 +6,11 @@ import { TextField, useSitecoreContext, } from '@sitecore-jss/sitecore-jss-nextjs'; +import PreviewSearchWidget, { ArticleModel } from './Search/PreviewSearch/PreviewSearch'; +import { isSearchSDKEnabled } from 'src/services/SearchSDKService'; +import PreviewSearchIcon from './Search/PreviewSearch/PreviewSearchIcon'; +import ClickOutside from './Search/ClickOutside'; +import { useRouter } from 'next/router'; interface Fields { Id: string; @@ -48,8 +53,37 @@ const getLinkField = (props: NavigationProps): LinkField => ({ }); export const Default = (props: NavigationProps): JSX.Element => { + const [isPreviewSearchOpen, setIsPreviewSearchOpen] = useState(false); const [isOpenMenu, openMenu] = useState(false); const { sitecoreContext } = useSitecoreContext(); + const containerRef = useRef(null); + const router = useRouter(); + + const onSearchIconClick = useCallback(() => { + setIsPreviewSearchOpen((isPreviewSearchOpen) => { + return !isPreviewSearchOpen; + }); + + // Focus on element with ID search-input + setTimeout(() => { + const searchInput = document.getElementById('search-input'); + if (searchInput) { + searchInput.focus(); + } + }, 0); + }, []); + + const onClose = useCallback(() => setIsPreviewSearchOpen(false), []); + ClickOutside([containerRef], onClose); + + const onRedirect = useCallback( + (article: ArticleModel) => { + onClose(); + router.push(new URL(article.url, window.location.origin).pathname); + }, + [onClose, router] + ); + const styles = props.params != null ? `${props.params.GridParameters ?? ''} ${props.params.Styles ?? ''}`.trimEnd() @@ -87,28 +121,51 @@ export const Default = (props: NavigationProps): JSX.Element => { /> )); + if (isSearchSDKEnabled) { + list.push( + + ); + } + return (
-