@ardium-ui/ui 5.0.0-alpha.89 → 5.0.0-alpha.90
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.
|
@@ -16925,28 +16925,58 @@ class _ArdSnackbarRefInternal {
|
|
|
16925
16925
|
this._onOpen.next();
|
|
16926
16926
|
this._onOpen.complete();
|
|
16927
16927
|
}
|
|
16928
|
-
markAsStartingToClose() {
|
|
16929
|
-
this._onCloseStart.next(
|
|
16928
|
+
markAsStartingToClose(withAction = false) {
|
|
16929
|
+
this._onCloseStart.next(withAction);
|
|
16930
16930
|
this._onCloseStart.complete();
|
|
16931
16931
|
}
|
|
16932
16932
|
}
|
|
16933
|
+
/**
|
|
16934
|
+
* Reference to an opened snackbar.
|
|
16935
|
+
* Provides methods for closing the snackbar programmatically, and observables for subscribing to open, close, and action events.
|
|
16936
|
+
*/
|
|
16933
16937
|
class ArdSnackbarRef {
|
|
16934
16938
|
constructor(dismiss, _onOpen, _onCloseStart) {
|
|
16935
16939
|
this.dismiss = dismiss;
|
|
16936
16940
|
this._onOpen = _onOpen;
|
|
16937
16941
|
this._onCloseStart = _onCloseStart;
|
|
16938
16942
|
this._onClose = new Subject();
|
|
16943
|
+
this._onAction = new Subject();
|
|
16944
|
+
/**
|
|
16945
|
+
* Observable that emits when the snackbar is opened. Completes after emitting the first value.
|
|
16946
|
+
*/
|
|
16939
16947
|
this.onOpen = this._onOpen.asObservable();
|
|
16948
|
+
/**
|
|
16949
|
+
* Observable that emits when the snackbar is closed and all animations have finished. Emits a boolean value indicating whether the snackbar was closed as a result of the user clicking the action button (true) or not (false). Completes after emitting the first value.
|
|
16950
|
+
*/
|
|
16940
16951
|
this.onClose = this._onClose.asObservable();
|
|
16952
|
+
/**
|
|
16953
|
+
* Observable that emits when the snackbar action is triggered, before the snackbar starts closing. Completes when the snackbar is closed, regardless of whether any value was emitted.
|
|
16954
|
+
*/
|
|
16955
|
+
this.onAction = this._onAction.asObservable();
|
|
16956
|
+
/**
|
|
16957
|
+
* Observable that emits when the snackbar starts the closing process. Emits a boolean value indicating whether the closing was triggered by the user clicking the action button (true) or not (false). Completes after emitting the first value.
|
|
16958
|
+
*/
|
|
16941
16959
|
this.onCloseStart = this._onCloseStart.asObservable();
|
|
16942
16960
|
this._isClosed = false;
|
|
16943
16961
|
}
|
|
16962
|
+
/**
|
|
16963
|
+
* Closes the snackbar, optionally indicating that the action was triggered.
|
|
16964
|
+
* @param withAction A boolean value indicating whether the snackbar is being closed as a result of the user clicking the action button (true) or not (false).
|
|
16965
|
+
*/
|
|
16944
16966
|
close(withAction = false) {
|
|
16945
16967
|
if (this.isClosed)
|
|
16946
16968
|
return;
|
|
16947
16969
|
this.dismiss(withAction);
|
|
16948
|
-
|
|
16970
|
+
if (withAction) {
|
|
16971
|
+
this._onAction.next();
|
|
16972
|
+
}
|
|
16973
|
+
this._onAction.complete();
|
|
16949
16974
|
}
|
|
16975
|
+
/**
|
|
16976
|
+
* Marks the snackbar as closed after the closing animation has finished.
|
|
16977
|
+
* @param withAction
|
|
16978
|
+
* @returns
|
|
16979
|
+
*/
|
|
16950
16980
|
markAsClosed(withAction = false) {
|
|
16951
16981
|
if (this.isClosed)
|
|
16952
16982
|
return;
|
|
@@ -16954,6 +16984,9 @@ class ArdSnackbarRef {
|
|
|
16954
16984
|
this._onClose.complete();
|
|
16955
16985
|
this._isClosed = true;
|
|
16956
16986
|
}
|
|
16987
|
+
/**
|
|
16988
|
+
* Indicates whether the snackbar has been closed and the closing animation has finished.
|
|
16989
|
+
*/
|
|
16957
16990
|
get isClosed() {
|
|
16958
16991
|
return this._isClosed;
|
|
16959
16992
|
}
|
|
@@ -17045,6 +17078,10 @@ const ARD_SNACKBAR_ANIMATION_LENGTH = new InjectionToken('ard-snackbar-animation
|
|
|
17045
17078
|
factory: () => 150,
|
|
17046
17079
|
});
|
|
17047
17080
|
|
|
17081
|
+
const TIMEOUT_LIMIT = 2_147_483_647; //maximum duration for setTimeout in browsers
|
|
17082
|
+
/**
|
|
17083
|
+
* Service for opening snackbars. Provides methods for opening snackbars with either a simple message and action, or with a custom component. Manages a queue of snackbars to be displayed, and handles the display and dismissal of snackbars according to the specified options. Also provides methods for retrieving and clearing the snackbar queue.
|
|
17084
|
+
*/
|
|
17048
17085
|
class ArdiumSnackbarService {
|
|
17049
17086
|
constructor() {
|
|
17050
17087
|
this._snackbarQueue = new Queue();
|
|
@@ -17054,6 +17091,14 @@ class ArdiumSnackbarService {
|
|
|
17054
17091
|
this._injector = inject(Injector);
|
|
17055
17092
|
}
|
|
17056
17093
|
//! public methods for creating new snackbars
|
|
17094
|
+
/**
|
|
17095
|
+
* Opens a snackbar with the given message, action and options.
|
|
17096
|
+
* @param message The message to display in the snackbar.
|
|
17097
|
+
* @param action The label for the snackbar action. If provided, the snackbar will have an action button with this label.
|
|
17098
|
+
* When the action button is clicked, the snackbar will emit a close event with `withAction` set to `true`.
|
|
17099
|
+
* @param options Additional options for configuring the snackbar.
|
|
17100
|
+
* @returns A reference to the opened snackbar.
|
|
17101
|
+
*/
|
|
17057
17102
|
open(message, action, options = {}) {
|
|
17058
17103
|
options.data = {
|
|
17059
17104
|
message,
|
|
@@ -17064,10 +17109,18 @@ class ArdiumSnackbarService {
|
|
|
17064
17109
|
mergedOptions.data.message = message;
|
|
17065
17110
|
mergedOptions.data.action = action;
|
|
17066
17111
|
}
|
|
17067
|
-
const internalRef = new _ArdSnackbarRefInternal(_ArdSimpleSnackbarComponent, mergedOptions, (withAction) =>
|
|
17112
|
+
const internalRef = new _ArdSnackbarRefInternal(_ArdSimpleSnackbarComponent, mergedOptions, (withAction) => {
|
|
17113
|
+
this.dismissCurrent(withAction);
|
|
17114
|
+
});
|
|
17068
17115
|
this._handleQueue(mergedOptions.queueHandling, internalRef);
|
|
17069
17116
|
return internalRef.publicRef;
|
|
17070
17117
|
}
|
|
17118
|
+
/**
|
|
17119
|
+
* Opens a snackbar with a custom component, passing the given options.
|
|
17120
|
+
* @param component The component to display inside the snackbar. This component will be instantiated and inserted into the snackbar overlay.
|
|
17121
|
+
* @param options Additional options for configuring the snackbar, such as data to pass to the component, placement, styling, etc.
|
|
17122
|
+
* @returns A reference to the opened snackbar, with the generic type of the component instance. You can use this reference to subscribe to open/close events, and to close the snackbar programmatically.
|
|
17123
|
+
*/
|
|
17071
17124
|
openFromComponent(component, options) {
|
|
17072
17125
|
const mergedOptions = this._mergeOptions(options);
|
|
17073
17126
|
const internalRef = new _ArdSnackbarRefInternal(component, mergedOptions, (withAction) => this.dismissCurrent(withAction));
|
|
@@ -17138,8 +17191,8 @@ class ArdiumSnackbarService {
|
|
|
17138
17191
|
sb.publicRef.instance = componentRef.instance;
|
|
17139
17192
|
sb.markAsOpened();
|
|
17140
17193
|
this._openedSnackbar = sb;
|
|
17141
|
-
const duration = sb.options.duration === Infinity || sb.options.duration <= 0
|
|
17142
|
-
?
|
|
17194
|
+
const duration = sb.options.duration === Infinity || sb.options.duration <= 0 || sb.options.duration > TIMEOUT_LIMIT
|
|
17195
|
+
? TIMEOUT_LIMIT
|
|
17143
17196
|
: sb.options.duration;
|
|
17144
17197
|
sb.timeout = setTimeout(() => {
|
|
17145
17198
|
this.dismissCurrent(false);
|
|
@@ -17202,6 +17255,10 @@ class ArdiumSnackbarService {
|
|
|
17202
17255
|
return this._overlay.create(config);
|
|
17203
17256
|
}
|
|
17204
17257
|
//! public actions
|
|
17258
|
+
/**
|
|
17259
|
+
* Dismisses the currently opened snackbar, if any. If `withAction` is true, it indicates that the snackbar is being dismissed as a result of the user clicking the action button (if it has one). This will cause the snackbar to emit a close event with `withAction` set to true, allowing you to differentiate between automatic dismissal and user-initiated dismissal via the action button.
|
|
17260
|
+
* @param withAction Optional boolean indicating whether the dismissal is due to the user clicking the action button. Defaults to false. If true, the snackbar's close event will emit with `withAction` set to true, allowing you to handle this case differently if needed.
|
|
17261
|
+
*/
|
|
17205
17262
|
dismissCurrent(withAction) {
|
|
17206
17263
|
const sb = this._openedSnackbar;
|
|
17207
17264
|
if (!sb) {
|
|
@@ -17210,17 +17267,23 @@ class ArdiumSnackbarService {
|
|
|
17210
17267
|
}
|
|
17211
17268
|
sb.markAsStartingToClose();
|
|
17212
17269
|
setTimeout(() => {
|
|
17213
|
-
sb.overlay?.dispose();
|
|
17214
17270
|
this._openedSnackbar = undefined;
|
|
17215
17271
|
sb.publicRef.markAsClosed(withAction);
|
|
17272
|
+
sb.overlay?.dispose();
|
|
17216
17273
|
clearTimeout(sb.timeout);
|
|
17217
17274
|
this._openNext();
|
|
17218
17275
|
}, this._animationLength);
|
|
17219
17276
|
}
|
|
17220
17277
|
//! public queue methods
|
|
17278
|
+
/**
|
|
17279
|
+
* Returns an array of references to the snackbars currently in the queue, in the order they will be opened. Note that this does not include the currently opened snackbar, if any.
|
|
17280
|
+
*/
|
|
17221
17281
|
getQueue() {
|
|
17222
17282
|
return this._snackbarQueue.toArray().map(v => v.publicRef);
|
|
17223
17283
|
}
|
|
17284
|
+
/**
|
|
17285
|
+
* Clears all pending snackbars from the queue. Does not affect the currently opened snackbar, if any. Use with caution, as this will remove all pending snackbars that have not yet been displayed, and they will not be shown at all.
|
|
17286
|
+
*/
|
|
17224
17287
|
clearQueue() {
|
|
17225
17288
|
this._snackbarQueue.clear();
|
|
17226
17289
|
}
|