@redocly/theme 0.7.5 → 0.8.0

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.
@@ -64,7 +64,7 @@ const MenuWrapper = styled_components_1.default.div `
64
64
  padding-left: var(--sidebar-item-nested-offset);
65
65
  overflow: hidden;
66
66
  ${(props) => props.isExpanded
67
- ? `max-height: 9999px;
67
+ ? `max-height: 99999px;
68
68
  transition: max-height .8s cubic-bezier(0.5, 0, 1, 0) 0s;`
69
69
  : `max-height: 0px;
70
70
  transition: max-height .8s cubic-bezier(0, 1, 0, 1) -.1s;`};
@@ -1,4 +1,5 @@
1
1
  interface SidebarProps {
2
+ isNavbar: boolean;
2
3
  opened?: boolean;
3
4
  animate?: boolean;
4
5
  }
@@ -18,13 +18,16 @@ exports.Sidebar = styled_components_1.default.aside.attrs(() => ({
18
18
  font-size: var(--sidebar-item-font-size);
19
19
  font-family: var(--sidebar-item-font-family);
20
20
  color: var(--sidebar-item-text-color);
21
- top: var(--navbar-height);
22
- height: calc(100vh - var(--navbar-height));
23
21
  display: flex;
24
22
  flex-direction: column;
25
23
  width: 100%;
26
24
  -webkit-font-smoothing: antialiased;
27
25
 
26
+ ${({ isNavbar }) => `
27
+ top: ${isNavbar ? 'var(--navbar-height)' : '0'};
28
+ height: calc(100vh ${isNavbar ? '- var(--navbar-height)' : ''});
29
+ `};
30
+
28
31
  ${({ opened, animate }) => `
29
32
  opacity: ${opened ? '1' : '0'};
30
33
  pointer-events: ${opened ? 'auto' : 'none'};
@@ -6,6 +6,7 @@ interface SidebarLayoutProps {
6
6
  label: string;
7
7
  slug: string;
8
8
  };
9
+ isNavbar: boolean;
9
10
  }
10
- export declare function SidebarLayout({ versions, menu, backLink, }: SidebarLayoutProps): JSX.Element | null;
11
+ export declare function SidebarLayout({ versions, menu, backLink, isNavbar, }: SidebarLayoutProps): JSX.Element | null;
11
12
  export {};
@@ -14,7 +14,7 @@ const SidebarSearch_1 = require("../Search/SidebarSearch");
14
14
  const useThemeConfig_1 = require("../hooks/useThemeConfig");
15
15
  const ArrowBack_1 = require("../Sidebar/ArrowBack");
16
16
  const Link_1 = require("../mocks/Link");
17
- function SidebarLayout({ versions, menu, backLink, }) {
17
+ function SidebarLayout({ versions, menu, backLink, isNavbar, }) {
18
18
  const [isOpen, setIsOpen] = (0, useMobileMenu_1.useMobileMenu)();
19
19
  const toggleMenu = () => setIsOpen(!isOpen);
20
20
  const { search, sidebar } = (0, useThemeConfig_1.useThemeConfig)();
@@ -24,7 +24,7 @@ function SidebarLayout({ versions, menu, backLink, }) {
24
24
  return (react_1.default.createElement(Wrapper, { "data-component-name": "Sidebar/SidebarLayout" },
25
25
  react_1.default.createElement(MobileSidebarButton_1.MobileSidebarButton, { opened: isOpen, onClick: toggleMenu }),
26
26
  !(search === null || search === void 0 ? void 0 : search.hide) && (search === null || search === void 0 ? void 0 : search.placement) === 'sidebar' ? react_1.default.createElement(SidebarSearch_1.SidebarSearch, null) : null,
27
- react_1.default.createElement(Sidebar_1.Sidebar, { animate: true, opened: isOpen },
27
+ react_1.default.createElement(Sidebar_1.Sidebar, { animate: true, opened: isOpen, isNavbar: isNavbar },
28
28
  (backLink && (react_1.default.createElement(BackLinkWrapper, null,
29
29
  react_1.default.createElement(Link_1.Link, { to: backLink.slug },
30
30
  react_1.default.createElement(ArrowBack_1.ArrowBack, null),
@@ -104,6 +104,6 @@ const TableOfContentItems = styled_components_1.default.div `
104
104
  max-height: calc(100vh - var(--navbar-height) - var(--toc-offset-top));
105
105
  border-left: 1px solid var(--toc-border-color);
106
106
  overflow-y: auto;
107
- width: var(--toc-width); ;
107
+ width: var(--toc-width);
108
108
  `;
109
109
  //# sourceMappingURL=TableOfContent.js.map
@@ -202,7 +202,7 @@ const headingsTypography = (0, styled_components_1.css) `
202
202
  --h2-font-weight: var(--heading-font-weight); // @presenter FontWeight
203
203
  --h2-font-size: 28px; // @presenter FontSize
204
204
  --h2-line-height: 28px; // @presenter LineHeight
205
- --h2-margin-top: 0; // @presenter Spacing
205
+ --h2-margin-top: var(--heading-margin-top); // @presenter Spacing
206
206
  --h2-margin-bottom: var(--heading-margin-bottom); // @presenter Spacing
207
207
  --h2-text-color: var(--heading-text-color); // @presenter Color
208
208
 
@@ -7,7 +7,7 @@ function useActiveHeading(contentElement, displayedHeaders) {
7
7
  const [heading, setHeading] = (0, react_1.useState)(displayedHeaders.length > 1 ? displayedHeaders[0] : undefined);
8
8
  const [headingElements, setHeadingElements] = (0, react_1.useState)([]);
9
9
  const headingElementsRef = (0, react_1.useRef)({});
10
- const history = (0, react_router_dom_1.useHistory)();
10
+ const location = (0, react_router_dom_1.useLocation)();
11
11
  const getVisibleHeadings = () => {
12
12
  const visibleHeadings = [];
13
13
  for (const key in headingElementsRef.current) {
@@ -56,12 +56,7 @@ function useActiveHeading(contentElement, displayedHeaders) {
56
56
  return;
57
57
  }
58
58
  setHeadingElements(findHeaders(contentElement));
59
- const unlisten = history.listen(() => {
60
- setHeadingElements(findHeaders(contentElement));
61
- });
62
- return () => unlisten();
63
- // eslint-disable-next-line react-hooks/exhaustive-deps
64
- }, [contentElement]);
59
+ }, [contentElement, location]);
65
60
  (0, react_1.useEffect)(() => {
66
61
  if (!(headingElements === null || headingElements === void 0 ? void 0 : headingElements.length)) {
67
62
  return;
@@ -33,7 +33,7 @@ function useActiveSectionId(location, hasOverviewPage = false) {
33
33
  window.addEventListener('scroll', scrollListener, { capture: false });
34
34
  setTimeout(() => {
35
35
  scrollListener();
36
- }, 0);
36
+ }, 10);
37
37
  return () => {
38
38
  window.removeEventListener('scroll', scrollListener);
39
39
  };
@@ -4,7 +4,7 @@ exports.useMobileMenu = void 0;
4
4
  const react_1 = require("react");
5
5
  const react_router_dom_1 = require("react-router-dom");
6
6
  function useMobileMenu(initialState = false) {
7
- const { location } = (0, react_router_dom_1.useHistory)();
7
+ const location = (0, react_router_dom_1.useLocation)();
8
8
  const [isOpen, setIsOpen] = (0, react_1.useState)(initialState);
9
9
  (0, react_1.useEffect)(() => setIsOpen(false), [location.pathname]);
10
10
  return [isOpen, setIsOpen];
@@ -14,8 +14,8 @@ exports.Jumbotron = (0, styled_components_1.default)(Background_1.Background).at
14
14
  flex-direction: column;
15
15
  padding-top: ${({ pt }) => pt || '0'};
16
16
  padding-bottom: ${({ pb }) => pb || '8em'};
17
- padding-left: ${({ pl }) => pl || '0'};
18
- padding-right: ${({ pr }) => pr || '0'};
17
+ padding-left: ${({ pl }) => pl || '1rem'};
18
+ padding-right: ${({ pr }) => pr || '1rem'};
19
19
  ${({ bgColor }) => bgColor && `background: ${bgColor}`};
20
20
  ${({ bgImage, bgColor }) => bgImage &&
21
21
  `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
4
4
  "description": "Shared UI components lib",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -39,8 +39,7 @@
39
39
  "prismjs": "^1.28.0",
40
40
  "react": "^17.0.2",
41
41
  "react-dom": "^17.0.2",
42
- "react-router": "^5.3.0",
43
- "react-router-dom": "^5.3.0",
42
+ "react-router-dom": "^6.4.4",
44
43
  "styled-components": "^5.3.6",
45
44
  "styled-system": "^5.1.5",
46
45
  "zod": ">=3.19.1"
@@ -71,8 +70,6 @@
71
70
  "@types/prismjs": "^1.26.0",
72
71
  "@types/react": "^17.0.43",
73
72
  "@types/react-dom": "^17.0.14",
74
- "@types/react-router-dom": "^5.3.3",
75
- "@types/react-router": "^5.1.20",
76
73
  "@types/styled-components": "^5.1.26",
77
74
  "@types/styled-system": "^5.1.13",
78
75
  "@typescript-eslint/eslint-plugin": "^5.23.0",
@@ -87,8 +84,7 @@
87
84
  "lodash.throttle": "^4.1.1",
88
85
  "npm-run-all": "^4.1.5",
89
86
  "react-refresh": "^0.14.0",
90
- "react-router": "^5.3.0",
91
- "react-router-dom": "^5.3.0",
87
+ "react-router-dom": "^6.4.4",
92
88
  "storybook-addon-pseudo-states": "^1.15.1",
93
89
  "storybook-design-token": "^2.7.1",
94
90
  "styled-components": "^5.3.6",
@@ -62,7 +62,7 @@ const MenuWrapper = styled.div<{ isExpanded?: boolean }>`
62
62
  overflow: hidden;
63
63
  ${(props) =>
64
64
  props.isExpanded
65
- ? `max-height: 9999px;
65
+ ? `max-height: 99999px;
66
66
  transition: max-height .8s cubic-bezier(0.5, 0, 1, 0) 0s;`
67
67
  : `max-height: 0px;
68
68
  transition: max-height .8s cubic-bezier(0, 1, 0, 1) -.1s;`};
@@ -1,6 +1,7 @@
1
1
  import styled from 'styled-components';
2
2
 
3
3
  interface SidebarProps {
4
+ isNavbar: boolean;
4
5
  opened?: boolean;
5
6
  animate?: boolean;
6
7
  }
@@ -18,13 +19,16 @@ export const Sidebar = styled.aside.attrs(() => ({
18
19
  font-size: var(--sidebar-item-font-size);
19
20
  font-family: var(--sidebar-item-font-family);
20
21
  color: var(--sidebar-item-text-color);
21
- top: var(--navbar-height);
22
- height: calc(100vh - var(--navbar-height));
23
22
  display: flex;
24
23
  flex-direction: column;
25
24
  width: 100%;
26
25
  -webkit-font-smoothing: antialiased;
27
26
 
27
+ ${({ isNavbar }) => `
28
+ top: ${isNavbar ? 'var(--navbar-height)' : '0'};
29
+ height: calc(100vh ${isNavbar ? '- var(--navbar-height)' : ''});
30
+ `};
31
+
28
32
  ${({ opened, animate }) => `
29
33
  opacity: ${opened ? '1' : '0'};
30
34
  pointer-events: ${opened ? 'auto' : 'none'};
@@ -17,12 +17,14 @@ interface SidebarLayoutProps {
17
17
  label: string;
18
18
  slug: string;
19
19
  };
20
+ isNavbar: boolean;
20
21
  }
21
22
 
22
23
  export function SidebarLayout({
23
24
  versions,
24
25
  menu,
25
26
  backLink,
27
+ isNavbar,
26
28
  }: SidebarLayoutProps): JSX.Element | null {
27
29
  const [isOpen, setIsOpen] = useMobileMenu();
28
30
  const toggleMenu = () => setIsOpen(!isOpen);
@@ -37,7 +39,7 @@ export function SidebarLayout({
37
39
  <MobileSidebarButton opened={isOpen} onClick={toggleMenu} />
38
40
 
39
41
  {!search?.hide && search?.placement === 'sidebar' ? <SidebarSearch /> : null}
40
- <Sidebar animate={true} opened={isOpen}>
42
+ <Sidebar animate={true} opened={isOpen} isNavbar={isNavbar}>
41
43
  {(backLink && (
42
44
  <BackLinkWrapper>
43
45
  <Link to={backLink.slug}>
@@ -109,5 +109,5 @@ const TableOfContentItems = styled.div`
109
109
  max-height: calc(100vh - var(--navbar-height) - var(--toc-offset-top));
110
110
  border-left: 1px solid var(--toc-border-color);
111
111
  overflow-y: auto;
112
- width: var(--toc-width); ;
112
+ width: var(--toc-width);
113
113
  `;
@@ -204,7 +204,7 @@ const headingsTypography = css`
204
204
  --h2-font-weight: var(--heading-font-weight); // @presenter FontWeight
205
205
  --h2-font-size: 28px; // @presenter FontSize
206
206
  --h2-line-height: 28px; // @presenter LineHeight
207
- --h2-margin-top: 0; // @presenter Spacing
207
+ --h2-margin-top: var(--heading-margin-top); // @presenter Spacing
208
208
  --h2-margin-bottom: var(--heading-margin-bottom); // @presenter Spacing
209
209
  --h2-text-color: var(--heading-text-color); // @presenter Color
210
210
 
@@ -1,6 +1,5 @@
1
1
  import { useState, useEffect, useRef, useCallback } from 'react';
2
- import { useHistory } from 'react-router-dom';
3
-
2
+ import { useLocation } from 'react-router-dom';
4
3
  export type UseActiveHeadingReturnType = string | undefined;
5
4
 
6
5
  type HeadingEntry = {
@@ -16,8 +15,7 @@ export function useActiveHeading(
16
15
  );
17
16
  const [headingElements, setHeadingElements] = useState<HTMLElement[]>([]);
18
17
  const headingElementsRef = useRef<HeadingEntry>({});
19
-
20
- const history = useHistory();
18
+ const location = useLocation();
21
19
 
22
20
  const getVisibleHeadings = () => {
23
21
  const visibleHeadings: IntersectionObserverEntry[] = [];
@@ -86,14 +84,7 @@ export function useActiveHeading(
86
84
  return;
87
85
  }
88
86
  setHeadingElements(findHeaders(contentElement));
89
-
90
- const unlisten = history.listen(() => {
91
- setHeadingElements(findHeaders(contentElement));
92
- });
93
-
94
- return () => unlisten();
95
- // eslint-disable-next-line react-hooks/exhaustive-deps
96
- }, [contentElement]);
87
+ }, [contentElement, location]);
97
88
 
98
89
  useEffect(() => {
99
90
  if (!headingElements?.length) {
@@ -41,7 +41,7 @@ export function useActiveSectionId(
41
41
  window.addEventListener('scroll', scrollListener, { capture: false });
42
42
  setTimeout(() => {
43
43
  scrollListener();
44
- }, 0);
44
+ }, 10);
45
45
 
46
46
  return () => {
47
47
  window.removeEventListener('scroll', scrollListener);
@@ -1,10 +1,10 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { useHistory } from 'react-router-dom';
2
+ import { useLocation } from 'react-router-dom';
3
3
 
4
4
  import type { Dispatch, SetStateAction } from 'react';
5
5
 
6
6
  export function useMobileMenu(initialState = false): [boolean, Dispatch<SetStateAction<boolean>>] {
7
- const { location } = useHistory();
7
+ const location = useLocation();
8
8
  const [isOpen, setIsOpen] = useState(initialState);
9
9
 
10
10
  useEffect(() => setIsOpen(false), [location.pathname]);
@@ -19,8 +19,8 @@ export const Jumbotron = styled(Background).attrs(() => ({
19
19
  flex-direction: column;
20
20
  padding-top: ${({ pt }) => pt || '0'};
21
21
  padding-bottom: ${({ pb }) => pb || '8em'};
22
- padding-left: ${({ pl }) => pl || '0'};
23
- padding-right: ${({ pr }) => pr || '0'};
22
+ padding-left: ${({ pl }) => pl || '1rem'};
23
+ padding-right: ${({ pr }) => pr || '1rem'};
24
24
  ${({ bgColor }) => bgColor && `background: ${bgColor}`};
25
25
  ${({ bgImage, bgColor }) =>
26
26
  bgImage &&