@thecb/components 7.7.8-beta.1 → 7.7.8-beta.11

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/index.cjs.js CHANGED
@@ -24466,43 +24466,85 @@ var useOutsideClickHook = function useOutsideClickHook(handler) {
24466
24466
  Hook that determines whether every element in an array of DOM selectors is fully present
24467
24467
  within the user's current viewport.
24468
24468
 
24469
- (elements: Array<String>) => Boolean;
24469
+ (elements: Array<String>, Number, Number) => Boolean;
24470
+ (["#submit-button", "#.module-small", "h2.alert-title"], 1024, 768) => true;
24470
24471
 
24471
24472
  Takes an array of strings that correspond to DOM selectors. Examples:
24472
24473
  "#submit-button", ".module-small", "h2.alert-title"
24473
24474
 
24475
+ Also takes numbers that represent the current viewport width and height.
24476
+ You can either calculate these once in your application before running this hook
24477
+ (so that they only update when the component running the hook re-renders), or you can
24478
+ use the useGetViewportOnResize hook to calculate them when the browser window is resized
24479
+
24474
24480
  The document query function will return the *first* element in the document that matches
24475
24481
  the string given.
24476
24482
 
24477
- A combination string of multiple selectors can also be provided, e.g.:
24478
- ".alert-info, .alert-warning, .alert-error"
24483
+ A combination string of multiple selectors can also be provided as an item in the array, e.g.:
24484
+ ".alert-info, .alert-warning, .alert-error". This will return the first element that matches *any* of the provided selectors.
24479
24485
 
24480
- This will return the first element that matches *any* of the provided selectors
24486
+ If the element is present in the DOM (domEL !== null), the function examines the element's bounding box
24487
+ to determine if the element is within the viewport. If any portion of the element is outside of
24488
+ the viewport, the function returns false.
24481
24489
 
24482
- If every element in the array is fully within the viewport, function returns true
24490
+ If all elements that exist are within the viewport, the function returns true.
24483
24491
  */
24484
24492
 
24485
24493
  var useCheckElementsInViewport = function useCheckElementsInViewport() {
24486
24494
  var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
24495
+ var viewportWidth = arguments.length > 1 ? arguments[1] : undefined;
24496
+ var viewportHeight = arguments.length > 2 ? arguments[2] : undefined;
24487
24497
 
24488
- var _useState = React.useState(false),
24489
- _useState2 = _slicedToArray(_useState, 2),
24490
- elementsVisible = _useState2[0],
24491
- setElementsVisible = _useState2[1];
24498
+ for (var i = 0; i < elements.length; i++) {
24499
+ var domEl = document.querySelector(elements[i]);
24500
+ var boundingBox = domEl === null || domEl === void 0 ? void 0 : domEl.getBoundingClientRect();
24492
24501
 
24493
- var viewportWidth = window.innerWidth || document.documentElement.clientWidth;
24494
- var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
24495
- React.useEffect(function () {
24496
- elements.forEach(function (element) {
24497
- var domEl = document.querySelector(element);
24498
- var boundingBox = domEl.getBoundingClientRect();
24502
+ if (domEl !== null) {
24503
+ if (boundingBox.top < 0 || boundingBox.left < 0 || boundingBox.right > viewportWidth || boundingBox.bottom > viewportHeight) {
24504
+ return false;
24505
+ }
24506
+ }
24507
+ }
24508
+
24509
+ return true;
24510
+ };
24511
+
24512
+ /*
24513
+ Hook that adds a resize listener to the window and updates viewport size via
24514
+ a provided handler function
24515
+
24516
+ (Object: {width: Number, height: Number}, Function) => undefined;
24517
+
24518
+ Provide the current value of the user's viewport and a handler function to receive updated values
24519
+
24520
+ Best used in combination with a useState hook in your component to receive updated values
24521
+ */
24522
+
24523
+ var useGetViewportOnResize = function useGetViewportOnResize(viewport, updateViewport) {
24524
+ var timeoutID = false;
24525
+ var delay = 250;
24499
24526
 
24500
- if (boundingBox.top >= 0 && boundingBox.left >= 0 && boundingBox.right <= viewportWidth && boundingBox.bottom <= viewportHeight) {
24501
- setElementsVisible(true);
24527
+ var updateViewportValues = function updateViewportValues() {
24528
+ clearTimeout(timeoutID);
24529
+ timeoutID = setTimeout(function () {
24530
+ var newWidth = window.innerWidth || document.documentElement.clientWidth;
24531
+ var newHeight = window.innerHeight || document.documentElement.clientHeight;
24532
+
24533
+ if (viewport !== null && viewport !== void 0 && viewport.width && (viewport === null || viewport === void 0 ? void 0 : viewport.width) !== newWidth || viewport !== null && viewport !== void 0 && viewport.height && (viewport === null || viewport === void 0 ? void 0 : viewport.height) !== newHeight) {
24534
+ updateViewport({
24535
+ width: newWidth,
24536
+ height: newHeight
24537
+ });
24502
24538
  }
24503
- });
24504
- }, [elements]);
24505
- return elementsVisible;
24539
+ }, delay);
24540
+ };
24541
+
24542
+ React.useEffect(function () {
24543
+ window.addEventListener("resize", updateViewportValues);
24544
+ return function () {
24545
+ clearTimeout(timeoutID);
24546
+ };
24547
+ }, []);
24506
24548
  };
24507
24549
 
24508
24550
 
@@ -24514,7 +24556,8 @@ var index$4 = /*#__PURE__*/Object.freeze({
24514
24556
  theme: themeUtils,
24515
24557
  useFocusInvalidInput: useFocusInvalidInput,
24516
24558
  useOutsideClick: useOutsideClickHook,
24517
- useCheckElementsInViewport: useCheckElementsInViewport
24559
+ useCheckElementsInViewport: useCheckElementsInViewport,
24560
+ useGetViewportOnResize: useGetViewportOnResize
24518
24561
  });
24519
24562
 
24520
24563
  var hoverColor$4 = "#116285";
@@ -40330,6 +40373,8 @@ var HighlightTabRow = function HighlightTabRow(_ref) {
40330
40373
  useOrderedList: useOrderedList,
40331
40374
  useUnorderedList: useUnorderedList
40332
40375
  }, repeat( /*#__PURE__*/React__default.createElement(Box, null), boxesBefore), tabs.map(function (t, i) {
40376
+ var _t$toLowerCase;
40377
+
40333
40378
  return /*#__PURE__*/React__default.createElement(Box, {
40334
40379
  key: t,
40335
40380
  borderSize: "3px",
@@ -40344,7 +40389,7 @@ var HighlightTabRow = function HighlightTabRow(_ref) {
40344
40389
  color: themeValues.textColor,
40345
40390
  weight: FONT_WEIGHT_SEMIBOLD,
40346
40391
  extraStyles: "display: block; white-space: nowrap;",
40347
- id: "".concat(t, "-tab-text")
40392
+ id: "".concat(t === null || t === void 0 ? void 0 : (_t$toLowerCase = t.toLowerCase()) === null || _t$toLowerCase === void 0 ? void 0 : _t$toLowerCase.replace(/\s/g, "-"), "-tab-text")
40348
40393
  }, t));
40349
40394
  }), repeat( /*#__PURE__*/React__default.createElement(Box, null), boxesAfter))));
40350
40395
  };
@@ -45538,19 +45583,28 @@ var Module = function Module(_ref) {
45538
45583
  variant = _ref$variant === void 0 ? "default" : _ref$variant,
45539
45584
  fontSize = _ref.fontSize,
45540
45585
  as = _ref.as,
45586
+ _ref$titleID = _ref.titleID,
45587
+ titleID = _ref$titleID === void 0 ? "" : _ref$titleID,
45588
+ rightTitleContent = _ref.rightTitleContent,
45541
45589
  children = _ref.children;
45542
45590
  var themedFontSize = variant === "small" ? "1.25rem" : variant === "default" ? "1.375rem" : "2rem";
45543
45591
  var computedFontSize = fontSize || themedFontSize;
45544
45592
  var themedElemType = variant === "small" ? "h6" : variant === "default" ? "h5" : "h2";
45545
45593
  var computedElemType = as || themedElemType;
45546
- return /*#__PURE__*/React__default.createElement(React.Fragment, null, heading && /*#__PURE__*/React__default.createElement(Title$1, {
45594
+ var headingText = /*#__PURE__*/React__default.createElement(Title$1, {
45547
45595
  weight: themeValues.fontWeight,
45548
45596
  color: themeValues.fontColor,
45549
45597
  margin: "".concat(spacing, " 0 ").concat(themeValues.titleSpacing, " 0"),
45550
45598
  textAlign: themeValues.textAlign,
45551
45599
  as: computedElemType,
45552
- extraStyles: "font-size: ".concat(computedFontSize, ";")
45553
- }, heading), /*#__PURE__*/React__default.createElement(Box, {
45600
+ extraStyles: "font-size: ".concat(computedFontSize, ";"),
45601
+ id: titleID
45602
+ }, heading);
45603
+ return /*#__PURE__*/React__default.createElement(React.Fragment, null, heading && !rightTitleContent && headingText, heading && rightTitleContent && /*#__PURE__*/React__default.createElement(Cluster, {
45604
+ justify: "space-between",
45605
+ align: "center",
45606
+ nowrap: true
45607
+ }, headingText, rightTitleContent), /*#__PURE__*/React__default.createElement(Box, {
45554
45608
  padding: "0 0 ".concat(spacingBottom)
45555
45609
  }, /*#__PURE__*/React__default.createElement(Box, {
45556
45610
  padding: padding,