-
Notifications
You must be signed in to change notification settings - Fork 96
#279 Rebuild components/rating/rating-modal.tsx with shadcn Dialog pr… #289
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||
| import React, { useState } from 'react'; | ||||||||||||||||||||||||||||||||
| import React, { useState } from "react"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| interface RatingStarsProps { | ||||||||||||||||||||||||||||||||
| value: number; | ||||||||||||||||||||||||||||||||
|
|
@@ -7,39 +7,51 @@ interface RatingStarsProps { | |||||||||||||||||||||||||||||||
| displayOnly?: boolean; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export const RatingStars: React.FC<RatingStarsProps> = ({ value, onChange, disabled, displayOnly }) => { | ||||||||||||||||||||||||||||||||
| export const RatingStars: React.FC<RatingStarsProps> = ({ | ||||||||||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||||||||||
| onChange, | ||||||||||||||||||||||||||||||||
| disabled, | ||||||||||||||||||||||||||||||||
| displayOnly, | ||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||
| const [hovered, setHovered] = useState<number | null>(null); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { | ||||||||||||||||||||||||||||||||
| if (!onChange || disabled || displayOnly) return; | ||||||||||||||||||||||||||||||||
| if (e.key === 'ArrowLeft' && value > 1) onChange(value - 1); | ||||||||||||||||||||||||||||||||
| if (e.key === 'ArrowRight' && value < 5) onChange(value + 1); | ||||||||||||||||||||||||||||||||
| if (e.key === "ArrowLeft" && value > 1) onChange(value - 1); | ||||||||||||||||||||||||||||||||
| if (e.key === "ArrowRight" && value < 5) onChange(value + 1); | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||
| tabIndex={displayOnly ? -1 : 0} | ||||||||||||||||||||||||||||||||
| role={displayOnly ? 'img' : 'slider'} | ||||||||||||||||||||||||||||||||
| role={displayOnly ? "img" : "slider"} | ||||||||||||||||||||||||||||||||
| aria-valuenow={value} | ||||||||||||||||||||||||||||||||
| aria-valuemin={1} | ||||||||||||||||||||||||||||||||
| aria-valuemax={5} | ||||||||||||||||||||||||||||||||
| onKeyDown={handleKeyDown} | ||||||||||||||||||||||||||||||||
| style={{ display: 'flex', gap: 4, outline: 'none', cursor: displayOnly ? 'default' : 'pointer' }} | ||||||||||||||||||||||||||||||||
| className={ | ||||||||||||||||||||||||||||||||
| displayOnly | ||||||||||||||||||||||||||||||||
| ? "flex items-center gap-1 outline-none" | ||||||||||||||||||||||||||||||||
| : "flex items-center gap-1 cursor-pointer outline-none" | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||
| {[1, 2, 3, 4, 5].map((star) => ( | ||||||||||||||||||||||||||||||||
| <span | ||||||||||||||||||||||||||||||||
| key={star} | ||||||||||||||||||||||||||||||||
| onMouseEnter={() => !displayOnly && setHovered(star)} | ||||||||||||||||||||||||||||||||
| onMouseLeave={() => !displayOnly && setHovered(null)} | ||||||||||||||||||||||||||||||||
| onClick={() => onChange && !disabled && !displayOnly && onChange(star)} | ||||||||||||||||||||||||||||||||
| style={{ | ||||||||||||||||||||||||||||||||
| color: (hovered ?? value) >= star ? '#FFD700' : '#CCC', | ||||||||||||||||||||||||||||||||
| fontSize: 28, | ||||||||||||||||||||||||||||||||
| transition: 'color 0.2s', | ||||||||||||||||||||||||||||||||
| pointerEvents: displayOnly ? 'none' : 'auto', | ||||||||||||||||||||||||||||||||
| userSelect: 'none', | ||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||
| aria-label={star + ' star'} | ||||||||||||||||||||||||||||||||
| onClick={() => | ||||||||||||||||||||||||||||||||
| onChange && !disabled && !displayOnly && onChange(star) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| className={ | ||||||||||||||||||||||||||||||||
| displayOnly | ||||||||||||||||||||||||||||||||
| ? "select-none text-2xl text-muted-foreground" | ||||||||||||||||||||||||||||||||
| : "select-none text-2xl transition-colors duration-200 " + | ||||||||||||||||||||||||||||||||
| ((hovered ?? value) >= star | ||||||||||||||||||||||||||||||||
| ? "text-yellow-400" | ||||||||||||||||||||||||||||||||
| : "text-muted-foreground") | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Preserve filled stars in This branch now renders every read-only star with the muted class, so a stored rating like Suggested fix- className={
- displayOnly
- ? "select-none text-2xl text-muted-foreground"
- : "select-none text-2xl transition-colors duration-200 " +
- ((hovered ?? value) >= star
- ? "text-yellow-400"
- : "text-muted-foreground")
- }
+ className={
+ "select-none text-2xl " +
+ (!displayOnly ? "transition-colors duration-200 " : "") +
+ ((displayOnly ? value : hovered ?? value) >= star
+ ? "text-yellow-400"
+ : "text-muted-foreground")
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| aria-label={star + " star"} | ||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||
| ★ | ||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Honor
disabledin focus and hover handling.disabledstill leaves the slider focusable and still updates the hover preview, so the control looks interactive even though click/keyboard changes are blocked.Suggested fix
Also applies to: 32-35, 41-45
🤖 Prompt for AI Agents