@splunk/react-ui 5.0.0-rc.2 → 5.0.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/Popover.js CHANGED
@@ -1125,76 +1125,77 @@
1125
1125
  * `Dropdown` covers use cases where you might consider using `Popover` directly.
1126
1126
  */ function tt(e) {
1127
1127
  var t, o;
1128
- var a = e.align, i = a === void 0 ? "center" : a, l = e.anchor, c = e.animation, f = c === void 0 ? true : c, s = e.animationConfig, p = s === void 0 ? et : s, v = e.appearance, d = v === void 0 ? "normal" : v, m = e.autoCloseWhenOffScreen, b = m === void 0 ? true : m, y = e.canCoverAnchor, w = e.children, O = e.closeReasons, C = O === void 0 ? Ke : O, x = e.defaultPlacement, k = x === void 0 ? "below" : x, R = e.elementRef, q = e.hideArrow, H = e.hitAreaRef, I = e.id, L = e.onRequestClose, D = e.open, F = e.outerRef, $ = e.pointTo, N = e.repositionMode, V = N === void 0 ? "flip" : N, z = e.retainFocus, K = z === void 0 ? true : z, Y = e.takeFocus, Q = Ve(e, [ "align", "anchor", "animation", "animationConfig", "appearance", "autoCloseWhenOffScreen", "canCoverAnchor", "children", "closeReasons", "defaultPlacement", "elementRef", "hideArrow", "hitAreaRef", "id", "onRequestClose", "open", "outerRef", "pointTo", "repositionMode", "retainFocus", "takeFocus" ]);
1128
+ var a = e.align, i = a === void 0 ? "center" : a, l = e.anchor, c = e.animation, f = c === void 0 ? true : c, s = e.animationConfig, p = s === void 0 ? et : s, v = e.appearance, d = v === void 0 ? "normal" : v, m = e.autoCloseWhenOffScreen, b = m === void 0 ? true : m, y = e.canCoverAnchor, w = e.children, O = e.closeReasons, C = O === void 0 ? Ke : O, x = e.defaultPlacement, k = x === void 0 ? "below" : x, R = e.elementRef, q = e.hideArrow, H = e.hitAreaRef, I = e.id, L = e.onRequestClose, D = e.open, F = e.outerRef, $ = e.pointTo, N = e.repositionMode, V = N === void 0 ? "flip" : N, z = e.retainFocus, K = z === void 0 ? true : z, Y = e.takeFocus, Q = e.toggleId, Z = Ve(e, [ "align", "anchor", "animation", "animationConfig", "appearance", "autoCloseWhenOffScreen", "canCoverAnchor", "children", "closeReasons", "defaultPlacement", "elementRef", "hideArrow", "hitAreaRef", "id", "onRequestClose", "open", "outerRef", "pointTo", "repositionMode", "retainFocus", "takeFocus", "toggleId" ]);
1129
1129
  // @docs-props-type PopoverPropsBase
1130
1130
  if (false) {}
1131
- var Z = (0, r.useState)(D), ee = Le(Z, 2), te = ee[0], re = ee[1];
1132
- var ne = (0, r.useState)(false), oe = Le(ne, 2), ae = oe[0], ie = oe[1];
1133
- if (D !== ae) {
1131
+ var ee = (0, r.useState)(D), te = Le(ee, 2), re = te[0], ne = te[1];
1132
+ var oe = (0, r.useState)(false), ae = Le(oe, 2), ie = ae[0], le = ae[1];
1133
+ if (D !== ie) {
1134
1134
  // formerly implemented by componentWillReceiveProps
1135
1135
  // we can't use prevOpen here since that's a ref behind the scenes
1136
1136
  // and won't get updated until the component re-renders successfully
1137
1137
  // whereas setAnimating will interrupt the re-render and we'll end up in an infinite loop
1138
1138
  // so we need to update the value of wasOpen at the same time
1139
- re(f);
1140
- ie(D);
1139
+ ne(f);
1140
+ le(D);
1141
1141
  }
1142
1142
  // this is a single state object because all these properties
1143
1143
  // are updated at the same time by setPlacement
1144
- var le = (0, r.useState)({}), fe = Le(le, 2), se = fe[0], pe = fe[1];
1145
- var ve = (0, r.useRef)(true);
1146
- var de = (0, r.useRef)(false);
1147
- var he = (0, r.useRef)(null);
1144
+ var fe = (0, r.useState)({}), se = Le(fe, 2), pe = se[0], ve = se[1];
1145
+ var de = (0, r.useRef)(true);
1146
+ var he = (0, r.useRef)(false);
1148
1147
  var me = (0, r.useRef)(null);
1149
1148
  var ye = (0, r.useRef)(null);
1150
- var ge = {
1151
- anchorHeight: ((t = se.anchorPos) === null || t === void 0 ? void 0 : t.height) || null,
1152
- anchorWidth: ((o = se.anchorPos) === null || o === void 0 ? void 0 : o.width) || null,
1153
- placement: se.placement || null,
1154
- maxHeight: Ze(se.maxHeight, d),
1155
- maxWidth: Ze(se.maxWidth, d)
1149
+ var ge = (0, r.useRef)(null);
1150
+ var we = {
1151
+ anchorHeight: ((t = pe.anchorPos) === null || t === void 0 ? void 0 : t.height) || null,
1152
+ anchorWidth: ((o = pe.anchorPos) === null || o === void 0 ? void 0 : o.width) || null,
1153
+ placement: pe.placement || null,
1154
+ maxHeight: Ze(pe.maxHeight, d),
1155
+ maxWidth: Ze(pe.maxWidth, d),
1156
+ toggleId: Q
1156
1157
  };
1157
- var we = (0, r.useMemo)((function() {
1158
+ var Se = (0, r.useMemo)((function() {
1158
1159
  return f ? {
1159
1160
  opacity: D ? 1 : 0
1160
1161
  } : {
1161
1162
  opacity: 1
1162
1163
  };
1163
1164
  }), [ f, D ]);
1164
- var Se = be();
1165
- var Oe = D || te;
1166
- var Pe = (0, r.useContext)(T()) || Se;
1167
- var je = Pe !== Se;
1168
- var Ce = (0, r.useContext)(ue), Ee = Ce.hideArrow;
1169
- var xe = q !== null && q !== void 0 ? q : Ee;
1165
+ var Oe = be();
1166
+ var Pe = D || re;
1167
+ var je = (0, r.useContext)(T()) || Oe;
1168
+ var Ce = je !== Oe;
1169
+ var Ee = (0, r.useContext)(ue), xe = Ee.hideArrow;
1170
+ var Ae = q !== null && q !== void 0 ? q : xe;
1170
1171
  (0, r.useEffect)((function() {
1171
1172
  if (false) {}
1172
1173
  }), [ l ]);
1173
- var Ae = (0, r.useCallback)((function(e) {
1174
+ var Te = (0, r.useCallback)((function(e) {
1174
1175
  if (D && (C === null || C === void 0 ? void 0 : C.includes(e.reason))) {
1175
1176
  L === null || L === void 0 ? void 0 : L(e);
1176
1177
  }
1177
1178
  }), [ C, D, L ]);
1178
- var Te = (0, r.useCallback)((function(e, t) {
1179
+ var Me = (0, r.useCallback)((function(e, t) {
1179
1180
  var r = Qe(e, t);
1180
1181
  if (r) {
1181
- Ae({
1182
+ Te({
1182
1183
  reason: "offScreen"
1183
1184
  });
1184
1185
  }
1185
1186
  return r;
1186
- }), [ Ae ]);
1187
- var Me = M()(), qe = Me.borderRadius, He = Me.spacingXSmall;
1188
- var Ie = parseInt(qe, 10);
1187
+ }), [ Te ]);
1188
+ var qe = M()(), He = qe.borderRadius, Ie = qe.spacingXSmall;
1189
1189
  var De = parseInt(He, 10);
1190
+ var Fe = parseInt(Ie, 10);
1190
1191
  // this is intentionally smaller when the arrow is hidden to address SUI-5452
1191
- var Fe = xe ? De : X;
1192
+ var $e = Ae ? Fe : X;
1192
1193
  // do not call this directly - use setPlacement (the throttled version) instead
1193
- var $e = (0, r.useCallback)((function(e) {
1194
- pe((function(t) {
1194
+ var _e = (0, r.useCallback)((function(e) {
1195
+ ve((function(t) {
1195
1196
  var r, n;
1196
1197
  // If these conditions are not met, we cannot set the popover.
1197
- if (!D || !ye.current || !l) {
1198
+ if (!D || !ge.current || !l) {
1198
1199
  // if (__DEV__ && !anchor && open) {
1199
1200
  // throw new Error(`Invalid anchor ${anchor} provided to Popover.`);
1200
1201
  // }
@@ -1209,12 +1210,12 @@
1209
1210
  offsets: true,
1210
1211
  pointTo: $
1211
1212
  });
1212
- var c = Je(Pe) ? Ge({
1213
- anchorEl: Pe,
1213
+ var c = Je(je) ? Ge({
1214
+ anchorEl: je,
1214
1215
  pointTo: $
1215
1216
  }) : undefined;
1216
1217
  if (e && b) {
1217
- if (Te(o, c)) {
1218
+ if (Me(o, c)) {
1218
1219
  return t;
1219
1220
  }
1220
1221
  }
@@ -1225,22 +1226,22 @@
1225
1226
  canCoverAnchor: y,
1226
1227
  defaultPlacement: k,
1227
1228
  repositionMode: V,
1228
- outerContainerEl: ye.current,
1229
- padding: Fe,
1230
- windowWidth: Se.innerWidth,
1231
- windowHeight: Se.innerHeight
1229
+ outerContainerEl: ge.current,
1230
+ padding: $e,
1231
+ windowWidth: Oe.innerWidth,
1232
+ windowHeight: Oe.innerHeight
1232
1233
  }), f = u.placement, s = u.outerContainerStyle, p = u.maxHeight, v = u.maxWidth;
1233
1234
  var d = Ye(a, t.anchorPos) && Ye(s, t.outerContainerStyle) && f === t.placement && p === t.maxHeight && v === t.maxWidth;
1234
1235
  var h = true;
1235
1236
  var m = {};
1236
1237
  var g;
1237
- if (he.current) {
1238
+ if (me.current) {
1238
1239
  var w = Ue({
1239
1240
  anchorPos: a,
1240
- borderRadius: Ie,
1241
+ borderRadius: De,
1241
1242
  outerContainerStyle: s,
1242
1243
  placement: f,
1243
- outerContainerEl: ye.current
1244
+ outerContainerEl: ge.current
1244
1245
  });
1245
1246
  var O = Le(w, 2);
1246
1247
  m = O[0];
@@ -1261,93 +1262,95 @@
1261
1262
  maxWidth: v
1262
1263
  };
1263
1264
  }));
1264
- }), [ i, l, b, Ie, Fe, y, Te, k, D, $, V, Pe, Se.innerHeight, Se.innerWidth ]);
1265
+ }), [ i, l, b, De, $e, y, Me, k, D, $, V, je, Oe.innerHeight, Oe.innerWidth ]);
1265
1266
  // these are useMemo rather than useCallback so that ESLint can correctly analyze the dependencies
1266
1267
  // see https://github.com/facebook/react/issues/19240#issuecomment-652945246
1267
- var _e = (0, r.useMemo)((function() {
1268
- return P()($e.bind(null, true), 0);
1269
- }), [ $e ]);
1270
- var Ne = (0, r.useMemo)((function() {
1271
- return P()($e.bind(null, true), 0);
1272
- }), [ $e ]);
1268
+ var Ne = (0, r.useMemo)((function() {
1269
+ return P()(_e.bind(null, true), 0);
1270
+ }), [ _e ]);
1273
1271
  var ze = (0, r.useMemo)((function() {
1274
- return P()($e, 0, {
1272
+ return P()(_e.bind(null, true), 0);
1273
+ }), [ _e ]);
1274
+ var Xe = (0, r.useMemo)((function() {
1275
+ return P()(_e, 0, {
1275
1276
  leading: false
1276
1277
  });
1277
- }), [ $e ]);
1278
+ }), [ _e ]);
1278
1279
  // this needs to run on every render - equivalent to componentDidUpdate
1279
1280
  (0, r.useEffect)((function() {
1280
- if (!me.current) {
1281
+ if (!ye.current) {
1281
1282
  return;
1282
1283
  }
1283
- if (D || te) {
1284
- ze();
1284
+ if (D || re) {
1285
+ Xe();
1285
1286
  }
1286
1287
  }));
1287
1288
  (0, r.useEffect)((function() {
1288
- if (Y && D && me.current && se.placement != null && !de.current) {
1289
- de.current = true;
1290
- (0, W.takeFocus)(me.current);
1289
+ if (Y && D && ye.current && pe.placement != null && !he.current) {
1290
+ he.current = true;
1291
+ (0, W.takeFocus)(ye.current);
1291
1292
  }
1292
- }), [ D, se.placement, Y ]);
1293
- // it is not part of the previous useEffect because it needs to be equivalent to componentWillUnmount
1294
- (0, r.useEffect)((function() {
1293
+ }), [ D, pe.placement, Y ]);
1294
+ (0, r.useEffect)((function() {
1295
+ // we need to set this to true on every mount because React.StrictMode will call the effect twice
1296
+ // and we need to ensure that allowAnimationUpdates is true while the component is mounted
1297
+ de.current = true;
1295
1298
  return function() {
1296
- ze.cancel();
1297
- _e.cancel();
1299
+ Xe.cancel();
1298
1300
  Ne.cancel();
1299
- ve.current = false;
1301
+ ze.cancel();
1302
+ de.current = false;
1300
1303
  };
1301
- // no dependencies here since this needs to set up a cleanup function exactly once
1304
+ // no dependencies here since this is equivalent to componentDidMount and componentWillUnmount
1302
1305
  // eslint-disable-next-line react-hooks/exhaustive-deps
1303
1306
  }), []);
1304
1307
  // EventListeners only need to be rendered when open,
1305
1308
  // otherwise leads to negative performance impacts
1306
- var Xe = Oe ? n().createElement(n().Fragment, null, je && n().createElement(E(), {
1307
- target: Pe,
1309
+ var tt = Pe ? n().createElement(n().Fragment, null, Ce && n().createElement(E(), {
1310
+ target: je,
1308
1311
  eventType: "scroll",
1309
- listener: _e,
1312
+ listener: Ne,
1310
1313
  options: Be,
1311
1314
  key: "eventListener"
1312
1315
  }), n().createElement(E(), {
1313
- target: Se,
1316
+ target: Oe,
1314
1317
  eventType: "resize",
1315
- listener: ze,
1318
+ listener: Xe,
1316
1319
  key: "eventListenerOnWindowResize"
1317
1320
  }), n().createElement(E(), {
1318
- target: Se,
1321
+ target: Oe,
1319
1322
  eventType: "scroll",
1320
- listener: Ne,
1323
+ listener: ze,
1321
1324
  options: Be,
1322
1325
  key: "eventListenerOnWindowScroll"
1323
1326
  })) : null;
1324
- var tt = (0, r.useCallback)((function() {
1327
+ var rt = (0, r.useCallback)((function() {
1325
1328
  // checking allowAnimationUpdates avoids trying to update state after the component has been unmounted - see SUI-3666
1326
- if (ve.current) {
1327
- re(false);
1329
+ if (de.current) {
1330
+ ne(false);
1328
1331
  }
1329
1332
  }), []);
1330
- var rt = (0, r.useCallback)((function(e) {
1331
- me.current = e;
1333
+ var nt = (0, r.useCallback)((function(e) {
1334
+ ye.current = e;
1332
1335
  if (e && Y) {
1333
1336
  u()(W.takeFocus, e);
1334
1337
  }
1335
1338
  ke(R, e);
1336
1339
  }), [ R, Y ]);
1337
- var nt = (0, r.useCallback)((function(e) {
1338
- ye.current = e;
1340
+ var ot = (0, r.useCallback)((function(e) {
1341
+ ge.current = e;
1339
1342
  ke(F, e);
1340
1343
  }), [ F ]);
1341
- var ot = (0, r.useCallback)((function(e) {
1342
- if (me.current) {
1344
+ var at = (0, r.useCallback)((function(e) {
1345
+ if (ye.current) {
1343
1346
  if (K) {
1344
- (0, W.handleTab)(me.current, e);
1347
+ (0, W.handleTab)(ye.current, e);
1345
1348
  } else if ((0, W.isTabKey)(e)) {
1346
- var t = (0, W.getSortedTabbableElements)(me.current);
1349
+ var t = (0, W.getSortedTabbableElements)(ye.current);
1347
1350
  if (t.length > 0) {
1348
1351
  var r = e.shiftKey ? t[0] : t[t.length - 1];
1349
1352
  if (r === e.target) {
1350
- Ae({
1353
+ Te({
1351
1354
  event: e,
1352
1355
  reason: "tabKey"
1353
1356
  });
@@ -1355,67 +1358,67 @@
1355
1358
  }
1356
1359
  }
1357
1360
  }
1358
- }), [ Ae, K ]);
1359
- var at = (0, r.useMemo)((function() {
1361
+ }), [ Te, K ]);
1362
+ var it = (0, r.useMemo)((function() {
1360
1363
  return {
1361
1364
  opacity: f ? 0 : 1
1362
1365
  };
1363
1366
  }), [ f ]);
1364
- var it = (0, r.useMemo)((function() {
1367
+ var lt = (0, r.useMemo)((function() {
1365
1368
  return We({
1366
1369
  tension: 300,
1367
1370
  friction: 20,
1368
1371
  clamp: true
1369
1372
  }, p);
1370
1373
  }), [ p ]);
1371
- var lt = (0, j.useAnimation)({
1372
- from: at,
1373
- to: we,
1374
+ var ct = (0, j.useAnimation)({
1375
+ from: it,
1376
+ to: Se,
1374
1377
  // Setting clamp to true will stop animating at the point it hit's it's goal value.
1375
1378
  // This will prevent click through while animating out (SUI-6618).
1376
- config: it,
1377
- onRest: tt
1379
+ config: lt,
1380
+ onRest: rt
1378
1381
  });
1379
- var ct = (0, r.useMemo)((function() {
1380
- return We(We({}, se.outerContainerStyle), lt);
1381
- }), [ se.outerContainerStyle, lt ]);
1382
1382
  var ut = (0, r.useMemo)((function() {
1383
+ return We(We({}, pe.outerContainerStyle), ct);
1384
+ }), [ pe.outerContainerStyle, ct ]);
1385
+ var ft = (0, r.useMemo)((function() {
1383
1386
  return h()(C === null || C === void 0 ? void 0 : C.filter((function(e) {
1384
1387
  return e !== "offScreen";
1385
1388
  })), A().possibleCloseReasons);
1386
1389
  }), [ C ]);
1387
- var ft = g()(w) ? w(ge) : w;
1390
+ var st = g()(w) ? w(we) : w;
1388
1391
 
1389
- return n().createElement(n().Fragment, null, Xe, n().createElement(A(), {
1390
- closeReasons: ut,
1391
- open: Oe,
1392
- onRequestClose: Ae,
1392
+ return n().createElement(n().Fragment, null, tt, n().createElement(A(), {
1393
+ closeReasons: ft,
1394
+ open: Pe,
1395
+ onRequestClose: Te,
1393
1396
  key: "Layer"
1394
- }, Oe && me.current && H && n().createElement(ce, {
1395
- anchorRect: se.anchorPos,
1396
- popoverEl: me.current,
1397
- popoverPlacement: se.placement,
1397
+ }, Pe && ye.current && H && n().createElement(ce, {
1398
+ anchorRect: pe.anchorPos,
1399
+ popoverEl: ye.current,
1400
+ popoverPlacement: pe.placement,
1398
1401
  ref: H
1399
- }), Oe && n().createElement(B, {
1402
+ }), Pe && n().createElement(B, {
1400
1403
  "data-test": "outer-popover",
1401
- style: ct,
1402
- ref: nt
1404
+ style: ut,
1405
+ ref: ot
1403
1406
  }, n().createElement(U, Re({
1404
1407
  $appearance: d,
1405
- $boxPadding: Fe,
1408
+ $boxPadding: $e,
1406
1409
  $open: D,
1407
1410
  "data-test": "popover",
1408
- ref: rt,
1411
+ ref: nt,
1409
1412
  id: I,
1410
- onKeyDown: ot
1411
- }, Q), n().createElement(n().Fragment, null, d === "none" && ft, d !== "none" && !xe && n().createElement(J, {
1413
+ onKeyDown: at
1414
+ }, Z), n().createElement(n().Fragment, null, d === "none" && st, d !== "none" && !Ae && n().createElement(J, {
1412
1415
  "data-test": "popover-arrow",
1413
1416
  $appearance: d,
1414
- ref: he,
1415
- style: se.arrowStyle
1417
+ ref: me,
1418
+ style: pe.arrowStyle
1416
1419
  }), d !== "none" && n().createElement(G, {
1417
1420
  $appearance: d
1418
- }, ft))))));
1421
+ }, st))))));
1419
1422
  }
1420
1423
  tt.propTypes = Xe;
1421
1424
  tt.possibleCloseReasons = Ke;
package/README.md CHANGED
@@ -8,7 +8,7 @@ Install the package and its dependencies.
8
8
 
9
9
  1. Install the peer dependencies:
10
10
  ```bash
11
- npm install react@^16 react-dom@^16 styled-components@^5
11
+ npm install react@^18 react-dom@^18 styled-components@^5
12
12
  ```
13
13
  2. Install the package:
14
14
  ```bash
@@ -74,7 +74,7 @@ It is strongly recommended to include only one instance of `@splunk/react-ui` in
74
74
  using multiple instances of this library on the same page is discouraged.
75
75
 
76
76
  ```
77
- | Multiple instances | @splunk/react-ui 4.x | @splunk/react-ui 4.x and 3.x |
77
+ | Multiple instances | @splunk/react-ui 5.x | @splunk/react-ui 5.x and 4.x |
78
78
  | ------------------ | ----------------------- | ---------------------------- |
79
79
  | In the same bundle | Deduplicate | Avoid |
80
80
  | On the same page | Avoid | Avoid |
@@ -84,19 +84,19 @@ using multiple instances of this library on the same page is discouraged.
84
84
 
85
85
  Multiple instances of `@splunk/react-ui` in the same bundle should be avoided.
86
86
  For example, instead of `4.0.0` and `4.1.0` only `4.1.0` should be used.
87
- Multiple versions of `3.x` are not supported.
87
+ Only major bug fixes will be supported in version `4.x`
88
88
  Use a package manager (Yarn or NPM) or a module bundler (Webpack) to deduplicate versions.
89
89
 
90
90
  ##### 1. Yarn or NPM:
91
91
  `yarn` and `npm` resolve dependencies to avoid duplicate versions.
92
92
 
93
93
  Pros:
94
- * Supports `4.x` and `3.x` in the same bundle.
94
+ * Supports `5.x` and `4.x` in the same bundle.
95
95
 
96
96
  Cons:
97
97
  * Extra versions can unexpectedly be added to lock files while updating dependencies.
98
98
  * Upgrades may require rebuilding the lock file.
99
- * All packages must all define their `@splunk/react-ui` dependency with a major version (`@^4.0` or `@^4.1`),
99
+ * All packages must all define their `@splunk/react-ui` dependency with a major version (`@^5.0` or `@^4.1`),
100
100
  not a minor version (`@~4.0`).
101
101
 
102
102
 
@@ -108,7 +108,7 @@ Pros:
108
108
  * Reliably builds with one version of `@splunk/react-ui`.
109
109
 
110
110
  Cons:
111
- * Cannot be used when `3.x` and `4.x` are required by different dependencies.
111
+ * Cannot be used when `5.x` and `4.x` are required by different dependencies.
112
112
  * If dependencies rely on a newer version, unexpected breakages may occur.
113
113
 
114
114
  ### On the same page