Skip to content

Commit

Permalink
Loading Toast
Browse files Browse the repository at this point in the history
  • Loading branch information
kikipoulet committed Sep 12, 2024
1 parent c27ea3e commit 1f0de91
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
Content="Show Toast" />
</suki:GroupBox>
</suki:GlassCard>

<suki:GlassCard>
<suki:GroupBox Header="Loading Toast">
<Button Margin="15,10,15,0"
Command="{Binding ShowLoadingToastCommand}"
Content="Show Toast" />
</suki:GroupBox>
</suki:GlassCard>
<suki:GlassCard>
<suki:GroupBox Header="3 Info Toasts">
<Button Margin="15,10,15,0"
Expand Down
12 changes: 12 additions & 0 deletions SukiUI.Demo/Features/ControlsLibrary/Toasts/ToastsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ private void ShowUpdatingToast()
[RelayCommand]
private void ShowErrorToast() => ShowTypeDemoToast(NotificationType.Error);

[RelayCommand]
private void ShowLoadingToast()
{
toastManager.CreateToast()
.WithTitle("Loading")
.WithLoadingState(true)
.WithContent(
$"This is a loading toast.")
.Dismiss().After(TimeSpan.FromSeconds(3))
.Dismiss().ByClicking()
.Queue();
}
private void ShowTypeDemoToast(NotificationType toastType)
{
toastManager.CreateToast()
Expand Down
5 changes: 4 additions & 1 deletion SukiUI/Controls/SukiToast.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@
VerticalAlignment="Center"
Data="{TemplateBinding Icon}"
Foreground="White" />

<Border IsVisible="{TemplateBinding LoadingState}" Background="{DynamicResource SukiCardBackground}">

<suki:WaveProgress IsTextVisible="False" Value="50" Height="35" Width="35"></suki:WaveProgress>
</Border>
</Panel>
</Border>
</Border>
Expand Down
8 changes: 8 additions & 0 deletions SukiUI/Controls/SukiToast.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public string Title
get => GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}

public static readonly StyledProperty<bool> LoadingStateProperty = AvaloniaProperty.Register<SukiToast, bool>(nameof(LoadingState));

public bool LoadingState
{
get => GetValue(LoadingStateProperty);
set => SetValue(LoadingStateProperty, value);
}

public static readonly StyledProperty<bool> CanDismissByClickingProperty = AvaloniaProperty.Register<SukiToast, bool>(nameof(CanDismissByClicking));

Expand Down
10 changes: 10 additions & 0 deletions SukiUI/Toasts/FluentSukiToastBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public static SukiToastBuilder WithTitle(this SukiToastBuilder builder, string t
return builder;
}


/// <summary>
/// Show a loading Toast.
/// </summary>
public static SukiToastBuilder WithLoadingState(this SukiToastBuilder builder, bool state)
{
builder.SetLoadingState(state);
return builder;
}

/// <summary>
/// Gives the toast some content. This can be a ViewModel if desired - View will be located via the default location strategy.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions SukiUI/Toasts/ISukiToast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface ISukiToast
object? Icon { get; set; }
IBrush? Foreground { get; set; }
bool CanDismissByClicking { get; set; }
bool LoadingState { get; set; }
Action<ISukiToast>? OnDismissed { get; set; }
Action<ISukiToast> OnClicked { get; set; }
ObservableCollection<object> ActionButtons { get; }
Expand Down
1 change: 1 addition & 0 deletions SukiUI/Toasts/SukiToastBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ISukiToast Queue()
public void SetContent(object? content) => Toast.Content = content;

public void SetCanDismissByClicking(bool canDismiss) => Toast.CanDismissByClicking = canDismiss;
public void SetLoadingState(bool loading) => Toast.LoadingState = loading;

public void SetType(NotificationType type)
{
Expand Down

0 comments on commit 1f0de91

Please sign in to comment.