Skip to content

Commit

Permalink
fix: support for floating numbers and large numbers on the slider
Browse files Browse the repository at this point in the history
* feat: add support for floating number
* feat: add dynamic size on slider
  • Loading branch information
FabienArcellier committed Sep 17, 2024
1 parent d4d7bbd commit a1960c0
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/ui/src/components/core/base/BaseInputRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:aria-valuemin="min"
:aria-valuemax="max"
:aria-valuenow="value"
:aria-valuetext="`${value} (${Math.round(progress)}%)`"
:aria-valuetext="`${displayValue} (${Math.round(progress)}%)`"
class="BaseInputRange"
:class="{
'BaseInputRange--popover-always-visible':
Expand All @@ -18,7 +18,7 @@
:style="{ left: popoverLeft }"
>
<span class="BaseInputRange__popover__content">
{{ value }}
{{ displayValue }}
</span>
</div>
</transition>
Expand Down Expand Up @@ -64,6 +64,10 @@ const thumbRadius = 9;
const thumb = ref<HTMLElement>();
const slider = ref<HTMLElement>();
const displayValue = computed(() => {
const precision = Math.ceil(-Math.log10(props.step));
return model.value.toFixed(precision);
});
const progress = computed(() => {
if (typeof model.value !== "number") return 50;
Expand Down Expand Up @@ -93,15 +97,8 @@ function displayPopover() {
}
// clamp(0px, calc(62% - 9px), calc(100% - 18px))
const thumbLeft = computed(
() => `clamp(
0px,
calc(${progress.value}% - ${thumbRadius}px),
calc(100% - ${thumbRadius * 2}px)
)`,
);
const popoverLeft = computed(() => `calc(${thumbLeft.value} - 3px)`);
const thumbLeft = computed(() => `${progress.value}%`);
const popoverLeft = computed(() => `${progress.value}%`);
function updateValue(value: number) {
displayPopover();
Expand Down Expand Up @@ -132,9 +129,7 @@ function handleMouseDown(initialEvent: MouseEvent) {
if (progress > 1 || progress < 0) return;
const value = Math.round(
(props.max - props.min) * progress + props.min,
);
const value = (props.max - props.min) * progress + props.min;
updateValue(value);
}
Expand Down Expand Up @@ -190,6 +185,7 @@ function handleMouseDown(initialEvent: MouseEvent) {
top: 0;
transition: box-shadow ease-in-out 0.5s;
transform: translateX(-50%);
}
.BaseInputRange__thumb:active {
Expand All @@ -212,14 +208,14 @@ function handleMouseDown(initialEvent: MouseEvent) {
background: var(--popover-bg-color);
height: 18px;
width: 24px;
max-width: 24px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
padding: 0 4px;
transform: translateX(-50%);
}
.BaseInputRange__popover::after {
Expand Down

0 comments on commit a1960c0

Please sign in to comment.