Skip to content

Commit d28715c

Browse files
authored
[dev-v5] Add a generic FluentOption<TOption> (#4456)
* Add a generic FluentOption<T> * Fix Unit Tests * Rename FluentOption TOption to TValue * Distinct TOption and TValue * Add a OptionValueFormatted parameter and update the examples * Update sample * Rename to OptionValue and OptionBindedValue * Refactor select components for consistency and debugging * Improve type safety and validation in FluentSelect/Option * Update docs and parsing for generic component types * Update doc * Fix build errors * Fix Unit Tests * Update Unit Tests * Rename OptionBindedValue to OptionValue (extracts value from option) and OptionValue to OptionValueToString (formats value for HTML) * Update example * Fix Unit Tests * Add "pointer-events: none;" * Fix doc and update test
1 parent bd5cedd commit d28715c

45 files changed

Lines changed: 482 additions & 271 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/Demo/FluentUI.Demo.Client/Documentation/Components/Image/Examples/FluentImageFit.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<FluentSelect TOption="ImageFit" Items="@(Enum.GetValues<ImageFit>())" @bind-Value="@_selectedFit" />
1+
<FluentSelect Items="@(Enum.GetValues<ImageFit>())" @bind-Value="@_selectedFit" />
22
<div style="width: auto; height: 400px; margin-top: 10px">
33
<FluentImage Fit="@_selectedFit" Source="/big-heart.jpg" AlternateText="Placeholder Image" />
44
</div>

examples/Demo/FluentUI.Demo.Client/Documentation/Components/Image/Examples/FluentImageShape.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<FluentSelect TOption="ImageShape" Items="@(Enum.GetValues<ImageShape>())" @bind-Value="@_selectedShape" />
1+
<FluentSelect Items="@(Enum.GetValues<ImageShape>())" @bind-Value="@_selectedShape" />
22
<div style="width: auto; height: 300px; margin-top: 10px">
33
<FluentImage Shape="@_selectedShape" Source="/big-heart.jpg" AlternateText="Placeholder Image" />
44
</div>

examples/Demo/FluentUI.Demo.Client/Documentation/Components/List/Combobox/Examples/ComboboxDefault.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<FluentCombobox Label="Countries"
2-
TOption="@SampleData.Olympics2024.Country"
32
Placeholder="Select your countries"
43
Multiple="true"
54
OptionText="@(i => i?.Name)"

examples/Demo/FluentUI.Demo.Client/Documentation/Components/List/Combobox/FluentCombobox.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ You can customize the items in the **FluentSelect** component by using Lambda ex
5050
The following example shows how to customize the items:
5151
- `OptionText`: This function is used to customize the text of the option. <br />
5252
- `OptionValue`: This function is used to customize the value of the option. <br />
53+
- `OptionValueToString`: This function is used to customize the HTML value of the option. <br />
5354
- `OptionDisabled`: This function is used to define the disabled options. <br />
5455

5556
See a similar example on the [FluentSelect](/List/Select#customize-the-items) page.
5657

5758
## API FluentCombobox
5859

59-
{{ API Type=FluentCombobox }}
60+
{{ API Type=FluentCombobox<string,string> }}
6061

6162
> [!NOTE] The `Width` parameter is not yet implemented.
6263
6364
## API FluentOption
6465

65-
{{ API Type=FluentOption }}
66+
{{ API Type=FluentOption<string> }}
6667

6768
## Migrating to v5
6869

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<FluentOption Selected>
1+
<FluentOption TValue="string" Selected>
22
<FluentAvatar Size="AvatarSize.Size16" Color="AvatarColor.Blue" Slot="@FluentSlot.Start">16</FluentAvatar>
33
Option with 16px avatar
44
</FluentOption>
55
<br />
66

7-
<FluentOption>
7+
<FluentOption TValue="string">
88
<FluentIcon Value="@(new Icons.Regular.Size24.Globe())" Color="Color.Error" Slot="@FluentSlot.Start" />
99
Option with 24px icon
1010
</FluentOption>
1111
<br />
12-
<FluentOption Selected Description="Additional information can be provided with the description parameter">
12+
<FluentOption TValue="string" Selected Description="Additional information can be provided with the description parameter">
1313
<FluentAvatar Size="AvatarSize.Size32" Color="AvatarColor.Blue" Slot="@FluentSlot.Start">32</FluentAvatar>
1414
Option with 32px avatar
1515
</FluentOption>

examples/Demo/FluentUI.Demo.Client/Documentation/Components/List/Select/Examples/SelectAppearance.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242

4343
@code {
4444
static string[] Colors = ["Red", "Green", "Blue"];
45-
string Value = "Red";
45+
string Value = "Green";
4646
}

examples/Demo/FluentUI.Demo.Client/Documentation/Components/List/Select/Examples/SelectCustomized.razor

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Items="@Coworkers"
66
@bind-Value="@Value"
77
OptionText="@(item => item?.FirstName)"
8-
OptionValue="@(item => item?.Id)"
8+
OptionValueToString="@(item => item?.Id)"
99
OptionDisabled="@(item => item == Coworkers.ElementAt(3))" />
1010

1111
<div>
@@ -14,8 +14,7 @@
1414

1515
@code {
1616
static Samples.Person?[] OneNullPerson = new Samples.Person?[] { null };
17-
static Samples.Person?[] Coworkers =>
18-
OneNullPerson.Union(Samples.Persons.Take(5).ToArray()).ToArray();
17+
static Samples.Person?[] Coworkers = OneNullPerson.Union(Samples.Persons.Take(5).ToArray()).ToArray();
1918

2019
Samples.Person? Value = Coworkers.ElementAt(2);
2120
}

examples/Demo/FluentUI.Demo.Client/Documentation/Components/List/Select/Examples/SelectEnum.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Items="@GetEnumValues()"
55
@bind-Value="@Value">
66
<OptionTemplate>
7-
<FluentStack>
7+
<FluentStack Style="pointer-events: none;">
88
<div class="color-block" style="--item-color: @context.ToAttributeValue()"></div>
99
<span>@context</span>
1010
</FluentStack>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- Using Items -->
2+
<FluentSelect Label="Language"
3+
Items="@Languages"
4+
@bind-Value="@SelectedId1"
5+
OptionText="@(i => i.Name)"
6+
OptionValue="@(i => i.Id)" />
7+
8+
<!-- Using FluentOptions -->
9+
<FluentSelect Label="Language"
10+
TOption="Language"
11+
TValue="int?"
12+
@bind-Value="@SelectedId2">
13+
<FluentOption TValue="int?" Value="@(null)" Text="[Select]" />
14+
@foreach (var language in Languages)
15+
{
16+
<FluentOption TValue="int?" Value="@language.Id">
17+
@language.Name
18+
</FluentOption>
19+
}
20+
</FluentSelect>
21+
22+
<div>
23+
IDs: (@SelectedId1, @SelectedId2)
24+
</div>
25+
26+
@code {
27+
28+
int SelectedId1 = 3;
29+
int? SelectedId2 = 3;
30+
31+
static Language[] Languages = new Language[]
32+
{
33+
new(1, "C#"),
34+
new(2, "Java"),
35+
new(3, "Python"),
36+
new(4, "JavaScript"),
37+
new(5, "Go")
38+
};
39+
40+
record Language(int Id, string Name);
41+
}

examples/Demo/FluentUI.Demo.Client/Documentation/Components/List/Select/Examples/SelectManual.razor

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
<FluentSelect Label="RGB Color"
1+
<FluentSelect TOption="string"
2+
TValue="string"
3+
Label="RGB Color"
24
Placeholder="Select a color"
35
@bind-Value="@Value">
4-
<FluentOption Value="#ff0000">Red</FluentOption>
5-
<FluentOption Value="#00ff00">Green</FluentOption>
6-
<FluentOption Value="#0000ff">Blue</FluentOption>
6+
<FluentOptionString Value="ff0000">Red</FluentOptionString>
7+
<FluentOptionString Value="00ff00">Green</FluentOptionString>
8+
<FluentOptionString Value="0000ff">Blue</FluentOptionString>
79
</FluentSelect>
810

911
<div>

0 commit comments

Comments
 (0)