From 671bf91e86067861ed084191f5152bae0677a2b6 Mon Sep 17 00:00:00 2001 From: Peace Date: Mon, 8 Jul 2024 18:03:59 +0900 Subject: [PATCH] combobox 1 --- .../Components/Layout/NavMenu.razor | 3 + .../Pages/FormInputs/FormInputCombobox.razor | 36 +++++++++++ BlazorFluentUI/Program.cs | 1 + BlazorFluentUI/Services/TestDataService.cs | 62 +++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 BlazorFluentUI/Components/Pages/FormInputs/FormInputCombobox.razor create mode 100644 BlazorFluentUI/Services/TestDataService.cs diff --git a/BlazorFluentUI/Components/Layout/NavMenu.razor b/BlazorFluentUI/Components/Layout/NavMenu.razor index 10fd007..6112cd7 100644 --- a/BlazorFluentUI/Components/Layout/NavMenu.razor +++ b/BlazorFluentUI/Components/Layout/NavMenu.razor @@ -25,6 +25,9 @@ Overview Checkbox InputFile + + Combobox + diff --git a/BlazorFluentUI/Components/Pages/FormInputs/FormInputCombobox.razor b/BlazorFluentUI/Components/Pages/FormInputs/FormInputCombobox.razor new file mode 100644 index 0000000..43ba0cc --- /dev/null +++ b/BlazorFluentUI/Components/Pages/FormInputs/FormInputCombobox.razor @@ -0,0 +1,36 @@ +@page "/forminputcombobox" + +@inject TestDataService dataService; + +@rendermode RenderMode.InteractiveServer + +Combobox + + + The FluentCombobox wrap a web component of a combobox. + + +Default Example + +

Select the T-shirt of best song from the list

+ + + +
+ Result: Lable @song?, Image @singer?, Size @size? +
+
+ +@code { + string? song; + string? singer; + string? size; + + protected override void OnInitialized() + { + singer = dataService.Singers.FirstOrDefault(); + } +} diff --git a/BlazorFluentUI/Program.cs b/BlazorFluentUI/Program.cs index 4b6e627..f6f9f22 100644 --- a/BlazorFluentUI/Program.cs +++ b/BlazorFluentUI/Program.cs @@ -16,6 +16,7 @@ builder.Services.AddRazorComponents(options => builder.Services.AddFluentUIComponents(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/BlazorFluentUI/Services/TestDataService.cs b/BlazorFluentUI/Services/TestDataService.cs new file mode 100644 index 0000000..be1d57d --- /dev/null +++ b/BlazorFluentUI/Services/TestDataService.cs @@ -0,0 +1,62 @@ +namespace BlazorFluentUI.Services +{ + public class TestDataService + { + public List Songs { get; set; } + public List Singers { get; set; } + public List Sizes { get; set; } + + public TestDataService() + { + Songs = GenerateRandomHitSongs(); + Singers = GenerateRandomSingers(); + Sizes = GenerateRandomSizes(); + } + + private List GenerateRandomHitSongs() + { + var random = new Random(); + var songs = new List + { + "Bohemian Rhapsody", "Imagine", "Hey Jude", "Like a Rolling Stone", "I Can't Get No Satisfaction", + "Good Vibrations", "Smells Like Teen Spirit", "What's Going On", "Hotel California", "One" + }; + + var hitSongs = new List(); + for (int i = 0; i < 5; i++) + { + hitSongs.Add(songs[random.Next(songs.Count)]); + } + + return hitSongs; + } + + private List GenerateRandomSingers() + { + var random = new Random(); + var singers = new List + { + "The Beatles", "Elvis Presley", "Michael Jackson", "Madonna", "Elton John", + "Led Zeppelin", "Pink Floyd", "Queen", "The Rolling Stones", "U2" + }; + + var randomSingers = new List(); + for (int i = 0; i < 5; i++) + { + randomSingers.Add(singers[random.Next(singers.Count)]); + } + + return randomSingers; + } + + private List GenerateRandomSizes() + { + var sizes = new List + { + "Extra Small", "Small", "Medium", "Large", "Extra Large", "Extra Extra Large" + }; + + return sizes; + } + } +}