bits-ui 1.7.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bits/accordion/accordion.svelte.d.ts +56 -53
- package/dist/bits/accordion/accordion.svelte.js +78 -89
- package/dist/bits/accordion/components/accordion-content.svelte +5 -3
- package/dist/bits/accordion/components/accordion-header.svelte +4 -2
- package/dist/bits/accordion/components/accordion-item.svelte +6 -3
- package/dist/bits/accordion/components/accordion-trigger.svelte +4 -2
- package/dist/bits/accordion/components/accordion.svelte +4 -2
- package/dist/bits/alert-dialog/components/alert-dialog-action.svelte +4 -2
- package/dist/bits/alert-dialog/components/alert-dialog-cancel.svelte +4 -2
- package/dist/bits/alert-dialog/components/alert-dialog-content.svelte +8 -3
- package/dist/bits/aspect-ratio/aspect-ratio.svelte.js +2 -2
- package/dist/bits/aspect-ratio/components/aspect-ratio.svelte +4 -2
- package/dist/bits/avatar/avatar.svelte.js +4 -4
- package/dist/bits/avatar/components/avatar-fallback.svelte +4 -2
- package/dist/bits/avatar/components/avatar-image.svelte +4 -2
- package/dist/bits/avatar/components/avatar.svelte +4 -2
- package/dist/bits/button/components/button.svelte +1 -1
- package/dist/bits/calendar/calendar.svelte.d.ts +1 -9
- package/dist/bits/calendar/calendar.svelte.js +47 -38
- package/dist/bits/calendar/components/calendar-cell.svelte +4 -2
- package/dist/bits/calendar/components/calendar-day.svelte +4 -2
- package/dist/bits/calendar/components/calendar-grid-body.svelte +4 -2
- package/dist/bits/calendar/components/calendar-grid-head.svelte +4 -2
- package/dist/bits/calendar/components/calendar-grid-row.svelte +4 -2
- package/dist/bits/calendar/components/calendar-grid.svelte +4 -2
- package/dist/bits/calendar/components/calendar-head-cell.svelte +4 -2
- package/dist/bits/calendar/components/calendar-header.svelte +4 -2
- package/dist/bits/calendar/components/calendar-heading.svelte +4 -2
- package/dist/bits/calendar/components/calendar-next-button.svelte +4 -2
- package/dist/bits/calendar/components/calendar-prev-button.svelte +4 -2
- package/dist/bits/checkbox/checkbox.svelte.js +4 -14
- package/dist/bits/checkbox/components/checkbox-group-label.svelte +4 -2
- package/dist/bits/checkbox/components/checkbox-group.svelte +4 -2
- package/dist/bits/checkbox/components/checkbox.svelte +4 -2
- package/dist/bits/collapsible/collapsible.svelte.js +4 -10
- package/dist/bits/collapsible/components/collapsible-content.svelte +5 -3
- package/dist/bits/collapsible/components/collapsible-trigger.svelte +4 -2
- package/dist/bits/collapsible/components/collapsible.svelte +4 -2
- package/dist/bits/combobox/components/combobox-input.svelte +1 -1
- package/dist/bits/combobox/components/combobox.svelte +1 -1
- package/dist/bits/command/command.svelte.js +13 -45
- package/dist/bits/command/components/_command-label.svelte +6 -7
- package/dist/bits/command/components/_command-label.svelte.d.ts +1 -1
- package/dist/bits/command/components/command-empty.svelte +4 -2
- package/dist/bits/command/components/command-group-heading.svelte +4 -2
- package/dist/bits/command/components/command-group-items.svelte +4 -2
- package/dist/bits/command/components/command-group.svelte +4 -2
- package/dist/bits/command/components/command-input.svelte +4 -2
- package/dist/bits/command/components/command-item.svelte +4 -2
- package/dist/bits/command/components/command-link-item.svelte +4 -2
- package/dist/bits/command/components/command-list.svelte +4 -2
- package/dist/bits/command/components/command-loading.svelte +4 -2
- package/dist/bits/command/components/command-separator.svelte +4 -2
- package/dist/bits/command/components/command-viewport.svelte +4 -2
- package/dist/bits/command/components/command.svelte +4 -2
- package/dist/bits/context-menu/components/context-menu-content-static.svelte +2 -3
- package/dist/bits/context-menu/components/context-menu-content.svelte +2 -3
- package/dist/bits/context-menu/components/context-menu-trigger.svelte +1 -1
- package/dist/bits/date-field/components/date-field-input.svelte +4 -2
- package/dist/bits/date-field/components/date-field-label.svelte +4 -2
- package/dist/bits/date-field/components/date-field-segment.svelte +4 -2
- package/dist/bits/date-field/date-field.svelte.d.ts +4 -4
- package/dist/bits/date-field/date-field.svelte.js +15 -33
- package/dist/bits/date-picker/components/date-picker-calendar.svelte +4 -2
- package/dist/bits/date-range-field/components/date-range-field-input.svelte +4 -2
- package/dist/bits/date-range-field/components/date-range-field-label.svelte +4 -2
- package/dist/bits/date-range-field/components/date-range-field.svelte +4 -2
- package/dist/bits/date-range-field/date-range-field.svelte.js +3 -13
- package/dist/bits/date-range-picker/components/date-range-picker-calendar.svelte +4 -2
- package/dist/bits/dialog/components/dialog-close.svelte +4 -2
- package/dist/bits/dialog/components/dialog-content.svelte +8 -2
- package/dist/bits/dialog/components/dialog-description.svelte +4 -2
- package/dist/bits/dialog/components/dialog-overlay.svelte +8 -3
- package/dist/bits/dialog/components/dialog-title.svelte +4 -2
- package/dist/bits/dialog/components/dialog-trigger.svelte +4 -2
- package/dist/bits/dialog/dialog.svelte.d.ts +1 -1
- package/dist/bits/dialog/dialog.svelte.js +19 -47
- package/dist/bits/dropdown-menu/components/dropdown-menu-content-static.svelte +6 -5
- package/dist/bits/dropdown-menu/components/dropdown-menu-content.svelte +6 -5
- package/dist/bits/index.d.ts +2 -0
- package/dist/bits/index.js +2 -0
- package/dist/bits/label/components/label.svelte +4 -2
- package/dist/bits/label/label.svelte.js +2 -2
- package/dist/bits/link-preview/components/link-preview-content-static.svelte +6 -2
- package/dist/bits/link-preview/components/link-preview-content.svelte +6 -2
- package/dist/bits/link-preview/components/link-preview-trigger.svelte +5 -3
- package/dist/bits/link-preview/link-preview.svelte.js +3 -14
- package/dist/bits/menu/components/menu-checkbox-group.svelte +4 -2
- package/dist/bits/menu/components/menu-checkbox-item.svelte +6 -4
- package/dist/bits/menu/components/menu-content-static.svelte +6 -5
- package/dist/bits/menu/components/menu-content.svelte +6 -5
- package/dist/bits/menu/components/menu-group-heading.svelte +4 -2
- package/dist/bits/menu/components/menu-group.svelte +4 -2
- package/dist/bits/menu/components/menu-item.svelte +4 -2
- package/dist/bits/menu/components/menu-radio-group.svelte +4 -2
- package/dist/bits/menu/components/menu-radio-item.svelte +4 -2
- package/dist/bits/menu/components/menu-separator.svelte +4 -2
- package/dist/bits/menu/components/menu-sub-content-static.svelte +6 -5
- package/dist/bits/menu/components/menu-sub-content.svelte +6 -5
- package/dist/bits/menu/components/menu-sub-trigger.svelte +6 -3
- package/dist/bits/menu/components/menu-trigger.svelte +5 -3
- package/dist/bits/menu/menu.svelte.d.ts +7 -20
- package/dist/bits/menu/menu.svelte.js +26 -54
- package/dist/bits/menubar/components/menubar-content-static.svelte +4 -2
- package/dist/bits/menubar/components/menubar-content.svelte +4 -2
- package/dist/bits/menubar/components/menubar-menu.svelte +4 -2
- package/dist/bits/menubar/components/menubar-trigger.svelte +14 -6
- package/dist/bits/menubar/components/menubar.svelte +4 -2
- package/dist/bits/menubar/menubar.svelte.d.ts +24 -20
- package/dist/bits/menubar/menubar.svelte.js +40 -56
- package/dist/bits/meter/components/meter.svelte +4 -2
- package/dist/bits/meter/meter.svelte.js +2 -2
- package/dist/bits/navigation-menu/components/navigation-menu-content-impl.svelte +5 -2
- package/dist/bits/navigation-menu/components/navigation-menu-content.svelte +8 -3
- package/dist/bits/navigation-menu/components/navigation-menu-indicator-impl.svelte +4 -2
- package/dist/bits/navigation-menu/components/navigation-menu-indicator.svelte +6 -4
- package/dist/bits/navigation-menu/components/navigation-menu-item.svelte +8 -3
- package/dist/bits/navigation-menu/components/navigation-menu-link.svelte +4 -2
- package/dist/bits/navigation-menu/components/navigation-menu-list.svelte +4 -2
- package/dist/bits/navigation-menu/components/navigation-menu-sub.svelte +4 -2
- package/dist/bits/navigation-menu/components/navigation-menu-trigger.svelte +4 -2
- package/dist/bits/navigation-menu/components/navigation-menu-viewport.svelte +7 -3
- package/dist/bits/navigation-menu/components/navigation-menu.svelte +4 -2
- package/dist/bits/navigation-menu/navigation-menu.svelte.d.ts +29 -17
- package/dist/bits/navigation-menu/navigation-menu.svelte.js +107 -74
- package/dist/bits/navigation-menu/types.d.ts +14 -7
- package/dist/bits/pagination/components/pagination-next-button.svelte +4 -2
- package/dist/bits/pagination/components/pagination-page.svelte +4 -2
- package/dist/bits/pagination/components/pagination-prev-button.svelte +4 -2
- package/dist/bits/pagination/components/pagination.svelte +4 -2
- package/dist/bits/pagination/pagination.svelte.js +4 -4
- package/dist/bits/pin-input/components/pin-input-cell.svelte +4 -2
- package/dist/bits/pin-input/components/pin-input.svelte +5 -3
- package/dist/bits/pin-input/pin-input.svelte.js +4 -10
- package/dist/bits/popover/components/popover-close.svelte +4 -2
- package/dist/bits/popover/components/popover-content-static.svelte +6 -2
- package/dist/bits/popover/components/popover-content.svelte +6 -2
- package/dist/bits/popover/components/popover-trigger.svelte +5 -3
- package/dist/bits/popover/popover.svelte.js +4 -18
- package/dist/bits/progress/components/progress.svelte +4 -2
- package/dist/bits/progress/progress.svelte.js +2 -2
- package/dist/bits/radio-group/components/radio-group-item.svelte +4 -2
- package/dist/bits/radio-group/components/radio-group.svelte +4 -2
- package/dist/bits/radio-group/radio-group.svelte.js +4 -7
- package/dist/bits/range-calendar/components/range-calendar-cell.svelte +4 -2
- package/dist/bits/range-calendar/components/range-calendar-day.svelte +4 -2
- package/dist/bits/range-calendar/components/range-calendar.svelte +4 -2
- package/dist/bits/range-calendar/range-calendar.svelte.js +4 -4
- package/dist/bits/scroll-area/components/scroll-area-corner.svelte +8 -2
- package/dist/bits/scroll-area/components/scroll-area-scrollbar-auto.svelte +4 -1
- package/dist/bits/scroll-area/components/scroll-area-scrollbar-hover.svelte +1 -1
- package/dist/bits/scroll-area/components/scroll-area-scrollbar-scroll.svelte +5 -1
- package/dist/bits/scroll-area/components/scroll-area-scrollbar.svelte +4 -2
- package/dist/bits/scroll-area/components/scroll-area-thumb.svelte +8 -3
- package/dist/bits/scroll-area/components/scroll-area-viewport.svelte +4 -2
- package/dist/bits/scroll-area/components/scroll-area.svelte +4 -2
- package/dist/bits/scroll-area/scroll-area.svelte.js +13 -47
- package/dist/bits/select/components/select-content-static.svelte +6 -2
- package/dist/bits/select/components/select-content.svelte +6 -2
- package/dist/bits/select/components/select-group-heading.svelte +3 -2
- package/dist/bits/select/components/select-group.svelte +4 -2
- package/dist/bits/select/components/select-item.svelte +4 -2
- package/dist/bits/select/components/select-scroll-down-button.svelte +4 -2
- package/dist/bits/select/components/select-scroll-up-button.svelte +4 -2
- package/dist/bits/select/components/select-trigger.svelte +5 -3
- package/dist/bits/select/components/select-viewport.svelte +4 -2
- package/dist/bits/select/components/select.svelte +1 -1
- package/dist/bits/select/select.svelte.d.ts +0 -18
- package/dist/bits/select/select.svelte.js +10 -43
- package/dist/bits/separator/components/separator.svelte +4 -2
- package/dist/bits/separator/separator.svelte.js +2 -2
- package/dist/bits/slider/components/slider-range.svelte +4 -2
- package/dist/bits/slider/components/slider-thumb-label.svelte +50 -0
- package/dist/bits/slider/components/slider-thumb-label.svelte.d.ts +4 -0
- package/dist/bits/slider/components/slider-thumb.svelte +4 -2
- package/dist/bits/slider/components/slider-tick-label.svelte +50 -0
- package/dist/bits/slider/components/slider-tick-label.svelte.d.ts +4 -0
- package/dist/bits/slider/components/slider-tick.svelte +4 -2
- package/dist/bits/slider/components/slider.svelte +26 -5
- package/dist/bits/slider/exports.d.ts +3 -1
- package/dist/bits/slider/exports.js +2 -0
- package/dist/bits/slider/helpers.d.ts +14 -0
- package/dist/bits/slider/helpers.js +122 -0
- package/dist/bits/slider/slider.svelte.d.ts +93 -6
- package/dist/bits/slider/slider.svelte.js +198 -101
- package/dist/bits/slider/types.d.ts +111 -11
- package/dist/bits/switch/components/switch-thumb.svelte +4 -2
- package/dist/bits/switch/components/switch.svelte +4 -2
- package/dist/bits/switch/switch.svelte.js +3 -3
- package/dist/bits/tabs/components/tabs-content.svelte +4 -2
- package/dist/bits/tabs/components/tabs-list.svelte +4 -2
- package/dist/bits/tabs/components/tabs-trigger.svelte +4 -2
- package/dist/bits/tabs/components/tabs.svelte +4 -2
- package/dist/bits/tabs/tabs.svelte.js +6 -6
- package/dist/bits/time-field/components/time-field-hidden-input.svelte +10 -0
- package/dist/bits/{date-field/components/date-field-error.svelte.d.ts → time-field/components/time-field-hidden-input.svelte.d.ts} +6 -14
- package/dist/bits/time-field/components/time-field-input.svelte +39 -0
- package/dist/bits/time-field/components/time-field-input.svelte.d.ts +4 -0
- package/dist/bits/time-field/components/time-field-label.svelte +34 -0
- package/dist/bits/time-field/components/time-field-label.svelte.d.ts +4 -0
- package/dist/bits/time-field/components/time-field-segment.svelte +37 -0
- package/dist/bits/time-field/components/time-field-segment.svelte.d.ts +4 -0
- package/dist/bits/time-field/components/time-field.svelte +94 -0
- package/dist/bits/time-field/components/time-field.svelte.d.ts +20 -0
- package/dist/bits/time-field/exports.d.ts +5 -0
- package/dist/bits/time-field/exports.js +4 -0
- package/dist/bits/time-field/index.d.ts +1 -0
- package/dist/bits/time-field/index.js +1 -0
- package/dist/bits/time-field/time-field.svelte.d.ts +415 -0
- package/dist/bits/time-field/time-field.svelte.js +971 -0
- package/dist/bits/time-field/types.d.ts +137 -0
- package/dist/bits/time-field/types.js +1 -0
- package/dist/bits/time-range-field/components/time-range-field-input.svelte +43 -0
- package/dist/bits/time-range-field/components/time-range-field-input.svelte.d.ts +4 -0
- package/dist/bits/time-range-field/components/time-range-field-label.svelte +34 -0
- package/dist/bits/time-range-field/components/time-range-field-label.svelte.d.ts +4 -0
- package/dist/bits/time-range-field/components/time-range-field.svelte +144 -0
- package/dist/bits/time-range-field/components/time-range-field.svelte.d.ts +20 -0
- package/dist/bits/time-range-field/exports.d.ts +5 -0
- package/dist/bits/time-range-field/exports.js +4 -0
- package/dist/bits/time-range-field/index.d.ts +1 -0
- package/dist/bits/time-range-field/index.js +1 -0
- package/dist/bits/time-range-field/time-range-field.svelte.d.ts +90 -0
- package/dist/bits/time-range-field/time-range-field.svelte.js +210 -0
- package/dist/bits/time-range-field/types.d.ts +150 -0
- package/dist/bits/time-range-field/types.js +1 -0
- package/dist/bits/toggle/components/toggle.svelte +4 -2
- package/dist/bits/toggle/toggle.svelte.js +2 -2
- package/dist/bits/toggle-group/components/toggle-group-item.svelte +4 -2
- package/dist/bits/toggle-group/components/toggle-group.svelte +4 -2
- package/dist/bits/toggle-group/toggle-group.svelte.js +4 -4
- package/dist/bits/toolbar/components/toolbar-button.svelte +4 -2
- package/dist/bits/toolbar/components/toolbar-group-item.svelte +4 -2
- package/dist/bits/toolbar/components/toolbar-group.svelte +4 -2
- package/dist/bits/toolbar/components/toolbar-link.svelte +4 -2
- package/dist/bits/toolbar/components/toolbar.svelte +4 -2
- package/dist/bits/toolbar/toolbar.svelte.js +7 -7
- package/dist/bits/tooltip/components/tooltip-content-static.svelte +6 -2
- package/dist/bits/tooltip/components/tooltip-content.svelte +6 -2
- package/dist/bits/tooltip/components/tooltip-trigger.svelte +5 -3
- package/dist/bits/tooltip/tooltip.svelte.js +3 -14
- package/dist/bits/utilities/dismissible-layer/dismissible-layer.svelte +2 -0
- package/dist/bits/utilities/dismissible-layer/types.d.ts +2 -0
- package/dist/bits/utilities/dismissible-layer/use-dismissable-layer.svelte.d.ts +3 -3
- package/dist/bits/utilities/dismissible-layer/use-dismissable-layer.svelte.js +16 -25
- package/dist/bits/utilities/floating-layer/components/floating-layer-anchor.svelte +2 -1
- package/dist/bits/utilities/floating-layer/types.d.ts +1 -0
- package/dist/bits/utilities/floating-layer/use-floating-layer.svelte.d.ts +3 -2
- package/dist/bits/utilities/floating-layer/use-floating-layer.svelte.js +5 -26
- package/dist/bits/utilities/focus-scope/focus-scope.svelte +2 -0
- package/dist/bits/utilities/focus-scope/types.d.ts +2 -0
- package/dist/bits/utilities/focus-scope/use-focus-scope.svelte.d.ts +2 -1
- package/dist/bits/utilities/focus-scope/use-focus-scope.svelte.js +2 -8
- package/dist/bits/utilities/popper-layer/popper-layer-inner.svelte +4 -0
- package/dist/bits/utilities/popper-layer/popper-layer.svelte +3 -1
- package/dist/bits/utilities/presence-layer/presence-layer.svelte +2 -2
- package/dist/bits/utilities/presence-layer/types.d.ts +2 -1
- package/dist/bits/utilities/presence-layer/use-presence.svelte.d.ts +1 -1
- package/dist/bits/utilities/presence-layer/use-presence.svelte.js +19 -36
- package/dist/bits/utilities/text-selection-layer/text-selection-layer.svelte +2 -0
- package/dist/bits/utilities/text-selection-layer/types.d.ts +2 -0
- package/dist/bits/utilities/text-selection-layer/use-text-selection-layer.svelte.d.ts +3 -1
- package/dist/bits/utilities/text-selection-layer/use-text-selection-layer.svelte.js +2 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/create-id.d.ts +8 -0
- package/dist/internal/create-id.js +5 -0
- package/dist/internal/date-time/field/helpers.d.ts +1 -0
- package/dist/internal/date-time/field/helpers.js +8 -2
- package/dist/internal/date-time/field/parts.d.ts +3 -1
- package/dist/internal/date-time/field/parts.js +10 -2
- package/dist/internal/date-time/field/segments.d.ts +9 -0
- package/dist/internal/date-time/field/segments.js +65 -0
- package/dist/internal/date-time/field/time-helpers.d.ts +77 -0
- package/dist/internal/date-time/field/time-helpers.js +301 -0
- package/dist/internal/date-time/field/types.d.ts +2 -2
- package/dist/internal/date-time/formatter.d.ts +11 -1
- package/dist/internal/date-time/formatter.js +56 -0
- package/dist/internal/date-time/utils.d.ts +7 -2
- package/dist/internal/date-time/utils.js +15 -1
- package/dist/internal/dom-context.svelte.d.ts +9 -0
- package/dist/internal/dom-context.svelte.js +26 -0
- package/dist/internal/use-roving-focus.svelte.d.ts +3 -3
- package/dist/internal/use-roving-focus.svelte.js +10 -11
- package/dist/shared/date/types.d.ts +27 -4
- package/dist/shared/index.d.ts +9 -2
- package/dist/types.d.ts +2 -0
- package/package.json +18 -16
- package/dist/bits/date-field/components/date-field-error.svelte +0 -0
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
* Abdelrahman (https://github.com/abdel-17)
|
|
4
4
|
*/
|
|
5
5
|
import { untrack } from "svelte";
|
|
6
|
-
import { executeCallbacks, onMountEffect,
|
|
6
|
+
import { executeCallbacks, onMountEffect, attachRef, } from "svelte-toolbelt";
|
|
7
7
|
import { on } from "svelte/events";
|
|
8
8
|
import { Context, watch } from "runed";
|
|
9
|
-
import { getRangeStyles, getThumbStyles, getTickStyles } from "./helpers.js";
|
|
9
|
+
import { getRangeStyles, getThumbStyles, getTickStyles, normalizeSteps, snapValueToCustomSteps, getAdjacentStepValue, getTickLabelStyles, getThumbLabelStyles, } from "./helpers.js";
|
|
10
10
|
import { getAriaDisabled, getAriaOrientation, getDataDisabled, getDataOrientation, } from "../../internal/attrs.js";
|
|
11
11
|
import { kbd } from "../../internal/kbd.js";
|
|
12
12
|
import { isElementOrSVGElement } from "../../internal/is.js";
|
|
13
13
|
import { isValidIndex } from "../../internal/arrays.js";
|
|
14
|
-
import { linearScale
|
|
14
|
+
import { linearScale } from "../../internal/math.js";
|
|
15
15
|
const SLIDER_ROOT_ATTR = "data-slider-root";
|
|
16
16
|
const SLIDER_THUMB_ATTR = "data-slider-thumb";
|
|
17
17
|
const SLIDER_RANGE_ATTR = "data-slider-range";
|
|
18
18
|
const SLIDER_TICK_ATTR = "data-slider-tick";
|
|
19
|
+
const SLIDER_TICK_LABEL_ATTR = "data-slider-tick-label";
|
|
20
|
+
const SLIDER_THUMB_LABEL_ATTR = "data-slider-thumb-label";
|
|
19
21
|
class SliderBaseRootState {
|
|
20
22
|
opts;
|
|
21
23
|
isActive = $state(false);
|
|
@@ -27,9 +29,12 @@ class SliderBaseRootState {
|
|
|
27
29
|
return this.opts.dir.current === "rtl" ? "tb" : "bt";
|
|
28
30
|
}
|
|
29
31
|
});
|
|
32
|
+
// Normalized steps array for consistent handling
|
|
33
|
+
normalizedSteps = $derived.by(() => {
|
|
34
|
+
return normalizeSteps(this.opts.step.current, this.opts.min.current, this.opts.max.current);
|
|
35
|
+
});
|
|
30
36
|
constructor(opts) {
|
|
31
37
|
this.opts = opts;
|
|
32
|
-
useRefById(opts);
|
|
33
38
|
}
|
|
34
39
|
isThumbActive(_index) {
|
|
35
40
|
return this.isActive;
|
|
@@ -46,6 +51,15 @@ class SliderBaseRootState {
|
|
|
46
51
|
return Array.from(node.querySelectorAll(`[${SLIDER_THUMB_ATTR}]`));
|
|
47
52
|
};
|
|
48
53
|
getThumbScale = () => {
|
|
54
|
+
// If trackPadding is explicitly set, use it directly instead of calculating from thumb size
|
|
55
|
+
const trackPadding = this.opts.trackPadding?.current;
|
|
56
|
+
if (trackPadding !== undefined && trackPadding > 0) {
|
|
57
|
+
return [trackPadding, 100 - trackPadding];
|
|
58
|
+
}
|
|
59
|
+
if (this.opts.thumbPositioning.current === "exact") {
|
|
60
|
+
// User opted out of containment
|
|
61
|
+
return [0, 100];
|
|
62
|
+
}
|
|
49
63
|
const isVertical = this.opts.orientation.current === "vertical";
|
|
50
64
|
// this assumes all thumbs are the same width
|
|
51
65
|
const activeThumb = this.getAllThumbs()[0];
|
|
@@ -79,6 +93,7 @@ class SliderBaseRootState {
|
|
|
79
93
|
touchAction: this.#touchAction,
|
|
80
94
|
},
|
|
81
95
|
[SLIDER_ROOT_ATTR]: "",
|
|
96
|
+
...attachRef(this.opts.ref),
|
|
82
97
|
}));
|
|
83
98
|
}
|
|
84
99
|
class SliderSingleRootState extends SliderBaseRootState {
|
|
@@ -96,18 +111,21 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
96
111
|
() => this.opts.max.current,
|
|
97
112
|
() => this.opts.value.current,
|
|
98
113
|
], ([step, min, max, value]) => {
|
|
114
|
+
const steps = normalizeSteps(step, min, max);
|
|
99
115
|
const isValidValue = (v) => {
|
|
100
|
-
|
|
101
|
-
return snappedValue === v;
|
|
116
|
+
return steps.includes(v);
|
|
102
117
|
};
|
|
103
118
|
const gcv = (v) => {
|
|
104
|
-
return
|
|
119
|
+
return snapValueToCustomSteps(v, steps);
|
|
105
120
|
};
|
|
106
121
|
if (!isValidValue(value)) {
|
|
107
122
|
this.opts.value.current = gcv(value);
|
|
108
123
|
}
|
|
109
124
|
});
|
|
110
125
|
}
|
|
126
|
+
isTickValueSelected = (tickValue) => {
|
|
127
|
+
return this.opts.value.current === tickValue;
|
|
128
|
+
};
|
|
111
129
|
applyPosition({ clientXY, start, end }) {
|
|
112
130
|
const min = this.opts.min.current;
|
|
113
131
|
const max = this.opts.max.current;
|
|
@@ -120,20 +138,13 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
120
138
|
this.updateValue(max);
|
|
121
139
|
}
|
|
122
140
|
else {
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const midpointOfNextStep = min + (currStep + 1) * step + step / 2;
|
|
127
|
-
const newValue = val >= midpointOfCurrStep && val < midpointOfNextStep
|
|
128
|
-
? (currStep + 1) * step + min
|
|
129
|
-
: currStep * step + min;
|
|
130
|
-
if (newValue <= max) {
|
|
131
|
-
this.updateValue(newValue);
|
|
132
|
-
}
|
|
141
|
+
const steps = this.normalizedSteps;
|
|
142
|
+
const newValue = snapValueToCustomSteps(val, steps);
|
|
143
|
+
this.updateValue(newValue);
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
146
|
updateValue = (newValue) => {
|
|
136
|
-
this.opts.value.current =
|
|
147
|
+
this.opts.value.current = snapValueToCustomSteps(newValue, this.normalizedSteps);
|
|
137
148
|
};
|
|
138
149
|
handlePointerMove = (e) => {
|
|
139
150
|
if (!this.isActive || this.opts.disabled.current)
|
|
@@ -212,7 +223,7 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
212
223
|
"aria-disabled": getAriaDisabled(this.opts.disabled.current),
|
|
213
224
|
"aria-orientation": getAriaOrientation(this.opts.orientation.current),
|
|
214
225
|
"data-value": thumbValue,
|
|
215
|
-
|
|
226
|
+
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
216
227
|
style,
|
|
217
228
|
[SLIDER_THUMB_ATTR]: "",
|
|
218
229
|
};
|
|
@@ -222,29 +233,22 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
222
233
|
return this.thumbsPropsArr.map((_, i) => i);
|
|
223
234
|
});
|
|
224
235
|
ticksPropsArr = $derived.by(() => {
|
|
225
|
-
const
|
|
226
|
-
const min = this.opts.min.current;
|
|
227
|
-
const step = this.opts.step.current;
|
|
228
|
-
const difference = max - min;
|
|
229
|
-
let count = Math.ceil(difference / step);
|
|
230
|
-
if (difference % step == 0) {
|
|
231
|
-
count++;
|
|
232
|
-
}
|
|
236
|
+
const steps = this.normalizedSteps;
|
|
233
237
|
const currValue = this.opts.value.current;
|
|
234
|
-
return
|
|
235
|
-
|
|
236
|
-
const
|
|
238
|
+
return steps.map((tickValue, i) => {
|
|
239
|
+
// Calculate position relative to the range
|
|
240
|
+
const tickPosition = this.getPositionFromValue(tickValue);
|
|
237
241
|
const isFirst = i === 0;
|
|
238
|
-
const isLast = i ===
|
|
242
|
+
const isLast = i === steps.length - 1;
|
|
239
243
|
const offsetPercentage = isFirst ? 0 : isLast ? -100 : -50;
|
|
240
|
-
const style = getTickStyles(this.direction,
|
|
241
|
-
const tickValue = min + i * step;
|
|
244
|
+
const style = getTickStyles(this.direction, tickPosition, offsetPercentage);
|
|
242
245
|
const bounded = tickValue <= currValue;
|
|
243
246
|
return {
|
|
244
247
|
"data-disabled": getDataDisabled(this.opts.disabled.current),
|
|
245
248
|
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
246
249
|
"data-bounded": bounded ? "" : undefined,
|
|
247
250
|
"data-value": tickValue,
|
|
251
|
+
"data-selected": this.isTickValueSelected(tickValue) ? "" : undefined,
|
|
248
252
|
style,
|
|
249
253
|
[SLIDER_TICK_ATTR]: "",
|
|
250
254
|
};
|
|
@@ -253,9 +257,26 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
253
257
|
ticksRenderArr = $derived.by(() => {
|
|
254
258
|
return this.ticksPropsArr.map((_, i) => i);
|
|
255
259
|
});
|
|
260
|
+
tickItemsArr = $derived.by(() => {
|
|
261
|
+
return this.ticksPropsArr.map((tick, i) => ({
|
|
262
|
+
value: tick["data-value"],
|
|
263
|
+
index: i,
|
|
264
|
+
}));
|
|
265
|
+
});
|
|
266
|
+
thumbItemsArr = $derived.by(() => {
|
|
267
|
+
const currValue = this.opts.value.current;
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
value: currValue,
|
|
271
|
+
index: 0,
|
|
272
|
+
},
|
|
273
|
+
];
|
|
274
|
+
});
|
|
256
275
|
snippetProps = $derived.by(() => ({
|
|
257
276
|
ticks: this.ticksRenderArr,
|
|
258
277
|
thumbs: this.thumbsRenderArr,
|
|
278
|
+
tickItems: this.tickItemsArr,
|
|
279
|
+
thumbItems: this.thumbItemsArr,
|
|
259
280
|
}));
|
|
260
281
|
}
|
|
261
282
|
class SliderMultiRootState extends SliderBaseRootState {
|
|
@@ -275,18 +296,21 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
275
296
|
() => this.opts.max.current,
|
|
276
297
|
() => this.opts.value.current,
|
|
277
298
|
], ([step, min, max, value]) => {
|
|
299
|
+
const steps = normalizeSteps(step, min, max);
|
|
278
300
|
const isValidValue = (v) => {
|
|
279
|
-
|
|
280
|
-
return snappedValue === v;
|
|
301
|
+
return steps.includes(v);
|
|
281
302
|
};
|
|
282
303
|
const gcv = (v) => {
|
|
283
|
-
return
|
|
304
|
+
return snapValueToCustomSteps(v, steps);
|
|
284
305
|
};
|
|
285
306
|
if (value.some((v) => !isValidValue(v))) {
|
|
286
307
|
this.opts.value.current = value.map(gcv);
|
|
287
308
|
}
|
|
288
309
|
});
|
|
289
310
|
}
|
|
311
|
+
isTickValueSelected = (tickValue) => {
|
|
312
|
+
return this.opts.value.current.includes(tickValue);
|
|
313
|
+
};
|
|
290
314
|
isThumbActive(index) {
|
|
291
315
|
return this.isActive && this.activeThumb?.idx === index;
|
|
292
316
|
}
|
|
@@ -302,16 +326,9 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
302
326
|
this.updateValue(max, activeThumbIdx);
|
|
303
327
|
}
|
|
304
328
|
else {
|
|
305
|
-
const
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
const midpointOfNextStep = min + (currStep + 1) * step + step / 2;
|
|
309
|
-
const newValue = val >= midpointOfCurrStep && val < midpointOfNextStep
|
|
310
|
-
? (currStep + 1) * step + min
|
|
311
|
-
: currStep * step + min;
|
|
312
|
-
if (newValue <= max) {
|
|
313
|
-
this.updateValue(newValue, activeThumbIdx);
|
|
314
|
-
}
|
|
329
|
+
const steps = this.normalizedSteps;
|
|
330
|
+
const newValue = snapValueToCustomSteps(val, steps);
|
|
331
|
+
this.updateValue(newValue, activeThumbIdx);
|
|
315
332
|
}
|
|
316
333
|
}
|
|
317
334
|
#getClosestThumb = (e) => {
|
|
@@ -444,10 +461,8 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
444
461
|
this.opts.value.current = newValue;
|
|
445
462
|
return;
|
|
446
463
|
}
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
const step = this.opts.step.current;
|
|
450
|
-
newValue[idx] = snapValueToStep(thumbValue, min, max, step);
|
|
464
|
+
const steps = this.normalizedSteps;
|
|
465
|
+
newValue[idx] = snapValueToCustomSteps(thumbValue, steps);
|
|
451
466
|
this.opts.value.current = newValue;
|
|
452
467
|
};
|
|
453
468
|
thumbsPropsArr = $derived.by(() => {
|
|
@@ -470,7 +485,7 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
470
485
|
"aria-disabled": getAriaDisabled(this.opts.disabled.current),
|
|
471
486
|
"aria-orientation": getAriaOrientation(this.opts.orientation.current),
|
|
472
487
|
"data-value": thumbValue,
|
|
473
|
-
|
|
488
|
+
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
474
489
|
style,
|
|
475
490
|
[SLIDER_THUMB_ATTR]: "",
|
|
476
491
|
};
|
|
@@ -480,23 +495,15 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
480
495
|
return this.thumbsPropsArr.map((_, i) => i);
|
|
481
496
|
});
|
|
482
497
|
ticksPropsArr = $derived.by(() => {
|
|
483
|
-
const
|
|
484
|
-
const min = this.opts.min.current;
|
|
485
|
-
const step = this.opts.step.current;
|
|
486
|
-
const difference = max - min;
|
|
487
|
-
let count = Math.ceil(difference / step);
|
|
488
|
-
if (difference % step == 0) {
|
|
489
|
-
count++;
|
|
490
|
-
}
|
|
498
|
+
const steps = this.normalizedSteps;
|
|
491
499
|
const currValue = this.opts.value.current;
|
|
492
|
-
return
|
|
493
|
-
|
|
494
|
-
const
|
|
500
|
+
return steps.map((tickValue, i) => {
|
|
501
|
+
// Calculate position relative to the range
|
|
502
|
+
const tickPosition = this.getPositionFromValue(tickValue);
|
|
495
503
|
const isFirst = i === 0;
|
|
496
|
-
const isLast = i ===
|
|
504
|
+
const isLast = i === steps.length - 1;
|
|
497
505
|
const offsetPercentage = isFirst ? 0 : isLast ? -100 : -50;
|
|
498
|
-
const style = getTickStyles(this.direction,
|
|
499
|
-
const tickValue = min + i * step;
|
|
506
|
+
const style = getTickStyles(this.direction, tickPosition, offsetPercentage);
|
|
500
507
|
const bounded = currValue.length === 1
|
|
501
508
|
? tickValue <= currValue[0]
|
|
502
509
|
: currValue[0] <= tickValue && tickValue <= currValue[currValue.length - 1];
|
|
@@ -513,9 +520,24 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
513
520
|
ticksRenderArr = $derived.by(() => {
|
|
514
521
|
return this.ticksPropsArr.map((_, i) => i);
|
|
515
522
|
});
|
|
523
|
+
tickItemsArr = $derived.by(() => {
|
|
524
|
+
return this.ticksPropsArr.map((tick, i) => ({
|
|
525
|
+
value: tick["data-value"],
|
|
526
|
+
index: i,
|
|
527
|
+
}));
|
|
528
|
+
});
|
|
529
|
+
thumbItemsArr = $derived.by(() => {
|
|
530
|
+
const currValue = this.opts.value.current;
|
|
531
|
+
return currValue.map((value, index) => ({
|
|
532
|
+
value,
|
|
533
|
+
index,
|
|
534
|
+
}));
|
|
535
|
+
});
|
|
516
536
|
snippetProps = $derived.by(() => ({
|
|
517
537
|
ticks: this.ticksRenderArr,
|
|
518
538
|
thumbs: this.thumbsRenderArr,
|
|
539
|
+
tickItems: this.tickItemsArr,
|
|
540
|
+
thumbItems: this.thumbItemsArr,
|
|
519
541
|
}));
|
|
520
542
|
}
|
|
521
543
|
const VALID_SLIDER_KEYS = [
|
|
@@ -532,21 +554,37 @@ class SliderRangeState {
|
|
|
532
554
|
constructor(opts, root) {
|
|
533
555
|
this.opts = opts;
|
|
534
556
|
this.root = root;
|
|
535
|
-
useRefById(opts);
|
|
536
557
|
}
|
|
537
558
|
rangeStyles = $derived.by(() => {
|
|
538
|
-
|
|
539
|
-
|
|
559
|
+
if (Array.isArray(this.root.opts.value.current)) {
|
|
560
|
+
// Multi-slider: range between min and max thumbs
|
|
561
|
+
const min = this.root.opts.value.current.length > 1
|
|
540
562
|
? this.root.getPositionFromValue(Math.min(...this.root.opts.value.current) ?? 0)
|
|
541
|
-
: 0
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
563
|
+
: 0;
|
|
564
|
+
const max = 100 -
|
|
565
|
+
this.root.getPositionFromValue(Math.max(...this.root.opts.value.current) ?? 0);
|
|
566
|
+
return {
|
|
567
|
+
position: "absolute",
|
|
568
|
+
...getRangeStyles(this.root.direction, min, max),
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
// Single slider: range from start to current value
|
|
573
|
+
const trackPadding = this.root.opts.trackPadding?.current;
|
|
574
|
+
const currentValue = this.root.opts.value.current;
|
|
575
|
+
const maxValue = this.root.opts.max.current;
|
|
576
|
+
// Always start from 0% (beginning of track container)
|
|
577
|
+
const min = 0;
|
|
578
|
+
// If trackPadding is set and we're at max value, extend to fill the container
|
|
579
|
+
// Otherwise use the thumb position
|
|
580
|
+
const max = trackPadding !== undefined && trackPadding > 0 && currentValue === maxValue
|
|
581
|
+
? 0 // 100% - 0% = full width
|
|
582
|
+
: 100 - this.root.getPositionFromValue(currentValue);
|
|
583
|
+
return {
|
|
584
|
+
position: "absolute",
|
|
585
|
+
...getRangeStyles(this.root.direction, min, max),
|
|
586
|
+
};
|
|
587
|
+
}
|
|
550
588
|
});
|
|
551
589
|
props = $derived.by(() => ({
|
|
552
590
|
id: this.opts.id.current,
|
|
@@ -554,6 +592,7 @@ class SliderRangeState {
|
|
|
554
592
|
"data-disabled": getDataDisabled(this.root.opts.disabled.current),
|
|
555
593
|
style: this.rangeStyles,
|
|
556
594
|
[SLIDER_RANGE_ATTR]: "",
|
|
595
|
+
...attachRef(this.opts.ref),
|
|
557
596
|
}));
|
|
558
597
|
}
|
|
559
598
|
class SliderThumbState {
|
|
@@ -563,7 +602,6 @@ class SliderThumbState {
|
|
|
563
602
|
constructor(opts, root) {
|
|
564
603
|
this.opts = opts;
|
|
565
604
|
this.root = root;
|
|
566
|
-
useRefById(opts);
|
|
567
605
|
this.onkeydown = this.onkeydown.bind(this);
|
|
568
606
|
}
|
|
569
607
|
#updateValue(newValue) {
|
|
@@ -596,7 +634,7 @@ class SliderThumbState {
|
|
|
596
634
|
const thumbValue = Array.isArray(value) ? value[idx] : value;
|
|
597
635
|
const orientation = this.root.opts.orientation.current;
|
|
598
636
|
const direction = this.root.direction;
|
|
599
|
-
const
|
|
637
|
+
const steps = this.root.normalizedSteps;
|
|
600
638
|
switch (e.key) {
|
|
601
639
|
case kbd.HOME:
|
|
602
640
|
this.#updateValue(min);
|
|
@@ -611,11 +649,10 @@ class SliderThumbState {
|
|
|
611
649
|
const newValue = direction === "rl" ? max : min;
|
|
612
650
|
this.#updateValue(newValue);
|
|
613
651
|
}
|
|
614
|
-
else
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
this.#updateValue(thumbValue - step);
|
|
652
|
+
else {
|
|
653
|
+
const stepDirection = direction === "rl" ? "next" : "prev";
|
|
654
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
655
|
+
this.#updateValue(newValue);
|
|
619
656
|
}
|
|
620
657
|
break;
|
|
621
658
|
case kbd.ARROW_RIGHT:
|
|
@@ -625,11 +662,10 @@ class SliderThumbState {
|
|
|
625
662
|
const newValue = direction === "rl" ? min : max;
|
|
626
663
|
this.#updateValue(newValue);
|
|
627
664
|
}
|
|
628
|
-
else
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
this.#updateValue(thumbValue + step);
|
|
665
|
+
else {
|
|
666
|
+
const stepDirection = direction === "rl" ? "prev" : "next";
|
|
667
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
668
|
+
this.#updateValue(newValue);
|
|
633
669
|
}
|
|
634
670
|
break;
|
|
635
671
|
case kbd.ARROW_UP:
|
|
@@ -637,11 +673,10 @@ class SliderThumbState {
|
|
|
637
673
|
const newValue = direction === "tb" ? min : max;
|
|
638
674
|
this.#updateValue(newValue);
|
|
639
675
|
}
|
|
640
|
-
else
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
this.#updateValue(thumbValue + step);
|
|
676
|
+
else {
|
|
677
|
+
const stepDirection = direction === "tb" ? "prev" : "next";
|
|
678
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
679
|
+
this.#updateValue(newValue);
|
|
645
680
|
}
|
|
646
681
|
break;
|
|
647
682
|
case kbd.ARROW_DOWN:
|
|
@@ -649,11 +684,10 @@ class SliderThumbState {
|
|
|
649
684
|
const newValue = direction === "tb" ? max : min;
|
|
650
685
|
this.#updateValue(newValue);
|
|
651
686
|
}
|
|
652
|
-
else
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
this.#updateValue(thumbValue - step);
|
|
687
|
+
else {
|
|
688
|
+
const stepDirection = direction === "tb" ? "next" : "prev";
|
|
689
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
690
|
+
this.#updateValue(newValue);
|
|
657
691
|
}
|
|
658
692
|
break;
|
|
659
693
|
}
|
|
@@ -665,6 +699,9 @@ class SliderThumbState {
|
|
|
665
699
|
id: this.opts.id.current,
|
|
666
700
|
onkeydown: this.onkeydown,
|
|
667
701
|
"data-active": this.root.isThumbActive(this.opts.index.current) ? "" : undefined,
|
|
702
|
+
"data-disabled": getDataDisabled(this.opts.disabled.current || this.root.opts.disabled.current),
|
|
703
|
+
tabindex: this.opts.disabled.current || this.root.opts.disabled.current ? -1 : 0,
|
|
704
|
+
...attachRef(this.opts.ref),
|
|
668
705
|
}));
|
|
669
706
|
}
|
|
670
707
|
class SliderTickState {
|
|
@@ -673,14 +710,68 @@ class SliderTickState {
|
|
|
673
710
|
constructor(opts, root) {
|
|
674
711
|
this.opts = opts;
|
|
675
712
|
this.root = root;
|
|
676
|
-
useRefById(opts);
|
|
677
713
|
}
|
|
678
714
|
props = $derived.by(() => ({
|
|
679
715
|
...this.root.ticksPropsArr[this.opts.index.current],
|
|
680
716
|
id: this.opts.id.current,
|
|
717
|
+
...attachRef(this.opts.ref),
|
|
681
718
|
}));
|
|
682
719
|
}
|
|
683
|
-
|
|
720
|
+
class SliderTickLabelState {
|
|
721
|
+
opts;
|
|
722
|
+
root;
|
|
723
|
+
constructor(opts, root) {
|
|
724
|
+
this.opts = opts;
|
|
725
|
+
this.root = root;
|
|
726
|
+
}
|
|
727
|
+
props = $derived.by(() => {
|
|
728
|
+
const tickProps = this.root.ticksPropsArr[this.opts.index.current];
|
|
729
|
+
const steps = this.root.normalizedSteps;
|
|
730
|
+
const tickValue = steps[this.opts.index.current];
|
|
731
|
+
const tickPosition = this.root.getPositionFromValue(tickValue);
|
|
732
|
+
const labelPosition = this.opts.position?.current ?? "top";
|
|
733
|
+
const style = getTickLabelStyles(this.root.direction, tickPosition, labelPosition);
|
|
734
|
+
return {
|
|
735
|
+
id: this.opts.id.current,
|
|
736
|
+
"data-orientation": getDataOrientation(this.root.opts.orientation.current),
|
|
737
|
+
"data-disabled": getDataDisabled(this.root.opts.disabled.current),
|
|
738
|
+
"data-bounded": tickProps["data-bounded"],
|
|
739
|
+
"data-value": tickValue,
|
|
740
|
+
"data-selected": this.root.isTickValueSelected(tickValue) ? "" : undefined,
|
|
741
|
+
"data-position": labelPosition,
|
|
742
|
+
style,
|
|
743
|
+
[SLIDER_TICK_LABEL_ATTR]: "",
|
|
744
|
+
...attachRef(this.opts.ref),
|
|
745
|
+
};
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
class SliderThumbLabelState {
|
|
749
|
+
opts;
|
|
750
|
+
root;
|
|
751
|
+
constructor(opts, root) {
|
|
752
|
+
this.opts = opts;
|
|
753
|
+
this.root = root;
|
|
754
|
+
}
|
|
755
|
+
props = $derived.by(() => {
|
|
756
|
+
const value = this.root.opts.value.current;
|
|
757
|
+
const thumbValue = Array.isArray(value) ? value[this.opts.index.current] : value;
|
|
758
|
+
const thumbPosition = this.root.getPositionFromValue(thumbValue);
|
|
759
|
+
const labelPosition = this.opts.position?.current ?? "top";
|
|
760
|
+
const style = getThumbLabelStyles(this.root.direction, thumbPosition, labelPosition);
|
|
761
|
+
return {
|
|
762
|
+
id: this.opts.id.current,
|
|
763
|
+
"data-orientation": getDataOrientation(this.root.opts.orientation.current),
|
|
764
|
+
"data-disabled": getDataDisabled(this.root.opts.disabled.current),
|
|
765
|
+
"data-value": thumbValue,
|
|
766
|
+
"data-active": this.root.isThumbActive(this.opts.index.current) ? "" : undefined,
|
|
767
|
+
"data-position": labelPosition,
|
|
768
|
+
style,
|
|
769
|
+
[SLIDER_THUMB_LABEL_ATTR]: "",
|
|
770
|
+
...attachRef(this.opts.ref),
|
|
771
|
+
};
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
export const SliderRootContext = new Context("Slider.Root");
|
|
684
775
|
export function useSliderRoot(props) {
|
|
685
776
|
const { type, ...rest } = props;
|
|
686
777
|
const rootState = type === "single"
|
|
@@ -697,3 +788,9 @@ export function useSliderThumb(props) {
|
|
|
697
788
|
export function useSliderTick(props) {
|
|
698
789
|
return new SliderTickState(props, SliderRootContext.get());
|
|
699
790
|
}
|
|
791
|
+
export function useSliderTickLabel(props) {
|
|
792
|
+
return new SliderTickLabelState(props, SliderRootContext.get());
|
|
793
|
+
}
|
|
794
|
+
export function useSliderThumbLabel(props) {
|
|
795
|
+
return new SliderThumbLabelState(props, SliderRootContext.get());
|
|
796
|
+
}
|