mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 08:02:26 +00:00
7069202190
* fix: prevent browser freeze when approval form number field has no default value Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: disable approval buttons and keep polling after approve/deny action Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: restore approval page link and prevent double resume in flow viewer Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: guard against NaN fallback in Range and reset actionTaken on new approval step Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix approval page url --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
144 lines
3.3 KiB
Svelte
144 lines
3.3 KiB
Svelte
<script lang="ts">
|
|
import { run, createBubbler, stopPropagation } from 'svelte/legacy'
|
|
|
|
const bubble = createBubbler()
|
|
import RangeSlider from 'svelte-range-slider-pips'
|
|
|
|
interface Props {
|
|
min?: number
|
|
max?: number
|
|
initialValue?: number
|
|
value?: any
|
|
disabled?: boolean
|
|
defaultValue?: number | undefined
|
|
format?: (value: number) => string
|
|
hideInput?: boolean
|
|
}
|
|
|
|
let {
|
|
min = 0,
|
|
max = 100,
|
|
initialValue = 0,
|
|
value = $bindable(),
|
|
disabled = false,
|
|
defaultValue = undefined,
|
|
format = (v) => `${v}`,
|
|
hideInput = false
|
|
}: Props = $props()
|
|
|
|
let step: number = 1
|
|
|
|
let slider: HTMLElement | undefined = $state()
|
|
|
|
function calculateAxisStep(min: number, max: number): number {
|
|
const range = max - min
|
|
return range < 100 ? 1 : range / 20
|
|
}
|
|
|
|
run(() => {
|
|
if (value === null || value === undefined || Number.isNaN(value)) {
|
|
const fallback =
|
|
initialValue !== undefined
|
|
? typeof initialValue === 'string'
|
|
? parseInt(initialValue)
|
|
: initialValue
|
|
: (min ?? 0)
|
|
value = Number.isNaN(fallback) ? (min ?? 0) : fallback
|
|
}
|
|
})
|
|
|
|
let axisStep = $derived(calculateAxisStep(min, max))
|
|
|
|
function handleKeyDown(event: KeyboardEvent) {
|
|
if (disabled) return
|
|
|
|
switch (event.key) {
|
|
case 'ArrowLeft':
|
|
if (value > min) {
|
|
value = Math.max(value - step, min)
|
|
}
|
|
break
|
|
case 'ArrowRight':
|
|
if (value < max) {
|
|
value = Math.min(value + step, max)
|
|
}
|
|
break
|
|
}
|
|
event.preventDefault()
|
|
}
|
|
|
|
// Calculate the handle width based on the length of the max value
|
|
let handleWidth = $derived(`${Math.max(max.toString().length ?? 2, 2)}em`)
|
|
</script>
|
|
|
|
<div class="flex flex-row w-full mx-2 items-center gap-8">
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
|
|
<div
|
|
class={'grow'}
|
|
style="--range-handle-focus: {'#7e9abd'}; --range-handle: {'#7e9abd'}; --handle-width: {handleWidth}; --handle-border: 4px;"
|
|
onpointerdown={stopPropagation(bubble('pointerdown'))}
|
|
onkeydown={handleKeyDown}
|
|
>{#if max <= min}
|
|
<div class="text-secondary text-sm"
|
|
>Impossible to display range: {`max (${max}) <= min (${min})`}</div
|
|
>
|
|
{:else}
|
|
<RangeSlider
|
|
id="range-slider-form"
|
|
springValues={{ stiffness: 1, damping: 1 }}
|
|
bind:slider
|
|
min={min == undefined ? 0 : +min}
|
|
max={max == undefined ? 1 : +max}
|
|
on:change={(e) => {
|
|
value = e.detail.value
|
|
}}
|
|
{defaultValue}
|
|
{disabled}
|
|
values={[value]}
|
|
pips
|
|
float
|
|
first="label"
|
|
last="label"
|
|
step={step ?? 1}
|
|
pipstep={(axisStep ?? 1) / (step ?? 1)}
|
|
formatter={format}
|
|
/>
|
|
{/if}
|
|
</div>
|
|
|
|
{#if !hideInput}
|
|
<input bind:value type="number" class="!w-16 h-8 !text-xs mb-6" {max} {min} {disabled} />
|
|
{/if}
|
|
</div>
|
|
|
|
<style>
|
|
:global(#range-slider-form.rangeSlider) {
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
:global(.dark #range-slider-form.rangeSlider) {
|
|
background-color: #3b4252;
|
|
}
|
|
|
|
:global(#range-slider-form.rangeSlider .rangeHandle) {
|
|
width: var(--handle-width, 2em) !important;
|
|
height: 2em;
|
|
display: flex;
|
|
justify-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
:global(#range-slider-form.rangeSlider .rangeFloat) {
|
|
opacity: 1;
|
|
background: transparent;
|
|
top: 50%;
|
|
transform: translate(-50%, -50%);
|
|
}
|
|
|
|
:global(.dark #range-slider-form.rangeSlider > .rangePips > .pip) {
|
|
color: #eeeeee;
|
|
}
|
|
</style>
|