@redocly/theme 0.1.6 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Footer/Footer.d.ts +3 -0
- package/Footer/Footer.js +35 -0
- package/Footer/FooterColumn.d.ts +7 -0
- package/Footer/FooterColumn.js +39 -0
- package/Footer/FooterColumns.d.ts +7 -0
- package/Footer/FooterColumns.js +44 -0
- package/Footer/FooterCopyright.d.ts +5 -0
- package/Footer/FooterCopyright.js +30 -0
- package/Footer/index.d.ts +4 -0
- package/Footer/index.js +20 -0
- package/JsonViewer/JsonViewer.js +1 -1
- package/JsonViewer/index.d.ts +1 -0
- package/JsonViewer/index.js +1 -0
- package/Layout/PageLayout.d.ts +6 -0
- package/Layout/PageLayout.js +31 -0
- package/Layout/RootLayout.d.ts +7 -0
- package/Layout/RootLayout.js +32 -0
- package/Layout/index.d.ts +2 -0
- package/Layout/index.js +18 -0
- package/Logo/Logo.d.ts +1 -6
- package/Logo/index.d.ts +1 -0
- package/Logo/index.js +17 -0
- package/Markdown/Admonition.d.ts +9 -0
- package/Markdown/Admonition.js +39 -0
- package/Markdown/CodeSample/CodeSample.d.ts +8 -0
- package/Markdown/CodeSample/CodeSample.js +30 -0
- package/Markdown/CodeSample/index.d.ts +3 -0
- package/Markdown/CodeSample/index.js +19 -0
- package/Markdown/CodeSample/styled.d.ts +5 -0
- package/Markdown/CodeSample/styled.js +109 -0
- package/Markdown/CodeSample/types.d.ts +9 -0
- package/Markdown/CodeSample/types.js +2 -0
- package/Markdown/ContentWrapper.d.ts +5 -0
- package/Markdown/ContentWrapper.js +21 -0
- package/Markdown/Heading.d.ts +5 -0
- package/Markdown/Heading.js +23 -0
- package/Markdown/MarkdownLayout.d.ts +7 -0
- package/Markdown/MarkdownLayout.js +23 -0
- package/Markdown/Mermaid.d.ts +6 -0
- package/Markdown/Mermaid.js +19 -0
- package/Markdown/PageWrapper.d.ts +3 -0
- package/Markdown/PageWrapper.js +15 -0
- package/Markdown/StyledMarkdown.d.ts +8 -0
- package/Markdown/StyledMarkdown.js +54 -0
- package/Markdown/Tabs/Tab.d.ts +8 -0
- package/Markdown/Tabs/Tab.js +35 -0
- package/Markdown/Tabs/Tabs.d.ts +10 -0
- package/Markdown/Tabs/Tabs.js +43 -0
- package/Markdown/Tabs/index.d.ts +2 -0
- package/Markdown/Tabs/index.js +18 -0
- package/Markdown/index.d.ts +9 -0
- package/Markdown/index.js +25 -0
- package/Navbar/Navbar.d.ts +2 -1
- package/Navbar/Navbar.js +9 -3
- package/Navbar/NavbarItem.d.ts +1 -1
- package/Navbar/NavbarItem.js +3 -3
- package/Navbar/NavbarMenu.d.ts +1 -1
- package/Navbar/NavbarMenu.js +8 -4
- package/OperationBadge/OperationBadge.d.ts +5 -0
- package/OperationBadge/OperationBadge.js +15 -0
- package/OperationBadge/index.d.ts +1 -0
- package/OperationBadge/index.js +17 -0
- package/PageNavigation/NextPageLink.d.ts +2 -0
- package/PageNavigation/NextPageLink.js +25 -0
- package/PageNavigation/PageNavigation.d.ts +2 -0
- package/PageNavigation/PageNavigation.js +31 -0
- package/PageNavigation/PreviousPageLink.d.ts +2 -0
- package/PageNavigation/PreviousPageLink.js +25 -0
- package/Panel/CodePanel.js +6 -6
- package/Panel/ContentPanel.js +4 -4
- package/Panel/Panel.d.ts +1 -1
- package/Panel/Panel.js +3 -3
- package/Panel/PanelComponent.d.ts +1 -1
- package/Panel/PanelComponent.js +3 -3
- package/Panel/index.d.ts +1 -0
- package/Panel/index.js +1 -0
- package/Search/Autocomplete.d.ts +13 -0
- package/Search/Autocomplete.js +79 -0
- package/Search/ClearIcon.d.ts +2 -0
- package/Search/ClearIcon.js +29 -0
- package/Search/Input.d.ts +3 -0
- package/Search/Input.js +15 -0
- package/Search/Parameters.d.ts +7 -0
- package/Search/Parameters.js +42 -0
- package/Search/Popover.d.ts +3 -0
- package/Search/Popover.js +15 -0
- package/Search/Search.d.ts +2 -0
- package/Search/Search.js +39 -0
- package/Search/SearchIcon.d.ts +2 -0
- package/Search/SearchIcon.js +29 -0
- package/Search/SearchItem.d.ts +7 -0
- package/Search/SearchItem.js +47 -0
- package/Search/index.d.ts +9 -0
- package/Search/index.js +25 -0
- package/Search/utils.d.ts +2 -0
- package/Search/utils.js +21 -0
- package/Sidebar/ApiCallItem.d.ts +8 -0
- package/Sidebar/ApiCallItem.js +35 -0
- package/Sidebar/ArrowBack.d.ts +4 -0
- package/Sidebar/ArrowBack.js +29 -0
- package/Sidebar/BackButton.d.ts +6 -0
- package/Sidebar/BackButton.js +31 -0
- package/Sidebar/Drilldown.d.ts +8 -0
- package/Sidebar/Drilldown.js +46 -0
- package/Sidebar/DrilldownMenu.d.ts +3 -0
- package/Sidebar/DrilldownMenu.js +55 -0
- package/Sidebar/DrilldownMenuItem.d.ts +3 -0
- package/Sidebar/DrilldownMenuItem.js +32 -0
- package/Sidebar/ExternalIcon.d.ts +4 -0
- package/Sidebar/ExternalIcon.js +29 -0
- package/Sidebar/Menu.d.ts +3 -0
- package/Sidebar/Menu.js +15 -0
- package/Sidebar/MenuContainer.d.ts +1 -0
- package/Sidebar/MenuContainer.js +13 -0
- package/Sidebar/MenuGroup.d.ts +9 -0
- package/Sidebar/MenuGroup.js +37 -0
- package/Sidebar/MenuItem.d.ts +3 -0
- package/Sidebar/MenuItem.js +34 -0
- package/Sidebar/MenuItemLabel.d.ts +5 -0
- package/Sidebar/MenuItemLabel.js +19 -0
- package/Sidebar/MenuLink.d.ts +5 -0
- package/Sidebar/MenuLink.js +16 -0
- package/Sidebar/MenuLinkItem.d.ts +3 -0
- package/Sidebar/MenuLinkItem.js +31 -0
- package/Sidebar/MobileSidebarButton.d.ts +5 -0
- package/Sidebar/MobileSidebarButton.js +21 -0
- package/Sidebar/Separator.d.ts +3 -0
- package/Sidebar/Separator.js +32 -0
- package/Sidebar/SeparatorItem.d.ts +5 -0
- package/Sidebar/SeparatorItem.js +14 -0
- package/Sidebar/SeparatorLine.d.ts +3 -0
- package/Sidebar/SeparatorLine.js +15 -0
- package/Sidebar/Sidebar.d.ts +8 -0
- package/Sidebar/Sidebar.js +24 -0
- package/Sidebar/SidebarLayout.d.ts +7 -0
- package/Sidebar/SidebarLayout.js +36 -0
- package/Sidebar/index.d.ts +19 -0
- package/Sidebar/index.js +35 -0
- package/Sidebar/types/DrilldownMenuProps.d.ts +6 -0
- package/Sidebar/types/DrilldownMenuProps.js +2 -0
- package/Sidebar/types/ItemState.d.ts +8 -0
- package/Sidebar/types/ItemState.js +2 -0
- package/Sidebar/types/MenuItemProps.d.ts +5 -0
- package/Sidebar/types/MenuItemProps.js +2 -0
- package/Sidebar/types/MenuStyle.d.ts +3 -0
- package/Sidebar/types/MenuStyle.js +8 -0
- package/Sidebar/types/NavItem.d.ts +26 -0
- package/Sidebar/types/NavItem.js +2 -0
- package/Sidebar/types/index.d.ts +5 -0
- package/Sidebar/types/index.js +21 -0
- package/SourceCode/SourceCode.js +2 -2
- package/TableOfContent/TableOfContent.d.ts +9 -0
- package/TableOfContent/TableOfContent.js +65 -0
- package/TableOfContent/index.d.ts +1 -0
- package/TableOfContent/index.js +17 -0
- package/globalStyle.js +1 -1
- package/hooks/index.d.ts +4 -0
- package/hooks/index.js +4 -0
- package/hooks/useActiveHeading.d.ts +2 -0
- package/hooks/useActiveHeading.js +34 -0
- package/hooks/useActiveSectionId.d.ts +3 -0
- package/hooks/useActiveSectionId.js +48 -0
- package/hooks/useFullHeight.d.ts +2 -0
- package/hooks/useFullHeight.js +47 -0
- package/hooks/useMobileMenu.d.ts +2 -0
- package/hooks/useMobileMenu.js +13 -0
- package/hooks/useNavbarHeight.d.ts +3 -0
- package/hooks/useNavbarHeight.js +20 -0
- package/icons/ShelfIcon/ShelfIcon.js +2 -2
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/mocks/hooks/usePageData.d.ts +5 -0
- package/mocks/hooks/usePageData.js +7 -0
- package/mocks/models.d.ts +3 -0
- package/mocks/models.js +2 -0
- package/mocks/search.d.ts +22 -0
- package/mocks/search.js +13 -0
- package/mocks/types/index.d.ts +1 -0
- package/mocks/types/index.js +2 -0
- package/mocks/usePreloadHistory.d.ts +3 -0
- package/mocks/usePreloadHistory.js +12 -0
- package/package.json +5 -2
- package/src/Button/Button.stories.tsx +1 -1
- package/src/Button/__tests__/Button.test.tsx +1 -1
- package/src/CodeBlock/__tests__/CodeBlock.test.tsx +1 -1
- package/src/CopyButton/CopyButton.stories.tsx +1 -1
- package/src/CopyButton/CopyButton.tsx +1 -1
- package/src/CopyButton/CopyButtonWrapper.tsx +4 -4
- package/src/CopyButton/__tests__/CopyButton.test.tsx +1 -1
- package/src/CopyButton/__tests__/CopyButtonWrapper.test.tsx +2 -1
- package/src/Footer/Footer.tsx +34 -0
- package/src/Footer/FooterColumn.tsx +62 -0
- package/src/Footer/FooterColumns.tsx +51 -0
- package/src/Footer/FooterCopyright.tsx +26 -0
- package/src/Footer/index.ts +4 -0
- package/src/Headings/Headings.stories.tsx +1 -1
- package/src/Headings/Headings.ts +1 -1
- package/src/Headings/__tests__/Headings.test.tsx +1 -1
- package/src/JsonViewer/JsonViewer.stories.tsx +1 -1
- package/src/JsonViewer/JsonViewer.tsx +6 -7
- package/src/JsonViewer/__tests__/JsonViewer.test.tsx +2 -1
- package/src/JsonViewer/index.ts +1 -0
- package/src/Layout/PageLayout.tsx +34 -0
- package/src/Layout/RootLayout.tsx +24 -0
- package/src/Layout/index.ts +2 -0
- package/src/Logo/Logo.tsx +1 -7
- package/src/Logo/index.ts +1 -0
- package/src/Markdown/Admonition.tsx +64 -0
- package/src/Markdown/CodeSample/CodeSample.tsx +39 -0
- package/src/Markdown/CodeSample/index.ts +3 -0
- package/src/Markdown/CodeSample/styled.ts +289 -0
- package/src/Markdown/CodeSample/types.ts +40 -0
- package/src/Markdown/ContentWrapper.tsx +20 -0
- package/src/Markdown/Heading.tsx +35 -0
- package/src/Markdown/MarkdownLayout.tsx +25 -0
- package/src/Markdown/Mermaid.tsx +23 -0
- package/src/Markdown/PageWrapper.tsx +9 -0
- package/src/Markdown/StyledMarkdown.tsx +312 -0
- package/src/Markdown/Tabs/Tab.tsx +37 -0
- package/src/Markdown/Tabs/Tabs.tsx +45 -0
- package/src/Markdown/Tabs/index.ts +2 -0
- package/src/Markdown/index.ts +9 -0
- package/src/Navbar/Navbar.stories.tsx +3 -13
- package/src/Navbar/Navbar.tsx +20 -26
- package/src/Navbar/NavbarItem.tsx +2 -2
- package/src/Navbar/NavbarMenu.tsx +6 -6
- package/src/OperationBadge/OperationBadge.stories.tsx +35 -0
- package/src/OperationBadge/OperationBadge.ts +59 -0
- package/src/OperationBadge/__tests__/OperationBadge.test.tsx +59 -0
- package/src/OperationBadge/__tests__/__snapshots__/OperationBadge.test.tsx.snap +651 -0
- package/src/OperationBadge/index.ts +1 -0
- package/src/PageNavigation/NextPageLink.tsx +22 -0
- package/src/PageNavigation/PageNavigation.tsx +20 -0
- package/src/PageNavigation/PreviousPageLink.tsx +22 -0
- package/src/Panel/CodePanel.stories.tsx +1 -2
- package/src/Panel/CodePanel.ts +8 -7
- package/src/Panel/ContentPanel.stories.tsx +1 -2
- package/src/Panel/ContentPanel.ts +5 -6
- package/src/Panel/Panel.stories.tsx +1 -3
- package/src/Panel/Panel.ts +3 -3
- package/src/Panel/PanelComponent.tsx +4 -5
- package/src/Panel/__tests__/CodePanel.test.tsx +1 -1
- package/src/Panel/__tests__/ContentPanel.test.tsx +1 -1
- package/src/Panel/__tests__/Panel.test.tsx +1 -2
- package/src/Panel/__tests__/__snapshots__/CodePanel.test.tsx.snap +8 -8
- package/src/Panel/__tests__/__snapshots__/ContentPanel.test.tsx.snap +22 -22
- package/src/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +16 -16
- package/src/Panel/index.ts +1 -0
- package/src/SamplesPanelControls/SamplesControlButton.stories.tsx +1 -1
- package/src/SamplesPanelControls/SamplesPanelControls.ts +1 -1
- package/src/Search/Autocomplete.tsx +128 -0
- package/src/Search/ClearIcon.tsx +31 -0
- package/src/Search/Input.tsx +19 -0
- package/src/Search/Parameters.tsx +62 -0
- package/src/Search/Popover.tsx +20 -0
- package/src/Search/Search.tsx +52 -0
- package/src/Search/SearchIcon.tsx +32 -0
- package/src/Search/SearchItem.tsx +85 -0
- package/src/Search/index.ts +9 -0
- package/src/Search/utils.tsx +19 -0
- package/src/Sidebar/ApiCallItem.tsx +33 -0
- package/src/Sidebar/ArrowBack.tsx +22 -0
- package/src/Sidebar/BackButton.tsx +44 -0
- package/src/Sidebar/Drilldown.tsx +46 -0
- package/src/Sidebar/DrilldownMenu.tsx +58 -0
- package/src/Sidebar/DrilldownMenuItem.tsx +40 -0
- package/src/Sidebar/ExternalIcon.tsx +37 -0
- package/src/Sidebar/Menu.tsx +11 -0
- package/src/Sidebar/MenuContainer.tsx +8 -0
- package/src/Sidebar/MenuGroup.tsx +55 -0
- package/src/Sidebar/MenuItem.tsx +25 -0
- package/src/Sidebar/MenuItemLabel.tsx +41 -0
- package/src/Sidebar/MenuLink.tsx +14 -0
- package/src/Sidebar/MenuLinkItem.tsx +24 -0
- package/src/Sidebar/MobileSidebarButton.tsx +44 -0
- package/src/Sidebar/Separator.tsx +17 -0
- package/src/Sidebar/SeparatorItem.tsx +14 -0
- package/src/Sidebar/SeparatorLine.tsx +9 -0
- package/src/Sidebar/Sidebar.tsx +54 -0
- package/src/Sidebar/SidebarLayout.tsx +30 -0
- package/src/Sidebar/index.ts +19 -0
- package/src/Sidebar/types/DrilldownMenuProps.ts +7 -0
- package/src/Sidebar/types/ItemState.ts +9 -0
- package/src/Sidebar/types/MenuItemProps.ts +6 -0
- package/src/Sidebar/types/MenuStyle.ts +4 -0
- package/src/Sidebar/types/NavItem.ts +27 -0
- package/src/Sidebar/types/index.ts +5 -0
- package/src/SidebarLogo/SidebarLogo.stories.tsx +1 -1
- package/src/SidebarLogo/__tests__/SidebarLogo.test.tsx +1 -1
- package/src/SourceCode/SourceCode.stories.tsx +1 -1
- package/src/SourceCode/SourceCode.tsx +7 -3
- package/src/SourceCode/__tests__/SourceCode.test.tsx +2 -1
- package/src/TableOfContent/TableOfContent.stories.tsx +39 -0
- package/src/TableOfContent/TableOfContent.tsx +112 -0
- package/src/TableOfContent/index.ts +1 -0
- package/src/Tooltip/Tooltip.stories.tsx +1 -1
- package/src/Tooltip/Tooltip.tsx +1 -1
- package/src/Tooltip/__tests__/Tooltip.test.tsx +1 -1
- package/src/globalStyle.ts +10 -73
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useActiveHeading.ts +46 -0
- package/src/hooks/useActiveSectionId.ts +53 -0
- package/src/hooks/useFullHeight.ts +47 -0
- package/src/hooks/useMobileMenu.ts +11 -0
- package/src/hooks/useNavbarHeight.ts +24 -0
- package/src/icons/ShelfIcon/ShelfIcon.stories.tsx +1 -1
- package/src/icons/ShelfIcon/ShelfIcon.tsx +1 -1
- package/src/icons/ShelfIcon/__tests__/ShelfIcon.test.tsx +1 -1
- package/src/index.ts +2 -0
- package/src/mocks/hooks/usePageData.ts +8 -0
- package/src/mocks/models.ts +3 -0
- package/src/mocks/search.ts +31 -0
- package/src/mocks/types/index.ts +1 -0
- package/src/mocks/usePreloadHistory.ts +9 -0
- package/src/types/portal/index.d.ts +6 -0
- package/src/types/portal/src/client/app/Sidebar/types.d.ts +50 -0
- package/src/types/portal/src/client/app/media-css.d.ts +7 -0
- package/src/types/portal/src/client/styling/default.d.ts +407 -0
- package/src/types/portal/src/client/styling/index.d.ts +14 -0
- package/src/types/portal/src/client/styling/resolve.d.ts +1 -0
- package/src/types/portal/src/server/constants.d.ts +11 -0
- package/src/types/portal/src/server/plugins/markdown/types.d.ts +28 -0
- package/src/types/portal/src/server/plugins/nav-utils.d.ts +19 -0
- package/src/types/portal/src/server/plugins/portal-config/types.d.ts +23 -0
- package/src/types/portal/src/server/plugins/sidebars/index.d.ts +16 -0
- package/src/types/portal/src/server/plugins/versions/index.d.ts +15 -0
- package/src/types/portal/src/server/plugins/versions/types.d.ts +23 -0
- package/src/types/portal/src/server/plugins/versions/utils.d.ts +10 -0
- package/src/types/portal/src/server/store.d.ts +101 -0
- package/src/types/portal/src/server/utils/async.d.ts +5 -0
- package/src/types/portal/src/server/utils/crypto.d.ts +3 -0
- package/src/types/portal/src/server/utils/fs.d.ts +3 -0
- package/src/types/portal/src/server/utils/index.d.ts +6 -0
- package/src/types/portal/src/server/utils/paths.d.ts +16 -0
- package/src/types/portal/src/server/utils/reporter/formatter.d.ts +11 -0
- package/src/types/portal/src/server/utils/reporter/reporter.d.ts +17 -0
- package/src/types/portal/src/server/utils/watcher.d.ts +16 -0
- package/src/types/portal/src/server/utils/yaml.d.ts +1 -0
- package/src/types/portal/src/shared/constants.d.ts +8 -0
- package/src/types/portal/src/shared/types.d.ts +77 -0
- package/src/types/portal/src/shared/urls.d.ts +7 -0
- package/src/types/portal/src/shared/utils.d.ts +10 -0
- package/src/ui/AlertIcon.tsx +110 -0
- package/src/ui/Arrow.tsx +36 -0
- package/src/ui/Background.tsx +16 -0
- package/src/ui/Box.tsx +39 -0
- package/src/ui/Button.tsx +19 -0
- package/src/ui/Dropdown.tsx +132 -0
- package/src/ui/Flex.tsx +21 -0
- package/src/ui/Jumbotron.tsx +57 -0
- package/src/ui/Tiles/ThinTile.tsx +151 -0
- package/src/ui/Tiles/TileHeader.ts +13 -0
- package/src/ui/Tiles/TileText.tsx +12 -0
- package/src/ui/Tiles/WideTile.tsx +138 -0
- package/src/ui/Tiles/index.ts +4 -0
- package/src/ui/Typography.tsx +167 -0
- package/src/ui/UniversalLink.tsx +100 -0
- package/src/ui/index.tsx +17 -0
- package/src/utils/__tests__/ClipboardService.test.ts +1 -1
- package/src/utils/__tests__/css-variables.test.ts +1 -1
- package/src/utils/__tests__/highlight.test.ts +1 -1
- package/src/utils/__tests__/jsonToHtml.test.ts +1 -1
- package/src/utils/__tests__/media-css.test.ts +1 -1
- package/src/utils/__tests__/theme-helpers.test.ts +1 -1
- package/src/utils/getNavbarElement.ts +10 -0
- package/src/utils/isUrl.ts +42 -0
- package/src/utils/replaceHashInColor.ts +3 -0
- package/ui/AlertIcon.d.ts +9 -0
- package/ui/AlertIcon.js +45 -0
- package/ui/Arrow.d.ts +7 -0
- package/ui/Arrow.js +42 -0
- package/ui/Background.d.ts +7 -0
- package/ui/Background.js +16 -0
- package/ui/Box.d.ts +6 -0
- package/ui/Box.js +16 -0
- package/ui/Button.d.ts +7 -0
- package/ui/Button.js +27 -0
- package/ui/Dropdown.d.ts +8 -0
- package/ui/Dropdown.js +55 -0
- package/ui/Flex.d.ts +10 -0
- package/ui/Flex.js +31 -0
- package/ui/Jumbotron.d.ts +18 -0
- package/ui/Jumbotron.js +44 -0
- package/ui/Tiles/ThinTile.d.ts +21 -0
- package/ui/Tiles/ThinTile.js +98 -0
- package/ui/Tiles/TileHeader.d.ts +5 -0
- package/ui/Tiles/TileHeader.js +15 -0
- package/ui/Tiles/TileText.d.ts +5 -0
- package/ui/Tiles/TileText.js +15 -0
- package/ui/Tiles/WideTile.d.ts +7 -0
- package/ui/Tiles/WideTile.js +93 -0
- package/ui/Tiles/index.d.ts +4 -0
- package/ui/Tiles/index.js +20 -0
- package/ui/Typography.d.ts +110 -0
- package/ui/Typography.js +137 -0
- package/ui/UniversalLink.d.ts +17 -0
- package/ui/UniversalLink.js +62 -0
- package/ui/index.d.ts +14 -0
- package/ui/index.js +34 -0
- package/utils/getNavbarElement.d.ts +1 -0
- package/utils/getNavbarElement.js +14 -0
- package/utils/isUrl.d.ts +12 -0
- package/utils/isUrl.js +36 -0
- package/utils/replaceHashInColor.d.ts +1 -0
- package/utils/replaceHashInColor.js +7 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const SeparatorLine = styled.div.attrs(() => ({
|
|
4
|
+
'data-component-name': 'Sidebar/SeparatorLine',
|
|
5
|
+
}))`
|
|
6
|
+
height: 1px;
|
|
7
|
+
background-color: var(--sidebar-separator-line-color);
|
|
8
|
+
margin: var(--sidebar-spacing-padding-vertical) 0;
|
|
9
|
+
`;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
interface SidebarProps {
|
|
4
|
+
opened?: boolean;
|
|
5
|
+
animate?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const Sidebar = styled.aside.attrs(() => ({
|
|
9
|
+
'data-component-name': 'Sidebar/Sidebar',
|
|
10
|
+
}))<SidebarProps>`
|
|
11
|
+
border-right: 1px solid var(--sidebar-right-line-color);
|
|
12
|
+
position: fixed;
|
|
13
|
+
left: 0;
|
|
14
|
+
right: 0;
|
|
15
|
+
bottom: 0;
|
|
16
|
+
z-index: 2;
|
|
17
|
+
background: var(--sidebar-background-color);
|
|
18
|
+
font-size: var(--sidebar-font-size);
|
|
19
|
+
font-family: var(--sidebar-font-family);
|
|
20
|
+
color: var(--sidebar-text-color);
|
|
21
|
+
top: var(--navbar-height);
|
|
22
|
+
height: calc(100vh - var(--navbar-height));
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
width: 100%;
|
|
26
|
+
-webkit-font-smoothing: antialiased;
|
|
27
|
+
|
|
28
|
+
${({ opened, animate }) => `
|
|
29
|
+
opacity: ${opened ? '1' : '0'};
|
|
30
|
+
pointer-events: ${opened ? 'auto' : 'none'};
|
|
31
|
+
|
|
32
|
+
& > * {
|
|
33
|
+
transform: ${opened ? 'translate(0, 0)' : 'translate(0, 40px)'};
|
|
34
|
+
transition: ${animate ? 'transform 0.65s ease, opacity 0.25s ease;' : 'none'};
|
|
35
|
+
}
|
|
36
|
+
`};
|
|
37
|
+
|
|
38
|
+
${({ theme }) => theme.mediaQueries.medium} {
|
|
39
|
+
position: sticky;
|
|
40
|
+
pointer-events: auto;
|
|
41
|
+
display: flex;
|
|
42
|
+
opacity: 1;
|
|
43
|
+
flex-shrink: 0;
|
|
44
|
+
width: var(--sidebar-width);
|
|
45
|
+
|
|
46
|
+
& > * {
|
|
47
|
+
transform: none;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
${({ theme }) => theme.mediaQueries.large} {
|
|
52
|
+
transform: none;
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { Sidebar } from '@theme/Sidebar/Sidebar';
|
|
5
|
+
import { useMobileMenu } from '@theme/hooks/useMobileMenu';
|
|
6
|
+
import { MobileSidebarButton } from '@theme/Sidebar/MobileSidebarButton';
|
|
7
|
+
import { MenuContainer } from '@theme/Sidebar/MenuContainer';
|
|
8
|
+
|
|
9
|
+
interface SidebarLayoutProps {
|
|
10
|
+
versions: React.ReactNode;
|
|
11
|
+
menu: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function SidebarLayout({ versions, menu }: SidebarLayoutProps): JSX.Element {
|
|
15
|
+
const [isOpen, setIsOpen] = useMobileMenu();
|
|
16
|
+
const toggleMenu = () => setIsOpen(!isOpen);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Wrapper data-component-name="Sidebar/SidebarLayout">
|
|
20
|
+
<MobileSidebarButton opened={isOpen} onClick={toggleMenu} />
|
|
21
|
+
|
|
22
|
+
<Sidebar animate={true} opened={isOpen}>
|
|
23
|
+
{versions}
|
|
24
|
+
<MenuContainer>{menu}</MenuContainer>
|
|
25
|
+
</Sidebar>
|
|
26
|
+
</Wrapper>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const Wrapper = styled.div``;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './ApiCallItem';
|
|
2
|
+
export * from './ArrowBack';
|
|
3
|
+
export * from './BackButton';
|
|
4
|
+
export * from './Drilldown';
|
|
5
|
+
export * from './DrilldownMenu';
|
|
6
|
+
export * from './DrilldownMenuItem';
|
|
7
|
+
export * from './ExternalIcon';
|
|
8
|
+
export * from './Menu';
|
|
9
|
+
export * from './MenuContainer';
|
|
10
|
+
export * from './MenuGroup';
|
|
11
|
+
export * from './MenuItem';
|
|
12
|
+
export * from './MenuItemLabel';
|
|
13
|
+
export * from './MenuLink';
|
|
14
|
+
export * from './MenuLinkItem';
|
|
15
|
+
export * from './MobileSidebarButton';
|
|
16
|
+
export * from './Separator';
|
|
17
|
+
export * from './SeparatorItem';
|
|
18
|
+
export * from './Sidebar';
|
|
19
|
+
export * from './SidebarLayout';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NavItem } from '@theme/Sidebar/types/NavItem';
|
|
2
|
+
import { MenuStyle } from '@theme/Sidebar/types/MenuStyle';
|
|
3
|
+
|
|
4
|
+
export interface ItemState extends NavItem {
|
|
5
|
+
items: ItemState[];
|
|
6
|
+
active: boolean;
|
|
7
|
+
hasActiveSubItem: boolean;
|
|
8
|
+
menuStyle?: MenuStyle;
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MenuStyle } from '@theme/Sidebar/types/MenuStyle';
|
|
2
|
+
|
|
3
|
+
export interface NavItem {
|
|
4
|
+
label?: string;
|
|
5
|
+
sublabel?: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
link?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
httpVerb?: string;
|
|
10
|
+
expanded?: string;
|
|
11
|
+
selectFirstItemOnExpand?: boolean;
|
|
12
|
+
pageId?: string;
|
|
13
|
+
redocPrevLink?: string;
|
|
14
|
+
redocPrevLabel?: string;
|
|
15
|
+
redocNextLink?: string;
|
|
16
|
+
redocNextLabel?: string;
|
|
17
|
+
redocFakePage?: boolean;
|
|
18
|
+
redocInfoPageId?: string;
|
|
19
|
+
target?: string;
|
|
20
|
+
external?: boolean;
|
|
21
|
+
items?: NavItem[];
|
|
22
|
+
permission?: string;
|
|
23
|
+
menuStyle?: MenuStyle;
|
|
24
|
+
separatorLine?: boolean;
|
|
25
|
+
version?: string;
|
|
26
|
+
default?: boolean;
|
|
27
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { highlight } from '
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { highlight } from '@theme/utils';
|
|
4
|
+
import {
|
|
5
|
+
SampleControls,
|
|
6
|
+
SampleControlsWrap,
|
|
7
|
+
PreformattedCodeBlock,
|
|
8
|
+
} from '@theme/SamplesPanelControls';
|
|
9
|
+
import { CopyButtonWrapper } from '@theme/CopyButton';
|
|
6
10
|
|
|
7
11
|
export interface SourceCodeProps {
|
|
8
12
|
lang: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { SourceCode } from '../SourceCode';
|
|
4
3
|
import { renderWithTheme } from '../../../tests/utils';
|
|
5
4
|
|
|
5
|
+
import { SourceCode } from '@theme/SourceCode';
|
|
6
|
+
|
|
6
7
|
describe('SourceCode', () => {
|
|
7
8
|
it('renders without copy button', () => {
|
|
8
9
|
const { container } = renderWithTheme(
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
+
import { ThemeProvider } from 'styled-components';
|
|
4
|
+
|
|
5
|
+
import { TableOfContent } from '@theme/TableOfContent';
|
|
6
|
+
import { generateMediaQueries } from '@theme/utils/media-css';
|
|
7
|
+
|
|
8
|
+
const breakpoints = { small: '1rem', medium: '1rem', large: '1rem' };
|
|
9
|
+
|
|
10
|
+
const theme = {
|
|
11
|
+
mediaQueries: generateMediaQueries(breakpoints),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: 'Portal/TableOfContent',
|
|
16
|
+
component: TableOfContent,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
20
|
+
<Story />
|
|
21
|
+
</ThemeProvider>
|
|
22
|
+
),
|
|
23
|
+
],
|
|
24
|
+
} as ComponentMeta<typeof TableOfContent>;
|
|
25
|
+
|
|
26
|
+
const Template: ComponentStory<typeof TableOfContent> = (args) => (
|
|
27
|
+
<TableOfContent {...args}>Click</TableOfContent>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const Default = Template.bind({});
|
|
31
|
+
Default.args = {
|
|
32
|
+
headings: [
|
|
33
|
+
{ id: '1', value: 'test 1', depth: 1 },
|
|
34
|
+
{ id: '2', value: 'test 2', depth: 1 },
|
|
35
|
+
{ id: '3', value: 'test 3', depth: 2 },
|
|
36
|
+
{ id: '4', value: 'test 4', depth: 2 },
|
|
37
|
+
{ id: '5', value: 'test 5', depth: 1 },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { useFullHeight } from '@theme/hooks/useFullHeight';
|
|
5
|
+
import { useActiveHeading } from '@theme/hooks/useActiveHeading';
|
|
6
|
+
import { MdHeading } from '@theme/types/portal';
|
|
7
|
+
|
|
8
|
+
interface TableOfContentProps {
|
|
9
|
+
headings?: Array<MdHeading | null> | null | undefined;
|
|
10
|
+
contentWrapper: HTMLDivElement | null;
|
|
11
|
+
tocMaxDepth: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function TableOfContent(props: TableOfContentProps): JSX.Element | null {
|
|
15
|
+
const { headings, tocMaxDepth } = props;
|
|
16
|
+
|
|
17
|
+
const sidebar = useRef<HTMLDivElement | null>(null);
|
|
18
|
+
useFullHeight(sidebar);
|
|
19
|
+
const activeHeadingId = useActiveHeading(props.contentWrapper);
|
|
20
|
+
|
|
21
|
+
if (headings && headings.length === 1 && headings[0]?.depth === 1) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (!headings?.length) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
{headings && (
|
|
31
|
+
<TableOfContentMenu data-component-name="TableOfContent/TableOfContent">
|
|
32
|
+
<TableOfContentItems ref={sidebar}>
|
|
33
|
+
<TocHeader>On this page</TocHeader>
|
|
34
|
+
{headings.map((heading: MdHeading | null, idx: number) => {
|
|
35
|
+
// TODO: not sure about !heading
|
|
36
|
+
if (!heading) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (idx === 0 && heading.depth === 1) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (heading.depth && heading.depth > tocMaxDepth) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const href = '#' + heading.id;
|
|
46
|
+
return (
|
|
47
|
+
<MenuItem
|
|
48
|
+
key={href}
|
|
49
|
+
depth={heading.depth || 0}
|
|
50
|
+
href={href}
|
|
51
|
+
className={activeHeadingId === heading.id ? 'active' : ''}
|
|
52
|
+
dangerouslySetInnerHTML={{ __html: heading.value || '' }}
|
|
53
|
+
data-cy={`toc-${heading.value}`}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
57
|
+
</TableOfContentItems>
|
|
58
|
+
</TableOfContentMenu>
|
|
59
|
+
)}
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const TocHeader = styled.div`
|
|
65
|
+
font-size: 0.8em;
|
|
66
|
+
padding: 10px 15px;
|
|
67
|
+
font-weight: bold;
|
|
68
|
+
text-transform: uppercase;
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const MenuItem = styled.a<{ depth: number }>`
|
|
72
|
+
display: block;
|
|
73
|
+
color: var(--color-text-main);
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
font-size: 0.8em;
|
|
76
|
+
padding: 10px 15px;
|
|
77
|
+
padding-left: ${({ depth }) => (depth - 1) * 15}px;
|
|
78
|
+
transition: background-color 0.3s, color 0.3s;
|
|
79
|
+
text-decoration: none;
|
|
80
|
+
word-break: break-word;
|
|
81
|
+
font-family: var(--font-family-h);
|
|
82
|
+
:hover,
|
|
83
|
+
&.active {
|
|
84
|
+
color: var(--sidebar-text-active-color);
|
|
85
|
+
background-color: var(--sidebar-text-active-background-color);
|
|
86
|
+
}
|
|
87
|
+
:empty {
|
|
88
|
+
padding: 0;
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const TableOfContentMenu = styled.aside`
|
|
93
|
+
font-size: 1rem;
|
|
94
|
+
background-color: transparent;
|
|
95
|
+
flex-shrink: 0;
|
|
96
|
+
display: none !important;
|
|
97
|
+
font-family: var(--font-family-primary);
|
|
98
|
+
|
|
99
|
+
${({ theme }) => theme.mediaQueries.medium} {
|
|
100
|
+
width: var(--toc-width);
|
|
101
|
+
display: block !important;
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
const TableOfContentItems = styled.div`
|
|
106
|
+
position: sticky;
|
|
107
|
+
top: calc(var(--navbar-height) + 20px);
|
|
108
|
+
max-height: calc(100vh - var(--navbar-height) - 20px);
|
|
109
|
+
border-left: 1px solid var(--color-border-light);
|
|
110
|
+
overflow-y: auto;
|
|
111
|
+
width: var(--toc-width); ;
|
|
112
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableOfContent';
|
package/src/Tooltip/Tooltip.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { PropsWithChildren } from 'react';
|
|
|
2
2
|
import React, { useCallback, useEffect, memo } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
4
|
|
|
5
|
-
import { useControl } from '
|
|
5
|
+
import { useControl } from '@theme/hooks';
|
|
6
6
|
|
|
7
7
|
export interface TooltipProps {
|
|
8
8
|
tip: string;
|
package/src/globalStyle.ts
CHANGED
|
@@ -129,6 +129,11 @@ export const GlobalStyle = createGlobalStyle`
|
|
|
129
129
|
--sidebar-spacing-horizontal: var(--sidebar-spacing-unit);
|
|
130
130
|
--sidebar-spacing-vertical: var(--sidebar-spacing-unit);
|
|
131
131
|
|
|
132
|
+
--sidebar-margin-left: calc(var(--sidebar-spacing-unit) * 2);
|
|
133
|
+
--sidebar-spacing-offset-top: calc(var(--sidebar-spacing-unit) * 2);
|
|
134
|
+
--sidebar-spacing-offset-left: calc(var(--sidebar-spacing-unit) * 2);
|
|
135
|
+
--sidebar-spacing-offset-nesting: calc(var(--sidebar-spacing-unit) * 2);
|
|
136
|
+
|
|
132
137
|
--sidebar-word-break: 'inherit';
|
|
133
138
|
--sidebar-separator-label-color: var(--sidebar-item-color);
|
|
134
139
|
--sidebar-separator-line-color: #dadada;
|
|
@@ -309,7 +314,7 @@ export const GlobalStyle = createGlobalStyle`
|
|
|
309
314
|
--panels-background-color: #fff;
|
|
310
315
|
|
|
311
316
|
--samples-panel-gap: 20px;
|
|
312
|
-
--samples-panel-width:
|
|
317
|
+
--samples-panel-width: 50%;
|
|
313
318
|
--samples-panel-block-background-color: #fff;
|
|
314
319
|
--samples-panel-background-color: #52606d;
|
|
315
320
|
--samples-panel-callback-background-color: var(--samples-panel-callback-background-color);
|
|
@@ -371,7 +376,9 @@ export const GlobalStyle = createGlobalStyle`
|
|
|
371
376
|
|
|
372
377
|
--field-name-font-size: var(--code-font-size);
|
|
373
378
|
--field-name-font-family: var(--code-font-family);
|
|
374
|
-
--field-
|
|
379
|
+
--field-example-color: var(--color-content);
|
|
380
|
+
--field-example-background-color: var(--inline-code-background-color);
|
|
381
|
+
--field-constraint-color: var(--color-content);
|
|
375
382
|
--field-constraint-background-color: var(--inline-code-background-color);
|
|
376
383
|
|
|
377
384
|
/*
|
|
@@ -413,38 +420,7 @@ export const GlobalStyle = createGlobalStyle`
|
|
|
413
420
|
/* Floating action button */
|
|
414
421
|
--fab-color: #0065FB;
|
|
415
422
|
--fab-background-color: #f2f2f2;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Sidebar
|
|
420
|
-
* */
|
|
421
|
-
--sidebar-spacing-unit: 8px;
|
|
422
|
-
--sidebar-margin-left: calc(var(--sidebar-spacing-unit) * 2);
|
|
423
|
-
--sidebar-padding-horizontal: var(--sidebar-spacing-unit);
|
|
424
|
-
--sidebar-padding-vertical: var(--sidebar-spacing-unit);
|
|
425
|
-
|
|
426
|
-
--sidebar-spacing-padding-vertical: var(--sidebar-spacing-unit);
|
|
427
|
-
--sidebar-spacing-padding-horizontal: var(--sidebar-spacing-unit);
|
|
428
|
-
--sidebar-spacing-offset-top: calc(var(--sidebar-spacing-unit) * 2);
|
|
429
|
-
--sidebar-spacing-offset-left: calc(var(--sidebar-spacing-unit) * 2);
|
|
430
|
-
--sidebar-spacing-offset-nesting: calc(var(--sidebar-spacing-unit) * 2);
|
|
431
|
-
|
|
432
|
-
--sidebar-chevron-size: var(--sidebar-spacing-unit);
|
|
433
|
-
--sidebar-chevron-color: var(--sidebar-text-color);
|
|
434
|
-
|
|
435
|
-
--sidebar-border-radius: 4px;
|
|
436
|
-
--sidebar-background-color: #fff;
|
|
437
|
-
--sidebar-font-size: var(--font-size-base);
|
|
438
|
-
--sidebar-font-family: var(--font-family-primary);
|
|
439
|
-
--sidebar-right-line-color: var(--color-border-light);
|
|
440
|
-
--sidebar-text-color: var(--color-text-main);
|
|
441
|
-
--sidebar-text-active-color: var(--sidebar-text-color);
|
|
442
|
-
--sidebar-text-active-background-color: var(--color-border-light);
|
|
443
|
-
--sidebar-width: 285px;
|
|
444
|
-
|
|
445
|
-
--sidebar-separator-line-color: #dadada;
|
|
446
|
-
--sidebar-separator-label-color: var(--sidebar-text-color);
|
|
447
|
-
|
|
423
|
+
|
|
448
424
|
/**
|
|
449
425
|
* Portal Logo
|
|
450
426
|
* */
|
|
@@ -470,43 +446,4 @@ export const GlobalStyle = createGlobalStyle`
|
|
|
470
446
|
--navbar-item-active-text-color: var(--color-primary-contrast);
|
|
471
447
|
--navbar-item-active-text-decoration: none;
|
|
472
448
|
}
|
|
473
|
-
|
|
474
|
-
@media (prefers-color-scheme: dark) {
|
|
475
|
-
:root {
|
|
476
|
-
--color-content: #f5f7fa;
|
|
477
|
-
--global-border-color: #4c4c4c;
|
|
478
|
-
--inline-code-color: #ed8282;
|
|
479
|
-
--schema-require-label-color: #e55252;
|
|
480
|
-
--global-background-color: #101010;
|
|
481
|
-
--sidebar-background-color: #101010;
|
|
482
|
-
--sidebar-item-active-background-color: #424242;
|
|
483
|
-
--samples-panel-block-background-color: var(--sidebar-background-color);
|
|
484
|
-
--color-secondary-200: #1f2933;
|
|
485
|
-
--color-primary-900: #4892ff;
|
|
486
|
-
--search-marked-background-color: #707000;
|
|
487
|
-
|
|
488
|
-
--response-success-border-color: #3c8d06;
|
|
489
|
-
--response-success-background-color: #2e7102;
|
|
490
|
-
--response-error-border-color: #8d5c5c;
|
|
491
|
-
--response-error-background-color: #802828;
|
|
492
|
-
--response-redirect-border-color: #ffa500;
|
|
493
|
-
--response-redirect-background-color: #ffa5001a;
|
|
494
|
-
--response-info-border-color: #87ceeb;
|
|
495
|
-
--response-info-background-color: #87ceeb1a;
|
|
496
|
-
|
|
497
|
-
--link-color: #4d91ff;
|
|
498
|
-
--link-hover-color: #3686ff;
|
|
499
|
-
|
|
500
|
-
--navbar-color-background: #f2f2f2;
|
|
501
|
-
|
|
502
|
-
.search-input {
|
|
503
|
-
color: var(--color-content);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
.button-clear {
|
|
507
|
-
--color-secondary-600: #3e4c59;
|
|
508
|
-
--color-secondary-400: #1b1b1b;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
449
|
`;
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useState, useMemo, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export type UseActiveHeadingReturnType = string | undefined;
|
|
4
|
+
|
|
5
|
+
export function useActiveHeading(contentElement: Element | null): UseActiveHeadingReturnType {
|
|
6
|
+
const [heading, setHeading] = useState<string | undefined>(undefined);
|
|
7
|
+
|
|
8
|
+
const headings: NodeListOf<HTMLElement> | null = useMemo(
|
|
9
|
+
() => contentElement && contentElement.querySelectorAll<HTMLElement>('.heading-anchor'),
|
|
10
|
+
[contentElement],
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const handler = useCallback(
|
|
14
|
+
// throttle(
|
|
15
|
+
() => {
|
|
16
|
+
if (!headings) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < headings.length; i++) {
|
|
21
|
+
if (headings[i].offsetTop > window.scrollY) {
|
|
22
|
+
const newHeading = i === 0 ? undefined : headings[i - 1].getAttribute('id') || undefined;
|
|
23
|
+
setHeading(newHeading);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
[headings],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (typeof window === 'undefined' || !headings || !headings.length) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
window.addEventListener('scroll', handler, {
|
|
37
|
+
capture: false,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
handler();
|
|
41
|
+
|
|
42
|
+
return () => window.removeEventListener('scroll', handler);
|
|
43
|
+
}, [handler, headings]);
|
|
44
|
+
|
|
45
|
+
return heading;
|
|
46
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useEffect, useState, useMemo } from 'react';
|
|
2
|
+
import throttle from 'lodash.throttle';
|
|
3
|
+
|
|
4
|
+
import { useNavbarHeight } from '@theme/hooks/useNavbarHeight';
|
|
5
|
+
import type { MenuProps } from '@theme/types/portal';
|
|
6
|
+
|
|
7
|
+
export type UseActiveSectionIdReturnType = string;
|
|
8
|
+
|
|
9
|
+
export function useActiveSectionId(
|
|
10
|
+
location: MenuProps['location'],
|
|
11
|
+
hasOverviewPage: boolean,
|
|
12
|
+
): UseActiveSectionIdReturnType {
|
|
13
|
+
const [itemId, setItemId] = useState<string>('');
|
|
14
|
+
const navbarHeight = useNavbarHeight(location);
|
|
15
|
+
const scrollListener = useMemo(
|
|
16
|
+
() =>
|
|
17
|
+
throttle(() => {
|
|
18
|
+
const sections = document.querySelectorAll('[data-section-id]');
|
|
19
|
+
if (sections.length < 2) {
|
|
20
|
+
setItemId('');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < sections.length; i++) {
|
|
24
|
+
const section = sections[i];
|
|
25
|
+
const rect = section.getBoundingClientRect();
|
|
26
|
+
if (rect.y < navbarHeight + 5 && rect.bottom > navbarHeight + 5) {
|
|
27
|
+
// use small padding 5px to account for rounding
|
|
28
|
+
setItemId(section.getAttribute('data-section-id') || '');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (hasOverviewPage) {
|
|
33
|
+
setItemId('');
|
|
34
|
+
} else {
|
|
35
|
+
setItemId((sections[0] && sections[0].getAttribute('data-section-id')) || '');
|
|
36
|
+
}
|
|
37
|
+
}, 150),
|
|
38
|
+
[navbarHeight, hasOverviewPage],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
window.addEventListener('scroll', scrollListener, { capture: false });
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
scrollListener();
|
|
45
|
+
}, 0);
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
window.removeEventListener('scroll', scrollListener); // TODO: add throttle
|
|
49
|
+
};
|
|
50
|
+
}, [location, navbarHeight, scrollListener]);
|
|
51
|
+
|
|
52
|
+
return itemId;
|
|
53
|
+
}
|