Skip to content

Commit

Permalink
Merge pull request #10 from ErnaneJ/score-format
Browse files Browse the repository at this point in the history
Feature: add possibility to format fill percentage.


Co-authored-by: Yelinz <[email protected]>
  • Loading branch information
ErnaneJ and Yelinz authored Jul 29, 2023
2 parents 842d9c2 + 3e55704 commit bb8ce29
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
14 changes: 8 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ This package will add a svelte component that may or may not receive a configura

- ⚙️ General Settings

| Attribute | Data Type | Required | Default |
|:---------:|:------------:|:---------:|:------------:|
| readOnly | `bool` | false | false |
| countStars| `integer` | false | 5 |
| score | `float` | false | 0.0 |
| showScore | `bool` | false | true |
| Attribute | Data Type | Required | Default |
|:----------:|:------------:|:-----------:|:------------:|
| readOnly | `bool` | false | false |
| countStars | `integer` | false | 5 |
| score | `float` | false | 0.0 |
| showScore | `bool` | false | true |
| scoreFormat| `function` | false | precent |

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

Expand Down Expand Up @@ -78,6 +79,7 @@ const config = {
},
score: 0.0,
showScore: true,
scoreFormat: function(){ return `(${this.score.toFixed(0)}/${this.countStars})` },
starConfig: {
size: 30,
fillColor: '#F9ED4F',
Expand Down
6 changes: 3 additions & 3 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/Stars.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@
{#each Array(config.countStars) as star, id}
{#if parseInt(config.score) == id}
<Star {id} readOnly={config.readOnly} starConfig={config.starConfig} fillPercentage={config.score - parseInt(config.score)}/>
{:else if parseInt(config.score) > id}
<Star {id} readOnly={config.readOnly} starConfig={config.starConfig} fillPercentage={1}/>
{:else}
{#if parseInt(config.score) > id}
<Star {id} readOnly={config.readOnly} starConfig={config.starConfig} fillPercentage={1}/>
{:else}
<Star {id} readOnly={config.readOnly} starConfig={config.starConfig} fillPercentage={0}/>
{/if}
<Star {id} readOnly={config.readOnly} starConfig={config.starConfig} fillPercentage={0}/>
{/if}
{/each}
</div>
<input class="slider" disabled={config.readOnly} type="range" min={config.range.min} max={config.range.max} step="{config.range.step}" bind:value={config.score} on:change >
</div>
{#if config.showScore}<span class="show-score" style="font-size: {config.starConfig.size/2}px;">({parseFloat((config.score/config.countStars)*100).toFixed(2)}%)</span>{/if}
{#if config.showScore}
<span class="show-score" style="font-size: {config.starConfig.size/2}px;">
{#if config.scoreFormat}
{config.scoreFormat()}
{:else}
({parseFloat((config.score/config.countStars)*100).toFixed(2)}%)
{/if}
</span>
{/if}
</section>

<style>
Expand Down

0 comments on commit bb8ce29

Please sign in to comment.