![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
svelte-star-rating
Advanced tools
A simple svelte component that shows a rating from 0 to 5 with svg stars when passed a number.
A simple svelte component that shows a rating from 0 to 5 with svg stars. Just need to pass a number. No dependencies required.
As with any other node package in svelte:
npm install svelte-star-rating
But remember to install it as a dev dependency when using it with SvelteKit (or Sapper):
npm install svelte-star-rating --save-dev
The package exports a svelte component.
The component takes a number of props:
Prop | Type | Default | Required | Description |
---|---|---|---|---|
rating | Number | - | Yes | The rating. Any number from 0 to 5.0 |
config | Object | {} | No | Config options for the component. See below |
style | String | - | No | CSS styles passed directly to the container component |
About the config object:
Option | Type | Default | Description |
---|---|---|---|
emptyColor | String | '#7f7f7f' | The color for the empty parts of the stars |
fullColor | String | '#ffcf00' | The color for the filling of the stars |
showText | Boolean | false | Show the rating number next to the stars or not |
size | Number | 20 | The size of the stars. Pass a number of pixels. |
About the style prop: It accepts a string of css styles, written as inline-css. It is passed directly, unchecked, to the main div
as inline-css. Use it cautiously.
showText: true
), font size is half the star size or 16px, whatever is higher.Also:
3.02 + 0.01 = 3.0299999995
, for example, due to the way JavaScript works. It's up to you to manage this before passing the number.Use it as follows:
<script>
import StarRating from 'svelte-star-rating';
</script>
<StarRating rating={3.35} />
Output:
<script>
import StarRating from 'svelte-star-rating';
const rating = 3.35;
const config = {
emptyColor: 'hsl(240, 80%, 85%)',
fullColor: '#f05',
showText: true,
size: 42,
};
const style = 'border: 1px solid firebrick;padding: 12px;';
</script>
<StarRating {rating} {config} {style} />
Output:
[2.0.1] - 2022-09-29
sveltejs/kit
version to 1.0.0-next.405
until the API is more stable.rating
had more than one decimal 0
, ie 3.00002
or 4.001
.FAQs
A simple svelte component that shows a rating from 0 to 5 with svg stars when passed a number.
The npm package svelte-star-rating receives a total of 614 weekly downloads. As such, svelte-star-rating popularity was classified as not popular.
We found that svelte-star-rating demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.