Socket
Socket
Sign inDemoInstall

@ernane/svelte-star-rating

Package Overview
Dependencies
13
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ernane/svelte-star-rating

Simple component to assign scores based on stars.


Version published
Weekly downloads
207
decreased by-29.11%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

✨ Svelte Star Rating ✨

Project   |    Installation   |    Features   |    Use   

preview star rating

💻 Project

Simple Svelte component, with no dependencies, for implementing and capturing assessments through a simple and intuitive interface that will take you to the stars.

See this demo!!

📦 Installation

$ npm install @ernane/svelte-star-rating # => or yarn

⚠️ if using SvelteKit or Sapper, it is advised to install as a development dependency:

$ npm install @ernane/svelte-star-rating --save-dev # => or yarn

📁 Features

This package will add a svelte component that may or may not receive a configuration object with the following attributes shown below.

  • ⚙️ General Settings
AttributeData TypeRequiredDefault
readOnlyboolfalsefalse
countStarsintegerfalse5
scorefloatfalse0.0
showScoreboolfalsetrue
scoreFormatfunctionfalseprecent
nameStringfalse""

In addition, we have two other nested attributes that specify distinct settings.

  • 📏 Range
AttributeData TypeRequiredDefault
minintegerfalse0
maxintegerfalse5
stepfloatfalse0.001
  • ⭐ Setting of the Stars:
AttributeData TypeRequiredDefault
sizeintegerfalse30
fillColorStringfalse#F9ED4F
strokeColorStringfalse#BB8511
unfilledColorStringfalse#FFF
strokeUnfilledColorStringfalse#000

In the end, the configuration object will be similar to the one shown below.

const config = {
  readOnly: false,
  countStars: 5,
  range: {
    min: 0, 
    max: 5, 
    step: 0.001
  },
  score: 0.0,
  showScore: true,
  scoreFormat: function(){ return `(${this.score.toFixed(0)}/${this.countStars})` },
  name: "",
  starConfig: {
    size: 30,
    fillColor: '#F9ED4F',
    strokeColor: "#BB8511",
    unfilledColor: '#FFF',
    strokeUnfilledColor: '#000'
  }
}
  • 🎯 Events

In addition, it is also possible to observe events of the component itself that will be executed in an internal element from a defined action. Below are the available events.

TypeTargetRequiredDefault
changeinput.sliderfalsenull

💡 Use

  • Import the component

    import StarRating from "@ernane/svelte-star-rating";
    
  • Create the configuration object

    const config = { ... }
    

    **As shown in the previous section

  • Finally, use it! 🎉

    <StarRating {config}/>
    

If you would like to implement or improve any feature feel free to submit a pull request. I would love to receive!


Developed with ❤ by Ernane Ferreira. 👋🏻

Keywords

FAQs

Last updated on 06 Apr 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc