diff --git a/.github/workflows/ci-daily.yml b/.github/workflows/ci-daily.yml index fc1f372af6..c45af75924 100644 --- a/.github/workflows/ci-daily.yml +++ b/.github/workflows/ci-daily.yml @@ -16,7 +16,8 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x + include-prerelease: true - name: Restore dependencies run: dotnet restore - name: Build diff --git a/README.md b/README.md index c01867b0f2..2649a00041 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The `Microsoft.Fast.Components.FluentUI` package provides a lightweight set of [Blazor](https://blazor.net) component wrappers around Microsoft's official FluentUI Web Components. The FluentUI Web Components are built on [FAST](https://www.fast.design/) and work in every major browser. To get up and running with `Microsoft.Fast.Components.FluentUI` see the Getting Started section below. -The source for `@fluentui/web-components` is hosted in [the Fluent UI monorepo](https://github.com/microsoft/fluentui/tree/master/packages/web-components). +The source for `@fluentui/web-components` is hosted in [the Fluent UI monorepo](https://github.com/microsoft/fluentui/tree/master/packages/web-components). An implementation of all the current Fluent Web Components can be found at https://aka.ms/fluentwebcomponents. ## Getting Started diff --git a/examples/FluentUIServerSample/Components/FluentDataGridTest.razor b/examples/FluentUIServerSample/Components/FluentDataGridTest.razor index d1ed6e8671..6a65caa303 100644 --- a/examples/FluentUIServerSample/Components/FluentDataGridTest.razor +++ b/examples/FluentUIServerSample/Components/FluentDataGridTest.razor @@ -36,13 +36,13 @@

Sorting/Filtering grid

Filter Fruit - + SortColumn(context))> - @context.Title + @context.Title @if (context.Title == lastSortColumn?.Title) { - @(isAscending ? " ↑" : " ↓") + @(isAscending ? " ↑" : " ↓") } @@ -73,13 +73,13 @@ private bool isAscending = false; public string filterValue = ""; - List RowsGrid1 = new List() + List RowsGrid1 = new() { new SampleGrid1Data("Rob", 19 ), new SampleGrid1Data("Bob", 20 ) }; - List RowsGrid2 = new List() + List RowsGrid2 = new() { new SampleGrid2Data("value 1-1", "value 2-1", "value 3-1", "value 4-1" ), new SampleGrid2Data("value 1-2", "value 2-2", "value 3-2", "value 4-2" ), @@ -87,7 +87,7 @@ new SampleGrid2Data("value 1-4", "value 2-4", "value 3-4", "value 4-4" ) }; - + List RawSortedRowsGrid = new List() { new SampleGrid3Data("apples", "$1.50", "red" ), @@ -96,7 +96,7 @@ new SampleGrid3Data("oranges", "$1.25", "orange" ) }; - List SortedRowsGrid; + List SortedRowsGrid = new(); protected override void OnInitialized() @@ -112,7 +112,7 @@ SortingColumnsGrid.Add(new ColumnDefinition("Fruit", x => x.fruit)); SortingColumnsGrid.Add(new ColumnDefinition("Cost", x => x.cost)); SortingColumnsGrid.Add(new ColumnDefinition("Color", x => x.color)); - + SortedRowsGrid = RawSortedRowsGrid; base.OnInitialized(); @@ -121,7 +121,7 @@ private void FilterChanged(ChangeEventArgs args) { var filter = args.Value as string; - + if (string.IsNullOrWhiteSpace(filter)) { SortedRowsGrid = RawSortedRowsGrid; @@ -132,9 +132,9 @@ } if (lastSortColumn != null) { - SortedRowsGrid.Sort(new CustomComparer(lastSortColumn.FieldSelector, isAscending)); + SortedRowsGrid.Sort(new CustomComparer(lastSortColumn.FieldSelector!, isAscending)); } - + } private void SortColumn(ColumnDefinition columnDefinition) @@ -148,7 +148,7 @@ lastSortColumn = columnDefinition; isAscending = true; } - SortedRowsGrid.Sort(new CustomComparer(columnDefinition.FieldSelector, isAscending)); + SortedRowsGrid.Sort(new CustomComparer(columnDefinition.FieldSelector!, isAscending)); } class CustomComparer : IComparer @@ -162,10 +162,10 @@ _isAscending = isAscending; } - int IComparer.Compare(SampleGrid3Data x, SampleGrid3Data y) + int IComparer.Compare(SampleGrid3Data? x, SampleGrid3Data? y) { - var xs = _selector(x) as string; - var ys = _selector(y) as string; + var xs = _selector(x!) as string; + var ys = _selector(y!) as string; if (xs == null || ys == null) return 0; return string.Compare(xs, ys) * (_isAscending ? 1 : -1); diff --git a/examples/FluentUIServerSample/Components/FluentDialogTest.razor b/examples/FluentUIServerSample/Components/FluentDialogTest.razor index 4188a7237b..299b17fed6 100644 --- a/examples/FluentUIServerSample/Components/FluentDialogTest.razor +++ b/examples/FluentUIServerSample/Components/FluentDialogTest.razor @@ -15,12 +15,12 @@ @code{ - private FluentDialog MyFluentDialog; + private FluentDialog? MyFluentDialog; public bool ModalHidden { get; set; } = true; - private void OnOpenModalRefButtonClick() => MyFluentDialog.Show(); - private void OnCloseModalRefButtonClick() => MyFluentDialog.Hide(); + private void OnOpenModalRefButtonClick() => MyFluentDialog!.Show(); + private void OnCloseModalRefButtonClick() => MyFluentDialog!.Hide(); private void OnOpenModalParameterButtonClick() => ModalHidden = false; private void OnCloseModalParameterButtonClick() => ModalHidden = true; diff --git a/examples/FluentUIServerSample/Components/FluentSwitchTest.razor b/examples/FluentUIServerSample/Components/FluentSwitchTest.razor index 402fbf13e8..7d320a1b9d 100644 --- a/examples/FluentUIServerSample/Components/FluentSwitchTest.razor +++ b/examples/FluentUIServerSample/Components/FluentSwitchTest.razor @@ -1,25 +1,3 @@ -
- - - Direction - ltr - rtl - - - - Theme - Dark - Light - -

Switch

Default

diff --git a/examples/FluentUIServerSample/FluentUIServerSample.csproj b/examples/FluentUIServerSample/FluentUIServerSample.csproj index 014d3f0b8a..f03c13a521 100644 --- a/examples/FluentUIServerSample/FluentUIServerSample.csproj +++ b/examples/FluentUIServerSample/FluentUIServerSample.csproj @@ -1,12 +1,12 @@ - + - net5.0 - 5.0.10 + net6.0 + enable diff --git a/examples/FluentUIServerSample/Pages/ComponentBindings.razor b/examples/FluentUIServerSample/Pages/ComponentBindings.razor index 9b5259088e..88b4d3c102 100644 --- a/examples/FluentUIServerSample/Pages/ComponentBindings.razor +++ b/examples/FluentUIServerSample/Pages/ComponentBindings.razor @@ -158,22 +158,22 @@ private class FormModel { [Required] - public string SelectValue { get; set; } + public string? SelectValue { get; set; } [Required] - public string TextFieldValue { get; set; } + public string? TextFieldValue { get; set; } [Required] public int? NumberFieldValue { get; set; } [Required] - public string TextAreaValue { get; set; } + public string? TextAreaValue { get; set; } [Required] - public string ComboboxValue { get; set; } + public string? ComboboxValue { get; set; } [Required] - public string RadioGroupValue { get; set; } + public string? RadioGroupValue { get; set; } [Required] public bool CheckboxValue { get; set; } diff --git a/examples/FluentUIServerSample/Pages/Error.cshtml.cs b/examples/FluentUIServerSample/Pages/Error.cshtml.cs index cd304bb09e..f13f59953b 100644 --- a/examples/FluentUIServerSample/Pages/Error.cshtml.cs +++ b/examples/FluentUIServerSample/Pages/Error.cshtml.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; +using System.Diagnostics; namespace FluentUIServerSample.Pages { @@ -13,7 +9,7 @@ namespace FluentUIServerSample.Pages [IgnoreAntiforgeryToken] public class ErrorModel : PageModel { - public string RequestId { get; set; } + public string? RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); diff --git a/examples/FluentUIServerSample/Pages/RawBindings.razor b/examples/FluentUIServerSample/Pages/RawBindings.razor index f631fbeb95..468002831e 100644 --- a/examples/FluentUIServerSample/Pages/RawBindings.razor +++ b/examples/FluentUIServerSample/Pages/RawBindings.razor @@ -121,12 +121,12 @@
@code { - string TextFieldValueImplicit; - string TextFieldValueExplicit; + string? TextFieldValueImplicit; + string? TextFieldValueExplicit; int NumberFieldValueImplicit; int NumberFieldValueExplicit; - string TextAreaValueImplicit; - string TextAreaValueExplicit; + string? TextAreaValueImplicit; + string? TextAreaValueExplicit; bool CheckboxValueImplicit; bool CheckboxValueExplicit; bool SwitchValueImplicit; @@ -135,13 +135,12 @@ bool FluentMenuItemValueExplicit; int SliderValueImplicit; int SliderValueExplicit; - string SelectValueImplicit; - string SelectValueExplicit; - string RadioGroupValueImplicit; - string RadioGroupValueExplicit; + string? SelectValueImplicit; + string? SelectValueExplicit; + string? RadioGroupValueImplicit; + string? RadioGroupValueExplicit; int ListboxIndexValueImplicit; int ListboxIndexValueExplicit; - string ComboboxValueImplicit; - string ComboboxValueExplicit; - + string? ComboboxValueImplicit; + string? ComboboxValueExplicit; } diff --git a/examples/FluentUIServerSample/Pages/Webcomponents.razor b/examples/FluentUIServerSample/Pages/Webcomponents.razor index 7488a82c32..129cd4c22b 100644 --- a/examples/FluentUIServerSample/Pages/Webcomponents.razor +++ b/examples/FluentUIServerSample/Pages/Webcomponents.razor @@ -1,7 +1,57 @@ @page "/webcomponents/{Target?}" + + + @using FluentUIServerSample.Components + +
- +

Fluent components test page

  • @@ -118,6 +168,22 @@
+
+ + + Direction + ltr + rtl + + + + Theme + Dark + Light + +
@switch (Target) { case "Accordion": @@ -237,52 +303,9 @@ }
+
- -@code { - [Parameter] public string Target { get; set; } = null; +@code{ + [Parameter] public string? Target { get; set; } = null; } \ No newline at end of file diff --git a/examples/FluentUIServerSample/Properties/launchSettings.json b/examples/FluentUIServerSample/Properties/launchSettings.json index 572143dbe9..632be8cfb7 100644 --- a/examples/FluentUIServerSample/Properties/launchSettings.json +++ b/examples/FluentUIServerSample/Properties/launchSettings.json @@ -13,12 +13,14 @@ "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "hotReloadProfile": "aspnetcore" }, "FluentUIServerSample": { "commandName": "Project", "dotnetRunMessages": "true", "launchBrowser": true, + "hotReloadProfile": "aspnetcore", "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/src/Microsoft.Fast.Components.FluentUI/Appearance.cs b/src/Microsoft.Fast.Components.FluentUI/Appearance.cs index c62398311f..fb9406db33 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Appearance.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Appearance.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.Fast.Components.FluentUI { @@ -19,9 +17,9 @@ public enum Appearance internal static class AppearanceExtensions { - private static Dictionary _appearanceValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _appearanceValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Appearance? value) => value == null ? null : _appearanceValues[value.Value]; + public static string? ToAttributeValue(this Appearance? value) => value == null ? null : _appearanceValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Autocomplete.cs b/src/Microsoft.Fast.Components.FluentUI/Autocomplete.cs index 42cf879418..0dedbfd4da 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Autocomplete.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Autocomplete.cs @@ -13,10 +13,10 @@ public enum Autocomplete internal static class AutocompleteExtensions { - private static Dictionary _autocompleteValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _autocompleteValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Autocomplete? value) => value == null ? null : _autocompleteValues[value.Value]; + public static string? ToAttributeValue(this Autocomplete? value) => value == null ? null : _autocompleteValues[value.Value]; } public enum Position @@ -27,9 +27,9 @@ public enum Position internal static class PositionExtensions { - private static Dictionary _positionValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _positionValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Position? value) => value == null ? null : _positionValues[value.Value]; + public static string? ToAttributeValue(this Position? value) => value == null ? null : _positionValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Color.cs b/src/Microsoft.Fast.Components.FluentUI/Color.cs index 243da3600e..b93b7093f7 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Color.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Color.cs @@ -12,10 +12,10 @@ public enum Color internal static class ColorExtensions { - private static Dictionary _colorValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _colorValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Color? value) => value == null ? null : _colorValues[value.Value]; + public static string? ToAttributeValue(this Color? value) => value == null ? null : _colorValues[value.Value]; } public enum Fill @@ -26,9 +26,9 @@ public enum Fill internal static class FillExtensions { - private static Dictionary _fillValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _fillValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Fill? value) => value == null ? null : _fillValues[value.Value]; + public static string? ToAttributeValue(this Fill? value) => value == null ? null : _fillValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordion.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordion.razor index ab2eaab376..6eb43f03e9 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordion.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordion.razor @@ -1,8 +1,8 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public ExpandMode? ExpandMode { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordionItem.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordionItem.razor index c08d3efd8d..68bb0eab33 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordionItem.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAccordionItem.razor @@ -1,8 +1,8 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public bool? Expanded { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchor.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchor.razor index 4966e472df..45817f2c60 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchor.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchor.razor @@ -1,11 +1,11 @@ @ChildContent @code { - [Parameter] public string Href { get; set; } + [Parameter] public string? Href { get; set; } [Parameter] public Appearance? Appearance { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchoredRegion.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchoredRegion.razor index a316440c9a..18fab83675 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchoredRegion.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentAnchoredRegion.razor @@ -21,13 +21,13 @@ /// The html id of the HTMLElement used as the anchor around which the positioning region is placed. This must be set for the component's positioning logic to be active. /// [Parameter] - public string Anchor { get; set; } + public string? Anchor { get; set; } /// /// The ID of the HTMLElement to be used as the viewport used to determine available layout space around the anchor element. If unset the parent element of the anchored region is used. /// [Parameter] - public string Viewport { get; set; } + public string? Viewport { get; set; } /// /// Default is 'uncontrolled'. @@ -96,8 +96,8 @@ public UpdateMode? AutoUpdateMode { get; set; } = UpdateMode.Anchor; [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentBadge.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentBadge.razor index c9abdcd575..c26f7515d4 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentBadge.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentBadge.razor @@ -7,7 +7,7 @@ [Parameter] public Appearance? Appearance { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumb.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumb.razor index 63272960f1..47a66f6997 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumb.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumb.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumbItem.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumbItem.razor index c4fee0db5d..4af1f80142 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumbItem.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentBreadcrumbItem.razor @@ -1,9 +1,9 @@ @ChildContent @code { - [Parameter] public string Href { get; set; } + [Parameter] public string? Href { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentButton.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentButton.razor index e4e2457939..1ea1583b75 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentButton.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentButton.razor @@ -7,7 +7,7 @@ [Parameter] public bool? Autofocus { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCard.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCard.razor index bddcba0796..0ba27dc22d 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCard.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCard.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCheckbox.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCheckbox.razor index 74f0ad4b2b..fd4b530553 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCheckbox.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCheckbox.razor @@ -1,16 +1,22 @@ @inherits FluentInputBase @using System.Globalization -@ChildContent + + @ChildContent + @code { - [Parameter] public string Href { get; set; } + [Parameter] public string? Href { get; set; } [Parameter] public bool? Disabled { get; set; } [Parameter] public bool? Required { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - protected override bool TryParseValueFromString(string value, out bool result, out string validationErrorMessage) => + protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage) => throw new NotSupportedException($"This component does not parse string inputs. Bind to the '{nameof(CurrentValue)}' property, not '{nameof(CurrentValueAsString)}'."); } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCombobox.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCombobox.razor index b33aac87fd..b1d92d37b4 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCombobox.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCombobox.razor @@ -1,5 +1,12 @@ -@inherits FluentInputBase -@ChildContent +@inherits FluentInputBase + + @ChildContent + @code { [Parameter] public bool? Filled { get; set; } @@ -10,9 +17,9 @@ [Parameter] public Position? Position { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out string? result, [NotNullWhen(false)] out string? validationErrorMessage) { result = value; validationErrorMessage = null; diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGrid.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGrid.razor index 0d4af53db1..f4d687073e 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGrid.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGrid.razor @@ -11,7 +11,7 @@ @{ int gridColumn = 1; - foreach (ColumnDefinition column in ColumnDefinitions) + foreach (ColumnDefinition column in ColumnDefinitions!) { @if (HeaderCellTemplate != null) @@ -60,10 +60,10 @@ //FAST Properties [Parameter] - public List RowsData { get; set; } + public List? RowsData { get; set; } [Parameter] - public IEnumerable> ColumnDefinitions { get; set; } + public IEnumerable>? ColumnDefinitions { get; set; } [Parameter] public RenderFragment>? HeaderCellTemplate { get; set; } = null; @@ -73,11 +73,11 @@ // General Blazor parameters [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridCell.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridCell.razor index 6f0e05fd4b..550c781b44 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridCell.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridCell.razor @@ -15,8 +15,8 @@ // General Blazor parameters [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridRow.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridRow.razor index b935ef76ca..fcb5234f1a 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridRow.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDataGridRow.razor @@ -5,8 +5,8 @@ @attributes="@AdditionalAttributes"> @for(int index=0; index column = ColumnDefinitions?.ElementAt(index); - @(column.FieldSelector!(RowData)?.ToString()) + ColumnDefinition column = ColumnDefinitions!.ElementAt(index); + @(column.FieldSelector!(RowData!)?.ToString()) } @ChildContent @@ -24,15 +24,15 @@ // FAST Properties [Parameter] - public TItem RowData { get; set; } + public TItem? RowData { get; set; } [Parameter] public IEnumerable>? ColumnDefinitions { get; set; } // General Blazor parameters [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDesignSystemProvider.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDesignSystemProvider.razor index 4f00f555a2..191cb39d03 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDesignSystemProvider.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDesignSystemProvider.razor @@ -128,6 +128,6 @@ [Parameter] public int? NeutralStrokeFocusDelta { get; set; } [Parameter] public float? BaseLayerLuminance { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDialog.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDialog.razor index e60a603e67..727156733e 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDialog.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDialog.razor @@ -3,9 +3,9 @@ { [Parameter] public bool? Modal { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } [Parameter] public bool Hidden { get; set; } = false; diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDivider.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDivider.razor index 81210f4162..f318d3fb26 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentDivider.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentDivider.razor @@ -1,7 +1,7 @@ @ChildContent @code { - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentFlipper.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentFlipper.razor index bdeee2cb2f..8caa7667a2 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentFlipper.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentFlipper.razor @@ -5,7 +5,7 @@ [Parameter] public Direction? Direction { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentHorizontalScroll.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentHorizontalScroll.razor index 1705551c47..20b10b7c83 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentHorizontalScroll.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentHorizontalScroll.razor @@ -19,8 +19,8 @@ public string? Easing { get; set; } [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentListbox.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentListbox.razor index 4d0e448577..ac1e9415f6 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentListbox.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentListbox.razor @@ -1,7 +1,7 @@ @ChildContent @code { - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenu.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenu.razor index 4cf878fa1c..1f873a9c29 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenu.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenu.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenuItem.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenuItem.razor index b4d8df9c38..06b223eb69 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenuItem.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentMenuItem.razor @@ -4,7 +4,7 @@ [Parameter] public bool? Checked { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentNumberField.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentNumberField.razor index d6154c6e84..4f205eac50 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentNumberField.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentNumberField.razor @@ -1,4 +1,4 @@ -@inherits FluentInputBase +@inherits FluentInputBase @typeparam TValue @using System.Globalization; @using System.Reflection; @@ -12,7 +12,7 @@ maxlength="@MaxLength" minlength="@MinLength" size="@Size" - change="@(EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString))" + @onchange="@(EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString))" readonly="@Readonly" disabled="@Disabled" required="@Required" @@ -34,14 +34,14 @@ [Parameter] public Appearance? Appearance { get; set; } - [Parameter] public string Placeholder { get; set; } + [Parameter] public string? Placeholder { get; set; } [Parameter] public string ParsingErrorMessage { get; set; } = "The {0} field must be a number."; - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter] public string Min { get; set; } = GetMinOrMaxValue("MinValue"); - [Parameter] public string Max { get; set; } = GetMinOrMaxValue("MaxValue"); + [Parameter] public string? Min { get; set; } = GetMinOrMaxValue("MinValue"); + [Parameter] public string? Max { get; set; } = GetMinOrMaxValue("MaxValue"); [Parameter] public int MinLength { get; set; } = 1; [Parameter] public int MaxLength { get; set; } = 14; [Parameter] public int Step { get; set; } = _stepAttributeValue; @@ -69,7 +69,7 @@ } } - protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out TValue? result, [NotNullWhen(false)] out string? validationErrorMessage) { if (BindConverter.TryConvertTo(value, CultureInfo.InvariantCulture, out result)) { @@ -119,11 +119,11 @@ } } - private static string GetMinOrMaxValue(string name) + private static string? GetMinOrMaxValue(string name) { var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); - FieldInfo field = targetType.GetField(name, BindingFlags.Public | BindingFlags.Static); + FieldInfo? field = targetType.GetField(name, BindingFlags.Public | BindingFlags.Static); if (field == null) { throw new InvalidOperationException("Invalid type argument for FluentNumberField: " + typeof(TValue).Name); @@ -131,30 +131,31 @@ var value = field.GetValue(null); - - if (targetType == typeof(int) || targetType == typeof(short)) - { - return value.ToString(); - } - - if (targetType == typeof(long)) - { - //Precision in underlying Fast script is limited to 12 digits - return name == "MinValue" ? "-999999999999" : "999999999999"; - } - if (targetType == typeof(float)) + if (value is not null) { - return ((float)value).ToString(CultureInfo.InvariantCulture); + if (targetType == typeof(int) || targetType == typeof(short)) + { + return value.ToString(); + } + + if (targetType == typeof(long)) + { + //Precision in underlying Fast script is limited to 12 digits + return name == "MinValue" ? "-999999999999" : "999999999999"; + } + if (targetType == typeof(float)) + { + return ((float)value).ToString(CultureInfo.InvariantCulture); + } + if (targetType == typeof(double)) + { + return ((double)value).ToString(CultureInfo.InvariantCulture); + } + if (targetType == typeof(decimal)) + { + return ((decimal)value).ToString("G12", CultureInfo.InvariantCulture); + } } - if (targetType == typeof(double)) - { - return ((double)value).ToString(CultureInfo.InvariantCulture); - } - if (targetType == typeof(decimal)) - { - return ((decimal)value).ToString("G12", CultureInfo.InvariantCulture); - } - // This should never occur return "0"; } diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentOption.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentOption.razor index 39ea192485..11c932ca48 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentOption.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentOption.razor @@ -3,11 +3,11 @@ { [Parameter] public bool? Disabled { get; set; } - [Parameter] public string Value { get; set; } + [Parameter] public string? Value { get; set; } [Parameter] public bool? Selected { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgress.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgress.razor index 5ccc6a2484..24e37836be 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgress.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgress.razor @@ -8,7 +8,7 @@ [Parameter] public bool? Paused { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgressRing.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgressRing.razor index 078c912652..1a5fbc18c2 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgressRing.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentProgressRing.razor @@ -8,7 +8,7 @@ [Parameter] public bool? Paused { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadio.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadio.razor index 5f8af2db2a..3ba1221e7e 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadio.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadio.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public string Value { get; set; } + [Parameter] public string? Value { get; set; } [Parameter] public bool? Required { get; set; } @@ -8,7 +8,7 @@ [Parameter] public bool? Checked { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadioGroup.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadioGroup.razor index acf51456f6..96514adc58 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadioGroup.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentRadioGroup.razor @@ -1,16 +1,16 @@ -@inherits FluentInputBase +@inherits FluentInputBase @ChildContent @code{ - [Parameter] public string Name { get; set; } + [Parameter] public string? Name { get; set; } [Parameter] public bool? Required { get; set; } [Parameter] public Orientation? Orientation { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out string? result, [NotNullWhen(false)] out string? validationErrorMessage) { result = value; validationErrorMessage = null; diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSelect.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSelect.razor index 1f373fbb54..e6fd03059f 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSelect.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSelect.razor @@ -1,17 +1,25 @@ -@inherits FluentInputBase -@ChildContent +@inherits FluentInputBase + + @ChildContent + @code{ [Parameter] public bool? Disabled { get; set; } [Parameter] public bool? Filled { get; set; } - [Parameter] public string Name { get; set; } - + [Parameter] public string? Name { get; set; } + [Parameter] public Position? Position { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out string? result, [NotNullWhen(false)] out string? validationErrorMessage) { result = value; validationErrorMessage = null; diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSkeleton.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSkeleton.razor index 21ed0d8dc3..2413e91694 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSkeleton.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSkeleton.razor @@ -5,9 +5,9 @@ [Parameter] public bool? Shimmer { get; set; } - [Parameter] public string Pattern { get; set; } + [Parameter] public string? Pattern { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSlider.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSlider.razor index 0a6e582f25..839d9d1304 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSlider.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSlider.razor @@ -1,6 +1,16 @@ @inherits FluentInputBase @using System.Globalization -@ChildContent + + @ChildContent + @code{ [Parameter] public Orientation? Orientation { get; set; } @@ -15,9 +25,9 @@ [Parameter] public bool? Readonly { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - protected override bool TryParseValueFromString(string value, out int result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out int result, [NotNullWhen(false)] out string? validationErrorMessage) { if (BindConverter.TryConvertTo(value, CultureInfo.InvariantCulture, out result)) { @@ -31,7 +41,7 @@ } } - protected override string FormatValueAsString(int value) + protected override string? FormatValueAsString(int value) { return BindConverter.FormatValue(value, CultureInfo.InvariantCulture); } diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSliderLabel.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSliderLabel.razor index 580e3f5d55..8f7e936db8 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSliderLabel.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSliderLabel.razor @@ -1,10 +1,10 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public int? Position { get; set; } [Parameter] public bool? HideMark { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSwitch.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSwitch.razor index 01f031bf62..1a0d7b0630 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentSwitch.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentSwitch.razor @@ -6,7 +6,7 @@ [Parameter] public bool? Required { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTab.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTab.razor index ef61a728d9..1aae0b3c94 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTab.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTab.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabPanel.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabPanel.razor index a8d86b84dc..a3460fec27 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabPanel.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabPanel.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabs.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabs.razor index 4aee601b48..0bb3be1a83 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabs.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTabs.razor @@ -4,7 +4,7 @@ [Parameter] public Orientation? Orientation { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextArea.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextArea.razor index fc41500cb5..6bd611374c 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextArea.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextArea.razor @@ -1,5 +1,16 @@ -@inherits FluentInputBase -@ChildContent +@inherits FluentInputBase + + @ChildContent + @code{ [Parameter] public bool? Disabled { get; set; } @@ -13,11 +24,11 @@ [Parameter] public Appearance? Appearance { get; set; } - [Parameter] public string Placeholder { get; set; } + [Parameter] public string? Placeholder { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } - protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) + protected override bool TryParseValueFromString(string? value, out string? result, [NotNullWhen(false)] out string? validationErrorMessage) { result = value; validationErrorMessage = null; diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextField.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextField.razor index 395d730566..b58a2e9dac 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextField.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTextField.razor @@ -1,8 +1,8 @@ -@inherits FluentInputBase +@inherits FluentInputBase AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTooltip.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTooltip.razor index fefe2e0496..6775a5194e 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTooltip.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTooltip.razor @@ -27,8 +27,8 @@ public bool? VerticalViewportLock { get; set; } = false; [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public IDictionary AdditionalAttributes { get; set; } + public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeItem.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeItem.razor index d350b6a8b5..1ebecfce9e 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeItem.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeItem.razor @@ -1,6 +1,6 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public bool? Disabled { get; set; } @@ -8,5 +8,5 @@ [Parameter] public bool? Expanded { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeView.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeView.razor index 14df3beb27..8c6f9dcc8f 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeView.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentTreeView.razor @@ -1,8 +1,8 @@ @ChildContent @code{ - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public bool? RenderCollapsedNodes { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IDictionary? AdditionalAttributes { get; set; } } \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/NavLinkFluentAnchor.cs b/src/Microsoft.Fast.Components.FluentUI/Components/NavLinkFluentAnchor.cs index 79aa84b63a..ae301e066d 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/NavLinkFluentAnchor.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Components/NavLinkFluentAnchor.cs @@ -1,16 +1,12 @@ - using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Rendering; using Microsoft.AspNetCore.Components.Routing; -using System; -using System.Collections.Generic; -using System.Linq; namespace Microsoft.Fast.Components.FluentUI { public class NavLinkFluentAnchor : NavLink - { - [Parameter] public string Href { get; set; } + { + [Parameter] public string? Href { get; set; } [Parameter] public Appearance? Appearance { get; set; } diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/_Imports.razor b/src/Microsoft.Fast.Components.FluentUI/Components/_Imports.razor index c421ecb677..e3058c9c61 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Components/_Imports.razor +++ b/src/Microsoft.Fast.Components.FluentUI/Components/_Imports.razor @@ -1,3 +1,4 @@ @namespace Microsoft.Fast.Components.FluentUI @using System +@using System.Diagnostics.CodeAnalysis @using Microsoft.AspNetCore.Components.Web diff --git a/src/Microsoft.Fast.Components.FluentUI/DataGridCellType.cs b/src/Microsoft.Fast.Components.FluentUI/DataGridCellType.cs index 48a4669cd2..b7f9aa64fd 100644 --- a/src/Microsoft.Fast.Components.FluentUI/DataGridCellType.cs +++ b/src/Microsoft.Fast.Components.FluentUI/DataGridCellType.cs @@ -13,9 +13,9 @@ public enum DataGridCellType internal static class CellTypeExtensions { - private static Dictionary _cellTypeValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _cellTypeValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this DataGridCellType? value) => value == null ? null : _cellTypeValues[value.Value]; + public static string? ToAttributeValue(this DataGridCellType? value) => value == null ? null : _cellTypeValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/DataGridRowType.cs b/src/Microsoft.Fast.Components.FluentUI/DataGridRowType.cs index 512f4f2650..4e09fe2889 100644 --- a/src/Microsoft.Fast.Components.FluentUI/DataGridRowType.cs +++ b/src/Microsoft.Fast.Components.FluentUI/DataGridRowType.cs @@ -14,9 +14,9 @@ public enum DataGridRowType internal static class DataGridRowTypeExtensions { - private static Dictionary _dataGridRowTypeValues = - Enum.GetValues().ToDictionary(id => id, id => string.Join("-", Regex.Split(Enum.GetName(id), @"(? _dataGridRowTypeValues = + Enum.GetValues().ToDictionary(id => id, id => string.Join("-", Regex.Split(Enum.GetName(id)!, @"(? value == null ? null : _dataGridRowTypeValues[value.Value]; + public static string? ToAttributeValue(this DataGridRowType? value) => value == null ? null : _dataGridRowTypeValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Direction.cs b/src/Microsoft.Fast.Components.FluentUI/Direction.cs index 1a9e66c5f2..39f8a4d1a4 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Direction.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Direction.cs @@ -12,9 +12,9 @@ public enum Direction internal static class DirectionExtensions { - private static Dictionary _directionValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _directionValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Direction? value) => value == null ? null : _directionValues[value.Value]; + public static string? ToAttributeValue(this Direction? value) => value == null ? null : _directionValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/ExpandMode.cs b/src/Microsoft.Fast.Components.FluentUI/ExpandMode.cs index fdef294b20..32de7d82dd 100644 --- a/src/Microsoft.Fast.Components.FluentUI/ExpandMode.cs +++ b/src/Microsoft.Fast.Components.FluentUI/ExpandMode.cs @@ -11,9 +11,9 @@ public enum ExpandMode internal static class ExpandModeExtensions { - private static Dictionary _expandModeValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _expandModeValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this ExpandMode? value) => value == null ? null : _expandModeValues[value.Value]; + public static string? ToAttributeValue(this ExpandMode? value) => value == null ? null : _expandModeValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/FluentInputBase.cs b/src/Microsoft.Fast.Components.FluentUI/FluentInputBase.cs index af141c8063..d9a7e84ffc 100644 --- a/src/Microsoft.Fast.Components.FluentUI/FluentInputBase.cs +++ b/src/Microsoft.Fast.Components.FluentUI/FluentInputBase.cs @@ -1,39 +1,69 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Forms; -using System; +using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; namespace Microsoft.Fast.Components.FluentUI { public abstract class FluentInputBase : ComponentBase, IDisposable { private readonly EventHandler _validationStateChangedHandler; private bool _previousParsingAttemptFailed; - private ValidationMessageStore _parsingValidationMessages; - private Type _nullableUnderlyingType; - - [CascadingParameter] EditContext CascadedEditContext { get; set; } - - [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary AdditionalAttributes { get; set; } - + private ValidationMessageStore? _parsingValidationMessages; + private Type? _nullableUnderlyingType; + + [CascadingParameter] private EditContext? CascadedEditContext { get; set; } + + /// + /// Gets or sets a collection of additional attributes that will be applied to the created element. + /// + [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } + + /// + /// Gets or sets the value of the input. This should be used with two-way binding. + /// + /// + /// @bind-Value="model.PropertyName" + /// [Parameter] - public TValue Value { get; set; } + public TValue? Value { get; set; } + /// + /// Gets or sets a callback that updates the bound value. + /// [Parameter] public EventCallback ValueChanged { get; set; } - [Parameter] public Expression> ValueExpression { get; set; } - - [Parameter] public string DisplayName { get; set; } - - protected EditContext EditContext { get; set; } - + /// + /// Gets or sets an expression that identifies the bound value. + /// + [Parameter] public Expression>? ValueExpression { get; set; } + + /// + /// Gets or sets the display name for this field. + /// This value is used when generating error messages when the input value fails to parse correctly. + /// + [Parameter] public string? DisplayName { get; set; } + + /// + /// Gets the associated . + /// This property is uninitialized if the input does not have a parent . + /// + protected EditContext EditContext { get; set; } = default!; + + /// + /// Gets the for the bound value. + /// protected internal FieldIdentifier FieldIdentifier { get; set; } - protected TValue CurrentValue + /// + /// Gets or sets the current value of the input. + /// + protected TValue? CurrentValue { get => Value; set @@ -48,22 +78,14 @@ protected TValue CurrentValue } } - protected string CurrentValueAsString + /// + /// Gets or sets the current value of the input, represented as a string. + /// + protected string? CurrentValueAsString { get => FormatValueAsString(CurrentValue); set { - if (EditContext == null) - { - if (TryParseValueFromString(value, out var parsedValue, out var _)) - { - CurrentValue = parsedValue; - } - - // If we are not in the context of an edit form, don't do anything with the current value. - return; - } - _parsingValidationMessages?.Clear(); bool parsingFailed; @@ -85,51 +107,63 @@ protected string CurrentValueAsString { parsingFailed = true; - if (_parsingValidationMessages == null) + // EditContext may be null if the input is not a child component of EditForm. + if (EditContext is not null) { - _parsingValidationMessages = new ValidationMessageStore(EditContext); - } - - _parsingValidationMessages.Add(FieldIdentifier, validationErrorMessage); + _parsingValidationMessages ??= new ValidationMessageStore(EditContext); + _parsingValidationMessages.Add(FieldIdentifier, validationErrorMessage); - // Since we're not writing to CurrentValue, we'll need to notify about modification from here - EditContext.NotifyFieldChanged(FieldIdentifier); + // Since we're not writing to CurrentValue, we'll need to notify about modification from here + EditContext.NotifyFieldChanged(FieldIdentifier); + } } // We can skip the validation notification if we were previously valid and still are if (parsingFailed || _previousParsingAttemptFailed) { - EditContext.NotifyValidationStateChanged(); + EditContext?.NotifyValidationStateChanged(); _previousParsingAttemptFailed = parsingFailed; } } } + /// + /// Constructs an instance of . + /// protected FluentInputBase() { _validationStateChangedHandler = OnValidateStateChanged; } - protected virtual string FormatValueAsString(TValue value) + /// + /// Formats the value as a string. Derived classes can override this to determine the formating used for . + /// + /// The value to format. + /// A string representation of the value. + protected virtual string? FormatValueAsString(TValue? value) => value?.ToString(); - protected abstract bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage); - - private string FieldClass - => EditContext?.FieldCssClass(FieldIdentifier); - + /// + /// Parses a string to create an instance of . Derived classes can override this to change how + /// interprets incoming values. + /// + /// The string value to be parsed. + /// An instance of . + /// If the value could not be parsed, provides a validation error message. + /// True if the value could be parsed; otherwise false. + protected abstract bool TryParseValueFromString(string? value, [MaybeNullWhen(false)] out TValue result, [NotNullWhen(false)] out string? validationErrorMessage); + + /// + /// Gets a CSS class string that combines the class attribute and and a string indicating + /// the status of the field being edited (a combination of "modified", "valid", and "invalid"). + /// Derived components should typically use this value for the primary HTML element's 'class' attribute. + /// protected string CssClass { get { - if (AdditionalAttributes != null && - AdditionalAttributes.TryGetValue("class", out var @class) && - !string.IsNullOrEmpty(Convert.ToString(@class, CultureInfo.InvariantCulture))) - { - return $"{@class} {FieldClass}"; - } - - return FieldClass; // Never null or empty + var fieldClass = EditContext?.FieldCssClass(FieldIdentifier) ?? string.Empty; + return CombineClassNames(AdditionalAttributes, fieldClass); } } @@ -139,16 +173,10 @@ public override Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); - if(EditContext != null || CascadedEditContext != null) + if (EditContext != null || CascadedEditContext != null) { // This is the first run // Could put this logic in OnInit, but its nice to avoid forcing people who override OnInit to call base.OnInit() - if (CascadedEditContext == null) - { - throw new InvalidOperationException($"{GetType()} requires a cascading parameter " + - $"of type {nameof(AspNetCore.Components.Forms.EditContext)}. For example, you can use {GetType().FullName} inside " + - $"an {nameof(EditForm)}."); - } if (ValueExpression == null) { @@ -156,30 +184,34 @@ public override Task SetParametersAsync(ParameterView parameters) $"parameter. Normally this is provided automatically when using 'bind-Value'."); } - EditContext = CascadedEditContext; FieldIdentifier = FieldIdentifier.Create(ValueExpression); - _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue)); - EditContext.OnValidationStateChanged += _validationStateChangedHandler; - if (CascadedEditContext != EditContext) + if (CascadedEditContext != null) { - // Not the first run - - // We don't support changing EditContext because it's messy to be clearing up state and event - // handlers for the previous one, and there's no strong use case. If a strong use case - // emerges, we can consider changing this. - throw new InvalidOperationException($"{GetType()} does not support changing the " + - $"{nameof(AspNetCore.Components.Forms.EditContext)} dynamically."); + EditContext = CascadedEditContext; + EditContext.OnValidationStateChanged += _validationStateChangedHandler; } - UpdateAdditionalValidationAttributes(); + _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue)); + } + else if (CascadedEditContext != EditContext) + { + // Not the first run + + // We don't support changing EditContext because it's messy to be clearing up state and event + // handlers for the previous one, and there's no strong use case. If a strong use case + // emerges, we can consider changing this. + throw new InvalidOperationException($"{GetType()} does not support changing the " + + $"{nameof(AspNetCore.Components.Forms.EditContext)} dynamically."); } + UpdateAdditionalValidationAttributes(); + // For derived components, retain the usual lifecycle with OnInit/OnParametersSet/etc. return base.SetParametersAsync(ParameterView.Empty); } - private void OnValidateStateChanged(object sender, ValidationStateChangedEventArgs eventArgs) + private void OnValidateStateChanged(object? sender, ValidationStateChangedEventArgs eventArgs) { UpdateAdditionalValidationAttributes(); @@ -188,7 +220,7 @@ private void OnValidateStateChanged(object sender, ValidationStateChangedEventAr private void UpdateAdditionalValidationAttributes() { - if (EditContext == null) + if (EditContext is null) { return; } @@ -232,7 +264,11 @@ private void UpdateAdditionalValidationAttributes() } } - private bool ConvertToDictionary(IReadOnlyDictionary source, out Dictionary result) + /// + /// Returns a dictionary with the same values as the specified . + /// + /// true, if a new dictrionary with copied values was created. false - otherwise. + private bool ConvertToDictionary(IReadOnlyDictionary? source, out Dictionary result) { var newDictionaryCreated = true; if (source == null) @@ -262,11 +298,34 @@ protected virtual void Dispose(bool disposing) void IDisposable.Dispose() { - if (EditContext != null) + // When initialization in the SetParametersAsync method fails, the EditContext property can remain equal to null + if (EditContext is not null) { EditContext.OnValidationStateChanged -= _validationStateChangedHandler; } Dispose(disposing: true); } + + public static string CombineClassNames(IReadOnlyDictionary? additionalAttributes, string classNames) + { + if (additionalAttributes is null || !additionalAttributes.TryGetValue("class", out var @class)) + { + return classNames; + } + + var classAttributeValue = Convert.ToString(@class, CultureInfo.InvariantCulture); + + if (string.IsNullOrEmpty(classAttributeValue)) + { + return classNames; + } + + if (string.IsNullOrEmpty(classNames)) + { + return classAttributeValue; + } + + return $"{classAttributeValue} {classNames}"; + } } } diff --git a/src/Microsoft.Fast.Components.FluentUI/GenerateHeaderOptions.cs b/src/Microsoft.Fast.Components.FluentUI/GenerateHeaderOptions.cs index ade40d4636..441ce7fd07 100644 --- a/src/Microsoft.Fast.Components.FluentUI/GenerateHeaderOptions.cs +++ b/src/Microsoft.Fast.Components.FluentUI/GenerateHeaderOptions.cs @@ -13,9 +13,9 @@ public enum GenerateHeaderOptions internal static class GenerateHeaderExtensions { - private static Dictionary _generateHeaderValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _generateHeaderValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this GenerateHeaderOptions? value) => value == null ? null : _generateHeaderValues[value.Value]; + public static string? ToAttributeValue(this GenerateHeaderOptions? value) => value == null ? null : _generateHeaderValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/HorizontalPosition.cs b/src/Microsoft.Fast.Components.FluentUI/HorizontalPosition.cs index beeb3906da..cf22efe2e5 100644 --- a/src/Microsoft.Fast.Components.FluentUI/HorizontalPosition.cs +++ b/src/Microsoft.Fast.Components.FluentUI/HorizontalPosition.cs @@ -15,9 +15,9 @@ public enum HorizontalPosition internal static class HorizontalDefaultPositionExtensions { - private static Dictionary _positionValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _positionValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this HorizontalPosition? value) => value == null ? null : _positionValues[value.Value]; + public static string? ToAttributeValue(this HorizontalPosition? value) => value == null ? null : _positionValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/LocalizationDirection.cs b/src/Microsoft.Fast.Components.FluentUI/LocalizationDirection.cs index 2436f88e01..238cb6105b 100644 --- a/src/Microsoft.Fast.Components.FluentUI/LocalizationDirection.cs +++ b/src/Microsoft.Fast.Components.FluentUI/LocalizationDirection.cs @@ -13,9 +13,9 @@ public enum LocalizationDirection internal static class LocalizationDirectionExtensions { - private static Dictionary _directionValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _directionValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this LocalizationDirection? value) => value == null ? null : _directionValues[value.Value]; + public static string? ToAttributeValue(this LocalizationDirection? value) => value == null ? null : _directionValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Microsoft.Fast.Components.FluentUI.csproj b/src/Microsoft.Fast.Components.FluentUI/Microsoft.Fast.Components.FluentUI.csproj index efc59d1049..d4d629ab06 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Microsoft.Fast.Components.FluentUI.csproj +++ b/src/Microsoft.Fast.Components.FluentUI/Microsoft.Fast.Components.FluentUI.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 Microsoft.Fast.Components.FluentUI Microsoft © Microsoft Corporation. All rights reserved. @@ -10,13 +10,14 @@ https://github.com/microsoft/fast-blazor MIT Fluent UI Web Components library for Blazor on .NET - Web Components, .NET, FluentUI, FAST, Blazor, .NET 5.0 + Web Components, .NET, FluentUI, FAST, Blazor, .NET 6.0 Microsoft Fluent UI Components Library for Blazor on FAST Authored by the Microsoft FAST team. true - 0.4.0 - 0.4.0 + 0.5.0 + 0.5.0 false + enable @@ -24,7 +25,7 @@ 4 true false - bin\Debug\net5.0\Microsoft.Fast.Components.FluentUI.xml + bin\Debug\net6.0\Microsoft.Fast.Components.FluentUI.xml 1701;1702,8669,1591 @@ -36,7 +37,7 @@ - + diff --git a/src/Microsoft.Fast.Components.FluentUI/Orientation.cs b/src/Microsoft.Fast.Components.FluentUI/Orientation.cs index f47ec1d6bf..7c1cd1bce8 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Orientation.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Orientation.cs @@ -12,9 +12,9 @@ public enum Orientation internal static class OrientationExtensions { - private static Dictionary _orientationValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _orientationValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Orientation? value) => value == null ? null : _orientationValues[value.Value]; + public static string? ToAttributeValue(this Orientation? value) => value == null ? null : _orientationValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Positioning.cs b/src/Microsoft.Fast.Components.FluentUI/Positioning.cs index 52ebbfbf05..fbcda7d7d6 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Positioning.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Positioning.cs @@ -13,9 +13,9 @@ public enum Positioning internal static class PositioningExtensions { - private static Dictionary _positioningValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _positioningValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Positioning? value) => value == null ? null : _positioningValues[value.Value]; + public static string? ToAttributeValue(this Positioning? value) => value == null ? null : _positioningValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Resize.cs b/src/Microsoft.Fast.Components.FluentUI/Resize.cs index 56746bcdbf..445dafcaeb 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Resize.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Resize.cs @@ -13,9 +13,9 @@ public enum Resize internal static class ResizeExtensions { - private static Dictionary _resizeValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _resizeValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Resize? value) => value == null ? null : _resizeValues[value.Value]; + public static string? ToAttributeValue(this Resize? value) => value == null ? null : _resizeValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Scaling.cs b/src/Microsoft.Fast.Components.FluentUI/Scaling.cs index fbbf38beae..3b65d4e5de 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Scaling.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Scaling.cs @@ -13,9 +13,9 @@ public enum Scaling internal static class ScalingExtensions { - private static Dictionary _scalingValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _scalingValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Scaling? value) => value == null ? null : _scalingValues[value.Value]; + public static string? ToAttributeValue(this Scaling? value) => value == null ? null : _scalingValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/Shape.cs b/src/Microsoft.Fast.Components.FluentUI/Shape.cs index 4d8917dfb3..eabbee155b 100644 --- a/src/Microsoft.Fast.Components.FluentUI/Shape.cs +++ b/src/Microsoft.Fast.Components.FluentUI/Shape.cs @@ -12,9 +12,9 @@ public enum Shape internal static class ShapeExtensions { - private static Dictionary _orientationValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _orientationValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this Shape? value) => value == null ? null : _orientationValues[value.Value]; + public static string? ToAttributeValue(this Shape? value) => value == null ? null : _orientationValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/TextFieldType.cs b/src/Microsoft.Fast.Components.FluentUI/TextFieldType.cs index dc73e34593..c024fb7072 100644 --- a/src/Microsoft.Fast.Components.FluentUI/TextFieldType.cs +++ b/src/Microsoft.Fast.Components.FluentUI/TextFieldType.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.Fast.Components.FluentUI { @@ -17,9 +15,9 @@ public enum TextFieldType internal static class TextFieldTypeExtensions { - private static Dictionary _textFieldTypeValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _textFieldTypeValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this TextFieldType? value) => value == null ? null : _textFieldTypeValues[value.Value]; + public static string? ToAttributeValue(this TextFieldType? value) => value == null ? null : _textFieldTypeValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/TooltipPosition.cs b/src/Microsoft.Fast.Components.FluentUI/TooltipPosition.cs index 584df27c68..af63b7b0d4 100644 --- a/src/Microsoft.Fast.Components.FluentUI/TooltipPosition.cs +++ b/src/Microsoft.Fast.Components.FluentUI/TooltipPosition.cs @@ -16,9 +16,9 @@ public enum TooltipPosition internal static class TooltipPositionExtensions { - private static Dictionary _tooltipPositionValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _tooltipPositionValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this TooltipPosition? value) => value == null ? null : _tooltipPositionValues[value.Value]; + public static string? ToAttributeValue(this TooltipPosition? value) => value == null ? null : _tooltipPositionValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/UpdateMode.cs b/src/Microsoft.Fast.Components.FluentUI/UpdateMode.cs index 7c7e40e7b6..07b2427ce7 100644 --- a/src/Microsoft.Fast.Components.FluentUI/UpdateMode.cs +++ b/src/Microsoft.Fast.Components.FluentUI/UpdateMode.cs @@ -12,9 +12,9 @@ public enum UpdateMode internal static class UpdateModeExtensions { - private static Dictionary _updateModeValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _updateModeValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this UpdateMode? value) => value == null ? null : _updateModeValues[value.Value]; + public static string? ToAttributeValue(this UpdateMode? value) => value == null ? null : _updateModeValues[value.Value]; } } diff --git a/src/Microsoft.Fast.Components.FluentUI/VerticalPosition.cs b/src/Microsoft.Fast.Components.FluentUI/VerticalPosition.cs index ab4b7a3d6a..64a8cdd40d 100644 --- a/src/Microsoft.Fast.Components.FluentUI/VerticalPosition.cs +++ b/src/Microsoft.Fast.Components.FluentUI/VerticalPosition.cs @@ -13,9 +13,9 @@ public enum VerticalPosition internal static class VerticalDefaultPositionExtensions { - private static Dictionary _positionValues = - Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id).ToLowerInvariant()); + private static readonly Dictionary _positionValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); - public static string ToAttributeValue(this VerticalPosition? value) => value == null ? null : _positionValues[value.Value]; + public static string? ToAttributeValue(this VerticalPosition? value) => value == null ? null : _positionValues[value.Value]; } }