visits-style 1.2.1 → 1.3.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.
- package/dist/components/Popover/index.d.ts +1 -1
- package/dist/components/Tooltip/index.d.ts +1 -1
- package/dist/visits-style.cjs.development.js +45 -93
- package/dist/visits-style.cjs.development.js.map +1 -1
- package/dist/visits-style.cjs.production.min.js +1 -1
- package/dist/visits-style.cjs.production.min.js.map +1 -1
- package/dist/visits-style.esm.js +46 -94
- package/dist/visits-style.esm.js.map +1 -1
- package/package.json +9 -7
- package/dist/hooks/usePopper.d.ts +0 -12
package/dist/visits-style.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { forwardRef, useLayoutEffect, useEffect, useRef, useMemo, useImperativeHandle, useState,
|
|
1
|
+
import React, { forwardRef, useLayoutEffect, useEffect, useRef, useMemo, useImperativeHandle, useState, cloneElement, Children, useCallback } from 'react';
|
|
2
2
|
import styled, { css, keyframes } from 'styled-components';
|
|
3
3
|
import { getLuminance, transparentize, darken } from 'polished';
|
|
4
|
+
import { useFloating, shift, flip, offset, autoUpdate } from '@floating-ui/react-dom';
|
|
4
5
|
import { createPortal } from 'react-dom';
|
|
5
|
-
import { createPopper } from '@popperjs/core';
|
|
6
6
|
import { Transition, TransitionGroup } from 'react-transition-group';
|
|
7
7
|
|
|
8
8
|
function _defineProperty(obj, key, value) {
|
|
@@ -1186,66 +1186,6 @@ React.forwardRef(function (_ref, ref) {
|
|
|
1186
1186
|
});
|
|
1187
1187
|
Portal.displayName = 'Portal';
|
|
1188
1188
|
|
|
1189
|
-
function usePopper(referenceElement, popperElement, options) {
|
|
1190
|
-
if (options === void 0) {
|
|
1191
|
-
options = {};
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
var instance = useRef(null);
|
|
1195
|
-
var popperOptions = useMemo(function () {
|
|
1196
|
-
return {
|
|
1197
|
-
placement: options.placement || 'bottom',
|
|
1198
|
-
strategy: options.strategy || 'absolute',
|
|
1199
|
-
modifiers: [{
|
|
1200
|
-
name: 'preventOverflow',
|
|
1201
|
-
enabled: true
|
|
1202
|
-
}, options.offset && {
|
|
1203
|
-
name: 'offset',
|
|
1204
|
-
options: {
|
|
1205
|
-
offset: [options.offset.x, options.offset.y]
|
|
1206
|
-
}
|
|
1207
|
-
}].filter(Boolean)
|
|
1208
|
-
};
|
|
1209
|
-
}, [options.placement, options.strategy, options.offset]);
|
|
1210
|
-
useIsomorphicLayoutEffect(function () {
|
|
1211
|
-
if (instance.current) {
|
|
1212
|
-
instance.current.setOptions(popperOptions);
|
|
1213
|
-
}
|
|
1214
|
-
}, [popperOptions]);
|
|
1215
|
-
useIsomorphicLayoutEffect(function () {
|
|
1216
|
-
return function () {
|
|
1217
|
-
if (instance.current) {
|
|
1218
|
-
instance.current.destroy();
|
|
1219
|
-
instance.current = null;
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1222
|
-
}, []);
|
|
1223
|
-
var open = useCallback(function () {
|
|
1224
|
-
if (instance.current) {
|
|
1225
|
-
instance.current.destroy();
|
|
1226
|
-
instance.current = null;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
if (referenceElement == null || popperElement == null) {
|
|
1230
|
-
return;
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
var refEl = // @ts-ignore
|
|
1234
|
-
'current' in referenceElement ? referenceElement.current : referenceElement; // @ts-ignore
|
|
1235
|
-
|
|
1236
|
-
var pEl = 'current' in popperElement ? popperElement.current : popperElement;
|
|
1237
|
-
if (refEl === null || pEl === null) return;
|
|
1238
|
-
instance.current = createPopper(refEl, pEl, popperOptions); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1239
|
-
}, [popperOptions]);
|
|
1240
|
-
var close = useCallback(function () {
|
|
1241
|
-
if (instance.current) {
|
|
1242
|
-
instance.current.destroy();
|
|
1243
|
-
instance.current = null;
|
|
1244
|
-
}
|
|
1245
|
-
}, []);
|
|
1246
|
-
return [open, close];
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
1189
|
function wrapEvent(child, handlerName, ourHandler) {
|
|
1250
1190
|
return function (event) {
|
|
1251
1191
|
if (typeof child !== 'string' && child.props[handlerName]) {
|
|
@@ -1268,34 +1208,36 @@ function Tooltip(_ref) {
|
|
|
1268
1208
|
_ref$className = _ref.className,
|
|
1269
1209
|
className = _ref$className === void 0 ? '' : _ref$className,
|
|
1270
1210
|
_ref$offset = _ref.offset,
|
|
1271
|
-
offset = _ref$offset === void 0 ? {
|
|
1211
|
+
offset$1 = _ref$offset === void 0 ? {
|
|
1272
1212
|
x: 0,
|
|
1273
1213
|
y: 6
|
|
1274
1214
|
} : _ref$offset;
|
|
1275
|
-
|
|
1276
|
-
var
|
|
1215
|
+
|
|
1216
|
+
var _useFloating = useFloating({
|
|
1217
|
+
placement: position,
|
|
1218
|
+
middleware: [shift(), flip(), offset({
|
|
1219
|
+
mainAxis: offset$1.y,
|
|
1220
|
+
crossAxis: offset$1.x
|
|
1221
|
+
})],
|
|
1222
|
+
whileElementsMounted: autoUpdate
|
|
1223
|
+
}),
|
|
1224
|
+
reference = _useFloating.reference,
|
|
1225
|
+
floating = _useFloating.floating,
|
|
1226
|
+
strategy = _useFloating.strategy,
|
|
1227
|
+
x = _useFloating.x,
|
|
1228
|
+
y = _useFloating.y;
|
|
1277
1229
|
|
|
1278
1230
|
var _useState = useState(false),
|
|
1279
1231
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1280
1232
|
open = _useState2[0],
|
|
1281
1233
|
setOpen = _useState2[1];
|
|
1282
1234
|
|
|
1283
|
-
var _usePopper = usePopper(parent, tooltip, {
|
|
1284
|
-
placement: position,
|
|
1285
|
-
offset: offset
|
|
1286
|
-
}),
|
|
1287
|
-
_usePopper2 = _slicedToArray(_usePopper, 2),
|
|
1288
|
-
openPopper = _usePopper2[0],
|
|
1289
|
-
closePopper = _usePopper2[1];
|
|
1290
|
-
|
|
1291
1235
|
var handleOpen = function handleOpen() {
|
|
1292
1236
|
setOpen(true);
|
|
1293
|
-
requestAnimationFrame(openPopper);
|
|
1294
1237
|
};
|
|
1295
1238
|
|
|
1296
1239
|
var handleClose = function handleClose() {
|
|
1297
1240
|
setOpen(false);
|
|
1298
|
-
closePopper();
|
|
1299
1241
|
};
|
|
1300
1242
|
|
|
1301
1243
|
var child = typeof children === 'string' ?
|
|
@@ -1306,7 +1248,7 @@ function Tooltip(_ref) {
|
|
|
1306
1248
|
React.createElement(React.Fragment, null,
|
|
1307
1249
|
/*#__PURE__*/
|
|
1308
1250
|
cloneElement(Children.only(child), {
|
|
1309
|
-
ref:
|
|
1251
|
+
ref: reference,
|
|
1310
1252
|
onMouseEnter: wrapEvent(child, 'onMouseEnter', handleOpen),
|
|
1311
1253
|
onMouseLeave: wrapEvent(child, 'onMouseLeave', handleClose),
|
|
1312
1254
|
onFocus: wrapEvent(child, 'onFocus', handleOpen),
|
|
@@ -1317,9 +1259,14 @@ function Tooltip(_ref) {
|
|
|
1317
1259
|
/*#__PURE__*/
|
|
1318
1260
|
React.createElement(TooltipWrapper, {
|
|
1319
1261
|
className: className,
|
|
1320
|
-
ref:
|
|
1262
|
+
ref: floating,
|
|
1321
1263
|
role: "tooltip",
|
|
1322
|
-
color: color
|
|
1264
|
+
color: color,
|
|
1265
|
+
style: {
|
|
1266
|
+
position: strategy,
|
|
1267
|
+
top: y || 0,
|
|
1268
|
+
left: x || 0
|
|
1269
|
+
}
|
|
1323
1270
|
}, label)))
|
|
1324
1271
|
);
|
|
1325
1272
|
}
|
|
@@ -1472,48 +1419,48 @@ forwardRef(function (_ref, ref) {
|
|
|
1472
1419
|
_ref$className = _ref.className,
|
|
1473
1420
|
className = _ref$className === void 0 ? '' : _ref$className,
|
|
1474
1421
|
_ref$offset = _ref.offset,
|
|
1475
|
-
offset = _ref$offset === void 0 ? {
|
|
1422
|
+
offset$1 = _ref$offset === void 0 ? {
|
|
1476
1423
|
x: 0,
|
|
1477
1424
|
y: 6
|
|
1478
1425
|
} : _ref$offset,
|
|
1479
1426
|
rest = _objectWithoutProperties(_ref, _excluded$a);
|
|
1480
1427
|
|
|
1481
|
-
var parent = useRef(null);
|
|
1482
|
-
var popover = useRef(null);
|
|
1483
|
-
|
|
1484
1428
|
var _useState = useState(false),
|
|
1485
1429
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1486
1430
|
open = _useState2[0],
|
|
1487
1431
|
setOpen = _useState2[1];
|
|
1488
1432
|
|
|
1489
|
-
var
|
|
1433
|
+
var _useFloating = useFloating({
|
|
1490
1434
|
placement: position,
|
|
1491
|
-
|
|
1435
|
+
middleware: [shift(), flip(), offset({
|
|
1436
|
+
mainAxis: offset$1.y,
|
|
1437
|
+
crossAxis: offset$1.x
|
|
1438
|
+
})],
|
|
1439
|
+
whileElementsMounted: autoUpdate
|
|
1492
1440
|
}),
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1441
|
+
reference = _useFloating.reference,
|
|
1442
|
+
floating = _useFloating.floating,
|
|
1443
|
+
strategy = _useFloating.strategy,
|
|
1444
|
+
x = _useFloating.x,
|
|
1445
|
+
y = _useFloating.y;
|
|
1496
1446
|
|
|
1497
1447
|
var handleFocus = function handleFocus(e) {
|
|
1498
1448
|
stopPropagation(e);
|
|
1499
1449
|
setOpen(true);
|
|
1500
|
-
requestAnimationFrame(openPopper);
|
|
1501
1450
|
if (onOpen) onOpen();
|
|
1502
1451
|
};
|
|
1503
1452
|
|
|
1504
1453
|
var handleBlur = function handleBlur(e) {
|
|
1505
1454
|
stopPropagation(e);
|
|
1506
|
-
closePopper();
|
|
1507
1455
|
setOpen(false);
|
|
1508
1456
|
if (onClose) onClose();
|
|
1509
1457
|
};
|
|
1510
1458
|
|
|
1511
1459
|
useEffect(function () {
|
|
1512
1460
|
if (disabled && open) {
|
|
1513
|
-
closePopper();
|
|
1514
1461
|
setOpen(false);
|
|
1515
1462
|
}
|
|
1516
|
-
}, [disabled, open
|
|
1463
|
+
}, [disabled, open]);
|
|
1517
1464
|
useImperativeHandle(ref, function () {
|
|
1518
1465
|
return {
|
|
1519
1466
|
open: handleFocus,
|
|
@@ -1525,7 +1472,7 @@ forwardRef(function (_ref, ref) {
|
|
|
1525
1472
|
React.createElement(React.Fragment, null,
|
|
1526
1473
|
/*#__PURE__*/
|
|
1527
1474
|
cloneElement(Children.only(label), {
|
|
1528
|
-
ref:
|
|
1475
|
+
ref: reference,
|
|
1529
1476
|
tabIndex: 0,
|
|
1530
1477
|
role: 'button',
|
|
1531
1478
|
onClick: wrapEvent(label, 'onClick', handleFocus),
|
|
@@ -1537,9 +1484,14 @@ forwardRef(function (_ref, ref) {
|
|
|
1537
1484
|
React.createElement(Tooltip$1, Object.assign({
|
|
1538
1485
|
role: "tooltip",
|
|
1539
1486
|
className: className,
|
|
1540
|
-
ref:
|
|
1487
|
+
ref: floating,
|
|
1541
1488
|
color: color,
|
|
1542
|
-
onClick: stopPropagation
|
|
1489
|
+
onClick: stopPropagation,
|
|
1490
|
+
style: {
|
|
1491
|
+
position: strategy,
|
|
1492
|
+
top: y || 0,
|
|
1493
|
+
left: x || 0
|
|
1494
|
+
}
|
|
1543
1495
|
}, rest), children),
|
|
1544
1496
|
/*#__PURE__*/
|
|
1545
1497
|
React.createElement(Shadow, {
|