@crystaldesign/content-item 26.13.0-beta.2 → 26.13.0-beta.21

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.
@@ -924,6 +924,31 @@ var loading = "loading-089Ib";
924
924
  var css_248z = ".root-wrapper-WNprt {\n min-height: 60px;\n position: relative;\n overscroll-behavior: contain;\n flex: 1;\n min-height: 0;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n\n.content-wrapper-K5XIs {\n flex: 1;\n min-height: 0;\n overflow: auto;\n transition: opacity 0.2s ease-in-out;\n}\n.content-wrapper-K5XIs.loading-089Ib {\n opacity: 0.5;\n}\n\n.content-wrapper-K5XIs .content-item-link {\n touch-action: manipulation;\n color: #1668dc;\n text-decoration: none;\n background-color: transparent;\n outline: none;\n cursor: pointer;\n transition: color 0.2s ease-in-out;\n}\n\n.content-wrapper-K5XIs .content-item-link:hover {\n color: #15417e;\n}\n";
925
925
  styleInject(css_248z);
926
926
 
927
+ /**
928
+ * True once `active` has stayed true for `delay` ms, false again as soon as it ends. A loader driven by it does not
929
+ * show at all for a fast load, which would otherwise only flicker.
930
+ */
931
+ function useDelayedFlag(active, delay) {
932
+ var _useState = useState(false),
933
+ _useState2 = _slicedToArray(_useState, 2),
934
+ shown = _useState2[0],
935
+ setShown = _useState2[1];
936
+ useEffect(function () {
937
+ if (!active) {
938
+ setShown(false);
939
+ return;
940
+ }
941
+ var timer = setTimeout(function () {
942
+ return setShown(true);
943
+ }, delay);
944
+ return function () {
945
+ return clearTimeout(timer);
946
+ };
947
+ }, [active, delay]);
948
+ return shown;
949
+ }
950
+
951
+ var LOADER_DELAY_MS = 300;
927
952
  var ContentItems = function ContentItems(_ref) {
928
953
  var wrapperStyle = _ref.wrapperStyle,
929
954
  params = _ref.params;
@@ -932,11 +957,13 @@ var ContentItems = function ContentItems(_ref) {
932
957
  loading$1 = _useContentItem.loading,
933
958
  error = _useContentItem.error,
934
959
  currentIdOrCodex = _useContentItem.currentIdOrCodex;
960
+ // Every update of the content passes through a loading state; only a slow one gets the loader
961
+ var showLoading = useDelayedFlag(!!loading$1, LOADER_DELAY_MS);
935
962
  return /*#__PURE__*/jsxs("div", {
936
963
  className: rootWrapper,
937
964
  id: 'diva-content-item',
938
- children: [loading$1 && /*#__PURE__*/jsx(Loader, {}), Array.isArray(content) ? /*#__PURE__*/jsxs("div", {
939
- className: classNames(contentWrapper, _defineProperty({}, loading, loading$1)),
965
+ children: [showLoading && /*#__PURE__*/jsx(Loader, {}), Array.isArray(content) ? /*#__PURE__*/jsxs("div", {
966
+ className: classNames(contentWrapper, _defineProperty({}, loading, showLoading)),
940
967
  style: wrapperStyle,
941
968
  children: [error && /*#__PURE__*/jsx(ErrorBox, {
942
969
  error: error
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/Components/ContentItems/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,UAAU,iBAAiB;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IACnC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACjC;AAED,QAAA,MAAM,YAAY,6BAA8B,iBAAiB,sBAiBhE,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/Components/ContentItems/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,UAAU,iBAAiB;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IACnC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACjC;AAED,QAAA,MAAM,YAAY,6BAA8B,iBAAiB,sBAqBhE,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * True once `active` has stayed true for `delay` ms, false again as soon as it ends. A loader driven by it does not
3
+ * show at all for a fast load, which would otherwise only flicker.
4
+ */
5
+ export declare function useDelayedFlag(active: boolean, delay: number): boolean;
6
+ //# sourceMappingURL=useDelayedFlag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDelayedFlag.d.ts","sourceRoot":"","sources":["../../../../../../src/Components/ContentItems/useDelayedFlag.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAatE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useDelayedFlag.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDelayedFlag.test.d.ts","sourceRoot":"","sources":["../../../../../src/tests/useDelayedFlag.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystaldesign/content-item",
3
- "version": "26.13.0-beta.2",
3
+ "version": "26.13.0-beta.21",
4
4
  "description": "CMS content item rendering (text, media, links).",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -25,7 +25,7 @@
25
25
  "webpack": "^5.73.0"
26
26
  },
27
27
  "dependencies": {
28
- "@crystaldesign/quick-config": "26.13.0-beta.2",
28
+ "@crystaldesign/quick-config": "26.13.0-beta.21",
29
29
  "axios": "^1.7.7",
30
30
  "classnames": "^2.5.1",
31
31
  "swiper": "^12.1.2"
@@ -37,5 +37,5 @@
37
37
  },
38
38
  "module": "build/esm/index.js",
39
39
  "types": "./build/types/content-item/src/index.d.ts",
40
- "gitHead": "80503e32af3f8fc88ae4f632f1153cc6d0abec08"
40
+ "gitHead": "8924c019e83cd44f3f2d2ecf41d0e26143d30128"
41
41
  }