-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(snackbar-service): remove Toasts and add EnqueuedSnackbars (#…
…1039) * 🎬 docs: fix exmaple * 🚧 feat: wip * 🆕 feat(Alert): add Title parameter * 🚧 feat: wip * 🆕 feat: add DefaultsProvider * 🚸 feat: enhance the stability of docs * 📝 docs: Add docs about defaults-providers * ♻ refactor: Update namespace * 🎬 docs: update example * 📝 docs(PopupService): update docs * 💄 style: Improve the ui of docs * 🆕 feat: update error-handler * ⚰ refactor: remove todo * 🐛 fix: build error
- Loading branch information
Showing
85 changed files
with
1,257 additions
and
1,545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
docs/Masa.Blazor.Docs/Examples/components/defaults-providers/Usage.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<div> | ||
<MCard Class="ma-10"> | ||
<MCardTitle>Title</MCardTitle> | ||
<MCardSubtitle>Subtitle</MCardSubtitle> | ||
</MCard> | ||
|
||
<MDefaultsProvider Defaults="@_defaults"> | ||
<MCard Class="ma-10"> | ||
<MCardTitle>Title</MCardTitle> | ||
<MCardSubtitle>Subtitle</MCardSubtitle> | ||
</MCard> | ||
</MDefaultsProvider> | ||
</div> | ||
|
||
@code { | ||
|
||
private readonly IDictionary<string, IDictionary<string, object>> _defaults = new Dictionary<string, IDictionary<string, object>>() | ||
{ | ||
{ | ||
nameof(MCard), new Dictionary<string, object>() | ||
{ | ||
{ nameof(MCard.Elevation), (StringNumber)10 } | ||
} | ||
} | ||
}; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
docs/Masa.Blazor.Docs/Examples/components/enqueued-snackbars/Action.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<div class="text-center"> | ||
<PEnqueuedSnackbars @ref="_enqueuedSnackbars" MaxCount="1" /> | ||
<MButton OnClick="TurnToText" Color="@_color">Turn to red</MButton> | ||
</div> | ||
|
||
@code { | ||
|
||
private PEnqueuedSnackbars? _enqueuedSnackbars; | ||
|
||
private string? _color; | ||
|
||
private void TurnToText() | ||
{ | ||
_color = "red"; | ||
|
||
_enqueuedSnackbars?.EnqueueSnackbar(new SnackbarOptions() | ||
{ | ||
Content = "Turn to red successfully!", | ||
Closeable = true, | ||
ActionText = "Undo", | ||
OnAction = async () => | ||
{ | ||
await Task.Delay(1000); | ||
_color = null; | ||
} | ||
}); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
docs/Masa.Blazor.Docs/Examples/components/enqueued-snackbars/Type.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="text-center"> | ||
<PEnqueuedSnackbars @ref="_enqueuedSnackbars"></PEnqueuedSnackbars> | ||
|
||
<MButton Color="info" Outlined OnClick="() => Enqueue(AlertTypes.Info)">Info</MButton> | ||
<MButton Color="warning" Outlined OnClick="() => Enqueue(AlertTypes.Warning)">Warning</MButton> | ||
<MButton Color="success" Outlined OnClick="() => Enqueue(AlertTypes.Success)">Success</MButton> | ||
<MButton Color="error" Outlined OnClick="() => Enqueue(AlertTypes.Error)">Error</MButton> | ||
</div> | ||
|
||
@code { | ||
|
||
private PEnqueuedSnackbars? _enqueuedSnackbars; | ||
|
||
private void Enqueue(AlertTypes type) | ||
{ | ||
_enqueuedSnackbars?.EnqueueSnackbar(new SnackbarOptions() | ||
{ | ||
Content = $"{type} snackbar!", | ||
Type = type, | ||
Closeable = true | ||
}); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
docs/Masa.Blazor.Docs/Examples/components/enqueued-snackbars/Usage/AdvanceUsage.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@namespace Masa.Blazor.Docs.Examples.components.enqueued_snackbars | ||
@inherits Masa.Blazor.Presets.PEnqueuedSnackbars | ||
|
||
<div class="text-center"> | ||
<PEnqueuedSnackbars Position="@Position" | ||
Timeout="@Timeout" | ||
MaxCount="@MaxCount" | ||
Closeable="Closeable" | ||
@ref="_enqueuedSnackbars" /> | ||
<MButton OnClick="Enqueue">Enqueue a snackbar</MButton> | ||
</div> | ||
|
||
@code { | ||
|
||
private PEnqueuedSnackbars? _enqueuedSnackbars; | ||
|
||
private void Enqueue() | ||
{ | ||
if (_enqueuedSnackbars is null) return; | ||
|
||
var content = DateTime.UtcNow; | ||
|
||
var snackbar = new SnackbarOptions() | ||
{ | ||
Title = "Enqueued snackbars", | ||
Content = $"created at {content} UTC" | ||
}; | ||
|
||
_enqueuedSnackbars.EnqueueSnackbar(snackbar); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
docs/Masa.Blazor.Docs/Examples/components/enqueued-snackbars/Usage/Usage.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Masa.Blazor.Presets; | ||
|
||
namespace Masa.Blazor.Docs.Examples.components.enqueued_snackbars; | ||
|
||
public class Usage : Masa.Blazor.Docs.Components.Usage | ||
{ | ||
public Usage() : base(typeof(AdvanceUsage)) | ||
{ | ||
} | ||
|
||
protected override string ComponentName => nameof(PEnqueuedSnackbars); | ||
|
||
protected override ParameterList<SelectParameter> GenSelectParameters() => new() | ||
{ | ||
{ | ||
nameof(PEnqueuedSnackbars.Position), new SelectParameter(new List<string>() | ||
{ | ||
nameof(SnackPosition.TopLeft), | ||
nameof(SnackPosition.TopRight), | ||
nameof(SnackPosition.TopCenter), | ||
nameof(SnackPosition.BottomLeft), | ||
nameof(SnackPosition.BottomRight), | ||
nameof(SnackPosition.BottomCenter), | ||
}, nameof(SnackPosition.BottomCenter)) | ||
} | ||
}; | ||
|
||
protected override ParameterList<CheckboxParameter> GenCheckboxParameters() => new() | ||
{ | ||
{ nameof(PEnqueuedSnackbars.Closeable), new CheckboxParameter(true) } | ||
}; | ||
|
||
protected override ParameterList<SliderParameter> GenSliderParameters() => new() | ||
{ | ||
{ nameof(PEnqueuedSnackbars.MaxCount), new SliderParameter(5, 1, 10, 1) }, | ||
{ nameof(PEnqueuedSnackbars.Timeout), new SliderParameter(5000, 0, 9000, 1000) }, | ||
}; | ||
|
||
protected override object? CastValue(ParameterItem<object?> parameter) | ||
{ | ||
return parameter.Key switch | ||
{ | ||
nameof(PEnqueuedSnackbars.Position) => GetPosition(parameter.Value?.ToString()), | ||
nameof(PEnqueuedSnackbars.MaxCount) => int.Parse(parameter.Value!.ToString()!), | ||
nameof(PEnqueuedSnackbars.Timeout) => int.Parse(parameter.Value!.ToString()!), | ||
_ => parameter.Value | ||
}; | ||
} | ||
|
||
protected override string FormatValue(string key, object value) | ||
{ | ||
if (key == nameof(PEnqueuedSnackbars.Position)) | ||
{ | ||
return value.ToString() switch | ||
{ | ||
nameof(SnackPosition.TopLeft) => "@SnackPosition.TopLeft", | ||
nameof(SnackPosition.TopRight) => "@SnackPosition.TopRight", | ||
nameof(SnackPosition.TopCenter) => "@SnackPosition.TopCenter", | ||
nameof(SnackPosition.BottomLeft) => "@SnackPosition.BottomLeft", | ||
nameof(SnackPosition.BottomRight) => "@SnackPosition.BottomRight", | ||
nameof(SnackPosition.BottomCenter) => "@SnackPosition.BottomCenter", | ||
_ => base.FormatValue(key, value) | ||
}; | ||
} | ||
|
||
return base.FormatValue(key, value); | ||
} | ||
|
||
private static SnackPosition GetPosition(string? name) | ||
{ | ||
return name switch | ||
{ | ||
nameof(SnackPosition.TopLeft) => SnackPosition.TopLeft, | ||
nameof(SnackPosition.TopRight) => SnackPosition.TopRight, | ||
nameof(SnackPosition.TopCenter) => SnackPosition.TopCenter, | ||
nameof(SnackPosition.BottomLeft) => SnackPosition.BottomLeft, | ||
nameof(SnackPosition.BottomRight) => SnackPosition.BottomRight, | ||
_ => SnackPosition.BottomCenter | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
docs/Masa.Blazor.Docs/Examples/components/popup-service/Alert.razor
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.