diff --git a/src/sxastarter/src/Layout.tsx b/src/sxastarter/src/Layout.tsx index 7b2e6389..cc6ab585 100644 --- a/src/sxastarter/src/Layout.tsx +++ b/src/sxastarter/src/Layout.tsx @@ -39,6 +39,7 @@ const Layout = ({ layoutData, headLinks }: LayoutProps): JSX.Element => { + {headLinks.map((headLink) => ( 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..1428a5bc 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,21 @@ .sitecore-preview-search-input { width: 800px; box-sizing: border-box; - padding: var(--sdc-spacing-xs); + padding: .6rem 2rem .6rem 3rem; + text-align: left !important; + color: var(--text-body); + background: var(--bg-body); + border-width: 1px; &:focus { outline: 1px solid var(--sdc-palette-grey-800); } } +.search-input-container-hidden { + display: none; +} + /* PreviewSearchContent */ .sitecore-preview-search-content { animation-duration: 500ms; @@ -107,7 +115,7 @@ /* PreviewSearchItems */ .sitecore-preview-search-items { flex: 3; - background: #fff; + background: var(--bg-body); overflow-y: auto; display: flex; @@ -117,6 +125,7 @@ list-style: none; margin: 0; padding: var(--sdc-spacing-s); + padding-top: 3rem; gap: var(--sdc-spacing-m); } } @@ -139,7 +148,10 @@ cursor: pointer; display: block; border: solid 1px transparent; - text-align: center; + + h2 { + text-align: center !important; + } &:focus-within { box-shadow: 2px 2px 4px var(--sdc-palette-grey-800); 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..0bde93bd 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,52 @@ export const Default = (props: NavigationProps): JSX.Element => { /> )); + if (isSearchSDKEnabled) { + list.push( +
  • + +
  • + ); + } + return (
    -