Skip to content

Commit 456ea8d

Browse files
committed
FluentToast wip
1 parent e68137b commit 456ea8d

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

examples/FluentUI.Demo.Shared/Pages/Toast/Examples/ToastProgressToasts.razor

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<FluentButton Appearance=Appearance.Neutral @onclick="@(() => ToastManager.ShowToast<ProgressToast>(_progressToastParameters1, settings => { settings.Timeout = 150; }))">Progress toast example 1</FluentButton>
44

5-
5+
<FluentButton Appearance="Appearance.Accent" @onclick=UpdateProgress>Update</FluentButton>
66

77
@code {
88
private ProgressToastParameters _progressToastParameters1 = default!;
@@ -14,15 +14,25 @@
1414
{
1515
Intent = ToastIntent.Upload,
1616
Title = "Uploading file",
17-
Details = "This may tkae a while.",
17+
Details = "This may take a while.",
1818
PrimaryAction = new ToastAction() { Text = "Cancel", Href = "#", OnClick = Clicked },
1919
SecondaryAction = new ToastAction() { Text = "Pause", Href = "#", OnClick = Clicked },
20-
Progress = 60
20+
Progress = "0"
2121
};
2222
}
2323

2424
private void Clicked()
2525
{
2626
DemoLogger.WriteLine("Clicked toast action");
2727
}
28+
29+
private void UpdateProgress()
30+
{
31+
for (int i = 0; i < 100; i++)
32+
{
33+
_progressToastParameters1.Progress = i.ToString();
34+
StateHasChanged();
35+
Thread.Sleep(100);
36+
};
37+
}
2838
}

examples/FluentUI.Demo.Shared/wwwroot/sources/ToastProgressToasts.razor.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<FluentButton Appearance=Appearance.Neutral @onclick="@(() => ToastManager.ShowToast<ProgressToast>(_progressToastParameters1, settings => { settings.Timeout = 150; }))">Progress toast example 1</FluentButton>
44

5-
5+
<FluentButton Appearance="Appearance.Accent" @onclick=UpdateProgress>Update</FluentButton>
66

77
@code {
88
private ProgressToastParameters _progressToastParameters1 = default!;
@@ -14,15 +14,25 @@
1414
{
1515
Intent = ToastIntent.Upload,
1616
Title = "Uploading file",
17-
Details = "This may tkae a while.",
17+
Details = "This may take a while.",
1818
PrimaryAction = new ToastAction() { Text = "Cancel", Href = "#", OnClick = Clicked },
1919
SecondaryAction = new ToastAction() { Text = "Pause", Href = "#", OnClick = Clicked },
20-
Progress = 60
20+
Progress = "0"
2121
};
2222
}
2323

2424
private void Clicked()
2525
{
2626
DemoLogger.WriteLine("Clicked toast action");
2727
}
28+
29+
private void UpdateProgress()
30+
{
31+
for (int i = 0; i < 100; i++)
32+
{
33+
_progressToastParameters1.Progress = i.ToString();
34+
StateHasChanged();
35+
Thread.Sleep(100);
36+
};
37+
}
2838
}

src/Microsoft.Fast.Components.FluentUI/Components/Toast/ContentComponents/ProgressToast.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
<div class="fluent-toast-details">@Details</div>
3636
}
3737

38-
@Progress
38+
<FluentProgress Class="fluent-toast-progressbar" Min="0" Max="100" @bind-Value="@Progress"></FluentProgress>
39+
<div class="fluent-toast-progressbar-percentage">@Progress%</div>
3940

4041

4142
@if (PrimaryAction is not null || SecondaryAction is not null)

src/Microsoft.Fast.Components.FluentUI/Components/Toast/ContentComponents/ProgressToast.razor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,24 @@ public partial class ProgressToast
5050
public ToastAction? SecondaryAction { get; set; }
5151

5252
[Parameter]
53-
public FluentProgress? Progress { get; set; } = default!;
53+
public string? Progress { get; set; }
54+
55+
[Parameter]
56+
public EventCallback<string?> ProgressChanged { get; set; }
5457

5558
protected override void OnInitialized()
5659
{
5760
_toastId = Toast.Id;
5861
Settings = Toast.Settings;
62+
5963
}
6064

6165
protected override void OnParametersSet()
6266
{
6367
if (EndContentType == ToastEndContentType.Action)
6468
throw new InvalidOperationException("EndContentType.Action is not supported for a CommunicationToast ");
69+
70+
6571
}
6672

6773
/// <summary>

src/Microsoft.Fast.Components.FluentUI/Components/Toast/Parameters/ProgressToastParameters.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class ProgressToastParameters : ToastParameters
99
private string? _details;
1010
private ToastAction? _primaryAction;
1111
private ToastAction? _secondaryAction;
12+
private string? _progress;
1213

1314
public ToastIntent Intent
1415
{
@@ -82,5 +83,23 @@ public ToastAction? SecondaryAction
8283
}
8384
}
8485

85-
public int Progress { get; set; }
86+
public string? Progress
87+
{
88+
get => _progress;
89+
set
90+
{
91+
_progress = value;
92+
if (!string.IsNullOrEmpty(_progress))
93+
{
94+
if (!Parameters.ContainsKey(nameof(Progress)))
95+
{
96+
Parameters.Add(nameof(Progress), _progress);
97+
}
98+
else
99+
{
100+
Parameters[nameof(Progress)] = _progress;
101+
}
102+
}
103+
}
104+
}
86105
}

0 commit comments

Comments
 (0)