-
Notifications
You must be signed in to change notification settings - Fork 461
[Rating] New rating component #2258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
7ab2d22
Add rating component
franklupo aaca1ed
Merge branch 'dev' into rating
vnbaaij 9ef2f20
Fix IconVariant
franklupo 1cebab9
Add IconColor
franklupo 8715dd1
Merge branch 'rating' of https://github.com/franklupo/fluentui-blazor…
franklupo 3b81877
Fix page name
franklupo fa89df7
Add support disabled
franklupo d3e007d
Add support label
franklupo 0796e11
Remove area not overable
franklupo 84de233
Imprve icona name
franklupo 1cd1940
Add icon color
franklupo a099a81
Add support arrowup/arrowdown
franklupo 868c559
Improve sample
franklupo ae7f412
Add event HoveredValueChanged
franklupo c3a0607
Add IconCustomColor
franklupo b379fd0
Fix aria-readonly
franklupo 792ba8d
Fix LabelTemplate
franklupo 56cee95
Improve code style
franklupo fd99146
Improve icon name
franklupo 62d8475
Add IconWidth
franklupo 833e18a
Fix label documentation
franklupo 872de54
Fix default value
franklupo 45e19ca
Fix HoveredValueChanged to OnPointerOver
franklupo 3b91b0a
Add AllowReset and rewrite HandleKeyDownAsync
franklupo 5fc5059
Add AllowReset
franklupo 99040df
Rewrite key down event
franklupo 111e0e4
Fix Style and Class
franklupo 88a94e9
Component explanation
franklupo 26a4b0f
Merge branch 'dev' into rating
vnbaaij 6fc81f6
Merge branch 'microsoft:dev' into rating
franklupo 37a800e
Improve code
franklupo dbb9479
Add Unit test
franklupo b7fbd45
Fix IconWidth like React Component
franklupo 79d25d2
Merge branch 'dev' into rating
vnbaaij ce9637f
Merge branch 'dev' into rating
vnbaaij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
examples/Demo/Shared/Pages/Rating/Examples/RatingDefault.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| | ||
| <FluentRating MaxValue="10" Value="5"/> | ||
25 changes: 25 additions & 0 deletions
25
examples/Demo/Shared/Pages/Rating/Examples/RatingExample.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <h4>Example</h4> | ||
franklupo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <FluentStack Orientation="Orientation.Horizontal"> | ||
| <FluentCheckbox Label="Read Only" @bind-Value="@_readOnly" /> | ||
| <FluentNumberField TValue="int" Label="Max Value" @bind-Value="@_maxValue" /> | ||
| <FluentSelect TOption="Color" | ||
| @bind-SelectedOption="@_iconColor" | ||
| Style="min-width: 100px;" | ||
| Items="@(Enum.GetValues<Color>().Where(i => i != Color.Custom))" | ||
| OptionValue="@(i => i.ToAttributeValue())" /> | ||
| </FluentStack> | ||
|
|
||
| <div> | ||
| <FluentRating MaxValue="@_maxValue" @bind-Value="@_value" ReadOnly="@_readOnly" IconColor="@_iconColor" /> | ||
| </div> | ||
|
|
||
| <div>Value: @_value</div> | ||
|
|
||
| @code | ||
| { | ||
| bool _readOnly; | ||
| int _maxValue = 10; | ||
| int _value = 2; | ||
| Color _iconColor = Color.Accent; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| @page "/Rating" | ||
| @using FluentUI.Demo.Shared.Pages.Rating.Examples | ||
|
|
||
| <PageTitle>@App.PageTitle("Rating")</PageTitle> | ||
|
|
||
| <h1>Rating</h1> | ||
|
|
||
| <h2 id="example">Examples</h2> | ||
|
|
||
| <DemoSection Title="Default" Component="@typeof(RatingDefault)"></DemoSection> | ||
|
|
||
| <DemoSection Title="Example" Component="@typeof(RatingExample)"></DemoSection> | ||
|
|
||
|
|
||
| <h2 id="documentation">Documentation</h2> | ||
|
|
||
| <ApiDocumentation Component="typeof(FluentRating)" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| @namespace Microsoft.FluentUI.AspNetCore.Components | ||
| @inherits FluentInputBase<int> | ||
|
|
||
| <FluentStack Id="@Id" | ||
| Orientation="Orientation.Horizontal" | ||
| Class="ClassValue" | ||
| Style="StyleValue" | ||
| role="radiogroup" | ||
| @onkeydown="HandleKeyDownAsync" | ||
| tabindex="@(Disabled ? -1 : 0)" | ||
| aria-readonly="@(ReadOnly.ToString().ToLower())"> | ||
| @for (int i = 1; i <= MaxValue; i++) | ||
| { | ||
| var currentValue = i; | ||
dvoituron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @if (ReadOnly) | ||
| { | ||
| <FluentIcon Value="@GetIcon(currentValue)" Color="IconColor" /> | ||
| } | ||
| else | ||
| { | ||
| <FluentIcon Value="@GetIcon(currentValue)" | ||
| Color="IconColor" | ||
franklupo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| OnClick="@(() => OnClickAsync(currentValue))" | ||
| @onpointerover="@(() => OnPointerOver(currentValue))" | ||
| @onpointerout="@(() => OnPointerOut())" /> | ||
| } | ||
| } | ||
| </FluentStack> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.Components.Web; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Globalization; | ||
|
|
||
| namespace Microsoft.FluentUI.AspNetCore.Components; | ||
|
|
||
| public partial class FluentRating : FluentInputBase<int> | ||
| { | ||
| private int? _mouseOverValue; | ||
|
|
||
| public FluentRating() => Id = Identifier.NewId(); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the maximum value. | ||
| /// </summary> | ||
| [Parameter] public int MaxValue { get; set; } = 10; | ||
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| /// <summary> | ||
| /// Gets or sets the icon drawing and fill color. | ||
| /// Value comes from the <see cref="AspNetCore.Components.Color"/> enumeration. Defaults to Accent. | ||
| /// </summary> | ||
| [Parameter] public Color? IconColor { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Selected or hovered icon. | ||
| /// </summary> | ||
| [Parameter] public Icon FullIcon { get; set; } = new CoreIcons.Filled.Size20.Star(); | ||
|
|
||
| /// <summary> | ||
| /// Non-selected item icon. | ||
| /// </summary> | ||
| [Parameter] public Icon EmptyIcon { get; set; } = new CoreIcons.Regular.Size20.Star(); | ||
|
|
||
| private Icon GetIcon(int index) => index <= (_mouseOverValue ?? Value) ? FullIcon : EmptyIcon; | ||
|
|
||
| protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(false)] out int result, [NotNullWhen(false)] out string? | ||
| validationErrorMessage) | ||
| { | ||
| if (BindConverter.TryConvertTo(value, CultureInfo.InvariantCulture, out result)) | ||
| { | ||
| validationErrorMessage = null; | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| validationErrorMessage = string.Format(CultureInfo.InvariantCulture, | ||
| "The {0} field must be a number.", | ||
| FieldBound ? FieldIdentifier.FieldName : UnknownBoundField); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| protected internal async Task HandleKeyDownAsync(KeyboardEventArgs keyboardEventArgs) | ||
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (Disabled || ReadOnly) { return; } | ||
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var value = Value + keyboardEventArgs.Key switch | ||
| { | ||
| "ArrowRight" when keyboardEventArgs.ShiftKey => MaxValue - Value, | ||
| "ArrowRight" => 1, | ||
| "ArrowLeft" when keyboardEventArgs.ShiftKey => -Value, | ||
| "ArrowLeft" => -1, | ||
| _ => 1, | ||
| }; | ||
|
|
||
| _mouseOverValue = null; | ||
| if (value > MaxValue) | ||
| { | ||
| value = MaxValue; | ||
| } | ||
| else if (value < 0) | ||
| { | ||
| value = 0; | ||
| } | ||
|
|
||
| await SetCurrentValueAsync(value); | ||
| } | ||
|
|
||
| private void OnPointerOut() => _mouseOverValue = null; | ||
| private void OnPointerOver(int value) => _mouseOverValue = value; | ||
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private async Task OnClickAsync(int value) | ||
| { | ||
| if (value == Value) { value = 0; } | ||
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
franklupo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await SetCurrentValueAsync(value); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.