@true-tech-team/react-components 0.0.4 → 0.0.5
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 +138 -0
- package/index.css +1 -1
- package/index.d.ts +10 -0
- package/index.js +1 -1
- package/index.mjs +10539 -6746
- package/lib/components/buttons/ButtonToggleGroup/ButtonToggleGroup.d.ts +79 -0
- package/lib/components/buttons/ButtonToggleGroup/ButtonToggleGroupContext.d.ts +38 -0
- package/lib/components/buttons/ButtonToggleGroup/ButtonToggleGroupItem.d.ts +37 -0
- package/lib/components/buttons/ButtonToggleGroup/index.d.ts +7 -0
- package/lib/components/buttons/ToggleButton/ToggleButton.d.ts +96 -0
- package/lib/components/buttons/ToggleButton/index.d.ts +3 -0
- package/lib/components/display/Icon/icons/BookmarkFilled.d.ts +3 -0
- package/lib/components/display/Icon/icons/ChevronsLeft.d.ts +3 -0
- package/lib/components/display/Icon/icons/ChevronsRight.d.ts +3 -0
- package/lib/components/display/Icon/icons/HeartFilled.d.ts +3 -0
- package/lib/components/display/Icon/icons/More.d.ts +3 -0
- package/lib/components/display/Icon/icons/StarFilled.d.ts +3 -0
- package/lib/components/display/Icon/icons/ThumbsUpFilled.d.ts +3 -0
- package/lib/components/display/Icon/icons/index.d.ts +15 -1
- package/lib/components/display/OverflowText/OverflowText.d.ts +81 -0
- package/lib/components/display/OverflowText/index.d.ts +2 -0
- package/lib/components/display/ScrollArea/ScrollArea.d.ts +112 -0
- package/lib/components/display/ScrollArea/index.d.ts +3 -0
- package/lib/components/display/Tabs/Tab.d.ts +41 -0
- package/lib/components/display/Tabs/TabList.d.ts +27 -0
- package/lib/components/display/Tabs/TabPanel.d.ts +31 -0
- package/lib/components/display/Tabs/Tabs.d.ts +90 -0
- package/lib/components/display/Tabs/TabsContext.d.ts +63 -0
- package/lib/components/display/Tabs/index.d.ts +11 -0
- package/lib/components/display/TruncatedList/TruncatedList.d.ts +69 -0
- package/lib/components/display/TruncatedList/index.d.ts +2 -0
- package/lib/components/display/index.d.ts +3 -0
- package/lib/components/index.d.ts +44 -0
- package/lib/components/inputs/CheckboxGroup/CheckboxGroup.d.ts +122 -0
- package/lib/components/inputs/CheckboxGroup/CheckboxGroupContext.d.ts +42 -0
- package/lib/components/inputs/CheckboxGroup/CheckboxGroupItem.d.ts +50 -0
- package/lib/components/inputs/CheckboxGroup/index.d.ts +7 -0
- package/lib/components/layout/AdaptiveGrid/AdaptiveGrid.d.ts +100 -0
- package/lib/components/layout/AdaptiveGrid/index.d.ts +2 -0
- package/lib/components/layout/MasonryLayout/MasonryLayout.d.ts +74 -0
- package/lib/components/layout/MasonryLayout/index.d.ts +2 -0
- package/lib/components/layout/Panes/Pane.d.ts +72 -0
- package/lib/components/layout/Panes/Panes.d.ts +75 -0
- package/lib/components/layout/Panes/PanesContext.d.ts +60 -0
- package/lib/components/layout/Panes/index.d.ts +6 -0
- package/lib/components/layout/ResponsiveStack/ResponsiveStack.d.ts +99 -0
- package/lib/components/layout/ResponsiveStack/index.d.ts +2 -0
- package/lib/components/layout/index.d.ts +4 -0
- package/lib/components/navigation/BottomNavigation/BottomNavigation.d.ts +53 -0
- package/lib/components/navigation/BottomNavigation/BottomNavigationContext.d.ts +27 -0
- package/lib/components/navigation/BottomNavigation/BottomNavigationItem.d.ts +59 -0
- package/lib/components/navigation/BottomNavigation/index.d.ts +7 -0
- package/lib/components/navigation/Breadcrumbs/BreadcrumbItem.d.ts +37 -0
- package/lib/components/navigation/Breadcrumbs/BreadcrumbSeparator.d.ts +22 -0
- package/lib/components/navigation/Breadcrumbs/Breadcrumbs.d.ts +96 -0
- package/lib/components/navigation/Breadcrumbs/index.d.ts +9 -0
- package/lib/components/navigation/Breadcrumbs/useBreadcrumbsFromPath.d.ts +73 -0
- package/lib/components/navigation/CollapsibleSidebar/CollapsibleSidebar.d.ts +113 -0
- package/lib/components/navigation/CollapsibleSidebar/index.d.ts +2 -0
- package/lib/components/navigation/NavLink/NavLink.d.ts +74 -0
- package/lib/components/navigation/NavLink/index.d.ts +3 -0
- package/lib/components/navigation/Navbar/Navbar.d.ts +81 -0
- package/lib/components/navigation/Navbar/NavbarActions.d.ts +21 -0
- package/lib/components/navigation/Navbar/NavbarBrand.d.ts +29 -0
- package/lib/components/navigation/Navbar/NavbarCollapse.d.ts +26 -0
- package/lib/components/navigation/Navbar/NavbarContext.d.ts +50 -0
- package/lib/components/navigation/Navbar/NavbarNav.d.ts +22 -0
- package/lib/components/navigation/Navbar/NavbarToggle.d.ts +21 -0
- package/lib/components/navigation/Navbar/index.d.ts +15 -0
- package/lib/components/navigation/Pagination/Pagination.d.ts +99 -0
- package/lib/components/navigation/Pagination/index.d.ts +3 -0
- package/lib/components/navigation/SideNav/SideNav.d.ts +89 -0
- package/lib/components/navigation/SideNav/SideNavContext.d.ts +43 -0
- package/lib/components/navigation/SideNav/SideNavDivider.d.ts +22 -0
- package/lib/components/navigation/SideNav/SideNavGroup.d.ts +44 -0
- package/lib/components/navigation/SideNav/SideNavItem.d.ts +71 -0
- package/lib/components/navigation/SideNav/index.d.ts +11 -0
- package/lib/components/navigation/Stepper/Step.d.ts +57 -0
- package/lib/components/navigation/Stepper/Stepper.d.ts +80 -0
- package/lib/components/navigation/Stepper/StepperContext.d.ts +58 -0
- package/lib/components/navigation/Stepper/index.d.ts +7 -0
- package/lib/components/navigation/index.d.ts +16 -0
- package/lib/components/overlays/Alert/Alert.d.ts +102 -0
- package/lib/components/overlays/Alert/AlertContext.d.ts +94 -0
- package/lib/components/overlays/Alert/AlertPresets.d.ts +42 -0
- package/lib/components/overlays/Alert/AlertProvider.d.ts +40 -0
- package/lib/components/overlays/Alert/index.d.ts +11 -0
- package/lib/components/overlays/Dialog/Dialog.d.ts +197 -0
- package/lib/components/overlays/Dialog/DialogContext.d.ts +75 -0
- package/lib/components/overlays/Dialog/DialogProvider.d.ts +30 -0
- package/lib/components/overlays/Dialog/index.d.ts +9 -0
- package/lib/components/overlays/Toast/Toast.d.ts +103 -0
- package/lib/components/overlays/Toast/ToastContainer.d.ts +37 -0
- package/lib/components/overlays/Toast/ToastContext.d.ts +126 -0
- package/lib/components/overlays/Toast/ToastProvider.d.ts +71 -0
- package/lib/components/overlays/Toast/index.d.ts +11 -0
- package/lib/hooks/index.d.ts +10 -0
- package/lib/hooks/useAlert/index.d.ts +2 -0
- package/lib/hooks/useAlert/useAlert.d.ts +99 -0
- package/lib/hooks/useAsyncToast/index.d.ts +2 -0
- package/lib/hooks/useAsyncToast/useAsyncToast.d.ts +93 -0
- package/lib/hooks/useDialog/index.d.ts +2 -0
- package/lib/hooks/useDialog/useDialog.d.ts +58 -0
- package/lib/hooks/useResizeObserver/index.d.ts +2 -0
- package/lib/hooks/useResizeObserver/useResizeObserver.d.ts +69 -0
- package/lib/hooks/useToast/index.d.ts +2 -0
- package/lib/hooks/useToast/useToast.d.ts +97 -0
- package/lib/providers/GlobalProvider/GlobalProvider.d.ts +16 -1
- package/package.json +1 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { IconName } from '../../display/Icon/icons';
|
|
3
|
+
import { BaseComponentProps } from '../../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Toast position options
|
|
6
|
+
*/
|
|
7
|
+
export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
8
|
+
/**
|
|
9
|
+
* Toast variant types
|
|
10
|
+
*/
|
|
11
|
+
export type ToastVariant = 'info' | 'success' | 'warning' | 'error' | 'loading';
|
|
12
|
+
/**
|
|
13
|
+
* Toast animation state
|
|
14
|
+
*/
|
|
15
|
+
export type ToastAnimationState = 'entering' | 'entered' | 'exiting' | 'exited';
|
|
16
|
+
/**
|
|
17
|
+
* Single toast props
|
|
18
|
+
*/
|
|
19
|
+
export interface ToastProps extends BaseComponentProps {
|
|
20
|
+
/**
|
|
21
|
+
* Unique toast ID
|
|
22
|
+
*/
|
|
23
|
+
id: string;
|
|
24
|
+
/**
|
|
25
|
+
* Toast variant
|
|
26
|
+
* @default 'info'
|
|
27
|
+
*/
|
|
28
|
+
variant?: ToastVariant;
|
|
29
|
+
/**
|
|
30
|
+
* Toast title
|
|
31
|
+
*/
|
|
32
|
+
title?: ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* Toast message/description
|
|
35
|
+
*/
|
|
36
|
+
message?: ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Custom icon (overrides variant default)
|
|
39
|
+
*/
|
|
40
|
+
icon?: IconName | ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Hide the icon
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
hideIcon?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Duration in milliseconds (0 for persistent)
|
|
48
|
+
* @default 5000
|
|
49
|
+
*/
|
|
50
|
+
duration?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Whether toast can be dismissed by user
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
dismissible?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Action button configuration
|
|
58
|
+
*/
|
|
59
|
+
action?: {
|
|
60
|
+
label: string;
|
|
61
|
+
onClick: () => void;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Callback when toast is dismissed
|
|
65
|
+
*/
|
|
66
|
+
onDismiss?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to show progress bar for duration
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
showProgress?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether to pause duration on hover
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
pauseOnHover?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Custom render function for toast content
|
|
79
|
+
*/
|
|
80
|
+
render?: (props: {
|
|
81
|
+
toast: ToastProps;
|
|
82
|
+
dismiss: () => void;
|
|
83
|
+
}) => ReactNode;
|
|
84
|
+
/**
|
|
85
|
+
* Animation state (managed by container)
|
|
86
|
+
*/
|
|
87
|
+
animationState?: ToastAnimationState;
|
|
88
|
+
/**
|
|
89
|
+
* Animation duration in ms
|
|
90
|
+
* @default 200
|
|
91
|
+
*/
|
|
92
|
+
animationDuration?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Position (for animation direction)
|
|
95
|
+
*/
|
|
96
|
+
position?: ToastPosition;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Toast component
|
|
100
|
+
* Single toast notification with auto-dismiss and actions
|
|
101
|
+
*/
|
|
102
|
+
export declare const Toast: React.FC<ToastProps>;
|
|
103
|
+
export default Toast;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../../types';
|
|
3
|
+
import { ToastPosition } from './Toast';
|
|
4
|
+
/**
|
|
5
|
+
* Toast container props
|
|
6
|
+
*/
|
|
7
|
+
export interface ToastContainerProps extends BaseComponentProps {
|
|
8
|
+
/**
|
|
9
|
+
* Position for toasts
|
|
10
|
+
* @default 'top-right'
|
|
11
|
+
*/
|
|
12
|
+
position?: ToastPosition;
|
|
13
|
+
/**
|
|
14
|
+
* Gap between toasts in pixels
|
|
15
|
+
* @default 12
|
|
16
|
+
*/
|
|
17
|
+
gap?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Offset from viewport edge
|
|
20
|
+
* @default 16
|
|
21
|
+
*/
|
|
22
|
+
offset?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Custom z-index
|
|
25
|
+
*/
|
|
26
|
+
zIndex?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Children (toast elements)
|
|
29
|
+
*/
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Toast container component
|
|
34
|
+
* Positions and stacks toast notifications
|
|
35
|
+
*/
|
|
36
|
+
export declare const ToastContainer: React.FC<ToastContainerProps>;
|
|
37
|
+
export default ToastContainer;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ToastProps, ToastPosition } from './Toast';
|
|
2
|
+
/**
|
|
3
|
+
* Toast data for creating new toasts
|
|
4
|
+
*/
|
|
5
|
+
export interface ToastData extends Omit<ToastProps, 'id' | 'animationState' | 'onDismiss'> {
|
|
6
|
+
/**
|
|
7
|
+
* Optional ID (auto-generated if not provided)
|
|
8
|
+
*/
|
|
9
|
+
id?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Toast instance with full props and internal state
|
|
13
|
+
*/
|
|
14
|
+
export interface ToastInstance extends ToastProps {
|
|
15
|
+
/**
|
|
16
|
+
* Timestamp when toast was created
|
|
17
|
+
*/
|
|
18
|
+
createdAt: number;
|
|
19
|
+
/**
|
|
20
|
+
* Timestamp when toast was paused (if paused)
|
|
21
|
+
*/
|
|
22
|
+
pausedAt?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Remaining duration when paused
|
|
25
|
+
*/
|
|
26
|
+
remainingDuration?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Promise toast options
|
|
30
|
+
*/
|
|
31
|
+
export interface PromiseToastOptions<T> {
|
|
32
|
+
/**
|
|
33
|
+
* Message or data to show while loading
|
|
34
|
+
*/
|
|
35
|
+
loading: string | Partial<ToastData>;
|
|
36
|
+
/**
|
|
37
|
+
* Message or data to show on success
|
|
38
|
+
* Can be a function that receives the result
|
|
39
|
+
*/
|
|
40
|
+
success: string | Partial<ToastData> | ((data: T) => string | Partial<ToastData>);
|
|
41
|
+
/**
|
|
42
|
+
* Message or data to show on error
|
|
43
|
+
* Can be a function that receives the error
|
|
44
|
+
*/
|
|
45
|
+
error: string | Partial<ToastData> | ((error: Error) => string | Partial<ToastData>);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Toast context value
|
|
49
|
+
*/
|
|
50
|
+
export interface ToastContextValue {
|
|
51
|
+
/**
|
|
52
|
+
* Current toast instances
|
|
53
|
+
*/
|
|
54
|
+
toasts: ToastInstance[];
|
|
55
|
+
/**
|
|
56
|
+
* Add a new toast
|
|
57
|
+
* @returns Toast ID
|
|
58
|
+
*/
|
|
59
|
+
addToast: (data: ToastData) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Remove a toast by ID
|
|
62
|
+
*/
|
|
63
|
+
removeToast: (id: string) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Update a toast
|
|
66
|
+
*/
|
|
67
|
+
updateToast: (id: string, data: Partial<ToastData>) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Remove all toasts
|
|
70
|
+
*/
|
|
71
|
+
removeAllToasts: () => void;
|
|
72
|
+
/**
|
|
73
|
+
* Pause a toast's timer
|
|
74
|
+
*/
|
|
75
|
+
pauseToast: (id: string) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Resume a toast's timer
|
|
78
|
+
*/
|
|
79
|
+
resumeToast: (id: string) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Show a success toast
|
|
82
|
+
*/
|
|
83
|
+
success: (message: string, options?: Partial<ToastData>) => string;
|
|
84
|
+
/**
|
|
85
|
+
* Show an error toast
|
|
86
|
+
*/
|
|
87
|
+
error: (message: string, options?: Partial<ToastData>) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Show a warning toast
|
|
90
|
+
*/
|
|
91
|
+
warning: (message: string, options?: Partial<ToastData>) => string;
|
|
92
|
+
/**
|
|
93
|
+
* Show an info toast
|
|
94
|
+
*/
|
|
95
|
+
info: (message: string, options?: Partial<ToastData>) => string;
|
|
96
|
+
/**
|
|
97
|
+
* Show a loading toast
|
|
98
|
+
*/
|
|
99
|
+
loading: (message: string, options?: Partial<ToastData>) => string;
|
|
100
|
+
/**
|
|
101
|
+
* Promise-based toast that shows loading, then success/error
|
|
102
|
+
* @returns Original promise result
|
|
103
|
+
*/
|
|
104
|
+
promise: <T>(promise: Promise<T>, options: PromiseToastOptions<T>) => Promise<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Container position
|
|
107
|
+
*/
|
|
108
|
+
position: ToastPosition;
|
|
109
|
+
/**
|
|
110
|
+
* Maximum visible toasts
|
|
111
|
+
*/
|
|
112
|
+
maxVisible: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Toast context
|
|
116
|
+
*/
|
|
117
|
+
export declare const ToastContext: import('react').Context<ToastContextValue | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Hook to access toast context (returns null if not in provider)
|
|
120
|
+
*/
|
|
121
|
+
export declare function useToastContext(): ToastContextValue | null;
|
|
122
|
+
/**
|
|
123
|
+
* Hook to access toast context (throws if not in provider)
|
|
124
|
+
* @throws Error if used outside of ToastProvider
|
|
125
|
+
*/
|
|
126
|
+
export declare function useToastContextStrict(): ToastContextValue;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ToastPosition } from './Toast';
|
|
3
|
+
import { ToastData } from './ToastContext';
|
|
4
|
+
/**
|
|
5
|
+
* Toast provider props
|
|
6
|
+
*/
|
|
7
|
+
export interface ToastProviderProps {
|
|
8
|
+
/**
|
|
9
|
+
* Children to render
|
|
10
|
+
*/
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Position for toasts
|
|
14
|
+
* @default 'top-right'
|
|
15
|
+
*/
|
|
16
|
+
position?: ToastPosition;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum number of visible toasts
|
|
19
|
+
* @default 5
|
|
20
|
+
*/
|
|
21
|
+
maxVisible?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Gap between toasts in pixels
|
|
24
|
+
* @default 12
|
|
25
|
+
*/
|
|
26
|
+
gap?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Offset from viewport edge
|
|
29
|
+
* @default 16
|
|
30
|
+
*/
|
|
31
|
+
offset?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Default duration for toasts in milliseconds
|
|
34
|
+
* @default 5000
|
|
35
|
+
*/
|
|
36
|
+
defaultDuration?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Animation duration in milliseconds
|
|
39
|
+
* @default 200
|
|
40
|
+
*/
|
|
41
|
+
animationDuration?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Default props to apply to all toasts
|
|
44
|
+
*/
|
|
45
|
+
defaultToastProps?: Partial<ToastData>;
|
|
46
|
+
/**
|
|
47
|
+
* Custom z-index for toast container
|
|
48
|
+
*/
|
|
49
|
+
zIndex?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Toast provider component
|
|
53
|
+
* Manages a stack of toasts for programmatic creation
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* <ToastProvider position="top-right" maxVisible={5}>
|
|
58
|
+
* <App />
|
|
59
|
+
* </ToastProvider>
|
|
60
|
+
*
|
|
61
|
+
* // In a component:
|
|
62
|
+
* const toast = useToast();
|
|
63
|
+
*
|
|
64
|
+
* toast.success('Changes saved successfully');
|
|
65
|
+
* toast.error('Failed to save changes');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function ToastProvider({ children, position, maxVisible, gap, offset, defaultDuration, animationDuration, defaultToastProps, zIndex, }: ToastProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
69
|
+
export declare namespace ToastProvider {
|
|
70
|
+
var displayName: string;
|
|
71
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toast component exports
|
|
3
|
+
*/
|
|
4
|
+
export { Toast } from './Toast';
|
|
5
|
+
export type { ToastProps, ToastPosition, ToastVariant, ToastAnimationState, } from './Toast';
|
|
6
|
+
export { ToastContainer } from './ToastContainer';
|
|
7
|
+
export type { ToastContainerProps } from './ToastContainer';
|
|
8
|
+
export { ToastProvider } from './ToastProvider';
|
|
9
|
+
export type { ToastProviderProps } from './ToastProvider';
|
|
10
|
+
export { ToastContext, useToastContext, useToastContextStrict, } from './ToastContext';
|
|
11
|
+
export type { ToastContextValue, ToastData, ToastInstance, PromiseToastOptions, } from './ToastContext';
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -9,3 +9,13 @@ export type { UsePopoverPositionOptions, UsePopoverPositionReturn, } from './use
|
|
|
9
9
|
export { useHover } from './useHover';
|
|
10
10
|
export type { UseHoverOptions, UseHoverReturn, HoverProps } from './useHover';
|
|
11
11
|
export { useDebounce } from './useDebounce';
|
|
12
|
+
export { useDialog } from './useDialog';
|
|
13
|
+
export type { UseDialogOptions, UseDialogReturn } from './useDialog';
|
|
14
|
+
export { useAlert } from './useAlert';
|
|
15
|
+
export type { UseAlertOptions, UseAlertReturn } from './useAlert';
|
|
16
|
+
export { useToast } from './useToast';
|
|
17
|
+
export type { UseToastOptions, UseToastReturn } from './useToast';
|
|
18
|
+
export { useAsyncToast } from './useAsyncToast';
|
|
19
|
+
export type { UseAsyncToastReturn, AsyncToastConfig } from './useAsyncToast';
|
|
20
|
+
export { useResizeObserver } from './useResizeObserver';
|
|
21
|
+
export type { UseResizeObserverOptions, UseResizeObserverReturn } from './useResizeObserver';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AlertProps } from '../../components/overlays/Alert';
|
|
2
|
+
/**
|
|
3
|
+
* Hook options
|
|
4
|
+
*/
|
|
5
|
+
export interface UseAlertOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Default props to apply to all alerts
|
|
8
|
+
*/
|
|
9
|
+
defaultProps?: Partial<AlertProps>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook return type
|
|
13
|
+
*/
|
|
14
|
+
export interface UseAlertReturn {
|
|
15
|
+
/**
|
|
16
|
+
* Show a custom alert
|
|
17
|
+
* @returns Promise<boolean> - true if confirmed, false if cancelled
|
|
18
|
+
*/
|
|
19
|
+
alert: (props: Omit<AlertProps, 'isOpen' | 'onConfirm' | 'onCancel'>) => Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Show a confirmation dialog
|
|
22
|
+
* @param title - Alert title
|
|
23
|
+
* @param description - Alert description
|
|
24
|
+
* @param options - Additional alert options
|
|
25
|
+
* @returns Promise<boolean> - true if confirmed, false if cancelled
|
|
26
|
+
*/
|
|
27
|
+
confirm: (title: string, description?: string, options?: Partial<AlertProps>) => Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Show an error alert
|
|
30
|
+
* @param title - Alert title
|
|
31
|
+
* @param description - Alert description
|
|
32
|
+
* @param options - Additional alert options
|
|
33
|
+
* @returns Promise<boolean> - true when dismissed
|
|
34
|
+
*/
|
|
35
|
+
error: (title: string, description?: string, options?: Partial<AlertProps>) => Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Show a success alert
|
|
38
|
+
* @param title - Alert title
|
|
39
|
+
* @param description - Alert description
|
|
40
|
+
* @param options - Additional alert options
|
|
41
|
+
* @returns Promise<boolean> - true when dismissed
|
|
42
|
+
*/
|
|
43
|
+
success: (title: string, description?: string, options?: Partial<AlertProps>) => Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Show a warning alert
|
|
46
|
+
* @param title - Alert title
|
|
47
|
+
* @param description - Alert description
|
|
48
|
+
* @param options - Additional alert options
|
|
49
|
+
* @returns Promise<boolean> - true when dismissed
|
|
50
|
+
*/
|
|
51
|
+
warning: (title: string, description?: string, options?: Partial<AlertProps>) => Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Show an info alert
|
|
54
|
+
* @param title - Alert title
|
|
55
|
+
* @param description - Alert description
|
|
56
|
+
* @param options - Additional alert options
|
|
57
|
+
* @returns Promise<boolean> - true when dismissed
|
|
58
|
+
*/
|
|
59
|
+
info: (title: string, description?: string, options?: Partial<AlertProps>) => Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Dismiss current alert
|
|
62
|
+
*/
|
|
63
|
+
dismiss: () => void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Hook for programmatically creating alerts
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* function MyComponent() {
|
|
71
|
+
* const alert = useAlert();
|
|
72
|
+
*
|
|
73
|
+
* const handleDelete = async () => {
|
|
74
|
+
* const confirmed = await alert.confirm(
|
|
75
|
+
* 'Delete Item',
|
|
76
|
+
* 'Are you sure you want to delete this item? This action cannot be undone.',
|
|
77
|
+
* { confirmVariant: 'danger' }
|
|
78
|
+
* );
|
|
79
|
+
*
|
|
80
|
+
* if (confirmed) {
|
|
81
|
+
* // Perform deletion
|
|
82
|
+
* await deleteItem();
|
|
83
|
+
* alert.success('Deleted', 'Item has been deleted successfully.');
|
|
84
|
+
* }
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* const handleError = () => {
|
|
88
|
+
* alert.error('Operation Failed', 'Something went wrong. Please try again.');
|
|
89
|
+
* };
|
|
90
|
+
*
|
|
91
|
+
* return (
|
|
92
|
+
* <Button onClick={handleDelete} variant="danger">
|
|
93
|
+
* Delete
|
|
94
|
+
* </Button>
|
|
95
|
+
* );
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function useAlert(options?: UseAlertOptions): UseAlertReturn;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { UseToastReturn } from '../useToast';
|
|
2
|
+
import { ToastData } from '../../components/overlays/Toast';
|
|
3
|
+
/**
|
|
4
|
+
* Async toast configuration
|
|
5
|
+
*/
|
|
6
|
+
export interface AsyncToastConfig<TData, TError = Error> {
|
|
7
|
+
/**
|
|
8
|
+
* Message or data to show while loading
|
|
9
|
+
*/
|
|
10
|
+
loading: string | Partial<ToastData>;
|
|
11
|
+
/**
|
|
12
|
+
* Message or data to show on success
|
|
13
|
+
* Can be a function that receives the result
|
|
14
|
+
*/
|
|
15
|
+
success: string | Partial<ToastData> | ((data: TData) => string | Partial<ToastData>);
|
|
16
|
+
/**
|
|
17
|
+
* Message or data to show on error
|
|
18
|
+
* Can be a function that receives the error
|
|
19
|
+
*/
|
|
20
|
+
error: string | Partial<ToastData> | ((error: TError) => string | Partial<ToastData>);
|
|
21
|
+
/**
|
|
22
|
+
* Duration for success toast (default: 5000)
|
|
23
|
+
*/
|
|
24
|
+
successDuration?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Duration for error toast (default: 5000)
|
|
27
|
+
*/
|
|
28
|
+
errorDuration?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Hook return type
|
|
32
|
+
*/
|
|
33
|
+
export interface UseAsyncToastReturn {
|
|
34
|
+
/**
|
|
35
|
+
* Wrap an async function with toast notifications
|
|
36
|
+
* Returns a function that when called, shows loading toast,
|
|
37
|
+
* then success/error based on result
|
|
38
|
+
*/
|
|
39
|
+
wrap: <TArgs extends unknown[], TData, TError = Error>(fn: (...args: TArgs) => Promise<TData>, config: AsyncToastConfig<TData, TError>) => (...args: TArgs) => Promise<TData>;
|
|
40
|
+
/**
|
|
41
|
+
* Execute a promise with toast notifications
|
|
42
|
+
*/
|
|
43
|
+
execute: <TData, TError = Error>(promise: Promise<TData>, config: AsyncToastConfig<TData, TError>) => Promise<TData>;
|
|
44
|
+
/**
|
|
45
|
+
* Access to underlying toast methods
|
|
46
|
+
*/
|
|
47
|
+
toast: UseToastReturn;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hook for API endpoint toasts with loading -> success/error flow
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* function UserForm() {
|
|
55
|
+
* const { wrap, execute } = useAsyncToast();
|
|
56
|
+
*
|
|
57
|
+
* // Method 1: Wrap an existing function
|
|
58
|
+
* const saveUser = wrap(
|
|
59
|
+
* async (data: UserData) => api.saveUser(data),
|
|
60
|
+
* {
|
|
61
|
+
* loading: 'Saving user...',
|
|
62
|
+
* success: (user) => `User ${user.name} saved successfully`,
|
|
63
|
+
* error: (err) => `Failed to save: ${err.message}`,
|
|
64
|
+
* }
|
|
65
|
+
* );
|
|
66
|
+
*
|
|
67
|
+
* // Method 2: Execute a one-off promise
|
|
68
|
+
* const handleFetch = async () => {
|
|
69
|
+
* try {
|
|
70
|
+
* const data = await execute(
|
|
71
|
+
* fetch('/api/data').then(r => r.json()),
|
|
72
|
+
* {
|
|
73
|
+
* loading: { message: 'Fetching data...', title: 'Loading' },
|
|
74
|
+
* success: 'Data loaded!',
|
|
75
|
+
* error: 'Failed to load data',
|
|
76
|
+
* }
|
|
77
|
+
* );
|
|
78
|
+
* // Use data...
|
|
79
|
+
* } catch (err) {
|
|
80
|
+
* // Handle error if needed
|
|
81
|
+
* }
|
|
82
|
+
* };
|
|
83
|
+
*
|
|
84
|
+
* const handleSubmit = async (formData: UserData) => {
|
|
85
|
+
* const user = await saveUser(formData);
|
|
86
|
+
* // user is typed as the return value of api.saveUser
|
|
87
|
+
* };
|
|
88
|
+
*
|
|
89
|
+
* return <form onSubmit={handleSubmit}>...</form>;
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function useAsyncToast(): UseAsyncToastReturn;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DialogContextValue, DialogProps } from '../../components/overlays/Dialog';
|
|
2
|
+
/**
|
|
3
|
+
* Hook options
|
|
4
|
+
*/
|
|
5
|
+
export interface UseDialogOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Default props to apply to all dialogs
|
|
8
|
+
*/
|
|
9
|
+
defaultProps?: Partial<DialogProps>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook return type
|
|
13
|
+
*/
|
|
14
|
+
export interface UseDialogReturn extends Pick<DialogContextValue, 'closeDialog' | 'closeTopDialog' | 'closeAllDialogs' | 'isDialogOpen' | 'dialogCount'> {
|
|
15
|
+
/**
|
|
16
|
+
* Open a dialog with optional default props merged
|
|
17
|
+
* @returns Promise that resolves when dialog closes
|
|
18
|
+
*/
|
|
19
|
+
open: <T = void>(props: Omit<DialogProps, 'isOpen'>) => Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Update props of an open dialog
|
|
22
|
+
*/
|
|
23
|
+
update: (id: string, props: Partial<DialogProps>) => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Hook for programmatically creating and managing dialogs
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* function MyComponent() {
|
|
31
|
+
* const dialog = useDialog();
|
|
32
|
+
*
|
|
33
|
+
* const handleClick = async () => {
|
|
34
|
+
* const result = await dialog.open({
|
|
35
|
+
* title: 'Confirm Action',
|
|
36
|
+
* children: 'Are you sure you want to proceed?',
|
|
37
|
+
* actions: (
|
|
38
|
+
* <>
|
|
39
|
+
* <Button variant="ghost" onClick={() => dialog.closeTopDialog(false)}>
|
|
40
|
+
* Cancel
|
|
41
|
+
* </Button>
|
|
42
|
+
* <Button onClick={() => dialog.closeTopDialog(true)}>
|
|
43
|
+
* Confirm
|
|
44
|
+
* </Button>
|
|
45
|
+
* </>
|
|
46
|
+
* ),
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* if (result) {
|
|
50
|
+
* // User confirmed
|
|
51
|
+
* }
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* return <Button onClick={handleClick}>Open Dialog</Button>;
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function useDialog(options?: UseDialogOptions): UseDialogReturn;
|