From 34ae55574059cf54850096aa044bed51489c8511 Mon Sep 17 00:00:00 2001 From: "Josh Berman [SSW]" <137844305+joshbermanssw@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:40:46 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20=E2=99=BB=EF=B8=8F=20Rework=20Do?= =?UTF-8?q?cs=20(#2580)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * main of desktop ui * v1 of UI * cleanup of logs * lg view test passed * test passed medium view * sm view test passed * extra clean * make version select work * push pr reviews * bety changes * betty changes * make yt videos full width * add search bar option to search page --- .../DocumentationNavigation/Breadcrumbs.tsx | 34 +-- .../DocumentationNavigation.tsx | 25 +- .../docsMain/directoryOverflowButton.tsx | 50 ++++ components/docsMain/docsMainBody.tsx | 21 ++ components/docsMain/docsMobileHeader.tsx | 77 ++++++ components/docsMain/tocOverflowButton.tsx | 66 ++++++ components/docsSearch/SearchNavigation.tsx | 41 +++- components/layout/DocsLayout.tsx | 80 ++++--- components/layout/Layout.tsx | 2 +- components/styles/Prism.tsx | 11 +- .../docAndBlogComponents.tsx | 50 +++- components/toc/index.tsx | 94 ++++---- components/ui/DocsPagination.tsx | 10 +- content/docs/data-fetching/custom-queries.mdx | 6 +- content/docs/editing/blocks.mdx | 10 +- pages/docs/[...slug].tsx | 221 +++++++++++------- pages/docs/product-tour.tsx | 6 +- pages/search.tsx | 15 +- 18 files changed, 583 insertions(+), 236 deletions(-) create mode 100644 components/docsMain/directoryOverflowButton.tsx create mode 100644 components/docsMain/docsMainBody.tsx create mode 100644 components/docsMain/docsMobileHeader.tsx create mode 100644 components/docsMain/tocOverflowButton.tsx diff --git a/components/DocumentationNavigation/Breadcrumbs.tsx b/components/DocumentationNavigation/Breadcrumbs.tsx index d1956b53a2..7be87c4aa2 100644 --- a/components/DocumentationNavigation/Breadcrumbs.tsx +++ b/components/DocumentationNavigation/Breadcrumbs.tsx @@ -1,7 +1,7 @@ -import React from 'react' -import { useRouter } from 'next/router' -import styled from 'styled-components' -import { matchActualTarget } from 'utils' +import React from 'react'; +import { useRouter } from 'next/router'; +import styled from 'styled-components'; +import { matchActualTarget } from 'utils'; export const ChevronRightIcon = ({ ...props }) => ( ( > -) +); export interface DocsNavProps { - navItems: any + navItems: any; } const getNestedBreadcrumbs = ( @@ -27,38 +27,38 @@ const getNestedBreadcrumbs = ( ) => { for (const listItem of listItems || []) { if (matchActualTarget(pagePath, listItem.slug || listItem.href)) { - breadcrumbs.push(listItem) - return [listItem] + breadcrumbs.push(listItem); + return [listItem]; } const nestedBreadcrumbs = getNestedBreadcrumbs( listItem.items, pagePath, breadcrumbs - ) + ); if (nestedBreadcrumbs.length) { - return [listItem, ...nestedBreadcrumbs] + return [listItem, ...nestedBreadcrumbs]; } } - return [] -} + return []; +}; export function Breadcrumbs({ navItems }: DocsNavProps) { - const router = useRouter() - const breadcrumbs = getNestedBreadcrumbs(navItems, router.asPath) || [] + const router = useRouter(); + const breadcrumbs = getNestedBreadcrumbs(navItems, router.asPath) || []; return ( <> {breadcrumbs.map((breadcrumb, i) => (
  • {i != 0 && } - + {breadcrumb.title || breadcrumb.category}
  • ))}
    - ) + ); } const BreadcrumbList = styled.ul` @@ -107,4 +107,4 @@ const BreadcrumbList = styled.ul` opacity: 1 !important; } } -` +`; diff --git a/components/DocumentationNavigation/DocumentationNavigation.tsx b/components/DocumentationNavigation/DocumentationNavigation.tsx index 0dd99e5ff6..897d9e0043 100644 --- a/components/DocumentationNavigation/DocumentationNavigation.tsx +++ b/components/DocumentationNavigation/DocumentationNavigation.tsx @@ -11,6 +11,7 @@ import { searchIndices } from '../../components/search/indices'; import { VersionSelect } from './VersionSelect'; import { BiMenu } from 'react-icons/bi'; import { IoMdClose } from 'react-icons/io'; +import { LeftHandSideParentContainer } from 'components/docsSearch/SearchNavigation'; export interface DocsNavProps { navItems: any; @@ -28,30 +29,6 @@ export function DocumentationNavigation({ navItems }: DocsNavProps) { onClick={() => setMobileNavIsOpen(!mobileNavIsOpen)} /> )} - - - - -
    - Tina Docs -
    - -
    - - - setMobileNavIsOpen(false)}> - - - - -
    - - {router.isFallback ? ( - - ) : ( - - )} -
    { + return ( +
    + +
    + ); +}; + +const DirectoryOverflowButton = (tocData) => { + const [isTableOfContentsOpen, setIsTableOfContentsOpen] = useState(false); + const containerRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event) => { + if (containerRef.current && !containerRef.current.contains(event.target)) { + setIsTableOfContentsOpen(false); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, []); + + return ( +
    +
    setIsTableOfContentsOpen(!isTableOfContentsOpen)} + > + + + Topics + +
    + {isTableOfContentsOpen && ( +
    + +
    + )} +
    + ); +}; + +export default DirectoryOverflowButton; diff --git a/components/docsMain/docsMainBody.tsx b/components/docsMain/docsMainBody.tsx new file mode 100644 index 0000000000..e8f06208c9 --- /dev/null +++ b/components/docsMain/docsMainBody.tsx @@ -0,0 +1,21 @@ +import { Breadcrumbs } from 'components/DocumentationNavigation/Breadcrumbs'; +import DocsMobileHeader from './docsMobileHeader'; + +const MainDocsBodyHeader = (docData) => { + const DocumentTitle = docData.data.new.results.data.doc.title; + + return ( +
    + {docData.screenSizing && ( + + )} + + +
    + {DocumentTitle} +
    +
    + ); +}; + +export default MainDocsBodyHeader; diff --git a/components/docsMain/docsMobileHeader.tsx b/components/docsMain/docsMobileHeader.tsx new file mode 100644 index 0000000000..82184e48d6 --- /dev/null +++ b/components/docsMain/docsMobileHeader.tsx @@ -0,0 +1,77 @@ +import { DocsSearchBarHeader } from 'components/docsSearch/SearchNavigation'; +import { useState } from 'react'; +import { FaChevronRight } from 'react-icons/fa'; +import DirectoryOverflowButton from './directoryOverflowButton'; + +export const MobileVersionSelect = () => { + const versions = [ + ['v.Latest', ''], + [ + 'v.0.68.13', + 'https://tinacms-site-next-i08bcbicy-tinacms.vercel.app/docs/', + ], + ['v.0.67.3', 'https://tinacms-site-next-pu1t2v9y4-tinacms.vercel.app/'], + ['v.Pre-Beta', 'https://pre-beta.tina.io/'], + ]; + const [versionSelected, setVersionSelected] = useState(versions[0][0]); + const [isOverflowOpen, setIsOverflowOpen] = useState(false); + + const handleVersionClick = (version) => { + setVersionSelected(version[0]); + setIsOverflowOpen(false); + + if (version[0] !== 'v.Latest') { + window.location.href = version[1]; + } + }; + + return ( +
    + {/* VERSION SELECT PILL BUTTON */} +
    setIsOverflowOpen(!isOverflowOpen)} + > +
    {versionSelected}
    +
    + +
    +
    + {/* VERSION SELECT OVERFLOW */} + {isOverflowOpen && ( +
    + {versions.map((version, index) => ( +
    handleVersionClick(version)} + > + {version[0]} +
    + ))} +
    + )} +
    + ); +}; + +const DocsMobileHeader = (data) => { + return ( +
    + + +
    + ); +}; + +export default DocsMobileHeader; diff --git a/components/docsMain/tocOverflowButton.tsx b/components/docsMain/tocOverflowButton.tsx new file mode 100644 index 0000000000..0e622e2799 --- /dev/null +++ b/components/docsMain/tocOverflowButton.tsx @@ -0,0 +1,66 @@ +import Link from 'next/link'; +import { useState, useEffect, useRef } from 'react'; +import { MdMenu } from 'react-icons/md'; +import { getDocId } from 'utils/docs/getDocIds'; + +const TocOverflow = ({ tocData }) => { + return ( +
    + {tocData.tocData.map((item, index) => { + const textIndentation = + item.type === 'h3' ? 'ml-4' : item.type === 'h4' ? 'ml-8' : ''; + + const linkHref = `#${item.text.replace(/\s+/g, '-').toLowerCase()}`; + + return ( + + {item.text} + + ); + })} +
    + ); +}; + +const TocOverflowButton = (tocData) => { + const [isTableOfContentsOpen, setIsTableOfContentsOpen] = useState(false); + const containerRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event) => { + if (containerRef.current && !containerRef.current.contains(event.target)) { + setIsTableOfContentsOpen(false); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, []); + + return ( +
    +
    setIsTableOfContentsOpen(!isTableOfContentsOpen)} + > + + + Table of Contents + +
    + {isTableOfContentsOpen && ( +
    + +
    + )} +
    + ); +}; + +export default TocOverflowButton; diff --git a/components/docsSearch/SearchNavigation.tsx b/components/docsSearch/SearchNavigation.tsx index 52fa68d82b..383fd8991a 100644 --- a/components/docsSearch/SearchNavigation.tsx +++ b/components/docsSearch/SearchNavigation.tsx @@ -1,8 +1,9 @@ import { DocsNavigationList } from 'components/DocumentationNavigation/DocsNavigationList'; import { VersionSelect } from 'components/DocumentationNavigation/VersionSelect'; +import { MobileVersionSelect } from 'components/docsMain/docsMobileHeader'; import Link from 'next/link'; import { useRouter } from 'next/router'; -import { useState, useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { HiMagnifyingGlass } from 'react-icons/hi2'; import { fetchAlgoliaSearchResults } from 'utils/new-search'; @@ -91,7 +92,7 @@ export const SearchResultsOverflowTabs = ({ query }) => {