Repository navigation
NXT-20677: Added Star Ratings component - #449
alexandrumorariu wants to merge 11 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #449 +/- ##
===========================================
+ Coverage 83.46% 83.70% +0.23%
===========================================
Files 157 159 +2
Lines 7864 8003 +139
Branches 2432 2491 +59
===========================================
+ Hits 6564 6699 +135
- Misses 1010 1014 +4
Partials 290 290 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
pointer mode does not behave as expected |
| onTouchStart={onTouchStart} | ||
| > | ||
| {Array.from({length: max}, (_, i) => { | ||
| const starValue = Math.min(Math.max(shownValue - i, 0), 1); |
There was a problem hiding this comment.
Each star rounds only its own share of the value (shownValue - i).
Subtracting decimals in floating point often gives a number just below the halfway point, so it rounds down when it should round up. For example, for 2.55, star 3 gets 2.55 - 2 = 0.5499999999999998, Math.round(5.4999…) gives 5, and the star fills only 50%.
The spec says to round half up to one decimal place
Suggested fix: round the whole value once, then work in whole tenths so no further decimal subtraction happens:
computed: {
// rating in whole tenths (0–50), rounded half-up per spec: 2.54 → 25, 2.55 → 26
tenths: ({active, displayValue, max, value}) => {
const shown = (active ? value : displayValue) || 0;
return Math.min(Math.max(Math.round(shown * 10), 0), max * 10);
}
},
render: ({tenths, ...rest}) => (
// ...
{Array.from({length: max}, (_, i) => {
const starValue = Math.min(Math.max(tenths - i * 10, 0), 10) / 10;
// ...
})}
)
There was a problem hiding this comment.
please also add a unit test for the spec examples (2.54 → 2.5 filled, 2.55 → 2.6 filled), to stop this from coming back.
| computed: { | ||
| className: ({highlighted, styler}) => styler.append({highlighted}), | ||
| style: ({style, value}) => { | ||
| const percent = Math.round(value * 10) * 10; |
There was a problem hiding this comment.
same comment as on starRatings:163
| import css from './Star.module.less'; | ||
|
|
||
| const SpottableIcon = Spottable(Icon); | ||
|
|
There was a problem hiding this comment.
let's add TODOs for JSDocs, so we don't forget them
| } | ||
| }; | ||
|
|
||
| const StarRatingsBase = kind({ |
There was a problem hiding this comment.
let's add TODOs for JSDocs, so we don't forget them
| </>); | ||
| }; | ||
|
|
||
| boolean('active', _StarRatings, StarRatingsConfig); |
There was a problem hiding this comment.
The StarRatings story only has controls for active and displayValue, and displayValue is limited to 0–5. There’s no control for value, defaultValue or max.
Becuase of this, there are problems which the storybook does not show directly:
No defaultValue gives 0 stars. You can see this one in the sampler: switch active on, and all five stars are empty.
The story passes no value or defaultValue.
Changeable then passes value as undefined.
shownValue turns that into 0 (StarRatings.js:147).
The spec’s lowest selectable value is 1, with 3 recommended as the default. Either the component should default to 3, or the docs and story should tell apps to pass defaultValue={3}.
| component: 'Star' | ||
| }; | ||
|
|
||
| export const _Star = (args) => { |
There was a problem hiding this comment.
I'm not sure we would need a story for this component. TBD in part 2
daniel-stoian-lgp
left a comment
There was a problem hiding this comment.
check my comments
|
Suggestion: use one Right now the mode decides which prop is read: active={false} shows displayValue, and active={true} shows value. This causes a few problems: Apps need two props for one number. A screen showing an app’s rating and a popup letting the user rate it are both showing “the rating”, but one uses displayValue and the other value. Switching modes means renaming the prop. If the wrong one is passed, the stars are silently empty, with no warning. The unused prop is still accepted. and both show 0 stars with no hint why.
Proposal:
|
Co-authored-by: Daniel Stoian <63335068+daniel-stoian-lgp@users.noreply.github.com>

Checklist
Issue Resolved / Feature Added
I added a StarRatings component to limestone.
Resolution
Additional Considerations
Links
NXT-20677
Comments