@redocly/theme 0.63.0-next.3 → 0.63.0-next.4

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 (36) hide show
  1. package/lib/components/Buttons/CopyButton.d.ts +1 -1
  2. package/lib/components/Buttons/CopyButton.js +1 -1
  3. package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistorySidebar.js +2 -2
  4. package/lib/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityVersionItem.js +6 -13
  5. package/lib/components/CodeBlock/CodeBlockControls.js +3 -3
  6. package/lib/components/PageActions/PageActions.js +1 -1
  7. package/lib/components/SidebarActions/styled.d.ts +1 -1
  8. package/lib/components/Tooltip/AnchorTooltip.d.ts +7 -0
  9. package/lib/components/Tooltip/AnchorTooltip.js +230 -0
  10. package/lib/components/Tooltip/JsTooltip.d.ts +3 -0
  11. package/lib/components/Tooltip/JsTooltip.js +274 -0
  12. package/lib/components/Tooltip/Tooltip.d.ts +2 -13
  13. package/lib/components/Tooltip/Tooltip.js +14 -190
  14. package/lib/core/hooks/use-page-actions.js +9 -5
  15. package/lib/core/hooks/use-theme-hooks.js +1 -0
  16. package/lib/core/types/hooks.d.ts +3 -0
  17. package/lib/core/types/index.d.ts +1 -0
  18. package/lib/core/types/tooltip.d.ts +13 -0
  19. package/lib/core/types/tooltip.js +3 -0
  20. package/lib/core/utils/transform-revisions-to-version-history.js +13 -20
  21. package/package.json +3 -3
  22. package/src/components/Buttons/CopyButton.tsx +2 -1
  23. package/src/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistorySidebar.tsx +2 -2
  24. package/src/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityVersionItem.tsx +5 -21
  25. package/src/components/CodeBlock/CodeBlockControls.tsx +3 -0
  26. package/src/components/PageActions/PageActions.tsx +6 -1
  27. package/src/components/Tooltip/AnchorTooltip.tsx +255 -0
  28. package/src/components/Tooltip/JsTooltip.tsx +292 -0
  29. package/src/components/Tooltip/Tooltip.tsx +18 -257
  30. package/src/core/hooks/__mocks__/use-theme-hooks.ts +3 -0
  31. package/src/core/hooks/use-page-actions.ts +5 -0
  32. package/src/core/hooks/use-theme-hooks.ts +1 -0
  33. package/src/core/types/hooks.ts +1 -0
  34. package/src/core/types/index.ts +1 -0
  35. package/src/core/types/tooltip.ts +14 -0
  36. package/src/core/utils/transform-revisions-to-version-history.ts +13 -21
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { TooltipProps } from '../../components/Tooltip/Tooltip';
2
+ import type { TooltipProps } from '../../core/types';
3
3
  import type { ButtonProps } from '../../components/Button/Button';
4
4
  export type CopyButtonProps = {
5
5
  data: unknown;
@@ -57,7 +57,7 @@ function CopyButtonComponent({ data, type = 'icon', toasterPlacement = 'top', to
57
57
  onCopyClick === null || onCopyClick === void 0 ? void 0 : onCopyClick(e);
58
58
  };
59
59
  return (react_1.default.createElement(Tooltip_1.Tooltip, { className: `copy-button ${className ? className : ''}`, tip: translate('codeSnippet.copy.buttonText', toasterText || 'Copied!'), isOpen: tooltip.isOpened, placement: toasterPlacement, width: "fit-content" },
60
- react_1.default.createElement(Button_1.Button, { "data-component-name": "Buttons/CopyButton", onClick: (e) => copy(e, toasterDuration), "data-testid": dataTestId, icon: type === 'icon' || type === 'compound' ? react_1.default.createElement(CopyIcon_1.CopyIcon, null) : undefined, size: size, variant: variant, disabled: disabled, fullWidth: fullWidth, tone: tone, extraClass: extraClass, iconPosition: iconPosition }, (type === 'text' || type === 'compound') &&
60
+ react_1.default.createElement(Button_1.Button, { "data-component-name": "Buttons/CopyButton", onClick: (e) => copy(e, toasterDuration), "data-testid": dataTestId, icon: type === 'icon' || type === 'compound' ? react_1.default.createElement(CopyIcon_1.CopyIcon, null) : undefined, size: size, variant: variant, disabled: disabled, fullWidth: fullWidth, tone: tone, extraClass: extraClass, iconPosition: iconPosition, "aria-label": "Copy" }, (type === 'text' || type === 'compound') &&
61
61
  (buttonText || translate('codeSnippet.copy.toasterText', 'Copy')))));
62
62
  }
63
63
  exports.CopyButton = (0, react_1.memo)(CopyButtonComponent);
@@ -111,10 +111,10 @@ function CatalogEntityHistorySidebar({ entityKey, revision, version, className,
111
111
  }
112
112
  const SidebarOverlay = styled_components_1.default.div `
113
113
  position: fixed;
114
- top: var(--navbar-height);
114
+ top: calc(var(--navbar-height) + var(--banner-height, 0));
115
115
  left: 0;
116
116
  width: var(--sidebar-width);
117
- height: calc(100vh - var(--navbar-height));
117
+ height: calc(100vh - var(--navbar-height) - var(--banner-height, 0));
118
118
  background-color: var(--catalog-history-sidebar-bg-color);
119
119
  border-right: 1px solid var(--catalog-history-sidebar-border-color);
120
120
  display: flex;
@@ -70,12 +70,10 @@ function CatalogEntityVersionItem({ group, basePath, isExpanded, onToggle, }) {
70
70
  }, [isExpanded]);
71
71
  const isNotSpecifiedVersion = group.version === constants_1.VERSION_NOT_SPECIFIED;
72
72
  const singleRevisionLink = (0, utils_1.buildRevisionUrl)(basePath, group.singleRevisionDate, group.version);
73
- const isClickable = hasRevisions || Boolean(singleRevisionLink);
74
- const isSingleRevisionActive = Boolean(singleRevisionLink && group.isCurrent);
75
73
  const versionTitle = isNotSpecifiedVersion
76
74
  ? `${translate('catalog.history.version.label', 'Version')}: ${translate('catalog.history.version.notSpecified', 'not specified')}`
77
75
  : `${translate('catalog.history.version.label', 'Version')}: ${group.version}`;
78
- const versionButton = (react_1.default.createElement(VersionButton, { type: "button", onClick: () => hasRevisions && onToggle(group.version), "$isClickable": isClickable, "$isCurrent": group.isCurrent, "$isActive": isSingleRevisionActive },
76
+ const versionButton = (react_1.default.createElement(VersionButton, { type: "button", onClick: () => hasRevisions && onToggle(group.version), "$isCurrent": group.isCurrent },
79
77
  react_1.default.createElement(VersionIcon, { "$isCurrent": group.isCurrent }, group.isCurrent ? (react_1.default.createElement(CheckmarkOutlineIcon_1.CheckmarkOutlineIcon, { size: "16px", color: "--catalog-history-sidebar-version-icon-color-current" })) : (react_1.default.createElement(NavaidMilitaryIcon_1.NavaidMilitaryIcon, { size: "16px", color: "--catalog-history-sidebar-version-icon-color" }))),
80
78
  react_1.default.createElement(VersionInfo, null,
81
79
  react_1.default.createElement(VersionTitleRow, null,
@@ -105,21 +103,16 @@ const VersionButton = styled_components_1.default.button `
105
103
  align-items: center;
106
104
  width: calc(100% - var(--catalog-history-sidebar-version-icon-margin-right));
107
105
  padding: var(--catalog-history-sidebar-version-header-padding);
108
- cursor: ${({ $isClickable }) => ($isClickable ? 'pointer' : 'default')};
106
+ cursor: pointer;
109
107
  border-radius: var(--catalog-history-sidebar-version-header-border-radius);
110
108
  transition: 0.2s ease;
111
109
  text-decoration: none;
112
110
  color: inherit;
113
- background-color: ${({ $isActive }) => $isActive ? 'var(--catalog-history-sidebar-revision-item-bg-color-active)' : 'transparent'};
111
+ background-color: 'transparent';
114
112
 
115
- ${({ $isClickable, $isActive }) => $isClickable &&
116
- `
117
- &:hover {
118
- background-color: ${$isActive
119
- ? 'var(--catalog-history-sidebar-revision-item-bg-color-active)'
120
- : 'var(--catalog-history-sidebar-version-header-bg-color-hover)'};
121
- }
122
- `}
113
+ &:hover {
114
+ background-color: var(--catalog-history-sidebar-version-header-bg-color-hover);
115
+ }
123
116
 
124
117
  ${({ $isCurrent }) => !$isCurrent &&
125
118
  `
@@ -39,11 +39,11 @@ function CodeBlockControls({ children, className, title, controls, tabs, dropdow
39
39
  react_1.default.createElement(ControlsWrapper, null,
40
40
  dropdown && react_1.default.createElement(CodeBlockDropdown_1.CodeBlockDropdown, Object.assign({}, dropdown)),
41
41
  report && !report.hidden && !((_a = report === null || report === void 0 ? void 0 : report.props) === null || _a === void 0 ? void 0 : _a.hide) ? (react_1.default.createElement(Tooltip_1.Tooltip, { tip: translate('codeSnippet.report.tooltipText', 'Report a problem'), placement: "top", arrowPosition: "right" },
42
- react_1.default.createElement(ControlButton, Object.assign({ variant: "text", size: "small", "data-testid": "report-button", icon: controlsType === 'icon' ? react_1.default.createElement(WarningSquareIcon_1.WarningSquareIcon, { size: "18px" }) : undefined }, report.props), controlsType != 'icon' && (((_b = report.props) === null || _b === void 0 ? void 0 : _b.buttonText) || 'Report')))) : null,
42
+ react_1.default.createElement(ControlButton, Object.assign({ variant: "text", size: "small", "data-testid": "report-button", icon: controlsType === 'icon' ? react_1.default.createElement(WarningSquareIcon_1.WarningSquareIcon, { size: "18px" }) : undefined, "aria-label": "Report a problem" }, report.props), controlsType != 'icon' && (((_b = report.props) === null || _b === void 0 ? void 0 : _b.buttonText) || 'Report')))) : null,
43
43
  expand && !((_c = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.expand) === null || _c === void 0 ? void 0 : _c.hide) ? (react_1.default.createElement(Tooltip_1.Tooltip, { tip: translate('codeSnippet.expand.tooltipText', 'Expand all'), placement: "top", arrowPosition: "right" },
44
- react_1.default.createElement(ControlButton, { variant: "text", size: "small", "data-testid": "expand-all", icon: controlsType === 'icon' ? react_1.default.createElement(MaximizeIcon_1.MaximizeIcon, null) : undefined, onClick: expand === null || expand === void 0 ? void 0 : expand.onClick }, controlsType !== 'icon' && ((expand === null || expand === void 0 ? void 0 : expand.label) || 'Expand all')))) : null,
44
+ react_1.default.createElement(ControlButton, { variant: "text", size: "small", "data-testid": "expand-all", icon: controlsType === 'icon' ? react_1.default.createElement(MaximizeIcon_1.MaximizeIcon, null) : undefined, "aria-label": "Expand all", onClick: expand === null || expand === void 0 ? void 0 : expand.onClick }, controlsType !== 'icon' && ((expand === null || expand === void 0 ? void 0 : expand.label) || 'Expand all')))) : null,
45
45
  collapse && !((_d = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.collapse) === null || _d === void 0 ? void 0 : _d.hide) ? (react_1.default.createElement(Tooltip_1.Tooltip, { tip: translate('codeSnippet.collapse.tooltipText', 'Collapse all'), placement: "top", arrowPosition: "right" },
46
- react_1.default.createElement(ControlButton, { variant: "text", size: "small", "data-testid": "collapse-all", icon: controlsType === 'icon' ? react_1.default.createElement(MinimizeIcon_1.MinimizeIcon, null) : undefined, onClick: collapse === null || collapse === void 0 ? void 0 : collapse.onClick }, controlsType !== 'icon' && ((expand === null || expand === void 0 ? void 0 : expand.label) || 'Collapse all')))) : null,
46
+ react_1.default.createElement(ControlButton, { variant: "text", size: "small", "data-testid": "collapse-all", icon: controlsType === 'icon' ? react_1.default.createElement(MinimizeIcon_1.MinimizeIcon, null) : undefined, onClick: collapse === null || collapse === void 0 ? void 0 : collapse.onClick, "aria-label": "Collapse all" }, controlsType !== 'icon' && ((expand === null || expand === void 0 ? void 0 : expand.label) || 'Collapse all')))) : null,
47
47
  select ? (react_1.default.createElement(ControlButton, { variant: "text", size: "small", "data-testid": "select-all", icon: controlsType === 'icon' ? react_1.default.createElement(SelectIcon_1.SelectIcon, null) : undefined, onClick: select === null || select === void 0 ? void 0 : select.onClick }, controlsType !== 'icon' && (select === null || select === void 0 ? void 0 : select.label) ? select.label : 'Select all')) : null,
48
48
  deselect ? (react_1.default.createElement(ControlButton, { variant: "text", size: "small", "data-testid": "clear-all", icon: controlsType === 'icon' ? react_1.default.createElement(DeselectIcon_1.DeselectIcon, null) : undefined, onClick: deselect === null || deselect === void 0 ? void 0 : deselect.onClick }, controlsType !== 'icon' && (deselect === null || deselect === void 0 ? void 0 : deselect.label) ? deselect.label : 'Clear all')) : null,
49
49
  copy && !((_e = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.copy) === null || _e === void 0 ? void 0 : _e.hide) ? (react_1.default.createElement(Tooltip_1.Tooltip, { tip: translate('codeSnippet.copy.tooltipText', 'Copy to clipboard'), placement: "top", arrowPosition: "right" },
@@ -88,7 +88,7 @@ function PageActions(props) {
88
88
  return (react_1.default.createElement(PageActionsWrapper, { "data-component-name": "PageActions/PageActions" },
89
89
  react_1.default.createElement(ButtonGroup_1.ButtonGroup, { variant: "outlined", size: "medium" },
90
90
  react_1.default.createElement(Button_1.Button, { icon: renderIcon(buttonAction, actionState), to: 'link' in buttonAction ? buttonAction.link : undefined, external: true, onClick: () => handleActionClick(buttonAction) }, buttonAction.buttonText),
91
- actions.length > 1 ? (react_1.default.createElement(StyledDropdown, { withArrow: true, trigger: react_1.default.createElement(Button_1.Button, null), placement: "bottom", alignment: "end" },
91
+ actions.length > 1 ? (react_1.default.createElement(StyledDropdown, { withArrow: true, trigger: react_1.default.createElement(Button_1.Button, { "aria-label": "More actions" }), placement: "bottom", alignment: "end" },
92
92
  react_1.default.createElement(StyledDropdownMenu, null, menuItems))) : null)));
93
93
  }
94
94
  function renderIcon(buttonAction, actionState) {
@@ -1,7 +1,7 @@
1
1
  declare const StyledChangeViewButton: import("styled-components").StyledComponent<"span", any, {
2
2
  collapsedSidebar?: boolean;
3
3
  }, never>;
4
- declare const StyledChangeViewButtonWrap: import("styled-components").StyledComponent<import("react").NamedExoticComponent<import("react").PropsWithChildren<import("../../components/Tooltip/Tooltip").TooltipProps>>, any, {
4
+ declare const StyledChangeViewButtonWrap: import("styled-components").StyledComponent<import("react").NamedExoticComponent<import("../..").TooltipProps>, any, {
5
5
  active?: boolean;
6
6
  }, never>;
7
7
  declare const ControlsWrap: import("styled-components").StyledComponent<"span", any, {
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { TooltipProps } from '../../core/types';
3
+ type Props = Exclude<TooltipProps, 'arrowPosition'> & {
4
+ arrowPosition?: 'left' | 'right' | 'center';
5
+ };
6
+ export declare const Tooltip: React.NamedExoticComponent<React.PropsWithChildren<Props>>;
7
+ export {};
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Tooltip = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const styled_components_1 = __importStar(require("styled-components"));
39
+ const hooks_1 = require("../../core/hooks");
40
+ const Portal_1 = require("../../components/Portal/Portal");
41
+ function TooltipComponent({ children, isOpen, tip, withArrow = true, placement = 'top', className = 'default', width, dataTestId, disabled = false, arrowPosition = 'center', }) {
42
+ const tooltipWrapperRef = (0, react_1.useRef)(null);
43
+ const tooltipBodyRef = (0, react_1.useRef)(null);
44
+ const { isOpened, handleOpen, handleClose } = (0, hooks_1.useControl)(isOpen);
45
+ const anchorName = `--tooltip${(0, react_1.useId)().replace(/:/g, '')}`;
46
+ (0, hooks_1.useOutsideClick)(isOpened ? [tooltipWrapperRef, tooltipBodyRef] : tooltipWrapperRef, handleClose);
47
+ const isControlled = isOpen !== undefined;
48
+ (0, react_1.useEffect)(() => {
49
+ if (!isControlled)
50
+ return;
51
+ if (isOpen && !disabled) {
52
+ handleOpen();
53
+ }
54
+ else {
55
+ handleClose();
56
+ }
57
+ }, [isOpen, disabled, isControlled, handleOpen, handleClose]);
58
+ const controllers = !isControlled && !disabled
59
+ ? {
60
+ onMouseEnter: handleOpen,
61
+ onMouseLeave: handleClose,
62
+ onClick: handleClose,
63
+ onFocus: handleOpen,
64
+ onBlur: handleClose,
65
+ }
66
+ : {};
67
+ return (react_1.default.createElement(TooltipWrapper, Object.assign({ ref: tooltipWrapperRef }, controllers, { className: `tooltip-${className}`, "data-component-name": "Tooltip/Tooltip", anchorName: anchorName }),
68
+ children,
69
+ isOpened && !disabled && (react_1.default.createElement(Portal_1.Portal, null,
70
+ react_1.default.createElement(TooltipBody, { ref: tooltipBodyRef, "data-testid": dataTestId || (typeof tip === 'string' ? tip : ''), placement: placement, width: width, withArrow: withArrow, arrowPosition: arrowPosition, anchorName: anchorName }, tip)))));
71
+ }
72
+ exports.Tooltip = (0, react_1.memo)(TooltipComponent);
73
+ const PLACEMENTS = {
74
+ top: (0, styled_components_1.css) `
75
+ bottom: anchor(top);
76
+ ${({ withArrow, arrowPosition }) => withArrow && arrowPosition === 'left'
77
+ ? (0, styled_components_1.css) `
78
+ transform: translate(-32px, -6px);
79
+ left: anchor(center);
80
+ `
81
+ : arrowPosition === 'right'
82
+ ? (0, styled_components_1.css) `
83
+ transform: translate(32px, -6px);
84
+ right: anchor(center);
85
+ `
86
+ : (0, styled_components_1.css) `
87
+ transform: translate(-50%, -6px);
88
+ left: anchor(center);
89
+ `}
90
+
91
+ ${({ withArrow, arrowPosition }) => withArrow &&
92
+ (0, styled_components_1.css) `
93
+ &::after {
94
+ border-left: 14px solid transparent;
95
+ border-right: 14px solid transparent;
96
+ border-top-width: 8px;
97
+ border-top-style: solid;
98
+ border-radius: 2px;
99
+ bottom: 0;
100
+ ${arrowPosition === 'left' && 'left: 16px; transform: translateY(100%);'}
101
+ ${arrowPosition === 'center' && 'left: 50%; transform: translate(-50%, 100%);'}
102
+ ${arrowPosition === 'right' && 'right: 16px; transform: translateY(100%);'}
103
+ }
104
+ `}
105
+ `,
106
+ bottom: (0, styled_components_1.css) `
107
+ top: anchor(bottom);
108
+ ${({ withArrow, arrowPosition }) => withArrow && arrowPosition === 'left'
109
+ ? (0, styled_components_1.css) `
110
+ transform: translate(-32px, 6px);
111
+ left: anchor(center);
112
+ `
113
+ : arrowPosition === 'right'
114
+ ? (0, styled_components_1.css) `
115
+ transform: translate(32px, 6px);
116
+ right: anchor(center);
117
+ `
118
+ : (0, styled_components_1.css) `
119
+ transform: translate(-50%, 6px);
120
+ left: anchor(center);
121
+ `}
122
+
123
+ ${({ withArrow, arrowPosition }) => withArrow &&
124
+ (0, styled_components_1.css) `
125
+ &::after {
126
+ border-left: 14px solid transparent;
127
+ border-right: 14px solid transparent;
128
+ border-bottom-width: 8px;
129
+ border-bottom-style: solid;
130
+ border-radius: 0 0 2px 2px;
131
+ top: 0;
132
+ ${arrowPosition === 'left' && 'left: 16px; transform: translateY(-100%);'}
133
+ ${arrowPosition === 'center' && 'left: 50%; transform: translate(-50%, -100%);'}
134
+ ${arrowPosition === 'right' && 'right: 16px; transform: translateY(-100%);'}
135
+ }
136
+ `}
137
+ `,
138
+ left: (0, styled_components_1.css) `
139
+ transform: translate(-100%, -50%);
140
+ margin-left: -7px;
141
+ top: anchor(center);
142
+ left: anchor(left);
143
+
144
+ ${({ withArrow }) => withArrow &&
145
+ (0, styled_components_1.css) `
146
+ &::after {
147
+ border-top: 14px solid transparent;
148
+ border-bottom: 14px solid transparent;
149
+ border-left-width: 8px;
150
+ border-left-style: solid;
151
+ border-radius: 2px 0 0 2px;
152
+ right: -9px;
153
+ top: 50%;
154
+ transform: translateY(-50%);
155
+ }
156
+ `}
157
+ `,
158
+ right: (0, styled_components_1.css) `
159
+ transform: translate(0, -50%);
160
+ margin-left: 7px;
161
+ top: anchor(center);
162
+ left: anchor(right);
163
+
164
+ ${({ withArrow }) => withArrow &&
165
+ (0, styled_components_1.css) `
166
+ &::after {
167
+ border-top: 14px solid transparent;
168
+ border-bottom: 14px solid transparent;
169
+ border-right-width: 8px;
170
+ border-right-style: solid;
171
+ border-radius: 0 2px 2px 0;
172
+ left: -9px;
173
+ top: 50%;
174
+ transform: translateY(-50%);
175
+ }
176
+ `}
177
+ `,
178
+ };
179
+ const TooltipWrapper = styled_components_1.default.div.attrs(({ anchorName }) => ({
180
+ style: {
181
+ anchorName: anchorName,
182
+ },
183
+ })) `
184
+ display: flex;
185
+ `;
186
+ const TooltipBody = styled_components_1.default.span.attrs(({ anchorName }) => ({
187
+ style: {
188
+ positionAnchor: anchorName,
189
+ },
190
+ })) `
191
+ position: fixed;
192
+ min-width: 64px;
193
+ padding: var(--tooltip-padding);
194
+ max-width: var(--tooltip-max-width);
195
+ white-space: normal;
196
+ word-break: normal;
197
+ overflow-wrap: break-word;
198
+ text-align: left;
199
+
200
+ border-radius: var(--border-radius-md);
201
+ transition: opacity 0.3s ease-out;
202
+
203
+ font-size: var(--font-size-base);
204
+ line-height: var(--line-height-base);
205
+
206
+ z-index: var(--z-index-overlay);
207
+
208
+ &::after {
209
+ position: absolute;
210
+
211
+ content: ' ';
212
+ display: inline-block;
213
+ width: 0;
214
+ height: 0;
215
+ border-color: var(--tooltip-arrow-color, var(--tooltip-bg-color));
216
+ }
217
+
218
+ background: var(--tooltip-bg-color);
219
+ color: var(--tooltip-text-color);
220
+ border: var(--tooltip-border-width, 0) var(--tooltip-border-style, solid)
221
+ var(--tooltip-border-color, transparent);
222
+ box-shadow: var(--bg-raised-shadow);
223
+
224
+ width: ${({ width }) => width || 'max-content'};
225
+
226
+ ${({ placement }) => (0, styled_components_1.css) `
227
+ ${PLACEMENTS[placement]};
228
+ `}
229
+ `;
230
+ //# sourceMappingURL=AnchorTooltip.js.map
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { TooltipProps } from '../../core/types';
3
+ export declare const Tooltip: React.NamedExoticComponent<React.PropsWithChildren<TooltipProps>>;
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Tooltip = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const styled_components_1 = __importStar(require("styled-components"));
39
+ const hooks_1 = require("../../core/hooks");
40
+ const Portal_1 = require("../../components/Portal/Portal");
41
+ function TooltipComponent({ children, isOpen, tip, withArrow = true, placement = 'top', className = 'default', width, dataTestId, disabled = false, arrowPosition = 'center', }) {
42
+ const ref = (0, react_1.useRef)(null);
43
+ const { isOpened, handleOpen, handleClose } = (0, hooks_1.useControl)(isOpen);
44
+ const [tooltipPosition, setTooltipPosition] = (0, react_1.useState)({ top: 0, left: 0 });
45
+ (0, hooks_1.useOutsideClick)(ref, handleClose);
46
+ const isControlled = isOpen !== undefined;
47
+ const updateTooltipPosition = (0, react_1.useCallback)(() => {
48
+ if (isOpened && ref.current) {
49
+ const rect = ref.current.getBoundingClientRect();
50
+ let top = 0;
51
+ let left = 0;
52
+ switch (placement) {
53
+ case 'top':
54
+ top = rect.top;
55
+ if (arrowPosition === 'left') {
56
+ left = rect.left - 24;
57
+ }
58
+ else if (arrowPosition === 'right') {
59
+ left = rect.right + 24;
60
+ }
61
+ else {
62
+ left = rect.left + rect.width / 2;
63
+ }
64
+ break;
65
+ case 'bottom':
66
+ top = rect.bottom;
67
+ if (arrowPosition === 'left') {
68
+ left = rect.left - 24;
69
+ }
70
+ else if (arrowPosition === 'right') {
71
+ left = rect.right + 24;
72
+ }
73
+ else {
74
+ left = rect.left + rect.width / 2;
75
+ }
76
+ break;
77
+ case 'left':
78
+ top = rect.top + rect.height / 2;
79
+ left = rect.left;
80
+ break;
81
+ case 'right':
82
+ top = rect.top + rect.height / 2;
83
+ left = rect.right;
84
+ break;
85
+ }
86
+ setTooltipPosition({ top, left });
87
+ }
88
+ }, [isOpened, placement, arrowPosition]);
89
+ (0, react_1.useLayoutEffect)(() => {
90
+ if (isOpened && ref.current) {
91
+ updateTooltipPosition();
92
+ const handleScroll = () => updateTooltipPosition();
93
+ const handleResize = () => updateTooltipPosition();
94
+ window.addEventListener('scroll', handleScroll, true);
95
+ window.addEventListener('resize', handleResize);
96
+ return () => {
97
+ window.removeEventListener('scroll', handleScroll, true);
98
+ window.removeEventListener('resize', handleResize);
99
+ };
100
+ }
101
+ }, [isOpened, placement, updateTooltipPosition]);
102
+ (0, react_1.useEffect)(() => {
103
+ if (isOpen && !disabled) {
104
+ handleOpen();
105
+ }
106
+ else {
107
+ handleClose();
108
+ }
109
+ }, [isOpen, handleOpen, handleClose, disabled]);
110
+ const controllers = !isControlled &&
111
+ !disabled && {
112
+ onMouseEnter: handleOpen,
113
+ onMouseLeave: handleClose,
114
+ onClick: handleClose,
115
+ onFocus: handleOpen,
116
+ onBlur: handleClose,
117
+ };
118
+ return (react_1.default.createElement(TooltipWrapper, Object.assign({ ref: ref }, controllers, { className: `tooltip-${className}`, "data-component-name": "Tooltip/Tooltip" }),
119
+ children,
120
+ isOpened && !disabled && (react_1.default.createElement(Portal_1.Portal, null,
121
+ react_1.default.createElement(TooltipBody, { "data-testid": dataTestId || (typeof tip === 'string' ? tip : ''), placement: placement, width: width, withArrow: withArrow, arrowPosition: arrowPosition, style: {
122
+ position: 'fixed',
123
+ top: tooltipPosition.top,
124
+ left: tooltipPosition.left,
125
+ } }, tip)))));
126
+ }
127
+ exports.Tooltip = (0, react_1.memo)(TooltipComponent);
128
+ const PLACEMENTS = {
129
+ top: (0, styled_components_1.css) `
130
+ ${({ withArrow, arrowPosition }) => withArrow && arrowPosition === 'left'
131
+ ? (0, styled_components_1.css) `
132
+ transform: translate(0, -100%);
133
+ margin-top: -10px;
134
+ `
135
+ : arrowPosition === 'right'
136
+ ? (0, styled_components_1.css) `
137
+ transform: translate(-100%, -100%);
138
+ margin-top: -10px;
139
+ `
140
+ : (0, styled_components_1.css) `
141
+ transform: translate(-50%, -100%);
142
+ margin-top: -10px;
143
+ `}
144
+
145
+ ${({ withArrow, arrowPosition }) => withArrow &&
146
+ (0, styled_components_1.css) `
147
+ &::after {
148
+ border-left: 14px solid transparent;
149
+ border-right: 14px solid transparent;
150
+ border-top-width: 8px;
151
+ border-top-style: solid;
152
+ border-radius: 2px;
153
+ bottom: 0;
154
+ ${arrowPosition === 'left' && 'left: 16px; transform: translateY(99%);'}
155
+ ${arrowPosition === 'center' && 'left: 50%; transform: translate(-50%, 99%);'}
156
+ ${arrowPosition === 'right' && 'right: 16px; transform: translateY(99%);'}
157
+ }
158
+ `}
159
+ `,
160
+ bottom: (0, styled_components_1.css) `
161
+ ${({ withArrow, arrowPosition }) => withArrow && arrowPosition === 'left'
162
+ ? (0, styled_components_1.css) `
163
+ transform: translate(0, 10px);
164
+ margin-top: 0;
165
+ `
166
+ : arrowPosition === 'right'
167
+ ? (0, styled_components_1.css) `
168
+ transform: translate(-100%, 10px);
169
+ margin-top: 0;
170
+ `
171
+ : (0, styled_components_1.css) `
172
+ transform: translate(-50%, 10px);
173
+ margin-top: 0;
174
+ `}
175
+
176
+ ${({ withArrow, arrowPosition }) => withArrow &&
177
+ (0, styled_components_1.css) `
178
+ &::after {
179
+ border-left: 14px solid transparent;
180
+ border-right: 14px solid transparent;
181
+ border-bottom-width: 8px;
182
+ border-bottom-style: solid;
183
+ border-radius: 0 0 2px 2px;
184
+ top: 0;
185
+ ${arrowPosition === 'left' && 'left: 16px; transform: translateY(-99%);'}
186
+ ${arrowPosition === 'center' && 'left: 50%; transform: translate(-50%, -99%);'}
187
+ ${arrowPosition === 'right' && 'right: 16px; transform: translateY(-99%);'}
188
+ }
189
+ `}
190
+ `,
191
+ left: (0, styled_components_1.css) `
192
+ transform: translate(-100%, -50%);
193
+ margin-left: -10px;
194
+
195
+ ${({ withArrow, arrowPosition }) => withArrow &&
196
+ (0, styled_components_1.css) `
197
+ &::after {
198
+ border-top: 14px solid transparent;
199
+ border-bottom: 14px solid transparent;
200
+ border-left-width: 8px;
201
+ border-left-style: solid;
202
+ border-radius: 2px 0 0 2px;
203
+ top: 50%;
204
+ right: 0;
205
+ ${arrowPosition === 'top' && 'top: 16px; transform: translateX(99%);'}
206
+ ${arrowPosition === 'center' && 'top: 50%; transform: translate(99%, -50%);'}
207
+ ${arrowPosition === 'bottom' && 'bottom: 16px; transform: translateX(99%);'}
208
+ }
209
+ `}
210
+ `,
211
+ right: (0, styled_components_1.css) `
212
+ transform: translate(0, -50%);
213
+ margin-left: 10px;
214
+
215
+ ${({ withArrow, arrowPosition }) => withArrow &&
216
+ (0, styled_components_1.css) `
217
+ &::after {
218
+ border-top: 14px solid transparent;
219
+ border-bottom: 14px solid transparent;
220
+ border-right-width: 8px;
221
+ border-right-style: solid;
222
+ border-radius: 0 2px 2px 0;
223
+ top: 50%;
224
+ left: 0;
225
+ ${arrowPosition === 'top' && 'top: 16px; transform: translateX(-99%);'}
226
+ ${arrowPosition === 'center' && 'top: 50%; transform: translate(-99%, -50%);'}
227
+ ${arrowPosition === 'bottom' && 'bottom: 16px; transform: translateX(-99%);'}
228
+ }
229
+ `}
230
+ `,
231
+ };
232
+ const TooltipWrapper = styled_components_1.default.div `
233
+ position: relative;
234
+ display: flex;
235
+ `;
236
+ const TooltipBody = styled_components_1.default.span `
237
+ display: inline-block;
238
+
239
+ padding: var(--tooltip-padding);
240
+ max-width: ${({ width }) => width || 'var(--tooltip-max-width)'};
241
+ white-space: normal;
242
+ word-break: normal;
243
+ overflow-wrap: break-word;
244
+
245
+ border-radius: var(--border-radius-md);
246
+ transition: opacity 0.3s ease-out;
247
+
248
+ font-size: var(--font-size-base);
249
+ line-height: var(--line-height-base);
250
+
251
+ z-index: var(--z-index-overlay);
252
+
253
+ &::after {
254
+ position: absolute;
255
+
256
+ content: ' ';
257
+ display: inline-block;
258
+ width: 0;
259
+ height: 0;
260
+ border-color: var(--tooltip-arrow-color, var(--tooltip-bg-color));
261
+ }
262
+
263
+ background: var(--tooltip-bg-color);
264
+ color: var(--tooltip-text-color);
265
+ border: var(--tooltip-border-width, 0) var(--tooltip-border-style, solid)
266
+ var(--tooltip-border-color, transparent);
267
+ box-shadow: var(--bg-raised-shadow);
268
+
269
+ width: ${({ width }) => width || 'auto'};
270
+ ${({ placement }) => (0, styled_components_1.css) `
271
+ ${PLACEMENTS[placement]};
272
+ `}
273
+ `;
274
+ //# sourceMappingURL=JsTooltip.js.map
@@ -1,14 +1,3 @@
1
1
  import React from 'react';
2
- import type { ReactNode } from 'react';
3
- export type TooltipProps = {
4
- tip: string | ReactNode;
5
- isOpen?: boolean;
6
- withArrow?: boolean;
7
- placement?: 'top' | 'bottom' | 'left' | 'right';
8
- className?: string;
9
- width?: string;
10
- dataTestId?: string;
11
- disabled?: boolean;
12
- arrowPosition?: 'left' | 'right' | 'center';
13
- };
14
- export declare const Tooltip: React.NamedExoticComponent<React.PropsWithChildren<TooltipProps>>;
2
+ import { TooltipProps } from '../../core/types';
3
+ export declare const Tooltip: React.NamedExoticComponent<TooltipProps>;