2026-01-21 21:50:30 +03:00
|
|
|
<!--
|
|
|
|
|
Component: ComboControl
|
|
|
|
|
Provides the same functionality as the original ComboControl but lacks increase/decrease buttons.
|
|
|
|
|
-->
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import type { TypographyControl } from '$shared/lib';
|
|
|
|
|
import { Input } from '$shared/shadcn/ui/input';
|
|
|
|
|
import { Slider } from '$shared/shadcn/ui/slider';
|
|
|
|
|
import { cn } from '$shared/shadcn/utils/shadcn-utils';
|
2026-02-07 18:07:28 +03:00
|
|
|
import type { Orientation } from 'bits-ui';
|
2026-01-21 21:50:30 +03:00
|
|
|
import type { ChangeEventHandler } from 'svelte/elements';
|
|
|
|
|
|
|
|
|
|
interface Props {
|
2026-02-07 18:07:28 +03:00
|
|
|
/**
|
|
|
|
|
* Typography control instance
|
|
|
|
|
*/
|
2026-01-21 21:50:30 +03:00
|
|
|
control: TypographyControl;
|
2026-02-07 18:07:28 +03:00
|
|
|
/**
|
|
|
|
|
* Orientation of the component
|
|
|
|
|
*/
|
|
|
|
|
orientation?: Orientation;
|
2026-01-21 21:50:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
control,
|
2026-02-07 18:07:28 +03:00
|
|
|
orientation = 'vertical',
|
2026-01-21 21:50:30 +03:00
|
|
|
}: Props = $props();
|
|
|
|
|
|
|
|
|
|
let sliderValue = $state(Number(control.value));
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
2026-02-07 18:07:28 +03:00
|
|
|
sliderValue = Number(control?.value);
|
2026-01-21 21:50:30 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const handleInputChange: ChangeEventHandler<HTMLInputElement> = event => {
|
|
|
|
|
const parsedValue = parseFloat(event.currentTarget.value);
|
|
|
|
|
if (!isNaN(parsedValue)) {
|
|
|
|
|
control.value = parsedValue;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSliderChange = (newValue: number) => {
|
|
|
|
|
control.value = newValue;
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-02-07 18:07:28 +03:00
|
|
|
<div class={cn('flex flex-col items-center gap-4 w-full', orientation === 'vertical' ? 'flex-col' : 'flex-row')}>
|
2026-01-21 21:50:30 +03:00
|
|
|
<Input
|
|
|
|
|
value={control.value}
|
|
|
|
|
onchange={handleInputChange}
|
|
|
|
|
min={control.min}
|
|
|
|
|
max={control.max}
|
|
|
|
|
class="w-14 h-8 text-xs text-center bg-white/40 border-none rounded-lg focus-visible:ring-indigo-500/50"
|
|
|
|
|
/>
|
|
|
|
|
<Slider
|
|
|
|
|
min={control.min}
|
|
|
|
|
max={control.max}
|
|
|
|
|
step={control.step}
|
|
|
|
|
value={sliderValue}
|
|
|
|
|
onValueChange={handleSliderChange}
|
|
|
|
|
type="single"
|
2026-02-07 18:07:28 +03:00
|
|
|
orientation={orientation}
|
|
|
|
|
class={cn(orientation === 'vertical' ? 'h-30' : 'w-full')}
|
2026-01-21 21:50:30 +03:00
|
|
|
/>
|
|
|
|
|
</div>
|