1.1.2 • Published 9 months ago

svelt-rating-selector-display v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

svelt-rating-selector-display

This small, dependency-free Svelte component enables effortless user rating input and display. It offers seamless customization with Unicode characters to suit individual preferences. Moreover, it boasts full reactivity to ensure a smooth and dynamic user experience. Has user accesability, and keyboard input.

Features:

  • Custom Theming
  • Custom Icons Using Unicode Characters
  • Get customer Ratings
  • Present Ratings with Utmost Precision
  • Set the Number Rating Icons
  • All Props are Reactive
  • Keyboard Shortcuts
  • Built in User Accesability
  • Handles Null values

How to istall

npm i svelt-rating-selector-display

How to use

How to get ratings

<script>
	import { RatingSelector } from 'svelte-rating-selector-display';
	let rating = Null; // This will be updated when a user selects a rating
</script>

<RatingSelector bind:rating enableSelection={true} />

How to display ratings

<script>
	import { RatingSelector } from 'svelte-rating-selector-display';
</script>

<RatingSelector rating={3.35} />

Props

PropTypeDescriptionDefault Value
ratingnumber | nullInital displayed rating, if null no rating is displayednull
enableSelectionboolean | nullIf true the user can select a rating, if false a static rating will be displayedfalse
numberOfIconsnumber | nullThe number of icons to display for the rating5
stylekey: string: string | nullA list of styles to be applied to the parent element of the selectornull

If null is passed in for a prop, it will be set as the default value.

How to format

CSS variables

Colors:Default ValueDescription
--icon-selected-color#ffd700 #ffd700Color of rating icons when they are selected
--icon-unselected-hover-color#ccc #cccColor of rating icons when they are not selected
--icon-selected-hover-color#f9dd39 #f9dd39Color of rating icons when they are selcted and hovered over
--icon-unslected-color#f9e053b1 #f9e053b1Color of rating icons when they are unslected and hovered over
--focused-stroke-color#ffffff #ffffffColor of stroke around rating icon when it is focused. This is for keyboard use, and user accessibility
Formating:Default ValueDescription
--icon-size3.5remSize of the rating icons
--icon-spacing0remSpace between rating icons
--selector-iconIcon to be desplayed
--focused-stroke-size3pxSize of stroke around rating icon when it is focused. This is for keyboard use, and user accessibility

example:

:root {
	--icon-selected-color: #211b27;
	--icon-unselected-hover-color: #948f97;
	--selector-icon: '☆';
}

Using style prop

<script>
	import { RatingSelector } from 'svelte-rating-selector-display';
	const style = {
		'--icon-selected-color': '#211B27',
		'--icon-unselected-color': '#948F97',
		'--selector-icon': JSON.stringify('☆'), // Note: --selection-icon must be stringified
	};
</script>

<RatingSelector rating={3.7} {style} />