@heritsilavo/react-error-boundary 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ export declare class CustomError extends Error {
2
+ code: string;
3
+ description: string;
4
+ constructor(code: string, message: string, description: string);
5
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type WrapperPropsType = {
3
+ children: React.ReactNode;
4
+ };
5
+ export declare const ErrorBoundary: React.FC<WrapperPropsType>;
6
+ export {};
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { CustomError } from './CustomError';
3
+ import { ErrorComponentType } from './components/DefaultErrorComponents';
4
+ interface ContextType {
5
+ handleError: (error: Error) => void;
6
+ error: CustomError | null;
7
+ clearError: () => void;
8
+ }
9
+ interface ErrorProviderProps {
10
+ children: React.ReactNode;
11
+ ErrorComponent?: React.ComponentType<ErrorComponentType>;
12
+ autoHideDelay?: number;
13
+ onError?: () => void;
14
+ closeErrorComponetOnClick?: boolean;
15
+ }
16
+ export declare const ErrorProvider: React.FC<ErrorProviderProps>;
17
+ export declare const useError: () => ContextType;
18
+ export declare const useThrowError: () => (code: string, message: string, description: string) => void;
19
+ export {};
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import './style.css';
3
+ import React from "react";
4
+ declare const ErrorComponentPropsSchema: z.ZodObject<{
5
+ error: z.ZodObject<{
6
+ code: z.ZodString;
7
+ message: z.ZodString;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ code: string;
11
+ message: string;
12
+ description?: string | undefined;
13
+ }, {
14
+ code: string;
15
+ message: string;
16
+ description?: string | undefined;
17
+ }>;
18
+ onClose: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodVoid>;
19
+ closeOnClick: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
20
+ visiblityTime: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ error: {
23
+ code: string;
24
+ message: string;
25
+ description?: string | undefined;
26
+ };
27
+ onClose: (...args: unknown[]) => void;
28
+ closeOnClick: boolean;
29
+ visiblityTime: number;
30
+ }, {
31
+ error: {
32
+ code: string;
33
+ message: string;
34
+ description?: string | undefined;
35
+ };
36
+ onClose: (...args: unknown[]) => void;
37
+ closeOnClick?: boolean | undefined;
38
+ visiblityTime?: number | undefined;
39
+ }>;
40
+ export type ErrorComponentType = z.infer<typeof ErrorComponentPropsSchema>;
41
+ export declare const DefaultErrorComponent: React.FC<ErrorComponentType>;
42
+ export default DefaultErrorComponent;
@@ -0,0 +1,4 @@
1
+ export * from "./CustomError";
2
+ export * from "./ErrorBoundary";
3
+ export * from "./ErrorContext";
4
+ export * from "./components/DefaultErrorComponents";
@@ -0,0 +1,5 @@
1
+ export declare class CustomError extends Error {
2
+ code: string;
3
+ description: string;
4
+ constructor(code: string, message: string, description: string);
5
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type WrapperPropsType = {
3
+ children: React.ReactNode;
4
+ };
5
+ export declare const ErrorBoundary: React.FC<WrapperPropsType>;
6
+ export {};
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { CustomError } from './CustomError';
3
+ import { ErrorComponentType } from './components/DefaultErrorComponents';
4
+ interface ContextType {
5
+ handleError: (error: Error) => void;
6
+ error: CustomError | null;
7
+ clearError: () => void;
8
+ }
9
+ interface ErrorProviderProps {
10
+ children: React.ReactNode;
11
+ ErrorComponent?: React.ComponentType<ErrorComponentType>;
12
+ autoHideDelay?: number;
13
+ onError?: () => void;
14
+ closeErrorComponetOnClick?: boolean;
15
+ }
16
+ export declare const ErrorProvider: React.FC<ErrorProviderProps>;
17
+ export declare const useError: () => ContextType;
18
+ export declare const useThrowError: () => (code: string, message: string, description: string) => void;
19
+ export {};
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import './style.css';
3
+ import React from "react";
4
+ declare const ErrorComponentPropsSchema: z.ZodObject<{
5
+ error: z.ZodObject<{
6
+ code: z.ZodString;
7
+ message: z.ZodString;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ code: string;
11
+ message: string;
12
+ description?: string | undefined;
13
+ }, {
14
+ code: string;
15
+ message: string;
16
+ description?: string | undefined;
17
+ }>;
18
+ onClose: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodVoid>;
19
+ closeOnClick: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
20
+ visiblityTime: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ error: {
23
+ code: string;
24
+ message: string;
25
+ description?: string | undefined;
26
+ };
27
+ onClose: (...args: unknown[]) => void;
28
+ closeOnClick: boolean;
29
+ visiblityTime: number;
30
+ }, {
31
+ error: {
32
+ code: string;
33
+ message: string;
34
+ description?: string | undefined;
35
+ };
36
+ onClose: (...args: unknown[]) => void;
37
+ closeOnClick?: boolean | undefined;
38
+ visiblityTime?: number | undefined;
39
+ }>;
40
+ export type ErrorComponentType = z.infer<typeof ErrorComponentPropsSchema>;
41
+ export declare const DefaultErrorComponent: React.FC<ErrorComponentType>;
42
+ export default DefaultErrorComponent;
@@ -0,0 +1,4 @@
1
+ export * from "./CustomError";
2
+ export * from "./ErrorBoundary";
3
+ export * from "./ErrorContext";
4
+ export * from "./components/DefaultErrorComponents";
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@heritsilavo/react-error-boundary",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "main": "./dist/react/index.js",
6
+ "module": "./dist/react/index.mjs",
7
+ "types": "./dist/react/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/react/index.mjs",
11
+ "require": "./dist/react/index.js",
12
+ "types": "./dist/react/index.d.ts"
13
+ },
14
+ "./next": {
15
+ "import": "./dist/next/index.mjs",
16
+ "require": "./dist/next/index.js",
17
+ "types": "./dist/next/index.d.ts"
18
+ }
19
+ },
20
+ "keywords": [
21
+ "react", "error", "boundary", "next", "typescript"
22
+ ],
23
+ "author": "heritsilavo (heritsilavo4835@gmail.com)",
24
+ "license": "ISC",
25
+ "description": "A React error boundary component for React and Next.js",
26
+ "files": ["dist"],
27
+ "peerDependencies": {
28
+ "react": "^18.0.0",
29
+ "react-dom": "^18.0.0",
30
+ "next": "^13.0.0"
31
+ },
32
+ "scripts": {
33
+ "build:react": "rollup -c rollup.react.config.js",
34
+ "build:next": "rollup -c rollup.next.config.js",
35
+ "build": "npm run build:react && npm run build:next"
36
+ },
37
+ "devDependencies": {
38
+ "@rollup/plugin-commonjs": "^24.0.0",
39
+ "@rollup/plugin-node-resolve": "^15.0.0",
40
+ "@rollup/plugin-typescript": "^11.0.0",
41
+ "@types/react": "^18.0.0",
42
+ "@types/react-dom": "^18.0.0",
43
+ "rollup": "^3.20.0",
44
+ "rollup-plugin-peer-deps-external": "^2.2.4",
45
+ "rollup-plugin-postcss": "^4.0.0",
46
+ "tslib": "^2.8.1",
47
+ "typescript": "^5.0.0",
48
+ "zod": "^3.23.8"
49
+ }
50
+ }