@longline/aqua-ui 1.0.302 → 1.0.303
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/controls/Chip/Chip.d.ts +41 -13
- package/controls/Chip/Chip.js +76 -22
- package/controls/Chip/index.d.ts +2 -1
- package/controls/Chip/index.js +1 -1
- package/controls/CircularProgress/CircularProgress.d.ts +38 -6
- package/controls/CircularProgress/CircularProgress.js +67 -17
- package/controls/CircularProgress/index.d.ts +1 -0
- package/controls/Dropzone/Dropzone.d.ts +42 -10
- package/controls/Dropzone/Dropzone.js +76 -16
- package/controls/Dropzone/index.d.ts +1 -0
- package/controls/Fab/Fab.d.ts +40 -15
- package/controls/Fab/Fab.js +76 -28
- package/controls/Fab/index.d.ts +2 -1
- package/controls/Fab/index.js +1 -1
- package/controls/Ghost/Ghost.d.ts +36 -0
- package/controls/Ghost/Ghost.js +72 -1
- package/controls/Ghost/index.d.ts +2 -1
- package/controls/Ghost/index.js +1 -1
- package/controls/Gradient/Gradient.d.ts +51 -5
- package/controls/Gradient/Gradient.js +98 -8
- package/controls/Gradient/index.d.ts +1 -0
- package/controls/Histogram/Histogram.d.ts +47 -6
- package/controls/Histogram/Histogram.js +84 -21
- package/controls/Histogram/HistogramAppearance.d.ts +2 -1
- package/controls/Histogram/IHistogramBin.d.ts +1 -1
- package/controls/Histogram/index.d.ts +5 -3
- package/controls/Histogram/index.js +2 -3
- package/controls/Icon/Icon.d.ts +50 -22
- package/controls/Icon/Icon.js +47 -18
- package/controls/Icon/index.d.ts +2 -1
- package/controls/Icon/index.js +1 -1
- package/controls/Key/Key.d.ts +39 -5
- package/controls/Key/Key.js +74 -8
- package/controls/Key/index.d.ts +2 -1
- package/controls/Key/index.js +1 -1
- package/controls/LinearChart/LinearChart.d.ts +36 -5
- package/controls/LinearChart/LinearChart.js +64 -6
- package/controls/LinearChart/index.d.ts +2 -1
- package/controls/LinearChart/index.js +1 -1
- package/controls/ListView/Column.d.ts +42 -5
- package/controls/ListView/Column.js +39 -3
- package/controls/ListView/IListViewProps.d.ts +2 -2
- package/controls/ListView/ListView.d.ts +58 -2
- package/controls/ListView/ListView.js +57 -2
- package/controls/ListView/index.d.ts +1 -0
- package/controls/Mouse/Mouse.d.ts +32 -7
- package/controls/Mouse/Mouse.js +60 -12
- package/controls/Mouse/index.d.ts +2 -1
- package/controls/Mouse/index.js +1 -1
- package/controls/PrimaryButton/PrimaryButton.d.ts +37 -9
- package/controls/PrimaryButton/PrimaryButton.js +70 -16
- package/controls/PrimaryButton/index.d.ts +2 -1
- package/controls/PrimaryButton/index.js +1 -1
- package/controls/Progress/Progress.d.ts +32 -10
- package/controls/Progress/Progress.js +60 -18
- package/controls/Progress/index.d.ts +2 -1
- package/controls/Progress/index.js +1 -1
- package/controls/SecondaryButton/SecondaryButton.d.ts +34 -8
- package/controls/SecondaryButton/SecondaryButton.js +64 -14
- package/controls/SecondaryButton/index.d.ts +1 -0
- package/controls/SpeechRecognizer/SpeechRecognizer.d.ts +31 -1
- package/controls/SpeechRecognizer/SpeechRecognizer.js +29 -1
- package/controls/SpeechRecognizer/index.d.ts +1 -1
- package/controls/SpeechRecognizer/index.js +1 -1
- package/controls/TabBar/Tab.d.ts +31 -1
- package/controls/TabBar/Tab.js +58 -1
- package/controls/TabBar/TabBar.d.ts +43 -5
- package/controls/TabBar/TabBar.js +82 -8
- package/controls/TabBar/index.d.ts +3 -1
- package/controls/TabBar/index.js +1 -1
- package/controls/TertiaryButton/TertiaryButton.d.ts +32 -7
- package/controls/TertiaryButton/TertiaryButton.js +60 -12
- package/controls/TertiaryButton/index.d.ts +2 -1
- package/controls/TertiaryButton/index.js +1 -1
- package/controls/ToggleButton/ToggleButton.d.ts +36 -3
- package/controls/ToggleButton/ToggleButton.js +69 -5
- package/controls/ToggleButton/index.d.ts +2 -1
- package/controls/ToggleButton/index.js +1 -1
- package/controls/View/View.d.ts +22 -8
- package/controls/View/View.js +40 -14
- package/controls/View/index.d.ts +2 -1
- package/controls/View/index.js +1 -1
- package/inputs/Dropdown/Dropdown.d.ts +2 -1
- package/inputs/Dropdown/index.d.ts +2 -1
- package/map/controls/CompassButton/CompassButton.d.ts +1 -1
- package/map/controls/FullscreenButton/FullscreenButton.d.ts +1 -1
- package/map/controls/ZoomInButton/ZoomInButton.d.ts +3 -2
- package/map/controls/ZoomOutButton/ZoomOutButton.d.ts +3 -2
- package/map/controls/base/MapButton/MapButton.d.ts +2 -1
- package/map/controls/base/MapButton/index.d.ts +2 -1
- package/package.json +1 -1
- package/services/Toast/IToastMessage.d.ts +3 -3
- package/services/Toast/IToastProps.d.ts +1 -1
- package/services/Toast/Toast.d.ts +43 -5
- package/services/Toast/Toast.js +35 -4
- package/services/Toast/ToastContainer.d.ts +37 -4
- package/services/Toast/ToastContainer.js +75 -9
- package/services/Toast/ToastContext.d.ts +5 -4
- package/services/Toast/ToastProvider.js +16 -11
- package/services/Toast/useToast.d.ts +37 -1
- package/services/Toast/useToast.js +42 -2
package/services/Toast/Toast.js
CHANGED
|
@@ -76,15 +76,46 @@ var CloseButton = styled.div(templateObject_2 || (templateObject_2 = __makeTempl
|
|
|
76
76
|
var Action = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n padding-left: 8px;\n color: ", ";\n cursor: pointer;\n white-space: nowrap;\n font: ", ";\n text-transform: uppercase;\n transition: color ease-in-out ", "ms;\n &:hover {\n color: ", ";\n }\n &:last-child {\n padding-right: 16px;\n }\n"], ["\n display: flex;\n align-items: center;\n padding-left: 8px;\n color: ", ";\n cursor: pointer;\n white-space: nowrap;\n font: ", ";\n text-transform: uppercase;\n transition: color ease-in-out ", "ms;\n &:hover {\n color: ", ";\n }\n &:last-child {\n padding-right: 16px;\n }\n"])), function (p) { return p.theme.colors.primary[4]; }, function (p) { return p.theme.font.labelCaps; }, function (p) { return p.theme.animation.duration; }, function (p) { return p.theme.colors.primary[2]; });
|
|
77
77
|
var ToastStyled = styled(ToastBase)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n // Position and size:\n display: flex;\n width: 344px;\n box-sizing: border-box;\n align-items: stretch;\n justify-content: space-between;\n user-select: none;\n pointer-events: all;\n\n // Space between toasts:\n margin: 8px 0 8px 0; \n\n // Appearance:\n padding: 14px 0 14px 0;\n background-color: ", ";\n color: #fff;\n border-radius: ", "px;\n font: ", ";\n\n // Content:\n a {\n color: ", " !important;\n }\n\n /* useTransitionState classes */\n transition: opacity ", "ms ease;\n &.preEnter, &.exiting, &.unmounted {\n opacity: 0;\n }\n &.entering {\n opacity: 1;\n }\n &.entered {\n opacity: 1;\n }\n\n"], ["\n // Position and size:\n display: flex;\n width: 344px;\n box-sizing: border-box;\n align-items: stretch;\n justify-content: space-between;\n user-select: none;\n pointer-events: all;\n\n // Space between toasts:\n margin: 8px 0 8px 0; \n\n // Appearance:\n padding: 14px 0 14px 0;\n background-color: ", ";\n color: #fff;\n border-radius: ", "px;\n font: ", ";\n\n // Content:\n a {\n color: ", " !important;\n }\n\n /* useTransitionState classes */\n transition: opacity ", "ms ease;\n &.preEnter, &.exiting, &.unmounted {\n opacity: 0;\n }\n &.entering {\n opacity: 1;\n }\n &.entered {\n opacity: 1;\n }\n\n"])), function (p) { return p.theme.colors.primary[1]; }, function (p) { return p.theme.radius.normal; }, function (p) { return p.theme.font.bodyMedium; }, function (p) { return p.theme.colors.neutral[100]; }, function (p) { return p.theme.animation.duration * 2; });
|
|
78
78
|
/**
|
|
79
|
-
* A
|
|
79
|
+
* A brief notification message that appears temporarily to provide feedback to the user.
|
|
80
80
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
81
|
+
* Toasts are typically created through the `useToast` hook rather than being rendered directly.
|
|
82
|
+
* They automatically disappear after a configurable duration, or can be manually dismissed
|
|
83
|
+
* by the user if `dismissable` is enabled.
|
|
84
|
+
*
|
|
85
|
+
* ## Usage
|
|
86
|
+
*
|
|
87
|
+
* ```tsx
|
|
88
|
+
* const { toast } = useToast();
|
|
89
|
+
*
|
|
90
|
+
* // Simple toast
|
|
91
|
+
* toast("Changes saved successfully");
|
|
92
|
+
*
|
|
93
|
+
* // Toast with options
|
|
94
|
+
* toast("File uploaded", {
|
|
84
95
|
* duration: 5000,
|
|
85
96
|
* dismissable: true
|
|
86
97
|
* });
|
|
98
|
+
*
|
|
99
|
+
* // Toast with action button
|
|
100
|
+
* toast("Item deleted", {
|
|
101
|
+
* action: () => undoDelete(),
|
|
102
|
+
* actionLabel: "Undo"
|
|
103
|
+
* });
|
|
87
104
|
* ```
|
|
105
|
+
*
|
|
106
|
+
* ## Toast Options
|
|
107
|
+
*
|
|
108
|
+
* | Option | Type | Default | Description |
|
|
109
|
+
* |--------|------|---------|-------------|
|
|
110
|
+
* | `duration` | `number` | `8000` | Auto-dismiss delay in ms. Set to `0` for persistent toast. |
|
|
111
|
+
* | `dismissable` | `boolean` | `false` | Show close button for manual dismissal |
|
|
112
|
+
* | `action` | `function` | - | Callback for action button click |
|
|
113
|
+
* | `actionLabel` | `ReactNode` | `"Action"` | Label for the action button |
|
|
114
|
+
*
|
|
115
|
+
* ## Animation
|
|
116
|
+
*
|
|
117
|
+
* Toasts fade in when appearing and fade out when dismissed or timed out.
|
|
118
|
+
* The animation duration is derived from the theme's animation settings.
|
|
88
119
|
*/
|
|
89
120
|
var Toast = function (_a) {
|
|
90
121
|
var _b = _a.duration, duration = _b === void 0 ? 8000 : _b, _c = _a.dismissable, dismissable = _c === void 0 ? false : _c, _d = _a.actionLabel, actionLabel = _d === void 0 ? "Action" : _d, props = __rest(_a, ["duration", "dismissable", "actionLabel"]);
|
|
@@ -30,11 +30,44 @@ interface IToastContainerProps {
|
|
|
30
30
|
verticalOffset?: number;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* A
|
|
34
|
-
* which is a context that must wrap the ToastContainer.
|
|
33
|
+
* A container that renders and positions all active toasts from the `ToastProvider` context.
|
|
35
34
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* The `ToastContainer` must be placed inside a `ToastProvider`. It automatically subscribes
|
|
36
|
+
* to the toast context and renders any active toasts. The container itself is invisible and
|
|
37
|
+
* does not capture pointer events, but individual toasts within it do.
|
|
38
|
+
*
|
|
39
|
+
* ## Usage
|
|
40
|
+
*
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <ToastProvider>
|
|
43
|
+
* <App />
|
|
44
|
+
* <ToastContainer
|
|
45
|
+
* verticalAlign="bottom"
|
|
46
|
+
* horizontalAlign="right"
|
|
47
|
+
* />
|
|
48
|
+
* </ToastProvider>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* ## Positioning
|
|
52
|
+
*
|
|
53
|
+
* Toasts can be positioned in any corner or centered horizontally:
|
|
54
|
+
*
|
|
55
|
+
* | Position | Props |
|
|
56
|
+
* |----------|-------|
|
|
57
|
+
* | Bottom-left | `verticalAlign="bottom" horizontalAlign="left"` (default) |
|
|
58
|
+
* | Bottom-right | `verticalAlign="bottom" horizontalAlign="right"` |
|
|
59
|
+
* | Bottom-center | `verticalAlign="bottom" horizontalAlign="center"` |
|
|
60
|
+
* | Top-left | `verticalAlign="top" horizontalAlign="left"` |
|
|
61
|
+
* | Top-right | `verticalAlign="top" horizontalAlign="right"` |
|
|
62
|
+
* | Top-center | `verticalAlign="top" horizontalAlign="center"` |
|
|
63
|
+
*
|
|
64
|
+
* Use `horizontalOffset` and `verticalOffset` to add padding from the edges.
|
|
65
|
+
*
|
|
66
|
+
* ## Stacking
|
|
67
|
+
*
|
|
68
|
+
* When multiple toasts are active, they stack vertically. With `verticalAlign="bottom"`,
|
|
69
|
+
* newer toasts appear above older ones. With `verticalAlign="top"`, newer toasts
|
|
70
|
+
* appear below older ones.
|
|
38
71
|
*/
|
|
39
72
|
declare const ToastContainer: {
|
|
40
73
|
({ horizontalOffset, verticalOffset, verticalAlign, horizontalAlign, ...props }: IToastContainerProps): React.JSX.Element;
|
|
@@ -40,19 +40,85 @@ var ToastContainerBase = function (props) {
|
|
|
40
40
|
};
|
|
41
41
|
var ToastContainerStyled = styled(ToastContainerBase)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n // Position:\n // ToastContainer occupies all area that it can, but captures no pointer events.\n // Toast children do capture pointer events.\n position: absolute;\n z-index: 9999;\n top: ", "px;\n bottom: ", "px;\n left: ", "px;\n right: ", "px;\n pointer-events: none !important;\n // Toasts are placed using a flexbox:\n display: flex;\n flex-direction: ", ";\n align-items: ", ";\n justify-content: ", ";\n"], ["\n // Position:\n // ToastContainer occupies all area that it can, but captures no pointer events.\n // Toast children do capture pointer events.\n position: absolute;\n z-index: 9999;\n top: ", "px;\n bottom: ", "px;\n left: ", "px;\n right: ", "px;\n pointer-events: none !important;\n // Toasts are placed using a flexbox:\n display: flex;\n flex-direction: ", ";\n align-items: ", ";\n justify-content: ", ";\n"
|
|
42
42
|
/**
|
|
43
|
-
* A
|
|
44
|
-
* which is a context that must wrap the ToastContainer.
|
|
43
|
+
* A container that renders and positions all active toasts from the `ToastProvider` context.
|
|
45
44
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* The `ToastContainer` must be placed inside a `ToastProvider`. It automatically subscribes
|
|
46
|
+
* to the toast context and renders any active toasts. The container itself is invisible and
|
|
47
|
+
* does not capture pointer events, but individual toasts within it do.
|
|
48
|
+
*
|
|
49
|
+
* ## Usage
|
|
50
|
+
*
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <ToastProvider>
|
|
53
|
+
* <App />
|
|
54
|
+
* <ToastContainer
|
|
55
|
+
* verticalAlign="bottom"
|
|
56
|
+
* horizontalAlign="right"
|
|
57
|
+
* />
|
|
58
|
+
* </ToastProvider>
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ## Positioning
|
|
62
|
+
*
|
|
63
|
+
* Toasts can be positioned in any corner or centered horizontally:
|
|
64
|
+
*
|
|
65
|
+
* | Position | Props |
|
|
66
|
+
* |----------|-------|
|
|
67
|
+
* | Bottom-left | `verticalAlign="bottom" horizontalAlign="left"` (default) |
|
|
68
|
+
* | Bottom-right | `verticalAlign="bottom" horizontalAlign="right"` |
|
|
69
|
+
* | Bottom-center | `verticalAlign="bottom" horizontalAlign="center"` |
|
|
70
|
+
* | Top-left | `verticalAlign="top" horizontalAlign="left"` |
|
|
71
|
+
* | Top-right | `verticalAlign="top" horizontalAlign="right"` |
|
|
72
|
+
* | Top-center | `verticalAlign="top" horizontalAlign="center"` |
|
|
73
|
+
*
|
|
74
|
+
* Use `horizontalOffset` and `verticalOffset` to add padding from the edges.
|
|
75
|
+
*
|
|
76
|
+
* ## Stacking
|
|
77
|
+
*
|
|
78
|
+
* When multiple toasts are active, they stack vertically. With `verticalAlign="bottom"`,
|
|
79
|
+
* newer toasts appear above older ones. With `verticalAlign="top"`, newer toasts
|
|
80
|
+
* appear below older ones.
|
|
48
81
|
*/
|
|
49
|
-
])), function (p) { return p.verticalAlign === 'top' ? p.verticalOffset : 0; }, function (p) { return p.verticalAlign === 'bottom' ? p.verticalOffset : 0; }, function (p) { return p.horizontalAlign === 'left' ? p.horizontalOffset : 0; }, function (p) { return p.horizontalAlign === 'right' ? p.horizontalOffset : 0; }, function (p) { return p.verticalAlign === 'top' ? 'column' : 'column-reverse'; }, function (p) { return p.horizontalAlign === 'left' ? 'start' : (p.horizontalAlign === 'right' ? 'end' : 'center'); }, function (p) { return p.verticalAlign
|
|
82
|
+
])), function (p) { return p.verticalAlign === 'top' ? p.verticalOffset : 0; }, function (p) { return p.verticalAlign === 'bottom' ? p.verticalOffset : 0; }, function (p) { return p.horizontalAlign === 'left' ? p.horizontalOffset : 0; }, function (p) { return p.horizontalAlign === 'right' ? p.horizontalOffset : 0; }, function (p) { return p.verticalAlign === 'top' ? 'column' : 'column-reverse'; }, function (p) { return p.horizontalAlign === 'left' ? 'start' : (p.horizontalAlign === 'right' ? 'end' : 'center'); }, function (p) { return p.verticalAlign === 'top' ? 'start' : 'end'; });
|
|
50
83
|
/**
|
|
51
|
-
* A
|
|
52
|
-
*
|
|
84
|
+
* A container that renders and positions all active toasts from the `ToastProvider` context.
|
|
85
|
+
*
|
|
86
|
+
* The `ToastContainer` must be placed inside a `ToastProvider`. It automatically subscribes
|
|
87
|
+
* to the toast context and renders any active toasts. The container itself is invisible and
|
|
88
|
+
* does not capture pointer events, but individual toasts within it do.
|
|
89
|
+
*
|
|
90
|
+
* ## Usage
|
|
91
|
+
*
|
|
92
|
+
* ```tsx
|
|
93
|
+
* <ToastProvider>
|
|
94
|
+
* <App />
|
|
95
|
+
* <ToastContainer
|
|
96
|
+
* verticalAlign="bottom"
|
|
97
|
+
* horizontalAlign="right"
|
|
98
|
+
* />
|
|
99
|
+
* </ToastProvider>
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* ## Positioning
|
|
103
|
+
*
|
|
104
|
+
* Toasts can be positioned in any corner or centered horizontally:
|
|
105
|
+
*
|
|
106
|
+
* | Position | Props |
|
|
107
|
+
* |----------|-------|
|
|
108
|
+
* | Bottom-left | `verticalAlign="bottom" horizontalAlign="left"` (default) |
|
|
109
|
+
* | Bottom-right | `verticalAlign="bottom" horizontalAlign="right"` |
|
|
110
|
+
* | Bottom-center | `verticalAlign="bottom" horizontalAlign="center"` |
|
|
111
|
+
* | Top-left | `verticalAlign="top" horizontalAlign="left"` |
|
|
112
|
+
* | Top-right | `verticalAlign="top" horizontalAlign="right"` |
|
|
113
|
+
* | Top-center | `verticalAlign="top" horizontalAlign="center"` |
|
|
114
|
+
*
|
|
115
|
+
* Use `horizontalOffset` and `verticalOffset` to add padding from the edges.
|
|
116
|
+
*
|
|
117
|
+
* ## Stacking
|
|
53
118
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
119
|
+
* When multiple toasts are active, they stack vertically. With `verticalAlign="bottom"`,
|
|
120
|
+
* newer toasts appear above older ones. With `verticalAlign="top"`, newer toasts
|
|
121
|
+
* appear below older ones.
|
|
56
122
|
*/
|
|
57
123
|
var ToastContainer = function (_a) {
|
|
58
124
|
var _b = _a.horizontalOffset, horizontalOffset = _b === void 0 ? 0 : _b, _c = _a.verticalOffset, verticalOffset = _c === void 0 ? 0 : _c, _d = _a.verticalAlign, verticalAlign = _d === void 0 ? 'bottom' : _d, _e = _a.horizontalAlign, horizontalAlign = _e === void 0 ? 'left' : _e, props = __rest(_a, ["horizontalOffset", "verticalOffset", "verticalAlign", "horizontalAlign"]);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { IToastMessage } from './IToastMessage';
|
|
3
|
-
import { IToastProps } from './IToastProps';
|
|
2
|
+
import type { IToastMessage } from './IToastMessage';
|
|
3
|
+
import type { IToastProps } from './IToastProps';
|
|
4
4
|
interface IToastContext {
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new `Toast`, with the React node for content. Optional
|
|
7
7
|
* properties can be provided.
|
|
8
8
|
*/
|
|
9
|
-
toast: (content: React.ReactNode, options
|
|
9
|
+
toast: (content: React.ReactNode, options?: IToastProps) => void;
|
|
10
10
|
/**
|
|
11
11
|
* Removes all toasts from the display.
|
|
12
12
|
*/
|
|
@@ -23,4 +23,5 @@ interface IToastContext {
|
|
|
23
23
|
remove: (key: string) => void;
|
|
24
24
|
}
|
|
25
25
|
declare const ToastContext: React.Context<IToastContext>;
|
|
26
|
-
export { ToastContext
|
|
26
|
+
export { ToastContext };
|
|
27
|
+
export type { IToastContext };
|
|
@@ -22,6 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import * as React from 'react';
|
|
24
24
|
import { ToastContext } from './ToastContext';
|
|
25
|
+
var toastCounter = 0;
|
|
25
26
|
/**
|
|
26
27
|
* The `ToastProvider` is a React context that wraps both components that
|
|
27
28
|
* generate toasts (through `useToast`) and the `ToastContainer` that displays
|
|
@@ -39,18 +40,22 @@ var ToastProvider = function (_a) {
|
|
|
39
40
|
* can be provided.
|
|
40
41
|
*/
|
|
41
42
|
var toast = function (content, options) {
|
|
42
|
-
setMessages(function (
|
|
43
|
+
setMessages(function (prevMessages) {
|
|
44
|
+
var _a;
|
|
45
|
+
var keys = Object.keys(prevMessages);
|
|
46
|
+
var newMessages = __assign({}, prevMessages);
|
|
43
47
|
// Remove excess messages:
|
|
44
|
-
while (
|
|
45
|
-
|
|
48
|
+
while (keys.length >= maxToasts) {
|
|
49
|
+
var oldestKey = keys.shift();
|
|
50
|
+
var _b = newMessages, _c = oldestKey, _ = _b[_c], rest = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
51
|
+
newMessages = rest;
|
|
46
52
|
}
|
|
47
|
-
// Create new message:
|
|
48
|
-
var key =
|
|
49
|
-
|
|
53
|
+
// Create new message with unique key:
|
|
54
|
+
var key = "toast-".concat(++toastCounter);
|
|
55
|
+
return __assign(__assign({}, newMessages), (_a = {}, _a[key] = {
|
|
50
56
|
message: content,
|
|
51
57
|
options: options
|
|
52
|
-
};
|
|
53
|
-
return __assign({}, messages);
|
|
58
|
+
}, _a));
|
|
54
59
|
});
|
|
55
60
|
};
|
|
56
61
|
/**
|
|
@@ -63,9 +68,9 @@ var ToastProvider = function (_a) {
|
|
|
63
68
|
* Remove a toast from the display list by key.
|
|
64
69
|
*/
|
|
65
70
|
var remove = function (key) {
|
|
66
|
-
setMessages(function (
|
|
67
|
-
|
|
68
|
-
return
|
|
71
|
+
setMessages(function (prevMessages) {
|
|
72
|
+
var _a = prevMessages, _b = key, _ = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
73
|
+
return rest;
|
|
69
74
|
});
|
|
70
75
|
};
|
|
71
76
|
return (React.createElement(ToastContext.Provider, { value: { toast: toast, messages: messages, clear: clear, remove: remove } }, props.children));
|
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A hook that provides access to the toast notification system.
|
|
3
|
+
*
|
|
4
|
+
* Must be used within a `ToastProvider`. Returns an object with methods to create,
|
|
5
|
+
* remove, and manage toast notifications.
|
|
6
|
+
*
|
|
7
|
+
* ## Usage
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const { toast, clear, remove, messages } = useToast();
|
|
11
|
+
*
|
|
12
|
+
* // Show a simple toast
|
|
13
|
+
* toast("Operation completed");
|
|
14
|
+
*
|
|
15
|
+
* // Show a toast with options
|
|
16
|
+
* toast("File saved", { duration: 3000, dismissable: true });
|
|
17
|
+
*
|
|
18
|
+
* // Show a toast with an action
|
|
19
|
+
* toast("Email sent", {
|
|
20
|
+
* action: () => openEmail(),
|
|
21
|
+
* actionLabel: "View"
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Clear all toasts
|
|
25
|
+
* clear();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ## Returned Object
|
|
29
|
+
*
|
|
30
|
+
* | Property | Type | Description |
|
|
31
|
+
* |----------|------|-------------|
|
|
32
|
+
* | `toast` | `(content, options?) => void` | Create a new toast notification |
|
|
33
|
+
* | `clear` | `() => void` | Remove all active toasts |
|
|
34
|
+
* | `remove` | `(key) => void` | Remove a specific toast by key |
|
|
35
|
+
* | `messages` | `object` | Current active toasts (for advanced use) |
|
|
36
|
+
*
|
|
37
|
+
* @throws Error if called outside of a `ToastProvider`
|
|
38
|
+
* @returns The toast context with methods to manage notifications
|
|
3
39
|
*/
|
|
4
40
|
declare const useToast: () => import("./ToastContext").IToastContext;
|
|
5
41
|
export { useToast };
|
|
@@ -1,9 +1,49 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ToastContext } from './ToastContext';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* A hook that provides access to the toast notification system.
|
|
5
|
+
*
|
|
6
|
+
* Must be used within a `ToastProvider`. Returns an object with methods to create,
|
|
7
|
+
* remove, and manage toast notifications.
|
|
8
|
+
*
|
|
9
|
+
* ## Usage
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { toast, clear, remove, messages } = useToast();
|
|
13
|
+
*
|
|
14
|
+
* // Show a simple toast
|
|
15
|
+
* toast("Operation completed");
|
|
16
|
+
*
|
|
17
|
+
* // Show a toast with options
|
|
18
|
+
* toast("File saved", { duration: 3000, dismissable: true });
|
|
19
|
+
*
|
|
20
|
+
* // Show a toast with an action
|
|
21
|
+
* toast("Email sent", {
|
|
22
|
+
* action: () => openEmail(),
|
|
23
|
+
* actionLabel: "View"
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Clear all toasts
|
|
27
|
+
* clear();
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* ## Returned Object
|
|
31
|
+
*
|
|
32
|
+
* | Property | Type | Description |
|
|
33
|
+
* |----------|------|-------------|
|
|
34
|
+
* | `toast` | `(content, options?) => void` | Create a new toast notification |
|
|
35
|
+
* | `clear` | `() => void` | Remove all active toasts |
|
|
36
|
+
* | `remove` | `(key) => void` | Remove a specific toast by key |
|
|
37
|
+
* | `messages` | `object` | Current active toasts (for advanced use) |
|
|
38
|
+
*
|
|
39
|
+
* @throws Error if called outside of a `ToastProvider`
|
|
40
|
+
* @returns The toast context with methods to manage notifications
|
|
5
41
|
*/
|
|
6
42
|
var useToast = function () {
|
|
7
|
-
|
|
43
|
+
var context = React.useContext(ToastContext);
|
|
44
|
+
if (context === null) {
|
|
45
|
+
throw new Error('useToast must be used within a ToastProvider');
|
|
46
|
+
}
|
|
47
|
+
return context;
|
|
8
48
|
};
|
|
9
49
|
export { useToast };
|