@rescui/tooltip 0.7.3 → 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.
@@ -0,0 +1,3 @@
1
+ export declare const extractPrimaryColors: (styles: CSSStyleDeclaration) => Record<string, string>;
2
+ /** Check out `@rescui/colors/src/public-api.p.css` file */
3
+ export declare const extractThemeFromCss: (styles: CSSStyleDeclaration) => "dark" | "light";
@@ -0,0 +1,21 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ var PRIMARY_COLORS = ['--rs-color-primary-light-theme', '--rs-color-primary-dim-light-theme', '--rs-color-primary-fog-light-theme', '--rs-color-primary-t-dim-light-theme', '--rs-color-primary-t-fog-light-theme', '--rs-color-primary-dark-theme', '--rs-color-primary-dim-dark-theme', '--rs-color-primary-fog-dark-theme', '--rs-color-primary-t-dim-dark-theme', '--rs-color-primary-t-fog-dark-theme'];
3
+
4
+ var extractPrimaryColors = function extractPrimaryColors(styles) {
5
+ var colors = {};
6
+ PRIMARY_COLORS.forEach(function (varName) {
7
+ colors[varName] = styles.getPropertyValue(varName) || 'initial';
8
+ });
9
+ return colors;
10
+ };
11
+ /** Check out `@rescui/colors/src/public-api.p.css` file */
12
+
13
+
14
+ var extractThemeFromCss = function extractThemeFromCss(styles) {
15
+ var themeDark = parseInt(styles.getPropertyValue('--rs-theme-dark'), 10) || 0;
16
+ var themeFlip = parseInt(styles.getPropertyValue('--rs-theme-flip'), 10) || 0;
17
+ var themeDarkCoefficient = themeDark * (1 - themeFlip) + themeFlip * (1 - themeDark);
18
+ return themeDarkCoefficient === 1 ? 'dark' : 'light';
19
+ };
20
+
21
+ export { extractPrimaryColors, extractThemeFromCss };
package/lib/index.css CHANGED
@@ -1,24 +1,72 @@
1
- ._tooltip_1twilvc_4{
1
+ ._tooltip_1d84c4t_5{
2
2
  position:relative;
3
3
  }
4
- ._closing_1twilvc_8{
4
+ ._closing_1d84c4t_9{
5
5
  pointer-events:none;
6
6
  }
7
- ._content_1twilvc_12{
8
- letter-spacing:0.0045em;
9
- font-family:'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
10
- font-family:var(--rs-font-family-ui, var(--rs-font-family-jb-sans, 'JetBrains Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Droid Sans', 'Helvetica Neue', Arial, sans-serif));
11
- -webkit-font-feature-settings:"kern", "liga", "calt";
12
- font-feature-settings:"kern", "liga", "calt";
13
- font-size:13px;
14
- font-size:var(--rs-text-3-font-size, 13px);
15
- line-height:20px;
16
- line-height:var(--rs-text-3-line-height, 20px);
7
+ ._content_1d84c4t_13{
8
+ --rs-theme-dark:1;
9
+
10
+ --_rs-theme-dark:var(
11
+ --_rs-internal-force-theme-dark-consult-rescui-before-using,
12
+ var(--rs-theme-dark, 0)
13
+ );
14
+
15
+ --_rs-theme-flip:var(--rs-theme-flip, 0);
16
+
17
+ --_rs-theme-dark-coefficient:calc(var(--_rs-theme-dark)*(1 - var(--_rs-theme-flip)) + var(--_rs-theme-flip)*(1 - var(--_rs-theme-dark)));
18
+
19
+ --_rs-theme-light-coefficient:calc(1 - var(--_rs-theme-dark-coefficient));
20
+ letter-spacing:var(
21
+ --rs-text-base-letter-spacing,
22
+ var(--_rs-typography-letter-spacing)
23
+ );
24
+ text-transform:var(--_rs-typography-text-transform);
25
+ font-family:var(--_rs-typography-font-family);
26
+ font-size:var(--_rs-typography-font-size);
27
+ font-weight:var(--_rs-typography-font-weight);
28
+ line-height:var(--_rs-typography-line-height);
29
+ font-variant-numeric:var(--_rs-typography-font-variant-numeric);
30
+ -webkit-font-feature-settings:'kern', 'liga', 'calt';
31
+ font-feature-settings:'kern', 'liga', 'calt';
17
32
  }
18
- ._rs-reset-letter-spacing_1twilvc_1 ._content_1twilvc_12{
19
- letter-spacing:normal;
33
+ ._content_1d84c4t_13 > p:not(:nth-child(1)),
34
+ ._content_1d84c4t_13 > pre:not(:nth-child(1)){
35
+ padding-top:var(--_rs-typography-auto-offset-or-initial);
20
36
  }
21
- ._content_1twilvc_12 {
37
+ ._content_1d84c4t_13 {
38
+ --_rs-typography-letter-spacing:0.0045em;
39
+ --_rs-typography-text-transform:initial;
40
+ --_rs-typography-font-variant-numeric:initial;
41
+ --_rs-typography-font-family:var(
42
+ --rs-font-family-ui,
43
+ var(--rs-font-family-jb-sans, 'JetBrains Sans', Inter, system-ui, -apple-system,
44
+ BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
45
+ 'Droid Sans', 'Helvetica Neue', Arial, sans-serif)
46
+ );
47
+ --_rs-typography-font-size:var(--rs-text-3-font-size, 13px);
48
+ --_rs-typography-font-weight:var(
49
+ --rs-font-weight-regular,
50
+ 400
51
+ );
52
+ --_rs-typography-line-height:var(
53
+ --rs-text-3-line-height,
54
+ 20px
55
+ );
56
+ --_rs-typography-base-color:var(
57
+ --_rs-typography-hardness-color,
58
+ var(
59
+ --rs-color-average,
60
+ rgba(calc(25 + var(--_rs-theme-dark-coefficient, 0)*230), calc(25 + var(--_rs-theme-dark-coefficient, 0)*230), calc(28 + var(--_rs-theme-dark-coefficient, 0)*227), 0.7)
61
+ )
62
+ );
63
+ --_rs-typography-text-auto-offset:8px;
64
+ --_rs-typography-ul-list-li-padding-left:28px;
65
+ --_rs-typography-ol-list-li-padding-left:21px;
66
+ --_rs-typography-list-li-margin-top-from-text:8px;
67
+ --_rs-typography-link-standalone-border-offset-from-text-base:1.15em;
68
+ --_rs-typography-link-external-standalone-border-offset-from-text-base:1.02em;
69
+ --_rs-typography-link-border-bottom-width-from-text:1px;
22
70
 
23
71
  max-width:283px;
24
72
 
@@ -39,56 +87,77 @@
39
87
  -webkit-transform:translate(0, 0);
40
88
  transform:translate(0, 0);
41
89
  }
42
- [data-real-placement='top-end'] ._content_1twilvc_12,
43
- [data-real-placement='bottom-end'] ._content_1twilvc_12{
90
+ [data-real-placement='top-end'] ._content_1d84c4t_13,
91
+ [data-real-placement='bottom-end'] ._content_1d84c4t_13{
44
92
  margin-right:0;
45
93
  }
46
- [data-real-placement='top-start'] ._content_1twilvc_12,
47
- [data-real-placement='bottom-start'] ._content_1twilvc_12{
94
+ [data-real-placement='top-start'] ._content_1d84c4t_13,
95
+ [data-real-placement='bottom-start'] ._content_1d84c4t_13{
48
96
  margin-left:0;
49
97
  }
50
- [data-real-placement='left-end'] ._content_1twilvc_12,
51
- [data-real-placement='right-end'] ._content_1twilvc_12{
98
+ [data-real-placement='left-end'] ._content_1d84c4t_13,
99
+ [data-real-placement='right-end'] ._content_1d84c4t_13{
52
100
  margin-bottom:0;
53
101
  }
54
- [data-real-placement='left-start'] ._content_1twilvc_12,
55
- [data-real-placement='right-start'] ._content_1twilvc_12{
102
+ [data-real-placement='left-start'] ._content_1d84c4t_13,
103
+ [data-real-placement='right-start'] ._content_1d84c4t_13{
56
104
  margin-top:0;
57
105
  }
58
- ._initial_1twilvc_47 ._content_1twilvc_12{
106
+ ._initial_1d84c4t_52 ._content_1d84c4t_13{
59
107
  -webkit-transition:none;
60
108
  transition:none;
61
109
  }
62
- ._closing_1twilvc_8 ._content_1twilvc_12{
110
+ ._closing_1d84c4t_9 ._content_1d84c4t_13{
63
111
  -webkit-transition-duration:200ms, 200ms;
64
112
  transition-duration:200ms, 200ms;
65
113
  }
66
- ._initial_1twilvc_47 ._content_1twilvc_12,
67
- ._closing_1twilvc_8 ._content_1twilvc_12{
114
+ ._initial_1d84c4t_52 ._content_1d84c4t_13,
115
+ ._closing_1d84c4t_9 ._content_1d84c4t_13{
68
116
  opacity:0;
69
117
  }
70
- ._initial_1twilvc_47[data-real-placement^='top'] ._content_1twilvc_12, ._closing_1twilvc_8[data-real-placement^='top'] ._content_1twilvc_12{
118
+ ._outerThemeLight_1d84c4t_66 ._content_1d84c4t_13{
119
+ --rs-color-primary-dark-theme:var(--rs-color-primary-light-theme);
120
+ --rs-color-primary-dim-dark-theme:var(--rs-color-primary-dim-light-theme);
121
+ --rs-color-primary-fog-dark-theme:var(--rs-color-primary-fog-light-theme);
122
+ --rs-color-primary-t-dim-dark-theme:var(
123
+ --rs-color-primary-t-dim-light-theme
124
+ );
125
+ --rs-color-primary-t-fog-dark-theme:var(
126
+ --rs-color-primary-t-fog-light-theme
127
+ );
128
+ }
129
+ ._outerThemeDark_1d84c4t_79 ._content_1d84c4t_13{
130
+ --rs-color-primary-light-theme:var(--rs-color-primary-dark-theme);
131
+ --rs-color-primary-dim-light-theme:var(--rs-color-primary-dim-dark-theme);
132
+ --rs-color-primary-fog-light-theme:var(--rs-color-primary-fog-dark-theme);
133
+ --rs-color-primary-t-dim-light-theme:var(
134
+ --rs-color-primary-t-dim-dark-theme
135
+ );
136
+ --rs-color-primary-t-fog-light-theme:var(
137
+ --rs-color-primary-t-fog-dark-theme
138
+ );
139
+ }
140
+ ._initial_1d84c4t_52[data-real-placement^='top'] ._content_1d84c4t_13, ._closing_1d84c4t_9[data-real-placement^='top'] ._content_1d84c4t_13{
71
141
  -webkit-transform:translate(0, 10px);
72
142
  transform:translate(0, 10px);
73
143
  }
74
- ._initial_1twilvc_47[data-real-placement^='right'] ._content_1twilvc_12, ._closing_1twilvc_8[data-real-placement^='right'] ._content_1twilvc_12{
144
+ ._initial_1d84c4t_52[data-real-placement^='right'] ._content_1d84c4t_13, ._closing_1d84c4t_9[data-real-placement^='right'] ._content_1d84c4t_13{
75
145
  -webkit-transform:translate(-10px, 0);
76
146
  transform:translate(-10px, 0);
77
147
  }
78
- ._initial_1twilvc_47[data-real-placement^='bottom'] ._content_1twilvc_12, ._closing_1twilvc_8[data-real-placement^='bottom'] ._content_1twilvc_12{
148
+ ._initial_1d84c4t_52[data-real-placement^='bottom'] ._content_1d84c4t_13, ._closing_1d84c4t_9[data-real-placement^='bottom'] ._content_1d84c4t_13{
79
149
  -webkit-transform:translate(0, -10px);
80
150
  transform:translate(0, -10px);
81
151
  }
82
- ._initial_1twilvc_47[data-real-placement^='left'] ._content_1twilvc_12, ._closing_1twilvc_8[data-real-placement^='left'] ._content_1twilvc_12{
152
+ ._initial_1d84c4t_52[data-real-placement^='left'] ._content_1d84c4t_13, ._closing_1d84c4t_9[data-real-placement^='left'] ._content_1d84c4t_13{
83
153
  -webkit-transform:translate(10px, 0);
84
154
  transform:translate(10px, 0);
85
155
  }
86
- ._trigger_1twilvc_81:focus-visible,
87
- ._trigger_1twilvc_81:focus[data-focus-method='key']{
88
- outline:none;
89
- -webkit-box-shadow:rgba(107, 87, 255, 0.8) 0 0 0 4px;
90
- -webkit-box-shadow:var(--rs-color-primary-t-dim-light-theme, rgba(107, 87, 255, 0.8)) 0 0 0 4px;
91
- box-shadow:rgba(107, 87, 255, 0.8) 0 0 0 4px;
92
- box-shadow:var(--rs-color-primary-t-dim-light-theme, rgba(107, 87, 255, 0.8)) 0 0 0 4px;
93
- }
156
+ ._trigger_1d84c4t_111:focus-visible,
157
+ ._trigger_1d84c4t_111:focus[data-focus-method='key']{
158
+ outline:none;
94
159
 
160
+ -webkit-box-shadow:var(--rs-color-primary-t-dim-light-theme) 0 0 0 4px;
161
+
162
+ box-shadow:var(--rs-color-primary-t-dim-light-theme) 0 0 0 4px;
163
+ }
@@ -1,9 +1,10 @@
1
1
  var styles = {
2
- "tooltip": "_tooltip_1twilvc_4",
3
- "closing": "_closing_1twilvc_8",
4
- "content": "_content_1twilvc_12",
5
- "rs-reset-letter-spacing": "_rs-reset-letter-spacing_1twilvc_1",
6
- "initial": "_initial_1twilvc_47",
7
- "trigger": "_trigger_1twilvc_81"
2
+ "tooltip": "_tooltip_1d84c4t_5",
3
+ "closing": "_closing_1d84c4t_9",
4
+ "content": "_content_1d84c4t_13",
5
+ "initial": "_initial_1d84c4t_52",
6
+ "outerThemeLight": "_outerThemeLight_1d84c4t_66",
7
+ "outerThemeDark": "_outerThemeDark_1d84c4t_79",
8
+ "trigger": "_trigger_1d84c4t_111"
8
9
  };
9
10
  export { styles as default };
package/lib/tooltip.js CHANGED
@@ -4,8 +4,8 @@ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
4
4
  import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
5
  import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
6
6
  import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
7
- import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
8
7
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
8
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
9
9
  import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
10
10
 
11
11
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -17,15 +17,16 @@ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/ins
17
17
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
18
18
  import "core-js/modules/es.object.to-string.js";
19
19
  import "core-js/modules/web.dom-collections.for-each.js";
20
- import React, { useState, useRef, useEffect, useCallback, cloneElement, createElement, isValidElement } from 'react';
20
+ import React, { useEffect, cloneElement, createElement, useState, useRef, useCallback, useContext, isValidElement } from 'react';
21
21
  import { Element, ForwardRef, typeOf } from 'react-is';
22
22
  import cn from 'classnames';
23
23
  import PropTypes from 'prop-types';
24
24
  import ReactDOM from 'react-dom';
25
25
  import { Manager, Reference, Popper } from 'react-popper';
26
- import { LayeringConsumer } from '@rescui/ui-contexts';
26
+ import { ThemeContext, LayeringConsumer, ThemeProvider } from '@rescui/ui-contexts';
27
27
  import styles from './index.p.module.css.js';
28
28
  import { useTooltipState, TOOLTIP_STATES } from './use-tooltip-state.js';
29
+ import { extractThemeFromCss, extractPrimaryColors } from './css-vars-utils.js';
29
30
  var HIDE_TIMEOUT = 500; // it should in sync with the transition-duration css-property
30
31
 
31
32
  var CLOSING_TIMEOUT = 300;
@@ -59,32 +60,90 @@ var isNode = function isNode(maybeNode) {
59
60
  }
60
61
  };
61
62
 
62
- var Tooltip = function Tooltip(_ref2) {
63
- var children = _ref2.children,
64
- _ref2$targetComponent = _ref2.targetComponent,
65
- targetComponent = _ref2$targetComponent === void 0 ? 'span' : _ref2$targetComponent,
66
- content = _ref2.content,
67
- className = _ref2.className,
68
- isVisibleFromProps = _ref2.isVisible,
69
- modifiers = _ref2.modifiers,
70
- _ref2$placement = _ref2.placement,
71
- placement = _ref2$placement === void 0 ? 'auto' : _ref2$placement,
72
- _ref2$sparse = _ref2.sparse,
73
- sparse = _ref2$sparse === void 0 ? true : _ref2$sparse,
74
- _ref2$fallbackPlaceme = _ref2.fallbackPlacements,
75
- fallbackPlacements = _ref2$fallbackPlaceme === void 0 ? ['top', 'bottom'] : _ref2$fallbackPlaceme,
76
- disableHideDelay = _ref2.disableHideDelay;
77
- var isControlled = typeof isVisibleFromProps !== 'undefined';
63
+ var OUTER_THEME_STYLES = {
64
+ light: styles.outerThemeLight,
65
+ dark: styles.outerThemeDark
66
+ };
67
+ var TriggerRenderer = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
68
+ var _context;
69
+
70
+ var triggerRef = _ref2.triggerRef,
71
+ setTriggerRef = _ref2.setTriggerRef,
72
+ targetComponent = _ref2.targetComponent,
73
+ isControlled = _ref2.isControlled,
74
+ handleMouseEnterTarget = _ref2.handleMouseEnterTarget,
75
+ handleMouseLeaveTarget = _ref2.handleMouseLeaveTarget,
76
+ children = _ref2.children;
77
+ var eventListeners = !isControlled ? {
78
+ onMouseEnter: handleMouseEnterTarget,
79
+ onMouseLeave: handleMouseLeaveTarget,
80
+ onFocus: handleMouseEnterTarget,
81
+ onBlur: handleMouseLeaveTarget,
82
+ tabIndex: 0
83
+ } : {};
84
+ useEffect(function () {
85
+ if (!ref) return;
86
+
87
+ if (typeof ref === 'function') {
88
+ ref(triggerRef);
89
+ } else {
90
+ ref.current = triggerRef;
91
+ }
92
+ }, [ref, triggerRef]);
93
+
94
+ var tooltipTargetProps = _Object$assign({}, {
95
+ ref: setTriggerRef
96
+ }, eventListeners);
97
+
98
+ if (typeof children === 'function') {
99
+ return children({
100
+ targetProps: tooltipTargetProps
101
+ });
102
+ } else if (_includesInstanceProperty(_context = [Element, ForwardRef]).call(_context, typeOf(children))) {
103
+ return /*#__PURE__*/cloneElement(children, _objectSpread({
104
+ className: cn(styles.trigger, children.props.className)
105
+ }, tooltipTargetProps));
106
+ } // create trigger-wrapper to bind tooltip
107
+
78
108
 
79
- var _useState = useState(false),
109
+ return /*#__PURE__*/createElement(targetComponent, _objectSpread({
110
+ className: styles.trigger
111
+ }, tooltipTargetProps), children);
112
+ });
113
+ TriggerRenderer.displayName = 'TriggerRenderer';
114
+
115
+ var Tooltip = function Tooltip(_ref3) {
116
+ var children = _ref3.children,
117
+ _ref3$targetComponent = _ref3.targetComponent,
118
+ targetComponent = _ref3$targetComponent === void 0 ? 'span' : _ref3$targetComponent,
119
+ content = _ref3.content,
120
+ className = _ref3.className,
121
+ isVisibleFromProps = _ref3.isVisible,
122
+ modifiers = _ref3.modifiers,
123
+ _ref3$placement = _ref3.placement,
124
+ placement = _ref3$placement === void 0 ? 'auto' : _ref3$placement,
125
+ _ref3$sparse = _ref3.sparse,
126
+ sparse = _ref3$sparse === void 0 ? true : _ref3$sparse,
127
+ _ref3$fallbackPlaceme = _ref3.fallbackPlacements,
128
+ fallbackPlacements = _ref3$fallbackPlaceme === void 0 ? ['top', 'bottom'] : _ref3$fallbackPlaceme,
129
+ disableHideDelay = _ref3.disableHideDelay;
130
+
131
+ var _useState = useState(null),
80
132
  _useState2 = _slicedToArray(_useState, 2),
81
- isVisibleState = _useState2[0],
82
- setIsVisibleState = _useState2[1];
133
+ triggerRef = _useState2[0],
134
+ setTriggerRef = _useState2[1];
135
+
136
+ var isControlled = typeof isVisibleFromProps !== 'undefined';
83
137
 
84
138
  var _useState3 = useState(false),
85
139
  _useState4 = _slicedToArray(_useState3, 2),
86
- isTooltipHovered = _useState4[0],
87
- setIsTooltipHovered = _useState4[1];
140
+ isVisibleState = _useState4[0],
141
+ setIsVisibleState = _useState4[1];
142
+
143
+ var _useState5 = useState(false),
144
+ _useState6 = _slicedToArray(_useState5, 2),
145
+ isTooltipHovered = _useState6[0],
146
+ setIsTooltipHovered = _useState6[1];
88
147
 
89
148
  var schedulePopperUpdateRef = useRef(null);
90
149
  var hideTimeoutRef = useRef(null);
@@ -119,10 +178,10 @@ var Tooltip = function Tooltip(_ref2) {
119
178
  var isClosing = tooltipState === TOOLTIP_STATES.CLOSING;
120
179
  var isExists = tooltipState !== TOOLTIP_STATES.CLOSED; // a state to toggle the starting transition
121
180
 
122
- var _useState5 = useState(true),
123
- _useState6 = _slicedToArray(_useState5, 2),
124
- isInitial = _useState6[0],
125
- setIsInitial = _useState6[1]; // reset the initial flag when the closing transition ends and the state switches to CLOSED
181
+ var _useState7 = useState(true),
182
+ _useState8 = _slicedToArray(_useState7, 2),
183
+ isInitial = _useState8[0],
184
+ setIsInitial = _useState8[1]; // reset the initial flag when the closing transition ends and the state switches to CLOSED
126
185
 
127
186
 
128
187
  useEffect(function () {
@@ -130,8 +189,8 @@ var Tooltip = function Tooltip(_ref2) {
130
189
  setIsInitial(true);
131
190
  }
132
191
  }, [isExists]);
133
- var disableInitialFlag = useCallback(function (_ref3) {
134
- var state = _ref3.state;
192
+ var disableInitialFlag = useCallback(function (_ref4) {
193
+ var state = _ref4.state;
135
194
  var el = state.elements.popper; // force layout phase
136
195
  // to make sure that the dom has registered the initial
137
196
  // styles with resolved placement (for `auto` placement)
@@ -139,41 +198,41 @@ var Tooltip = function Tooltip(_ref2) {
139
198
  el.getBoundingClientRect();
140
199
  setIsInitial(false);
141
200
  }, []);
142
- return /*#__PURE__*/React.createElement(LayeringConsumer, null, function (_ref4) {
201
+ var tooltipShouldBeRendered = isExists && isNode(content);
202
+ var primaryColors = {};
203
+ var themeFromCss = 'light';
204
+
205
+ if (triggerRef && tooltipShouldBeRendered) {
206
+ // In theory this part of the code might cause issues with SSR.
207
+ // But in this specific context, because of the nature of the state-ref "triggerRef",
208
+ // we are sure that the tooltip wouldn't be rendered on the first client render.
209
+ // Therefore, the first render on the client will be the same as on the server.
210
+ var triggerStyles = getComputedStyle(triggerRef);
211
+ themeFromCss = extractThemeFromCss(triggerStyles);
212
+ primaryColors = extractPrimaryColors(triggerStyles);
213
+ }
214
+
215
+ var _useContext = useContext(ThemeContext),
216
+ themeFromContext = _useContext.theme,
217
+ noProvider = _useContext.noProvider;
218
+
219
+ var theme = noProvider ? themeFromCss : themeFromContext;
220
+ return /*#__PURE__*/React.createElement(LayeringConsumer, null, function (_ref5) {
143
221
  var _context2;
144
222
 
145
- var tooltipZIndex = _ref4.tooltipZIndex;
146
- return /*#__PURE__*/React.createElement(Manager, null, /*#__PURE__*/React.createElement(Reference, null, function (_ref5) {
147
- var _context;
148
-
149
- var ref = _ref5.ref;
150
- var eventListeners = !isControlled ? {
151
- onMouseEnter: handleMouseEnterTarget,
152
- onMouseLeave: handleMouseLeaveTarget,
153
- onFocus: handleMouseEnterTarget,
154
- onBlur: handleMouseLeaveTarget,
155
- tabIndex: 0
156
- } : {};
157
-
158
- var tooltipTargetProps = _Object$assign({}, {
159
- ref: ref
160
- }, eventListeners);
161
-
162
- if (typeof children === 'function') {
163
- return children({
164
- targetProps: tooltipTargetProps
165
- });
166
- } else if (_includesInstanceProperty(_context = [Element, ForwardRef]).call(_context, typeOf(children))) {
167
- return /*#__PURE__*/cloneElement(children, _objectSpread({
168
- className: cn(styles.trigger, children.props.className)
169
- }, tooltipTargetProps));
170
- } // create trigger-wrapper to bind tooltip
171
-
172
-
173
- return /*#__PURE__*/createElement(targetComponent, _objectSpread({
174
- className: styles.trigger
175
- }, tooltipTargetProps), children);
176
- }), isExists && isNode(content) && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(Popper, {
223
+ var tooltipZIndex = _ref5.tooltipZIndex;
224
+ return /*#__PURE__*/React.createElement(Manager, null, /*#__PURE__*/React.createElement(Reference, null, function (_ref6) {
225
+ var ref = _ref6.ref;
226
+ return /*#__PURE__*/React.createElement(TriggerRenderer, {
227
+ ref: ref,
228
+ triggerRef: triggerRef,
229
+ setTriggerRef: setTriggerRef,
230
+ targetComponent: targetComponent,
231
+ isControlled: isControlled,
232
+ handleMouseEnterTarget: handleMouseEnterTarget,
233
+ handleMouseLeaveTarget: handleMouseLeaveTarget
234
+ }, children);
235
+ }), tooltipShouldBeRendered && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(Popper, {
177
236
  placement: placement,
178
237
  modifiers: _concatInstanceProperty(_context2 = [// the modifier to trigger starting animation
179
238
  {
@@ -190,8 +249,8 @@ var Tooltip = function Tooltip(_ref2) {
190
249
  }, {
191
250
  name: 'offset',
192
251
  options: {
193
- offset: function offset(_ref6) {
194
- var offsetPlacement = _ref6.placement;
252
+ offset: function offset(_ref7) {
253
+ var offsetPlacement = _ref7.placement;
195
254
 
196
255
  if (_includesInstanceProperty(offsetPlacement).call(offsetPlacement, 'left') || _includesInstanceProperty(offsetPlacement).call(offsetPlacement, 'right')) {
197
256
  return [0, sparse ? 16 : 8];
@@ -201,16 +260,16 @@ var Tooltip = function Tooltip(_ref2) {
201
260
  }
202
261
  }
203
262
  }]).call(_context2, _toConsumableArray(modifiers || []))
204
- }, function (_ref7) {
205
- var ref = _ref7.ref,
206
- style = _ref7.style,
207
- update = _ref7.update,
208
- realPlacement = _ref7.placement;
263
+ }, function (_ref8) {
264
+ var ref = _ref8.ref,
265
+ style = _ref8.style,
266
+ update = _ref8.update,
267
+ realPlacement = _ref8.placement;
209
268
  schedulePopperUpdateRef.current = update;
210
269
  return /*#__PURE__*/React.createElement("span", {
211
- className: cn(styles.tooltip, isInitial && styles.initial, isClosing && styles.closing, className),
270
+ className: cn(styles.tooltip, isInitial && styles.initial, isClosing && styles.closing, OUTER_THEME_STYLES[theme], className),
212
271
  ref: ref,
213
- style: _objectSpread(_objectSpread({}, style), {}, {
272
+ style: _objectSpread(_objectSpread(_objectSpread({}, style), primaryColors), {}, {
214
273
  zIndex: tooltipZIndex
215
274
  }),
216
275
  onMouseEnter: function onMouseEnter() {
@@ -223,9 +282,12 @@ var Tooltip = function Tooltip(_ref2) {
223
282
  "data-placement": placement,
224
283
  "data-real-placement": realPlacement,
225
284
  "data-test": "tooltip"
285
+ }, /*#__PURE__*/React.createElement(ThemeProvider, {
286
+ theme: "dark",
287
+ ignoreThemeValueForCSSApi: noProvider
226
288
  }, /*#__PURE__*/React.createElement("div", {
227
289
  className: cn(styles.content)
228
- }, content));
290
+ }, content)));
229
291
  })));
230
292
  });
231
293
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/tooltip",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -28,13 +28,13 @@
28
28
  "react-dom": ">=16.8.0 <19"
29
29
  },
30
30
  "devDependencies": {
31
- "@rescui/colors": "^0.1.11",
32
- "@rescui/scripts": "^0.2.3",
33
- "@rescui/typography": "^0.15.0",
31
+ "@rescui/colors": "^0.2.0",
32
+ "@rescui/scripts": "^0.3.0",
33
+ "@rescui/typography": "^0.16.0",
34
34
  "@types/react-is": "^17.0.3"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "rescui-scripts build"
38
38
  },
39
- "gitHead": "e21b6f80037993b094ceaff022db6d4cd176a88d"
39
+ "gitHead": "51da8a7188f4c558c563065a4ff4ef5c8e74994c"
40
40
  }