You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
726 B

1 year ago
  1. <script lang="ts">
  2. import BFormOption from "./BFormOption.svelte";
  3. import BFormParameter from "./BFormParameter.svelte";
  4. export let value: number | null;
  5. function update(percentage: number) {
  6. if (value !== null) {
  7. value = percentage / 100;
  8. }
  9. }
  10. function toggle() {
  11. if (value === null) {
  12. value = 0.50;
  13. } else {
  14. value = null;
  15. }
  16. }
  17. let percentage: number
  18. $: percentage = Math.round(Math.max(Math.min((value || 0) * 100, 100), 0));
  19. $: update(percentage);
  20. </script>
  21. <BFormOption on:click={toggle} icon="cirlce_notch" state={(value !== null) || null}>
  22. <BFormParameter type="number" label="%" bind:value={percentage} min={0} max={100} step={1} narrower />
  23. </BFormOption>