@js-smart/react-kit 1.0.0 → 1.0.2

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.
Files changed (61) hide show
  1. package/index.d.ts +21 -0
  2. package/index.js +208 -0
  3. package/index.mjs +14350 -0
  4. package/lib/components/CenteredCircularProgress.d.ts +7 -0
  5. package/lib/components/ConfirmationDialog.d.ts +11 -0
  6. package/lib/components/DismissibleAlert.d.ts +18 -0
  7. package/lib/components/OpenInNewIconLink.d.ts +18 -0
  8. package/lib/components/ReactIf.d.ts +14 -0
  9. package/lib/components/buttons/CancelButton.d.ts +26 -0
  10. package/lib/components/buttons/DeleteButton.d.ts +14 -0
  11. package/lib/components/buttons/ExcelButton.d.ts +26 -0
  12. package/lib/components/buttons/GoBackButton.d.ts +8 -0
  13. package/lib/components/buttons/HistoryButton.d.ts +26 -0
  14. package/lib/components/buttons/LoadingSuccessButton.d.ts +26 -0
  15. package/lib/components/buttons/ManageButton.d.ts +11 -0
  16. package/lib/components/buttons/SuccessButton.d.ts +26 -0
  17. package/lib/components/snack-bar/AppSnackBar.d.ts +7 -0
  18. package/lib/components/snack-bar/QuerySnackBar.d.ts +18 -0
  19. package/lib/constants/AppConstants.d.ts +15 -0
  20. package/lib/types/ProgressState.d.ts +7 -0
  21. package/lib/utils/BooleanUtils.d.ts +7 -0
  22. package/lib/utils/DateUtils.d.ts +22 -0
  23. package/lib/utils/NumberUtils.d.ts +7 -0
  24. package/lib/utils/ProgressStateUtils.d.ts +39 -0
  25. package/lib/utils/StringUtils.d.ts +7 -0
  26. package/lib/utils/UrlUtils.d.ts +11 -0
  27. package/package.json +20 -1
  28. package/style.css +0 -0
  29. package/.babelrc +0 -12
  30. package/.eslintrc.json +0 -18
  31. package/README.md +0 -7
  32. package/project.json +0 -10
  33. package/src/index.ts +0 -29
  34. package/src/lib/components/CenteredCircularProgress.tsx +0 -16
  35. package/src/lib/components/ConfirmationDialog.tsx +0 -40
  36. package/src/lib/components/DismissibleAlert.tsx +0 -64
  37. package/src/lib/components/OpenInNewIconLink.tsx +0 -28
  38. package/src/lib/components/ReactIf.tsx +0 -13
  39. package/src/lib/components/buttons/CancelButton.tsx +0 -39
  40. package/src/lib/components/buttons/DeleteButton.tsx +0 -29
  41. package/src/lib/components/buttons/ExcelButton.tsx +0 -39
  42. package/src/lib/components/buttons/GoBackButton.tsx +0 -14
  43. package/src/lib/components/buttons/HistoryButton.tsx +0 -39
  44. package/src/lib/components/buttons/LoadingSuccessButton.tsx +0 -50
  45. package/src/lib/components/buttons/ManageButton.tsx +0 -26
  46. package/src/lib/components/buttons/SuccessButton.tsx +0 -38
  47. package/src/lib/components/snack-bar/AppSnackBar.tsx +0 -46
  48. package/src/lib/components/snack-bar/QuerySnackBar.tsx +0 -62
  49. package/src/lib/constants/AppConstants.ts +0 -17
  50. package/src/lib/react-kit.module.scss +0 -22
  51. package/src/lib/types/ProgressState.ts +0 -7
  52. package/src/lib/utils/BooleanUtils.ts +0 -13
  53. package/src/lib/utils/DateUtils.ts +0 -43
  54. package/src/lib/utils/NumberUtils.ts +0 -12
  55. package/src/lib/utils/ProgressStateUtils.ts +0 -74
  56. package/src/lib/utils/StringUtils.ts +0 -14
  57. package/src/lib/utils/UrlUtils.ts +0 -19
  58. package/tsconfig.json +0 -21
  59. package/tsconfig.lib.json +0 -23
  60. package/tsconfig.spec.json +0 -26
  61. package/vite.config.ts +0 -63
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Reusable Circular Progress component
3
+ *
4
+ * @author Pavan Kumar Jadda
5
+ * @since 0.1.0
6
+ */
7
+ export declare function CenteredCircularProgress(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ interface ConfirmDialogProps {
2
+ id: string;
3
+ keepMounted: boolean;
4
+ title?: string;
5
+ message: string;
6
+ value: string;
7
+ open: boolean;
8
+ onClose: (value: string) => void;
9
+ }
10
+ export declare function ConfirmDialog(props: ConfirmDialogProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,18 @@
1
+ import { AlertColor } from '@mui/material';
2
+
3
+ /**
4
+ * Dismissible Alert properties
5
+ *
6
+ * @author Pavan Kumar Jadda
7
+ * @since 0.2.17
8
+ */
9
+ type DismissibleAlertProps = {
10
+ message: string;
11
+ severity: AlertColor;
12
+ className?: string;
13
+ dismissible?: boolean;
14
+ dismissOnTimeOut?: boolean;
15
+ dismissTimeOut?: number;
16
+ };
17
+ export declare function DismissibleAlert(props: DismissibleAlertProps): import("react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -0,0 +1,18 @@
1
+ import { default as React } from 'react';
2
+
3
+ interface OpenInNewIconLinkProps {
4
+ href: string;
5
+ linkText: string;
6
+ target: string;
7
+ children?: React.ReactNode;
8
+ }
9
+ /**
10
+ * Reusable component to open a link in new tab and show open new icon at the end
11
+ *
12
+ * @param props Properties of the component
13
+ *
14
+ * @author Pavan Kumar Jadda
15
+ * @since 1.2.24
16
+ */
17
+ export declare function OpenInNewIconLink(props: OpenInNewIconLinkProps): import("react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -0,0 +1,14 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Reusable If component, that renders content if the condition is true. Similar to *ngIf from Angular
5
+ *
6
+ * @param props Properties of the React Node
7
+ *
8
+ * @author Pavan Kumar Jadda
9
+ * @since 0.1.0
10
+ */
11
+ export declare function ReactIf(props: {
12
+ condition: boolean | undefined;
13
+ children: React.ReactNode;
14
+ }): React.JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ import { SxProps, Theme } from '@mui/material';
3
+
4
+ /**
5
+ * Reusable Success Button component properties
6
+ *
7
+ * @author Pavan Kumar Jadda
8
+ * @since 1.2.14
9
+ */
10
+ interface CancelButtonProps {
11
+ children?: React.ReactNode;
12
+ className?: string;
13
+ dataCy?: string;
14
+ sx?: SxProps<Theme>;
15
+ type?: 'button' | 'submit' | 'reset';
16
+ onClick: () => void;
17
+ startIcon?: React.ReactNode;
18
+ }
19
+ /**
20
+ * Reusable Cancel Button component
21
+ *
22
+ * @author Pavan Kumar Jadda
23
+ * @since 1.2.14
24
+ */
25
+ export declare function CancelButton(props: CancelButtonProps): React.JSX.Element;
26
+ export {};
@@ -0,0 +1,14 @@
1
+ import { default as React } from 'react';
2
+
3
+ interface DeleteButtonProps {
4
+ loading: boolean;
5
+ label?: string;
6
+ loadingLabel?: string;
7
+ loadingPosition?: 'start' | 'end' | 'center';
8
+ type?: 'button' | 'submit' | 'reset' | undefined;
9
+ dataCy?: string;
10
+ startIcon?: React.ReactNode;
11
+ onClick: () => void;
12
+ }
13
+ export declare function DeleteButton(props: DeleteButtonProps): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ import { SxProps, Theme } from '@mui/material';
3
+
4
+ /**
5
+ * Reusable Excel Button component properties
6
+ *
7
+ * @author Pavan Kumar Jadda
8
+ * @since 1.2.9
9
+ */
10
+ interface SuccessButtonProps {
11
+ children?: React.ReactNode;
12
+ className?: string;
13
+ sx?: SxProps<Theme>;
14
+ type?: 'button' | 'submit' | 'reset';
15
+ onClick: () => void;
16
+ startIcon?: React.ReactNode;
17
+ dataCy?: string;
18
+ }
19
+ /**
20
+ * Reusable Excel Button component
21
+ *
22
+ * @author Pavan Kumar Jadda
23
+ * @since 1.2.9
24
+ */
25
+ export declare function ExcelButton(props: SuccessButtonProps): React.JSX.Element;
26
+ export {};
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+
3
+ interface GoBackButtonProps {
4
+ onClick: () => void;
5
+ children?: React.ReactNode;
6
+ }
7
+ export declare function GoBackButton(props: GoBackButtonProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ import { SxProps, Theme } from '@mui/material';
3
+
4
+ /**
5
+ * Reusable History Button component properties
6
+ *
7
+ * @author Pavan Kumar Jadda
8
+ * @since 1.2.15
9
+ */
10
+ interface HistoryButtonProps {
11
+ children?: React.ReactNode;
12
+ className?: string;
13
+ dataCy?: string;
14
+ sx?: SxProps<Theme>;
15
+ type?: 'button' | 'submit' | 'reset';
16
+ onClick: () => void;
17
+ startIcon?: React.ReactNode;
18
+ }
19
+ /**
20
+ * Reusable History Button component
21
+ *
22
+ * @author Pavan Kumar Jadda
23
+ * @since 1.2.15
24
+ */
25
+ export declare function HistoryButton(props: HistoryButtonProps): React.JSX.Element;
26
+ export {};
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ import { SxProps, Theme } from '@mui/material';
3
+
4
+ /**
5
+ * Reusable Success Button component properties
6
+ *
7
+ * @author Pavan Kumar Jadda
8
+ * @since 0.3.3
9
+ */
10
+ interface Props {
11
+ children?: React.ReactNode;
12
+ type?: 'button' | 'submit' | 'reset';
13
+ loading: boolean;
14
+ dataCy?: string;
15
+ startIcon?: React.ReactNode;
16
+ sx?: SxProps<Theme>;
17
+ onClick?: () => void;
18
+ }
19
+ /**
20
+ * Reusable Success Loading Button
21
+ *
22
+ * @author Pavan Kumar Jadda
23
+ * @since 0.1.0
24
+ */
25
+ export declare function LoadingSuccessButton(props: Props): import("react/jsx-runtime").JSX.Element;
26
+ export {};
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+
3
+ interface ManageButtonProps {
4
+ size?: 'small' | 'medium' | 'large';
5
+ dataCy?: string;
6
+ startIcon?: React.ReactNode;
7
+ onClick: () => void;
8
+ children?: React.ReactNode;
9
+ }
10
+ export declare function ManageButton(props: ManageButtonProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ import { SxProps, Theme } from '@mui/material';
3
+
4
+ /**
5
+ * Reusable Success Button component properties
6
+ *
7
+ * @author Pavan Kumar Jadda
8
+ * @since 0.3.3
9
+ */
10
+ interface SuccessButtonProps {
11
+ children?: React.ReactNode;
12
+ className?: string;
13
+ dataCy?: string;
14
+ sx?: SxProps<Theme>;
15
+ type?: 'button' | 'submit' | 'reset';
16
+ onClick: () => void;
17
+ startIcon?: React.ReactNode;
18
+ }
19
+ /**
20
+ * Reusable Success Button component
21
+ *
22
+ * @author Pavan Kumar Jadda
23
+ * @since 0.1.0
24
+ */
25
+ export declare function SuccessButton(props: SuccessButtonProps): React.JSX.Element;
26
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ProgressState } from '../../types/ProgressState';
2
+
3
+ export declare const AppSnackBar: (props: {
4
+ open: boolean;
5
+ progressState: ProgressState;
6
+ autoHideDuration?: number;
7
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ interface QuerySnackBarProps {
2
+ open: boolean;
3
+ isPending?: boolean;
4
+ isSuccess: boolean;
5
+ isError: boolean;
6
+ message: string;
7
+ autoHideDuration?: number;
8
+ }
9
+ /**
10
+ * Reusable component to display snackbar based on React Query mutation state
11
+ *
12
+ * @param props QuerySnackBarProps
13
+ *
14
+ * @author Pavan Kumar Jadda
15
+ * @since 1.2.27
16
+ */
17
+ export declare const QuerySnackBar: (props: QuerySnackBarProps) => import("react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Global System settings used in the application
3
+ *
4
+ * @author Pavan Kumar Jadda
5
+ * @since 1.0.0
6
+ */
7
+ export declare enum SystemConfig {
8
+ SYSTEM_TIME_ZONE = "America/New_York",
9
+ SYSTEM_LOCALE = "en-US",
10
+ SYSTEM_DATE_FORMAT = "MM/dd/yyyy",
11
+ SYSTEM_DATE_TIME_FORMAT = "MM/dd/yyyy hh:mm:ss a",
12
+ ISO_DATE_FORMAT = "yyyy-MM-dd",
13
+ SYSTEM_COOKIE_TIMEOUT_HOURS = 24,
14
+ SYSTEM_COOKIE_TIMEOUT_MILLI_SECONDS = 3600000
15
+ }
@@ -0,0 +1,7 @@
1
+ export interface ProgressState {
2
+ loading: boolean;
3
+ success: boolean;
4
+ error: boolean;
5
+ complete: boolean;
6
+ message: string;
7
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns `true` if the provided string is `undefined`, `null` or empty '' string otherwise returns false
3
+ *
4
+ * @author Pavan Kumar Jadda
5
+ * @since 0.1.0
6
+ */
7
+ export declare function parseBoolean(value: boolean | string | null | undefined): boolean;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Sets Cookie expiration to 24 hours. By default, server sets 60 minutes expiration but after each API request it extends to another 60 minutes. In client side set 24 hours as expiration date,
3
+ * if the user hasn't refreshed web page in 60 minutes, they would get HTTP 401 error and redirected to login page. And redirect URL will be stored in cookie
4
+ *
5
+ * @author Pavan Kumar Jadda
6
+ * @since 0.2.30
7
+ */
8
+ export declare const setCookieExpirationDate: () => Date;
9
+ /**
10
+ * Convert String format browser Date Time to ISO Date
11
+ *
12
+ * @author Pavan Kumar Jadda
13
+ * @since 0.2.30
14
+ */
15
+ export declare const convertToIsoDate: (currentDateTime: string) => string;
16
+ /**
17
+ * Convert String format browser Date Time to ISO Date
18
+ *
19
+ * @author Pavan Kumar Jadda
20
+ * @since 0.2.30
21
+ */
22
+ export declare const formatDate: (date: string | undefined, newFormat: string) => string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns number parsed from the given string
3
+ *
4
+ * @author Pavan Kumar Jadda
5
+ * @since 0.3.5
6
+ */
7
+ export declare function parseNumber(value: string | null | undefined): number | undefined;
@@ -0,0 +1,39 @@
1
+ import { ProgressState } from '../types/ProgressState';
2
+
3
+ /**
4
+ * Initialize Loading or Update ProgressState
5
+ *
6
+ * @return Updated State Object
7
+ *
8
+ * @author Pavan Kumar Jadda
9
+ * @since 1.4.6
10
+ */
11
+ export declare const initializeState: () => ProgressState;
12
+ /**
13
+ * Initialize Loading or Update ProgressState
14
+ *
15
+ * @param progressState Object to initialize
16
+ * @return ProgressState Updated State Object
17
+ *
18
+ * @author Pavan Kumar Jadda
19
+ * @since 0.2.30
20
+ */
21
+ export declare const markLoading: (progressState: ProgressState) => ProgressState;
22
+ /**
23
+ * Update state as success
24
+ *
25
+ * @return ProgressState Updated State Object
26
+ *
27
+ * @author Pavan Kumar Jadda
28
+ * @since 0.2.30
29
+ */
30
+ export declare const markSuccess: (progressState: ProgressState, message?: string) => ProgressState;
31
+ /**
32
+ * Update state as failure or error
33
+ *
34
+ * @return ProgressState Updated State Object
35
+ *
36
+ * @author Pavan Kumar Jadda
37
+ * @since 0.2.30
38
+ */
39
+ export declare const markError: (progressState: ProgressState, message?: string) => ProgressState;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns `true` if the provided string is `undefined`, `null` or empty '' string otherwise returns false
3
+ *
4
+ * @author Pavan Kumar Jadda
5
+ * @since 0.1.0
6
+ */
7
+ export declare function isBlankOrEmpty(value: any): boolean;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks if the given URL is encoded or not
3
+ *
4
+ * @param url The URL to check
5
+ *
6
+ * @returns True if the URL is encoded, false otherwise
7
+ *
8
+ * @author Pavan Kumar Jadda
9
+ * @since 1.3.14
10
+ */
11
+ export declare const isEncoded: (url: string) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@js-smart/react-kit",
3
3
  "private": false,
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
7
7
  "publishConfig": {
@@ -12,5 +12,24 @@
12
12
  "import": "./index.mjs",
13
13
  "require": "./index.js"
14
14
  }
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/js-smart/react-kit"
19
+ },
20
+ "author": {
21
+ "name": "Pavan Kumar Jadda",
22
+ "email": "contactdeveloperpj@gmail.com"
23
+ },
24
+ "keywords": [
25
+ "react",
26
+ "react-kit",
27
+ "react-components",
28
+ "react-utils",
29
+ "typescript"
30
+ ],
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/js-smart/react-kit/issues"
15
34
  }
16
35
  }
package/style.css ADDED
File without changes
package/.babelrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@nx/react/babel",
5
- {
6
- "runtime": "automatic",
7
- "useBuiltIns": "usage"
8
- }
9
- ]
10
- ],
11
- "plugins": []
12
- }
package/.eslintrc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": ["plugin:@nx/react", "../.eslintrc.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {}
8
- },
9
- {
10
- "files": ["*.ts", "*.tsx"],
11
- "rules": {}
12
- },
13
- {
14
- "files": ["*.js", "*.jsx"],
15
- "rules": {}
16
- }
17
- ]
18
- }
package/README.md DELETED
@@ -1,7 +0,0 @@
1
- # react-kit
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Running unit tests
6
-
7
- Run `nx test react-kit` to execute the unit tests via [Vitest](https://vitest.dev/).
package/project.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "name": "react-kit",
3
- "$schema": "../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "react-kit/src",
5
- "projectType": "library",
6
- "tags": [],
7
- "// targets": "to see all targets run: nx show project react-kit --web",
8
- "targets": {
9
- }
10
- }
package/src/index.ts DELETED
@@ -1,29 +0,0 @@
1
- // Export all buttons
2
- export * from './lib/components/buttons/CancelButton';
3
- //export * from './lib/components/buttons/DeleteButton';
4
- export { default as DeleteButton } from './lib/components/buttons/DeleteButton';
5
- export * from './lib/components/buttons/ExcelButton';
6
- export * from './lib/components/buttons/GoBackButton';
7
- export * from './lib/components/buttons/HistoryButton';
8
- export * from './lib/components/buttons/LoadingSuccessButton';
9
- export * from './lib/components/buttons/ManageButton';
10
- export * from './lib/components/buttons/SuccessButton';
11
-
12
- // Export snackbar components
13
- export * from './lib/components/snack-bar/AppSnackBar';
14
- export * from './lib/components/snack-bar/QuerySnackBar';
15
-
16
- // Export all other components
17
- export * from './lib/components/CenteredCircularProgress';
18
- export * from './lib/components/ConfirmationDialog';
19
- export * from './lib/components/DismissibleAlert';
20
- export * from './lib/components/OpenInNewIconLink';
21
- export * from './lib/components/ReactIf';
22
-
23
- // Export all utilities
24
- export * from './lib/utils/BooleanUtils';
25
- export * from './lib/utils/DateUtils';
26
- export * from './lib/utils/NumberUtils';
27
- export * from './lib/utils/ProgressStateUtils';
28
- export * from './lib/utils/StringUtils';
29
- export * from './lib/utils/UrlUtils';
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { CircularProgress } from '@mui/material';
3
-
4
- /**
5
- * Reusable Circular Progress component
6
- *
7
- * @author Pavan Kumar Jadda
8
- * @since 0.1.0
9
- */
10
- export default function CenteredCircularProgress() {
11
- return (
12
- <div style={{ margin: '15px' }} className="custom-flex-justify-center">
13
- <CircularProgress />
14
- </div>
15
- );
16
- }
@@ -1,40 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- Button,
4
- Dialog,
5
- DialogActions,
6
- DialogContent,
7
- DialogTitle,
8
- } from '@mui/material';
9
-
10
- interface ConfirmDialogProps {
11
- id: string;
12
- keepMounted: boolean;
13
- title?: string;
14
- message: string;
15
- value: string;
16
- open: boolean;
17
- onClose: (value: string) => void;
18
- }
19
-
20
- export function ConfirmDialog(props: ConfirmDialogProps) {
21
- const { onClose, title, message, open, ...other } = props;
22
-
23
- return (
24
- <Dialog
25
- sx={{ '& .MuiDialog-paper': { width: '80%', maxHeight: 435 } }}
26
- maxWidth="xs"
27
- open={open}
28
- {...other}
29
- >
30
- <DialogTitle>{title ?? 'Confirm'}</DialogTitle>
31
- <DialogContent dividers>{message}</DialogContent>
32
- <DialogActions>
33
- <Button autoFocus onClick={() => onClose('No')}>
34
- Cancel
35
- </Button>
36
- <Button onClick={() => onClose('Yes')}>Yes</Button>
37
- </DialogActions>
38
- </Dialog>
39
- );
40
- }
@@ -1,64 +0,0 @@
1
- import { Alert, AlertColor, IconButton } from '@mui/material';
2
- import React, { useState } from 'react';
3
- import CloseIcon from '@mui/icons-material/Close';
4
-
5
- /**
6
- * Dismissible Alert properties
7
- *
8
- * @author Pavan Kumar Jadda
9
- * @since 0.2.17
10
- */
11
- type DismissibleAlertProps = {
12
- message: string;
13
- severity: AlertColor;
14
- className?: string;
15
- dismissible?: boolean;
16
- dismissOnTimeOut?: boolean;
17
- dismissTimeOut?: number;
18
- };
19
-
20
- function DismissibleAlert(props: DismissibleAlertProps) {
21
- const [open, setOpen] = useState(true);
22
- const [dismissible] = useState(props.dismissible ?? true);
23
- const [dismissOnTimeOut] = useState(props.dismissOnTimeOut ?? true);
24
- const [dismissTimeOut] = useState<number>(props.dismissTimeOut ?? 5000);
25
-
26
- /**
27
- * If `dismissOnTimeOut` is set then Dismiss the alert on time out
28
- *
29
- * @author Pavan Kumar Jadda
30
- * @since 0.2.17
31
- */
32
- setTimeout(() => {
33
- dismissOnTimeOut ? setOpen(false) : setOpen(open);
34
- }, dismissTimeOut);
35
-
36
- return (
37
- <>
38
- {open && (
39
- <Alert
40
- action={
41
- dismissible ? (
42
- <IconButton
43
- aria-label="close"
44
- color="inherit"
45
- size="small"
46
- onClick={() => {
47
- setOpen(false);
48
- }}>
49
- <CloseIcon fontSize="inherit" />
50
- </IconButton>
51
- ) : (
52
- <></>
53
- )
54
- }
55
- style={{ margin: '20px' }}
56
- {...props}>
57
- {props.message}
58
- </Alert>
59
- )}
60
- </>
61
- );
62
- }
63
-
64
- export default DismissibleAlert;