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
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { box, onDestroyEffect, attachRef } from "svelte-toolbelt";
|
|
2
|
+
import { Context, watch } from "runed";
|
|
3
|
+
import { TimeFieldInputState, useTimeFieldRoot } from "../time-field/time-field.svelte.js";
|
|
4
|
+
import { useId } from "../../internal/use-id.js";
|
|
5
|
+
import { getDataDisabled, getDataInvalid } from "../../internal/attrs.js";
|
|
6
|
+
import { createTimeFormatter } from "../../internal/date-time/formatter.js";
|
|
7
|
+
import { removeDescriptionElement } from "../../internal/date-time/field/helpers.js";
|
|
8
|
+
import { getFirstSegment } from "../../internal/date-time/field/segments.js";
|
|
9
|
+
import { convertTimeValueToTime, isTimeBefore, } from "../../internal/date-time/field/time-helpers.js";
|
|
10
|
+
export const TIME_RANGE_FIELD_ROOT_ATTR = "data-time-range-field-root";
|
|
11
|
+
const TIME_RANGE_FIELD_LABEL_ATTR = "data-time-range-field-label";
|
|
12
|
+
export class TimeRangeFieldRootState {
|
|
13
|
+
opts;
|
|
14
|
+
startFieldState = undefined;
|
|
15
|
+
endFieldState = undefined;
|
|
16
|
+
descriptionId = useId();
|
|
17
|
+
formatter;
|
|
18
|
+
fieldNode = $state(null);
|
|
19
|
+
labelNode = $state(null);
|
|
20
|
+
descriptionNode = $state(null);
|
|
21
|
+
startValueComplete = $derived.by(() => this.opts.startValue.current !== undefined);
|
|
22
|
+
endValueComplete = $derived.by(() => this.opts.endValue.current !== undefined);
|
|
23
|
+
rangeComplete = $derived(this.startValueComplete && this.endValueComplete);
|
|
24
|
+
startValueTime = $derived.by(() => {
|
|
25
|
+
if (!this.opts.startValue.current)
|
|
26
|
+
return undefined;
|
|
27
|
+
return convertTimeValueToTime(this.opts.startValue.current);
|
|
28
|
+
});
|
|
29
|
+
endValueTime = $derived.by(() => {
|
|
30
|
+
if (!this.opts.endValue.current)
|
|
31
|
+
return undefined;
|
|
32
|
+
return convertTimeValueToTime(this.opts.endValue.current);
|
|
33
|
+
});
|
|
34
|
+
minValueTime = $derived.by(() => {
|
|
35
|
+
if (!this.opts.minValue.current)
|
|
36
|
+
return undefined;
|
|
37
|
+
return convertTimeValueToTime(this.opts.minValue.current);
|
|
38
|
+
});
|
|
39
|
+
maxValueTime = $derived.by(() => {
|
|
40
|
+
if (!this.opts.maxValue.current)
|
|
41
|
+
return undefined;
|
|
42
|
+
return convertTimeValueToTime(this.opts.maxValue.current);
|
|
43
|
+
});
|
|
44
|
+
constructor(opts) {
|
|
45
|
+
this.opts = opts;
|
|
46
|
+
this.formatter = createTimeFormatter(this.opts.locale.current);
|
|
47
|
+
onDestroyEffect(() => {
|
|
48
|
+
removeDescriptionElement(this.descriptionId);
|
|
49
|
+
});
|
|
50
|
+
$effect(() => {
|
|
51
|
+
if (this.formatter.getLocale() === this.opts.locale.current)
|
|
52
|
+
return;
|
|
53
|
+
this.formatter.setLocale(this.opts.locale.current);
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Synchronize the start and end values with the `value` in case
|
|
57
|
+
* it is updated externally.
|
|
58
|
+
*/
|
|
59
|
+
watch(() => this.opts.value.current, (value) => {
|
|
60
|
+
if (value.start && value.end) {
|
|
61
|
+
this.opts.startValue.current = value.start;
|
|
62
|
+
this.opts.endValue.current = value.end;
|
|
63
|
+
}
|
|
64
|
+
else if (value.start) {
|
|
65
|
+
this.opts.startValue.current = value.start;
|
|
66
|
+
this.opts.endValue.current = undefined;
|
|
67
|
+
}
|
|
68
|
+
else if (value.start === undefined && value.end === undefined) {
|
|
69
|
+
this.opts.startValue.current = undefined;
|
|
70
|
+
this.opts.endValue.current = undefined;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Synchronize the placeholder value with the current start value
|
|
75
|
+
*/
|
|
76
|
+
watch(() => this.opts.value.current, (value) => {
|
|
77
|
+
const startValue = value.start;
|
|
78
|
+
if (startValue && this.opts.placeholder.current !== startValue) {
|
|
79
|
+
this.opts.placeholder.current = startValue;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
watch([() => this.opts.startValue.current, () => this.opts.endValue.current], ([startValue, endValue]) => {
|
|
83
|
+
if (this.opts.value.current &&
|
|
84
|
+
this.opts.value.current.start === startValue &&
|
|
85
|
+
this.opts.value.current.end === endValue) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (startValue && endValue) {
|
|
89
|
+
this.#updateValue((prev) => {
|
|
90
|
+
if (prev.start === startValue && prev.end === endValue) {
|
|
91
|
+
return prev;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
start: startValue,
|
|
95
|
+
end: endValue,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (this.opts.value.current &&
|
|
100
|
+
this.opts.value.current.start &&
|
|
101
|
+
this.opts.value.current.end) {
|
|
102
|
+
this.opts.value.current.start = undefined;
|
|
103
|
+
this.opts.value.current.end = undefined;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
validationStatus = $derived.by(() => {
|
|
108
|
+
const value = this.opts.value.current;
|
|
109
|
+
if (value === undefined)
|
|
110
|
+
return false;
|
|
111
|
+
if (value.start === undefined || value.end === undefined)
|
|
112
|
+
return false;
|
|
113
|
+
const msg = this.opts.validate.current?.({
|
|
114
|
+
start: value.start,
|
|
115
|
+
end: value.end,
|
|
116
|
+
});
|
|
117
|
+
if (msg) {
|
|
118
|
+
return {
|
|
119
|
+
reason: "custom",
|
|
120
|
+
message: msg,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (this.minValueTime &&
|
|
124
|
+
this.startValueTime &&
|
|
125
|
+
isTimeBefore(this.startValueTime, this.minValueTime)) {
|
|
126
|
+
return {
|
|
127
|
+
reason: "min",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (this.maxValueTime &&
|
|
131
|
+
this.endValueTime &&
|
|
132
|
+
isTimeBefore(this.maxValueTime, this.endValueTime)) {
|
|
133
|
+
return {
|
|
134
|
+
reason: "max",
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
});
|
|
139
|
+
isInvalid = $derived.by(() => {
|
|
140
|
+
if (this.validationStatus === false)
|
|
141
|
+
return false;
|
|
142
|
+
return true;
|
|
143
|
+
});
|
|
144
|
+
#updateValue(cb) {
|
|
145
|
+
const value = this.opts.value.current;
|
|
146
|
+
const newValue = cb(value);
|
|
147
|
+
this.opts.value.current = newValue;
|
|
148
|
+
}
|
|
149
|
+
props = $derived.by(() => ({
|
|
150
|
+
id: this.opts.id.current,
|
|
151
|
+
role: "group",
|
|
152
|
+
[TIME_RANGE_FIELD_ROOT_ATTR]: "",
|
|
153
|
+
"data-invalid": getDataInvalid(this.isInvalid),
|
|
154
|
+
...attachRef(this.opts.ref, (v) => (this.fieldNode = v)),
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
class TimeRangeFieldLabelState {
|
|
158
|
+
opts;
|
|
159
|
+
root;
|
|
160
|
+
constructor(opts, root) {
|
|
161
|
+
this.opts = opts;
|
|
162
|
+
this.root = root;
|
|
163
|
+
}
|
|
164
|
+
#onclick = () => {
|
|
165
|
+
if (this.root.opts.disabled.current)
|
|
166
|
+
return;
|
|
167
|
+
const firstSegment = getFirstSegment(this.root.fieldNode);
|
|
168
|
+
if (!firstSegment)
|
|
169
|
+
return;
|
|
170
|
+
firstSegment.focus();
|
|
171
|
+
};
|
|
172
|
+
props = $derived.by(() => ({
|
|
173
|
+
id: this.opts.id.current,
|
|
174
|
+
// TODO: invalid state for field
|
|
175
|
+
"data-invalid": getDataInvalid(this.root.isInvalid),
|
|
176
|
+
"data-disabled": getDataDisabled(this.root.opts.disabled.current),
|
|
177
|
+
[TIME_RANGE_FIELD_LABEL_ATTR]: "",
|
|
178
|
+
onclick: this.#onclick,
|
|
179
|
+
...attachRef(this.opts.ref, (v) => (this.root.labelNode = v)),
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
export const TimeRangeFieldRootContext = new Context("TimeRangeField.Root");
|
|
183
|
+
export function useTimeRangeFieldRoot(props) {
|
|
184
|
+
return TimeRangeFieldRootContext.set(new TimeRangeFieldRootState(props));
|
|
185
|
+
}
|
|
186
|
+
export function useTimeRangeFieldLabel(props) {
|
|
187
|
+
return new TimeRangeFieldLabelState(props, TimeRangeFieldRootContext.get());
|
|
188
|
+
}
|
|
189
|
+
export function useTimeRangeFieldInput(props, type) {
|
|
190
|
+
const root = TimeRangeFieldRootContext.get();
|
|
191
|
+
const fieldState = useTimeFieldRoot({
|
|
192
|
+
value: type === "start" ? root.opts.startValue : root.opts.endValue,
|
|
193
|
+
disabled: root.opts.disabled,
|
|
194
|
+
readonly: root.opts.readonly,
|
|
195
|
+
readonlySegments: root.opts.readonlySegments,
|
|
196
|
+
validate: box.with(() => undefined),
|
|
197
|
+
minValue: root.opts.minValue,
|
|
198
|
+
maxValue: root.opts.maxValue,
|
|
199
|
+
hourCycle: root.opts.hourCycle,
|
|
200
|
+
locale: root.opts.locale,
|
|
201
|
+
hideTimeZone: root.opts.hideTimeZone,
|
|
202
|
+
required: root.opts.required,
|
|
203
|
+
granularity: root.opts.granularity,
|
|
204
|
+
placeholder: root.opts.placeholder,
|
|
205
|
+
onInvalid: root.opts.onInvalid,
|
|
206
|
+
errorMessageId: root.opts.errorMessageId,
|
|
207
|
+
isInvalidProp: box.with(() => root.isInvalid),
|
|
208
|
+
}, root);
|
|
209
|
+
return new TimeFieldInputState({ name: props.name, id: props.id, ref: props.ref }, fieldState);
|
|
210
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { Time } from "@internationalized/date";
|
|
2
|
+
import type { OnChangeFn, WithChild, Without } from "../../internal/types.js";
|
|
3
|
+
import type { BitsPrimitiveDivAttributes, BitsPrimitiveSpanAttributes } from "../../shared/attributes.js";
|
|
4
|
+
import type { TimeSegmentPart } from "../../shared/index.js";
|
|
5
|
+
import type { TimeFieldSegmentProps, TimeFieldSegmentPropsWithoutHTML } from "../time-field/types.js";
|
|
6
|
+
import type { EditableTimeSegmentPart, TimeGranularity, TimeOnInvalid, TimeRange, TimeRangeValidator, TimeValue } from "../../shared/date/types.js";
|
|
7
|
+
export type TimeRangeFieldRootPropsWithoutHTML<T extends TimeValue = Time> = WithChild<{
|
|
8
|
+
/**
|
|
9
|
+
* The value of the date range field.
|
|
10
|
+
*
|
|
11
|
+
* @bindable
|
|
12
|
+
*/
|
|
13
|
+
value?: TimeRange<T>;
|
|
14
|
+
/**
|
|
15
|
+
* A callback that is called when the value of the date range field changes.
|
|
16
|
+
*/
|
|
17
|
+
onValueChange?: OnChangeFn<TimeRange<T> | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* The placeholder value of the time field. This determines the format
|
|
20
|
+
* and what date the field starts at when it is empty.
|
|
21
|
+
*
|
|
22
|
+
* @bindable
|
|
23
|
+
*/
|
|
24
|
+
placeholder?: TimeValue;
|
|
25
|
+
/**
|
|
26
|
+
* A callback that is called when the time field's placeholder value changes.
|
|
27
|
+
*/
|
|
28
|
+
onPlaceholderChange?: OnChangeFn<TimeValue | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* A function that returns a string or array of strings as validation errors if the date is
|
|
31
|
+
* invalid, or nothing if the date is valid
|
|
32
|
+
*/
|
|
33
|
+
validate?: TimeRangeValidator<T>;
|
|
34
|
+
/**
|
|
35
|
+
* A callback fired when the time field's value is invalid. Use this to display an error
|
|
36
|
+
* message to the user.
|
|
37
|
+
*/
|
|
38
|
+
onInvalid?: TimeOnInvalid;
|
|
39
|
+
/**
|
|
40
|
+
* The minimum acceptable date. When provided, the time field
|
|
41
|
+
* will be marked as invalid if the user enters a date before this date.
|
|
42
|
+
*/
|
|
43
|
+
minValue?: TimeValue;
|
|
44
|
+
/**
|
|
45
|
+
* The maximum acceptable date. When provided, the time field
|
|
46
|
+
* will be marked as invalid if the user enters a date after this date.
|
|
47
|
+
*/
|
|
48
|
+
maxValue?: TimeValue;
|
|
49
|
+
/**
|
|
50
|
+
* If true, the time field will be disabled and users will not be able
|
|
51
|
+
* to interact with it. This also disables the hidden input element if
|
|
52
|
+
* the time field is used in a form.
|
|
53
|
+
*
|
|
54
|
+
* @defaultValue false
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* If true, the time field will be readonly, and users will not be able to
|
|
59
|
+
* edit the values of any of the individual segments.
|
|
60
|
+
*
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
readonly?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* If true, the time field will be required, which is useful when used within
|
|
66
|
+
* a form. If the time field is empty when the form is submitted, the form
|
|
67
|
+
* will not be valid.
|
|
68
|
+
*
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
required?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* An array of segment names that should be readonly. If provided, only the
|
|
74
|
+
* segments not in this array will be editable.
|
|
75
|
+
*/
|
|
76
|
+
readonlySegments?: EditableTimeSegmentPart[];
|
|
77
|
+
/**
|
|
78
|
+
* The format to use for displaying the time in the input.
|
|
79
|
+
* If using a 12 hour clock, ensure you also include the `dayPeriod`
|
|
80
|
+
* segment in your input to ensure the user can select AM/PM.
|
|
81
|
+
*
|
|
82
|
+
* @default - the locale's default time format
|
|
83
|
+
*/
|
|
84
|
+
hourCycle?: 12 | 24;
|
|
85
|
+
/**
|
|
86
|
+
* The locale to use for formatting the time field.
|
|
87
|
+
*
|
|
88
|
+
* @default 'en'
|
|
89
|
+
*/
|
|
90
|
+
locale?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The granularity of the time field. This determines which
|
|
93
|
+
* segments will be includes in the segments array used to
|
|
94
|
+
* build the time field.
|
|
95
|
+
*
|
|
96
|
+
* Granularity is only used for visual purposes, and does not impact
|
|
97
|
+
* the value of the time field. You can have the same value synced
|
|
98
|
+
* between multiple time fields with different granularities and they
|
|
99
|
+
* will all contain the same value.
|
|
100
|
+
*
|
|
101
|
+
* @default 'minute'
|
|
102
|
+
*/
|
|
103
|
+
granularity?: TimeGranularity;
|
|
104
|
+
/**
|
|
105
|
+
* Whether or not to hide the timeZoneName segment from the time field.
|
|
106
|
+
*
|
|
107
|
+
* @defaultValue false;
|
|
108
|
+
*/
|
|
109
|
+
hideTimeZone?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* A callback function called when the start value changes. This doesn't necessarily mean
|
|
112
|
+
* the `value` has updated and should be used to apply cosmetic changes to the field when
|
|
113
|
+
* only part of the value is changed/completed.
|
|
114
|
+
*/
|
|
115
|
+
onStartValueChange?: OnChangeFn<T | undefined>;
|
|
116
|
+
/**
|
|
117
|
+
* A callback function called when the end value changes. This doesn't necessarily mean
|
|
118
|
+
* the `value` has updated and should be used to apply cosmetic changes to the field when
|
|
119
|
+
* only part of the value is changed/completed.
|
|
120
|
+
*/
|
|
121
|
+
onEndValueChange?: OnChangeFn<T | undefined>;
|
|
122
|
+
/**
|
|
123
|
+
* The `id` of the element which contains the error messages for the time field when the
|
|
124
|
+
* time is invalid.
|
|
125
|
+
*/
|
|
126
|
+
errorMessageId?: string;
|
|
127
|
+
}>;
|
|
128
|
+
export type TimeRangeFieldRootProps<T extends TimeValue = Time> = TimeRangeFieldRootPropsWithoutHTML<T> & Without<BitsPrimitiveDivAttributes, TimeRangeFieldRootPropsWithoutHTML<T>>;
|
|
129
|
+
export type TimeRangeFieldLabelPropsWithoutHTML = WithChild;
|
|
130
|
+
export type TimeRangeFieldLabelProps = TimeRangeFieldLabelPropsWithoutHTML & Without<BitsPrimitiveSpanAttributes, TimeRangeFieldLabelPropsWithoutHTML>;
|
|
131
|
+
export type TimeRangeFieldInputSnippetProps = {
|
|
132
|
+
segments: Array<{
|
|
133
|
+
part: TimeSegmentPart;
|
|
134
|
+
value: string;
|
|
135
|
+
}>;
|
|
136
|
+
};
|
|
137
|
+
export type TimeRangeFieldInputPropsWithoutHTML = WithChild<{
|
|
138
|
+
/**
|
|
139
|
+
* The name to use for the hidden input element associated with this input
|
|
140
|
+
* used for form submission.
|
|
141
|
+
*/
|
|
142
|
+
name?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Whether this input represents the start or end of the date range.
|
|
145
|
+
*/
|
|
146
|
+
type: "start" | "end";
|
|
147
|
+
}, TimeRangeFieldInputSnippetProps>;
|
|
148
|
+
export type TimeRangeFieldInputProps = TimeRangeFieldInputPropsWithoutHTML & Without<BitsPrimitiveDivAttributes, TimeRangeFieldInputPropsWithoutHTML>;
|
|
149
|
+
export type TimeRangeFieldSegmentPropsWithoutHTML = TimeFieldSegmentPropsWithoutHTML;
|
|
150
|
+
export type TimeRangeFieldSegmentProps = TimeFieldSegmentProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
3
|
import type { ToggleRootProps } from "../types.js";
|
|
4
4
|
import { useToggleRoot } from "../toggle.svelte.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
6
|
import { noop } from "../../../internal/noop.js";
|
|
7
7
|
|
|
8
|
+
const uid = $props.id();
|
|
9
|
+
|
|
8
10
|
let {
|
|
9
11
|
ref = $bindable(null),
|
|
10
|
-
id =
|
|
12
|
+
id = createId(uid),
|
|
11
13
|
pressed = $bindable(false),
|
|
12
14
|
onPressedChange = noop,
|
|
13
15
|
disabled = false,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { attachRef } from "svelte-toolbelt";
|
|
2
2
|
import { getAriaPressed, getDataDisabled, getDisabled } from "../../internal/attrs.js";
|
|
3
3
|
const TOGGLE_ROOT_ATTR = "data-toggle-root";
|
|
4
4
|
class ToggleRootState {
|
|
5
5
|
opts;
|
|
6
6
|
constructor(opts) {
|
|
7
7
|
this.opts = opts;
|
|
8
|
-
useRefById(opts);
|
|
9
8
|
this.onclick = this.onclick.bind(this);
|
|
10
9
|
}
|
|
11
10
|
#togglePressed() {
|
|
@@ -29,6 +28,7 @@ class ToggleRootState {
|
|
|
29
28
|
"data-state": getToggleDataState(this.opts.pressed.current),
|
|
30
29
|
disabled: getDisabled(this.opts.disabled.current),
|
|
31
30
|
onclick: this.onclick,
|
|
31
|
+
...attachRef(this.opts.ref),
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
34
|
export function useToggleRoot(props) {
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
3
|
import type { ToggleGroupItemProps } from "../types.js";
|
|
4
4
|
import { useToggleGroupItem } from "../toggle-group.svelte.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
|
+
|
|
7
|
+
const uid = $props.id();
|
|
6
8
|
|
|
7
9
|
let {
|
|
8
10
|
children,
|
|
@@ -10,7 +12,7 @@
|
|
|
10
12
|
ref = $bindable(null),
|
|
11
13
|
value,
|
|
12
14
|
disabled = false,
|
|
13
|
-
id =
|
|
15
|
+
id = createId(uid),
|
|
14
16
|
type = "button",
|
|
15
17
|
...restProps
|
|
16
18
|
}: ToggleGroupItemProps = $props();
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
import { mergeProps } from "svelte-toolbelt";
|
|
4
4
|
import type { ToggleGroupRootProps } from "../types.js";
|
|
5
5
|
import { useToggleGroupRoot } from "../toggle-group.svelte.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createId } from "../../../internal/create-id.js";
|
|
7
7
|
import { noop } from "../../../internal/noop.js";
|
|
8
8
|
import { watch } from "runed";
|
|
9
9
|
|
|
10
|
+
const uid = $props.id();
|
|
11
|
+
|
|
10
12
|
let {
|
|
11
|
-
id =
|
|
13
|
+
id = createId(uid),
|
|
12
14
|
ref = $bindable(null),
|
|
13
15
|
value = $bindable(),
|
|
14
16
|
onValueChange = noop,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { attachRef } from "svelte-toolbelt";
|
|
2
2
|
import { Context } from "runed";
|
|
3
3
|
import { getAriaChecked, getAriaPressed, getDataDisabled, getDataOrientation, getDisabled, } from "../../internal/attrs.js";
|
|
4
4
|
import { kbd } from "../../internal/kbd.js";
|
|
@@ -12,11 +12,10 @@ class ToggleGroupBaseState {
|
|
|
12
12
|
this.opts = opts;
|
|
13
13
|
this.rovingFocusGroup = useRovingFocus({
|
|
14
14
|
candidateAttr: TOGGLE_GROUP_ITEM_ATTR,
|
|
15
|
-
|
|
15
|
+
rootNode: opts.ref,
|
|
16
16
|
loop: opts.loop,
|
|
17
17
|
orientation: opts.orientation,
|
|
18
18
|
});
|
|
19
|
-
useRefById(opts);
|
|
20
19
|
}
|
|
21
20
|
props = $derived.by(() => ({
|
|
22
21
|
id: this.opts.id.current,
|
|
@@ -24,6 +23,7 @@ class ToggleGroupBaseState {
|
|
|
24
23
|
role: "group",
|
|
25
24
|
"data-orientation": getDataOrientation(this.opts.orientation.current),
|
|
26
25
|
"data-disabled": getDataDisabled(this.opts.disabled.current),
|
|
26
|
+
...attachRef(this.opts.ref),
|
|
27
27
|
}));
|
|
28
28
|
}
|
|
29
29
|
class ToggleGroupSingleState extends ToggleGroupBaseState {
|
|
@@ -75,7 +75,6 @@ class ToggleGroupItemState {
|
|
|
75
75
|
constructor(opts, root) {
|
|
76
76
|
this.opts = opts;
|
|
77
77
|
this.root = root;
|
|
78
|
-
useRefById(opts);
|
|
79
78
|
$effect(() => {
|
|
80
79
|
if (!this.root.opts.rovingFocus.current) {
|
|
81
80
|
this.#tabIndex = 0;
|
|
@@ -135,6 +134,7 @@ class ToggleGroupItemState {
|
|
|
135
134
|
//
|
|
136
135
|
onclick: this.onclick,
|
|
137
136
|
onkeydown: this.onkeydown,
|
|
137
|
+
...attachRef(this.opts.ref),
|
|
138
138
|
}));
|
|
139
139
|
}
|
|
140
140
|
//
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
3
|
import type { ToolbarButtonProps } from "../types.js";
|
|
4
4
|
import { useToolbarButton } from "../toolbar.svelte.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
|
+
|
|
7
|
+
const uid = $props.id();
|
|
6
8
|
|
|
7
9
|
let {
|
|
8
10
|
child,
|
|
9
11
|
children,
|
|
10
12
|
disabled = false,
|
|
11
13
|
type = "button",
|
|
12
|
-
id =
|
|
14
|
+
id = createId(uid),
|
|
13
15
|
ref = $bindable(null),
|
|
14
16
|
...restProps
|
|
15
17
|
}: ToolbarButtonProps = $props();
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
3
|
import type { ToolbarGroupItemProps } from "../types.js";
|
|
4
4
|
import { useToolbarGroupItem } from "../toolbar.svelte.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
|
+
|
|
7
|
+
const uid = $props.id();
|
|
6
8
|
|
|
7
9
|
let {
|
|
8
10
|
child,
|
|
@@ -10,7 +12,7 @@
|
|
|
10
12
|
value,
|
|
11
13
|
disabled = false,
|
|
12
14
|
type = "button",
|
|
13
|
-
id =
|
|
15
|
+
id = createId(uid),
|
|
14
16
|
ref = $bindable(null),
|
|
15
17
|
...restProps
|
|
16
18
|
}: ToolbarGroupItemProps = $props();
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
import { mergeProps } from "svelte-toolbelt";
|
|
4
4
|
import type { ToolbarGroupProps } from "../types.js";
|
|
5
5
|
import { useToolbarGroup } from "../toolbar.svelte.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createId } from "../../../internal/create-id.js";
|
|
7
7
|
import { noop } from "../../../internal/noop.js";
|
|
8
8
|
import { watch } from "runed";
|
|
9
9
|
|
|
10
|
+
const uid = $props.id();
|
|
11
|
+
|
|
10
12
|
let {
|
|
11
|
-
id =
|
|
13
|
+
id = createId(uid),
|
|
12
14
|
ref = $bindable(null),
|
|
13
15
|
value = $bindable(),
|
|
14
16
|
onValueChange = noop,
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
3
|
import { useToolbarLink } from "../toolbar.svelte.js";
|
|
4
4
|
import type { ToolbarLinkProps } from "../types.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
|
+
|
|
7
|
+
const uid = $props.id();
|
|
6
8
|
|
|
7
9
|
let {
|
|
8
10
|
children,
|
|
9
11
|
href,
|
|
10
12
|
child,
|
|
11
13
|
ref = $bindable(null),
|
|
12
|
-
id =
|
|
14
|
+
id = createId(uid),
|
|
13
15
|
...restProps
|
|
14
16
|
}: ToolbarLinkProps = $props();
|
|
15
17
|
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
3
|
import type { ToolbarRootProps } from "../types.js";
|
|
4
4
|
import { useToolbarRoot } from "../toolbar.svelte.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
|
+
|
|
7
|
+
const uid = $props.id();
|
|
6
8
|
|
|
7
9
|
let {
|
|
8
10
|
ref = $bindable(null),
|
|
9
|
-
id =
|
|
11
|
+
id = createId(uid),
|
|
10
12
|
orientation = "horizontal",
|
|
11
13
|
loop = true,
|
|
12
14
|
child,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { attachRef } from "svelte-toolbelt";
|
|
2
2
|
import { Context } from "runed";
|
|
3
3
|
import { getAriaChecked, getAriaPressed, getDataDisabled, getDataOrientation, getDisabled, } from "../../internal/attrs.js";
|
|
4
4
|
import { kbd } from "../../internal/kbd.js";
|
|
@@ -15,11 +15,10 @@ class ToolbarRootState {
|
|
|
15
15
|
rovingFocusGroup;
|
|
16
16
|
constructor(opts) {
|
|
17
17
|
this.opts = opts;
|
|
18
|
-
useRefById(opts);
|
|
19
18
|
this.rovingFocusGroup = useRovingFocus({
|
|
20
19
|
orientation: this.opts.orientation,
|
|
21
20
|
loop: this.opts.loop,
|
|
22
|
-
|
|
21
|
+
rootNode: this.opts.ref,
|
|
23
22
|
candidateAttr: TOOLBAR_ITEM_ATTR,
|
|
24
23
|
});
|
|
25
24
|
}
|
|
@@ -28,6 +27,7 @@ class ToolbarRootState {
|
|
|
28
27
|
role: "toolbar",
|
|
29
28
|
"data-orientation": this.opts.orientation.current,
|
|
30
29
|
[TOOLBAR_ROOT_ATTR]: "",
|
|
30
|
+
...attachRef(this.opts.ref),
|
|
31
31
|
}));
|
|
32
32
|
}
|
|
33
33
|
class ToolbarGroupBaseState {
|
|
@@ -36,7 +36,6 @@ class ToolbarGroupBaseState {
|
|
|
36
36
|
constructor(opts, root) {
|
|
37
37
|
this.opts = opts;
|
|
38
38
|
this.root = root;
|
|
39
|
-
useRefById(opts);
|
|
40
39
|
}
|
|
41
40
|
props = $derived.by(() => ({
|
|
42
41
|
id: this.opts.id.current,
|
|
@@ -44,6 +43,7 @@ class ToolbarGroupBaseState {
|
|
|
44
43
|
role: "group",
|
|
45
44
|
"data-orientation": getDataOrientation(this.root.opts.orientation.current),
|
|
46
45
|
"data-disabled": getDataDisabled(this.opts.disabled.current),
|
|
46
|
+
...attachRef(this.opts.ref),
|
|
47
47
|
}));
|
|
48
48
|
}
|
|
49
49
|
class ToolbarGroupSingleState extends ToolbarGroupBaseState {
|
|
@@ -99,7 +99,6 @@ class ToolbarGroupItemState {
|
|
|
99
99
|
this.opts = opts;
|
|
100
100
|
this.group = group;
|
|
101
101
|
this.root = root;
|
|
102
|
-
useRefById(opts);
|
|
103
102
|
$effect(() => {
|
|
104
103
|
this.#tabIndex = this.root.rovingFocusGroup.getTabIndex(this.opts.ref.current);
|
|
105
104
|
});
|
|
@@ -150,6 +149,7 @@ class ToolbarGroupItemState {
|
|
|
150
149
|
//
|
|
151
150
|
onclick: this.onclick,
|
|
152
151
|
onkeydown: this.onkeydown,
|
|
152
|
+
...attachRef(this.opts.ref),
|
|
153
153
|
}));
|
|
154
154
|
}
|
|
155
155
|
class ToolbarLinkState {
|
|
@@ -158,7 +158,6 @@ class ToolbarLinkState {
|
|
|
158
158
|
constructor(opts, root) {
|
|
159
159
|
this.opts = opts;
|
|
160
160
|
this.root = root;
|
|
161
|
-
useRefById(opts);
|
|
162
161
|
$effect(() => {
|
|
163
162
|
this.#tabIndex = this.root.rovingFocusGroup.getTabIndex(this.opts.ref.current);
|
|
164
163
|
});
|
|
@@ -185,6 +184,7 @@ class ToolbarLinkState {
|
|
|
185
184
|
"data-orientation": getDataOrientation(this.root.opts.orientation.current),
|
|
186
185
|
//
|
|
187
186
|
onkeydown: this.onkeydown,
|
|
187
|
+
...attachRef(this.opts.ref),
|
|
188
188
|
}));
|
|
189
189
|
}
|
|
190
190
|
class ToolbarButtonState {
|
|
@@ -193,7 +193,6 @@ class ToolbarButtonState {
|
|
|
193
193
|
constructor(opts, root) {
|
|
194
194
|
this.opts = opts;
|
|
195
195
|
this.root = root;
|
|
196
|
-
useRefById(opts);
|
|
197
196
|
$effect(() => {
|
|
198
197
|
this.#tabIndex = this.root.rovingFocusGroup.getTabIndex(this.opts.ref.current);
|
|
199
198
|
});
|
|
@@ -222,6 +221,7 @@ class ToolbarButtonState {
|
|
|
222
221
|
disabled: getDisabled(this.opts.disabled.current),
|
|
223
222
|
//
|
|
224
223
|
onkeydown: this.onkeydown,
|
|
224
|
+
...attachRef(this.opts.ref),
|
|
225
225
|
}));
|
|
226
226
|
}
|
|
227
227
|
//
|