@gofreego/tsutils 0.1.6 → 0.1.7

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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode, CSSProperties } from 'react';
2
- import { IconButtonProps } from '@mui/material';
2
+ import { AlertColor, IconButtonProps } from '@mui/material';
3
3
  import { Highlighter } from 'shiki';
4
4
 
5
5
  /**
@@ -122,6 +122,77 @@ interface ReadmeViewerProps {
122
122
  }
123
123
  declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
124
124
 
125
+ /**
126
+ * Notification type representing a toast message
127
+ */
128
+ interface Notification {
129
+ id: string;
130
+ message: string;
131
+ type: AlertColor;
132
+ duration?: number;
133
+ }
134
+ /**
135
+ * Context interface for notification management
136
+ */
137
+ interface NotificationContextType {
138
+ showNotification: (message: string, type: AlertColor, duration?: number) => void;
139
+ success: (message: string, duration?: number) => void;
140
+ error: (message: string, duration?: number) => void;
141
+ warning: (message: string, duration?: number) => void;
142
+ info: (message: string, duration?: number) => void;
143
+ }
144
+ interface NotificationProviderProps {
145
+ /** Components to wrap with notification context */
146
+ children: ReactNode;
147
+ /** Default duration for notifications in milliseconds. Defaults to 6000ms */
148
+ defaultDuration?: number;
149
+ /** Maximum number of notifications to show at once. Defaults to 3 */
150
+ maxNotifications?: number;
151
+ /** Position of the notifications. Defaults to top-right */
152
+ anchorOrigin?: {
153
+ vertical: 'top' | 'bottom';
154
+ horizontal: 'left' | 'center' | 'right';
155
+ };
156
+ }
157
+ /**
158
+ * NotificationProvider manages toast notifications using Material-UI Snackbar and Alert.
159
+ * Provides methods to show success, error, warning, and info notifications.
160
+ *
161
+ * @example
162
+ * ```tsx
163
+ * <NotificationProvider>
164
+ * <App />
165
+ * </NotificationProvider>
166
+ * ```
167
+ *
168
+ * // In a component:
169
+ * ```tsx
170
+ * const { success, error } = useNotification()
171
+ * success('Operation completed!')
172
+ * error('Something went wrong')
173
+ * ```
174
+ */
175
+ declare const NotificationProvider: React.FC<NotificationProviderProps>;
176
+ /**
177
+ * Hook to access notification context
178
+ * Must be used within a NotificationProvider
179
+ *
180
+ * @example
181
+ * ```tsx
182
+ * const { success, error, warning, info } = useNotification()
183
+ *
184
+ * // Show notifications
185
+ * success('Data saved successfully!')
186
+ * error('Failed to save data')
187
+ * warning('This action cannot be undone')
188
+ * info('New update available')
189
+ *
190
+ * // With custom duration
191
+ * success('Quick message', 3000)
192
+ * ```
193
+ */
194
+ declare const useNotification: () => NotificationContextType;
195
+
125
196
  /**
126
197
  * Theme mode options
127
198
  * - 'light': Always use light theme
@@ -566,4 +637,4 @@ declare class PermissionManager {
566
637
  static hasPermission(permission: string): boolean;
567
638
  }
568
639
 
569
- export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useTheme, zIndex };
640
+ export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode, CSSProperties } from 'react';
2
- import { IconButtonProps } from '@mui/material';
2
+ import { AlertColor, IconButtonProps } from '@mui/material';
3
3
  import { Highlighter } from 'shiki';
4
4
 
5
5
  /**
@@ -122,6 +122,77 @@ interface ReadmeViewerProps {
122
122
  }
123
123
  declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
124
124
 
125
+ /**
126
+ * Notification type representing a toast message
127
+ */
128
+ interface Notification {
129
+ id: string;
130
+ message: string;
131
+ type: AlertColor;
132
+ duration?: number;
133
+ }
134
+ /**
135
+ * Context interface for notification management
136
+ */
137
+ interface NotificationContextType {
138
+ showNotification: (message: string, type: AlertColor, duration?: number) => void;
139
+ success: (message: string, duration?: number) => void;
140
+ error: (message: string, duration?: number) => void;
141
+ warning: (message: string, duration?: number) => void;
142
+ info: (message: string, duration?: number) => void;
143
+ }
144
+ interface NotificationProviderProps {
145
+ /** Components to wrap with notification context */
146
+ children: ReactNode;
147
+ /** Default duration for notifications in milliseconds. Defaults to 6000ms */
148
+ defaultDuration?: number;
149
+ /** Maximum number of notifications to show at once. Defaults to 3 */
150
+ maxNotifications?: number;
151
+ /** Position of the notifications. Defaults to top-right */
152
+ anchorOrigin?: {
153
+ vertical: 'top' | 'bottom';
154
+ horizontal: 'left' | 'center' | 'right';
155
+ };
156
+ }
157
+ /**
158
+ * NotificationProvider manages toast notifications using Material-UI Snackbar and Alert.
159
+ * Provides methods to show success, error, warning, and info notifications.
160
+ *
161
+ * @example
162
+ * ```tsx
163
+ * <NotificationProvider>
164
+ * <App />
165
+ * </NotificationProvider>
166
+ * ```
167
+ *
168
+ * // In a component:
169
+ * ```tsx
170
+ * const { success, error } = useNotification()
171
+ * success('Operation completed!')
172
+ * error('Something went wrong')
173
+ * ```
174
+ */
175
+ declare const NotificationProvider: React.FC<NotificationProviderProps>;
176
+ /**
177
+ * Hook to access notification context
178
+ * Must be used within a NotificationProvider
179
+ *
180
+ * @example
181
+ * ```tsx
182
+ * const { success, error, warning, info } = useNotification()
183
+ *
184
+ * // Show notifications
185
+ * success('Data saved successfully!')
186
+ * error('Failed to save data')
187
+ * warning('This action cannot be undone')
188
+ * info('New update available')
189
+ *
190
+ * // With custom duration
191
+ * success('Quick message', 3000)
192
+ * ```
193
+ */
194
+ declare const useNotification: () => NotificationContextType;
195
+
125
196
  /**
126
197
  * Theme mode options
127
198
  * - 'light': Always use light theme
@@ -566,4 +637,4 @@ declare class PermissionManager {
566
637
  static hasPermission(permission: string): boolean;
567
638
  }
568
639
 
569
- export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useTheme, zIndex };
640
+ export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
package/dist/index.js CHANGED
@@ -495,6 +495,82 @@ var ReadmeViewer = ({
495
495
  ) });
496
496
  };
497
497
  var ReadmeViewer_default = ReadmeViewer;
498
+ var NotificationContext = react.createContext(void 0);
499
+ var NotificationProvider = ({
500
+ children,
501
+ defaultDuration = 6e3,
502
+ maxNotifications = 3,
503
+ anchorOrigin = { vertical: "top", horizontal: "right" }
504
+ }) => {
505
+ const [notifications, setNotifications] = react.useState([]);
506
+ const showNotification = react.useCallback((message, type, duration = defaultDuration) => {
507
+ const id = `${Date.now()}-${Math.random()}`;
508
+ const newNotification = { id, message, type, duration };
509
+ setNotifications((prev) => {
510
+ const updated = [...prev, newNotification];
511
+ if (updated.length > maxNotifications) {
512
+ return updated.slice(updated.length - maxNotifications);
513
+ }
514
+ return updated;
515
+ });
516
+ }, [defaultDuration, maxNotifications]);
517
+ const handleClose = react.useCallback((id) => {
518
+ setNotifications((prev) => prev.filter((notif) => notif.id !== id));
519
+ }, []);
520
+ const success = react.useCallback((message, duration) => {
521
+ showNotification(message, "success", duration);
522
+ }, [showNotification]);
523
+ const error = react.useCallback((message, duration) => {
524
+ showNotification(message, "error", duration);
525
+ }, [showNotification]);
526
+ const warning = react.useCallback((message, duration) => {
527
+ showNotification(message, "warning", duration);
528
+ }, [showNotification]);
529
+ const info = react.useCallback((message, duration) => {
530
+ showNotification(message, "info", duration);
531
+ }, [showNotification]);
532
+ const contextValue = {
533
+ showNotification,
534
+ success,
535
+ error,
536
+ warning,
537
+ info
538
+ };
539
+ return /* @__PURE__ */ jsxRuntime.jsxs(NotificationContext.Provider, { value: contextValue, children: [
540
+ children,
541
+ notifications.map((notification, index) => /* @__PURE__ */ jsxRuntime.jsx(
542
+ material.Snackbar,
543
+ {
544
+ open: true,
545
+ autoHideDuration: notification.duration,
546
+ onClose: () => handleClose(notification.id),
547
+ anchorOrigin,
548
+ style: {
549
+ marginTop: index * 70
550
+ // Stack notifications vertically
551
+ },
552
+ children: /* @__PURE__ */ jsxRuntime.jsx(
553
+ material.Alert,
554
+ {
555
+ onClose: () => handleClose(notification.id),
556
+ severity: notification.type,
557
+ variant: "filled",
558
+ sx: { width: "100%" },
559
+ children: notification.message
560
+ }
561
+ )
562
+ },
563
+ notification.id
564
+ ))
565
+ ] });
566
+ };
567
+ var useNotification = () => {
568
+ const context = react.useContext(NotificationContext);
569
+ if (!context) {
570
+ throw new Error("useNotification must be used within a NotificationProvider");
571
+ }
572
+ return context;
573
+ };
498
574
 
499
575
  // src/theme/tokens.ts
500
576
  var tokens_exports = {};
@@ -1298,6 +1374,7 @@ PermissionManager.cachedPermissions = null;
1298
1374
  exports.AuthProvider = AuthProvider;
1299
1375
  exports.HttpClient = HttpClient;
1300
1376
  exports.LocalStorage = LocalStorage;
1377
+ exports.NotificationProvider = NotificationProvider;
1301
1378
  exports.PermissionManager = PermissionManager;
1302
1379
  exports.ReadmeViewer = ReadmeViewer_default;
1303
1380
  exports.SidebarLayout = SidebarLayout;
@@ -1319,6 +1396,7 @@ exports.throttle = throttle;
1319
1396
  exports.tokens = tokens_exports;
1320
1397
  exports.transition = transition;
1321
1398
  exports.useAuth = useAuth;
1399
+ exports.useNotification = useNotification;
1322
1400
  exports.useTheme = useTheme;
1323
1401
  exports.zIndex = zIndex;
1324
1402
  //# sourceMappingURL=index.js.map