npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dev-ekkx/svelte-star-rating

v1.1.3

Published

Simple star rating component for Svelte

Readme

Svelte Star Rating

Simple, zero-dependency star rating component for Svelte.

  • Tiny and framework-native (Svelte 5)
  • Fully controlled with bind:value
  • Half/partial star fill supported (any step you want)
  • Customizable size and colors
  • Optional readonly mode

Installation

Using your preferred package manager:

  • npm: npm i @dev-ekkx/svelte-star-rating
  • pnpm: pnpm add @dev-ekkx/svelte-star-rating
  • bun: bun add @dev-ekkx/svelte-star-rating

Peer dependency:

  • svelte ^5.0.0

Quick start

  1. Import the component
<script lang="ts">
	import { StarRating } from '@dev-ekkx/svelte-star-rating';

	// Current rating value (number). You can bind and update it.
	let value = 4.4;

	// Component config
	const config = {
		readonly: false,
		maxVal: 5,
		minVal: 0,
		step: 0.1, // allows tenth-star granularity
		numOfStars: 5,
		starConfig: {
			size: 26, // pixels
			filledColor: '#F98416',
			unfilledColor: '#5D5D5D'
		}
	};
</script>

<StarRating bind:value {config} />
  1. Read-only display
<script lang="ts">
	import { StarRating } from '@dev-ekkx/svelte-star-rating';
	let value = 3.7;
	const config = {
		readonly: true,
		minVal: 0,
		maxVal: 5,
		step: 0.1,
		numOfStars: 5,
		starConfig: { size: 20, filledColor: '#ffc107', unfilledColor: '#e0e0e0' }
	};
</script>

<StarRating {config} bind:value />

Note: when readonly is true, the slider is disabled and the current value is preserved.

API

Component: StarRating

  • Props
    • config: ConfigI (required)
    • bind:value: number (optional; default 4.54 inside component). If you bind to a variable, it becomes a controlled component and updates as the user interacts.

Types:

export interface StylesI {
    /** Inline CSS applied to the outer stars container */
    containerStyles?: string;
    /** Inline CSS applied to the stars row wrapper */
    starStyles?: string;
}

export interface StarConfigI {
    size: number;
    filledColor: string;
    unfilledColor: string;
}

export interface ConfigI {
    /** Optional name for the underlying input element; defaults to 'stars' */
    name?: string;
    readonly: boolean;
    numOfStars: number;
    minVal: number;
    maxVal: number;
    step: number;
    starConfig: StarConfigI;
    /** Optional inline styles for container and stars row */
    styles?: StylesI;
}

Behavior notes:

  • The component renders numOfStars SVG stars.
  • value may be fractional. Stars will be fully filled for indices below floor(value), and the next star will be partially filled to match the fraction. Remaining stars are unfilled.
  • The HTML input[type="range"] is visually hidden but handles keyboard/mouse/touch interaction when readonly is false.
  • The slider range is clamped to [minVal, maxVal] with the provided step.

Accessibility:

  • The interactive slider is focusable and operable via keyboard when readonly is false.
  • Consider adding surrounding labels or aria attributes in your app if needed.

Styling and customization

Use starConfig to control visuals per instance:

  • size: pixel size of each star SVG
  • filledColor: color for the filled portion
  • unfilledColor: color for the unfilled portion

Because the component uses inline SVG, colors apply directly and do not require external CSS.

Optional styles object (inline CSS strings):

  • styles.containerStyles: Applied to the outer section wrapper of the component. Useful for margins, borders, padding, background, overall gap, width, alignment, etc.
  • styles.starStyles: Applied to the row that holds the stars. Useful for controlling spacing between stars ( gap), alignment, transforms, etc.

Example:

<script>
  import { StarRating } from '@dev-ekkx/svelte-star-rating';
    
  let value = $state(4.4);
  const config = $state<ConfigI>({
        name: 'stars',
        readonly: false,
        maxVal: 5,
        minVal: 0,
        step: 0.1,
        numOfStars: 5,
        styles: {
            containerStyles: "border: 1px solid red; padding: 8px; border-radius: 8px; width:max-content; gap:0rem; margin-inline: auto",
            starStyles: "gap: 0.1rem"
        },
        starConfig: {
            size: 26,
            filledColor: '#F98416',
            unfilledColor: '#5D5D5D'
        }
    });

</script>

<StarRating bind:value {config} />

Examples

  • Five stars, integer steps only:
<script>
	import { StarRating } from '@dev-ekkx/svelte-star-rating';
	let value = 0;
	const config = {
		readonly: false,
		minVal: 0,
		maxVal: 5,
		step: 1,
		numOfStars: 5,
		starConfig: { size: 32, filledColor: 'gold', unfilledColor: '#ccc' }
	};
</script>

<StarRating bind:value {config} /><p>Your rating: {value}</p>
  • Ten stars, quarter steps:
<script>
	import { StarRating } from '@dev-ekkx/svelte-star-rating';
	let value = 7.5;
	const config = {
		readonly: false,
		minVal: 0,
		maxVal: 10,
		step: 0.25,
		numOfStars: 10,
		starConfig: { size: 18, filledColor: '#4f46e5', unfilledColor: '#e5e7eb' }
	};
</script>

<StarRating bind:value {config} />

Notes

  • This package uses named export:
    import { StarRating } from '@dev-ekkx/svelte-star-rating';
  • Requires Svelte 5 (uses $bindable/$state in the demo and bind:value in the component).
  • Works in SSR environments as it is purely presentational and eventless, but interaction (range input) is client-only.

License

MIT License © 2025 Emmanuel Komla Kpendo (Dev Ekkx). See LICENSE file for details.