@sonardigital/carbon-ui 1.1.40 → 1.1.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonardigital/carbon-ui",
3
- "version": "1.1.40",
3
+ "version": "1.1.41",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -0,0 +1,19 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ export const Delay: React.FC<{
4
+ time: number;
5
+ children?: React.ReactNode;
6
+ fallback: React.ReactNode;
7
+ }> = ({ time, children, fallback }) => {
8
+ const [shouldRender, setShouldRender] = useState(false);
9
+
10
+ useEffect(() => {
11
+ const timer = setTimeout(() => {
12
+ setShouldRender(true);
13
+ }, time);
14
+
15
+ return () => clearTimeout(timer);
16
+ }, [time]);
17
+
18
+ return shouldRender ? children : fallback;
19
+ };
@@ -0,0 +1,51 @@
1
+ import React, { Component, Suspense } from 'react';
2
+ import { Delay } from '../delay';
3
+
4
+ interface Props {
5
+ children: React.ReactNode;
6
+ fallback?: React.ReactNode;
7
+ time?: number;
8
+ delay?: boolean;
9
+ isLoading?: boolean | (undefined | null | boolean)[];
10
+ }
11
+
12
+ interface State {
13
+ hasError: boolean;
14
+ }
15
+
16
+ export class ErrorBoundary extends Component<Props, State> {
17
+ constructor(props: Props) {
18
+ super(props);
19
+ this.state = { hasError: false };
20
+ }
21
+
22
+ componentDidCatch(): void {
23
+ this.setState({ hasError: true });
24
+ }
25
+
26
+ render(): React.ReactElement | React.ReactNode {
27
+ const { isLoading, fallback, children, delay, time } = this.props;
28
+
29
+ // eslint-disable-next-line
30
+ // @ts-ignore
31
+ if ([isLoading]?.flat()?.includes(true)) {
32
+ return fallback;
33
+ }
34
+
35
+ if (this.state.hasError) {
36
+ return 'Error while rendering the section';
37
+ }
38
+
39
+ return (
40
+ <Suspense fallback={fallback}>
41
+ {delay && time !== 0 ? (
42
+ <Delay time={time ?? 0} fallback={fallback}>
43
+ {children}
44
+ </Delay>
45
+ ) : (
46
+ children
47
+ )}
48
+ </Suspense>
49
+ );
50
+ }
51
+ }
@@ -1,3 +1,5 @@
1
1
  export * from './Drawer_';
2
2
  export * from './Dropdown';
3
3
  export * from './ScrollToTop/ScrollToTop';
4
+ export * from './error-boundary';
5
+ export * from './delay';
@@ -14,7 +14,7 @@ export const typography = {
14
14
  fontWeight: 500,
15
15
  },
16
16
  h4: {
17
- fontSize: '2.5rem',
17
+ fontSize: '2.2rem',
18
18
  fontWeight: 500,
19
19
  },
20
20
  h5: {
@@ -27,7 +27,7 @@ export const typography = {
27
27
  fontWeight: 350,
28
28
  },
29
29
  body2: {
30
- fontSize: '1.8rem',
30
+ fontSize: '1.7rem',
31
31
  fontWeight: 350,
32
32
  lineHeight: 1.5,
33
33
  },