budibase/packages/bbui/src/ProgressCircle/ProgressCircle.svelte

63 lines
1.7 KiB
Svelte
Raw Normal View History

2021-04-15 18:06:22 +02:00
<script>
import "@spectrum-css/progresscircle/dist/index-vars.css"
2021-04-15 18:06:22 +02:00
2021-05-05 10:02:48 +02:00
export let size = "M"
function convertSize(size) {
switch (size) {
case "S":
return "small"
case "L":
return "large"
default:
return
}
}
2021-04-15 18:06:22 +02:00
2021-09-16 17:53:34 +02:00
export let value = null
export let minValue = 0
2021-05-05 09:43:01 +02:00
export let maxValue = 100
let subMask1Style
let subMask2Style
2021-05-05 10:02:48 +02:00
$: calculateSubMasks(value)
function calculateSubMasks(value) {
if (value) {
let percentage = ((value - minValue) / (maxValue - minValue)) * 100
let angle
if (percentage > 0 && percentage <= 50) {
angle = -180 + (percentage / 50) * 180
subMask1Style = `transform: rotate(${angle}deg);`
subMask2Style = "transform: rotate(-180deg);"
} else if (percentage > 50) {
angle = -180 + ((percentage - 50) / 50) * 180
subMask1Style = "transform: rotate(0deg);"
subMask2Style = `transform: rotate(${angle}deg);`
}
}
}
export let overBackground
2021-04-15 18:06:22 +02:00
</script>
<div
2021-05-05 10:02:48 +02:00
on:click
class:spectrum-ProgressCircle--indeterminate={value == null}
2021-05-05 09:43:01 +02:00
class:spectrum-ProgressCircle--overBackground={overBackground}
2021-05-05 10:02:48 +02:00
class="spectrum-ProgressCircle spectrum-ProgressCircle--{convertSize(size)}"
>
<div class="spectrum-ProgressCircle-track" />
<div class="spectrum-ProgressCircle-fills">
<div class="spectrum-ProgressCircle-fillMask1">
<div class="spectrum-ProgressCircle-fillSubMask1" style={subMask1Style}>
<div class="spectrum-ProgressCircle-fill" />
2021-04-15 18:06:22 +02:00
</div>
</div>
<div class="spectrum-ProgressCircle-fillMask2">
<div class="spectrum-ProgressCircle-fillSubMask2" style={subMask2Style}>
<div class="spectrum-ProgressCircle-fill" />
2021-04-15 18:06:22 +02:00
</div>
</div>
</div>
</div>