Skip to content

Commit

Permalink
[Rating] Refactorization for Accessibility features (#2322)
Browse files Browse the repository at this point in the history
* Refactorization Rating component

* Fix Unit Tests

* Add Unit Tests

* Add Accessibility (need to update Unit Tests)

* Fix Unit Tests

* Update Unit Tests

* Update OnHoveredValueChanged to OnHoverValueChanged
  • Loading branch information
dvoituron authored Jul 4, 2024
1 parent 211af3f commit 05d9d7d
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 377 deletions.
51 changes: 36 additions & 15 deletions examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7651,9 +7651,25 @@
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRadioGroup`1.TryParseValueFromString(System.String,`0@,System.String@)">
<inheritdoc />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.MaxValue">
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.ClassValue">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.StyleValue">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.Max">
<summary>
Gets or sets the maximum value.
Gets or sets the number of elements.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.IconFilled">
<summary>
The icon to display when the rating value is greater than or equal to the item's value.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.IconOutline">
<summary>
The icon to display when the rating value is less than the item's value.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.IconColor">
Expand All @@ -7674,30 +7690,35 @@
The icon width.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.IconFilled">
<summary>
The icon to display when the rating value is greater than or equal to the item's value.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.IconOutline">
<summary>
The icon to display when the rating value is less than the item's value.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.AllowReset">
<summary>
Gets or sets a value that whether to allow clear when click again.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.OnPointerOver">
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.OnHoverValueChanged">
<summary>
Fires when hovered value changes. Value will be null if no rating item is hovered.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.ClassValue">
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.GroupName">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentRating.StyleValue">
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRating.GetIcon(System.Int32)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRating.TryParseValueFromString(System.String,System.Int32@,System.String@)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRating.OnClickAsync(System.Int32,System.Boolean)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRating.OnMouseEnterAsync(System.Int32)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRating.OnMouseLeaveAsync">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentRating.UpdateHoverValueAsync(System.Nullable{System.Int32})">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSearch.JSRuntime">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<h4>Example</h4>

<FluentStack VerticalAlignment="VerticalAlignment.Center" Style="margin-left: 32px;">
<FluentRating Max="@_maxValue"
@bind-Value="@_value"
IconFilled="@_iconFilled"
IconOutline="@_iconOutline"
ReadOnly="@_readOnly"
IconColor="@_iconColor"
Disabled="@_disabled" ,
AllowReset="@_allowReset" />

<FluentLabel>Value: @_value</FluentLabel>
</FluentStack>

<hr />

<FluentStack HorizontalGap="100">
<div>
<FluentSelect Label="ReadOnly"
@bind-SelectedOption="@_readOnly"
Style="@FixedWidth"
Items="@(new[] { true, false })" />

<FluentSelect Label="AllowReset"
@bind-SelectedOption="@_allowReset"
Style="@FixedWidth"
Items="@(new[] { true, false })" />

<FluentSelect Label="Disabled"
@bind-SelectedOption="@_disabled"
Style="@FixedWidth"
Items="@(new[] { true, false })" />
</div>
<div>
<FluentNumberField TValue="int"
Label="Max Value"
Style="@FixedWidth"
Min="1"
Max="20"
@bind-Value="@_maxValue" />

<FluentSelect Label="Color"
@bind-SelectedOption="@_iconColor"
Style="@FixedWidth"
Items="@(Enum.GetValues<Color>().Where(i => i != Color.Custom))"
OptionValue="@(i => i.ToAttributeValue())" />

<FluentSelect Label="Icons"
TOption="string"
SelectedOptionChanged="@SetIcon"
Style="@FixedWidth"
Items="IconsName" />
</div>
</FluentStack>

@code
{
readonly string FixedWidth = "max-width: 100px; min-width: 100px; margin: 10px;";
readonly List<string> IconsName = ["Heart", "Star", "Alert", "PersonCircle"];
readonly Icon[] IconsFilled = new Icon[]
{
new Icons.Filled.Size20.Heart(),
new Icons.Filled.Size20.Star(),
new Icons.Filled.Size20.Alert(),
new Icons.Filled.Size20.PersonCircle(),
};
readonly Icon[] IconsOutline = new Icon[]
{
new Icons.Regular.Size20.Heart(),
new Icons.Regular.Size20.Star(),
new Icons.Regular.Size20.Alert(),
new Icons.Regular.Size20.PersonCircle(),
};

bool _readOnly = false;
bool _disabled = false;
bool _allowReset = false;
int _maxValue = 10;
int _value = 2;
Color _iconColor = Color.Error;

Icon _iconFilled = new Icons.Filled.Size20.Star();
Icon _iconOutline = new Icons.Regular.Size20.Star();


void SetIcon(string? name)
{
var index = name is null ? 0 : IconsName.IndexOf(name);

_iconFilled = IconsFilled[index];
_iconOutline = IconsOutline[index];
}

protected override void OnParametersSet() => SetIcon(null);
}
28 changes: 27 additions & 1 deletion examples/Demo/Shared/Pages/Rating/Examples/RatingDefault.razor
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@

<FluentRating MaxValue="10" Value="5" Label="Test"/>
<FluentStack VerticalAlignment="VerticalAlignment.Center">
<FluentRating Max="5"
@bind-Value="@SelectedValue"
OnHoverValueChanged="@(i => HoverValue = i)" />
<FluentLabel>@LabelText</FluentLabel>
</FluentStack>

<FluentButton Appearance="Appearance.Lightweight"
OnClick="@((e) => SelectedValue = 0)">
Clear Rating
</FluentButton>

@code
{
int SelectedValue = 0;
int? HoverValue = null;

private string LabelText => (HoverValue ?? SelectedValue) switch
{
1 => "Very bad",
2 => "Bad",
3 => "Sufficient",
4 => "Good",
5 => "Awesome!",
_ => "Rate our product!"
};
}
38 changes: 0 additions & 38 deletions examples/Demo/Shared/Pages/Rating/Examples/RatingEvent.razor

This file was deleted.

69 changes: 0 additions & 69 deletions examples/Demo/Shared/Pages/Rating/Examples/RatingExample.razor

This file was deleted.

10 changes: 2 additions & 8 deletions examples/Demo/Shared/Pages/Rating/RatingPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@

<h2 id="a11y">Accessibility</h2>
<p>
You can use the arrow keys to increase (<kbd>&rarr;</kbd> / <kbd>&uarr;</kbd>) or decrease (<kbd>&larr;</kbd> / <kbd>&darr;</kbd>) the value. Pressing <kbd>Shift + arrow</kbd> sets the value to 0 or the maximum.
You can use the arrow keys to increase (<kbd>&rarr;</kbd> / <kbd>&uarr;</kbd>) or decrease (<kbd>&larr;</kbd> / <kbd>&darr;</kbd>) the value.
</p>

<h2 id="example">Examples</h2>

<DemoSection Title="Default" Component="@typeof(RatingDefault)"></DemoSection>

<DemoSection Title="Example" Component="@typeof(RatingExample)"></DemoSection>

<DemoSection Title="Event" Component="@typeof(RatingEvent)">
<Description>
You can use the <code>OnPointerOver</code> event to capture a changing rating value.
</Description>
</DemoSection>
<DemoSection Title="Customization" Component="@typeof(RatingCustomization)"></DemoSection>

<h2 id="documentation">Documentation</h2>

Expand Down
Loading

0 comments on commit 05d9d7d

Please sign in to comment.