From f20a1f2ca3c9547062b16014f0b24ada2e007043 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 12 Aug 2022 23:56:30 +0200 Subject: [PATCH] Added a generic assistant component --- .../UI MAUI/Components/Assistant.razor | 17 ++++++++++ .../UI MAUI/Components/Assistant.razor.cs | 32 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 I18N Commander/UI MAUI/Components/Assistant.razor create mode 100644 I18N Commander/UI MAUI/Components/Assistant.razor.cs diff --git a/I18N Commander/UI MAUI/Components/Assistant.razor b/I18N Commander/UI MAUI/Components/Assistant.razor new file mode 100644 index 0000000..c2439f9 --- /dev/null +++ b/I18N Commander/UI MAUI/Components/Assistant.razor @@ -0,0 +1,17 @@ +
+
+

+ @if (this.IsIconAvailable) + { + + } + @this.HeaderText +

+ +
+
+ @this.ChildContent +
+
\ No newline at end of file diff --git a/I18N Commander/UI MAUI/Components/Assistant.razor.cs b/I18N Commander/UI MAUI/Components/Assistant.razor.cs new file mode 100644 index 0000000..1980ea1 --- /dev/null +++ b/I18N Commander/UI MAUI/Components/Assistant.razor.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Components; + +namespace UI_MAUI.Components; + +public partial class Assistant : ComponentBase +{ + [Parameter] + public string HeaderText { get; set; } = string.Empty; + + [Parameter] + public string Name { get; set; } = "Assistant"; + + [Parameter] + public string IconName { get; set; } = string.Empty; + + [Parameter] + public Height BaseHeight { get; set; } = new(60, 40, 50); + + public readonly record struct Height(int Phone, int Desktop, int Tablet); + + [Parameter] + public RenderFragment ChildContent { get; set; } + + private string AssistantHeight => + DeviceInfo.Idiom == DeviceIdiom.Phone ? $"--bs-offcanvas-height: {this.BaseHeight.Phone}vh;" : + DeviceInfo.Idiom == DeviceIdiom.Tablet ? $"--bs-offcanvas-height: {this.BaseHeight.Tablet}vh;" : + $"--bs-offcanvas-height: {this.BaseHeight.Desktop}vh;"; + + private string HeaderIconAltText => $"Icon: {this.HeaderText}"; + + private bool IsIconAvailable => !string.IsNullOrWhiteSpace(this.IconName); +} \ No newline at end of file