diff --git a/src/ShadUI.Demo/MainWindow.axaml b/src/ShadUI.Demo/MainWindow.axaml index e63e5705..b3258cb1 100644 --- a/src/ShadUI.Demo/MainWindow.axaml +++ b/src/ShadUI.Demo/MainWindow.axaml @@ -345,6 +345,20 @@ + + + + + + + ] [Transient] [Transient] +[Transient] [Transient] [Transient] [Transient] diff --git a/src/ShadUI.Demo/ViewModels/ProgressBarViewModel.cs b/src/ShadUI.Demo/ViewModels/ProgressBarViewModel.cs new file mode 100644 index 00000000..cbf8a83a --- /dev/null +++ b/src/ShadUI.Demo/ViewModels/ProgressBarViewModel.cs @@ -0,0 +1,51 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using System; +using System.IO; + +namespace ShadUI.Demo.ViewModels; + +[Page("progressBar")] +public sealed partial class ProgressBarViewModel : ViewModelBase, INavigable +{ + private readonly PageManager _pageManager; + + public ProgressBarViewModel(PageManager pageManager) + { + _pageManager = pageManager; + + var xamlPath = Path.Combine(AppContext.BaseDirectory, "views", "ProgressBarPage.axaml"); + DefaultProgressBar = xamlPath.ExtractByLineRange(58, 66).CleanIndentation(); + SuccessProgressBar = xamlPath.ExtractByLineRange(72, 81).CleanIndentation(); + InfoProgressBar = xamlPath.ExtractByLineRange(87, 96).CleanIndentation(); + WarningProgressBar = xamlPath.ExtractByLineRange(102, 111).CleanIndentation(); + DangerProgressBar = xamlPath.ExtractByLineRange(117, 126).CleanIndentation(); + } + + [RelayCommand] + private void BackPage() + { + _pageManager.Navigate(); + } + + [RelayCommand] + private void NextPage() + { + _pageManager.Navigate(); + } + + [ObservableProperty] + private string _defaultProgressBar = string.Empty; + + [ObservableProperty] + private string _successProgressBar = string.Empty; + + [ObservableProperty] + private string _infoProgressBar = string.Empty; + + [ObservableProperty] + private string _warningProgressBar = string.Empty; + + [ObservableProperty] + private string _dangerProgressBar = string.Empty; +} \ No newline at end of file diff --git a/src/ShadUI.Demo/ViewModels/ToastViewModel.cs b/src/ShadUI.Demo/ViewModels/ToastViewModel.cs index 6aeee923..7e5c2cf9 100644 --- a/src/ShadUI.Demo/ViewModels/ToastViewModel.cs +++ b/src/ShadUI.Demo/ViewModels/ToastViewModel.cs @@ -1,8 +1,9 @@ -using System; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using System; using System.Collections.ObjectModel; using System.IO; -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; +using System.Threading.Tasks; namespace ShadUI.Demo.ViewModels; @@ -26,6 +27,7 @@ public ToastViewModel(PageManager pageManager, ToastManager toastManager) WarningToastCode = WrapCode(path.ExtractByLineRange(122, 129).CleanIndentation()); ErrorToastCode = WrapCode(path.ExtractByLineRange(134, 141).CleanIndentation()); DynamicToastCode = WrapCode(path.ExtractByLineRange(148, 173).CleanIndentation()); + DynamicToastCodeWithProgressBar = WrapCode(path.ExtractByLineRange(175, 197).CleanIndentation()); } [RelayCommand] @@ -170,4 +172,27 @@ private void ShowToastWithType() .DismissOnClick() .Show(SelectedNotification); } + + [ObservableProperty] + private Notification _selectedNotificationWithProgressBar; + + [ObservableProperty] + private bool _isProgressIndeterminate = true; + + [ObservableProperty] + private int _progressValue = 30; + + [ObservableProperty] + private string _dynamicToastCodeWithProgressBar = string.Empty; + + [RelayCommand] + private async Task ShowToastWithProgressBar() + { + _toastManager.CreateToast("Your message has been sent.") + .WithContent($"{DateTime.Now:dddd, MMMM d 'at' h:mm tt}") + .WithAction("Retry", () => _toastManager.CreateToast("Retry clicked").Show(Notification.Success)) + .DismissOnClick() + .WithProgressBar(IsProgressIndeterminate, ProgressValue) + .Show(SelectedNotificationWithProgressBar); + } } \ No newline at end of file diff --git a/src/ShadUI.Demo/Views/ProgressBarPage.axaml b/src/ShadUI.Demo/Views/ProgressBarPage.axaml new file mode 100644 index 00000000..d5b080e0 --- /dev/null +++ b/src/ShadUI.Demo/Views/ProgressBarPage.axaml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ShadUI.Demo/Views/ProgressBarPage.axaml.cs b/src/ShadUI.Demo/Views/ProgressBarPage.axaml.cs new file mode 100644 index 00000000..ed284fb9 --- /dev/null +++ b/src/ShadUI.Demo/Views/ProgressBarPage.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace ShadUI.Demo.Views; + +public partial class ProgressBarPage : UserControl +{ + public ProgressBarPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/ShadUI.Demo/Views/ToastPage.axaml b/src/ShadUI.Demo/Views/ToastPage.axaml index 6716f923..6d9834bc 100644 --- a/src/ShadUI.Demo/Views/ToastPage.axaml +++ b/src/ShadUI.Demo/Views/ToastPage.axaml @@ -7,7 +7,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:shadui="clr-namespace:ShadUI;assembly=ShadUI" xmlns:viewModels="clr-namespace:ShadUI.Demo.ViewModels" - d:DesignHeight="450" + d:DesignHeight="4250" d:DesignWidth="800" x:DataType="viewModels:ToastViewModel" mc:Ignorable="d"> @@ -204,6 +204,37 @@ + + + + + Notification + Send a notification to the client with progress bar + + + + + + + + + + + + + + + + + + + + diff --git a/src/ShadUI/Controls/Toast/Toast.axaml.cs b/src/ShadUI/Controls/Toast/Toast.axaml.cs index bf8c220c..5edd489a 100644 --- a/src/ShadUI/Controls/Toast/Toast.axaml.cs +++ b/src/ShadUI/Controls/Toast/Toast.axaml.cs @@ -115,6 +115,33 @@ public bool CanDismissByClicking set => SetValue(CanDismissByClickingProperty, value); } + public static readonly StyledProperty ShowProgressBarProperty = + AvaloniaProperty.Register(nameof(ShowProgressBar)); + + public bool ShowProgressBar + { + get => GetValue(ShowProgressBarProperty); + set => SetValue(ShowProgressBarProperty, value); + } + + public static readonly StyledProperty IsProgressIndeterminateProperty = + AvaloniaProperty.Register(nameof(IsProgressIndeterminate), true); + + public bool IsProgressIndeterminate + { + get => GetValue(IsProgressIndeterminateProperty); + set => SetValue(IsProgressIndeterminateProperty, value); + } + + public static readonly StyledProperty ProgressValueProperty = + AvaloniaProperty.Register(nameof(ProgressValue), 0); + + public double ProgressValue + { + get => GetValue(ProgressValueProperty); + set => SetValue(ProgressValueProperty, value); + } + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); diff --git a/src/ShadUI/Controls/Toast/ToastBuilder.cs b/src/ShadUI/Controls/Toast/ToastBuilder.cs index 045605f7..b7fdcef9 100644 --- a/src/ShadUI/Controls/Toast/ToastBuilder.cs +++ b/src/ShadUI/Controls/Toast/ToastBuilder.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; // ReSharper disable once CheckNamespace namespace ShadUI; @@ -34,6 +35,10 @@ internal ToastBuilder(ToastManager manager) internal ToastPosition? Position { get; set; } + internal bool ShowProgressBar { get; set; } + internal bool IsProgressIndeterminate { get; set; } + internal int ProgressValue { get; set; } + internal ToastBuilder CreateToast(string title) { _toast = new Toast(_manager) @@ -54,6 +59,9 @@ internal void Show() _toast.CanDismissByClicking = DismissOnClick; _toast.Action = Action; _toast.Position = Position; + _toast.ShowProgressBar = ShowProgressBar; + _toast.IsProgressIndeterminate = IsProgressIndeterminate; + _toast.ProgressValue = ProgressValue; _manager.Queue(_toast); } } \ No newline at end of file diff --git a/src/ShadUI/Controls/Toast/ToastBuilderExtensions.cs b/src/ShadUI/Controls/Toast/ToastBuilderExtensions.cs index 9467ce0c..93fa4f8f 100644 --- a/src/ShadUI/Controls/Toast/ToastBuilderExtensions.cs +++ b/src/ShadUI/Controls/Toast/ToastBuilderExtensions.cs @@ -55,6 +55,27 @@ public static ToastBuilder WithAction(this ToastBuilder builder, string label, A return builder; } + /// + /// Enables display of the ProgressBar. + /// + /// The current + /// + /// If true, the progress bar will show an indeterminate (animated) state. + /// If false, the progress bar will reflect a specific value provided by . + /// + /// + /// The initial progress value (0–100) to display when is false. + /// Ignored if is true. + /// + /// + public static ToastBuilder WithProgressBar(this ToastBuilder builder, bool isIndeterminate = true, int progressValue = 0) + { + builder.ShowProgressBar = true; + builder.IsProgressIndeterminate = isIndeterminate; + builder.ProgressValue = progressValue; + return builder; + } + /// /// Sets the toast position to the top left. ///