@quintoandar-tokko/tooltip 1.0.129

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/lib/index.js +134 -0
  3. package/package.json +21 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 One Loop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/index.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Tooltip = exports.ParentTooltip = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _core = require("@popperjs/core");
9
+ var _box = require("@quintoandar-tokko/box");
10
+ var _hooks = require("@quintoandar-tokko/hooks");
11
+ var _excluded = ["children", "setHover", "hover", "placement", "offset"],
12
+ _excluded2 = ["parentId", "childrenId", "variant", "txVariant", "placement", "offset", "arrow"];
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
15
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
17
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
18
+ var ParentTooltip = exports.ParentTooltip = function ParentTooltip(_ref) {
19
+ var children = _ref.children,
20
+ setHover = _ref.setHover,
21
+ hover = _ref.hover,
22
+ _ref$placement = _ref.placement,
23
+ placement = _ref$placement === void 0 ? 'right' : _ref$placement,
24
+ _ref$offset = _ref.offset,
25
+ offset = _ref$offset === void 0 ? 8 : _ref$offset,
26
+ props = _objectWithoutProperties(_ref, _excluded);
27
+ var styles = {
28
+ position: 'absolute',
29
+ width: offset + 'px'
30
+ };
31
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && document !== undefined && document.getElementById(props.id) !== null) {
32
+ var values = document.getElementById(props.id).getBoundingClientRect();
33
+ if (placement === 'right') {
34
+ styles = {
35
+ position: 'fixed',
36
+ width: offset + 'px',
37
+ height: values.height,
38
+ marginLeft: values.width
39
+ };
40
+ } else if (placement === 'bottom') {
41
+ styles = {
42
+ position: 'fixed',
43
+ width: values.width,
44
+ height: offset + 'px',
45
+ marginTop: values.width
46
+ };
47
+ } else if (placement === 'left') {
48
+ styles = {
49
+ position: 'fixed',
50
+ width: offset + 'px',
51
+ height: values.height,
52
+ marginLeft: -offset + 'px'
53
+ };
54
+ } else if (placement === 'top') {
55
+ styles = {
56
+ position: 'fixed',
57
+ width: values.width,
58
+ height: offset + 'px',
59
+ marginTop: -offset + 'px'
60
+ };
61
+ }
62
+ }
63
+ return /*#__PURE__*/_react["default"].createElement(_box.Box, {
64
+ sx: {
65
+ position: 'relative'
66
+ }
67
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({}, props, {
68
+ __css: {
69
+ display: 'flex',
70
+ width: 'fit-content'
71
+ }
72
+ }), children, hover && /*#__PURE__*/_react["default"].createElement("div", {
73
+ id: 'join' + props.id,
74
+ role: 'join' + props.id,
75
+ onMouseOut: function onMouseOut(e) {
76
+ return setHover((0, _hooks.isMouseOutJoin)(e, 'join' + props.id, placement));
77
+ },
78
+ style: styles
79
+ })));
80
+ };
81
+ var Tooltip = exports.Tooltip = function Tooltip(_ref2) {
82
+ var parentId = _ref2.parentId,
83
+ childrenId = _ref2.childrenId,
84
+ _ref2$variant = _ref2.variant,
85
+ variant = _ref2$variant === void 0 ? 'tooltip' : _ref2$variant,
86
+ _ref2$txVariant = _ref2.txVariant,
87
+ txVariant = _ref2$txVariant === void 0 ? 'arrowTooltip' : _ref2$txVariant,
88
+ _ref2$placement = _ref2.placement,
89
+ placement = _ref2$placement === void 0 ? 'right' : _ref2$placement,
90
+ _ref2$offset = _ref2.offset,
91
+ offset = _ref2$offset === void 0 ? 8 : _ref2$offset,
92
+ arrow = _ref2.arrow,
93
+ props = _objectWithoutProperties(_ref2, _excluded2);
94
+ var popcorn = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && document !== undefined ? document.querySelector('#' + parentId) : null;
95
+ var tooltip = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && document !== undefined ? document.querySelector('#' + childrenId) : null;
96
+ if (popcorn != null && tooltip != null) {
97
+ (0, _core.createPopper)(popcorn, tooltip, {
98
+ placement: placement,
99
+ modifiers: [{
100
+ name: 'offset',
101
+ options: {
102
+ offset: [0, offset]
103
+ }
104
+ }]
105
+ });
106
+ }
107
+ return /*#__PURE__*/_react["default"].createElement(_box.Box, {
108
+ sx: {
109
+ position: 'relative'
110
+ }
111
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({
112
+ tx: "panelTooltip",
113
+ variant: variant
114
+ }, props, {
115
+ __css: {
116
+ appearance: 'none',
117
+ display: 'flex',
118
+ alignItems: 'flex-start',
119
+ border: 'none',
120
+ fontFamily: 'Nunito Sans',
121
+ justifyContent: 'center'
122
+ }
123
+ })), arrow && /*#__PURE__*/_react["default"].createElement(_box.Box, {
124
+ tx: txVariant,
125
+ variant: placement,
126
+ id: "arrow",
127
+ __css: {
128
+ position: 'absolute',
129
+ background: 'inherit',
130
+ transform: 'translate(-50%)'
131
+ },
132
+ "data-popper-arrow": true
133
+ }));
134
+ };
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@quintoandar-tokko/tooltip",
3
+ "version": "1.0.129",
4
+ "main": "lib/index.js",
5
+ "module": "src/index.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "dependencies": {
10
+ "@popperjs/core": "^2.11.5",
11
+ "@quintoandar-tokko/box": "^1.2.286",
12
+ "prop-types": "^15.7.2"
13
+ },
14
+ "peerDependencies": {
15
+ "react": "^16.8.0"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "gitHead": "d33e426a17c29e62c8ea591ae6afa96300d55ad9"
21
+ }