@arkyn/components 3.0.1-beta.23 → 3.0.1-beta.25
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 +2 -0
- package/dist/bundle.js +1821 -1353
- package/dist/bundle.umd.cjs +177 -1
- package/dist/components/popover/index.d.ts +146 -0
- package/dist/components/popover/index.d.ts.map +1 -0
- package/dist/components/popover/index.js +151 -0
- package/dist/components/tab/tabContainer/index.d.ts +1 -1
- package/dist/components/tab/tabContainer/index.d.ts.map +1 -1
- package/dist/hooks/useToast.d.ts +70 -0
- package/dist/hooks/useToast.d.ts.map +1 -0
- package/dist/hooks/useToast.js +72 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/providers/toastProvider.d.ts +48 -0
- package/dist/providers/toastProvider.d.ts.map +1 -0
- package/dist/providers/toastProvider.js +73 -0
- package/dist/style.css +1 -1
- package/package.json +3 -2
@@ -0,0 +1,146 @@
|
|
1
|
+
import { ReactNode } from "react";
|
2
|
+
import "./styles.css";
|
3
|
+
type OrientationProps = "bottomLeft" | "bottomRight" | "topLeft" | "topRight" | "top" | "left" | "bottom" | "right";
|
4
|
+
type PopoverProps = {
|
5
|
+
children: ReactNode;
|
6
|
+
button: ReactNode;
|
7
|
+
closeOnClick?: boolean;
|
8
|
+
orientation?: OrientationProps;
|
9
|
+
className?: string;
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* Popover component - used for displaying contextual content in a floating container that appears relative to a trigger button
|
13
|
+
*
|
14
|
+
* @param props - Popover component properties
|
15
|
+
* @param props.children - Required content to display inside the popover when opened
|
16
|
+
* @param props.button - Required trigger element that opens the popover when clicked
|
17
|
+
* @param props.closeOnClick - Whether the popover should close when clicking on its content. Default: undefined (remains open)
|
18
|
+
* @param props.orientation - Position where the popover appears relative to the trigger button. Default: "bottomLeft"
|
19
|
+
* @param props.className - Additional CSS classes for styling the popover container
|
20
|
+
*
|
21
|
+
* @returns Popover JSX element with trigger button, animated content, and overlay for outside click handling
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* ```tsx
|
25
|
+
* // Basic popover with default orientation
|
26
|
+
* <Popover
|
27
|
+
* button={<button>Click me</button>}
|
28
|
+
* >
|
29
|
+
* <div>Popover content here</div>
|
30
|
+
* </Popover>
|
31
|
+
*
|
32
|
+
* // Popover with custom orientation
|
33
|
+
* <Popover
|
34
|
+
* button={<IconButton icon="menu" />}
|
35
|
+
* orientation="topRight"
|
36
|
+
* >
|
37
|
+
* <nav>
|
38
|
+
* <a href="/profile">Profile</a>
|
39
|
+
* <a href="/settings">Settings</a>
|
40
|
+
* <a href="/logout">Logout</a>
|
41
|
+
* </nav>
|
42
|
+
* </Popover>
|
43
|
+
*
|
44
|
+
* // Popover that closes when content is clicked
|
45
|
+
* <Popover
|
46
|
+
* button={<Button>Select Option</Button>}
|
47
|
+
* closeOnClick
|
48
|
+
* orientation="bottom"
|
49
|
+
* >
|
50
|
+
* <ul>
|
51
|
+
* <li onClick={() => selectOption('option1')}>Option 1</li>
|
52
|
+
* <li onClick={() => selectOption('option2')}>Option 2</li>
|
53
|
+
* <li onClick={() => selectOption('option3')}>Option 3</li>
|
54
|
+
* </ul>
|
55
|
+
* </Popover>
|
56
|
+
*
|
57
|
+
* // Popover with custom styling and left orientation
|
58
|
+
* <Popover
|
59
|
+
* button={<Button variant="outline">Info</Button>}
|
60
|
+
* orientation="left"
|
61
|
+
* className="custom-popover"
|
62
|
+
* >
|
63
|
+
* <div className="info-panel">
|
64
|
+
* <h3>Additional Information</h3>
|
65
|
+
* <p>This is some helpful information that appears in a popover.</p>
|
66
|
+
* <Button size="sm">Learn More</Button>
|
67
|
+
* </div>
|
68
|
+
* </Popover>
|
69
|
+
*
|
70
|
+
* // Popover with form content and top-right positioning
|
71
|
+
* <Popover
|
72
|
+
* button={<Badge>Filter</Badge>}
|
73
|
+
* orientation="topRight"
|
74
|
+
* >
|
75
|
+
* <form className="filter-form">
|
76
|
+
* <Input name="search" placeholder="Search..." />
|
77
|
+
* <Select name="category" options={categories} />
|
78
|
+
* <Button type="submit">Apply Filters</Button>
|
79
|
+
* </form>
|
80
|
+
* </Popover>
|
81
|
+
*
|
82
|
+
* // Popover with complex content and bottom-right positioning
|
83
|
+
* <Popover
|
84
|
+
* button={<Avatar src="/user.jpg" />}
|
85
|
+
* orientation="bottomRight"
|
86
|
+
* closeOnClick
|
87
|
+
* >
|
88
|
+
* <div className="user-menu">
|
89
|
+
* <div className="user-info">
|
90
|
+
* <img src="/user.jpg" alt="User" />
|
91
|
+
* <div>
|
92
|
+
* <h4>John Doe</h4>
|
93
|
+
* <p>john@example.com</p>
|
94
|
+
* </div>
|
95
|
+
* </div>
|
96
|
+
* <Divider />
|
97
|
+
* <MenuItem icon="user">Profile</MenuItem>
|
98
|
+
* <MenuItem icon="settings">Settings</MenuItem>
|
99
|
+
* <MenuItem icon="logout">Sign Out</MenuItem>
|
100
|
+
* </div>
|
101
|
+
* </Popover>
|
102
|
+
*
|
103
|
+
* // Popover for context menu with right orientation
|
104
|
+
* <Popover
|
105
|
+
* button={<Button variant="ghost" size="sm">⋮</Button>}
|
106
|
+
* orientation="right"
|
107
|
+
* closeOnClick
|
108
|
+
* >
|
109
|
+
* <div className="context-menu">
|
110
|
+
* <button onClick={() => editItem()}>Edit</button>
|
111
|
+
* <button onClick={() => duplicateItem()}>Duplicate</button>
|
112
|
+
* <button onClick={() => deleteItem()}>Delete</button>
|
113
|
+
* </div>
|
114
|
+
* </Popover>
|
115
|
+
*
|
116
|
+
* // Popover with notification content and top positioning
|
117
|
+
* <Popover
|
118
|
+
* button={<Badge count={3}>🔔</Badge>}
|
119
|
+
* orientation="top"
|
120
|
+
* >
|
121
|
+
* <div className="notifications">
|
122
|
+
* <h3>Recent Notifications</h3>
|
123
|
+
* <div className="notification-item">New message received</div>
|
124
|
+
* <div className="notification-item">Task completed</div>
|
125
|
+
* <div className="notification-item">Meeting reminder</div>
|
126
|
+
* <Button variant="ghost" size="sm">View All</Button>
|
127
|
+
* </div>
|
128
|
+
* </Popover>
|
129
|
+
* ```
|
130
|
+
*
|
131
|
+
* @remarks
|
132
|
+
* This component provides:
|
133
|
+
* - 8 different orientation options for flexible positioning (bottomLeft, bottomRight, topLeft, topRight, top, left, bottom, right)
|
134
|
+
* - Smooth fade animation using Framer Motion for opening and closing
|
135
|
+
* - Automatic scroll lock when popover is open to prevent background scrolling
|
136
|
+
* - Click-outside-to-close functionality via overlay
|
137
|
+
* - Optional click-on-content-to-close behavior
|
138
|
+
* - Full accessibility support for keyboard navigation and screen readers
|
139
|
+
*
|
140
|
+
* The popover automatically handles positioning, animations, and user interactions.
|
141
|
+
* It uses CSS classes for styling and can be customized through the className prop.
|
142
|
+
* The component is ideal for dropdowns, context menus, tooltips, and any contextual UI elements.
|
143
|
+
*/
|
144
|
+
declare function Popover(props: PopoverProps): import("react/jsx-runtime").JSX.Element;
|
145
|
+
export { Popover };
|
146
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/popover/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAG5C,OAAO,cAAc,CAAC;AAEtB,KAAK,gBAAgB,GACjB,YAAY,GACZ,aAAa,GACb,SAAS,GACT,UAAU,GACV,KAAK,GACL,MAAM,GACN,QAAQ,GACR,OAAO,CAAC;AAEZ,KAAK,YAAY,GAAG;IAClB,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,SAAS,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoIG;AAEH,iBAAS,OAAO,CAAC,KAAK,EAAE,YAAY,2CAwCnC;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
@@ -0,0 +1,151 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { motion } from "framer-motion";
|
3
|
+
import { useState } from "react";
|
4
|
+
import { useScrollLock } from "../../hooks/useScrollLock";
|
5
|
+
import "./styles.css";
|
6
|
+
/**
|
7
|
+
* Popover component - used for displaying contextual content in a floating container that appears relative to a trigger button
|
8
|
+
*
|
9
|
+
* @param props - Popover component properties
|
10
|
+
* @param props.children - Required content to display inside the popover when opened
|
11
|
+
* @param props.button - Required trigger element that opens the popover when clicked
|
12
|
+
* @param props.closeOnClick - Whether the popover should close when clicking on its content. Default: undefined (remains open)
|
13
|
+
* @param props.orientation - Position where the popover appears relative to the trigger button. Default: "bottomLeft"
|
14
|
+
* @param props.className - Additional CSS classes for styling the popover container
|
15
|
+
*
|
16
|
+
* @returns Popover JSX element with trigger button, animated content, and overlay for outside click handling
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* ```tsx
|
20
|
+
* // Basic popover with default orientation
|
21
|
+
* <Popover
|
22
|
+
* button={<button>Click me</button>}
|
23
|
+
* >
|
24
|
+
* <div>Popover content here</div>
|
25
|
+
* </Popover>
|
26
|
+
*
|
27
|
+
* // Popover with custom orientation
|
28
|
+
* <Popover
|
29
|
+
* button={<IconButton icon="menu" />}
|
30
|
+
* orientation="topRight"
|
31
|
+
* >
|
32
|
+
* <nav>
|
33
|
+
* <a href="/profile">Profile</a>
|
34
|
+
* <a href="/settings">Settings</a>
|
35
|
+
* <a href="/logout">Logout</a>
|
36
|
+
* </nav>
|
37
|
+
* </Popover>
|
38
|
+
*
|
39
|
+
* // Popover that closes when content is clicked
|
40
|
+
* <Popover
|
41
|
+
* button={<Button>Select Option</Button>}
|
42
|
+
* closeOnClick
|
43
|
+
* orientation="bottom"
|
44
|
+
* >
|
45
|
+
* <ul>
|
46
|
+
* <li onClick={() => selectOption('option1')}>Option 1</li>
|
47
|
+
* <li onClick={() => selectOption('option2')}>Option 2</li>
|
48
|
+
* <li onClick={() => selectOption('option3')}>Option 3</li>
|
49
|
+
* </ul>
|
50
|
+
* </Popover>
|
51
|
+
*
|
52
|
+
* // Popover with custom styling and left orientation
|
53
|
+
* <Popover
|
54
|
+
* button={<Button variant="outline">Info</Button>}
|
55
|
+
* orientation="left"
|
56
|
+
* className="custom-popover"
|
57
|
+
* >
|
58
|
+
* <div className="info-panel">
|
59
|
+
* <h3>Additional Information</h3>
|
60
|
+
* <p>This is some helpful information that appears in a popover.</p>
|
61
|
+
* <Button size="sm">Learn More</Button>
|
62
|
+
* </div>
|
63
|
+
* </Popover>
|
64
|
+
*
|
65
|
+
* // Popover with form content and top-right positioning
|
66
|
+
* <Popover
|
67
|
+
* button={<Badge>Filter</Badge>}
|
68
|
+
* orientation="topRight"
|
69
|
+
* >
|
70
|
+
* <form className="filter-form">
|
71
|
+
* <Input name="search" placeholder="Search..." />
|
72
|
+
* <Select name="category" options={categories} />
|
73
|
+
* <Button type="submit">Apply Filters</Button>
|
74
|
+
* </form>
|
75
|
+
* </Popover>
|
76
|
+
*
|
77
|
+
* // Popover with complex content and bottom-right positioning
|
78
|
+
* <Popover
|
79
|
+
* button={<Avatar src="/user.jpg" />}
|
80
|
+
* orientation="bottomRight"
|
81
|
+
* closeOnClick
|
82
|
+
* >
|
83
|
+
* <div className="user-menu">
|
84
|
+
* <div className="user-info">
|
85
|
+
* <img src="/user.jpg" alt="User" />
|
86
|
+
* <div>
|
87
|
+
* <h4>John Doe</h4>
|
88
|
+
* <p>john@example.com</p>
|
89
|
+
* </div>
|
90
|
+
* </div>
|
91
|
+
* <Divider />
|
92
|
+
* <MenuItem icon="user">Profile</MenuItem>
|
93
|
+
* <MenuItem icon="settings">Settings</MenuItem>
|
94
|
+
* <MenuItem icon="logout">Sign Out</MenuItem>
|
95
|
+
* </div>
|
96
|
+
* </Popover>
|
97
|
+
*
|
98
|
+
* // Popover for context menu with right orientation
|
99
|
+
* <Popover
|
100
|
+
* button={<Button variant="ghost" size="sm">⋮</Button>}
|
101
|
+
* orientation="right"
|
102
|
+
* closeOnClick
|
103
|
+
* >
|
104
|
+
* <div className="context-menu">
|
105
|
+
* <button onClick={() => editItem()}>Edit</button>
|
106
|
+
* <button onClick={() => duplicateItem()}>Duplicate</button>
|
107
|
+
* <button onClick={() => deleteItem()}>Delete</button>
|
108
|
+
* </div>
|
109
|
+
* </Popover>
|
110
|
+
*
|
111
|
+
* // Popover with notification content and top positioning
|
112
|
+
* <Popover
|
113
|
+
* button={<Badge count={3}>🔔</Badge>}
|
114
|
+
* orientation="top"
|
115
|
+
* >
|
116
|
+
* <div className="notifications">
|
117
|
+
* <h3>Recent Notifications</h3>
|
118
|
+
* <div className="notification-item">New message received</div>
|
119
|
+
* <div className="notification-item">Task completed</div>
|
120
|
+
* <div className="notification-item">Meeting reminder</div>
|
121
|
+
* <Button variant="ghost" size="sm">View All</Button>
|
122
|
+
* </div>
|
123
|
+
* </Popover>
|
124
|
+
* ```
|
125
|
+
*
|
126
|
+
* @remarks
|
127
|
+
* This component provides:
|
128
|
+
* - 8 different orientation options for flexible positioning (bottomLeft, bottomRight, topLeft, topRight, top, left, bottom, right)
|
129
|
+
* - Smooth fade animation using Framer Motion for opening and closing
|
130
|
+
* - Automatic scroll lock when popover is open to prevent background scrolling
|
131
|
+
* - Click-outside-to-close functionality via overlay
|
132
|
+
* - Optional click-on-content-to-close behavior
|
133
|
+
* - Full accessibility support for keyboard navigation and screen readers
|
134
|
+
*
|
135
|
+
* The popover automatically handles positioning, animations, and user interactions.
|
136
|
+
* It uses CSS classes for styling and can be customized through the className prop.
|
137
|
+
* The component is ideal for dropdowns, context menus, tooltips, and any contextual UI elements.
|
138
|
+
*/
|
139
|
+
function Popover(props) {
|
140
|
+
const { children, button, closeOnClick, className: baseClassName = "", orientation = "bottomLeft", } = props;
|
141
|
+
const [isOpen, setIsOpen] = useState(false);
|
142
|
+
const visible = isOpen ? "visibleTrue" : "visibleFalse";
|
143
|
+
const className = `arkynPopover ${orientation} ${visible} ${baseClassName}`;
|
144
|
+
function handleOpenPopover() {
|
145
|
+
if (!isOpen)
|
146
|
+
setIsOpen(true);
|
147
|
+
}
|
148
|
+
useScrollLock(isOpen);
|
149
|
+
return (_jsxs("div", { className: className, onClick: handleOpenPopover, children: [button, _jsx(motion.div, { style: { visibility: isOpen ? "visible" : "hidden" }, transition: { ease: "easeOut", duration: 0 }, initial: { opacity: 0 }, animate: { opacity: isOpen ? 1 : 0 }, exit: { opacity: 0 }, onClick: () => closeOnClick && setIsOpen(false), className: "arkynPopoverContent", children: children }), isOpen && (_jsx("div", { onClick: () => setIsOpen(false), className: "arkynPopoverOverlay" }))] }));
|
150
|
+
}
|
151
|
+
export { Popover };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { HTMLAttributes, ReactNode } from "react";
|
2
2
|
import "./styles.css";
|
3
|
-
type TabContainerProps = Omit<HTMLAttributes<HTMLElement>, "
|
3
|
+
type TabContainerProps = Omit<HTMLAttributes<HTMLElement>, "onChange" | "children" | "ref" | "onClick"> & {
|
4
4
|
children: ReactNode;
|
5
5
|
disabled?: boolean;
|
6
6
|
defaultValue?: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/tab/tabContainer/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAG5D,OAAO,cAAc,CAAC;AAEtB,KAAK,iBAAiB,GAAG,IAAI,CAC3B,cAAc,CAAC,WAAW,CAAC,EAC3B,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/tab/tabContainer/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAG5D,OAAO,cAAc,CAAC;AAEtB,KAAK,iBAAiB,GAAG,IAAI,CAC3B,cAAc,CAAC,WAAW,CAAC,EAC3B,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,CAC5C,GAAG;IACF,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AAEH,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,2CA8B7C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/**
|
2
|
+
* Custom hook to access toast functionality from ToastProvider context
|
3
|
+
*
|
4
|
+
* @returns Object containing toast methods and state
|
5
|
+
* @returns {function} showToast - Function to display toast notifications
|
6
|
+
*
|
7
|
+
* @throws {Error} Throws an error if used outside of ToastProvider
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* Basic usage:
|
11
|
+
* ```tsx
|
12
|
+
* function MyComponent() {
|
13
|
+
* const { showToast } = useToast();
|
14
|
+
*
|
15
|
+
* const handleSuccess = () => {
|
16
|
+
* showToast({
|
17
|
+
* message: 'Operation completed successfully!',
|
18
|
+
* type: 'success'
|
19
|
+
* });
|
20
|
+
* };
|
21
|
+
*
|
22
|
+
* const handleError = () => {
|
23
|
+
* showToast({
|
24
|
+
* message: 'Something went wrong!',
|
25
|
+
* type: 'danger'
|
26
|
+
* });
|
27
|
+
* };
|
28
|
+
*
|
29
|
+
* return (
|
30
|
+
* <div>
|
31
|
+
* <button onClick={handleSuccess}>Success Toast</button>
|
32
|
+
* <button onClick={handleError}>Error Toast</button>
|
33
|
+
* </div>
|
34
|
+
* );
|
35
|
+
* }
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
* Using in async operations:
|
40
|
+
* ```tsx
|
41
|
+
* function FormComponent() {
|
42
|
+
* const { showToast } = useToast();
|
43
|
+
*
|
44
|
+
* const handleSubmit = async (data) => {
|
45
|
+
* try {
|
46
|
+
* await submitForm(data);
|
47
|
+
* showToast({
|
48
|
+
* message: 'Form submitted successfully!',
|
49
|
+
* type: 'success'
|
50
|
+
* });
|
51
|
+
* } catch (error) {
|
52
|
+
* showToast({
|
53
|
+
* message: 'Failed to submit form',
|
54
|
+
* type: 'danger'
|
55
|
+
* });
|
56
|
+
* }
|
57
|
+
* };
|
58
|
+
*
|
59
|
+
* return <form onSubmit={handleSubmit}>...</form>;
|
60
|
+
* }
|
61
|
+
* ```
|
62
|
+
*/
|
63
|
+
declare function useToast(): {
|
64
|
+
showToast(toast: {
|
65
|
+
message: string;
|
66
|
+
type: "success" | "danger";
|
67
|
+
}): void;
|
68
|
+
};
|
69
|
+
export { useToast };
|
70
|
+
//# sourceMappingURL=useToast.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useToast.d.ts","sourceRoot":"","sources":["../../src/hooks/useToast.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,iBAAS,QAAQ;;;;;EAQhB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { toastContext } from "../providers/toastProvider";
|
2
|
+
import { useContext } from "react";
|
3
|
+
/**
|
4
|
+
* Custom hook to access toast functionality from ToastProvider context
|
5
|
+
*
|
6
|
+
* @returns Object containing toast methods and state
|
7
|
+
* @returns {function} showToast - Function to display toast notifications
|
8
|
+
*
|
9
|
+
* @throws {Error} Throws an error if used outside of ToastProvider
|
10
|
+
*
|
11
|
+
* @example
|
12
|
+
* Basic usage:
|
13
|
+
* ```tsx
|
14
|
+
* function MyComponent() {
|
15
|
+
* const { showToast } = useToast();
|
16
|
+
*
|
17
|
+
* const handleSuccess = () => {
|
18
|
+
* showToast({
|
19
|
+
* message: 'Operation completed successfully!',
|
20
|
+
* type: 'success'
|
21
|
+
* });
|
22
|
+
* };
|
23
|
+
*
|
24
|
+
* const handleError = () => {
|
25
|
+
* showToast({
|
26
|
+
* message: 'Something went wrong!',
|
27
|
+
* type: 'danger'
|
28
|
+
* });
|
29
|
+
* };
|
30
|
+
*
|
31
|
+
* return (
|
32
|
+
* <div>
|
33
|
+
* <button onClick={handleSuccess}>Success Toast</button>
|
34
|
+
* <button onClick={handleError}>Error Toast</button>
|
35
|
+
* </div>
|
36
|
+
* );
|
37
|
+
* }
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* @example
|
41
|
+
* Using in async operations:
|
42
|
+
* ```tsx
|
43
|
+
* function FormComponent() {
|
44
|
+
* const { showToast } = useToast();
|
45
|
+
*
|
46
|
+
* const handleSubmit = async (data) => {
|
47
|
+
* try {
|
48
|
+
* await submitForm(data);
|
49
|
+
* showToast({
|
50
|
+
* message: 'Form submitted successfully!',
|
51
|
+
* type: 'success'
|
52
|
+
* });
|
53
|
+
* } catch (error) {
|
54
|
+
* showToast({
|
55
|
+
* message: 'Failed to submit form',
|
56
|
+
* type: 'danger'
|
57
|
+
* });
|
58
|
+
* }
|
59
|
+
* };
|
60
|
+
*
|
61
|
+
* return <form onSubmit={handleSubmit}>...</form>;
|
62
|
+
* }
|
63
|
+
* ```
|
64
|
+
*/
|
65
|
+
function useToast() {
|
66
|
+
const contextData = useContext(toastContext);
|
67
|
+
if (Object.entries(contextData).length === 0) {
|
68
|
+
throw new Error("useToast must be used within a Provider");
|
69
|
+
}
|
70
|
+
return contextData;
|
71
|
+
}
|
72
|
+
export { useToast };
|
package/dist/index.d.ts
CHANGED
@@ -28,6 +28,7 @@ export { ModalFooter } from "./components/modal/modalFooter";
|
|
28
28
|
export { ModalHeader } from "./components/modal/modalHeader";
|
29
29
|
export { MultiSelect } from "./components/multiSelect";
|
30
30
|
export { PhoneInput } from "./components/phoneInput";
|
31
|
+
export { Popover } from "./components/popover";
|
31
32
|
export { RadioBox } from "./components/radio/radioBox";
|
32
33
|
export { RadioGroup } from "./components/radio/radioGroup";
|
33
34
|
export { Slider } from "./components/slider";
|
@@ -51,4 +52,5 @@ export { useSlider } from "./hooks/useSlider";
|
|
51
52
|
export { DrawerProvider } from "./providers/drawerProvider";
|
52
53
|
export { FormProvider } from "./providers/formProvider";
|
53
54
|
export { ModalProvider } from "./providers/modalProvider";
|
55
|
+
export { ToastProvider } from "./providers/toastProvider";
|
54
56
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC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CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
@@ -29,6 +29,7 @@ export { ModalFooter } from "./components/modal/modalFooter";
|
|
29
29
|
export { ModalHeader } from "./components/modal/modalHeader";
|
30
30
|
export { MultiSelect } from "./components/multiSelect";
|
31
31
|
export { PhoneInput } from "./components/phoneInput";
|
32
|
+
export { Popover } from "./components/popover";
|
32
33
|
export { RadioBox } from "./components/radio/radioBox";
|
33
34
|
export { RadioGroup } from "./components/radio/radioGroup";
|
34
35
|
export { Slider } from "./components/slider";
|
@@ -54,3 +55,4 @@ export { useSlider } from "./hooks/useSlider";
|
|
54
55
|
export { DrawerProvider } from "./providers/drawerProvider";
|
55
56
|
export { FormProvider } from "./providers/formProvider";
|
56
57
|
export { ModalProvider } from "./providers/modalProvider";
|
58
|
+
export { ToastProvider } from "./providers/toastProvider";
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { ReactNode } from "react";
|
2
|
+
type ToastProps = {
|
3
|
+
message: string;
|
4
|
+
type: "success" | "danger";
|
5
|
+
};
|
6
|
+
type ToastContextProps = {
|
7
|
+
showToast(toast: ToastProps): void;
|
8
|
+
};
|
9
|
+
type ToastProviderProps = {
|
10
|
+
children: ReactNode;
|
11
|
+
};
|
12
|
+
declare const toastContext: import("react").Context<ToastContextProps>;
|
13
|
+
/**
|
14
|
+
* ToastProvider component - provides toast context for managing toast notifications
|
15
|
+
*
|
16
|
+
* @param props - ToastProvider component properties
|
17
|
+
* @param props.children - React elements that will have access to the toast context
|
18
|
+
*
|
19
|
+
* @returns ToastProvider JSX element that wraps children with toast context
|
20
|
+
*
|
21
|
+
* @example
|
22
|
+
* Basic usage:
|
23
|
+
* ```tsx
|
24
|
+
* <ToastProvider>
|
25
|
+
* <App />
|
26
|
+
* </ToastProvider>
|
27
|
+
* ```
|
28
|
+
*
|
29
|
+
* @example
|
30
|
+
* Using toast in component:
|
31
|
+
* ```tsx
|
32
|
+
* function MyComponent() {
|
33
|
+
* const { showToast } = useToast();
|
34
|
+
*
|
35
|
+
* const handleClick = () => {
|
36
|
+
* showToast({
|
37
|
+
* message: 'Success!',
|
38
|
+
* type: 'success'
|
39
|
+
* });
|
40
|
+
* };
|
41
|
+
*
|
42
|
+
* return <button onClick={handleClick}>Show Toast</button>;
|
43
|
+
* }
|
44
|
+
* ```
|
45
|
+
*/
|
46
|
+
declare function ToastProvider({ children }: ToastProviderProps): import("react/jsx-runtime").JSX.Element;
|
47
|
+
export { toastContext, ToastProvider };
|
48
|
+
//# sourceMappingURL=toastProvider.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"toastProvider.d.ts","sourceRoot":"","sources":["../../src/providers/toastProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAGjD,KAAK,UAAU,GAAG;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC5B,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,YAAY,4CAAyC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,iBAAS,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,2CA2CtD;AAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { createContext } from "react";
|
3
|
+
import toast, { Toaster } from "react-hot-toast";
|
4
|
+
const toastContext = createContext({});
|
5
|
+
/**
|
6
|
+
* ToastProvider component - provides toast context for managing toast notifications
|
7
|
+
*
|
8
|
+
* @param props - ToastProvider component properties
|
9
|
+
* @param props.children - React elements that will have access to the toast context
|
10
|
+
*
|
11
|
+
* @returns ToastProvider JSX element that wraps children with toast context
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* Basic usage:
|
15
|
+
* ```tsx
|
16
|
+
* <ToastProvider>
|
17
|
+
* <App />
|
18
|
+
* </ToastProvider>
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* @example
|
22
|
+
* Using toast in component:
|
23
|
+
* ```tsx
|
24
|
+
* function MyComponent() {
|
25
|
+
* const { showToast } = useToast();
|
26
|
+
*
|
27
|
+
* const handleClick = () => {
|
28
|
+
* showToast({
|
29
|
+
* message: 'Success!',
|
30
|
+
* type: 'success'
|
31
|
+
* });
|
32
|
+
* };
|
33
|
+
*
|
34
|
+
* return <button onClick={handleClick}>Show Toast</button>;
|
35
|
+
* }
|
36
|
+
* ```
|
37
|
+
*/
|
38
|
+
function ToastProvider({ children }) {
|
39
|
+
function showToast(props) {
|
40
|
+
switch (props.type) {
|
41
|
+
case "success":
|
42
|
+
return toast.success(props.message, {
|
43
|
+
style: {
|
44
|
+
background: "#10B981",
|
45
|
+
color: "#ffffff",
|
46
|
+
padding: "12px 16px",
|
47
|
+
fontSize: "14px",
|
48
|
+
fontWeight: 600,
|
49
|
+
},
|
50
|
+
iconTheme: {
|
51
|
+
primary: "#059669",
|
52
|
+
secondary: "#ffffff",
|
53
|
+
},
|
54
|
+
});
|
55
|
+
case "danger":
|
56
|
+
return toast.error(props.message, {
|
57
|
+
style: {
|
58
|
+
background: "#E11D48",
|
59
|
+
color: "#ffffff",
|
60
|
+
padding: "12px 16px",
|
61
|
+
fontSize: "14px",
|
62
|
+
fontWeight: 600,
|
63
|
+
},
|
64
|
+
iconTheme: {
|
65
|
+
primary: "#BE123C",
|
66
|
+
secondary: "#ffffff",
|
67
|
+
},
|
68
|
+
});
|
69
|
+
}
|
70
|
+
}
|
71
|
+
return (_jsxs(toastContext.Provider, { value: { showToast }, children: [_jsx(Toaster, { position: "top-right", containerStyle: { zIndex: 999999999999999 } }), children] }));
|
72
|
+
}
|
73
|
+
export { toastContext, ToastProvider };
|