SaveButton
Description
The SaveButton component is a specialized button designed to handle the various states of a saving operation. It automatically manages the visual representation of states such as "Save Pending", "Verifying", "Saving", "Saved", and "Error". This component simplifies the UI logic for save actions by encapsulating the state transitions and appropriate icon/text feedback.
Usage
Instantiate the SaveButton using the constructor. You can customize the text displayed for each state and handle click events. The button's state is controlled programmatically via the SetState method.
Enums
SaveState
- SavePending: The initial state, button is ready to be clicked (Primary style).
- Verifying: Indicates verification is in progress (Spinner, Disabled).
- Saving: Indicates saving is in progress (Spinner, Disabled).
- Saved: Indicates the save was successful (Success style).
- Error: Indicates an error occurred (Danger style).
API reference
public class SaveButton : IComponentA button variant that shows a "saving…" spinner and a confirmation tick while an async save operation is in progress.
Methods
public SaveButton Configure(string save = null, string verifying = null, string saving = null, string saved = null, string error = null, string saveHover = null, UIcons saveIcon = UIcons.Disk, UIcons saveHoverIcon = UIcons.Disk, bool pendingPrimary = true)Configures the component to configure.
public SaveButton SetState(State state, string message = null)Sets the state of the component.
public SaveButton NothingToSave(string message = null)Configures the nothing to save on the component.
public SaveButton Pending(string message = null)Configures the component to pending.
public SaveButton Verifying(string message = null)Configures the component to verifying.
public SaveButton Saving(string message = null)Configures the component to saving.
public SaveButton Saved(string message = null)Configures the component to saved.
public SaveButton Error(string message = null)Gets or sets the validation error message displayed beneath the component.
public SaveButton OnClick(Action action)Registers a callback invoked when the click event fires.
public SaveButton OnClickSpinWhile(Func<Task> actionAsync)Registers a callback invoked when the click spin while event fires.
public async Task<State> VerifyingWhile(Func<Task<State>> action, string text = null, Action<SaveButton, Exception> onError = null)Configures the verifying while on the component.
public SaveButton OnClickSpinWhile(Func<Task> action, string text = null, Action<SaveButton, Exception> onError = null)Registers a callback invoked when the click spin while event fires.