etudes 30.2.0 → 31.0.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/build/index.d.ts CHANGED
@@ -20,7 +20,6 @@ export * from './hooks/useDropzone.js';
20
20
  export * from './hooks/useImageLoader.js';
21
21
  export * from './hooks/useImageSize.js';
22
22
  export * from './hooks/useInertiaDrag.js';
23
- export * from './hooks/useInertiaDragValue.js';
24
23
  export * from './hooks/useIntersectionObserver.js';
25
24
  export * from './hooks/useInterval.js';
26
25
  export * from './hooks/useIsMounted.js';
@@ -1,5 +1,12 @@
1
1
  import { HTMLAttributes, Ref } from 'react';
2
2
  import { Size } from 'spase';
3
+ /**
4
+ * A component containing a pannable 360° panorama image.
5
+ */
6
+ export declare function Panorama({ ref, angle, speed, src, zeroAnchor, onAngleChange, onDragEnd, onDragStart, onImageSizeChange, onLoadImageComplete, onLoadImageError, onLoadImageStart, onPositionChange, ...props }: Panorama.Props): import("react/jsx-runtime").JSX.Element;
7
+ export declare namespace Panorama {
8
+ var displayName: string;
9
+ }
3
10
  export declare namespace Panorama {
4
11
  /**
5
12
  * Type describing the props of {@link Panorama}.
@@ -32,24 +39,17 @@ export declare namespace Panorama {
32
39
  */
33
40
  zeroAnchor?: number;
34
41
  /**
35
- * Handler invoked when the position changes. This can either be invoked
36
- * from the `angle` prop being changed or from the image being dragged.
42
+ * Handler invoked when the position changes.
37
43
  *
38
44
  * @param position The current position.
39
- * @param isDragging Specifies if the position change is due to dragging.
40
45
  */
41
- onPositionChange?: (position: number, isDragging: boolean) => void;
46
+ onPositionChange?: (position: number) => void;
42
47
  /**
43
- * Handler invoked when the angle changes. This can either be invoked from
44
- * the `angle` prop being changed or from the image being dragged. When
45
- * `angle` is being double-bound, ensure that the value is only being set by
46
- * this handler when `isDragging` is `true` to avoid potential update
47
- * overflow.
48
+ * Handler invoked when the angle changes.
48
49
  *
49
50
  * @param angle The current angle.
50
- * @param isDragging Specifies if the angle change is due to dragging.
51
51
  */
52
- onAngleChange?: (angle: number, isDragging: boolean) => void;
52
+ onAngleChange?: (angle: number) => void;
53
53
  /**
54
54
  * Handler invoked when dragging starts.
55
55
  */
@@ -74,17 +74,8 @@ export declare namespace Panorama {
74
74
  * Handler invoked when the image size changes. This is the actual size of
75
75
  * the loaded image. When no images are loaded yet, the size is `undefined`.
76
76
  *
77
- * @param size The actual size of the loaded image. If no images are loaded
78
- * yet, the size is `undefined`.
77
+ * @param size The actual size of the loaded image.
79
78
  */
80
79
  onImageSizeChange?: (size?: Size.Size) => void;
81
80
  } & Omit<HTMLAttributes<HTMLDivElement>, 'aria-valuenow' | 'role'>;
82
81
  }
83
- /**
84
- * A component containing a pannable 360° panorama image. The angle supports
85
- * two-way binding.
86
- */
87
- export declare function Panorama({ ref, angle: externalAngle, speed, src, zeroAnchor, onAngleChange, onDragEnd, onDragStart, onImageSizeChange, onLoadImageComplete, onLoadImageError, onLoadImageStart, onPositionChange, ...props }: Panorama.Props): import("react/jsx-runtime").JSX.Element;
88
- export declare namespace Panorama {
89
- var displayName: string;
90
- }
@@ -2,13 +2,13 @@ import { HTMLAttributes, Ref } from 'react';
2
2
  /**
3
3
  * A slider component that allows the user to select a range of values.
4
4
  *
5
- * @exports RangeSlider.Gutter Component for the gutter.
6
- * @exports RangeSlider.Highlight Component for the highlight.
7
5
  * @exports RangeSlider.Knob Component for the knob.
8
6
  * @exports RangeSlider.KnobContainer Component for the container of the knob.
9
7
  * @exports RangeSlider.Label Component for the label.
8
+ * @exports RangeSlider.Track Component for the track.
9
+ * @exports RangeSlider.TrackHighlight Component for the track highlight.
10
10
  */
11
- export declare function RangeSlider({ className, ref, children, decimalPlaces, knobHeight, knobPadding, knobWidth, max: maxValue, min: minValue, orientation, range: externalRange, steps, isClipped, onChange, ...props }: RangeSlider.Props): import("react/jsx-runtime").JSX.Element;
11
+ export declare function RangeSlider({ className, ref, children, knobHeight, knobPadding, knobWidth, max: maxValue, min: minValue, orientation, range, steps, isClipped, formatLabel, onChange, onDragEnd, onDragStart, ...props }: RangeSlider.Props): import("react/jsx-runtime").JSX.Element;
12
12
  export declare namespace RangeSlider {
13
13
  var displayName: string;
14
14
  }
@@ -29,10 +29,6 @@ export declare namespace RangeSlider {
29
29
  * Reference to the root element.
30
30
  */
31
31
  ref?: Ref<HTMLDivElement>;
32
- /**
33
- * Number of decimal places to display.
34
- */
35
- decimalPlaces?: number;
36
32
  /**
37
33
  * Specifies if the knobs are clipped to the track.
38
34
  */
@@ -73,23 +69,46 @@ export declare namespace RangeSlider {
73
69
  */
74
70
  steps?: number;
75
71
  /**
76
- * Handler invoked when the range of values changes.
72
+ * A function that formats the labels displayed on the knobs based on the
73
+ * selected values. If not provided, no label will be rendered.
74
+ *
75
+ * @param value The value of the side specified by `side`.
76
+ * @param side Specifies which side the label is for, either the 'start' or
77
+ * 'end' knob.
78
+ *
79
+ * @returns The formatted string.
80
+ */
81
+ formatLabel?: (value: number, side: 'end' | 'start') => string;
82
+ /**
83
+ * Handler invoked when the range of values changes due to dragging a knob.
84
+ * While dragging it is invoked repeatedly with `isDragging` set to `true`;
85
+ * when a knob is released it is invoked once more with the stepped range and
86
+ * `isDragging` set to `false`.
77
87
  *
78
88
  * @param range The current range of values.
89
+ * @param isDragging Specifies if the change is from an in-progress drag.
90
+ */
91
+ onChange?: (range: Range, isDragging: boolean) => void;
92
+ /**
93
+ * Handler invoked when dragging a knob ends.
94
+ */
95
+ onDragEnd?: () => void;
96
+ /**
97
+ * Handler invoked when dragging a knob begins.
79
98
  */
80
- onChange?: (range: Range) => void;
99
+ onDragStart?: () => void;
81
100
  } & Omit<HTMLAttributes<HTMLDivElement>, 'aria-valuemax' | 'aria-valuemin' | 'onChange' | 'role'>;
82
101
  /**
83
- * Component for the gutter of a {@link RangeSlider}.
102
+ * Component for the track of a {@link RangeSlider}.
84
103
  */
85
- const Gutter: {
104
+ const Track: {
86
105
  ({ ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
87
106
  displayName: string;
88
107
  };
89
108
  /**
90
- * Component for the highlight of a {@link RangeSlider}.
109
+ * Component for the track highlight of a {@link RangeSlider}.
91
110
  */
92
- const Highlight: {
111
+ const TrackHighlight: {
93
112
  ({ ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
94
113
  displayName: string;
95
114
  };
@@ -1,12 +1,11 @@
1
1
  import { HTMLAttributes, Ref } from 'react';
2
2
  /**
3
- * A slider component supporting both horizontal and vertical orientations whose
4
- * sliding position (a decimal between 0.0 and 1.0, inclusive) can be two-way
5
- * bound. The component consists of three customizable elements: a draggable
6
- * knob, a label on the knob, and a scroll track on either side of the knob.
7
- * While the width and height of the slider is inferred from its CSS rules, the
8
- * width and height of the knob are set via props (`knobWidth` and `knobHeight`,
9
- * respectively). The size of the knob does not impact the size of the slider.
3
+ * A slider component supporting both horizontal and vertical orientations. The
4
+ * component consists of three customizable elements: a draggable knob, a label
5
+ * on the knob, and a scroll track on either side of the knob. While the width
6
+ * and height of the slider is inferred from its CSS rules, the width and height
7
+ * of the knob are set via props (`knobWidth` and `knobHeight`, respectively).
8
+ * The size of the knob does not impact the size of the slider.
10
9
  *
11
10
  * @exports Slider.Knob Component for the knob.
12
11
  * @exports Slider.KnobContainer Component for the container of the knob.
@@ -14,7 +13,7 @@ import { HTMLAttributes, Ref } from 'react';
14
13
  * @exports Slider.Track Component for the slide track on either side of the
15
14
  * knob.
16
15
  */
17
- export declare function Slider({ className, ref, children, knobHeight, knobPadding, knobWidth, labelProvider, orientation, position: externalPosition, trackPadding, isClipped, isInverted, isTrackInteractive, shouldOnlyDispatchOnDragEnd, onChange, onDragEnd, onDragStart, ...props }: Readonly<Slider.Props>): import("react/jsx-runtime").JSX.Element;
16
+ export declare function Slider({ className, ref, children, knobHeight, knobPadding, knobWidth, orientation, position, trackPadding, isClipped, isInverted, isTrackInteractive, formatLabel, onChange, onDragEnd, onDragStart, ...props }: Readonly<Slider.Props>): import("react/jsx-runtime").JSX.Element;
18
17
  export declare namespace Slider {
19
18
  var displayName: string;
20
19
  }
@@ -45,12 +44,6 @@ export declare namespace Slider {
45
44
  * Specifies if the track is clickable to set the position of the knob.
46
45
  */
47
46
  isTrackInteractive?: boolean;
48
- /**
49
- * Indicates if position change events are dispatched only when dragging
50
- * ends. When disabled, aforementioned events are fired repeatedly while
51
- * dragging.
52
- */
53
- shouldOnlyDispatchOnDragEnd?: boolean;
54
47
  /**
55
48
  * Padding between the track and the knob in pixels.
56
49
  */
@@ -76,20 +69,16 @@ export declare namespace Slider {
76
69
  */
77
70
  position?: number;
78
71
  /**
79
- * A function that returns the label to be displayed at a given slider
80
- * position.
72
+ * A function that formats the position to be displayed as the slider label.
73
+ * If not provided, no label will be rendered.
81
74
  *
82
75
  * @param position The current slider position.
83
76
  *
84
- * @returns The label.
77
+ * @returns The formatted string.
85
78
  */
86
- labelProvider?: (position: number) => string;
79
+ formatLabel?: (position: number) => string;
87
80
  /**
88
- * Handler invoked when position changes. This can either be invoked from
89
- * the `position` prop being changed or from the slider being dragged. Note
90
- * that if the event is emitted at the end of dragging due to
91
- * `shouldOnlyDispatchOnDragEnd` set to `true`, the `isDragging` parameter
92
- * here is still `true`.
81
+ * Handler invoked when position changes.
93
82
  *
94
83
  * @param position The current slider position.
95
84
  * @param isDragging Specifies if the position change is due to dragging.
@@ -1,16 +1,16 @@
1
1
  import { HTMLAttributes, Ref } from 'react';
2
2
  /**
3
3
  * A "step" slider component supporting both horizontal and vertical
4
- * orientations that automatically snaps to a set of predefined points on the
5
- * slider when dragged. These points are referred to as "steps", indexed by an
6
- * integer referred to as "index". This index can be two-way bound. The
7
- * component consists of four customizable elements: a draggable knob, a label
8
- * on the knob, a scroll track before the knob and a scroll track after the
9
- * knob. While the width and height of the slider is inferred from its CSS
10
- * rules, the width and height of the knob are set via props (`knobWidth` and
11
- * `knobHeight`, respectively). The size of the knob does not impact the size of
12
- * the slider. While dragging, the slider still emits a position change event,
13
- * where the position is a decimal ranging between 0.0 and 1.0, inclusive.
4
+ * orientations that automatically whose knob snaps to a set of predefined
5
+ * points on the track upon drag release. These points are referred to as
6
+ * "steps", indexed by an integer referred to as "index". The index is
7
+ * controlled via the `index` prop; feed the value reported by `onIndexChange`
8
+ * back into it to persist changes. While the width and height of the slider is
9
+ * inferred from its CSS rules, the width and height of the knob are set via
10
+ * props (`knobWidth` and `knobHeight`, respectively). The size of the knob does
11
+ * not impact the size of the slider. While dragging, the slider still emits a
12
+ * position change event, where the position is a decimal ranging between 0.0
13
+ * and 1.0, inclusive.
14
14
  *
15
15
  * @exports StepSlider.Knob Component for the knob.
16
16
  * @exports StepSlider.KnobContainer Component for the container of the knob.
@@ -18,11 +18,10 @@ import { HTMLAttributes, Ref } from 'react';
18
18
  * @exports StepSlider.Track Component for the slide track on either side of the
19
19
  * knob.
20
20
  */
21
- export declare function StepSlider({ className, ref, children, index: externalIndex, knobHeight, knobPadding, knobWidth, labelProvider, orientation, steps, trackPadding, isClipped, isInverted, isTrackInteractive, shouldOnlyDispatchOnDragEnd, onDragEnd, onDragStart, onIndexChange, onPositionChange, ...props }: StepSlider.Props): import("react/jsx-runtime").JSX.Element;
21
+ export declare function StepSlider({ className, ref, children, index, knobHeight, knobPadding, knobWidth, orientation, steps, trackPadding, isClipped, isInverted, isTrackInteractive, formatLabel: labelProvider, onDragEnd, onDragStart, onIndexChange, onPositionChange, ...props }: StepSlider.Props): import("react/jsx-runtime").JSX.Element;
22
22
  export declare namespace StepSlider {
23
23
  var displayName: string;
24
24
  }
25
- declare function _generateSteps(length: number): readonly number[];
26
25
  export declare namespace StepSlider {
27
26
  /**
28
27
  * Type describing the orientation of {@link StepSlider}.
@@ -50,12 +49,6 @@ export declare namespace StepSlider {
50
49
  * Specifies if the track is clickable to set the position of the knob.
51
50
  */
52
51
  isTrackInteractive?: boolean;
53
- /**
54
- * Indicates if position/index change events are dispatched only when dragging
55
- * ends. When disabled, aforementioned events are fired repeatedly while
56
- * dragging.
57
- */
58
- shouldOnlyDispatchOnDragEnd?: boolean;
59
52
  /**
60
53
  * Padding between the track and the knob in pixels.
61
54
  */
@@ -97,37 +90,35 @@ export declare namespace StepSlider {
97
90
  *
98
91
  * @returns The label.
99
92
  */
100
- labelProvider?: (position: number, index: number) => string;
93
+ formatLabel?: (position: number, index: number) => string;
94
+ /**
95
+ * Handler invoked when dragging ends.
96
+ */
97
+ onDragEnd?: () => void;
98
+ /**
99
+ * Handler invoked when dragging begins.
100
+ */
101
+ onDragStart?: () => void;
101
102
  /**
102
- * Handler invoked when index changes. This can either be invoked from the
103
- * `index` prop being changed or from the slider being dragged. Note that if
104
- * the event is emitted at the end of dragging due to
105
- * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here
106
- * is still `true`. This event is emitted right after `onPositionChange`.
103
+ * Handler invoked when the nearest step index changes due to dragging or a
104
+ * track click. While dragging it is invoked with `isDragging` set to
105
+ * `true`; on release (after snapping) and on a track click it is invoked
106
+ * with `isDragging` set to `false`. Emitted right after `onPositionChange`.
107
107
  *
108
108
  * @param index The current slider index.
109
- * @param isDragging Specifies if the index change is due to dragging.
109
+ * @param isDragging Specifies if the change is from an in-progress drag.
110
110
  */
111
111
  onIndexChange?: (index: number, isDragging: boolean) => void;
112
112
  /**
113
- * Handler invoked when position changes. This can either be invoked from
114
- * the `index` prop being changed or from the slider being dragged. Note
115
- * that if the event is emitted at the end of dragging due to
116
- * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here
117
- * is still `true`. This event is emitted right before `onIndexChange`.
113
+ * Handler invoked when the continuous position changes due to dragging or a
114
+ * track click. While dragging it is invoked with `isDragging` set to
115
+ * `true`; on release (after snapping) and on a track click it is invoked
116
+ * with `isDragging` set to `false`. Emitted right before `onIndexChange`.
118
117
  *
119
118
  * @param position The current slider position.
120
- * @param isDragging Specifies if the position change is due to dragging.
119
+ * @param isDragging Specifies if the change is from an in-progress drag.
121
120
  */
122
121
  onPositionChange?: (position: number, isDragging: boolean) => void;
123
- /**
124
- * Handler invoked when dragging ends.
125
- */
126
- onDragEnd?: () => void;
127
- /**
128
- * Handler invoked when dragging begins.
129
- */
130
- onDragStart?: () => void;
131
122
  } & Omit<HTMLAttributes<HTMLDivElement>, 'aria-valuenow' | 'onChange' | 'role'>;
132
123
  /**
133
124
  * Component for the knob of a {@link StepSlider}.
@@ -167,4 +158,5 @@ export declare namespace StepSlider {
167
158
  */
168
159
  const generateSteps: typeof _generateSteps;
169
160
  }
161
+ declare function _generateSteps(length: number): readonly number[];
170
162
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "30.2.0",
3
+ "version": "31.0.0",
4
4
  "description": "A study of headless React components",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,56 +0,0 @@
1
- import { Dispatch, RefObject, SetStateAction } from 'react';
2
- import { useInertiaDrag } from './useInertiaDrag.js';
3
- /**
4
- * Type describing the output of {@link useInertiaDragValue}.
5
- */
6
- export type UseDragValueOutput<T = [number, number]> = {
7
- /**
8
- * Indicates whether the drag is currently happening.
9
- */
10
- isDragging: boolean;
11
- /**
12
- * Indicates whether the drag is currently being released.
13
- */
14
- isReleasing: boolean;
15
- /**
16
- * The current associated value of this hook.
17
- */
18
- value: T;
19
- /**
20
- * A function that sets the current associated value of this hook.
21
- *
22
- * @param value The new associated value.
23
- */
24
- setValue: Dispatch<SetStateAction<T>>;
25
- };
26
- /**
27
- * Type describing the options of {@link useInertiaDragValue}.
28
- */
29
- export type UseDragValueOptions<T = [number, number]> = {
30
- /**
31
- * The initial associated value of this hook.
32
- */
33
- initialValue: T;
34
- /**
35
- * A function that transforms the drag move delta values to the associated
36
- * value of this hook.
37
- *
38
- * @param currentValue The current associated value.
39
- * @param dx The displacement on the x-axis (in pixels) since the last emitted
40
- * drag move event.
41
- * @param dy The displacement on the y-axis (in pixels) since the last emitted
42
- * drag move event.
43
- *
44
- * @returns The transformed value.
45
- */
46
- transform: (currentValue: T, dx: number, dy: number) => T;
47
- } & Parameters<typeof useInertiaDrag>[1];
48
- /**
49
- * Hook for adding dragging interaction to an element.
50
- *
51
- * @param target The target element or reference to add drag interaction to.
52
- * @param options Additional options.
53
- *
54
- * @returns The states created for this effect.
55
- */
56
- export declare function useInertiaDragValue<T = [number, number]>(target: HTMLElement | null | RefObject<HTMLElement> | RefObject<HTMLElement | null> | RefObject<HTMLElement | undefined> | undefined, { initialValue, transform, onDragEnd, onDragMove, onDragStart, ...options }: UseDragValueOptions<T>): UseDragValueOutput<T>;