1 GitHub star = 1 new component.

Star the repo
Feedbackratingscore

Rating Pill

Compact rating pill badge with star and numerical score.

Live Preview

4.5
3.4
2.1

Usage

Copy and paste this code into your React component:

tsx
import { RatingPill } from 'react-component-kit-ui/feedback';

<RatingPill score={4.8} />

Manual Installation

If you are not using the npm package, create a new file and paste the following code: src/components/RatingPill.tsx + RatingPill.css:

RatingPill.tsx
'use client';

import type { HTMLAttributes } from 'react';
import './RatingPill.css';

/**
 * RatingPill โ€” A compact badge displaying a numeric score or rating stars.
 * Colour adapts to the score: โ‰ฅ4 high, โ‰ฅ3 mid, otherwise low.
 *
 * @param score - Required. Usually 0โ€“5.
 * @param showStar - Optional. Default true.
 */
export interface RatingPillProps extends HTMLAttributes<HTMLDivElement> {
  score: number;
  showStar?: boolean;
}

export function RatingPill({ score, showStar = true, className, ...rest }: RatingPillProps) {
  const status = score >= 4 ? 'high' : score >= 3 ? 'mid' : 'low';
  return (
    <div aria-label={`Rating ${score.toFixed(1)}`} {...rest} className={['rate-pill', `rate-pill--${status}`, className].filter(Boolean).join(' ')}>
      <span className="rate-pill__val">{score.toFixed(1)}</span>
      {showStar && <span className="rate-pill__star" aria-hidden="true">โ˜…</span>}
    </div>
  );
}

export default RatingPill;
RatingPill.css
/* RatingPill โ€” ported from astro-component-kit (feedback/RatingPill.astro) */

.rate-pill { 
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: var(--sp-1, 4px) var(--sp-3, 12px); 
  border-radius: var(--r-full, 100px); 
  font-weight: 800; 
  font-size: 0.75rem; 
  color: #fff; 
  width: fit-content; 
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.rate-pill--high { background: #10b981; }
.rate-pill--mid { background: #f59e0b; }
.rate-pill--low { background: #ef4444; }

.rate-pill__star { font-size: 0.8rem; margin-top: -1px; }
.rate-pill__val { font-family: inherit; }

Quick Info

Category
Feedback
Filename
RatingPill.tsx
Dependencies
None โ€” pure React + CSS
Tags
ratingscore