@proyecto-viviana/solid-stately 0.2.4 → 0.2.7
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/LICENSE +21 -0
- package/dist/autocomplete/createAutocompleteState.d.ts +2 -1
- package/dist/checkbox/createCheckboxGroupState.d.ts +10 -1
- package/dist/collections/types.d.ts +11 -0
- package/dist/color/getColorChannels.d.ts +20 -0
- package/dist/data/createAsyncList.d.ts +111 -0
- package/dist/data/createListData.d.ts +65 -0
- package/dist/data/createTreeData.d.ts +61 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/datepicker/index.d.ts +10 -0
- package/dist/grid/types.d.ts +5 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3737 -2697
- package/dist/index.js.map +1 -7
- package/dist/menu/index.d.ts +8 -0
- package/dist/radio/createRadioGroupState.d.ts +10 -1
- package/dist/select/createSelectState.d.ts +17 -0
- package/dist/selection/index.d.ts +11 -0
- package/dist/toast/createToastState.d.ts +7 -1
- package/dist/toggle/createToggleGroupState.d.ts +45 -0
- package/dist/toggle/index.d.ts +1 -0
- package/dist/tree/TreeCollection.d.ts +3 -2
- package/package.json +6 -5
- package/src/autocomplete/createAutocompleteState.ts +10 -11
- package/src/calendar/createDateFieldState.ts +24 -1
- package/src/checkbox/createCheckboxGroupState.ts +42 -6
- package/src/collections/ListCollection.ts +152 -146
- package/src/collections/createListState.ts +266 -264
- package/src/collections/createMenuState.ts +106 -106
- package/src/collections/createSelectionState.ts +336 -336
- package/src/collections/index.ts +46 -46
- package/src/collections/types.ts +181 -169
- package/src/color/Color.ts +951 -951
- package/src/color/createColorAreaState.ts +293 -293
- package/src/color/createColorFieldState.ts +292 -292
- package/src/color/createColorSliderState.ts +241 -241
- package/src/color/createColorWheelState.ts +211 -211
- package/src/color/getColorChannels.ts +34 -0
- package/src/color/index.ts +47 -47
- package/src/color/types.ts +127 -127
- package/src/combobox/createComboBoxState.ts +703 -703
- package/src/combobox/index.ts +13 -13
- package/src/data/createAsyncList.ts +377 -0
- package/src/data/createListData.ts +298 -0
- package/src/data/createTreeData.ts +433 -0
- package/src/data/index.ts +25 -0
- package/src/datepicker/index.ts +36 -0
- package/src/disclosure/createDisclosureState.ts +4 -4
- package/src/dnd/createDragState.ts +153 -153
- package/src/dnd/createDraggableCollectionState.ts +165 -165
- package/src/dnd/createDropState.ts +212 -212
- package/src/dnd/createDroppableCollectionState.ts +357 -357
- package/src/dnd/index.ts +76 -76
- package/src/dnd/types.ts +317 -317
- package/src/form/createFormValidationState.ts +389 -389
- package/src/form/index.ts +15 -15
- package/src/grid/types.ts +5 -0
- package/src/index.ts +49 -0
- package/src/menu/index.ts +19 -0
- package/src/numberfield/createNumberFieldState.ts +427 -383
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/createOverlayTriggerState.ts +67 -67
- package/src/overlays/index.ts +5 -5
- package/src/radio/createRadioGroupState.ts +44 -6
- package/src/searchfield/createSearchFieldState.ts +62 -62
- package/src/searchfield/index.ts +5 -5
- package/src/select/createSelectState.ts +290 -181
- package/src/select/index.ts +5 -5
- package/src/selection/index.ts +28 -0
- package/src/slider/createSliderState.ts +211 -211
- package/src/slider/index.ts +6 -6
- package/src/tabs/createTabListState.ts +37 -11
- package/src/toast/createToastState.d.ts +6 -1
- package/src/toast/createToastState.ts +8 -1
- package/src/toggle/createToggleGroupState.ts +127 -0
- package/src/toggle/index.ts +6 -0
- package/src/tooltip/createTooltipTriggerState.ts +183 -183
- package/src/tooltip/index.ts +6 -6
- package/src/tree/TreeCollection.ts +208 -175
- package/src/tree/createTreeState.ts +392 -392
- package/src/tree/index.ts +13 -13
- package/src/tree/types.ts +174 -174
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ColorSlider state management.
|
|
3
|
-
* Based on @react-stately/color useColorSliderState.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createSignal, createMemo, type Accessor } from 'solid-js';
|
|
7
|
-
import type { Color, ColorChannel } from './types';
|
|
8
|
-
import { normalizeColor } from './Color';
|
|
9
|
-
|
|
10
|
-
export interface ColorSliderStateOptions {
|
|
11
|
-
/** The current color value (controlled). */
|
|
12
|
-
value?: Color | string;
|
|
13
|
-
/** The default color value (uncontrolled). */
|
|
14
|
-
defaultValue?: Color | string;
|
|
15
|
-
/** Handler called when the color changes. */
|
|
16
|
-
onChange?: (color: Color) => void;
|
|
17
|
-
/** Handler called when dragging ends. */
|
|
18
|
-
onChangeEnd?: (color: Color) => void;
|
|
19
|
-
/** The color channel this slider controls. */
|
|
20
|
-
channel: ColorChannel;
|
|
21
|
-
/** Whether the slider is disabled. */
|
|
22
|
-
isDisabled?: boolean;
|
|
23
|
-
/** The locale for formatting. */
|
|
24
|
-
locale?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ColorSliderState {
|
|
28
|
-
/** The current color value. */
|
|
29
|
-
readonly value: Color;
|
|
30
|
-
/** Whether the slider is being dragged. */
|
|
31
|
-
readonly isDragging: boolean;
|
|
32
|
-
/** The color channel being controlled. */
|
|
33
|
-
readonly channel: ColorChannel;
|
|
34
|
-
/** The step value for the channel. */
|
|
35
|
-
readonly step: number;
|
|
36
|
-
/** The page step value for the channel. */
|
|
37
|
-
readonly pageSize: number;
|
|
38
|
-
/** The minimum value for the channel. */
|
|
39
|
-
readonly minValue: number;
|
|
40
|
-
/** The maximum value for the channel. */
|
|
41
|
-
readonly maxValue: number;
|
|
42
|
-
/** Whether the slider is disabled. */
|
|
43
|
-
readonly isDisabled: boolean;
|
|
44
|
-
|
|
45
|
-
/** Get the current channel value. */
|
|
46
|
-
getThumbValue(): number;
|
|
47
|
-
/** Get the minimum percent. */
|
|
48
|
-
getThumbMinValue(): number;
|
|
49
|
-
/** Get the maximum percent. */
|
|
50
|
-
getThumbMaxValue(): number;
|
|
51
|
-
/** Get the thumb value as a percentage. */
|
|
52
|
-
getThumbPercent(): number;
|
|
53
|
-
/** Set the channel value. */
|
|
54
|
-
setThumbValue(value: number): void;
|
|
55
|
-
/** Set the thumb value from a percentage (0-1). */
|
|
56
|
-
setThumbPercent(percent: number): void;
|
|
57
|
-
/** Increment the channel value. */
|
|
58
|
-
incrementThumb(stepSize?: number): void;
|
|
59
|
-
/** Decrement the channel value. */
|
|
60
|
-
decrementThumb(stepSize?: number): void;
|
|
61
|
-
/** Set the dragging state. */
|
|
62
|
-
setDragging(isDragging: boolean): void;
|
|
63
|
-
/** Get the display color (with alpha = 1). */
|
|
64
|
-
getDisplayColor(): Color;
|
|
65
|
-
/** Get the formatted value label. */
|
|
66
|
-
getThumbValueLabel(): string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Creates state for a color slider.
|
|
71
|
-
*/
|
|
72
|
-
export function createColorSliderState(
|
|
73
|
-
options: Accessor<ColorSliderStateOptions>
|
|
74
|
-
): ColorSliderState {
|
|
75
|
-
const getOptions = () => options();
|
|
76
|
-
|
|
77
|
-
// Internal value state
|
|
78
|
-
const [internalValue, setInternalValue] = createSignal<Color | null>(null);
|
|
79
|
-
const [isDragging, setIsDragging] = createSignal(false);
|
|
80
|
-
|
|
81
|
-
// Initialize internal value
|
|
82
|
-
const initValue = () => {
|
|
83
|
-
const opts = getOptions();
|
|
84
|
-
if (opts.defaultValue) {
|
|
85
|
-
return normalizeColor(opts.defaultValue);
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Set initial value
|
|
91
|
-
if (internalValue() === null) {
|
|
92
|
-
const init = initValue();
|
|
93
|
-
if (init) {
|
|
94
|
-
setInternalValue(init);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Controlled vs uncontrolled value
|
|
99
|
-
const value = createMemo(() => {
|
|
100
|
-
const opts = getOptions();
|
|
101
|
-
if (opts.value !== undefined) {
|
|
102
|
-
return normalizeColor(opts.value);
|
|
103
|
-
}
|
|
104
|
-
return internalValue() ?? normalizeColor('#ff0000');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const channel = createMemo(() => getOptions().channel);
|
|
108
|
-
const isDisabled = createMemo(() => getOptions().isDisabled ?? false);
|
|
109
|
-
const locale = createMemo(() => getOptions().locale ?? 'en-US');
|
|
110
|
-
|
|
111
|
-
// Get channel range
|
|
112
|
-
const channelRange = createMemo(() => value().getChannelRange(channel()));
|
|
113
|
-
|
|
114
|
-
const step = createMemo(() => channelRange().step);
|
|
115
|
-
const pageSize = createMemo(() => channelRange().pageSize);
|
|
116
|
-
const minValue = createMemo(() => channelRange().minValue);
|
|
117
|
-
const maxValue = createMemo(() => channelRange().maxValue);
|
|
118
|
-
|
|
119
|
-
// Update value
|
|
120
|
-
const updateValue = (newColor: Color) => {
|
|
121
|
-
const opts = getOptions();
|
|
122
|
-
|
|
123
|
-
// Controlled mode
|
|
124
|
-
if (opts.value !== undefined) {
|
|
125
|
-
opts.onChange?.(newColor);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Uncontrolled mode
|
|
130
|
-
setInternalValue(newColor);
|
|
131
|
-
opts.onChange?.(newColor);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// Get thumb value
|
|
135
|
-
const getThumbValue = () => {
|
|
136
|
-
return value().getChannelValue(channel());
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Get min/max values
|
|
140
|
-
const getThumbMinValue = () => minValue();
|
|
141
|
-
const getThumbMaxValue = () => maxValue();
|
|
142
|
-
|
|
143
|
-
// Get thumb percent
|
|
144
|
-
const getThumbPercent = () => {
|
|
145
|
-
const val = getThumbValue();
|
|
146
|
-
const min = minValue();
|
|
147
|
-
const max = maxValue();
|
|
148
|
-
return (val - min) / (max - min);
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
// Set thumb value
|
|
152
|
-
const setThumbValue = (newValue: number) => {
|
|
153
|
-
const clamped = Math.max(minValue(), Math.min(maxValue(), newValue));
|
|
154
|
-
const rounded = Math.round(clamped / step()) * step();
|
|
155
|
-
const newColor = value().withChannelValue(channel(), rounded);
|
|
156
|
-
updateValue(newColor);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// Set thumb from percent
|
|
160
|
-
const setThumbPercent = (percent: number) => {
|
|
161
|
-
const min = minValue();
|
|
162
|
-
const max = maxValue();
|
|
163
|
-
const val = min + (max - min) * percent;
|
|
164
|
-
setThumbValue(val);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// Increment
|
|
168
|
-
const incrementThumb = (stepSize?: number) => {
|
|
169
|
-
const s = stepSize ?? step();
|
|
170
|
-
setThumbValue(getThumbValue() + s);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// Decrement
|
|
174
|
-
const decrementThumb = (stepSize?: number) => {
|
|
175
|
-
const s = stepSize ?? step();
|
|
176
|
-
setThumbValue(getThumbValue() - s);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// Set dragging
|
|
180
|
-
const setDraggingState = (dragging: boolean) => {
|
|
181
|
-
const wasDragging = isDragging();
|
|
182
|
-
setIsDragging(dragging);
|
|
183
|
-
|
|
184
|
-
// Call onChangeEnd when dragging ends
|
|
185
|
-
if (wasDragging && !dragging) {
|
|
186
|
-
getOptions().onChangeEnd?.(value());
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// Get display color (alpha = 1)
|
|
191
|
-
const getDisplayColor = () => {
|
|
192
|
-
const v = value();
|
|
193
|
-
return v.withChannelValue('alpha', 1);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// Get formatted value label
|
|
197
|
-
const getThumbValueLabel = () => {
|
|
198
|
-
const v = value();
|
|
199
|
-
const ch = channel();
|
|
200
|
-
const loc = locale();
|
|
201
|
-
return v.formatChannelValue(ch, loc);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
get value() {
|
|
206
|
-
return value();
|
|
207
|
-
},
|
|
208
|
-
get isDragging() {
|
|
209
|
-
return isDragging();
|
|
210
|
-
},
|
|
211
|
-
get channel() {
|
|
212
|
-
return channel();
|
|
213
|
-
},
|
|
214
|
-
get step() {
|
|
215
|
-
return step();
|
|
216
|
-
},
|
|
217
|
-
get pageSize() {
|
|
218
|
-
return pageSize();
|
|
219
|
-
},
|
|
220
|
-
get minValue() {
|
|
221
|
-
return minValue();
|
|
222
|
-
},
|
|
223
|
-
get maxValue() {
|
|
224
|
-
return maxValue();
|
|
225
|
-
},
|
|
226
|
-
get isDisabled() {
|
|
227
|
-
return isDisabled();
|
|
228
|
-
},
|
|
229
|
-
getThumbValue,
|
|
230
|
-
getThumbMinValue,
|
|
231
|
-
getThumbMaxValue,
|
|
232
|
-
getThumbPercent,
|
|
233
|
-
setThumbValue,
|
|
234
|
-
setThumbPercent,
|
|
235
|
-
incrementThumb,
|
|
236
|
-
decrementThumb,
|
|
237
|
-
setDragging: setDraggingState,
|
|
238
|
-
getDisplayColor,
|
|
239
|
-
getThumbValueLabel,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* ColorSlider state management.
|
|
3
|
+
* Based on @react-stately/color useColorSliderState.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createSignal, createMemo, type Accessor } from 'solid-js';
|
|
7
|
+
import type { Color, ColorChannel } from './types';
|
|
8
|
+
import { normalizeColor } from './Color';
|
|
9
|
+
|
|
10
|
+
export interface ColorSliderStateOptions {
|
|
11
|
+
/** The current color value (controlled). */
|
|
12
|
+
value?: Color | string;
|
|
13
|
+
/** The default color value (uncontrolled). */
|
|
14
|
+
defaultValue?: Color | string;
|
|
15
|
+
/** Handler called when the color changes. */
|
|
16
|
+
onChange?: (color: Color) => void;
|
|
17
|
+
/** Handler called when dragging ends. */
|
|
18
|
+
onChangeEnd?: (color: Color) => void;
|
|
19
|
+
/** The color channel this slider controls. */
|
|
20
|
+
channel: ColorChannel;
|
|
21
|
+
/** Whether the slider is disabled. */
|
|
22
|
+
isDisabled?: boolean;
|
|
23
|
+
/** The locale for formatting. */
|
|
24
|
+
locale?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ColorSliderState {
|
|
28
|
+
/** The current color value. */
|
|
29
|
+
readonly value: Color;
|
|
30
|
+
/** Whether the slider is being dragged. */
|
|
31
|
+
readonly isDragging: boolean;
|
|
32
|
+
/** The color channel being controlled. */
|
|
33
|
+
readonly channel: ColorChannel;
|
|
34
|
+
/** The step value for the channel. */
|
|
35
|
+
readonly step: number;
|
|
36
|
+
/** The page step value for the channel. */
|
|
37
|
+
readonly pageSize: number;
|
|
38
|
+
/** The minimum value for the channel. */
|
|
39
|
+
readonly minValue: number;
|
|
40
|
+
/** The maximum value for the channel. */
|
|
41
|
+
readonly maxValue: number;
|
|
42
|
+
/** Whether the slider is disabled. */
|
|
43
|
+
readonly isDisabled: boolean;
|
|
44
|
+
|
|
45
|
+
/** Get the current channel value. */
|
|
46
|
+
getThumbValue(): number;
|
|
47
|
+
/** Get the minimum percent. */
|
|
48
|
+
getThumbMinValue(): number;
|
|
49
|
+
/** Get the maximum percent. */
|
|
50
|
+
getThumbMaxValue(): number;
|
|
51
|
+
/** Get the thumb value as a percentage. */
|
|
52
|
+
getThumbPercent(): number;
|
|
53
|
+
/** Set the channel value. */
|
|
54
|
+
setThumbValue(value: number): void;
|
|
55
|
+
/** Set the thumb value from a percentage (0-1). */
|
|
56
|
+
setThumbPercent(percent: number): void;
|
|
57
|
+
/** Increment the channel value. */
|
|
58
|
+
incrementThumb(stepSize?: number): void;
|
|
59
|
+
/** Decrement the channel value. */
|
|
60
|
+
decrementThumb(stepSize?: number): void;
|
|
61
|
+
/** Set the dragging state. */
|
|
62
|
+
setDragging(isDragging: boolean): void;
|
|
63
|
+
/** Get the display color (with alpha = 1). */
|
|
64
|
+
getDisplayColor(): Color;
|
|
65
|
+
/** Get the formatted value label. */
|
|
66
|
+
getThumbValueLabel(): string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Creates state for a color slider.
|
|
71
|
+
*/
|
|
72
|
+
export function createColorSliderState(
|
|
73
|
+
options: Accessor<ColorSliderStateOptions>
|
|
74
|
+
): ColorSliderState {
|
|
75
|
+
const getOptions = () => options();
|
|
76
|
+
|
|
77
|
+
// Internal value state
|
|
78
|
+
const [internalValue, setInternalValue] = createSignal<Color | null>(null);
|
|
79
|
+
const [isDragging, setIsDragging] = createSignal(false);
|
|
80
|
+
|
|
81
|
+
// Initialize internal value
|
|
82
|
+
const initValue = () => {
|
|
83
|
+
const opts = getOptions();
|
|
84
|
+
if (opts.defaultValue) {
|
|
85
|
+
return normalizeColor(opts.defaultValue);
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Set initial value
|
|
91
|
+
if (internalValue() === null) {
|
|
92
|
+
const init = initValue();
|
|
93
|
+
if (init) {
|
|
94
|
+
setInternalValue(init);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Controlled vs uncontrolled value
|
|
99
|
+
const value = createMemo(() => {
|
|
100
|
+
const opts = getOptions();
|
|
101
|
+
if (opts.value !== undefined) {
|
|
102
|
+
return normalizeColor(opts.value);
|
|
103
|
+
}
|
|
104
|
+
return internalValue() ?? normalizeColor('#ff0000');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const channel = createMemo(() => getOptions().channel);
|
|
108
|
+
const isDisabled = createMemo(() => getOptions().isDisabled ?? false);
|
|
109
|
+
const locale = createMemo(() => getOptions().locale ?? 'en-US');
|
|
110
|
+
|
|
111
|
+
// Get channel range
|
|
112
|
+
const channelRange = createMemo(() => value().getChannelRange(channel()));
|
|
113
|
+
|
|
114
|
+
const step = createMemo(() => channelRange().step);
|
|
115
|
+
const pageSize = createMemo(() => channelRange().pageSize);
|
|
116
|
+
const minValue = createMemo(() => channelRange().minValue);
|
|
117
|
+
const maxValue = createMemo(() => channelRange().maxValue);
|
|
118
|
+
|
|
119
|
+
// Update value
|
|
120
|
+
const updateValue = (newColor: Color) => {
|
|
121
|
+
const opts = getOptions();
|
|
122
|
+
|
|
123
|
+
// Controlled mode
|
|
124
|
+
if (opts.value !== undefined) {
|
|
125
|
+
opts.onChange?.(newColor);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Uncontrolled mode
|
|
130
|
+
setInternalValue(newColor);
|
|
131
|
+
opts.onChange?.(newColor);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// Get thumb value
|
|
135
|
+
const getThumbValue = () => {
|
|
136
|
+
return value().getChannelValue(channel());
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Get min/max values
|
|
140
|
+
const getThumbMinValue = () => minValue();
|
|
141
|
+
const getThumbMaxValue = () => maxValue();
|
|
142
|
+
|
|
143
|
+
// Get thumb percent
|
|
144
|
+
const getThumbPercent = () => {
|
|
145
|
+
const val = getThumbValue();
|
|
146
|
+
const min = minValue();
|
|
147
|
+
const max = maxValue();
|
|
148
|
+
return (val - min) / (max - min);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Set thumb value
|
|
152
|
+
const setThumbValue = (newValue: number) => {
|
|
153
|
+
const clamped = Math.max(minValue(), Math.min(maxValue(), newValue));
|
|
154
|
+
const rounded = Math.round(clamped / step()) * step();
|
|
155
|
+
const newColor = value().withChannelValue(channel(), rounded);
|
|
156
|
+
updateValue(newColor);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Set thumb from percent
|
|
160
|
+
const setThumbPercent = (percent: number) => {
|
|
161
|
+
const min = minValue();
|
|
162
|
+
const max = maxValue();
|
|
163
|
+
const val = min + (max - min) * percent;
|
|
164
|
+
setThumbValue(val);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Increment
|
|
168
|
+
const incrementThumb = (stepSize?: number) => {
|
|
169
|
+
const s = stepSize ?? step();
|
|
170
|
+
setThumbValue(getThumbValue() + s);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// Decrement
|
|
174
|
+
const decrementThumb = (stepSize?: number) => {
|
|
175
|
+
const s = stepSize ?? step();
|
|
176
|
+
setThumbValue(getThumbValue() - s);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Set dragging
|
|
180
|
+
const setDraggingState = (dragging: boolean) => {
|
|
181
|
+
const wasDragging = isDragging();
|
|
182
|
+
setIsDragging(dragging);
|
|
183
|
+
|
|
184
|
+
// Call onChangeEnd when dragging ends
|
|
185
|
+
if (wasDragging && !dragging) {
|
|
186
|
+
getOptions().onChangeEnd?.(value());
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Get display color (alpha = 1)
|
|
191
|
+
const getDisplayColor = () => {
|
|
192
|
+
const v = value();
|
|
193
|
+
return v.withChannelValue('alpha', 1);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Get formatted value label
|
|
197
|
+
const getThumbValueLabel = () => {
|
|
198
|
+
const v = value();
|
|
199
|
+
const ch = channel();
|
|
200
|
+
const loc = locale();
|
|
201
|
+
return v.formatChannelValue(ch, loc);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
get value() {
|
|
206
|
+
return value();
|
|
207
|
+
},
|
|
208
|
+
get isDragging() {
|
|
209
|
+
return isDragging();
|
|
210
|
+
},
|
|
211
|
+
get channel() {
|
|
212
|
+
return channel();
|
|
213
|
+
},
|
|
214
|
+
get step() {
|
|
215
|
+
return step();
|
|
216
|
+
},
|
|
217
|
+
get pageSize() {
|
|
218
|
+
return pageSize();
|
|
219
|
+
},
|
|
220
|
+
get minValue() {
|
|
221
|
+
return minValue();
|
|
222
|
+
},
|
|
223
|
+
get maxValue() {
|
|
224
|
+
return maxValue();
|
|
225
|
+
},
|
|
226
|
+
get isDisabled() {
|
|
227
|
+
return isDisabled();
|
|
228
|
+
},
|
|
229
|
+
getThumbValue,
|
|
230
|
+
getThumbMinValue,
|
|
231
|
+
getThumbMaxValue,
|
|
232
|
+
getThumbPercent,
|
|
233
|
+
setThumbValue,
|
|
234
|
+
setThumbPercent,
|
|
235
|
+
incrementThumb,
|
|
236
|
+
decrementThumb,
|
|
237
|
+
setDragging: setDraggingState,
|
|
238
|
+
getDisplayColor,
|
|
239
|
+
getThumbValueLabel,
|
|
240
|
+
};
|
|
241
|
+
}
|