From 91517237c3e5379e21e58f1def05f47448005f51 Mon Sep 17 00:00:00 2001 From: Peace Date: Tue, 9 Jul 2024 16:31:42 +0900 Subject: [PATCH] rating --- .../Components/Layout/NavMenu.razor | 1 + .../Pages/FormInputs/FormInputRating.razor | 139 ++++++++++++++++++ BlazorFluentUI/wwwroot/app-cutom.css | 12 ++ 3 files changed, 152 insertions(+) create mode 100644 BlazorFluentUI/Components/Pages/FormInputs/FormInputRating.razor diff --git a/BlazorFluentUI/Components/Layout/NavMenu.razor b/BlazorFluentUI/Components/Layout/NavMenu.razor index 5501058..935c1be 100644 --- a/BlazorFluentUI/Components/Layout/NavMenu.razor +++ b/BlazorFluentUI/Components/Layout/NavMenu.razor @@ -32,6 +32,7 @@ NumberField Radio + Rating diff --git a/BlazorFluentUI/Components/Pages/FormInputs/FormInputRating.razor b/BlazorFluentUI/Components/Pages/FormInputs/FormInputRating.razor new file mode 100644 index 0000000..1ff5147 --- /dev/null +++ b/BlazorFluentUI/Components/Pages/FormInputs/FormInputRating.razor @@ -0,0 +1,139 @@ +@page "/forminputrating" +@using Microsoft.FluentUI.AspNetCore.Components.Extensions + +@rendermode RenderMode.InteractiveServer + +Rating + + + The FluentRating component allows users to provide a rating for a particular item. + + +Accessiblilty + + You can use the arrow keys to + increase (➡️/⬆️) + or + decrease (⬅️/⬇️) + the value + + +Default Example + + + + @LabelText + + Clear Rating + + +Customization + + + + Value: @_value + + + + + + + + + + + + + + + + + + + + + + +@code { + int SelectedValue = 0; + int? HoverValue = null; + + private string LabelText => (HoverValue ?? SelectedValue) switch + { + 1 => "Very bad", + 2 => "Bad", + 3 => "Sufficient", + 4 => "Good", + 5 => "Awesome!", + _ => "Rate our product!" + }; + + readonly List IconsName = ["Heart", "Star", "Alert", "PersonCircle"]; + readonly Icon[] IconsFilled = new Icon[] + { + new Icons.Filled.Size20.Heart(), + new Icons.Filled.Size20.Star(), + new Icons.Filled.Size20.Alert(), + new Icons.Filled.Size20.PersonCircle(), + }; + readonly Icon[] IconsOutline = new Icon[] + { + new Icons.Regular.Size20.Heart(), + new Icons.Regular.Size20.Star(), + new Icons.Regular.Size20.Alert(), + new Icons.Regular.Size20.PersonCircle(), + }; + + bool _readOnly = false; + bool _disabled = false; + bool _allowReset = false; + int _maxValue = 10; + int _value = 2; + Color _iconColor = Color.Error; + + Icon _iconFilled = new Icons.Filled.Size20.Star(); + Icon _iconOutline = new Icons.Regular.Size20.Star(); + + + void SetIcon(string? name) + { + var index = name is null ? 0 : IconsName.IndexOf(name); + + _iconFilled = IconsFilled[index]; + _iconOutline = IconsOutline[index]; + } + + protected override void OnParametersSet() => SetIcon(null); +} diff --git a/BlazorFluentUI/wwwroot/app-cutom.css b/BlazorFluentUI/wwwroot/app-cutom.css index 9bee22b..b50eb57 100644 --- a/BlazorFluentUI/wwwroot/app-cutom.css +++ b/BlazorFluentUI/wwwroot/app-cutom.css @@ -16,8 +16,20 @@ border-width: 1px } +.fluent-border-s1-r5 { + border-radius: 5px; + border-style: solid; + border-color: var(--accent-fill-rest); + border-width: 1px +} + .fluent-border-d1 { border-style: dashed; border-color: var(--accent-fill-rest); border-width: 1px +} + +.fluent-fixed-w100 { + max-width: 100px; + min-width: 100px; } \ No newline at end of file