@redocly/theme 0.1.31 → 0.2.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.
Files changed (43) hide show
  1. package/Navbar/Navbar.d.ts +2 -1
  2. package/Navbar/Navbar.js +3 -2
  3. package/Profile/Profile.js +3 -4
  4. package/Search/Autocomplete.d.ts +1 -1
  5. package/Search/Parameters.d.ts +1 -1
  6. package/Search/SearchItem.d.ts +1 -1
  7. package/TableOfContent/TableOfContent.js +1 -1
  8. package/Tooltip/Tooltip.d.ts +2 -2
  9. package/Tooltip/Tooltip.js +4 -2
  10. package/hooks/index.d.ts +1 -0
  11. package/hooks/index.js +1 -0
  12. package/hooks/useOutsideClick.d.ts +2 -0
  13. package/hooks/useOutsideClick.js +21 -0
  14. package/mocks/{models.d.ts → types.d.ts} +0 -0
  15. package/mocks/{models.js → types.js} +0 -0
  16. package/package.json +1 -1
  17. package/src/Footer/CustomFooterNavItem.tsx +2 -1
  18. package/src/Footer/Footer.tsx +2 -1
  19. package/src/Footer/FooterColumn.tsx +2 -1
  20. package/src/Footer/FooterColumns.tsx +2 -1
  21. package/src/Navbar/MobileNavbarDropdown.tsx +1 -0
  22. package/src/Navbar/MobileNavbarItem.tsx +1 -0
  23. package/src/Navbar/MobileNavbarMenu.tsx +2 -1
  24. package/src/Navbar/Navbar.tsx +3 -1
  25. package/src/Navbar/NavbarDropdown.tsx +1 -0
  26. package/src/Navbar/NavbarItem.tsx +1 -0
  27. package/src/Navbar/NavbarMenu.tsx +2 -1
  28. package/src/PageNavigation/NextPageLink.tsx +1 -0
  29. package/src/PageNavigation/PreviousPageLink.tsx +1 -0
  30. package/src/Profile/Profile.tsx +4 -5
  31. package/src/Search/Autocomplete.tsx +2 -1
  32. package/src/Search/Parameters.tsx +2 -1
  33. package/src/Search/SearchItem.tsx +2 -1
  34. package/src/TableOfContent/TableOfContent.tsx +1 -1
  35. package/src/Tooltip/Tooltip.tsx +7 -4
  36. package/src/hooks/index.ts +1 -0
  37. package/src/hooks/useActiveSectionId.ts +1 -1
  38. package/src/hooks/useOutsideClick.ts +21 -0
  39. package/src/mocks/{models.ts → types.ts} +0 -0
  40. package/src/utils/color.ts +9 -6
  41. package/src/utils/theme-helpers.ts +1 -1
  42. package/utils/color.d.ts +1 -2
  43. package/utils/color.js +11 -9
@@ -4,7 +4,8 @@ interface NavbarProps {
4
4
  menu: ResolvedConfigLinks;
5
5
  logo: React.ReactNode;
6
6
  search: React.ReactNode;
7
+ profile?: React.ReactNode;
7
8
  }
8
- export declare function Navbar({ menu, logo, search }: NavbarProps): JSX.Element | null;
9
+ export declare function Navbar({ menu, logo, search, profile }: NavbarProps): JSX.Element | null;
9
10
  export declare const NavbarContainer: import("styled-components").StyledComponent<"nav", any, {}, never>;
10
11
  export {};
package/Navbar/Navbar.js CHANGED
@@ -33,7 +33,7 @@ var useMobileMenu_1 = require("../hooks/useMobileMenu");
33
33
  var MobileNavbarMenuButton_1 = require("../Navbar/MobileNavbarMenuButton");
34
34
  var MobileNavbarMenu_1 = require("../Navbar/MobileNavbarMenu");
35
35
  function Navbar(_a) {
36
- var menu = _a.menu, logo = _a.logo, search = _a.search;
36
+ var menu = _a.menu, logo = _a.logo, search = _a.search, profile = _a.profile;
37
37
  var _b = __read((0, useMobileMenu_1.useMobileMenu)(false), 2), isOpen = _b[0], setIsOpen = _b[1];
38
38
  var _c = (0, hooks_1.useThemeSettings)(constants_1.DEFAULT_THEME_NAME), searchSettings = _c.search, navbar = _c.navbar;
39
39
  var hideSearch = (searchSettings === null || searchSettings === void 0 ? void 0 : searchSettings.hide) || ((searchSettings === null || searchSettings === void 0 ? void 0 : searchSettings.placement) && (searchSettings === null || searchSettings === void 0 ? void 0 : searchSettings.placement) !== 'navbar');
@@ -47,7 +47,8 @@ function Navbar(_a) {
47
47
  isOpen && react_1.default.createElement(MobileNavbarMenu_1.MobileNavbarMenu, { closeMenu: closeMobileMenu, menuItems: menu }),
48
48
  logo,
49
49
  react_1.default.createElement(Navbar_1.NavbarMenu, { menuItems: menu }),
50
- hideSearch ? null : search));
50
+ hideSearch ? null : search,
51
+ profile));
51
52
  }
52
53
  exports.Navbar = Navbar;
53
54
  exports.NavbarContainer = styled_components_1.default.nav(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: var(--navbar-height);\n box-sizing: border-box;\n display: flex;\n color: var(--navbar-text-color);\n align-items: center;\n justify-content: space-between;\n flex-shrink: 0;\n\n font-size: 0.875rem;\n position: sticky;\n top: 0;\n z-index: 200;\n padding: 10px var(--sidebar-margin-left);\n background: var(--navbar-background-color);\n font-family: var(--h-font-family);\n\n ", " {\n padding: 10px var(--sidebar-margin-left);\n font-size: 1rem;\n }\n\n ", " {\n background: transparent;\n display: none;\n > :not(a, img) {\n display: none !important;\n }\n img {\n padding: 0;\n margin: 0;\n }\n }\n"], ["\n height: var(--navbar-height);\n box-sizing: border-box;\n display: flex;\n color: var(--navbar-text-color);\n align-items: center;\n justify-content: space-between;\n flex-shrink: 0;\n\n font-size: 0.875rem;\n position: sticky;\n top: 0;\n z-index: 200;\n padding: 10px var(--sidebar-margin-left);\n background: var(--navbar-background-color);\n font-family: var(--h-font-family);\n\n ", " {\n padding: 10px var(--sidebar-margin-left);\n font-size: 1rem;\n }\n\n ", " {\n background: transparent;\n display: none;\n > :not(a, img) {\n display: none !important;\n }\n img {\n padding: 0;\n margin: 0;\n }\n }\n"])), function (_a) {
@@ -31,7 +31,6 @@ exports.Profile = void 0;
31
31
  var react_1 = __importStar(require("react"));
32
32
  var styled_components_1 = __importStar(require("styled-components"));
33
33
  var utils_1 = require("../utils");
34
- var RANDOM_BG_COLOR = (0, utils_1.getRandomColor)();
35
34
  function ProfileComponent(_a) {
36
35
  var _b;
37
36
  var name = _a.name, imageUrl = _a.imageUrl, onClick = _a.onClick, color = _a.color;
@@ -44,14 +43,14 @@ function ProfileComponent(_a) {
44
43
  var avatarLetters = "".concat(name.charAt(0).toUpperCase()).concat(((_b = name.split(' ')[1]) === null || _b === void 0 ? void 0 : _b.charAt(0).toUpperCase()) || '');
45
44
  return (react_1.default.createElement(ProfileWrapper, { onClick: onClick },
46
45
  react_1.default.createElement(StyledUserName, { "data-cy": "user-name", color: color }, name),
47
- react_1.default.createElement(AvatarWrapper, { background: RANDOM_BG_COLOR },
46
+ react_1.default.createElement(AvatarWrapper, { background: (0, utils_1.stringToHslColor)(name) },
48
47
  react_1.default.createElement("span", null, avatarLetters))));
49
48
  }
50
49
  exports.Profile = (0, react_1.memo)(ProfileComponent);
51
- var ProfileWrapper = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n cursor: pointer;\n width: auto;\n"], ["\n display: flex;\n align-items: center;\n cursor: pointer;\n width: auto;\n"])));
50
+ var ProfileWrapper = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n cursor: pointer;\n width: auto;\n padding-left: calc(var(--sidebar-spacing-horizontal) * 2);\n"], ["\n display: flex;\n align-items: center;\n cursor: pointer;\n width: auto;\n padding-left: calc(var(--sidebar-spacing-horizontal) * 2);\n"])));
52
51
  var StyledUserName = styled_components_1.default.span(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n color: ", ";\n"], ["\n color: ", ";\n"])), function (_a) {
53
52
  var color = _a.color;
54
- return color || 'var(--color-content)';
53
+ return color || 'var(--navbar-text-color)';
55
54
  });
56
55
  var AvatarWrapper = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n width: 40px;\n height: 40px;\n display: flex;\n overflow: hidden;\n position: relative;\n font-size: 1.25rem;\n align-items: center;\n flex-shrink: 0;\n line-height: 1;\n user-select: none;\n border-radius: 50%;\n justify-content: center;\n margin-left: 16px;\n\n ", "\n\n & > img {\n color: transparent;\n width: 100%;\n height: 100%;\n object-fit: cover;\n text-align: center;\n text-indent: 10000px;\n }\n"], ["\n width: 40px;\n height: 40px;\n display: flex;\n overflow: hidden;\n position: relative;\n font-size: 1.25rem;\n align-items: center;\n flex-shrink: 0;\n line-height: 1;\n user-select: none;\n border-radius: 50%;\n justify-content: center;\n margin-left: 16px;\n\n ", "\n\n & > img {\n color: transparent;\n width: 100%;\n height: 100%;\n object-fit: cover;\n text-align: center;\n text-indent: 10000px;\n }\n"])), function (_a) {
57
56
  var background = _a.background;
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { ActiveItem } from '../mocks/models';
2
+ import type { ActiveItem } from '../mocks/types';
3
3
  interface AutocompleteProps<T> {
4
4
  placeholder?: string;
5
5
  value: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { OperationParameter } from '../mocks/models';
2
+ import type { OperationParameter } from '../mocks/types';
3
3
  interface ParametersProps {
4
4
  parameters: OperationParameter[];
5
5
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { ActiveItem, SearchDocument } from '../mocks/models';
2
+ import type { ActiveItem, SearchDocument } from '../mocks/types';
3
3
  interface SearchItemProps {
4
4
  item: ActiveItem<SearchDocument>;
5
5
  }
@@ -76,7 +76,7 @@ function TableOfContent(props) {
76
76
  return null;
77
77
  }
78
78
  var href = '#' + heading.id;
79
- return (react_1.default.createElement(MenuItem, { key: href, href: href, depth: heading.depth || 0, className: activeHeadingId === heading.id ? 'active' : '', dangerouslySetInnerHTML: { __html: heading.value || '' }, "data-cy": "toc-".concat(heading.value) }));
79
+ return (react_1.default.createElement(MenuItem, { key: href + idx, href: href, depth: heading.depth || 0, className: activeHeadingId === heading.id ? 'active' : '', dangerouslySetInnerHTML: { __html: heading.value || '' }, "data-cy": "toc-".concat(heading.value) }));
80
80
  }))))));
81
81
  }
82
82
  exports.TableOfContent = TableOfContent;
@@ -1,5 +1,5 @@
1
- import type { PropsWithChildren, ReactNode } from 'react';
2
1
  import React from 'react';
2
+ import type { PropsWithChildren, ReactNode } from 'react';
3
3
  export interface TooltipProps {
4
4
  tip: string | ReactNode;
5
5
  isOpen?: boolean;
@@ -10,4 +10,4 @@ export interface TooltipProps {
10
10
  dataTestId?: string;
11
11
  }
12
12
  export declare function TooltipComponent({ children, isOpen, tip, withArrow, placement, className, width, dataTestId, }: PropsWithChildren<TooltipProps>): JSX.Element;
13
- export declare const Tooltip: React.NamedExoticComponent<PropsWithChildren<TooltipProps>>;
13
+ export declare const Tooltip: React.NamedExoticComponent<React.PropsWithChildren<TooltipProps>>;
@@ -44,7 +44,9 @@ var styled_components_1 = __importStar(require("styled-components"));
44
44
  var hooks_1 = require("../hooks");
45
45
  function TooltipComponent(_a) {
46
46
  var children = _a.children, isOpen = _a.isOpen, tip = _a.tip, _b = _a.withArrow, withArrow = _b === void 0 ? true : _b, _c = _a.placement, placement = _c === void 0 ? 'top' : _c, _d = _a.className, className = _d === void 0 ? 'default' : _d, width = _a.width, dataTestId = _a.dataTestId;
47
+ var ref = (0, react_1.useRef)(null);
47
48
  var _e = (0, hooks_1.useControl)(isOpen), isOpened = _e.isOpened, handleOpen = _e.handleOpen, handleClose = _e.handleClose;
49
+ (0, hooks_1.useOutsideClick)(ref, handleClose);
48
50
  var isControlled = isOpen !== undefined;
49
51
  (0, react_1.useEffect)(function () {
50
52
  if (isControlled) {
@@ -61,7 +63,7 @@ function TooltipComponent(_a) {
61
63
  onMouseLeave: handleClose,
62
64
  onClick: handleClose,
63
65
  };
64
- return (react_1.default.createElement(TooltipWrapper, __assign({}, controllers, { className: "tooltip-".concat(className), "data-component-name": "Tooltip/Tooltip" }),
66
+ return (react_1.default.createElement(TooltipWrapper, __assign({ ref: ref }, controllers, { className: "tooltip-".concat(className), "data-component-name": "Tooltip/Tooltip" }),
65
67
  children,
66
68
  isOpened && (react_1.default.createElement(TooltipBody, { "data-cy": dataTestId || (typeof tip === 'string' ? tip : ''), placement: placement, width: width, withArrow: withArrow }, tip))));
67
69
  }
@@ -86,7 +88,7 @@ var PLACEMENTS = {
86
88
  }),
87
89
  };
88
90
  var TooltipWrapper = styled_components_1.default.div(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n position: relative;\n display: inline-block;\n"], ["\n position: relative;\n display: inline-block;\n"])));
89
- var TooltipBody = styled_components_1.default.span(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n display: inline-block;\n\n position: absolute;\n text-align: center;\n\n padding: 10px 20px;\n max-width: 250px;\n white-space: normal;\n overflow-wrap: break-word;\n\n border-radius: var(--global-border-radius);\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n\n font-size: 13px;\n\n &::after {\n position: absolute;\n\n content: ' ';\n display: inline-block;\n width: 0;\n height: 0;\n border-color: var(--tooltip-background-color);\n }\n\n background: var(--tooltip-background-color);\n color: var(--tooltip-color);\n box-shadow: rgb(0 0 0 / 25%) 0 2px 4px;\n\n width: ", ";\n ", "\n"], ["\n display: inline-block;\n\n position: absolute;\n text-align: center;\n\n padding: 10px 20px;\n max-width: 250px;\n white-space: normal;\n overflow-wrap: break-word;\n\n border-radius: var(--global-border-radius);\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n\n font-size: 13px;\n\n &::after {\n position: absolute;\n\n content: ' ';\n display: inline-block;\n width: 0;\n height: 0;\n border-color: var(--tooltip-background-color);\n }\n\n background: var(--tooltip-background-color);\n color: var(--tooltip-color);\n box-shadow: rgb(0 0 0 / 25%) 0 2px 4px;\n\n width: ", ";\n ", "\n"])), function (_a) {
91
+ var TooltipBody = styled_components_1.default.span(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n display: inline-block;\n\n position: absolute;\n text-align: center;\n\n padding: 10px 20px;\n max-width: 250px;\n white-space: normal;\n overflow-wrap: break-word;\n\n border-radius: var(--global-border-radius);\n transition: opacity 0.3s ease-out;\n\n font-size: 13px;\n\n &::after {\n position: absolute;\n\n content: ' ';\n display: inline-block;\n width: 0;\n height: 0;\n border-color: var(--tooltip-background-color);\n }\n\n background: var(--tooltip-background-color);\n color: var(--tooltip-color);\n box-shadow: rgb(0 0 0 / 25%) 0 2px 4px;\n\n width: ", ";\n ", "\n"], ["\n display: inline-block;\n\n position: absolute;\n text-align: center;\n\n padding: 10px 20px;\n max-width: 250px;\n white-space: normal;\n overflow-wrap: break-word;\n\n border-radius: var(--global-border-radius);\n transition: opacity 0.3s ease-out;\n\n font-size: 13px;\n\n &::after {\n position: absolute;\n\n content: ' ';\n display: inline-block;\n width: 0;\n height: 0;\n border-color: var(--tooltip-background-color);\n }\n\n background: var(--tooltip-background-color);\n color: var(--tooltip-color);\n box-shadow: rgb(0 0 0 / 25%) 0 2px 4px;\n\n width: ", ";\n ", "\n"])), function (_a) {
90
92
  var width = _a.width;
91
93
  return width || '120px';
92
94
  }, function (_a) {
package/hooks/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from '../hooks/useActiveHeading';
5
5
  export * from '../hooks/useActiveSectionId';
6
6
  export * from '../hooks/useFullHeight';
7
7
  export * from '../hooks/useNavbarHeight';
8
+ export * from '../hooks/useOutsideClick';
package/hooks/index.js CHANGED
@@ -21,3 +21,4 @@ __exportStar(require("../hooks/useActiveHeading"), exports);
21
21
  __exportStar(require("../hooks/useActiveSectionId"), exports);
22
22
  __exportStar(require("../hooks/useFullHeight"), exports);
23
23
  __exportStar(require("../hooks/useNavbarHeight"), exports);
24
+ __exportStar(require("../hooks/useOutsideClick"), exports);
@@ -0,0 +1,2 @@
1
+ import { MutableRefObject } from 'react';
2
+ export declare function useOutsideClick(ref: MutableRefObject<HTMLElement | null>, handler: (event: MouseEvent | TouchEvent) => void): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useOutsideClick = void 0;
4
+ var react_1 = require("react");
5
+ function useOutsideClick(ref, handler) {
6
+ (0, react_1.useEffect)(function () {
7
+ var listener = function (event) {
8
+ if (!ref.current || ref.current.contains(event.target)) {
9
+ return;
10
+ }
11
+ handler(event);
12
+ };
13
+ document.addEventListener('mousedown', listener);
14
+ document.addEventListener('touchstart', listener);
15
+ return function () {
16
+ document.removeEventListener('mousedown', listener);
17
+ document.removeEventListener('touchstart', listener);
18
+ };
19
+ }, [ref, handler]);
20
+ }
21
+ exports.useOutsideClick = useOutsideClick;
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.1.31",
3
+ "version": "0.2.0",
4
4
  "description": "Shared UI components",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
- import { Link } from '@portal/Link';
5
4
  import type { ResolvedNavItem, ResolvedNavLinkItem } from '@theme/types/portal';
6
5
 
6
+ import { Link } from '@portal/Link';
7
+
7
8
  interface CustomFooterNavItemProps {
8
9
  navItem: ResolvedNavItem;
9
10
  }
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
+ import type { NavGroupRecord, ResolvedNavItem } from '@theme/types/portal';
5
+
4
6
  import { FooterColumns } from '@theme/Footer/FooterColumns';
5
7
  import { FooterCopyright } from '@theme/Footer/FooterCopyright';
6
- import type { NavGroupRecord, ResolvedNavItem } from '@theme/types/portal';
7
8
  import { useThemeSettings } from '@portal/hooks';
8
9
  import { DEFAULT_THEME_NAME } from '@portal/constants';
9
10
  import { isEmptyArray } from '@theme/utils';
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
- import { Link } from '@portal/Link';
5
4
  import type { ResolvedNavItem } from '@theme/types/portal';
6
5
 
6
+ import { Link } from '@portal/Link';
7
+
7
8
  interface FooterColumnProps {
8
9
  column: ResolvedNavItem;
9
10
  }
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
- import { FooterColumn } from '@theme/Footer/FooterColumn';
5
4
  import type { ResolvedNavItem } from '@theme/types/portal';
6
5
 
6
+ import { FooterColumn } from '@theme/Footer/FooterColumn';
7
+
7
8
  interface FooterColumnsProps {
8
9
  columns: ResolvedNavItem[];
9
10
  }
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  import type { ResolvedNavLinkItem } from '@theme/types/portal';
5
+
5
6
  import { Link } from '@portal/Link';
6
7
 
7
8
  interface NavbarDropdownProps {
@@ -7,6 +7,7 @@ import type {
7
7
  ResolvedNavLinkItem,
8
8
  ResolvedNavGroupItem,
9
9
  } from '@theme/types/portal';
10
+
10
11
  import { Link } from '@portal/Link';
11
12
  import { withPathPrefix } from '@portal/utils';
12
13
  import { MobileDropdownWrapper, MobileNavbarDropdown } from '@theme/Navbar/MobileNavbarDropdown';
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
+ import type { ResolvedConfigLinks, ResolvedNavItem } from '@theme/types/portal';
5
+
4
6
  import { NavMenuItem, NavMenuItemWithDropdownWrapper } from '@theme/Navbar/NavbarItem';
5
7
  import { MobileNavbarItem } from '@theme/Navbar/MobileNavbarItem';
6
8
  import { DropdownWrapper } from '@theme/Navbar/NavbarDropdown';
7
- import type { ResolvedConfigLinks, ResolvedNavItem } from '@theme/types/portal';
8
9
  import { isPrimitive, isEmptyArray } from '@theme/utils';
9
10
 
10
11
  export function MobileNavbarMenu({
@@ -13,9 +13,10 @@ interface NavbarProps {
13
13
  menu: ResolvedConfigLinks;
14
14
  logo: React.ReactNode;
15
15
  search: React.ReactNode;
16
+ profile?: React.ReactNode;
16
17
  }
17
18
 
18
- export function Navbar({ menu, logo, search }: NavbarProps): JSX.Element | null {
19
+ export function Navbar({ menu, logo, search, profile }: NavbarProps): JSX.Element | null {
19
20
  const [isOpen, setIsOpen] = useMobileMenu(false);
20
21
  const { search: searchSettings, navbar } = useThemeSettings(DEFAULT_THEME_NAME);
21
22
  const hideSearch =
@@ -35,6 +36,7 @@ export function Navbar({ menu, logo, search }: NavbarProps): JSX.Element | null
35
36
  {logo}
36
37
  <NavbarMenu menuItems={menu} />
37
38
  {hideSearch ? null : search}
39
+ {profile}
38
40
  </NavbarContainer>
39
41
  );
40
42
  }
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  import type { ResolvedNavLinkItem } from '@theme/types/portal';
5
+
5
6
  import { Link } from '@portal/Link';
6
7
 
7
8
  interface NavbarDropdownProps {
@@ -7,6 +7,7 @@ import type {
7
7
  ResolvedNavLinkItem,
8
8
  ResolvedNavGroupItem,
9
9
  } from '@theme/types/portal';
10
+
10
11
  import { Link } from '@portal/Link';
11
12
  import { withPathPrefix } from '@portal/utils';
12
13
  import { NavbarDropdown, DropdownWrapper } from '@theme/Navbar/NavbarDropdown';
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
- import { NavbarItem } from '@theme/Navbar/NavbarItem';
5
4
  import type { ResolvedConfigLinks, ResolvedNavItem } from '@theme/types/portal';
5
+
6
+ import { NavbarItem } from '@theme/Navbar/NavbarItem';
6
7
  import { isPrimitive, isEmptyArray } from '@theme/utils';
7
8
 
8
9
  export function NavbarMenu({ menuItems }: { menuItems: ResolvedConfigLinks }): JSX.Element | null {
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  import type { ResolvedNavItemWithLink } from '@theme/types/portal';
5
+
5
6
  import { useThemeSettings, useSidebarSiblingsData } from '@portal/hooks';
6
7
  import { DEFAULT_THEME_NAME } from '@portal/constants';
7
8
  import { Button } from '@theme/Button/Button';
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  import type { ResolvedNavItemWithLink } from '@theme/types/portal';
5
+
5
6
  import { useThemeSettings, useSidebarSiblingsData } from '@portal/hooks';
6
7
  import { DEFAULT_THEME_NAME } from '@portal/constants';
7
8
  import { Button } from '@theme/Button/Button';
@@ -1,7 +1,7 @@
1
1
  import React, { memo } from 'react';
2
2
  import styled, { css } from 'styled-components';
3
3
 
4
- import { getRandomColor } from '@theme/utils';
4
+ import { stringToHslColor } from '@theme/utils';
5
5
 
6
6
  export interface ProfileProps {
7
7
  name: string;
@@ -10,8 +10,6 @@ export interface ProfileProps {
10
10
  onClick?: () => void;
11
11
  }
12
12
 
13
- const RANDOM_BG_COLOR: string = getRandomColor();
14
-
15
13
  function ProfileComponent({ name, imageUrl, onClick, color }: ProfileProps): JSX.Element {
16
14
  if (imageUrl) {
17
15
  return (
@@ -37,7 +35,7 @@ function ProfileComponent({ name, imageUrl, onClick, color }: ProfileProps): JSX
37
35
  <StyledUserName data-cy="user-name" color={color}>
38
36
  {name}
39
37
  </StyledUserName>
40
- <AvatarWrapper background={RANDOM_BG_COLOR}>
38
+ <AvatarWrapper background={stringToHslColor(name)}>
41
39
  <span>{avatarLetters}</span>
42
40
  </AvatarWrapper>
43
41
  </ProfileWrapper>
@@ -51,10 +49,11 @@ const ProfileWrapper = styled.div`
51
49
  align-items: center;
52
50
  cursor: pointer;
53
51
  width: auto;
52
+ padding-left: calc(var(--sidebar-spacing-horizontal) * 2);
54
53
  `;
55
54
 
56
55
  const StyledUserName = styled.span`
57
- color: ${({ color }) => color || 'var(--color-content)'};
56
+ color: ${({ color }) => color || 'var(--navbar-text-color)'};
58
57
  `;
59
58
 
60
59
  const AvatarWrapper = styled.div<{ background?: string }>`
@@ -9,9 +9,10 @@ import React, {
9
9
  import { useLocation } from 'react-router-dom';
10
10
  import styled from 'styled-components';
11
11
 
12
+ import type { ActiveItem } from '@portal/types';
13
+
12
14
  import { FormInput } from '@theme/Search/Input';
13
15
  import { Popover } from '@theme/Search/Popover';
14
- import { ActiveItem } from '@shared/models';
15
16
 
16
17
  interface AutocompleteProps<T> {
17
18
  placeholder?: string;
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
- import { OperationParameter } from '@shared/models';
4
+ import type { OperationParameter } from '@portal/types';
5
+
5
6
  import { highlight } from '@theme/Search/utils';
6
7
 
7
8
  interface ParametersProps {
@@ -1,9 +1,10 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
+ import type { ActiveItem, SearchDocument } from '@portal/types';
5
+
4
6
  import { OperationBadge } from '@theme/OperationBadge';
5
7
  import { Link } from '@portal/Link';
6
- import { ActiveItem, SearchDocument } from '@shared/models';
7
8
  import { Parameters } from '@theme/Search/Parameters';
8
9
  import { highlight } from '@theme/Search/utils';
9
10
 
@@ -61,7 +61,7 @@ export function TableOfContent(props: TableOfContentProps): JSX.Element | null {
61
61
  const href = '#' + heading.id;
62
62
  return (
63
63
  <MenuItem
64
- key={href}
64
+ key={href + idx}
65
65
  href={href}
66
66
  depth={heading.depth || 0}
67
67
  className={activeHeadingId === heading.id ? 'active' : ''}
@@ -1,8 +1,8 @@
1
- import type { PropsWithChildren, ReactNode } from 'react';
2
- import React, { useEffect, memo } from 'react';
1
+ import React, { useEffect, memo, useRef } from 'react';
3
2
  import styled, { css } from 'styled-components';
3
+ import type { PropsWithChildren, ReactNode } from 'react';
4
4
 
5
- import { useControl } from '@theme/hooks';
5
+ import { useControl, useOutsideClick } from '@theme/hooks';
6
6
 
7
7
  export interface TooltipProps {
8
8
  tip: string | ReactNode;
@@ -24,8 +24,11 @@ export function TooltipComponent({
24
24
  width,
25
25
  dataTestId,
26
26
  }: PropsWithChildren<TooltipProps>): JSX.Element {
27
+ const ref = useRef<HTMLDivElement | null>(null);
27
28
  const { isOpened, handleOpen, handleClose } = useControl(isOpen);
28
29
 
30
+ useOutsideClick(ref, handleClose);
31
+
29
32
  const isControlled = isOpen !== undefined;
30
33
 
31
34
  useEffect(() => {
@@ -46,6 +49,7 @@ export function TooltipComponent({
46
49
 
47
50
  return (
48
51
  <TooltipWrapper
52
+ ref={ref}
49
53
  {...controllers}
50
54
  className={`tooltip-${className}`}
51
55
  data-component-name="Tooltip/Tooltip"
@@ -169,7 +173,6 @@ const TooltipBody = styled.span<
169
173
  overflow-wrap: break-word;
170
174
 
171
175
  border-radius: var(--global-border-radius);
172
- pointer-events: none;
173
176
  transition: opacity 0.3s ease-out;
174
177
 
175
178
  font-size: 13px;
@@ -5,3 +5,4 @@ export * from '@theme/hooks/useActiveHeading';
5
5
  export * from '@theme/hooks/useActiveSectionId';
6
6
  export * from '@theme/hooks/useFullHeight';
7
7
  export * from '@theme/hooks/useNavbarHeight';
8
+ export * from '@theme/hooks/useOutsideClick';
@@ -1,6 +1,6 @@
1
- import type { Location } from 'history';
2
1
  import { useEffect, useState, useMemo } from 'react';
3
2
  import throttle from 'lodash.throttle';
3
+ import type { Location } from 'history';
4
4
 
5
5
  import { useNavbarHeight } from '@theme/hooks/useNavbarHeight';
6
6
 
@@ -0,0 +1,21 @@
1
+ import { MutableRefObject, useEffect } from 'react';
2
+
3
+ export function useOutsideClick(
4
+ ref: MutableRefObject<HTMLElement | null>,
5
+ handler: (event: MouseEvent | TouchEvent) => void,
6
+ ): void {
7
+ useEffect(() => {
8
+ const listener = (event: MouseEvent | TouchEvent) => {
9
+ if (!ref.current || ref.current.contains(event.target as Node)) {
10
+ return;
11
+ }
12
+ handler(event);
13
+ };
14
+ document.addEventListener('mousedown', listener);
15
+ document.addEventListener('touchstart', listener);
16
+ return () => {
17
+ document.removeEventListener('mousedown', listener);
18
+ document.removeEventListener('touchstart', listener);
19
+ };
20
+ }, [ref, handler]);
21
+ }
File without changes
@@ -1,9 +1,12 @@
1
- export const getRandomNumber = (limit: number): number => Math.floor(Math.random() * limit);
1
+ export function stringToHslColor(value: string): string {
2
+ const s = 30;
3
+ const l = 80;
4
+ let hash = 0;
2
5
 
3
- export function getRandomColor(): string {
4
- const h = getRandomNumber(360);
5
- const s = getRandomNumber(100);
6
- const l = getRandomNumber(100);
6
+ for (let i = 0; i < value.length; i++) {
7
+ hash = value.charCodeAt(i) + ((hash << 5) - hash);
8
+ }
7
9
 
8
- return `hsl(${h}deg, ${s}%, ${l}%)`;
10
+ const h = hash % 360;
11
+ return `hsl(${h}, ${s}%, ${l}%)`;
9
12
  }
@@ -1,5 +1,5 @@
1
- import type { FlattenSimpleInterpolation } from 'styled-components';
2
1
  import { css } from 'styled-components';
2
+ import type { FlattenSimpleInterpolation } from 'styled-components';
3
3
 
4
4
  enum Token {
5
5
  Comment = 'comment',
package/utils/color.d.ts CHANGED
@@ -1,2 +1 @@
1
- export declare const getRandomNumber: (limit: number) => number;
2
- export declare function getRandomColor(): string;
1
+ export declare function stringToHslColor(value: string): string;
package/utils/color.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRandomColor = exports.getRandomNumber = void 0;
4
- var getRandomNumber = function (limit) { return Math.floor(Math.random() * limit); };
5
- exports.getRandomNumber = getRandomNumber;
6
- function getRandomColor() {
7
- var h = (0, exports.getRandomNumber)(360);
8
- var s = (0, exports.getRandomNumber)(100);
9
- var l = (0, exports.getRandomNumber)(100);
10
- return "hsl(".concat(h, "deg, ").concat(s, "%, ").concat(l, "%)");
3
+ exports.stringToHslColor = void 0;
4
+ function stringToHslColor(value) {
5
+ var s = 30;
6
+ var l = 80;
7
+ var hash = 0;
8
+ for (var i = 0; i < value.length; i++) {
9
+ hash = value.charCodeAt(i) + ((hash << 5) - hash);
10
+ }
11
+ var h = hash % 360;
12
+ return "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)");
11
13
  }
12
- exports.getRandomColor = getRandomColor;
14
+ exports.stringToHslColor = stringToHslColor;