-
Notifications
You must be signed in to change notification settings - Fork 856
feat: DC-4631 Add new dropdown to toc section #7037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d136d38
Add new dropdown to toc section
carlagn 926e668
Update hrefs on dropdown
carlagn cd3c8df
Update icons and add T3
carlagn e2d80ab
Update link text
carlagn 8a9c9f1
revert deleted files
carlagn 8f4e46b
Merge branch 'main' into feat/DC-4631-dropdown-toc
carlagn 86bfb92
cleanup
carlagn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import useComponentVisible from "@site/src/utils/useComponentVisible"; | ||
| import clsx from "clsx"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { Icon } from "../Icon"; | ||
| import styles from "./styles.module.scss"; | ||
|
|
||
| type DropdownType = { | ||
| items: Array<React.ReactNode>; | ||
| anchorText: string; | ||
| dark?: boolean; | ||
| rightClick?: boolean; | ||
| pos?: "top" | "bottom"; | ||
| }; | ||
| const Dropdown = ({ | ||
| anchorText, | ||
| items, | ||
| dark = false, | ||
| rightClick = false, | ||
| pos = "bottom", | ||
| }: DropdownType) => { | ||
| const [isOpen, openDrop] = useState<boolean>(false); | ||
| const { ref, isComponentVisible, setIsComponentVisible } = useComponentVisible(true); | ||
|
|
||
| useEffect(() => { | ||
| if (!isComponentVisible) openDrop(false); | ||
| }, [isComponentVisible]); | ||
|
|
||
| const escEvent = (e: KeyboardEvent) => { | ||
| if (e.key === "Escape") openDrop(false); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| window.addEventListener("keydown", escEvent); | ||
| return () => window.removeEventListener("keydown", escEvent); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div | ||
| className={clsx(styles.root)} | ||
| ref={ref} | ||
| onClick={() => { | ||
| if (!rightClick) { | ||
| setIsComponentVisible(true); | ||
| openDrop(!isOpen); | ||
| } | ||
| }} | ||
| onContextMenu={(e) => { | ||
| if (rightClick && window.innerWidth > 940) { | ||
| e.preventDefault(); | ||
| setIsComponentVisible(true); | ||
| openDrop(true); | ||
| } | ||
| }} | ||
| > | ||
| <div className={clsx(styles.anchor, isOpen && styles.active)}> | ||
| <Icon icon="fa-regular fa-arrow-up-right" size="inherit" btn="left"/> | ||
| {anchorText} | ||
| <Icon icon="fa-regular fa-chevron-down" size="inherit" btn="right"/> | ||
| </div> | ||
| <div | ||
| className={clsx( | ||
| styles.overlayWrapper, | ||
| isOpen && styles.showOverlay | ||
| )} | ||
| onClick={(e: any) => { | ||
| e.stopPropagation(); | ||
| openDrop(false); | ||
| }} | ||
| > | ||
| <div className={clsx(pos === "top" && styles.topPos, styles.container)}> | ||
| {items.map((item: any, idx: number) => ( | ||
| <div key={idx} className={styles.item}> | ||
| {item} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Dropdown; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| $border-color: #2d3748; | ||
|
|
||
| .root { | ||
| color: var(--primary-font-color); | ||
| font-family: var(--font-family-body, Inter); | ||
| font-size: var(--font-size-xs, 14px); | ||
| font-style: normal; | ||
| font-weight: 400; | ||
| line-height: 140%; /* 19.6px */ | ||
| width: fit-content; | ||
| position: absolute; | ||
| right: 0; | ||
| top: 0; | ||
| } | ||
|
|
||
| .anchor { | ||
| border-radius: 8px; | ||
| padding: 4px 8px; | ||
| cursor: pointer; | ||
| width: fit-content; | ||
| border: 1px solid var(--disabled-font-color); | ||
| background: var(--surface-primary); | ||
| &.active { | ||
| background: var(--surface-brand-grey); | ||
| } | ||
| } | ||
|
|
||
| .overlayWrapper { | ||
| opacity: 0; | ||
| pointer-events: none; | ||
| @media (max-width: 599px) { | ||
| position: fixed; | ||
| height: 100vh; | ||
| z-index: 102; | ||
| width: 100vw; | ||
| background: rgb(9, 10, 21, 0.75); | ||
| top: 0; | ||
| left: 0; | ||
| } | ||
| .container { | ||
| transform: translateY(-8px); | ||
| } | ||
| &.showOverlay { | ||
| .container { | ||
| transform: translateY(0); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .showOverlay { | ||
| opacity: 1; | ||
| pointer-events: auto; | ||
| } | ||
|
|
||
| .container { | ||
| background: var(--surface-primary); | ||
| box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.10), 0 2px 4px -2px rgba(0, 0, 0, 0.10); | ||
| border-radius: 8px; | ||
| bottom: 0; | ||
| position: absolute; | ||
| width: 100%; | ||
| overflow: hidden; | ||
| right: 0; | ||
| transition: transform 300ms ease; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
| @media (min-width: 600px) { | ||
| top: 100%; | ||
| margin-top: 16px; | ||
| bottom: unset; | ||
| width: auto; | ||
| } | ||
| } | ||
|
|
||
| .item { | ||
| color: var(--primary-font-color); | ||
| width: max-content; | ||
| min-width: 100%; | ||
| cursor: pointer; | ||
| padding: 6px 12px; | ||
| background: var(--surface-primary); | ||
| transition: background 300ms ease-out; | ||
| &:hover { | ||
| background: var(--surface-brand-grey-strong); | ||
| } | ||
| } | ||
|
|
||
| .topPos { | ||
| @media (min-width: 600px) { | ||
| top: unset !important; | ||
| left: 0 !important; | ||
| transform: unset !important; | ||
| bottom: 100% !important; | ||
| } | ||
| & > * { | ||
| width: 100%; | ||
| display: inline-block; | ||
| } | ||
|
|
||
| a { | ||
| color: inherit; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import React, {type ReactNode} from 'react'; | ||
| import clsx from 'clsx'; | ||
| import {useWindowSize} from '@docusaurus/theme-common'; | ||
| import {useDoc} from '@docusaurus/plugin-content-docs/client'; | ||
| import DocItemPaginator from '@theme/DocItem/Paginator'; | ||
| import DocVersionBanner from '@theme/DocVersionBanner'; | ||
| import DocVersionBadge from '@theme/DocVersionBadge'; | ||
| import DocItemFooter from '@theme/DocItem/Footer'; | ||
| import DocItemTOCMobile from '@theme/DocItem/TOC/Mobile'; | ||
| import DocItemTOCDesktop from '@theme/DocItem/TOC/Desktop'; | ||
| import DocItemContent from '@theme/DocItem/Content'; | ||
| import DocBreadcrumbs from '@theme/DocBreadcrumbs'; | ||
| import ContentVisibility from '@theme/ContentVisibility'; | ||
| import type {Props} from '@theme/DocItem/Layout'; | ||
|
|
||
| import styles from './styles.module.css'; | ||
|
|
||
| /** | ||
| * Decide if the toc should be rendered, on mobile or desktop viewports | ||
| */ | ||
| function useDocTOC() { | ||
| const {frontMatter, toc} = useDoc(); | ||
| const windowSize = useWindowSize(); | ||
|
|
||
| const hidden = frontMatter.hide_table_of_contents; | ||
| const canRender = !hidden && toc.length > 0; | ||
|
|
||
| const mobile = canRender ? <DocItemTOCMobile /> : undefined; | ||
|
|
||
| const desktop = | ||
| canRender && (windowSize === 'desktop' || windowSize === 'ssr') ? ( | ||
| <DocItemTOCDesktop /> | ||
| ) : undefined; | ||
|
|
||
| return { | ||
| hidden, | ||
| mobile, | ||
| desktop, | ||
| }; | ||
| } | ||
|
|
||
| export default function DocItemLayout({children}: Props): ReactNode { | ||
| const docTOC = useDocTOC(); | ||
| const {metadata} = useDoc(); | ||
| return ( | ||
| <div className="row"> | ||
| <div className={clsx('col', !docTOC.hidden && styles.docItemCol)}> | ||
| <ContentVisibility metadata={metadata} /> | ||
| <DocVersionBanner /> | ||
| <div className={styles.docItemContainer}> | ||
| <article> | ||
| <DocBreadcrumbs /> | ||
| <DocVersionBadge /> | ||
| {docTOC.mobile} | ||
| <DocItemContent>{children}</DocItemContent> | ||
| <DocItemFooter /> | ||
| </article> | ||
| <DocItemPaginator /> | ||
| </div> | ||
| </div> | ||
| {docTOC.desktop && <div className="col col--3"> | ||
| {React.cloneElement(docTOC.desktop as React.ReactElement, { | ||
| //@ts-ignore | ||
| metadata, | ||
| })} | ||
| </div>} | ||
carlagn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .docItemContainer header + *, | ||
| .docItemContainer article > *:first-child { | ||
| margin-top: 0; | ||
| } | ||
|
|
||
| @media (min-width: 997px) { | ||
| .docItemCol { | ||
| max-width: 75% !important; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React, {type ReactNode} from 'react'; | ||
| import {ThemeClassNames} from '@docusaurus/theme-common'; | ||
| import {useDoc} from '@docusaurus/plugin-content-docs/client'; | ||
| import TOC from '@site/src/theme/TOC'; | ||
|
|
||
| export default function DocItemTOCDesktop({metadata}: any): ReactNode { | ||
carlagn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const {toc, frontMatter} = useDoc(); | ||
| return ( | ||
| <TOC | ||
| toc={toc} | ||
| minHeadingLevel={frontMatter.toc_min_heading_level} | ||
| maxHeadingLevel={frontMatter.toc_max_heading_level} | ||
| className={ThemeClassNames.docs.docTocDesktop} | ||
| metadata={metadata} | ||
| /> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.