@xyo-network/react-shared 2.28.8 → 2.28.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.
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { AlertProps } from '@mui/material';
3
+ import { XyoApiError } from '@xyo-network/api';
4
+ export interface ApiErrorAlertProps extends AlertProps {
5
+ call?: XyoApiError;
6
+ }
7
+ declare const ApiErrorAlert: React.FC<ApiErrorAlertProps>;
8
+ export { ApiErrorAlert };
9
+ //# sourceMappingURL=ApiErrorAlert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiErrorAlert.d.ts","sourceRoot":"","sources":["../../../src/components/ApiErrorAlert.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAS,UAAU,EAA0B,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,MAAM,WAAW,kBAAmB,SAAQ,UAAU;IACpD,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAW/C,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Alert, AlertTitle, Typography } from '@mui/material';
3
+ const ApiErrorAlert = ({ call, ...props }) => {
4
+ return (_jsxs(Alert, { severity: "error", ...props, children: [_jsx(AlertTitle, { children: "Whoops! Something went wrong" }), _jsx(Typography, { sx: { wordBreak: 'break-all' }, children: call?.config?.url }), _jsx(Typography, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }), _jsx(Typography, { variant: "caption", children: call?.message })] }));
5
+ };
6
+ export { ApiErrorAlert };
7
+ //# sourceMappingURL=ApiErrorAlert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiErrorAlert.js","sourceRoot":"","sources":["../../../src/components/ApiErrorAlert.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAc,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAOzE,MAAM,aAAa,GAAiC,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACzE,OAAO,CACL,MAAC,KAAK,IAAC,QAAQ,EAAC,OAAO,KAAK,KAAK,aAC/B,KAAC,UAAU,+CAA0C,EACrD,KAAC,UAAU,IAAC,EAAE,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,YAAG,IAAI,EAAE,MAAM,EAAE,GAAG,GAAc,EAC5E,KAAC,UAAU,IAAC,OAAO,EAAC,SAAS,EAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAC,MAAM,uBAE3C,EACb,KAAC,UAAU,IAAC,OAAO,EAAC,SAAS,YAAE,IAAI,EAAE,OAAO,GAAc,IACpD,CACT,CAAA;AACH,CAAC,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -2,6 +2,7 @@ import { Component, ErrorInfo, ReactNode } from 'react';
2
2
  export interface ErrorBoundaryProps {
3
3
  children: ReactNode;
4
4
  fallback?: ReactNode;
5
+ fallbackWithError?: (error: Error) => ReactNode;
5
6
  }
6
7
  export interface ErrorBoundaryState {
7
8
  error?: Error;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundry.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundry.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEvD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAA;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACtE,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;IAI5C,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAIpD,MAAM;CAcP"}
1
+ {"version":3,"file":"ErrorBoundry.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundry.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEvD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAA;IAEnB,QAAQ,CAAC,EAAE,SAAS,CAAA;IAEpB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAA;CAChD;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACtE,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;IAI5C,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAIpD,MAAM;CAiBP"}
@@ -15,6 +15,9 @@ export class ErrorBoundary extends Component {
15
15
  }
16
16
  render() {
17
17
  if (this.state.error) {
18
+ if (this.props.fallbackWithError) {
19
+ return this.props.fallbackWithError(this.state.error);
20
+ }
18
21
  return (this.props.fallback ?? (_jsxs(FlexCol, { children: [_jsx(Typography, { variant: "h1", children: "Something went wrong." }), _jsxs(Typography, { variant: "body1", children: ["[", this.state.error?.message, "]"] })] })));
19
22
  }
20
23
  return this.props.children;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundry.js","sourceRoot":"","sources":["../../../src/components/ErrorBoundry.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eA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AE,KAAK,EAAE,SAAS,EAAE,CAAA;IACnC,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO,EAAE,KAAK,EAAE,CAAA;IAClB,CAAC;IAED,iBAAiB,CAAC,KAAY,EAAE,SAAoB;QAClD,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,KAAK,SAAS,EAAE,CAAC,CAAA;IACzC,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YACpB,IAAI,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;gBAChC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;aACtD;YACD,OAAO,CACL,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CACrB,MAAC,OAAO,eACN,KAAC,UAAU,IAAC,OAAO,EAAC,IAAI,sCAAmC,EAC3D,MAAC,UAAU,IAAC,OAAO,EAAC,OAAO,kBAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,SAAe,IAC9D,CACX,CACF,CAAA;SACF;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAA;IAC5B,CAAC;CACF"}
@@ -1,4 +1,5 @@
1
1
  export * from './Ampersand';
2
+ export * from './ApiErrorAlert';
2
3
  export * from './BasicHero';
3
4
  export * from './ErrorBoundry';
4
5
  export * from './JsonRouteWrapper';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export * from './Ampersand';
2
+ export * from './ApiErrorAlert';
2
3
  export * from './BasicHero';
3
4
  export * from './ErrorBoundry';
4
5
  export * from './JsonRouteWrapper';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "@xylabs/react-link": "^2.14.13",
24
24
  "@xylabs/react-quick-tip-button": "^2.14.13",
25
25
  "@xylabs/react-shared": "^2.14.13",
26
- "@xyo-network/core": "^2.26.18",
26
+ "@xyo-network/core": "^2.26.20",
27
27
  "axios": "^0.27.2",
28
28
  "react": "^18.2.0",
29
29
  "react-dom": "^18.2.0",
@@ -35,9 +35,9 @@
35
35
  "devDependencies": {
36
36
  "@storybook/react": "^6.5.10",
37
37
  "@xylabs/pixel": "^1.4.5",
38
- "@xylabs/tsconfig-dom": "^2.5.121",
39
- "@xyo-network/api": "^2.26.18",
40
- "@xyo-network/react-storybook": "^2.28.8"
38
+ "@xylabs/tsconfig-dom": "^2.5.123",
39
+ "@xyo-network/api": "^2.26.20",
40
+ "@xyo-network/react-storybook": "^2.28.11"
41
41
  },
42
42
  "browser": "dist/esm/index.js",
43
43
  "docs": "dist/docs.json",
@@ -81,5 +81,5 @@
81
81
  },
82
82
  "sideEffects": false,
83
83
  "types": "dist/esm/index.d.ts",
84
- "version": "2.28.8"
84
+ "version": "2.28.11"
85
85
  }
@@ -0,0 +1,21 @@
1
+ import { Alert, AlertProps, AlertTitle, Typography } from '@mui/material'
2
+ import { XyoApiError } from '@xyo-network/api'
3
+
4
+ export interface ApiErrorAlertProps extends AlertProps {
5
+ call?: XyoApiError
6
+ }
7
+
8
+ const ApiErrorAlert: React.FC<ApiErrorAlertProps> = ({ call, ...props }) => {
9
+ return (
10
+ <Alert severity="error" {...props}>
11
+ <AlertTitle>Whoops! Something went wrong</AlertTitle>
12
+ <Typography sx={{ wordBreak: 'break-all' }}>{call?.config?.url}</Typography>
13
+ <Typography variant="caption" mr={0.5} fontWeight="bold">
14
+ Error:
15
+ </Typography>
16
+ <Typography variant="caption">{call?.message}</Typography>
17
+ </Alert>
18
+ )
19
+ }
20
+
21
+ export { ApiErrorAlert }
@@ -4,7 +4,10 @@ import { Component, ErrorInfo, ReactNode } from 'react'
4
4
 
5
5
  export interface ErrorBoundaryProps {
6
6
  children: ReactNode
7
+ // fallback as a static ReactNode value
7
8
  fallback?: ReactNode
9
+ // fallback element that can receive the error as a prop
10
+ fallbackWithError?: (error: Error) => ReactNode
8
11
  }
9
12
 
10
13
  export interface ErrorBoundaryState {
@@ -27,6 +30,9 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt
27
30
 
28
31
  render() {
29
32
  if (this.state.error) {
33
+ if (this.props.fallbackWithError) {
34
+ return this.props.fallbackWithError(this.state.error)
35
+ }
30
36
  return (
31
37
  this.props.fallback ?? (
32
38
  <FlexCol>
@@ -1,4 +1,5 @@
1
1
  export * from './Ampersand'
2
+ export * from './ApiErrorAlert'
2
3
  export * from './BasicHero'
3
4
  export * from './ErrorBoundry'
4
5
  export * from './JsonRouteWrapper'