2023-09-28 04:02:42 +02:00
|
|
|
<script lang="ts">
|
2023-09-28 23:50:27 +02:00
|
|
|
import ToSvelte from "../Base/ToSvelte.svelte"
|
|
|
|
import Svg from "../../Svg"
|
|
|
|
import { createEventDispatcher } from "svelte"
|
2023-12-01 15:23:28 +01:00
|
|
|
import Star from "../../assets/svg/Star.svelte"
|
|
|
|
import Star_half from "../../assets/svg/Star_half.svelte"
|
|
|
|
import Star_outline from "../../assets/svg/Star_outline.svelte"
|
2023-09-28 04:02:42 +02:00
|
|
|
|
2023-09-28 23:50:27 +02:00
|
|
|
export let score: number
|
|
|
|
export let cutoff: number
|
|
|
|
export let starSize = "w-h h-4"
|
2023-12-21 17:36:43 +01:00
|
|
|
export let i: number
|
2023-09-28 04:02:42 +02:00
|
|
|
|
2023-12-21 17:36:43 +01:00
|
|
|
let dispatch = createEventDispatcher<{ hover: { score: number }, click: { score: number } }>()
|
2023-09-28 23:50:27 +02:00
|
|
|
let container: HTMLElement
|
2023-09-28 04:02:42 +02:00
|
|
|
|
|
|
|
function getScore(e: MouseEvent): number {
|
2023-09-28 23:50:27 +02:00
|
|
|
const x = e.clientX - e.target.getBoundingClientRect().x
|
|
|
|
const w = container.getClientRects()[0]?.width
|
|
|
|
return x / w < 0.5 ? cutoff - 10 : cutoff
|
2023-09-28 04:02:42 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-09-28 23:50:27 +02:00
|
|
|
<div
|
|
|
|
bind:this={container}
|
|
|
|
on:click={(e) => dispatch("click", { score: getScore(e) })}
|
|
|
|
on:mousemove={(e) => dispatch("hover", { score: getScore(e) })}
|
|
|
|
>
|
2023-09-28 04:02:42 +02:00
|
|
|
{#if score >= cutoff}
|
2023-12-01 15:23:28 +01:00
|
|
|
<Star class={starSize} />
|
2023-09-28 04:02:42 +02:00
|
|
|
{:else if score + 10 >= cutoff}
|
2023-12-01 15:23:28 +01:00
|
|
|
<Star_half class={starSize} />
|
2023-09-28 04:02:42 +02:00
|
|
|
{:else}
|
2023-12-01 15:23:28 +01:00
|
|
|
<Star_outline class={starSize} />
|
2023-09-28 04:02:42 +02:00
|
|
|
{/if}
|
|
|
|
</div>
|