- Réglage « Notation » retiré, ainsi que le curseur sur 10 et l'affichage « /10 » (fiche, cartes, Top 5, stats, filtres, carte de partage) : tout s'affiche sur 5 étoiles - Les notes restent stockées comme avant (sur 10 en interne) : rien ne change pour les notes existantes - Réglage ratingScale retiré des réglages synchronisés et des sauvegardes ; textes inutiles retirés (18 langues) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
76 lines
2.9 KiB
TypeScript
76 lines
2.9 KiB
TypeScript
import { t } from '../i18n'
|
|
import { Star, X } from 'lucide-react'
|
|
import type { MouseEvent } from 'react'
|
|
import { cx, formatRating } from '../lib/utils'
|
|
|
|
/** Petite note compacte (étoile + valeur) pour les cartes. */
|
|
export function RatingBadge({ value }: { value?: number }) {
|
|
if (value == null || value === 0) return null
|
|
return (
|
|
<span className="inline-flex items-center gap-1 text-xs font-semibold text-ink">
|
|
<Star size={12} className="fill-accent text-accent" />
|
|
{formatRating(value)}
|
|
<span className="font-normal text-ink-3">/5</span>
|
|
</span>
|
|
)
|
|
}
|
|
|
|
interface InputProps {
|
|
/** Valeur interne sur 10 */
|
|
value?: number
|
|
onChange: (value: number | undefined) => void
|
|
size?: 'lg' | 'sm'
|
|
label?: string
|
|
}
|
|
|
|
/**
|
|
* Saisie de note : étoiles avec demi-étoiles (touche la moitié gauche d'une étoile pour ½).
|
|
* La valeur est stockée sur 10.
|
|
*/
|
|
export function RatingInput({ value, onChange, size = 'lg', label }: InputProps) {
|
|
const px = size === 'lg' ? 34 : 24
|
|
|
|
const stars = (value ?? 0) / 2
|
|
const pick = (e: MouseEvent<HTMLButtonElement>, index: number) => {
|
|
const rect = e.currentTarget.getBoundingClientRect()
|
|
// Clavier (Entrée / Espace) : pas de position de clic, on donne l'étoile entière
|
|
// En arabe (RTL), l'étoile se remplit depuis la droite : la demi-étoile est la moitié droite
|
|
const rtl = getComputedStyle(e.currentTarget).direction === 'rtl'
|
|
const fromStart = rtl ? rect.right - e.clientX : e.clientX - rect.left
|
|
const half = e.detail !== 0 && fromStart < rect.width / 2
|
|
const next = (index + (half ? 0.5 : 1)) * 2
|
|
onChange(next === value ? undefined : next) // retoucher la même valeur efface la note
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center gap-1" role="group" aria-label={label ?? t('rating.outOf5')}>
|
|
{Array.from({ length: 5 }, (_, i) => {
|
|
const fill = Math.max(0, Math.min(1, stars - i))
|
|
return (
|
|
<button
|
|
key={i}
|
|
type="button"
|
|
onClick={(e) => pick(e, i)}
|
|
className="relative transition active:scale-90"
|
|
style={{ width: px, height: px }}
|
|
aria-label={t('rating.stars', { count: i + 1 })}
|
|
>
|
|
<Star size={px} strokeWidth={1.5} className="absolute inset-0 text-ink-3" />
|
|
<span className="absolute inset-0 overflow-hidden" style={{ width: `${fill * 100}%` }}>
|
|
<Star size={px} strokeWidth={1.5} className="fill-accent text-accent" />
|
|
</span>
|
|
</button>
|
|
)
|
|
})}
|
|
<span className={cx('ms-2 tabular-nums text-ink-2', size === 'lg' ? 'text-base' : 'text-xs')}>
|
|
{value ? formatRating(value) : ''}
|
|
</span>
|
|
{value != null && size === 'lg' && (
|
|
<button type="button" onClick={() => onChange(undefined)} className="ms-auto p-1 text-ink-3" aria-label={t('rating.clear')}>
|
|
<X size={18} />
|
|
</button>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|