@mackin.com/styleguide 10.2.1 → 10.2.2

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/index.esm.js +53 -25
  2. package/index.js +53 -25
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -1258,15 +1258,18 @@ const useLogger = (componentName, enabled) => {
1258
1258
  const portalId = 'backdrop';
1259
1259
  const BackdropContext = React__default.createContext({
1260
1260
  showing: false,
1261
- showCount: 0,
1262
1261
  portalId: portalId,
1262
+ children: [],
1263
1263
  setShow: () => {
1264
1264
  /* empty */
1265
1265
  }
1266
1266
  });
1267
+ function useBackdropContext() {
1268
+ return useContext(BackdropContext);
1269
+ }
1267
1270
  const BackdropContextProvider = (p) => {
1268
1271
  var _a;
1269
- const [showCount, setShowCount] = useState(0);
1272
+ const [modalChildren, setModalChildren] = useState([]);
1270
1273
  const log = useLogger('BackdropContextProvider', (_a = p.__debug) !== null && _a !== void 0 ? _a : false);
1271
1274
  if (p.__debug) {
1272
1275
  useEffect(() => {
@@ -1276,26 +1279,38 @@ const BackdropContextProvider = (p) => {
1276
1279
  };
1277
1280
  }, []);
1278
1281
  useIgnoreMount(() => {
1279
- log('showCount changed', showCount);
1280
- }, [showCount]);
1282
+ log('showCount changed', modalChildren);
1283
+ }, [modalChildren]);
1281
1284
  }
1282
1285
  return (React__default.createElement(BackdropContext.Provider, { value: {
1283
1286
  portalId: portalId,
1284
- showing: showCount > 0,
1285
- showCount: showCount,
1287
+ showing: modalChildren.length > 0,
1288
+ children: modalChildren.slice(),
1286
1289
  setShow: (show, from) => {
1287
1290
  if (show) {
1288
- setShowCount(s => {
1289
- const count = s + 1;
1290
- log(`setShow from ${from} ${s} -> ${count}`);
1291
- return count;
1291
+ setModalChildren(previousChildren => {
1292
+ const newChildren = [...previousChildren, from];
1293
+ log(`setModalChildren TRUE from ${JSON.stringify(from)}.`);
1294
+ return newChildren;
1292
1295
  });
1293
1296
  }
1294
1297
  else {
1295
- setShowCount(s => {
1296
- const count = Math.max(0, s - 1);
1297
- log(`setShow from ${from} ${s} -> ${count}`);
1298
- return count;
1298
+ setModalChildren(previousChildren => {
1299
+ let newChildren;
1300
+ if (from.key === backdropOverlayKey && !show) {
1301
+ if (previousChildren.length === 1) {
1302
+ newChildren = [];
1303
+ }
1304
+ else {
1305
+ newChildren = [...previousChildren];
1306
+ newChildren.pop();
1307
+ }
1308
+ }
1309
+ else {
1310
+ newChildren = previousChildren.filter(c => c.key !== from.key);
1311
+ }
1312
+ log(`setModalChildren FALSE from ${JSON.stringify(from)}.`);
1313
+ return newChildren;
1299
1314
  });
1300
1315
  }
1301
1316
  }
@@ -1310,9 +1325,10 @@ const BackdropContextProvider = (p) => {
1310
1325
  margin: 0,
1311
1326
  zIndex: 9999
1312
1327
  })) },
1313
- "Backdrop showCount: ",
1314
- showCount))));
1328
+ "Backdrop children: ",
1329
+ JSON.stringify(modalChildren, null, 4)))));
1315
1330
  };
1331
+ const backdropOverlayKey = 'BackdropOverlay';
1316
1332
  const BackdropOverlay = (p) => {
1317
1333
  var _a, _b;
1318
1334
  const context = useContext(BackdropContext);
@@ -1330,15 +1346,25 @@ const BackdropOverlay = (p) => {
1330
1346
  log('context.showing changed', context.showing);
1331
1347
  }, [context.showing]);
1332
1348
  }
1349
+ let zIndex = -1;
1350
+ if (context.showing) {
1351
+ zIndex = theme.zIndexes.backdrop;
1352
+ context.children.forEach(child => {
1353
+ if (child.zIndex > zIndex) {
1354
+ // -1 so it's always directly below the child
1355
+ zIndex = child.zIndex - 1;
1356
+ }
1357
+ });
1358
+ }
1333
1359
  return (React__default.createElement("div", { onClick: () => {
1334
- context === null || context === void 0 ? void 0 : context.setShow(false, 'BackdropOverlay');
1360
+ context === null || context === void 0 ? void 0 : context.setShow(false, { key: backdropOverlayKey, zIndex });
1335
1361
  log('onClick', 'setShow', false);
1336
1362
  }, id: context === null || context === void 0 ? void 0 : context.portalId, className: css({
1337
1363
  cursor: 'pointer',
1338
1364
  position: 'fixed',
1339
1365
  top: 0, right: 0, bottom: 0, left: 0,
1340
1366
  backgroundColor: theme.colors.backdrop,
1341
- zIndex: (context === null || context === void 0 ? void 0 : context.showing) ? theme.zIndexes.backdrop : -1,
1367
+ zIndex,
1342
1368
  visibility: (context === null || context === void 0 ? void 0 : context.showing) ? 'visible' : 'hidden',
1343
1369
  opacity: (context === null || context === void 0 ? void 0 : context.showing) ? 1 : 0,
1344
1370
  transition: `opacity ${showTimeMs}ms ease-in-out`,
@@ -1582,7 +1608,7 @@ const useScrollbarSize = (recalc) => {
1582
1608
 
1583
1609
  const Modal = (p) => {
1584
1610
  var _a, _b, _c, _d;
1585
- const backdrop = useContext(BackdropContext);
1611
+ const backdrop = useBackdropContext();
1586
1612
  const mouseDownElement = useRef(undefined);
1587
1613
  const theme = useThemeSafely();
1588
1614
  const hasHeader = p.closeButton || p.heading;
@@ -1623,13 +1649,14 @@ const Modal = (p) => {
1623
1649
  });
1624
1650
  }
1625
1651
  };
1652
+ const zIndex = theme.zIndexes.modal;
1626
1653
  useEffect(() => {
1627
1654
  log('mounted');
1628
1655
  return () => {
1629
1656
  var _a;
1630
1657
  if (showing.current) {
1631
1658
  log(`un-mount in progress and this modal is showing. decrement the backdrop and try to remove singleton body styles.`);
1632
- backdrop.setShow(false, (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal');
1659
+ backdrop.setShow(false, { key: (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal', zIndex });
1633
1660
  log('backdrop.setShow', false);
1634
1661
  tryRemoveScrollStyles();
1635
1662
  }
@@ -1642,7 +1669,7 @@ const Modal = (p) => {
1642
1669
  useBooleanChanged((show, previousShow) => {
1643
1670
  var _a;
1644
1671
  log('show changed', `${previousShow !== null && previousShow !== void 0 ? previousShow : 'undefined'} > ${show}`);
1645
- backdrop.setShow(show, (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal');
1672
+ backdrop.setShow(show, { key: (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal', zIndex });
1646
1673
  showing.current = show;
1647
1674
  log('backdrop.setShow', show);
1648
1675
  if (show) {
@@ -1670,7 +1697,7 @@ const Modal = (p) => {
1670
1697
  const modalBodyStyles = css({
1671
1698
  maxHeight: p.scrollable ? undefined : '99vh',
1672
1699
  overflow: 'hidden',
1673
- zIndex: theme.zIndexes.modal,
1700
+ zIndex,
1674
1701
  cursor: 'default',
1675
1702
  margin: '1rem',
1676
1703
  backgroundColor: p.noBackground ? undefined : theme.colors.modalBg,
@@ -2722,7 +2749,7 @@ const Nav = (props) => {
2722
2749
  const theme = useThemeSafely();
2723
2750
  const navWidth = (_a = props.navWidth) !== null && _a !== void 0 ? _a : theme.layout.navWidth;
2724
2751
  const totalNavOffset = `calc(${navWidth} + 20px)`;
2725
- const backdrop = React.useContext(BackdropContext);
2752
+ const backdrop = useBackdropContext();
2726
2753
  const log = useLogger(`Nav ${(_b = props.id) !== null && _b !== void 0 ? _b : '?'}`, (_c = props.__debug) !== null && _c !== void 0 ? _c : false);
2727
2754
  const slideMs = (_d = props.slideMs) !== null && _d !== void 0 ? _d : theme.timings.nav.slideMs;
2728
2755
  const slideRight = keyframes `
@@ -2749,6 +2776,7 @@ const Nav = (props) => {
2749
2776
  const classNavNotShowing = css `
2750
2777
  animation: ${slideLeft} ${slideMs}ms cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
2751
2778
  `;
2779
+ const zIndex = theme.zIndexes.nav;
2752
2780
  // the padding-top here is to offset the navs' content from the header. the shadow creeps over it.
2753
2781
  const navStyles = css `
2754
2782
  label: Nav;
@@ -2761,7 +2789,7 @@ const Nav = (props) => {
2761
2789
  width: ${navWidth};
2762
2790
  min-width: ${navWidth};
2763
2791
  box-shadow: 4px 2px 12px 6px rgba(0, 0, 0, 0.2);
2764
- z-index: ${theme.zIndexes.nav};
2792
+ z-index: ${zIndex};
2765
2793
  overflow-y: auto;
2766
2794
  .omniLink, .omniLink:active, .omniLink:focus, .omniLink:visited {
2767
2795
  color: ${theme.colors.navFont};
@@ -2776,7 +2804,7 @@ const Nav = (props) => {
2776
2804
  useBooleanChanged((current, previous) => {
2777
2805
  var _a;
2778
2806
  log('show changed', `${previous !== null && previous !== void 0 ? previous : 'undefined'} > ${current}`);
2779
- backdrop.setShow(current, (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav');
2807
+ backdrop.setShow(current, { key: (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav', zIndex });
2780
2808
  }, props.show);
2781
2809
  React.useLayoutEffect(() => {
2782
2810
  if (nav && nav.current) {
package/index.js CHANGED
@@ -1276,15 +1276,18 @@ const useLogger = (componentName, enabled) => {
1276
1276
  const portalId = 'backdrop';
1277
1277
  const BackdropContext = React.createContext({
1278
1278
  showing: false,
1279
- showCount: 0,
1280
1279
  portalId: portalId,
1280
+ children: [],
1281
1281
  setShow: () => {
1282
1282
  /* empty */
1283
1283
  }
1284
1284
  });
1285
+ function useBackdropContext() {
1286
+ return React.useContext(BackdropContext);
1287
+ }
1285
1288
  const BackdropContextProvider = (p) => {
1286
1289
  var _a;
1287
- const [showCount, setShowCount] = React.useState(0);
1290
+ const [modalChildren, setModalChildren] = React.useState([]);
1288
1291
  const log = useLogger('BackdropContextProvider', (_a = p.__debug) !== null && _a !== void 0 ? _a : false);
1289
1292
  if (p.__debug) {
1290
1293
  React.useEffect(() => {
@@ -1294,26 +1297,38 @@ const BackdropContextProvider = (p) => {
1294
1297
  };
1295
1298
  }, []);
1296
1299
  useIgnoreMount(() => {
1297
- log('showCount changed', showCount);
1298
- }, [showCount]);
1300
+ log('showCount changed', modalChildren);
1301
+ }, [modalChildren]);
1299
1302
  }
1300
1303
  return (React.createElement(BackdropContext.Provider, { value: {
1301
1304
  portalId: portalId,
1302
- showing: showCount > 0,
1303
- showCount: showCount,
1305
+ showing: modalChildren.length > 0,
1306
+ children: modalChildren.slice(),
1304
1307
  setShow: (show, from) => {
1305
1308
  if (show) {
1306
- setShowCount(s => {
1307
- const count = s + 1;
1308
- log(`setShow from ${from} ${s} -> ${count}`);
1309
- return count;
1309
+ setModalChildren(previousChildren => {
1310
+ const newChildren = [...previousChildren, from];
1311
+ log(`setModalChildren TRUE from ${JSON.stringify(from)}.`);
1312
+ return newChildren;
1310
1313
  });
1311
1314
  }
1312
1315
  else {
1313
- setShowCount(s => {
1314
- const count = Math.max(0, s - 1);
1315
- log(`setShow from ${from} ${s} -> ${count}`);
1316
- return count;
1316
+ setModalChildren(previousChildren => {
1317
+ let newChildren;
1318
+ if (from.key === backdropOverlayKey && !show) {
1319
+ if (previousChildren.length === 1) {
1320
+ newChildren = [];
1321
+ }
1322
+ else {
1323
+ newChildren = [...previousChildren];
1324
+ newChildren.pop();
1325
+ }
1326
+ }
1327
+ else {
1328
+ newChildren = previousChildren.filter(c => c.key !== from.key);
1329
+ }
1330
+ log(`setModalChildren FALSE from ${JSON.stringify(from)}.`);
1331
+ return newChildren;
1317
1332
  });
1318
1333
  }
1319
1334
  }
@@ -1328,9 +1343,10 @@ const BackdropContextProvider = (p) => {
1328
1343
  margin: 0,
1329
1344
  zIndex: 9999
1330
1345
  })) },
1331
- "Backdrop showCount: ",
1332
- showCount))));
1346
+ "Backdrop children: ",
1347
+ JSON.stringify(modalChildren, null, 4)))));
1333
1348
  };
1349
+ const backdropOverlayKey = 'BackdropOverlay';
1334
1350
  const BackdropOverlay = (p) => {
1335
1351
  var _a, _b;
1336
1352
  const context = React.useContext(BackdropContext);
@@ -1348,15 +1364,25 @@ const BackdropOverlay = (p) => {
1348
1364
  log('context.showing changed', context.showing);
1349
1365
  }, [context.showing]);
1350
1366
  }
1367
+ let zIndex = -1;
1368
+ if (context.showing) {
1369
+ zIndex = theme.zIndexes.backdrop;
1370
+ context.children.forEach(child => {
1371
+ if (child.zIndex > zIndex) {
1372
+ // -1 so it's always directly below the child
1373
+ zIndex = child.zIndex - 1;
1374
+ }
1375
+ });
1376
+ }
1351
1377
  return (React.createElement("div", { onClick: () => {
1352
- context === null || context === void 0 ? void 0 : context.setShow(false, 'BackdropOverlay');
1378
+ context === null || context === void 0 ? void 0 : context.setShow(false, { key: backdropOverlayKey, zIndex });
1353
1379
  log('onClick', 'setShow', false);
1354
1380
  }, id: context === null || context === void 0 ? void 0 : context.portalId, className: css.css({
1355
1381
  cursor: 'pointer',
1356
1382
  position: 'fixed',
1357
1383
  top: 0, right: 0, bottom: 0, left: 0,
1358
1384
  backgroundColor: theme.colors.backdrop,
1359
- zIndex: (context === null || context === void 0 ? void 0 : context.showing) ? theme.zIndexes.backdrop : -1,
1385
+ zIndex,
1360
1386
  visibility: (context === null || context === void 0 ? void 0 : context.showing) ? 'visible' : 'hidden',
1361
1387
  opacity: (context === null || context === void 0 ? void 0 : context.showing) ? 1 : 0,
1362
1388
  transition: `opacity ${showTimeMs}ms ease-in-out`,
@@ -1600,7 +1626,7 @@ const useScrollbarSize = (recalc) => {
1600
1626
 
1601
1627
  const Modal = (p) => {
1602
1628
  var _a, _b, _c, _d;
1603
- const backdrop = React.useContext(BackdropContext);
1629
+ const backdrop = useBackdropContext();
1604
1630
  const mouseDownElement = React.useRef(undefined);
1605
1631
  const theme = useThemeSafely();
1606
1632
  const hasHeader = p.closeButton || p.heading;
@@ -1641,13 +1667,14 @@ const Modal = (p) => {
1641
1667
  });
1642
1668
  }
1643
1669
  };
1670
+ const zIndex = theme.zIndexes.modal;
1644
1671
  React.useEffect(() => {
1645
1672
  log('mounted');
1646
1673
  return () => {
1647
1674
  var _a;
1648
1675
  if (showing.current) {
1649
1676
  log(`un-mount in progress and this modal is showing. decrement the backdrop and try to remove singleton body styles.`);
1650
- backdrop.setShow(false, (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal');
1677
+ backdrop.setShow(false, { key: (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal', zIndex });
1651
1678
  log('backdrop.setShow', false);
1652
1679
  tryRemoveScrollStyles();
1653
1680
  }
@@ -1660,7 +1687,7 @@ const Modal = (p) => {
1660
1687
  useBooleanChanged((show, previousShow) => {
1661
1688
  var _a;
1662
1689
  log('show changed', `${previousShow !== null && previousShow !== void 0 ? previousShow : 'undefined'} > ${show}`);
1663
- backdrop.setShow(show, (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal');
1690
+ backdrop.setShow(show, { key: (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal', zIndex });
1664
1691
  showing.current = show;
1665
1692
  log('backdrop.setShow', show);
1666
1693
  if (show) {
@@ -1688,7 +1715,7 @@ const Modal = (p) => {
1688
1715
  const modalBodyStyles = css.css({
1689
1716
  maxHeight: p.scrollable ? undefined : '99vh',
1690
1717
  overflow: 'hidden',
1691
- zIndex: theme.zIndexes.modal,
1718
+ zIndex,
1692
1719
  cursor: 'default',
1693
1720
  margin: '1rem',
1694
1721
  backgroundColor: p.noBackground ? undefined : theme.colors.modalBg,
@@ -2740,7 +2767,7 @@ const Nav = (props) => {
2740
2767
  const theme = useThemeSafely();
2741
2768
  const navWidth = (_a = props.navWidth) !== null && _a !== void 0 ? _a : theme.layout.navWidth;
2742
2769
  const totalNavOffset = `calc(${navWidth} + 20px)`;
2743
- const backdrop = React__namespace.useContext(BackdropContext);
2770
+ const backdrop = useBackdropContext();
2744
2771
  const log = useLogger(`Nav ${(_b = props.id) !== null && _b !== void 0 ? _b : '?'}`, (_c = props.__debug) !== null && _c !== void 0 ? _c : false);
2745
2772
  const slideMs = (_d = props.slideMs) !== null && _d !== void 0 ? _d : theme.timings.nav.slideMs;
2746
2773
  const slideRight = css.keyframes `
@@ -2767,6 +2794,7 @@ const Nav = (props) => {
2767
2794
  const classNavNotShowing = css.css `
2768
2795
  animation: ${slideLeft} ${slideMs}ms cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
2769
2796
  `;
2797
+ const zIndex = theme.zIndexes.nav;
2770
2798
  // the padding-top here is to offset the navs' content from the header. the shadow creeps over it.
2771
2799
  const navStyles = css.css `
2772
2800
  label: Nav;
@@ -2779,7 +2807,7 @@ const Nav = (props) => {
2779
2807
  width: ${navWidth};
2780
2808
  min-width: ${navWidth};
2781
2809
  box-shadow: 4px 2px 12px 6px rgba(0, 0, 0, 0.2);
2782
- z-index: ${theme.zIndexes.nav};
2810
+ z-index: ${zIndex};
2783
2811
  overflow-y: auto;
2784
2812
  .omniLink, .omniLink:active, .omniLink:focus, .omniLink:visited {
2785
2813
  color: ${theme.colors.navFont};
@@ -2794,7 +2822,7 @@ const Nav = (props) => {
2794
2822
  useBooleanChanged((current, previous) => {
2795
2823
  var _a;
2796
2824
  log('show changed', `${previous !== null && previous !== void 0 ? previous : 'undefined'} > ${current}`);
2797
- backdrop.setShow(current, (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav');
2825
+ backdrop.setShow(current, { key: (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav', zIndex });
2798
2826
  }, props.show);
2799
2827
  React__namespace.useLayoutEffect(() => {
2800
2828
  if (nav && nav.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "10.2.1",
3
+ "version": "10.2.2",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "module": "./index.esm.js",