1.6.0 • Published 4 months ago

starscore v1.6.0

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

Starscore

A star-score library for web app.

Features

  • Create star-score component via SVG.
  • Support for custom icons.
  • Not relying on any third-party libraries.
  • Support typescript.

Installation

# pnpm
$ pnpm add starscore

# yarn
$ yarn add starscore

# npm
$ npm i starscore

Usage

  1. Imports style.
import 'starscore/lib/style.css'
  1. Create a star-score instance.
<div id="starscore-container"></div>
import { createStarscore } from 'starscore'

const starscoreInstance = createStarscore({
  container: '#starscore-container'
})

Options

PropTypeDefault ValueDescription
containerstring,HTMLElement''Specify the container of star-score.
initialValuenumber0Set a initialization score.
sizenumber, string20pxIcon size.
gutterstring, number4pxIcon gutter.
colorstring#ee0a24Selected color.
voidColorstring#c8c9ccVoid color.
disabledColorstring#c8c9ccDisabled color.
typestring'star'Specify this to use a built-in icon. You can use star or heart.
iconstring-Specify this to change SVG string of the selected icon.
voidIconstring-Specify this to change SVG string of the void icon.
clearablebooleanfalseWhether to allow clear when click again.
readonlybooleanfalseWhether to be readonly.
disabledbooleanfalseWhether to disable score.
allowHalfbooleanfalseWhether to allow half star.
showDescriptionbooleanfalseWhether to show current score description.
descriptionColorstring#909399Specify this to change the color of current score description.
descriptionFontSizestring, number13pxSpecify this to change the font-size of current score description.
scoreDetailsFunction() => ''Specify this to custom the desctiption content of current score. currentScore: number is the only parameter.
onChangeFunction-Event triggered when the current score changes. (currentScore: number) => void

APIs

Methods of instance

setValue

You can use it to change the score value after After instantiation.

starscoreInstance.setValue(5) // set 5 score

getValue

You can use this to obtain the current score value.

starscoreInstance.getValue()

setOptions

You can use it to change the options after After instantiation.

starscoreInstance.setOptions({
  disabled: true // disable the star-score
}, true)

The second parameter specifies whether to re-render, defaults is false.

destory

Destory the star-score instance.

starscoreInstance.destory()
1.6.0

4 months ago

1.5.3

8 months ago

1.5.2

9 months ago

1.5.1

9 months ago

1.4.1

9 months ago

1.4.0

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.0

9 months ago

1.1.0

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago