bits-ui 1.8.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 +6 -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 +5 -3
- package/dist/bits/navigation-menu/components/navigation-menu.svelte +4 -2
- package/dist/bits/navigation-menu/navigation-menu.svelte.js +13 -50
- 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 +24 -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 +91 -5
- package/dist/bits/slider/slider.svelte.js +194 -101
- package/dist/bits/slider/types.d.ts +105 -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 +2 -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,11 @@ 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
|
+
}
|
|
49
59
|
if (this.opts.thumbPositioning.current === "exact") {
|
|
50
60
|
// User opted out of containment
|
|
51
61
|
return [0, 100];
|
|
@@ -83,6 +93,7 @@ class SliderBaseRootState {
|
|
|
83
93
|
touchAction: this.#touchAction,
|
|
84
94
|
},
|
|
85
95
|
[SLIDER_ROOT_ATTR]: "",
|
|
96
|
+
...attachRef(this.opts.ref),
|
|
86
97
|
}));
|
|
87
98
|
}
|
|
88
99
|
class SliderSingleRootState extends SliderBaseRootState {
|
|
@@ -100,18 +111,21 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
100
111
|
() => this.opts.max.current,
|
|
101
112
|
() => this.opts.value.current,
|
|
102
113
|
], ([step, min, max, value]) => {
|
|
114
|
+
const steps = normalizeSteps(step, min, max);
|
|
103
115
|
const isValidValue = (v) => {
|
|
104
|
-
|
|
105
|
-
return snappedValue === v;
|
|
116
|
+
return steps.includes(v);
|
|
106
117
|
};
|
|
107
118
|
const gcv = (v) => {
|
|
108
|
-
return
|
|
119
|
+
return snapValueToCustomSteps(v, steps);
|
|
109
120
|
};
|
|
110
121
|
if (!isValidValue(value)) {
|
|
111
122
|
this.opts.value.current = gcv(value);
|
|
112
123
|
}
|
|
113
124
|
});
|
|
114
125
|
}
|
|
126
|
+
isTickValueSelected = (tickValue) => {
|
|
127
|
+
return this.opts.value.current === tickValue;
|
|
128
|
+
};
|
|
115
129
|
applyPosition({ clientXY, start, end }) {
|
|
116
130
|
const min = this.opts.min.current;
|
|
117
131
|
const max = this.opts.max.current;
|
|
@@ -124,20 +138,13 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
124
138
|
this.updateValue(max);
|
|
125
139
|
}
|
|
126
140
|
else {
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const midpointOfNextStep = min + (currStep + 1) * step + step / 2;
|
|
131
|
-
const newValue = val >= midpointOfCurrStep && val < midpointOfNextStep
|
|
132
|
-
? (currStep + 1) * step + min
|
|
133
|
-
: currStep * step + min;
|
|
134
|
-
if (newValue <= max) {
|
|
135
|
-
this.updateValue(newValue);
|
|
136
|
-
}
|
|
141
|
+
const steps = this.normalizedSteps;
|
|
142
|
+
const newValue = snapValueToCustomSteps(val, steps);
|
|
143
|
+
this.updateValue(newValue);
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
146
|
updateValue = (newValue) => {
|
|
140
|
-
this.opts.value.current =
|
|
147
|
+
this.opts.value.current = snapValueToCustomSteps(newValue, this.normalizedSteps);
|
|
141
148
|
};
|
|
142
149
|
handlePointerMove = (e) => {
|
|
143
150
|
if (!this.isActive || this.opts.disabled.current)
|
|
@@ -216,7 +223,7 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
216
223
|
"aria-disabled": getAriaDisabled(this.opts.disabled.current),
|
|
217
224
|
"aria-orientation": getAriaOrientation(this.opts.orientation.current),
|
|
218
225
|
"data-value": thumbValue,
|
|
219
|
-
|
|
226
|
+
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
220
227
|
style,
|
|
221
228
|
[SLIDER_THUMB_ATTR]: "",
|
|
222
229
|
};
|
|
@@ -226,29 +233,22 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
226
233
|
return this.thumbsPropsArr.map((_, i) => i);
|
|
227
234
|
});
|
|
228
235
|
ticksPropsArr = $derived.by(() => {
|
|
229
|
-
const
|
|
230
|
-
const min = this.opts.min.current;
|
|
231
|
-
const step = this.opts.step.current;
|
|
232
|
-
const difference = max - min;
|
|
233
|
-
let count = Math.ceil(difference / step);
|
|
234
|
-
if (difference % step == 0) {
|
|
235
|
-
count++;
|
|
236
|
-
}
|
|
236
|
+
const steps = this.normalizedSteps;
|
|
237
237
|
const currValue = this.opts.value.current;
|
|
238
|
-
return
|
|
239
|
-
|
|
240
|
-
const
|
|
238
|
+
return steps.map((tickValue, i) => {
|
|
239
|
+
// Calculate position relative to the range
|
|
240
|
+
const tickPosition = this.getPositionFromValue(tickValue);
|
|
241
241
|
const isFirst = i === 0;
|
|
242
|
-
const isLast = i ===
|
|
242
|
+
const isLast = i === steps.length - 1;
|
|
243
243
|
const offsetPercentage = isFirst ? 0 : isLast ? -100 : -50;
|
|
244
|
-
const style = getTickStyles(this.direction,
|
|
245
|
-
const tickValue = min + i * step;
|
|
244
|
+
const style = getTickStyles(this.direction, tickPosition, offsetPercentage);
|
|
246
245
|
const bounded = tickValue <= currValue;
|
|
247
246
|
return {
|
|
248
247
|
"data-disabled": getDataDisabled(this.opts.disabled.current),
|
|
249
248
|
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
250
249
|
"data-bounded": bounded ? "" : undefined,
|
|
251
250
|
"data-value": tickValue,
|
|
251
|
+
"data-selected": this.isTickValueSelected(tickValue) ? "" : undefined,
|
|
252
252
|
style,
|
|
253
253
|
[SLIDER_TICK_ATTR]: "",
|
|
254
254
|
};
|
|
@@ -257,9 +257,26 @@ class SliderSingleRootState extends SliderBaseRootState {
|
|
|
257
257
|
ticksRenderArr = $derived.by(() => {
|
|
258
258
|
return this.ticksPropsArr.map((_, i) => i);
|
|
259
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
|
+
});
|
|
260
275
|
snippetProps = $derived.by(() => ({
|
|
261
276
|
ticks: this.ticksRenderArr,
|
|
262
277
|
thumbs: this.thumbsRenderArr,
|
|
278
|
+
tickItems: this.tickItemsArr,
|
|
279
|
+
thumbItems: this.thumbItemsArr,
|
|
263
280
|
}));
|
|
264
281
|
}
|
|
265
282
|
class SliderMultiRootState extends SliderBaseRootState {
|
|
@@ -279,18 +296,21 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
279
296
|
() => this.opts.max.current,
|
|
280
297
|
() => this.opts.value.current,
|
|
281
298
|
], ([step, min, max, value]) => {
|
|
299
|
+
const steps = normalizeSteps(step, min, max);
|
|
282
300
|
const isValidValue = (v) => {
|
|
283
|
-
|
|
284
|
-
return snappedValue === v;
|
|
301
|
+
return steps.includes(v);
|
|
285
302
|
};
|
|
286
303
|
const gcv = (v) => {
|
|
287
|
-
return
|
|
304
|
+
return snapValueToCustomSteps(v, steps);
|
|
288
305
|
};
|
|
289
306
|
if (value.some((v) => !isValidValue(v))) {
|
|
290
307
|
this.opts.value.current = value.map(gcv);
|
|
291
308
|
}
|
|
292
309
|
});
|
|
293
310
|
}
|
|
311
|
+
isTickValueSelected = (tickValue) => {
|
|
312
|
+
return this.opts.value.current.includes(tickValue);
|
|
313
|
+
};
|
|
294
314
|
isThumbActive(index) {
|
|
295
315
|
return this.isActive && this.activeThumb?.idx === index;
|
|
296
316
|
}
|
|
@@ -306,16 +326,9 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
306
326
|
this.updateValue(max, activeThumbIdx);
|
|
307
327
|
}
|
|
308
328
|
else {
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
const midpointOfNextStep = min + (currStep + 1) * step + step / 2;
|
|
313
|
-
const newValue = val >= midpointOfCurrStep && val < midpointOfNextStep
|
|
314
|
-
? (currStep + 1) * step + min
|
|
315
|
-
: currStep * step + min;
|
|
316
|
-
if (newValue <= max) {
|
|
317
|
-
this.updateValue(newValue, activeThumbIdx);
|
|
318
|
-
}
|
|
329
|
+
const steps = this.normalizedSteps;
|
|
330
|
+
const newValue = snapValueToCustomSteps(val, steps);
|
|
331
|
+
this.updateValue(newValue, activeThumbIdx);
|
|
319
332
|
}
|
|
320
333
|
}
|
|
321
334
|
#getClosestThumb = (e) => {
|
|
@@ -448,10 +461,8 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
448
461
|
this.opts.value.current = newValue;
|
|
449
462
|
return;
|
|
450
463
|
}
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
const step = this.opts.step.current;
|
|
454
|
-
newValue[idx] = snapValueToStep(thumbValue, min, max, step);
|
|
464
|
+
const steps = this.normalizedSteps;
|
|
465
|
+
newValue[idx] = snapValueToCustomSteps(thumbValue, steps);
|
|
455
466
|
this.opts.value.current = newValue;
|
|
456
467
|
};
|
|
457
468
|
thumbsPropsArr = $derived.by(() => {
|
|
@@ -474,7 +485,7 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
474
485
|
"aria-disabled": getAriaDisabled(this.opts.disabled.current),
|
|
475
486
|
"aria-orientation": getAriaOrientation(this.opts.orientation.current),
|
|
476
487
|
"data-value": thumbValue,
|
|
477
|
-
|
|
488
|
+
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
478
489
|
style,
|
|
479
490
|
[SLIDER_THUMB_ATTR]: "",
|
|
480
491
|
};
|
|
@@ -484,23 +495,15 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
484
495
|
return this.thumbsPropsArr.map((_, i) => i);
|
|
485
496
|
});
|
|
486
497
|
ticksPropsArr = $derived.by(() => {
|
|
487
|
-
const
|
|
488
|
-
const min = this.opts.min.current;
|
|
489
|
-
const step = this.opts.step.current;
|
|
490
|
-
const difference = max - min;
|
|
491
|
-
let count = Math.ceil(difference / step);
|
|
492
|
-
if (difference % step == 0) {
|
|
493
|
-
count++;
|
|
494
|
-
}
|
|
498
|
+
const steps = this.normalizedSteps;
|
|
495
499
|
const currValue = this.opts.value.current;
|
|
496
|
-
return
|
|
497
|
-
|
|
498
|
-
const
|
|
500
|
+
return steps.map((tickValue, i) => {
|
|
501
|
+
// Calculate position relative to the range
|
|
502
|
+
const tickPosition = this.getPositionFromValue(tickValue);
|
|
499
503
|
const isFirst = i === 0;
|
|
500
|
-
const isLast = i ===
|
|
504
|
+
const isLast = i === steps.length - 1;
|
|
501
505
|
const offsetPercentage = isFirst ? 0 : isLast ? -100 : -50;
|
|
502
|
-
const style = getTickStyles(this.direction,
|
|
503
|
-
const tickValue = min + i * step;
|
|
506
|
+
const style = getTickStyles(this.direction, tickPosition, offsetPercentage);
|
|
504
507
|
const bounded = currValue.length === 1
|
|
505
508
|
? tickValue <= currValue[0]
|
|
506
509
|
: currValue[0] <= tickValue && tickValue <= currValue[currValue.length - 1];
|
|
@@ -517,9 +520,24 @@ class SliderMultiRootState extends SliderBaseRootState {
|
|
|
517
520
|
ticksRenderArr = $derived.by(() => {
|
|
518
521
|
return this.ticksPropsArr.map((_, i) => i);
|
|
519
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
|
+
});
|
|
520
536
|
snippetProps = $derived.by(() => ({
|
|
521
537
|
ticks: this.ticksRenderArr,
|
|
522
538
|
thumbs: this.thumbsRenderArr,
|
|
539
|
+
tickItems: this.tickItemsArr,
|
|
540
|
+
thumbItems: this.thumbItemsArr,
|
|
523
541
|
}));
|
|
524
542
|
}
|
|
525
543
|
const VALID_SLIDER_KEYS = [
|
|
@@ -536,21 +554,37 @@ class SliderRangeState {
|
|
|
536
554
|
constructor(opts, root) {
|
|
537
555
|
this.opts = opts;
|
|
538
556
|
this.root = root;
|
|
539
|
-
useRefById(opts);
|
|
540
557
|
}
|
|
541
558
|
rangeStyles = $derived.by(() => {
|
|
542
|
-
|
|
543
|
-
|
|
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
|
|
544
562
|
? this.root.getPositionFromValue(Math.min(...this.root.opts.value.current) ?? 0)
|
|
545
|
-
: 0
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
+
}
|
|
554
588
|
});
|
|
555
589
|
props = $derived.by(() => ({
|
|
556
590
|
id: this.opts.id.current,
|
|
@@ -558,6 +592,7 @@ class SliderRangeState {
|
|
|
558
592
|
"data-disabled": getDataDisabled(this.root.opts.disabled.current),
|
|
559
593
|
style: this.rangeStyles,
|
|
560
594
|
[SLIDER_RANGE_ATTR]: "",
|
|
595
|
+
...attachRef(this.opts.ref),
|
|
561
596
|
}));
|
|
562
597
|
}
|
|
563
598
|
class SliderThumbState {
|
|
@@ -567,7 +602,6 @@ class SliderThumbState {
|
|
|
567
602
|
constructor(opts, root) {
|
|
568
603
|
this.opts = opts;
|
|
569
604
|
this.root = root;
|
|
570
|
-
useRefById(opts);
|
|
571
605
|
this.onkeydown = this.onkeydown.bind(this);
|
|
572
606
|
}
|
|
573
607
|
#updateValue(newValue) {
|
|
@@ -600,7 +634,7 @@ class SliderThumbState {
|
|
|
600
634
|
const thumbValue = Array.isArray(value) ? value[idx] : value;
|
|
601
635
|
const orientation = this.root.opts.orientation.current;
|
|
602
636
|
const direction = this.root.direction;
|
|
603
|
-
const
|
|
637
|
+
const steps = this.root.normalizedSteps;
|
|
604
638
|
switch (e.key) {
|
|
605
639
|
case kbd.HOME:
|
|
606
640
|
this.#updateValue(min);
|
|
@@ -615,11 +649,10 @@ class SliderThumbState {
|
|
|
615
649
|
const newValue = direction === "rl" ? max : min;
|
|
616
650
|
this.#updateValue(newValue);
|
|
617
651
|
}
|
|
618
|
-
else
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
this.#updateValue(thumbValue - step);
|
|
652
|
+
else {
|
|
653
|
+
const stepDirection = direction === "rl" ? "next" : "prev";
|
|
654
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
655
|
+
this.#updateValue(newValue);
|
|
623
656
|
}
|
|
624
657
|
break;
|
|
625
658
|
case kbd.ARROW_RIGHT:
|
|
@@ -629,11 +662,10 @@ class SliderThumbState {
|
|
|
629
662
|
const newValue = direction === "rl" ? min : max;
|
|
630
663
|
this.#updateValue(newValue);
|
|
631
664
|
}
|
|
632
|
-
else
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
this.#updateValue(thumbValue + step);
|
|
665
|
+
else {
|
|
666
|
+
const stepDirection = direction === "rl" ? "prev" : "next";
|
|
667
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
668
|
+
this.#updateValue(newValue);
|
|
637
669
|
}
|
|
638
670
|
break;
|
|
639
671
|
case kbd.ARROW_UP:
|
|
@@ -641,11 +673,10 @@ class SliderThumbState {
|
|
|
641
673
|
const newValue = direction === "tb" ? min : max;
|
|
642
674
|
this.#updateValue(newValue);
|
|
643
675
|
}
|
|
644
|
-
else
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
this.#updateValue(thumbValue + step);
|
|
676
|
+
else {
|
|
677
|
+
const stepDirection = direction === "tb" ? "prev" : "next";
|
|
678
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
679
|
+
this.#updateValue(newValue);
|
|
649
680
|
}
|
|
650
681
|
break;
|
|
651
682
|
case kbd.ARROW_DOWN:
|
|
@@ -653,11 +684,10 @@ class SliderThumbState {
|
|
|
653
684
|
const newValue = direction === "tb" ? max : min;
|
|
654
685
|
this.#updateValue(newValue);
|
|
655
686
|
}
|
|
656
|
-
else
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
this.#updateValue(thumbValue - step);
|
|
687
|
+
else {
|
|
688
|
+
const stepDirection = direction === "tb" ? "next" : "prev";
|
|
689
|
+
const newValue = getAdjacentStepValue(thumbValue, steps, stepDirection);
|
|
690
|
+
this.#updateValue(newValue);
|
|
661
691
|
}
|
|
662
692
|
break;
|
|
663
693
|
}
|
|
@@ -669,6 +699,9 @@ class SliderThumbState {
|
|
|
669
699
|
id: this.opts.id.current,
|
|
670
700
|
onkeydown: this.onkeydown,
|
|
671
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),
|
|
672
705
|
}));
|
|
673
706
|
}
|
|
674
707
|
class SliderTickState {
|
|
@@ -677,14 +710,68 @@ class SliderTickState {
|
|
|
677
710
|
constructor(opts, root) {
|
|
678
711
|
this.opts = opts;
|
|
679
712
|
this.root = root;
|
|
680
|
-
useRefById(opts);
|
|
681
713
|
}
|
|
682
714
|
props = $derived.by(() => ({
|
|
683
715
|
...this.root.ticksPropsArr[this.opts.index.current],
|
|
684
716
|
id: this.opts.id.current,
|
|
717
|
+
...attachRef(this.opts.ref),
|
|
685
718
|
}));
|
|
686
719
|
}
|
|
687
|
-
|
|
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");
|
|
688
775
|
export function useSliderRoot(props) {
|
|
689
776
|
const { type, ...rest } = props;
|
|
690
777
|
const rootState = type === "single"
|
|
@@ -701,3 +788,9 @@ export function useSliderThumb(props) {
|
|
|
701
788
|
export function useSliderTick(props) {
|
|
702
789
|
return new SliderTickState(props, SliderRootContext.get());
|
|
703
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
|
+
}
|