diff --git a/src/theme/Navbar/Content/MobileSearch/MobileSearch.module.scss b/src/theme/Navbar/Content/MobileSearch/MobileSearch.module.scss new file mode 100644 index 0000000..673d79c --- /dev/null +++ b/src/theme/Navbar/Content/MobileSearch/MobileSearch.module.scss @@ -0,0 +1,33 @@ +.root { + display: flex; + flex-direction: row; + align-items: center; + justify-content: flex-end; + + width: 100%; + padding: 0 1.875rem; + + & > div { + flex: 0 0 !important; + } +} + +.root > div:nth-child(2) { + width: 57%; + flex-basis: 57%; + margin-left: 12px; + flex-shrink: 0; + flex-grow: 1; + flex: 1 1 57% !important; + + button { + width: auto; + } +} + +.root > div:last-child > button { + font-size: 0.75rem; + font-weight: bold; + color: #909091; + margin-left: 8px; +} diff --git a/src/theme/Navbar/Content/MobileSearch/MobileSearch.tsx b/src/theme/Navbar/Content/MobileSearch/MobileSearch.tsx new file mode 100644 index 0000000..de40515 --- /dev/null +++ b/src/theme/Navbar/Content/MobileSearch/MobileSearch.tsx @@ -0,0 +1,28 @@ +import NavbarLogo from '@theme/Navbar/Logo' +import clsx from 'clsx' +import React, { useState } from 'react' +import { useDebounce } from 'react-use' +import { SearchBar } from '../../../SearchBar/SearchBar' +import styles from './MobileSearch.module.scss' + +export const MobileSearch: React.FC<{ + render: boolean + onCancel: () => void +}> = ({ render, onCancel }) => { + const [renderSearchBar, setRenderSearchBar] = useState(false) + useDebounce(() => setRenderSearchBar(render), render ? 0 : 1000, [render]) + + return ( +
+
+ +
+
{renderSearchBar && }
+
+ +
+
+ ) +} diff --git a/src/theme/Navbar/Content/MobileSearch/index.ts b/src/theme/Navbar/Content/MobileSearch/index.ts new file mode 100644 index 0000000..251136d --- /dev/null +++ b/src/theme/Navbar/Content/MobileSearch/index.ts @@ -0,0 +1 @@ +export * from './MobileSearch' diff --git a/src/theme/Navbar/Content/index.tsx b/src/theme/Navbar/Content/index.tsx index 98032b6..dbc949a 100644 --- a/src/theme/Navbar/Content/index.tsx +++ b/src/theme/Navbar/Content/index.tsx @@ -1,5 +1,10 @@ import { useThemeConfig } from '@docusaurus/theme-common' -import { useNavbarMobileSidebar } from '@docusaurus/theme-common/internal' +import { + useNavbarMobileSidebar, + useSearchPage, +} from '@docusaurus/theme-common/internal' +import { IconSearch } from '@site/src/components/Icon' +import { IconButton } from '@site/src/components/IconButton' import { globalStore, selectHiddenSidebar, @@ -12,7 +17,9 @@ import NavbarSearch from '@theme/Navbar/Search' import NavbarItem, { Props as NavbarItemConfig } from '@theme/NavbarItem' import SearchBar from '@theme/SearchBar' import clsx from 'clsx' -import React from 'react' +import React, { useState } from 'react' +import { useSearch } from '../../SearchBar/hooks/useSearch' +import { MobileSearch } from './MobileSearch/MobileSearch' import { ShareButton } from './ShareButton' import styles from './styles.module.scss' @@ -59,8 +66,16 @@ export default function NavbarContent(): JSX.Element { const dispatch = globalStore.useDispatch() const hiddenDesktopSidebar = globalStore.useSelector(selectHiddenSidebar) + const [mobileSearch, setMobileSearch] = useState(false) + return ( -
+
)}
+ +
+ {localeDropdown && } + setMobileSearch(true)} + > + + +
+ +
+ setMobileSearch(false)} + /> +
) } diff --git a/src/theme/Navbar/Content/styles.module.scss b/src/theme/Navbar/Content/styles.module.scss index 9e32a17..64b1efa 100644 --- a/src/theme/Navbar/Content/styles.module.scss +++ b/src/theme/Navbar/Content/styles.module.scss @@ -112,6 +112,7 @@ @include utils.responsive('lg', 'down') { .root { padding: 0 var(--ifm-spacing-horizontal); + overflow: hidden; } .root > * { @@ -124,8 +125,6 @@ } .headerMiddle { - margin-left: 20px; - .leftContainer.shifted { transform: none; } @@ -138,6 +137,55 @@ .headerRight { display: none !important; } + + .searchContainer { + display: none; + } +} + +.headerRightMobile { + visibility: visible; + display: flex !important; + + flex: 1 1 auto !important; + + align-items: center; + justify-content: flex-end; + + & > div { + display: initial; + } + + & > div:first-child { + border-radius: 12px; + padding: 4px 12px; + height: 2.125rem; + + a { + font-size: 0.875rem; + } + + svg { + margin-left: 0.75rem; + vertical-align: middle; + } + + margin-right: 0.75rem; + } + + .searchButton { + background-color: #eeeef1; + padding: 7px 13px; + border-radius: 12px; + } + + transition: 0.7s ease-in-out; + transform: translateX(0%); + + &.shifted { + transform: translateX(-100%); + opacity: 0%; + } } /* @@ -160,3 +208,52 @@ Hide color mode toggle in small viewports display: none; } } + +.root { + & > div:first-child, + .headerMiddle { + opacity: 1; + transition: 1s; + visibility: visible; + } +} + +.root.activeMobileSearch { + & > div:first-child, + .headerMiddle { + opacity: 0; + visibility: hidden; + } +} + +.mobileSearchContainer { + top: 0; + left: 0; + width: 100%; + height: 100%; + position: absolute; + + background-color: var(--ifm-background-surface-color); + transform: translateX(100%); + opacity: 0; + transition: 0.6s ease-in-out; + visibility: hidden; + + &.visible { + opacity: 1; + transform: translateX(0%); + visibility: visible; + } +} + +.headerRightMobile { + display: none !important; + visibility: hidden; +} + +@include utils.responsive('lg', 'down') { + .headerRightMobile { + display: flex !important; + visibility: visible; + } +} diff --git a/src/theme/Navbar/index.scss b/src/theme/Navbar/index.scss index cd1c7d7..1575746 100644 --- a/src/theme/Navbar/index.scss +++ b/src/theme/Navbar/index.scss @@ -1,3 +1,5 @@ +@use '@site/src/css/utils'; + .navbar-sidebar__brand { --ifm-navbar-padding-horizontal: 1rem; } @@ -13,3 +15,9 @@ :root { } + +@include utils.responsive('lg', 'down') { + .navbar { + background: var(--ifm-background-surface-color); + } +}