bits-ui 2.2.1 → 2.3.1
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 +0 -5
- package/dist/bits/accordion/accordion.svelte.js +11 -14
- package/dist/bits/aspect-ratio/aspect-ratio.svelte.d.ts +0 -1
- package/dist/bits/aspect-ratio/aspect-ratio.svelte.js +6 -2
- package/dist/bits/avatar/avatar.svelte.d.ts +0 -3
- package/dist/bits/avatar/avatar.svelte.js +8 -6
- package/dist/bits/calendar/calendar.svelte.d.ts +2 -2
- package/dist/bits/calendar/calendar.svelte.js +4 -4
- package/dist/bits/checkbox/checkbox.svelte.d.ts +0 -3
- package/dist/bits/checkbox/checkbox.svelte.js +14 -14
- package/dist/bits/collapsible/collapsible.svelte.d.ts +0 -3
- package/dist/bits/collapsible/collapsible.svelte.js +8 -7
- package/dist/bits/command/command.svelte.d.ts +0 -12
- package/dist/bits/command/command.svelte.js +35 -31
- package/dist/bits/date-field/date-field.svelte.d.ts +2 -4
- package/dist/bits/date-field/date-field.svelte.js +8 -6
- package/dist/bits/date-picker/components/date-picker-trigger.svelte +2 -2
- package/dist/bits/date-range-field/date-range-field.svelte.d.ts +1 -3
- package/dist/bits/date-range-field/date-range-field.svelte.js +7 -5
- package/dist/bits/date-range-picker/components/date-range-picker-trigger.svelte +2 -2
- package/dist/bits/dialog/dialog.svelte.d.ts +2 -12
- package/dist/bits/dialog/dialog.svelte.js +16 -24
- package/dist/bits/index.d.ts +1 -0
- package/dist/bits/index.js +1 -0
- package/dist/bits/label/label.svelte.d.ts +0 -1
- package/dist/bits/label/label.svelte.js +6 -2
- package/dist/bits/link-preview/link-preview.svelte.d.ts +0 -2
- package/dist/bits/link-preview/link-preview.svelte.js +7 -5
- package/dist/bits/menu/components/menu-sub-content-static.svelte +1 -1
- package/dist/bits/menu/components/menu-sub-content.svelte +1 -1
- package/dist/bits/menu/menu.svelte.d.ts +2 -1
- package/dist/bits/menu/menu.svelte.js +39 -21
- package/dist/bits/menubar/menubar.svelte.d.ts +1 -7
- package/dist/bits/menubar/menubar.svelte.js +12 -14
- package/dist/bits/meter/meter.svelte.d.ts +0 -1
- package/dist/bits/meter/meter.svelte.js +6 -2
- package/dist/bits/navigation-menu/navigation-menu.svelte.d.ts +2 -11
- package/dist/bits/navigation-menu/navigation-menu.svelte.js +30 -25
- package/dist/bits/pagination/pagination.svelte.d.ts +0 -4
- package/dist/bits/pagination/pagination.svelte.js +9 -10
- package/dist/bits/pin-input/pin-input.svelte.d.ts +0 -2
- package/dist/bits/pin-input/pin-input.svelte.js +7 -5
- package/dist/bits/popover/popover.svelte.d.ts +0 -3
- package/dist/bits/popover/popover.svelte.js +9 -5
- package/dist/bits/progress/progress.svelte.d.ts +0 -1
- package/dist/bits/progress/progress.svelte.js +6 -2
- package/dist/bits/radio-group/radio-group.svelte.d.ts +7 -9
- package/dist/bits/radio-group/radio-group.svelte.js +9 -10
- package/dist/bits/range-calendar/range-calendar.svelte.d.ts +38 -38
- package/dist/bits/range-calendar/range-calendar.svelte.js +79 -79
- package/dist/bits/rating-group/components/rating-group-input.svelte +10 -0
- package/dist/bits/rating-group/components/rating-group-input.svelte.d.ts +18 -0
- package/dist/bits/rating-group/components/rating-group-item.svelte +38 -0
- package/dist/bits/rating-group/components/rating-group-item.svelte.d.ts +4 -0
- package/dist/bits/rating-group/components/rating-group.svelte +80 -0
- package/dist/bits/rating-group/components/rating-group.svelte.d.ts +4 -0
- package/dist/bits/rating-group/exports.d.ts +3 -0
- package/dist/bits/rating-group/exports.js +2 -0
- package/dist/bits/rating-group/index.d.ts +1 -0
- package/dist/bits/rating-group/index.js +1 -0
- package/dist/bits/rating-group/rating-group.svelte.d.ts +112 -0
- package/dist/bits/rating-group/rating-group.svelte.js +317 -0
- package/dist/bits/rating-group/types.d.ts +111 -0
- package/dist/bits/rating-group/types.js +1 -0
- package/dist/bits/scroll-area/scroll-area.svelte.d.ts +15 -19
- package/dist/bits/scroll-area/scroll-area.svelte.js +10 -10
- package/dist/bits/select/select.svelte.d.ts +28 -30
- package/dist/bits/select/select.svelte.js +36 -48
- package/dist/bits/separator/separator.svelte.d.ts +1 -2
- package/dist/bits/separator/separator.svelte.js +6 -3
- package/dist/bits/slider/slider.svelte.d.ts +17 -24
- package/dist/bits/slider/slider.svelte.js +15 -17
- package/dist/bits/switch/switch.svelte.d.ts +6 -8
- package/dist/bits/switch/switch.svelte.js +7 -5
- package/dist/bits/tabs/tabs.svelte.d.ts +5 -9
- package/dist/bits/tabs/tabs.svelte.js +11 -11
- package/dist/bits/time-field/time-field.svelte.d.ts +1 -3
- package/dist/bits/time-field/time-field.svelte.js +7 -5
- package/dist/bits/time-range-field/time-range-field.svelte.d.ts +1 -3
- package/dist/bits/time-range-field/time-range-field.svelte.js +7 -5
- package/dist/bits/toggle/toggle.svelte.d.ts +3 -3
- package/dist/bits/toggle/toggle.svelte.js +6 -3
- package/dist/bits/toggle-group/toggle-group.svelte.d.ts +1 -2
- package/dist/bits/toggle-group/toggle-group.svelte.js +8 -6
- package/dist/bits/toolbar/toolbar.svelte.d.ts +11 -18
- package/dist/bits/toolbar/toolbar.svelte.js +14 -17
- package/dist/bits/tooltip/tooltip.svelte.d.ts +13 -14
- package/dist/bits/tooltip/tooltip.svelte.js +7 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/attrs.d.ts +14 -0
- package/dist/internal/attrs.js +18 -0
- package/dist/internal/date-time/calendar-helpers.svelte.d.ts +1 -0
- package/dist/internal/date-time/calendar-helpers.svelte.js +18 -1
- package/dist/internal/use-arrow-navigation.d.ts +2 -2
- package/dist/internal/use-arrow-navigation.js +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,13 +2,15 @@ import { Previous, watch } from "runed";
|
|
|
2
2
|
import { onMount } from "svelte";
|
|
3
3
|
import { box, attachRef, DOMContext } from "svelte-toolbelt";
|
|
4
4
|
import { usePasswordManagerBadge } from "./usePasswordManager.svelte.js";
|
|
5
|
-
import { getDisabled } from "../../internal/attrs.js";
|
|
5
|
+
import { createBitsAttrs, getDisabled } from "../../internal/attrs.js";
|
|
6
6
|
import { on } from "svelte/events";
|
|
7
7
|
export const REGEXP_ONLY_DIGITS = "^\\d+$";
|
|
8
8
|
export const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
|
|
9
9
|
export const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const pinInputAttrs = createBitsAttrs({
|
|
11
|
+
component: "pin-input",
|
|
12
|
+
parts: ["root", "cell"],
|
|
13
|
+
});
|
|
12
14
|
const KEYS_TO_IGNORE = [
|
|
13
15
|
"Backspace",
|
|
14
16
|
"Delete",
|
|
@@ -151,7 +153,7 @@ class PinInputRootState {
|
|
|
151
153
|
}));
|
|
152
154
|
rootProps = $derived.by(() => ({
|
|
153
155
|
id: this.opts.id.current,
|
|
154
|
-
[
|
|
156
|
+
[pinInputAttrs.root]: "",
|
|
155
157
|
style: this.#rootStyles,
|
|
156
158
|
...attachRef(this.opts.ref),
|
|
157
159
|
}));
|
|
@@ -394,7 +396,7 @@ class PinInputCellState {
|
|
|
394
396
|
}
|
|
395
397
|
props = $derived.by(() => ({
|
|
396
398
|
id: this.opts.id.current,
|
|
397
|
-
[
|
|
399
|
+
[pinInputAttrs.cell]: "",
|
|
398
400
|
"data-active": this.opts.cell.current.isActive ? "" : undefined,
|
|
399
401
|
"data-inactive": !this.opts.cell.current.isActive ? "" : undefined,
|
|
400
402
|
...attachRef(this.opts.ref),
|
|
@@ -28,7 +28,6 @@ declare class PopoverTriggerState {
|
|
|
28
28
|
readonly "aria-expanded": "true" | "false";
|
|
29
29
|
readonly "data-state": "open" | "closed";
|
|
30
30
|
readonly "aria-controls": string | undefined;
|
|
31
|
-
readonly "data-popover-trigger": "";
|
|
32
31
|
readonly disabled: boolean;
|
|
33
32
|
readonly onkeydown: (e: BitsKeyboardEvent) => void;
|
|
34
33
|
readonly onclick: (e: BitsMouseEvent) => void;
|
|
@@ -53,7 +52,6 @@ declare class PopoverContentState {
|
|
|
53
52
|
readonly id: string;
|
|
54
53
|
readonly tabindex: -1;
|
|
55
54
|
readonly "data-state": "open" | "closed";
|
|
56
|
-
readonly "data-popover-content": "";
|
|
57
55
|
readonly style: {
|
|
58
56
|
readonly pointerEvents: "auto";
|
|
59
57
|
};
|
|
@@ -76,7 +74,6 @@ declare class PopoverCloseState {
|
|
|
76
74
|
readonly onclick: (_: BitsPointerEvent) => void;
|
|
77
75
|
readonly onkeydown: (e: BitsKeyboardEvent) => void;
|
|
78
76
|
readonly type: "button";
|
|
79
|
-
readonly "data-popover-close": "";
|
|
80
77
|
};
|
|
81
78
|
}
|
|
82
79
|
export declare function usePopoverRoot(props: PopoverRootStateProps): PopoverRootState;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { attachRef } from "svelte-toolbelt";
|
|
2
2
|
import { Context } from "runed";
|
|
3
3
|
import { kbd } from "../../internal/kbd.js";
|
|
4
|
-
import { getAriaExpanded, getDataOpenClosed } from "../../internal/attrs.js";
|
|
4
|
+
import { createBitsAttrs, getAriaExpanded, getDataOpenClosed } from "../../internal/attrs.js";
|
|
5
5
|
import { isElement } from "../../internal/is.js";
|
|
6
|
+
const popoverAttrs = createBitsAttrs({
|
|
7
|
+
component: "popover",
|
|
8
|
+
parts: ["root", "trigger", "content", "close"],
|
|
9
|
+
});
|
|
6
10
|
class PopoverRootState {
|
|
7
11
|
opts;
|
|
8
12
|
contentNode = $state(null);
|
|
@@ -55,7 +59,7 @@ class PopoverTriggerState {
|
|
|
55
59
|
"aria-expanded": getAriaExpanded(this.root.opts.open.current),
|
|
56
60
|
"data-state": getDataOpenClosed(this.root.opts.open.current),
|
|
57
61
|
"aria-controls": this.#getAriaControls(),
|
|
58
|
-
|
|
62
|
+
[popoverAttrs.trigger]: "",
|
|
59
63
|
disabled: this.opts.disabled.current,
|
|
60
64
|
//
|
|
61
65
|
onkeydown: this.onkeydown,
|
|
@@ -76,7 +80,7 @@ class PopoverContentState {
|
|
|
76
80
|
return;
|
|
77
81
|
if (!isElement(e.target))
|
|
78
82
|
return;
|
|
79
|
-
const closestTrigger = e.target.closest(
|
|
83
|
+
const closestTrigger = e.target.closest(popoverAttrs.selector("trigger"));
|
|
80
84
|
if (closestTrigger === this.root.triggerNode)
|
|
81
85
|
return;
|
|
82
86
|
this.root.handleClose();
|
|
@@ -99,7 +103,7 @@ class PopoverContentState {
|
|
|
99
103
|
id: this.opts.id.current,
|
|
100
104
|
tabindex: -1,
|
|
101
105
|
"data-state": getDataOpenClosed(this.root.opts.open.current),
|
|
102
|
-
|
|
106
|
+
[popoverAttrs.content]: "",
|
|
103
107
|
style: {
|
|
104
108
|
pointerEvents: "auto",
|
|
105
109
|
},
|
|
@@ -134,7 +138,7 @@ class PopoverCloseState {
|
|
|
134
138
|
onclick: this.onclick,
|
|
135
139
|
onkeydown: this.onkeydown,
|
|
136
140
|
type: "button",
|
|
137
|
-
|
|
141
|
+
[popoverAttrs.close]: "",
|
|
138
142
|
...attachRef(this.opts.ref),
|
|
139
143
|
}));
|
|
140
144
|
}
|
|
@@ -19,7 +19,6 @@ declare class ProgressRootState {
|
|
|
19
19
|
readonly "data-max": number;
|
|
20
20
|
readonly "data-min": number;
|
|
21
21
|
readonly "data-indeterminate": "" | undefined;
|
|
22
|
-
readonly "data-progress-root": "";
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
24
|
export declare function useProgressRootState(props: ProgressRootStateProps): ProgressRootState;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { attachRef } from "svelte-toolbelt";
|
|
2
|
-
|
|
2
|
+
import { createBitsAttrs } from "../../internal/attrs.js";
|
|
3
|
+
const progressAttrs = createBitsAttrs({
|
|
4
|
+
component: "progress",
|
|
5
|
+
parts: ["root"],
|
|
6
|
+
});
|
|
3
7
|
class ProgressRootState {
|
|
4
8
|
opts;
|
|
5
9
|
constructor(opts) {
|
|
@@ -16,7 +20,7 @@ class ProgressRootState {
|
|
|
16
20
|
"data-max": this.opts.max.current,
|
|
17
21
|
"data-min": this.opts.min.current,
|
|
18
22
|
"data-indeterminate": this.opts.value.current === null ? "" : undefined,
|
|
19
|
-
[
|
|
23
|
+
[progressAttrs.root]: "",
|
|
20
24
|
...attachRef(this.opts.ref),
|
|
21
25
|
}));
|
|
22
26
|
}
|
|
@@ -13,18 +13,17 @@ type RadioGroupRootStateProps = WithRefProps<ReadableBoxedValues<{
|
|
|
13
13
|
}>>;
|
|
14
14
|
declare class RadioGroupRootState {
|
|
15
15
|
readonly opts: RadioGroupRootStateProps;
|
|
16
|
+
readonly hasValue: boolean;
|
|
16
17
|
rovingFocusGroup: UseRovingFocusReturn;
|
|
17
|
-
hasValue: boolean;
|
|
18
18
|
constructor(opts: RadioGroupRootStateProps);
|
|
19
19
|
isChecked(value: string): boolean;
|
|
20
20
|
setValue(value: string): void;
|
|
21
|
-
props: {
|
|
21
|
+
readonly props: {
|
|
22
22
|
readonly id: string;
|
|
23
23
|
readonly role: "radiogroup";
|
|
24
24
|
readonly "aria-required": "true" | "false";
|
|
25
25
|
readonly "data-disabled": "" | undefined;
|
|
26
26
|
readonly "data-orientation": Orientation;
|
|
27
|
-
readonly "data-radio-group-root": "";
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
type RadioGroupItemStateProps = WithRefProps<ReadableBoxedValues<{
|
|
@@ -35,15 +34,15 @@ declare class RadioGroupItemState {
|
|
|
35
34
|
#private;
|
|
36
35
|
readonly opts: RadioGroupItemStateProps;
|
|
37
36
|
readonly root: RadioGroupRootState;
|
|
38
|
-
checked: boolean;
|
|
37
|
+
readonly checked: boolean;
|
|
39
38
|
constructor(opts: RadioGroupItemStateProps, root: RadioGroupRootState);
|
|
40
39
|
onclick(_: BitsMouseEvent): void;
|
|
41
40
|
onfocus(_: BitsFocusEvent): void;
|
|
42
41
|
onkeydown(e: BitsKeyboardEvent): void;
|
|
43
|
-
snippetProps: {
|
|
42
|
+
readonly snippetProps: {
|
|
44
43
|
checked: boolean;
|
|
45
44
|
};
|
|
46
|
-
props: {
|
|
45
|
+
readonly props: {
|
|
47
46
|
readonly id: string;
|
|
48
47
|
readonly disabled: true | undefined;
|
|
49
48
|
readonly "data-value": string;
|
|
@@ -51,7 +50,6 @@ declare class RadioGroupItemState {
|
|
|
51
50
|
readonly "data-disabled": "" | undefined;
|
|
52
51
|
readonly "data-state": "checked" | "unchecked";
|
|
53
52
|
readonly "aria-checked": "true" | "false" | "mixed";
|
|
54
|
-
readonly "data-radio-group-item": "";
|
|
55
53
|
readonly type: "button";
|
|
56
54
|
readonly role: "radio";
|
|
57
55
|
readonly tabindex: number;
|
|
@@ -62,8 +60,8 @@ declare class RadioGroupItemState {
|
|
|
62
60
|
}
|
|
63
61
|
declare class RadioGroupInputState {
|
|
64
62
|
readonly root: RadioGroupRootState;
|
|
65
|
-
shouldRender: boolean;
|
|
66
|
-
props: {
|
|
63
|
+
readonly shouldRender: boolean;
|
|
64
|
+
readonly props: {
|
|
67
65
|
readonly name: string | undefined;
|
|
68
66
|
readonly value: string;
|
|
69
67
|
readonly required: boolean;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { attachRef } from "svelte-toolbelt";
|
|
2
2
|
import { Context, watch } from "runed";
|
|
3
|
-
import { getAriaChecked, getAriaRequired, getDataDisabled } from "../../internal/attrs.js";
|
|
3
|
+
import { createBitsAttrs, getAriaChecked, getAriaRequired, getDataDisabled, } from "../../internal/attrs.js";
|
|
4
4
|
import { useRovingFocus, } from "../../internal/use-roving-focus.svelte.js";
|
|
5
5
|
import { kbd } from "../../internal/kbd.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const radioGroupAttrs = createBitsAttrs({
|
|
7
|
+
component: "radio-group",
|
|
8
|
+
parts: ["root", "item"],
|
|
9
|
+
});
|
|
8
10
|
class RadioGroupRootState {
|
|
9
11
|
opts;
|
|
10
|
-
rovingFocusGroup;
|
|
11
12
|
hasValue = $derived.by(() => this.opts.value.current !== "");
|
|
13
|
+
rovingFocusGroup;
|
|
12
14
|
constructor(opts) {
|
|
13
15
|
this.opts = opts;
|
|
14
16
|
this.rovingFocusGroup = useRovingFocus({
|
|
15
17
|
rootNode: this.opts.ref,
|
|
16
|
-
candidateAttr:
|
|
18
|
+
candidateAttr: radioGroupAttrs.item,
|
|
17
19
|
loop: this.opts.loop,
|
|
18
20
|
orientation: this.opts.orientation,
|
|
19
21
|
});
|
|
@@ -30,7 +32,7 @@ class RadioGroupRootState {
|
|
|
30
32
|
"aria-required": getAriaRequired(this.opts.required.current),
|
|
31
33
|
"data-disabled": getDataDisabled(this.opts.disabled.current),
|
|
32
34
|
"data-orientation": this.opts.orientation.current,
|
|
33
|
-
[
|
|
35
|
+
[radioGroupAttrs.root]: "",
|
|
34
36
|
...attachRef(this.opts.ref),
|
|
35
37
|
}));
|
|
36
38
|
}
|
|
@@ -93,7 +95,7 @@ class RadioGroupItemState {
|
|
|
93
95
|
"data-disabled": getDataDisabled(this.#isDisabled),
|
|
94
96
|
"data-state": this.#isChecked ? "checked" : "unchecked",
|
|
95
97
|
"aria-checked": getAriaChecked(this.#isChecked, false),
|
|
96
|
-
[
|
|
98
|
+
[radioGroupAttrs.item]: "",
|
|
97
99
|
type: "button",
|
|
98
100
|
role: "radio",
|
|
99
101
|
tabindex: this.#tabIndex,
|
|
@@ -104,9 +106,6 @@ class RadioGroupItemState {
|
|
|
104
106
|
...attachRef(this.opts.ref),
|
|
105
107
|
}));
|
|
106
108
|
}
|
|
107
|
-
//
|
|
108
|
-
// INPUT
|
|
109
|
-
//
|
|
110
109
|
class RadioGroupInputState {
|
|
111
110
|
root;
|
|
112
111
|
shouldRender = $derived.by(() => this.root.opts.name.current !== undefined);
|
|
@@ -5,7 +5,7 @@ import type { ReadableBoxedValues, WritableBoxedValues } from "../../internal/bo
|
|
|
5
5
|
import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, WithRefProps } from "../../internal/types.js";
|
|
6
6
|
import { type Announcer } from "../../internal/date-time/announcer.js";
|
|
7
7
|
import { type Formatter } from "../../internal/date-time/formatter.js";
|
|
8
|
-
import {
|
|
8
|
+
import { calendarAttrs } from "../../internal/date-time/calendar-helpers.svelte.js";
|
|
9
9
|
import type { WeekStartsOn } from "../../shared/date/types.js";
|
|
10
10
|
type RangeCalendarRootStateProps = WithRefProps<WritableBoxedValues<{
|
|
11
11
|
value: DateRange;
|
|
@@ -39,16 +39,14 @@ type RangeCalendarRootStateProps = WithRefProps<WritableBoxedValues<{
|
|
|
39
39
|
export declare class RangeCalendarRootState {
|
|
40
40
|
#private;
|
|
41
41
|
readonly opts: RangeCalendarRootStateProps;
|
|
42
|
+
readonly visibleMonths: DateValue[];
|
|
42
43
|
months: Month<DateValue>[];
|
|
43
|
-
visibleMonths: DateValue[];
|
|
44
44
|
announcer: Announcer;
|
|
45
45
|
formatter: Formatter;
|
|
46
46
|
accessibleHeadingId: string;
|
|
47
47
|
focusedValue: DateValue | undefined;
|
|
48
48
|
lastPressedDateValue: DateValue | undefined;
|
|
49
49
|
domContext: DOMContext;
|
|
50
|
-
constructor(opts: RangeCalendarRootStateProps);
|
|
51
|
-
setMonths: (months: Month<DateValue>[]) => void;
|
|
52
50
|
/**
|
|
53
51
|
* This derived state holds an array of localized day names for the current
|
|
54
52
|
* locale and calendar view. It dynamically syncs with the 'weekStartsOn' option,
|
|
@@ -56,24 +54,26 @@ export declare class RangeCalendarRootState {
|
|
|
56
54
|
* calendar's days of the week is strongly recommended, as it guarantees that
|
|
57
55
|
* the days are correctly formatted for the current locale and calendar view.
|
|
58
56
|
*/
|
|
59
|
-
weekdays: string[];
|
|
57
|
+
readonly weekdays: string[];
|
|
58
|
+
readonly isStartInvalid: boolean;
|
|
59
|
+
readonly isEndInvalid: boolean;
|
|
60
|
+
readonly isInvalid: boolean;
|
|
61
|
+
readonly isNextButtonDisabled: boolean;
|
|
62
|
+
readonly isPrevButtonDisabled: boolean;
|
|
63
|
+
readonly headingValue: string;
|
|
64
|
+
readonly fullCalendarLabel: string;
|
|
65
|
+
readonly highlightedRange: {
|
|
66
|
+
start: DateValue;
|
|
67
|
+
end: DateValue;
|
|
68
|
+
} | null;
|
|
69
|
+
constructor(opts: RangeCalendarRootStateProps);
|
|
70
|
+
setMonths: (months: Month<DateValue>[]) => void;
|
|
60
71
|
isOutsideVisibleMonths(date: DateValue): boolean;
|
|
61
72
|
isDateDisabled(date: DateValue): boolean;
|
|
62
73
|
isDateUnavailable(date: DateValue): boolean;
|
|
63
|
-
isStartInvalid: boolean;
|
|
64
|
-
isEndInvalid: boolean;
|
|
65
|
-
isInvalid: boolean;
|
|
66
|
-
isNextButtonDisabled: boolean;
|
|
67
|
-
isPrevButtonDisabled: boolean;
|
|
68
|
-
headingValue: string;
|
|
69
|
-
fullCalendarLabel: string;
|
|
70
74
|
isSelectionStart(date: DateValue): boolean;
|
|
71
75
|
isSelectionEnd(date: DateValue): boolean;
|
|
72
76
|
isSelected(date: DateValue): boolean;
|
|
73
|
-
highlightedRange: {
|
|
74
|
-
start: DateValue;
|
|
75
|
-
end: DateValue;
|
|
76
|
-
} | null;
|
|
77
77
|
shiftFocus(node: HTMLElement, add: number): void;
|
|
78
78
|
handleCellClick(e: Event, date: DateValue): void;
|
|
79
79
|
onkeydown(event: BitsKeyboardEvent): void;
|
|
@@ -89,12 +89,12 @@ export declare class RangeCalendarRootState {
|
|
|
89
89
|
prevYear(): void;
|
|
90
90
|
setYear(year: number): void;
|
|
91
91
|
setMonth(month: number): void;
|
|
92
|
-
getBitsAttr
|
|
93
|
-
snippetProps: {
|
|
92
|
+
getBitsAttr: (typeof calendarAttrs)["getAttr"];
|
|
93
|
+
readonly snippetProps: {
|
|
94
94
|
months: Month<DateValue>[];
|
|
95
95
|
weekdays: string[];
|
|
96
96
|
};
|
|
97
|
-
props: {
|
|
97
|
+
readonly props: {
|
|
98
98
|
readonly onkeydown: (event: BitsKeyboardEvent) => void;
|
|
99
99
|
readonly id: string;
|
|
100
100
|
readonly role: "application";
|
|
@@ -111,26 +111,26 @@ type RangeCalendarCellStateProps = WithRefProps<ReadableBoxedValues<{
|
|
|
111
111
|
export declare class RangeCalendarCellState {
|
|
112
112
|
readonly opts: RangeCalendarCellStateProps;
|
|
113
113
|
readonly root: RangeCalendarRootState;
|
|
114
|
-
cellDate: Date;
|
|
115
|
-
isDisabled: boolean;
|
|
116
|
-
isUnavailable: boolean;
|
|
117
|
-
isDateToday: boolean;
|
|
118
|
-
isOutsideMonth: boolean;
|
|
119
|
-
isOutsideVisibleMonths: boolean;
|
|
120
|
-
isFocusedDate: boolean;
|
|
121
|
-
isSelectedDate: boolean;
|
|
122
|
-
isSelectionStart: boolean;
|
|
123
|
-
isSelectionEnd: boolean;
|
|
124
|
-
isHighlighted: boolean;
|
|
125
|
-
labelText: string;
|
|
114
|
+
readonly cellDate: Date;
|
|
115
|
+
readonly isDisabled: boolean;
|
|
116
|
+
readonly isUnavailable: boolean;
|
|
117
|
+
readonly isDateToday: boolean;
|
|
118
|
+
readonly isOutsideMonth: boolean;
|
|
119
|
+
readonly isOutsideVisibleMonths: boolean;
|
|
120
|
+
readonly isFocusedDate: boolean;
|
|
121
|
+
readonly isSelectedDate: boolean;
|
|
122
|
+
readonly isSelectionStart: boolean;
|
|
123
|
+
readonly isSelectionEnd: boolean;
|
|
124
|
+
readonly isHighlighted: boolean;
|
|
125
|
+
readonly labelText: string;
|
|
126
126
|
constructor(opts: RangeCalendarCellStateProps, root: RangeCalendarRootState);
|
|
127
|
-
snippetProps: {
|
|
127
|
+
readonly snippetProps: {
|
|
128
128
|
disabled: boolean;
|
|
129
129
|
unavailable: boolean;
|
|
130
130
|
selected: boolean;
|
|
131
131
|
};
|
|
132
|
-
ariaDisabled: boolean;
|
|
133
|
-
sharedDataAttrs: {
|
|
132
|
+
readonly ariaDisabled: boolean;
|
|
133
|
+
readonly sharedDataAttrs: {
|
|
134
134
|
readonly "data-unavailable": "" | undefined;
|
|
135
135
|
readonly "data-today": "" | undefined;
|
|
136
136
|
readonly "data-outside-month": "" | undefined;
|
|
@@ -144,7 +144,7 @@ export declare class RangeCalendarCellState {
|
|
|
144
144
|
readonly "data-type": string;
|
|
145
145
|
readonly "data-disabled": "" | undefined;
|
|
146
146
|
};
|
|
147
|
-
props: {
|
|
147
|
+
readonly props: {
|
|
148
148
|
readonly "data-unavailable": "" | undefined;
|
|
149
149
|
readonly "data-today": "" | undefined;
|
|
150
150
|
readonly "data-outside-month": "" | undefined;
|
|
@@ -172,14 +172,14 @@ declare class RangeCalendarDayState {
|
|
|
172
172
|
onclick(e: BitsMouseEvent): void;
|
|
173
173
|
onmouseenter(_: BitsMouseEvent): void;
|
|
174
174
|
onfocusin(_: BitsFocusEvent): void;
|
|
175
|
-
snippetProps: {
|
|
175
|
+
readonly snippetProps: {
|
|
176
176
|
disabled: boolean;
|
|
177
177
|
unavailable: boolean;
|
|
178
178
|
selected: boolean;
|
|
179
179
|
day: string;
|
|
180
180
|
};
|
|
181
|
-
props: {
|
|
182
|
-
readonly tabindex:
|
|
181
|
+
readonly props: {
|
|
182
|
+
readonly tabindex: 0 | -1 | undefined;
|
|
183
183
|
readonly "data-bits-day": "";
|
|
184
184
|
readonly onclick: (e: BitsMouseEvent) => void;
|
|
185
185
|
readonly onmouseenter: (_: BitsMouseEvent) => void;
|
|
@@ -6,19 +6,93 @@ import { useId } from "../../internal/use-id.js";
|
|
|
6
6
|
import { getAriaDisabled, getAriaSelected, getDataDisabled, getDataSelected, getDataUnavailable, } from "../../internal/attrs.js";
|
|
7
7
|
import { getAnnouncer } from "../../internal/date-time/announcer.js";
|
|
8
8
|
import { createFormatter } from "../../internal/date-time/formatter.js";
|
|
9
|
-
import { createMonths, getCalendarElementProps, getCalendarHeadingValue, getIsNextButtonDisabled, getIsPrevButtonDisabled, getWeekdays, handleCalendarKeydown, handleCalendarNextPage, handleCalendarPrevPage, shiftCalendarFocus, useEnsureNonDisabledPlaceholder, useMonthViewOptionsSync, useMonthViewPlaceholderSync, } from "../../internal/date-time/calendar-helpers.svelte.js";
|
|
9
|
+
import { calendarAttrs, createMonths, getCalendarElementProps, getCalendarHeadingValue, getIsNextButtonDisabled, getIsPrevButtonDisabled, getWeekdays, handleCalendarKeydown, handleCalendarNextPage, handleCalendarPrevPage, shiftCalendarFocus, useEnsureNonDisabledPlaceholder, useMonthViewOptionsSync, useMonthViewPlaceholderSync, } from "../../internal/date-time/calendar-helpers.svelte.js";
|
|
10
10
|
import { areAllDaysBetweenValid, getDateValueType, isAfter, isBefore, isBetweenInclusive, toDate, } from "../../internal/date-time/utils.js";
|
|
11
11
|
import { onMount } from "svelte";
|
|
12
12
|
export class RangeCalendarRootState {
|
|
13
13
|
opts;
|
|
14
|
-
months = $state([]);
|
|
15
14
|
visibleMonths = $derived.by(() => this.months.map((month) => month.value));
|
|
15
|
+
months = $state([]);
|
|
16
16
|
announcer;
|
|
17
17
|
formatter;
|
|
18
18
|
accessibleHeadingId = useId();
|
|
19
19
|
focusedValue = $state(undefined);
|
|
20
20
|
lastPressedDateValue = undefined;
|
|
21
21
|
domContext;
|
|
22
|
+
/**
|
|
23
|
+
* This derived state holds an array of localized day names for the current
|
|
24
|
+
* locale and calendar view. It dynamically syncs with the 'weekStartsOn' option,
|
|
25
|
+
* updating its content when the option changes. Using this state to render the
|
|
26
|
+
* calendar's days of the week is strongly recommended, as it guarantees that
|
|
27
|
+
* the days are correctly formatted for the current locale and calendar view.
|
|
28
|
+
*/
|
|
29
|
+
weekdays = $derived.by(() => {
|
|
30
|
+
return getWeekdays({
|
|
31
|
+
months: this.months,
|
|
32
|
+
formatter: this.formatter,
|
|
33
|
+
weekdayFormat: this.opts.weekdayFormat.current,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
isStartInvalid = $derived.by(() => {
|
|
37
|
+
if (!this.opts.startValue.current)
|
|
38
|
+
return false;
|
|
39
|
+
return (this.isDateUnavailable(this.opts.startValue.current) ||
|
|
40
|
+
this.isDateDisabled(this.opts.startValue.current));
|
|
41
|
+
});
|
|
42
|
+
isEndInvalid = $derived.by(() => {
|
|
43
|
+
if (!this.opts.endValue.current)
|
|
44
|
+
return false;
|
|
45
|
+
return (this.isDateUnavailable(this.opts.endValue.current) ||
|
|
46
|
+
this.isDateDisabled(this.opts.endValue.current));
|
|
47
|
+
});
|
|
48
|
+
isInvalid = $derived.by(() => {
|
|
49
|
+
if (this.isStartInvalid || this.isEndInvalid)
|
|
50
|
+
return true;
|
|
51
|
+
if (this.opts.endValue.current &&
|
|
52
|
+
this.opts.startValue.current &&
|
|
53
|
+
isBefore(this.opts.endValue.current, this.opts.startValue.current))
|
|
54
|
+
return true;
|
|
55
|
+
return false;
|
|
56
|
+
});
|
|
57
|
+
isNextButtonDisabled = $derived.by(() => {
|
|
58
|
+
return getIsNextButtonDisabled({
|
|
59
|
+
maxValue: this.opts.maxValue.current,
|
|
60
|
+
months: this.months,
|
|
61
|
+
disabled: this.opts.disabled.current,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
isPrevButtonDisabled = $derived.by(() => {
|
|
65
|
+
return getIsPrevButtonDisabled({
|
|
66
|
+
minValue: this.opts.minValue.current,
|
|
67
|
+
months: this.months,
|
|
68
|
+
disabled: this.opts.disabled.current,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
headingValue = $derived.by(() => {
|
|
72
|
+
return getCalendarHeadingValue({
|
|
73
|
+
months: this.months,
|
|
74
|
+
formatter: this.formatter,
|
|
75
|
+
locale: this.opts.locale.current,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
fullCalendarLabel = $derived.by(() => `${this.opts.calendarLabel.current} ${this.headingValue}`);
|
|
79
|
+
highlightedRange = $derived.by(() => {
|
|
80
|
+
if (this.opts.startValue.current && this.opts.endValue.current)
|
|
81
|
+
return null;
|
|
82
|
+
if (!this.opts.startValue.current || !this.focusedValue)
|
|
83
|
+
return null;
|
|
84
|
+
const isStartBeforeFocused = isBefore(this.opts.startValue.current, this.focusedValue);
|
|
85
|
+
const start = isStartBeforeFocused ? this.opts.startValue.current : this.focusedValue;
|
|
86
|
+
const end = isStartBeforeFocused ? this.focusedValue : this.opts.startValue.current;
|
|
87
|
+
const range = { start, end };
|
|
88
|
+
if (isSameDay(start.add({ days: 1 }), end) || isSameDay(start, end)) {
|
|
89
|
+
return range;
|
|
90
|
+
}
|
|
91
|
+
const isValid = areAllDaysBetweenValid(start, end, this.isDateUnavailable, this.isDateDisabled);
|
|
92
|
+
if (isValid)
|
|
93
|
+
return range;
|
|
94
|
+
return null;
|
|
95
|
+
});
|
|
22
96
|
constructor(opts) {
|
|
23
97
|
this.opts = opts;
|
|
24
98
|
this.domContext = new DOMContext(opts.ref);
|
|
@@ -173,20 +247,6 @@ export class RangeCalendarRootState {
|
|
|
173
247
|
setMonths = (months) => {
|
|
174
248
|
this.months = months;
|
|
175
249
|
};
|
|
176
|
-
/**
|
|
177
|
-
* This derived state holds an array of localized day names for the current
|
|
178
|
-
* locale and calendar view. It dynamically syncs with the 'weekStartsOn' option,
|
|
179
|
-
* updating its content when the option changes. Using this state to render the
|
|
180
|
-
* calendar's days of the week is strongly recommended, as it guarantees that
|
|
181
|
-
* the days are correctly formatted for the current locale and calendar view.
|
|
182
|
-
*/
|
|
183
|
-
weekdays = $derived.by(() => {
|
|
184
|
-
return getWeekdays({
|
|
185
|
-
months: this.months,
|
|
186
|
-
formatter: this.formatter,
|
|
187
|
-
weekdayFormat: this.opts.weekdayFormat.current,
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
250
|
isOutsideVisibleMonths(date) {
|
|
191
251
|
return !this.visibleMonths.some((month) => isSameMonth(date, month));
|
|
192
252
|
}
|
|
@@ -206,49 +266,6 @@ export class RangeCalendarRootState {
|
|
|
206
266
|
return true;
|
|
207
267
|
return false;
|
|
208
268
|
}
|
|
209
|
-
isStartInvalid = $derived.by(() => {
|
|
210
|
-
if (!this.opts.startValue.current)
|
|
211
|
-
return false;
|
|
212
|
-
return (this.isDateUnavailable(this.opts.startValue.current) ||
|
|
213
|
-
this.isDateDisabled(this.opts.startValue.current));
|
|
214
|
-
});
|
|
215
|
-
isEndInvalid = $derived.by(() => {
|
|
216
|
-
if (!this.opts.endValue.current)
|
|
217
|
-
return false;
|
|
218
|
-
return (this.isDateUnavailable(this.opts.endValue.current) ||
|
|
219
|
-
this.isDateDisabled(this.opts.endValue.current));
|
|
220
|
-
});
|
|
221
|
-
isInvalid = $derived.by(() => {
|
|
222
|
-
if (this.isStartInvalid || this.isEndInvalid)
|
|
223
|
-
return true;
|
|
224
|
-
if (this.opts.endValue.current &&
|
|
225
|
-
this.opts.startValue.current &&
|
|
226
|
-
isBefore(this.opts.endValue.current, this.opts.startValue.current))
|
|
227
|
-
return true;
|
|
228
|
-
return false;
|
|
229
|
-
});
|
|
230
|
-
isNextButtonDisabled = $derived.by(() => {
|
|
231
|
-
return getIsNextButtonDisabled({
|
|
232
|
-
maxValue: this.opts.maxValue.current,
|
|
233
|
-
months: this.months,
|
|
234
|
-
disabled: this.opts.disabled.current,
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
isPrevButtonDisabled = $derived.by(() => {
|
|
238
|
-
return getIsPrevButtonDisabled({
|
|
239
|
-
minValue: this.opts.minValue.current,
|
|
240
|
-
months: this.months,
|
|
241
|
-
disabled: this.opts.disabled.current,
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
headingValue = $derived.by(() => {
|
|
245
|
-
return getCalendarHeadingValue({
|
|
246
|
-
months: this.months,
|
|
247
|
-
formatter: this.formatter,
|
|
248
|
-
locale: this.opts.locale.current,
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
fullCalendarLabel = $derived.by(() => `${this.opts.calendarLabel.current} ${this.headingValue}`);
|
|
252
269
|
isSelectionStart(date) {
|
|
253
270
|
if (!this.opts.startValue.current)
|
|
254
271
|
return false;
|
|
@@ -269,23 +286,6 @@ export class RangeCalendarRootState {
|
|
|
269
286
|
}
|
|
270
287
|
return false;
|
|
271
288
|
}
|
|
272
|
-
highlightedRange = $derived.by(() => {
|
|
273
|
-
if (this.opts.startValue.current && this.opts.endValue.current)
|
|
274
|
-
return null;
|
|
275
|
-
if (!this.opts.startValue.current || !this.focusedValue)
|
|
276
|
-
return null;
|
|
277
|
-
const isStartBeforeFocused = isBefore(this.opts.startValue.current, this.focusedValue);
|
|
278
|
-
const start = isStartBeforeFocused ? this.opts.startValue.current : this.focusedValue;
|
|
279
|
-
const end = isStartBeforeFocused ? this.focusedValue : this.opts.startValue.current;
|
|
280
|
-
const range = { start, end };
|
|
281
|
-
if (isSameDay(start.add({ days: 1 }), end) || isSameDay(start, end)) {
|
|
282
|
-
return range;
|
|
283
|
-
}
|
|
284
|
-
const isValid = areAllDaysBetweenValid(start, end, this.isDateUnavailable, this.isDateDisabled);
|
|
285
|
-
if (isValid)
|
|
286
|
-
return range;
|
|
287
|
-
return null;
|
|
288
|
-
});
|
|
289
289
|
shiftFocus(node, add) {
|
|
290
290
|
return shiftCalendarFocus({
|
|
291
291
|
node,
|
|
@@ -403,9 +403,9 @@ export class RangeCalendarRootState {
|
|
|
403
403
|
setMonth(month) {
|
|
404
404
|
this.opts.placeholder.current = this.opts.placeholder.current.set({ month });
|
|
405
405
|
}
|
|
406
|
-
getBitsAttr(part) {
|
|
407
|
-
return
|
|
408
|
-
}
|
|
406
|
+
getBitsAttr = (part) => {
|
|
407
|
+
return calendarAttrs.getAttr(part, "range-calendar");
|
|
408
|
+
};
|
|
409
409
|
snippetProps = $derived.by(() => ({
|
|
410
410
|
months: this.months,
|
|
411
411
|
weekdays: this.weekdays,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useRatingGroupHiddenInput } from "../rating-group.svelte.js";
|
|
3
|
+
import HiddenInput from "../../utilities/hidden-input.svelte";
|
|
4
|
+
|
|
5
|
+
const inputState = useRatingGroupHiddenInput();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
{#if inputState.shouldRender}
|
|
9
|
+
<HiddenInput {...inputState.props} />
|
|
10
|
+
{/if}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const RatingGroupInput: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type RatingGroupInput = InstanceType<typeof RatingGroupInput>;
|
|
18
|
+
export default RatingGroupInput;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { box, mergeProps } from "svelte-toolbelt";
|
|
3
|
+
import type { RatingGroupItemProps } from "../types.js";
|
|
4
|
+
import { useRatingGroupItem } from "../rating-group.svelte.js";
|
|
5
|
+
import { createId } from "../../../internal/create-id.js";
|
|
6
|
+
|
|
7
|
+
const uid = $props.id();
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
disabled = false,
|
|
11
|
+
index,
|
|
12
|
+
children,
|
|
13
|
+
child,
|
|
14
|
+
ref = $bindable(null),
|
|
15
|
+
id = createId(uid),
|
|
16
|
+
...restProps
|
|
17
|
+
}: RatingGroupItemProps = $props();
|
|
18
|
+
|
|
19
|
+
const itemState = useRatingGroupItem({
|
|
20
|
+
disabled: box.with(() => Boolean(disabled)),
|
|
21
|
+
index: box.with(() => index),
|
|
22
|
+
id: box.with(() => id),
|
|
23
|
+
ref: box.with(
|
|
24
|
+
() => ref,
|
|
25
|
+
(v) => (ref = v)
|
|
26
|
+
),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const mergedProps = $derived(mergeProps(restProps, itemState.props));
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
{#if child}
|
|
33
|
+
{@render child({ props: mergedProps, ...itemState.snippetProps })}
|
|
34
|
+
{:else}
|
|
35
|
+
<div {...mergedProps}>
|
|
36
|
+
{@render children?.(itemState.snippetProps)}
|
|
37
|
+
</div>
|
|
38
|
+
{/if}
|