mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented quick tag editing in library list
This commit is contained in:
1 parent
aad1ec5bc0
commit
c98b621f05
4 files changed
+191
-35
No files matched your search
@@ -1,19 +1,48 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
interface Props {
|
||||
value: number
|
||||
/** When provided, the stars become clickable to set the rating (0–5). */
|
||||
onChange?: (value: number) => void
|
||||
}
|
||||
|
||||
// Compact 5-star rating. Filled stars use the gold accent; empties are faint.
|
||||
export function RatingStars({ value }: Props) {
|
||||
if (!value) return <span className="text-faint">—</span>
|
||||
// Compact 5-star rating. Read-only by default (shows a dash when unrated). When
|
||||
// `onChange` is given it's interactive: always shows five stars — hollow (☆) up
|
||||
// to the rating, solid gold (★) below it — with hover preview. Clicking a star
|
||||
// sets that rating; clicking the current top star again clears it to 0.
|
||||
export function RatingStars({ value, onChange }: Props) {
|
||||
const [hover, setHover] = useState(0)
|
||||
|
||||
if (!onChange) {
|
||||
if (!value) return <span className="text-faint">—</span>
|
||||
return (
|
||||
<span className="whitespace-nowrap tracking-tight" title={`${value} / 5`}>
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<span key={i} className={i <= value ? 'text-gold' : 'text-ink-600'}>
|
||||
{i <= value ? '★' : '☆'}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const shown = hover || value
|
||||
return (
|
||||
<span className="whitespace-nowrap tracking-tight" title={`${value} / 5`}>
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<span
|
||||
<button
|
||||
key={i}
|
||||
className={i <= value ? 'text-gold' : 'text-ink-600'}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onChange(i === value ? 0 : i)
|
||||
}}
|
||||
onMouseEnter={() => setHover(i)}
|
||||
onMouseLeave={() => setHover(0)}
|
||||
className={`transition-colors ${i <= shown ? 'text-gold' : 'text-ink-600 hover:text-gold/60'}`}
|
||||
title={i === value ? 'Clear rating' : `Set ${i} star${i > 1 ? 's' : ''}`}
|
||||
>
|
||||
★
|
||||
</span>
|
||||
{i <= shown ? '★' : '☆'}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user