react-hook-toolkit 1.2.3 → 1.2.4

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/README.md CHANGED
@@ -788,215 +788,6 @@ const { send, message, status } = useWebSocket('ws://api.example.com');
788
788
  // Example
789
789
  send(JSON.stringify({ action: 'ping' }));
790
790
  ```
791
- ---
792
-
793
- Let me know if you'd like more information or changes!
794
-
795
- ------------------------------------- **Custom Components** --------------------------------------------
796
-
797
- ✅ **DynamicLoader**
798
- A Higher-Order Component (HOC) that dynamically loads a React component using `React.lazy()` with `Suspense`, while wrapping it in an `ErrorBoundary` to handle potential errors gracefully. It ensures that the component is loaded only when needed, reducing the initial bundle size and improving performance.
799
-
800
- ```jsx
801
- import React, { lazy } from "react";
802
- const MyComponent = DynamicLoader(lazy(() => import("./MyComponent")));
803
-
804
- ```
805
- ---
806
-
807
- ✅ **ContextMenuWrapper**
808
- Displays a customizable context menu with support for light/dark themes, keyboard navigation, accessibility compliance, and automatic positioning. Handles items, dividers, icons, shortcuts, and click events.
809
-
810
- ```tsx
811
- <ContextMenuWrapper
812
- options={[
813
- { label: 'Edit', icon: <EditIcon />, onClick: handleEdit },
814
- { label: 'Copy', shortcut: '⌘C', onClick: handleCopy },
815
- 'divider',
816
- { label: 'Delete', disabled: true, onClick: handleDelete }
817
- ]}
818
- theme="dark"
819
- onShow={() => console.log('Menu opened')}
820
- onHide={() => console.log('Menu closed')}
821
- currentInstance={this}
822
- >
823
- <div>Right-click here</div>
824
- </ContextMenu>
825
- ```
826
-
827
- ✅ **AnimatedWrapper**
828
- A lightweight wrapper component that applies animations to its children with customizable animation type and delay.Ideal for enhancing UI transitions smoothly.
829
-
830
- ```tsx
831
- <AnimatedWrapper animationClass="animate__fadeIn" delay={1}>
832
- <div>Hello with delay</div>
833
- </AnimatedWrapper>
834
- ```
835
-
836
- ✅ **RichTextEditor**
837
- Provides a fully-featured WYSIWYG editor with HTML conversion, customizable toolbar, and responsive design for rich text input.
838
-
839
- ```tsx
840
- <RichTextEditor
841
- initialHtml="<p>Initial content</p>"
842
- onChange={(html) => console.log(html)}
843
- placeholder="Type your text here..."
844
- minHeight="300px"
845
- />
846
- ```
847
-
848
- ---
849
- ✅ **FilePreview**
850
- Displays a styled file card with an icon based on file type, filename with ellipsis handling, file size, and an optional download action.
851
-
852
- ```tsx
853
- <FilePreview
854
- primaryKey="file123"
855
- filename="example.pdf"
856
- size="2.3 MB"
857
- onDownload={(id) => console.log("Download:", id)}
858
- />
859
- ```
860
- ---
861
- ✅ **UploadFile**
862
- Renders an icon button for file uploads with visual feedback for different upload states (loading, success, error). It supports disabling, color customization, and a hidden file input for seamless UX.
863
-
864
- ```tsx
865
- <UploadFile
866
- isUpload={true}
867
- color="#1976d2"
868
- state={{
869
- isUploaded: false,
870
- isUploadError: false,
871
- isLoadingUpload: true,
872
- }}
873
- onFileSelect={(file) => console.log(file)}
874
- />
875
-
876
- const handleFileSelect = async (files: any) => {
877
- setState({ isUploaded: false, isUploadError: false, isLoadingUpload: true });
878
- try {
879
- await _promise(2000);
880
- setState({ isUploaded: true, isUploadError: false, isLoadingUpload: false });
881
- } catch (err) {
882
- setState({ isUploaded: false, isUploadError: true, isLoadingUpload: false });
883
- }
884
- };
885
- ```
886
- ---
887
-
888
- ✅ **DownloadFile**
889
- Renders an icon button for file downloads with visual feedback for different states (loading, success, error). It supports color customization and disables interaction during loading.
890
-
891
- ```tsx
892
- <DownloadFile
893
- isDownload={true}
894
- color="primary"
895
- state={{
896
- isDownloaded: false,
897
- isDownloadError: false,
898
- isLoadingDownload: true,
899
- }}
900
- onDownload={() => console.log('Download initiated')}
901
- />
902
- ```
903
-
904
- ---
905
-
906
- ✅ **LabeledValue**
907
- Displays a simple key-value label pair in a single line, with optional styling.
908
-
909
- ```tsx
910
- <LabeledValue
911
- label="Name"
912
- value="ABC"
913
- />
914
- ```
915
- ---
916
-
917
- ✅ **DetailsCard**
918
- Renders a card with a title and grid-based layout of labeled values. It supports custom spacing, responsive behavior, and optional card shadow.
919
-
920
- ```tsx
921
- <DetailsCard
922
- title="Details"
923
- spacing={2}
924
- details={[
925
- { label: 'Name', value: 'XYZ' },
926
- ]}
927
- />
928
- ```
929
-
930
- ---
931
- ✅ **AlertMessage**
932
- A functional React component that displays dynamic alerts using the enqueueSnackbar function. It provides a customizable message with a specified type and duration. The alerts can be dismissed manually by clicking a close button, and they support various configurations such as position, auto-hide duration, and duplicate prevention.
933
-
934
- ```jsx
935
- <AlertMessage type="success" msg="Data saved successfully!" />
936
- ```
937
- ---
938
- ✅ **FieldSkeleton**
939
- Simulates form field placeholders with optional label skeletons, useful for loading states in forms or input sections.
940
-
941
- ```jsx
942
- <FieldSkeleton
943
- length={3}
944
- spacing={2}
945
- isLabel={true}
946
- responsive={{ xs: 12, sm: 6, md: 4 }}
947
- />
948
- ```
949
- ---
950
-
951
- ✅ **FileSkeleton**
952
- Displays one or more placeholder file cards mimicking the layout of file previews. Useful during file list loading.
953
-
954
- ```tsx
955
- <FileSkeleton
956
- length={3}
957
- width={350}
958
- borderColor="#dfdfdf"
959
- />
960
- ```
961
-
962
- ---
963
-
964
- ✅ **TableSkeleton**
965
- Shows a full table layout with skeleton headers and rows. Includes a toolbar area for filters or search bars.
966
-
967
- ```tsx
968
- <TableSkeleton
969
- rows={6}
970
- columns={6}
971
- />
972
- ```
973
-
974
- ---
975
-
976
- ✅ **CardSkeleton**
977
- Simulates a card layout with a title and multiple row placeholders, ideal for stat or summary cards.
978
-
979
- ```tsx
980
- <CardSkeleton />
981
- ```
982
-
983
- ---
984
-
985
- ✅ **LineChartSkeleton**
986
- Represents a placeholder for a line chart with gridlines and axis lines to simulate loading of chart data.
987
-
988
- ```tsx
989
- <LineChartSkeleton />
990
- ```
991
-
992
- ---
993
-
994
- ✅ **PieChartSkeleton**
995
- Displays a skeleton placeholder for a pie chart inside a card layout. Includes a title and circular loading element.
996
-
997
- ```tsx
998
- <PieChartSkeleton />
999
- ```
1000
791
 
1001
792
  ---
1002
793
 
@@ -1,2 +1,7 @@
1
1
  import { UseBrowserControlsReturn } from "../type";
2
2
  export declare const useBrowser: () => UseBrowserControlsReturn;
3
+ export declare const useRouter: (initialPath: string) => {
4
+ pathname: string;
5
+ searchParams: URLSearchParams;
6
+ navigate: (path: string) => void;
7
+ };
@@ -43,7 +43,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
43
43
  }
44
44
  return to.concat(ar || Array.prototype.slice.call(from));
45
45
  };
46
- import { useCallback, useEffect, useState } from "react";
46
+ import { useCallback, useEffect, useMemo, useState } from "react";
47
47
  export var useBrowser = function () {
48
48
  var _a, _b;
49
49
  var _c = useState(new URL(window.location.href)), currentUrl = _c[0], setCurrentUrl = _c[1];
@@ -379,3 +379,15 @@ export var useBrowser = function () {
379
379
  closeCurrentTab: closeCurrentTab,
380
380
  };
381
381
  };
382
+ export var useRouter = function (initialPath) {
383
+ var _a = useState(initialPath), pathname = _a[0], setPathname = _a[1];
384
+ var searchParams = useState(function () { return new URLSearchParams(); })[0];
385
+ var router = useMemo(function () {
386
+ return {
387
+ pathname: pathname,
388
+ searchParams: searchParams,
389
+ navigate: function (path) { return setPathname(String(path)); },
390
+ };
391
+ }, [pathname, searchParams]);
392
+ return router;
393
+ };
@@ -1,10 +1 @@
1
- import React, { FC } from 'react';
2
- import { FileComponentProps, AlertPropsType, DetailsCardProps, UploadButtonProps, DownloadFileProps, ContextMenuProps } from '../type';
3
1
  export declare const DynamicLoader: (Component: any) => (props: any) => import("react/jsx-runtime").JSX.Element;
4
- export declare const AlertMessage: FC<AlertPropsType>;
5
- export declare const DetailsCard: ({ isLoading, title, details, spacing, boxShadow, background, loaderType, displayType, }: DetailsCardProps) => import("react/jsx-runtime").JSX.Element;
6
- export declare const LabeledValue: ({ label, value, style }: any) => import("react/jsx-runtime").JSX.Element;
7
- export declare const FilePreview: ({ primaryKey, filename, size, onDownload, width, borderColor, fileColor, isDownloading, }: FileComponentProps) => import("react/jsx-runtime").JSX.Element;
8
- export declare const UploadFile: React.FC<UploadButtonProps>;
9
- export declare const DownloadFile: React.FC<DownloadFileProps>;
10
- export declare const ContextMenuWrapper: React.FC<ContextMenuProps>;
@@ -9,17 +9,12 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
- import { forwardRef, useState } from 'react';
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
13
  import { useEffect, useCallback, useRef, Suspense } from 'react';
15
- import { Paper, MenuList, MenuItem, ListItemIcon, ListItemText, Divider, Typography, styled, Box, Alert, AlertTitle, IconButton, CardContent, Tooltip, Card, Grid, Skeleton, CircularProgress, } from '@mui/material';
16
- import { Close, InsertDriveFile, Image, Description, Download, CheckCircleOutlined, ErrorOutlineOutlined, Upload, } from '@mui/icons-material';
17
- import { useTheme } from '@mui/material/styles';
14
+ import { Box, Alert, AlertTitle } from '@mui/material';
18
15
  import NProgress from 'nprogress';
19
16
  import { ErrorBoundary } from 'react-error-boundary';
20
17
  import { promise } from '../utils';
21
- import { getHook } from '../chunk1415/chunk143';
22
- import { useWindowSize } from './chunk940514';
23
18
  function Fallback(_a) {
24
19
  var error = _a.error;
25
20
  return (_jsxs(Box, { sx: { padding: 2 }, children: [process.env.NODE_ENV === 'production' && (_jsxs(Alert, { sx: { py: 0, borderLeft: '2px solid #00abff !important', border: '1px solid #d0cfcf' }, severity: "info", children: [_jsx(AlertTitle, { children: "Page Loading Error" }), "Please check your network connection..."] })), process.env.NODE_ENV !== 'production' && (_jsxs(Alert, { severity: "error", sx: { py: 0, borderTop: '2px solid #791212ad !important', border: '1px solid #d0cfcf' }, children: [_jsx(AlertTitle, { children: "Error" }), error.message] }))] }));
@@ -55,245 +50,3 @@ var LoadingScreen = function () {
55
50
  };
56
51
  // prettier-ignore
57
52
  export var DynamicLoader = function (Component) { return function (props) { return (_jsx(Error, { children: _jsx(Suspense, { fallback: _jsx(LoadingScreen, {}), children: _jsx(Component, __assign({}, props)) }) })); }; };
58
- export var AlertMessage = function (_a) {
59
- var type = _a.type, msg = _a.msg, duration = _a.duration;
60
- var _b = getHook('snackBar'), enqueueSnackbar = _b.enqueueSnackbar, closeSnackbar = _b.closeSnackbar;
61
- if (msg !== undefined && msg !== '') {
62
- enqueueSnackbar(msg !== null && msg !== void 0 ? msg : '', {
63
- anchorOrigin: {
64
- // @shivaji perpose dyanamic global alert.
65
- horizontal: 'right',
66
- vertical: 'top',
67
- },
68
- variant: type,
69
- preventDuplicate: true,
70
- // persist: true, whenever you want to close.
71
- action: function (key) { return (_jsx(IconButton, { "aria-label": "close", size: "small", onClick: function () { return closeSnackbar(key); }, children: _jsx(Close, { fontSize: "small", sx: { color: '#fff' } }) })); },
72
- autoHideDuration: duration !== null && duration !== void 0 ? duration : 6000,
73
- });
74
- }
75
- return null;
76
- };
77
- export var DetailsCard = function (_a) {
78
- var _b = _a.isLoading, isLoading = _b === void 0 ? false : _b, title = _a.title, details = _a.details, _c = _a.spacing, spacing = _c === void 0 ? 2 : _c, _d = _a.boxShadow, boxShadow = _d === void 0 ? '0px 0px 2px 2px #d8d8d8' : _d, _e = _a.background, background = _e === void 0 ? '#eee' : _e, _f = _a.loaderType, loaderType = _f === void 0 ? 'skeleton' : _f, _g = _a.displayType, displayType = _g === void 0 ? 'flex' : _g;
79
- var width = useWindowSize().width;
80
- return (_jsx(Card, { sx: { boxShadow: boxShadow }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", sx: { background: background, padding: '4px' }, children: title }), _jsx(Grid, { container: true, spacing: spacing, sx: { mt: 1 }, children: details.filter(Boolean).map(function (item, index) { return (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 6, lg: width < 1367 ? 6 : 4, children: _jsxs(Box, { display: displayType, alignItems: "center", sx: { fontSize: '14px' }, children: [_jsxs(Typography, { fontWeight: "bold", component: "span", sx: { fontSize: '14px' }, children: [item === null || item === void 0 ? void 0 : item.label, ":\u00A0"] }), isLoading ? (loaderType === 'skeleton' ? (_jsx(Skeleton, { sx: { ml: 2 }, variant: "text", width: 100, height: 20 })) : (_jsx(CircularProgress, { sx: { ml: 2 }, color: "success", size: 18 }))) : (_jsx(Typography, { component: "span", sx: { fontSize: '14px' }, children: (item === null || item === void 0 ? void 0 : item.value) !== undefined && (item === null || item === void 0 ? void 0 : item.value) !== null && (item === null || item === void 0 ? void 0 : item.value) !== '' ? item.value : 'N/A' }))] }) }, index.toString())); }) })] }) }));
81
- };
82
- export var LabeledValue = function (_a) {
83
- var label = _a.label, value = _a.value, _b = _a.style, style = _b === void 0 ? undefined : _b;
84
- return (_jsx(_Fragment, { children: _jsx(Typography, { sx: style !== null && style !== void 0 ? style : { padding: '5px' }, children: _jsxs("span", { style: { fontSize: '13px' }, children: [_jsxs("b", { children: [label, " "] }), ": ", value !== null && value !== void 0 ? value : 'N/A'] }) }) }));
85
- };
86
- export var FilePreview = function (_a) {
87
- var primaryKey = _a.primaryKey, filename = _a.filename, size = _a.size, _b = _a.onDownload, onDownload = _b === void 0 ? undefined : _b, _c = _a.width, width = _c === void 0 ? 350 : _c, _d = _a.borderColor, borderColor = _d === void 0 ? '#dfdfdf' : _d, _e = _a.fileColor, fileColor = _e === void 0 ? 'primary' : _e, _f = _a.isDownloading, isDownloading = _f === void 0 ? false : _f;
88
- // Icon mapping configuration
89
- var iconMap = {
90
- pdf: _jsx(InsertDriveFile, { fontSize: "large", color: fileColor }),
91
- image: _jsx(Image, { fontSize: "large", color: fileColor }),
92
- doc: _jsx(Description, { fontSize: "large", color: fileColor }),
93
- default: _jsx(Description, { fontSize: "large", color: fileColor }),
94
- };
95
- // Determine file type from filename extension
96
- var getFileType = function (filenames) {
97
- var extension = filenames.split('.').pop().toLowerCase();
98
- if (['pdf'].includes(extension))
99
- return 'pdf';
100
- if (['jpg', 'jpeg', 'png', 'gif'].includes(extension))
101
- return 'image';
102
- if (['doc', 'docx', 'txt'].includes(extension))
103
- return 'doc';
104
- return 'default';
105
- };
106
- return (_jsx(Card, { variant: "outlined", sx: {
107
- maxWidth: width,
108
- minWidth: width,
109
- border: "1px solid ".concat(borderColor),
110
- borderRadius: 1,
111
- '&:hover': { boxShadow: 2 },
112
- marginLeft: 1,
113
- }, children: _jsxs(CardContent, { sx: {
114
- display: 'flex',
115
- alignItems: 'center',
116
- gap: 2,
117
- padding: '8px !important',
118
- }, children: [iconMap[getFileType(filename)], _jsxs(Box, { sx: { flexGrow: 1 }, children: [filename.length > 33 ? (_jsx(Tooltip, { title: filename, placement: "top", arrow: true, children: _jsx(Typography, { sx: {
119
- fontSize: '14px',
120
- whiteSpace: 'nowrap',
121
- overflow: 'hidden',
122
- textOverflow: 'ellipsis',
123
- maxWidth: width - 120,
124
- }, children: filename }) })) : (_jsx(Typography, { sx: {
125
- fontSize: '14px',
126
- whiteSpace: 'nowrap',
127
- overflow: 'hidden',
128
- textOverflow: 'ellipsis',
129
- maxWidth: width - 120,
130
- }, children: filename })), _jsx(Typography, { variant: "caption", color: "text.secondary", children: size })] }), _jsx(IconButton, { disabled: onDownload === undefined, "aria-label": "download", onClick: function () { return onDownload(primaryKey); }, sx: { color: '#dfdfdf', '&:hover': { color: 'primary.main' } }, children: isDownloading ? (_jsx(CircularProgress, { color: "success", size: 20 })) : (_jsx(Download, { fontSize: "small", color: onDownload ? 'primary' : 'inherit' })) })] }) }));
131
- };
132
- var VisuallyHiddenInput = forwardRef(function (props, ref) { return (_jsx("input", __assign({ ref: ref, type: "file", style: {
133
- position: 'absolute',
134
- width: 1,
135
- height: 1,
136
- padding: 0,
137
- overflow: 'hidden',
138
- clip: 'rect(0,0,0,0)',
139
- whiteSpace: 'nowrap',
140
- border: 0,
141
- } }, props))); });
142
- export var UploadFile = function (_a) {
143
- var _b = _a.isUpload, isUpload = _b === void 0 ? true : _b, color = _a.color, _c = _a.state, state = _c === void 0 ? {} : _c, onFileSelect = _a.onFileSelect;
144
- var onFileInputChange = function (e) {
145
- var _a;
146
- var file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
147
- if (file) {
148
- onFileSelect(file);
149
- e.target.value = '';
150
- }
151
- };
152
- return (_jsx(Tooltip, { title: "Upload", children: _jsxs(Box, { sx: { position: 'relative', display: 'inline-block' }, children: [_jsxs(IconButton, { disabled: !isUpload, component: "label", children: [(state === null || state === void 0 ? void 0 : state.isUploaded) ? (_jsx(CheckCircleOutlined, { color: "success" })) : (state === null || state === void 0 ? void 0 : state.isUploadError) ? (_jsx(ErrorOutlineOutlined, { color: "error" })) : (_jsx(Upload, { color: color !== null && color !== void 0 ? color : 'primary' })), _jsx(VisuallyHiddenInput, { onChange: onFileInputChange })] }), (state === null || state === void 0 ? void 0 : state.isLoadingUpload) && (_jsx(CircularProgress, { size: "40px", sx: {
153
- position: 'absolute',
154
- top: 0,
155
- left: 0,
156
- zIndex: 1,
157
- } }))] }) }));
158
- };
159
- export var DownloadFile = function (_a) {
160
- var _b = _a.isDownload, isDownload = _b === void 0 ? true : _b, color = _a.color, _c = _a.state, state = _c === void 0 ? {} : _c, onDownload = _a.onDownload;
161
- return (_jsx(Tooltip, { title: "Download", children: _jsxs(Box, { sx: { position: 'relative', display: 'inline-block' }, children: [_jsx(IconButton, { disabled: !isDownload || (state === null || state === void 0 ? void 0 : state.isLoadingDownload), onClick: onDownload, sx: {
162
- bgcolor: function (theme) { return (color ? (theme.palette.mode === 'dark' ? '#303041' : color) : 'default'); },
163
- }, children: (state === null || state === void 0 ? void 0 : state.isDownloaded) ? (_jsx(CheckCircleOutlined, { color: "success" })) : (state === null || state === void 0 ? void 0 : state.isDownloadError) ? (_jsx(ErrorOutlineOutlined, { color: "error" })) : (_jsx(Download, { color: color !== null && color !== void 0 ? color : 'primary' })) }), (state === null || state === void 0 ? void 0 : state.isLoadingDownload) && (_jsx(CircularProgress, { size: "40px", sx: {
164
- position: 'absolute',
165
- top: 0,
166
- left: 0,
167
- zIndex: 1,
168
- } }))] }) }));
169
- };
170
- var StyledMenuPaper = styled(Paper)(function (_a) {
171
- var theme = _a.theme;
172
- return ({
173
- minWidth: 200,
174
- padding: theme.spacing(0, 0),
175
- boxShadow: theme.shadows[3],
176
- '&.context-menu-dark': {
177
- backgroundColor: theme.palette.grey[800],
178
- color: theme.palette.common.white,
179
- },
180
- });
181
- });
182
- var StyledMenuItem = styled(MenuItem)(function (_a) {
183
- var theme = _a.theme;
184
- return ({
185
- padding: theme.spacing(0.5, 1),
186
- fontSize: '14px',
187
- '& .MuiListItemText-root': {
188
- '& .MuiTypography-root': {
189
- fontSize: '14px',
190
- },
191
- },
192
- '&.context-menu-item-dark': {
193
- color: theme.palette.common.white,
194
- '&:hover': {
195
- backgroundColor: theme.palette.grey[700],
196
- },
197
- },
198
- '&.context-menu-item--disabled': {
199
- opacity: 0.5,
200
- pointerEvents: 'none',
201
- },
202
- });
203
- });
204
- var ShortcutText = styled(Typography)(function (_a) {
205
- var theme = _a.theme;
206
- return ({
207
- marginLeft: theme.spacing(2),
208
- fontSize: '0.75rem',
209
- color: theme.palette.text.secondary,
210
- '&.context-menu-shortcut-dark': {
211
- color: theme.palette.grey[400],
212
- },
213
- });
214
- });
215
- export var ContextMenuWrapper = function (_a) {
216
- var options = _a.options, children = _a.children, disabled = _a.disabled, className = _a.className, menuClassName = _a.menuClassName, _b = _a.position, position = _b === void 0 ? 'auto' : _b, onShow = _a.onShow, onHide = _a.onHide, currentInstance = _a.currentInstance, _c = _a.theme, theme = _c === void 0 ? 'light' : _c;
217
- var muiTheme = useTheme();
218
- var _d = useState(false), isVisible = _d[0], setIsVisible = _d[1];
219
- var _e = useState({ x: 0, y: 0 }), menuPosition = _e[0], setMenuPosition = _e[1];
220
- var menuRef = useRef(null);
221
- var triggerRef = useRef(null);
222
- var handleContextMenu = function (e) {
223
- var _a, _b;
224
- e.preventDefault();
225
- if (disabled)
226
- return;
227
- var x = e.clientX;
228
- var y = e.clientY;
229
- if (position === 'auto') {
230
- var viewportWidth = window.innerWidth;
231
- var viewportHeight = window.innerHeight;
232
- var menuWidth = ((_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 200;
233
- var menuHeight = ((_b = menuRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 200;
234
- if (x + menuWidth > viewportWidth) {
235
- x = viewportWidth - menuWidth - 5;
236
- }
237
- if (y + menuHeight > viewportHeight) {
238
- y = viewportHeight - menuHeight - 5;
239
- }
240
- }
241
- setMenuPosition({ x: x, y: y });
242
- setIsVisible(true);
243
- onShow === null || onShow === void 0 ? void 0 : onShow();
244
- };
245
- var closeMenu = function () {
246
- setIsVisible(false);
247
- onHide === null || onHide === void 0 ? void 0 : onHide();
248
- };
249
- var handleClickOutside = function (e) {
250
- if (menuRef.current &&
251
- !menuRef.current.contains(e.target) &&
252
- triggerRef.current &&
253
- !triggerRef.current.contains(e.target)) {
254
- closeMenu();
255
- }
256
- };
257
- var handleKeyDown = function (e) {
258
- if (e.key === 'Escape') {
259
- closeMenu();
260
- }
261
- };
262
- var handleItemClick = function (item) {
263
- var _a;
264
- if (item.disabled)
265
- return;
266
- (_a = item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, currentInstance !== null && currentInstance !== void 0 ? currentInstance : item);
267
- closeMenu();
268
- };
269
- useEffect(function () {
270
- if (isVisible) {
271
- document.addEventListener('mousedown', handleClickOutside);
272
- document.addEventListener('keydown', handleKeyDown);
273
- }
274
- else {
275
- document.removeEventListener('mousedown', handleClickOutside);
276
- document.removeEventListener('keydown', handleKeyDown);
277
- }
278
- return function () {
279
- document.removeEventListener('mousedown', handleClickOutside);
280
- document.removeEventListener('keydown', handleKeyDown);
281
- };
282
- }, [isVisible]);
283
- return (_jsxs("div", { ref: triggerRef, className: "context-menu-trigger ".concat(className || ''), onContextMenu: handleContextMenu, children: [children, isVisible && (_jsx("div", { ref: menuRef, style: {
284
- position: 'fixed',
285
- left: "".concat(menuPosition.x, "px"),
286
- top: "".concat(menuPosition.y, "px"),
287
- zIndex: muiTheme.zIndex.modal,
288
- }, children: _jsx(StyledMenuPaper, { className: "".concat(menuClassName || '', " context-menu-").concat(theme), children: _jsx(MenuList, { children: options.map(function (item, index) {
289
- if (item === 'divider') {
290
- return _jsx(Divider, { className: "context-menu-divider-".concat(theme) }, "divider-".concat(index.toString()));
291
- }
292
- return (_jsxs(StyledMenuItem, { sx: { fontSize: '10px' }, className: "".concat(item.className || '', " context-menu-item-").concat(theme, " ").concat(item.disabled ? 'context-menu-item--disabled' : ''), onClick: function () { return handleItemClick(item); }, onKeyDown: function (e) {
293
- if (e.key === 'Enter' || e.key === ' ') {
294
- e.preventDefault();
295
- handleItemClick(item);
296
- }
297
- }, tabIndex: item.disabled ? -1 : 0, disabled: item.disabled, children: [item.icon && (_jsx(ListItemIcon, { sx: { marginRight: -1 }, className: "context-menu-icon-".concat(theme), children: item.icon })), _jsx(ListItemText, { className: "context-menu-text-".concat(theme), children: item.label }), item.shortcut && (_jsx(ShortcutText, { className: "context-menu-shortcut-".concat(theme), children: item.shortcut }))] }, item.key || index));
298
- }) }) }) }))] }));
299
- };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import 'nprogress/nprogress.css';
2
2
  import 'animate.css';
3
- import { DynamicLoader, AlertMessage, FilePreview, LabeledValue, DetailsCard, UploadFile, DownloadFile, ContextMenuWrapper } from './chunk1516/chunk613852';
3
+ import { DynamicLoader } from './chunk1516/chunk613852';
4
4
  import { ReactHooksWrapper, getHook, setHook } from './chunk1415/chunk143';
5
- import { FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton } from './chunk1617/chunk613555';
6
5
  import { useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, useRecentSearch, useSpeech, usePermission, usePageLeave, useMotion, useHoverDirty, useBeforeUnload, useClickAway, useResponsive, useUnmountedRef } from './chunk1516/chunk726433';
7
- import { useBrowser } from './chunk1516/chunk0022';
6
+ import { useBrowser, useRouter } from './chunk1516/chunk0022';
8
7
  import { privateAxios, publicAxios } from './chunk1213/chunk158862';
9
8
  declare const useDrawer: () => import("./chunk1213/chunk158261").DrawerContextValue;
10
9
  import { useGenericReducer, useArray, useAsync, useAxios, useClipboard, useCookie, useDarkMode, useDebounce, useDebouncedCallback, useDebouncedValue, useDelay, useRequest, useRequestRetry, useForm, useImageLoader, useIndexedDB, useInterval, useKeyPress, useLocalStorage, useMediaQuery, useMousePosition, useOnlineStatus, usePersistedState, usePrevious, useReducedMotion, useResizeObserver, useScrollDirection, useScrollLock, useScrollPosition, useScript, useStepper, useThrottle, useTimeout, useToggle, useVisibilityChange, useWindowSize } from './chunk1516/chunk940514';
11
10
  import { createOptimizedContext, useBattery, useCountDown, useCountUp, useCrossFieldValidation, useCss, useDragReorder, useEventListener, useEventListeners, useFieldArray, useFormSubmit, useFormWizard, useGeoLocation, useHistory, useInfiniteScroll, useIsMounted, usePersistedForm, usePreferredLanguage, useSessionStorage, useSmartForm, useSound, useSpeak, useTimer, useTouch, useUndo, useUpdateEffect, useWebSocket } from './chunk1516/chunk0021';
12
11
  import { DrawerProvider } from './chunk1213/chunk158261';
13
- import { AnimatedWrapper } from './chunk1617/chunk613557';
14
12
  export default ReactHooksWrapper;
15
- export { getHook, setHook, privateAxios, publicAxios, useGenericReducer, useArray, useAsync, useAxios, useBrowser, useBattery, useBeforeUnload, useClipboard, useCookie, useClickAway, useCountDown, useCountUp, useCrossFieldValidation, useCss, useDrawer, useDarkMode, useDebounce, useDebouncedCallback, useDebouncedValue, useDelay, useDragReorder, useEventListener, useEventListeners, useRequest, useRequestRetry, useFieldArray, useForm, useFormSubmit, useFormWizard, useGeoLocation, useHoverDirty, useHistory, useHistoryState, useIdle, useImageLoader, useIndexedDB, useInfiniteScroll, useInterval, useIsFirstRender, useIsMounted, useKeyPress, useList, useLocalStorage, useLockBodyScroll, useLongPress, useMotion, useMediaQuery, useMousePosition, useOnlineStatus, usePersistedForm, usePersistedState, usePreferredLanguage, usePrevious, usePermission, usePageLeave, useReducedMotion, useRecentSearch, useResponsive, useResizeObserver, useScript, useScrollDirection, useScrollLock, useScrollPosition, useSessionStorage, useSmartForm, useSound, useSpeech, useSpeak, useStepper, useThrottle, useTimeout, useTimer, useToggle, useTouch, useUnmountedRef, useUndo, useUpdateEffect, useVisibilityChange, useWebSocket, useWindowSize, AlertMessage, CardSkeleton, AnimatedWrapper, ContextMenuWrapper, DrawerProvider, DetailsCard, DownloadFile, DynamicLoader, FieldSkeleton, FilePreview, FileSkeleton, LineChartSkeleton, LabeledValue, PieChartSkeleton, TableSkeleton, UploadFile, createOptimizedContext, };
13
+ export { getHook, setHook, privateAxios, publicAxios, useGenericReducer, useArray, useAsync, useAxios, useBrowser, useBattery, useBeforeUnload, useClipboard, useCookie, useClickAway, useCountDown, useCountUp, useCrossFieldValidation, useCss, useDrawer, useDarkMode, useDebounce, useDebouncedCallback, useDebouncedValue, useDelay, useDragReorder, useEventListener, useEventListeners, useRequest, useRequestRetry, useFieldArray, useForm, useFormSubmit, useFormWizard, useGeoLocation, useHoverDirty, useHistory, useHistoryState, useIdle, useImageLoader, useIndexedDB, useInfiniteScroll, useInterval, useIsFirstRender, useIsMounted, useKeyPress, useList, useLocalStorage, useLockBodyScroll, useLongPress, useMotion, useMediaQuery, useMousePosition, useOnlineStatus, usePersistedForm, usePersistedState, usePreferredLanguage, usePrevious, usePermission, usePageLeave, useRouter, useReducedMotion, useRecentSearch, useResponsive, useResizeObserver, useScript, useScrollDirection, useScrollLock, useScrollPosition, useSessionStorage, useSmartForm, useSound, useSpeech, useSpeak, useStepper, useThrottle, useTimeout, useTimer, useToggle, useTouch, useUnmountedRef, useUndo, useUpdateEffect, useVisibilityChange, useWebSocket, useWindowSize, DrawerProvider, DynamicLoader, createOptimizedContext, };
package/dist/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import 'nprogress/nprogress.css';
2
2
  import 'animate.css';
3
- import { DynamicLoader, AlertMessage, FilePreview, LabeledValue, DetailsCard, UploadFile, DownloadFile, ContextMenuWrapper } from './chunk1516/chunk613852';
3
+ import { DynamicLoader } from './chunk1516/chunk613852';
4
4
  import { ReactHooksWrapper, getHook, setHook } from './chunk1415/chunk143';
5
- import { FileSkeleton, TableSkeleton, PieChartSkeleton, CardSkeleton, LineChartSkeleton, FieldSkeleton } from './chunk1617/chunk613555';
6
5
  import { useHistoryState, useIdle, useIsFirstRender, useList, useLockBodyScroll, useLongPress, useRecentSearch, useSpeech, usePermission, usePageLeave, useMotion, useHoverDirty, useBeforeUnload, useClickAway, useResponsive, useUnmountedRef } from './chunk1516/chunk726433';
7
- import { useBrowser } from './chunk1516/chunk0022';
6
+ import { useBrowser, useRouter } from './chunk1516/chunk0022';
8
7
  import { useContext } from 'react';
9
8
  import DrawerContext from './chunk1213/chunk158261';
10
9
  import { privateAxios, publicAxios } from './chunk1213/chunk158862';
@@ -12,6 +11,5 @@ var useDrawer = function () { return useContext(DrawerContext); };
12
11
  import { useGenericReducer, useArray, useAsync, useAxios, useClipboard, useCookie, useDarkMode, useDebounce, useDebouncedCallback, useDebouncedValue, useDelay, useRequest, useRequestRetry, useForm, useImageLoader, useIndexedDB, useInterval, useKeyPress, useLocalStorage, useMediaQuery, useMousePosition, useOnlineStatus, usePersistedState, usePrevious, useReducedMotion, useResizeObserver, useScrollDirection, useScrollLock, useScrollPosition, useScript, useStepper, useThrottle, useTimeout, useToggle, useVisibilityChange, useWindowSize, } from './chunk1516/chunk940514';
13
12
  import { createOptimizedContext, useBattery, useCountDown, useCountUp, useCrossFieldValidation, useCss, useDragReorder, useEventListener, useEventListeners, useFieldArray, useFormSubmit, useFormWizard, useGeoLocation, useHistory, useInfiniteScroll, useIsMounted, usePersistedForm, usePreferredLanguage, useSessionStorage, useSmartForm, useSound, useSpeak, useTimer, useTouch, useUndo, useUpdateEffect, useWebSocket } from './chunk1516/chunk0021';
14
13
  import { DrawerProvider } from './chunk1213/chunk158261';
15
- import { AnimatedWrapper } from './chunk1617/chunk613557';
16
14
  export default ReactHooksWrapper;
17
- export { getHook, setHook, privateAxios, publicAxios, useGenericReducer, useArray, useAsync, useAxios, useBrowser, useBattery, useBeforeUnload, useClipboard, useCookie, useClickAway, useCountDown, useCountUp, useCrossFieldValidation, useCss, useDrawer, useDarkMode, useDebounce, useDebouncedCallback, useDebouncedValue, useDelay, useDragReorder, useEventListener, useEventListeners, useRequest, useRequestRetry, useFieldArray, useForm, useFormSubmit, useFormWizard, useGeoLocation, useHoverDirty, useHistory, useHistoryState, useIdle, useImageLoader, useIndexedDB, useInfiniteScroll, useInterval, useIsFirstRender, useIsMounted, useKeyPress, useList, useLocalStorage, useLockBodyScroll, useLongPress, useMotion, useMediaQuery, useMousePosition, useOnlineStatus, usePersistedForm, usePersistedState, usePreferredLanguage, usePrevious, usePermission, usePageLeave, useReducedMotion, useRecentSearch, useResponsive, useResizeObserver, useScript, useScrollDirection, useScrollLock, useScrollPosition, useSessionStorage, useSmartForm, useSound, useSpeech, useSpeak, useStepper, useThrottle, useTimeout, useTimer, useToggle, useTouch, useUnmountedRef, useUndo, useUpdateEffect, useVisibilityChange, useWebSocket, useWindowSize, AlertMessage, CardSkeleton, AnimatedWrapper, ContextMenuWrapper, DrawerProvider, DetailsCard, DownloadFile, DynamicLoader, FieldSkeleton, FilePreview, FileSkeleton, LineChartSkeleton, LabeledValue, PieChartSkeleton, TableSkeleton, UploadFile, createOptimizedContext, };
15
+ export { getHook, setHook, privateAxios, publicAxios, useGenericReducer, useArray, useAsync, useAxios, useBrowser, useBattery, useBeforeUnload, useClipboard, useCookie, useClickAway, useCountDown, useCountUp, useCrossFieldValidation, useCss, useDrawer, useDarkMode, useDebounce, useDebouncedCallback, useDebouncedValue, useDelay, useDragReorder, useEventListener, useEventListeners, useRequest, useRequestRetry, useFieldArray, useForm, useFormSubmit, useFormWizard, useGeoLocation, useHoverDirty, useHistory, useHistoryState, useIdle, useImageLoader, useIndexedDB, useInfiniteScroll, useInterval, useIsFirstRender, useIsMounted, useKeyPress, useList, useLocalStorage, useLockBodyScroll, useLongPress, useMotion, useMediaQuery, useMousePosition, useOnlineStatus, usePersistedForm, usePersistedState, usePreferredLanguage, usePrevious, usePermission, usePageLeave, useRouter, useReducedMotion, useRecentSearch, useResponsive, useResizeObserver, useScript, useScrollDirection, useScrollLock, useScrollPosition, useSessionStorage, useSmartForm, useSound, useSpeech, useSpeak, useStepper, useThrottle, useTimeout, useTimer, useToggle, useTouch, useUnmountedRef, useUndo, useUpdateEffect, useVisibilityChange, useWebSocket, useWindowSize, DrawerProvider, DynamicLoader, createOptimizedContext, };
package/dist/type.d.ts CHANGED
@@ -12,66 +12,6 @@ export interface DrawerContextValue {
12
12
  export interface DrawerProviderProps {
13
13
  children: ReactNode;
14
14
  }
15
- export interface FileComponentProps {
16
- primaryKey: string | number;
17
- filename: string;
18
- size: string | number;
19
- onDownload?: any;
20
- width?: number;
21
- borderColor?: string;
22
- fileColor?: 'inherit' | 'primary' | 'secondary' | 'error' | 'disabled' | 'action';
23
- isDownloading: boolean;
24
- }
25
- export interface AlertPropsType {
26
- type: string;
27
- msg: string;
28
- duration?: number;
29
- }
30
- export interface DetailsCardProps {
31
- isLoading?: boolean;
32
- title: string;
33
- details: any[];
34
- spacing?: number;
35
- boxShadow?: string;
36
- background?: string;
37
- loaderType?: 'skeleton' | 'circular';
38
- displayType?: 'flex' | 'block';
39
- }
40
- export interface UploadButtonProps {
41
- isUpload?: boolean;
42
- color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning';
43
- state?: {
44
- isUploaded?: boolean;
45
- isUploadError?: boolean;
46
- isLoadingUpload?: boolean;
47
- };
48
- onFileSelect: (file: File) => void;
49
- }
50
- export interface DownloadButtonState {
51
- isDownloaded?: boolean;
52
- isDownloadError?: boolean;
53
- isLoadingDownload?: boolean;
54
- }
55
- export interface DownloadFileProps {
56
- isDownload?: boolean;
57
- color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning';
58
- state?: DownloadButtonState;
59
- onDownload: () => void;
60
- }
61
- type MenuPosition = 'auto' | 'fixed';
62
- type ThemeMode = 'light' | 'dark';
63
- export interface ContextMenuProps {
64
- options: any;
65
- children: React.ReactNode;
66
- disabled?: boolean;
67
- className?: string;
68
- menuClassName?: string;
69
- position?: MenuPosition;
70
- onShow?: () => void;
71
- onHide?: () => void;
72
- currentInstance?: any;
73
- theme?: ThemeMode;
74
- }
75
15
  export interface UndoableHistoryState<T> {
76
16
  past: T[];
77
17
  present: T;
@@ -283,4 +223,3 @@ export interface AnimatedWrapperProps {
283
223
  delay?: any;
284
224
  children: React.ReactNode;
285
225
  }
286
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-toolkit",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Ultimate package for React developers, offering a powerful collection of hooks and components to enhance their development experience.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",