@a-type/ui 0.6.5 → 0.6.6

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.
@@ -1,7 +1,9 @@
1
- import React, { Component, ReactNode } from 'react';
1
+ import React, { Component, ReactElement, ReactNode } from 'react';
2
2
  export declare class ErrorBoundary extends Component<{
3
3
  children: ReactNode;
4
- fallback?: ReactNode;
4
+ fallback?: ReactNode | ((props: {
5
+ clearError: () => void;
6
+ }) => ReactElement);
5
7
  }, {
6
8
  error: Error | null;
7
9
  }> {
@@ -11,5 +13,5 @@ export declare class ErrorBoundary extends Component<{
11
13
  static getDerivedStateFromError(error: Error): {
12
14
  error: Error;
13
15
  };
14
- render(): React.ReactNode;
16
+ render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined;
15
17
  }
@@ -17,6 +17,11 @@ class ErrorBoundary extends react_1.Component {
17
17
  }
18
18
  render() {
19
19
  if (this.state.error) {
20
+ if (typeof this.props.fallback === 'function') {
21
+ return this.props.fallback({
22
+ clearError: () => this.setState({ error: null }),
23
+ });
24
+ }
20
25
  return this.props.fallback || null;
21
26
  }
22
27
  return this.props.children;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../../../src/components/errorBoundary/ErrorBoundary.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AACb,iCAAoD;AAEpD,MAAa,aAAc,SAAQ,iBAGlC;IAHD;;QAIC,UAAK,GAAG;YACP,KAAK,EAAE,IAAI;SACX,CAAC;IAaH,CAAC;IAXA,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC3C,6DAA6D;QAC7D,OAAO,EAAE,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,MAAM;QACL,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YACrB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;SACnC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC5B,CAAC;CACD;AAnBD,sCAmBC"}
1
+ {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../../../src/components/errorBoundary/ErrorBoundary.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AACb,iCAAkE;AAElE,MAAa,aAAc,SAAQ,iBAQlC;IARD;;QASC,UAAK,GAAG;YACP,KAAK,EAAE,IAAI;SACX,CAAC;IAkBH,CAAC;IAhBA,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC3C,6DAA6D;QAC7D,OAAO,EAAE,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,MAAM;QACL,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YACrB,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU,EAAE;gBAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;oBAC1B,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;iBAChD,CAAC,CAAC;aACH;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;SACnC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC5B,CAAC;CACD;AA7BD,sCA6BC"}
@@ -1,7 +1,9 @@
1
- import React, { Component, ReactNode } from 'react';
1
+ import React, { Component, ReactElement, ReactNode } from 'react';
2
2
  export declare class ErrorBoundary extends Component<{
3
3
  children: ReactNode;
4
- fallback?: ReactNode;
4
+ fallback?: ReactNode | ((props: {
5
+ clearError: () => void;
6
+ }) => ReactElement);
5
7
  }, {
6
8
  error: Error | null;
7
9
  }> {
@@ -11,5 +13,5 @@ export declare class ErrorBoundary extends Component<{
11
13
  static getDerivedStateFromError(error: Error): {
12
14
  error: Error;
13
15
  };
14
- render(): React.ReactNode;
16
+ render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined;
15
17
  }
@@ -14,6 +14,11 @@ export class ErrorBoundary extends Component {
14
14
  }
15
15
  render() {
16
16
  if (this.state.error) {
17
+ if (typeof this.props.fallback === 'function') {
18
+ return this.props.fallback({
19
+ clearError: () => this.setState({ error: null }),
20
+ });
21
+ }
17
22
  return this.props.fallback || null;
18
23
  }
19
24
  return this.props.children;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../../../src/components/errorBoundary/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAc,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAEpD,MAAM,OAAO,aAAc,SAAQ,SAGlC;IAHD;;QAIC,UAAK,GAAG;YACP,KAAK,EAAE,IAAI;SACX,CAAC;IAaH,CAAC;IAXA,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC3C,6DAA6D;QAC7D,OAAO,EAAE,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,MAAM;QACL,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YACrB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;SACnC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC5B,CAAC;CACD"}
1
+ {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../../../src/components/errorBoundary/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAc,EAAE,SAAS,EAA2B,MAAM,OAAO,CAAC;AAElE,MAAM,OAAO,aAAc,SAAQ,SAQlC;IARD;;QASC,UAAK,GAAG;YACP,KAAK,EAAE,IAAI;SACX,CAAC;IAkBH,CAAC;IAhBA,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC3C,6DAA6D;QAC7D,OAAO,EAAE,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,MAAM;QACL,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;YACrB,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU,EAAE;gBAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;oBAC1B,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;iBAChD,CAAC,CAAC;aACH;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;SACnC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC5B,CAAC;CACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-type/ui",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "/dist",
@@ -1,8 +1,13 @@
1
1
  'use client';
2
- import React, { Component, ReactNode } from 'react';
2
+ import React, { Component, ReactElement, ReactNode } from 'react';
3
3
 
4
4
  export class ErrorBoundary extends Component<
5
- { children: ReactNode; fallback?: ReactNode },
5
+ {
6
+ children: ReactNode;
7
+ fallback?:
8
+ | ReactNode
9
+ | ((props: { clearError: () => void }) => ReactElement);
10
+ },
6
11
  { error: Error | null }
7
12
  > {
8
13
  state = {
@@ -16,6 +21,11 @@ export class ErrorBoundary extends Component<
16
21
 
17
22
  render() {
18
23
  if (this.state.error) {
24
+ if (typeof this.props.fallback === 'function') {
25
+ return this.props.fallback({
26
+ clearError: () => this.setState({ error: null }),
27
+ });
28
+ }
19
29
  return this.props.fallback || null;
20
30
  }
21
31
  return this.props.children;