etudes 1.2.0 → 2.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/README.md +1 -1
- package/lib/Accordion.d.ts +80 -71
- package/lib/Accordion.js +173 -183
- package/lib/Accordion.js.map +1 -1
- package/lib/BurgerButton.d.ts +20 -7
- package/lib/BurgerButton.js +113 -20
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Conditional.d.ts +2 -3
- package/lib/Conditional.js +0 -1
- package/lib/Conditional.js.map +1 -1
- package/lib/DebugConsole.d.ts +14 -23
- package/lib/DebugConsole.js +86 -87
- package/lib/DebugConsole.js.map +1 -1
- package/lib/Dial.d.ts +53 -16
- package/lib/Dial.js +121 -35
- package/lib/Dial.js.map +1 -1
- package/lib/Dropdown.d.ts +68 -83
- package/lib/Dropdown.js +226 -161
- package/lib/Dropdown.js.map +1 -1
- package/lib/Each.d.ts +2 -2
- package/lib/Each.js.map +1 -1
- package/lib/ExtractChild.d.ts +5 -4
- package/lib/ExtractChild.js +13 -11
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +2 -2
- package/lib/ExtractChildren.js +7 -5
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/FlatSVG.d.ts +30 -25
- package/lib/FlatSVG.js +28 -37
- package/lib/FlatSVG.js.map +1 -1
- package/lib/List.d.ts +97 -54
- package/lib/List.js +124 -63
- package/lib/List.js.map +1 -1
- package/lib/MasonryGrid.d.ts +27 -15
- package/lib/MasonryGrid.js +163 -148
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Panorama.d.ts +100 -21
- package/lib/Panorama.js +45 -44
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +65 -23
- package/lib/PanoramaSlider.js +150 -45
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +29 -89
- package/lib/RangeSlider.js +272 -286
- package/lib/RangeSlider.js.map +1 -1
- package/lib/Repeat.d.ts +4 -3
- package/lib/Repeat.js +3 -2
- package/lib/Repeat.js.map +1 -1
- package/lib/RotatingGallery.d.ts +38 -36
- package/lib/RotatingGallery.js +47 -17
- package/lib/RotatingGallery.js.map +1 -1
- package/lib/SelectableButton.d.ts +13 -4
- package/lib/SelectableButton.js +3 -14
- package/lib/SelectableButton.js.map +1 -1
- package/lib/Slider.d.ts +103 -41
- package/lib/Slider.js +182 -82
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +146 -59
- package/lib/StepwiseSlider.js +248 -142
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/SwipeContainer.d.ts +13 -5
- package/lib/SwipeContainer.js +5 -15
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/TextField.js +5 -15
- package/lib/TextField.js.map +1 -1
- package/lib/Video.d.ts +30 -51
- package/lib/Video.js +77 -119
- package/lib/Video.js.map +1 -1
- package/lib/WithTooltip.d.ts +16 -18
- package/lib/WithTooltip.js +167 -101
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useDocumentTitle.d.ts +2 -1
- package/lib/hooks/useDocumentTitle.js +2 -1
- package/lib/hooks/useDocumentTitle.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +25 -16
- package/lib/hooks/useDragEffect.js +30 -20
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +2 -1
- package/lib/hooks/useElementRect.js +5 -4
- package/lib/hooks/useElementRect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +2 -2
- package/lib/hooks/useInterval.js +1 -1
- package/lib/hooks/useInterval.js.map +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +6 -6
- package/lib/hooks/useLoadImageEffect.js.map +1 -1
- package/lib/hooks/usePrevious.d.ts +6 -0
- package/lib/hooks/usePrevious.js +17 -0
- package/lib/hooks/usePrevious.js.map +1 -0
- package/lib/hooks/useResizeEffect.d.ts +2 -2
- package/lib/hooks/useResizeEffect.js +5 -8
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/lib/hooks/useSearchParamState.d.ts +10 -7
- package/lib/hooks/useSearchParamState.js +14 -10
- package/lib/hooks/useSearchParamState.js.map +1 -1
- package/lib/utils/asClassNameDict.d.ts +3 -0
- package/lib/utils/asClassNameDict.js +7 -0
- package/lib/utils/asClassNameDict.js.map +1 -0
- package/lib/utils/asComponentDict.d.ts +5 -0
- package/lib/utils/asComponentDict.js +23 -0
- package/lib/utils/asComponentDict.js.map +1 -0
- package/lib/utils/asStyleDict.d.ts +4 -0
- package/lib/utils/asStyleDict.js +7 -0
- package/lib/utils/asStyleDict.js.map +1 -0
- package/lib/utils/cloneStyledElement.d.ts +18 -0
- package/lib/utils/cloneStyledElement.js +63 -0
- package/lib/utils/cloneStyledElement.js.map +1 -0
- package/lib/utils/styles.d.ts +2 -0
- package/lib/utils/styles.js +22 -0
- package/lib/utils/styles.js.map +1 -0
- package/lib/utils/useDebug.d.ts +2 -0
- package/lib/utils/useDebug.js +46 -0
- package/lib/utils/useDebug.js.map +1 -0
- package/package.json +25 -33
- package/lib/AbstractSelectableCollection.d.ts +0 -94
- package/lib/AbstractSelectableCollection.js +0 -151
- package/lib/AbstractSelectableCollection.js.map +0 -1
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
package/lib/Slider.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
-
|
|
1
|
+
import React, { HTMLAttributes, PropsWithChildren } from 'react';
|
|
2
|
+
declare type Orientation = 'horizontal' | 'vertical';
|
|
3
|
+
export declare type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
|
|
3
4
|
/**
|
|
4
|
-
* By default the position is a value from 0 - 1, 0 being the start of the
|
|
5
|
-
* end. Switching on this flag inverts this behavior,
|
|
6
|
-
* being the start.
|
|
5
|
+
* By default the position is a value from 0 - 1, 0 being the start of the
|
|
6
|
+
* slider and 1 being the end. Switching on this flag inverts this behavior,
|
|
7
|
+
* where 0 becomes the end of the slider and 1 being the start.
|
|
7
8
|
*/
|
|
8
9
|
isInverted?: boolean;
|
|
9
10
|
/**
|
|
@@ -11,18 +12,10 @@ export declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
|
11
12
|
*/
|
|
12
13
|
isTrackInteractive?: boolean;
|
|
13
14
|
/**
|
|
14
|
-
* Indicates if position change events are dispatched only when dragging ends.
|
|
15
|
-
* aforementioned events are fired repeatedly while dragging.
|
|
15
|
+
* Indicates if position change events are dispatched only when dragging ends.
|
|
16
|
+
* When disabled, aforementioned events are fired repeatedly while dragging.
|
|
16
17
|
*/
|
|
17
18
|
onlyDispatchesOnDragEnd?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* A function that returns the label to be displayed at a given slider position.
|
|
20
|
-
*
|
|
21
|
-
* @param position - The current slider position.
|
|
22
|
-
*
|
|
23
|
-
* @returns The label.
|
|
24
|
-
*/
|
|
25
|
-
labelProvider?: (position: number) => string;
|
|
26
19
|
/**
|
|
27
20
|
* Padding between the track and the knob in pixels.
|
|
28
21
|
*/
|
|
@@ -38,15 +31,25 @@ export declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
|
38
31
|
/**
|
|
39
32
|
* Orientation of the slider.
|
|
40
33
|
*/
|
|
41
|
-
orientation?:
|
|
34
|
+
orientation?: Orientation;
|
|
42
35
|
/**
|
|
43
36
|
* The current position.
|
|
44
37
|
*/
|
|
45
38
|
position?: number;
|
|
46
39
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
40
|
+
* A function that returns the label to be displayed at a given slider
|
|
41
|
+
* position.
|
|
42
|
+
*
|
|
43
|
+
* @param position - The current slider position.
|
|
44
|
+
*
|
|
45
|
+
* @returns The label.
|
|
46
|
+
*/
|
|
47
|
+
labelProvider?: (position: number) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Handler invoked when position changes. This can either be invoked from the
|
|
50
|
+
* `position` prop being changed or from the slider being dragged. Note that
|
|
51
|
+
* if the event is emitted at the end of dragging due to
|
|
52
|
+
* `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
|
|
50
53
|
* still `true`.
|
|
51
54
|
*
|
|
52
55
|
* @param position - The current slider position.
|
|
@@ -61,30 +64,89 @@ export declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
|
61
64
|
* Handler invoked when dragging begins.
|
|
62
65
|
*/
|
|
63
66
|
onDragStart?: () => void;
|
|
64
|
-
}
|
|
67
|
+
}>;
|
|
65
68
|
/**
|
|
66
|
-
* A slider component supporting both horizontal and vertical orientations whose
|
|
67
|
-
* decimal between 0.0 and 1.0, inclusive) can be two-way
|
|
68
|
-
*
|
|
69
|
-
* a
|
|
70
|
-
*
|
|
69
|
+
* A slider component supporting both horizontal and vertical orientations whose
|
|
70
|
+
* sliding position (a decimal between 0.0 and 1.0, inclusive) can be two-way
|
|
71
|
+
* binded. The component consists of three customizable elements: a draggable
|
|
72
|
+
* knob, a label on the knob, and a scroll track on either side of the knob.
|
|
73
|
+
* While the width and height of the slider is inferred from its CSS rules, the
|
|
74
|
+
* width and height of the knob are set via props (`knobWidth` and `knobHeight`,
|
|
71
75
|
* respectively). The size of the knob does not impact the size of the slider.
|
|
72
76
|
*
|
|
73
77
|
* @exports SliderKnob - The component for the knob.
|
|
74
|
-
* @exports
|
|
75
|
-
* @exports
|
|
76
|
-
*
|
|
78
|
+
* @exports SliderLabel - The component for the label on the knob.
|
|
79
|
+
* @exports SliderTrack - The component for the slide track on either side of
|
|
80
|
+
* the knob.
|
|
77
81
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
83
|
+
/**
|
|
84
|
+
* By default the position is a value from 0 - 1, 0 being the start of the
|
|
85
|
+
* slider and 1 being the end. Switching on this flag inverts this behavior,
|
|
86
|
+
* where 0 becomes the end of the slider and 1 being the start.
|
|
87
|
+
*/
|
|
88
|
+
isInverted?: boolean | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Specifies if the track is clickable to set the position of the knob.
|
|
91
|
+
*/
|
|
92
|
+
isTrackInteractive?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Indicates if position change events are dispatched only when dragging ends.
|
|
95
|
+
* When disabled, aforementioned events are fired repeatedly while dragging.
|
|
96
|
+
*/
|
|
97
|
+
onlyDispatchesOnDragEnd?: boolean | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Padding between the track and the knob in pixels.
|
|
100
|
+
*/
|
|
101
|
+
trackPadding?: number | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Height of the knob in pixels.
|
|
104
|
+
*/
|
|
105
|
+
knobHeight?: number | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Width of the knob in pixels.
|
|
108
|
+
*/
|
|
109
|
+
knobWidth?: number | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Orientation of the slider.
|
|
112
|
+
*/
|
|
113
|
+
orientation?: Orientation | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* The current position.
|
|
116
|
+
*/
|
|
117
|
+
position?: number | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* A function that returns the label to be displayed at a given slider
|
|
120
|
+
* position.
|
|
121
|
+
*
|
|
122
|
+
* @param position - The current slider position.
|
|
123
|
+
*
|
|
124
|
+
* @returns The label.
|
|
125
|
+
*/
|
|
126
|
+
labelProvider?: ((position: number) => string) | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Handler invoked when position changes. This can either be invoked from the
|
|
129
|
+
* `position` prop being changed or from the slider being dragged. Note that
|
|
130
|
+
* if the event is emitted at the end of dragging due to
|
|
131
|
+
* `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is
|
|
132
|
+
* still `true`.
|
|
133
|
+
*
|
|
134
|
+
* @param position - The current slider position.
|
|
135
|
+
* @param isDragging - Specifies if the position change is due to dragging.
|
|
136
|
+
*/
|
|
137
|
+
onPositionChange?: ((position: number, isDragging: boolean) => void) | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Handler invoked when dragging ends.
|
|
140
|
+
*/
|
|
141
|
+
onDragEnd?: (() => void) | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Handler invoked when dragging begins.
|
|
144
|
+
*/
|
|
145
|
+
onDragStart?: (() => void) | undefined;
|
|
146
|
+
} & {
|
|
147
|
+
children?: React.ReactNode;
|
|
148
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
149
|
+
export default _default;
|
|
150
|
+
export declare const SliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
|
|
151
|
+
export declare const SliderKnob: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
|
|
152
|
+
export declare const SliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
|
package/lib/Slider.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
2
|
var __assign = (this && this.__assign) || function () {
|
|
7
3
|
__assign = Object.assign || function(t) {
|
|
8
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -68,73 +64,80 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
68
64
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
69
65
|
};
|
|
70
66
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
-
exports.
|
|
67
|
+
exports.SliderLabel = exports.SliderKnob = exports.SliderTrack = void 0;
|
|
72
68
|
var classnames_1 = __importDefault(require("classnames"));
|
|
73
69
|
var react_1 = __importStar(require("react"));
|
|
74
70
|
var spase_1 = require("spase");
|
|
75
|
-
var styled_components_1 = __importStar(require("styled-components"));
|
|
76
71
|
var useDragEffect_1 = __importDefault(require("./hooks/useDragEffect"));
|
|
77
|
-
var
|
|
72
|
+
var asClassNameDict_1 = __importDefault(require("./utils/asClassNameDict"));
|
|
73
|
+
var asComponentDict_1 = __importDefault(require("./utils/asComponentDict"));
|
|
74
|
+
var asStyleDict_1 = __importDefault(require("./utils/asStyleDict"));
|
|
75
|
+
var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
|
|
76
|
+
var styles_1 = __importDefault(require("./utils/styles"));
|
|
78
77
|
/**
|
|
79
|
-
* A slider component supporting both horizontal and vertical orientations whose
|
|
80
|
-
* decimal between 0.0 and 1.0, inclusive) can be two-way
|
|
81
|
-
*
|
|
82
|
-
* a
|
|
83
|
-
*
|
|
78
|
+
* A slider component supporting both horizontal and vertical orientations whose
|
|
79
|
+
* sliding position (a decimal between 0.0 and 1.0, inclusive) can be two-way
|
|
80
|
+
* binded. The component consists of three customizable elements: a draggable
|
|
81
|
+
* knob, a label on the knob, and a scroll track on either side of the knob.
|
|
82
|
+
* While the width and height of the slider is inferred from its CSS rules, the
|
|
83
|
+
* width and height of the knob are set via props (`knobWidth` and `knobHeight`,
|
|
84
84
|
* respectively). The size of the knob does not impact the size of the slider.
|
|
85
85
|
*
|
|
86
86
|
* @exports SliderKnob - The component for the knob.
|
|
87
|
-
* @exports
|
|
88
|
-
* @exports
|
|
89
|
-
*
|
|
87
|
+
* @exports SliderLabel - The component for the label on the knob.
|
|
88
|
+
* @exports SliderTrack - The component for the slide track on either side of
|
|
89
|
+
* the knob.
|
|
90
90
|
*/
|
|
91
|
-
function
|
|
92
|
-
var _b
|
|
93
|
-
var
|
|
91
|
+
exports.default = (0, react_1.forwardRef)(function (_a, ref) {
|
|
92
|
+
var _b, _c, _d, _e;
|
|
93
|
+
var children = _a.children, className = _a.className, _f = _a.isInverted, isInverted = _f === void 0 ? false : _f, _g = _a.isTrackInteractive, isTrackInteractive = _g === void 0 ? true : _g, _h = _a.knobHeight, knobHeight = _h === void 0 ? 30 : _h, _j = _a.knobWidth, knobWidth = _j === void 0 ? 30 : _j, labelProvider = _a.labelProvider, _k = _a.onlyDispatchesOnDragEnd, onlyDispatchesOnDragEnd = _k === void 0 ? false : _k, _l = _a.orientation, orientation = _l === void 0 ? 'vertical' : _l, _m = _a.position, externalPosition = _m === void 0 ? 0 : _m, _o = _a.trackPadding, trackPadding = _o === void 0 ? 0 : _o, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, onPositionChange = _a.onPositionChange, props = __rest(_a, ["children", "className", "isInverted", "isTrackInteractive", "knobHeight", "knobWidth", "labelProvider", "onlyDispatchesOnDragEnd", "orientation", "position", "trackPadding", "onDragEnd", "onDragStart", "onPositionChange"]);
|
|
94
|
+
var mapDragValueToPosition = function (value, dx, dy) {
|
|
94
95
|
var _a;
|
|
95
|
-
var rect = (_a = spase_1.Rect.from(
|
|
96
|
-
var
|
|
97
|
-
var
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
return
|
|
96
|
+
var rect = (_a = spase_1.Rect.from(bodyRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
|
|
97
|
+
var truePosition = isInverted ? 1 - value : value;
|
|
98
|
+
var trueNewPositionX = truePosition * rect.width + dx;
|
|
99
|
+
var trueNewPositionY = truePosition * rect.height + dy;
|
|
100
|
+
var trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width));
|
|
101
|
+
var normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition;
|
|
102
|
+
return normalizedPosition;
|
|
102
103
|
};
|
|
103
|
-
var
|
|
104
|
+
var trackClickHandler = function (event) {
|
|
104
105
|
var _a;
|
|
105
106
|
if (!isTrackInteractive)
|
|
106
107
|
return;
|
|
107
|
-
var rect = (_a = spase_1.Rect.from(
|
|
108
|
+
var rect = (_a = spase_1.Rect.from(bodyRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
|
|
108
109
|
switch (orientation) {
|
|
109
110
|
case 'horizontal': {
|
|
110
|
-
var
|
|
111
|
-
var
|
|
112
|
-
setPosition(
|
|
111
|
+
var trackPosition = (event.clientX - rect.left) / rect.width;
|
|
112
|
+
var normalizedPosition = isInverted ? 1 - trackPosition : trackPosition;
|
|
113
|
+
setPosition(normalizedPosition);
|
|
113
114
|
break;
|
|
114
115
|
}
|
|
115
116
|
case 'vertical': {
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
setPosition(
|
|
117
|
+
var trackPosition = (event.clientY - rect.top) / rect.height;
|
|
118
|
+
var normalizedPosition = isInverted ? 1 - trackPosition : trackPosition;
|
|
119
|
+
setPosition(normalizedPosition);
|
|
119
120
|
break;
|
|
120
121
|
}
|
|
122
|
+
default: break;
|
|
121
123
|
}
|
|
122
124
|
};
|
|
123
|
-
var
|
|
124
|
-
var
|
|
125
|
-
var
|
|
125
|
+
var bodyRef = (0, react_1.useRef)(null);
|
|
126
|
+
var knobContainerRef = (0, react_1.useRef)(null);
|
|
127
|
+
var _p = (0, useDragEffect_1.default)(knobContainerRef, {
|
|
126
128
|
initialValue: externalPosition,
|
|
127
|
-
transform:
|
|
129
|
+
transform: mapDragValueToPosition,
|
|
128
130
|
onDragStart: onDragStart,
|
|
129
131
|
onDragEnd: onDragEnd,
|
|
130
|
-
}),
|
|
131
|
-
//
|
|
132
|
-
//
|
|
132
|
+
}), _q = __read(_p.isDragging, 1), isDragging = _q[0], _r = __read(_p.isReleasing, 1), isReleasing = _r[0], _s = __read(_p.value, 2), position = _s[0], setPosition = _s[1];
|
|
133
|
+
// Natural position is the position affecting internal components accounting
|
|
134
|
+
// for `isInverted`.
|
|
133
135
|
var naturalPosition = isInverted ? 1 - position : position;
|
|
136
|
+
var isAtEnd = isInverted ? position === 0 : position === 1;
|
|
137
|
+
var isAtStart = isInverted ? position === 1 : position === 0;
|
|
134
138
|
(0, react_1.useEffect)(function () {
|
|
135
139
|
if (isDragging || externalPosition === position)
|
|
136
140
|
return;
|
|
137
|
-
debug('Updating drag effect value from position prop...', 'OK', "prop=".concat(externalPosition, ", effect=").concat(position));
|
|
138
141
|
setPosition(externalPosition);
|
|
139
142
|
}, [externalPosition]);
|
|
140
143
|
(0, react_1.useEffect)(function () {
|
|
@@ -147,45 +150,142 @@ function Slider(_a) {
|
|
|
147
150
|
return;
|
|
148
151
|
onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange(position, true);
|
|
149
152
|
}, [isDragging]);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
153
|
+
var components = (0, asComponentDict_1.default)(children, {
|
|
154
|
+
knob: exports.SliderKnob,
|
|
155
|
+
label: exports.SliderLabel,
|
|
156
|
+
track: exports.SliderTrack,
|
|
157
|
+
});
|
|
158
|
+
var fixedClassNames = (0, asClassNameDict_1.default)({
|
|
159
|
+
root: (0, classnames_1.default)(orientation, {
|
|
160
|
+
'at-end': isAtEnd,
|
|
161
|
+
'at-start': isAtStart,
|
|
162
|
+
'dragging': isDragging,
|
|
163
|
+
'releasing': isReleasing,
|
|
164
|
+
}),
|
|
165
|
+
track: (0, classnames_1.default)(orientation, {
|
|
166
|
+
'at-end': isAtEnd,
|
|
167
|
+
'at-start': isAtStart,
|
|
168
|
+
'dragging': isDragging,
|
|
169
|
+
'releasing': isReleasing,
|
|
170
|
+
}),
|
|
171
|
+
knob: (0, classnames_1.default)(orientation, {
|
|
172
|
+
'at-end': isAtEnd,
|
|
173
|
+
'at-start': isAtStart,
|
|
174
|
+
'dragging': isDragging,
|
|
175
|
+
'releasing': isReleasing,
|
|
176
|
+
}),
|
|
177
|
+
label: (0, classnames_1.default)(orientation, {
|
|
178
|
+
'at-end': isAtEnd,
|
|
179
|
+
'at-start': isAtStart,
|
|
180
|
+
'dragging': isDragging,
|
|
181
|
+
'releasing': isReleasing,
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
var fixedStyles = (0, asStyleDict_1.default)({
|
|
185
|
+
body: {
|
|
186
|
+
height: '100%',
|
|
187
|
+
width: '100%',
|
|
188
|
+
},
|
|
189
|
+
knobContainer: __assign({ background: 'none', border: 'none', outline: 'none', position: 'absolute', transform: 'translate3d(-50%, -50%, 0)', zIndex: '1' }, orientation === 'vertical' ? {
|
|
190
|
+
left: '50%',
|
|
191
|
+
top: "".concat(naturalPosition * 100, "%"),
|
|
192
|
+
transition: isDragging === false ? 'top 100ms ease-out' : 'none',
|
|
193
|
+
} : {
|
|
194
|
+
left: "".concat(naturalPosition * 100, "%"),
|
|
195
|
+
top: '50%',
|
|
196
|
+
transition: isDragging === false ? 'left 100ms ease-out' : 'none',
|
|
197
|
+
}),
|
|
198
|
+
knob: {
|
|
199
|
+
height: "".concat(knobHeight, "px"),
|
|
200
|
+
touchAction: 'none',
|
|
201
|
+
width: "".concat(knobWidth, "px"),
|
|
202
|
+
},
|
|
203
|
+
label: {
|
|
204
|
+
pointerEvents: 'none',
|
|
205
|
+
userSelect: 'none',
|
|
206
|
+
},
|
|
207
|
+
track: __assign({ cursor: isTrackInteractive ? 'pointer' : 'auto', pointerEvents: isTrackInteractive ? 'auto' : 'none', position: 'absolute' }, orientation === 'vertical' ? {
|
|
208
|
+
left: '0',
|
|
209
|
+
margin: '0 auto',
|
|
210
|
+
right: '0',
|
|
211
|
+
width: '100%',
|
|
212
|
+
} : {
|
|
213
|
+
bottom: '0',
|
|
214
|
+
height: '100%',
|
|
215
|
+
margin: 'auto 0',
|
|
216
|
+
top: '0',
|
|
217
|
+
}),
|
|
218
|
+
trackHitbox: {
|
|
219
|
+
height: '100%',
|
|
220
|
+
minHeight: '20px',
|
|
221
|
+
minWidth: '20px',
|
|
222
|
+
position: 'absolute',
|
|
223
|
+
transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',
|
|
224
|
+
width: '100%',
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
var defaultStyles = (0, asStyleDict_1.default)({
|
|
228
|
+
knob: {
|
|
229
|
+
alignItems: 'center',
|
|
230
|
+
background: '#fff',
|
|
231
|
+
boxSizing: 'border-box',
|
|
232
|
+
display: 'flex',
|
|
233
|
+
justifyContent: 'center',
|
|
234
|
+
},
|
|
235
|
+
label: {
|
|
236
|
+
color: '#000',
|
|
237
|
+
fontSize: '12px',
|
|
238
|
+
lineHeight: "".concat(knobHeight, "px"),
|
|
239
|
+
},
|
|
240
|
+
track: {
|
|
241
|
+
background: '#fff',
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
return (react_1.default.createElement("div", __assign({}, props, { ref: ref, className: (0, classnames_1.default)(className, fixedClassNames.root) }),
|
|
245
|
+
react_1.default.createElement("div", { ref: bodyRef, style: fixedStyles.body },
|
|
246
|
+
(0, cloneStyledElement_1.default)((_b = components.track) !== null && _b !== void 0 ? _b : react_1.default.createElement(exports.SliderTrack, { style: defaultStyles.track }), {
|
|
247
|
+
className: (0, classnames_1.default)('start', fixedClassNames.track),
|
|
248
|
+
style: (0, styles_1.default)(fixedStyles.track, orientation === 'vertical' ? {
|
|
249
|
+
height: "calc(".concat(naturalPosition * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobHeight * 0.5, "px - ").concat(trackPadding, "px)"),
|
|
250
|
+
top: '0',
|
|
251
|
+
} : {
|
|
252
|
+
left: '0',
|
|
253
|
+
width: "calc(".concat(naturalPosition * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobWidth * 0.5, "px - ").concat(trackPadding, "px)"),
|
|
254
|
+
}),
|
|
255
|
+
onClick: trackClickHandler,
|
|
256
|
+
}, react_1.default.createElement("div", { style: fixedStyles.trackHitbox })),
|
|
257
|
+
(0, cloneStyledElement_1.default)((_c = components.track) !== null && _c !== void 0 ? _c : react_1.default.createElement(exports.SliderTrack, { style: defaultStyles.track }), {
|
|
258
|
+
className: (0, classnames_1.default)('end', fixedClassNames.track),
|
|
259
|
+
style: (0, styles_1.default)(fixedStyles.track, orientation === 'vertical' ? {
|
|
260
|
+
bottom: '0',
|
|
261
|
+
height: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobHeight * 0.5, "px - ").concat(trackPadding, "px)"),
|
|
262
|
+
} : {
|
|
263
|
+
right: '0',
|
|
264
|
+
width: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(trackPadding <= 0 ? 0 : knobWidth * 0.5, "px - ").concat(trackPadding, "px)"),
|
|
265
|
+
}),
|
|
266
|
+
onClick: trackClickHandler,
|
|
267
|
+
}, react_1.default.createElement("div", { style: fixedStyles.trackHitbox })),
|
|
268
|
+
react_1.default.createElement("button", { ref: knobContainerRef, style: fixedStyles.knobContainer }, (0, cloneStyledElement_1.default)((_d = components.knob) !== null && _d !== void 0 ? _d : react_1.default.createElement(exports.SliderKnob, { style: defaultStyles.knob }), {
|
|
269
|
+
className: (0, classnames_1.default)(fixedClassNames.knob),
|
|
270
|
+
style: (0, styles_1.default)(fixedStyles.knob),
|
|
271
|
+
}, labelProvider && (0, cloneStyledElement_1.default)((_e = components.label) !== null && _e !== void 0 ? _e : react_1.default.createElement(exports.SliderLabel, { style: defaultStyles.label }), {
|
|
272
|
+
className: (0, classnames_1.default)(fixedClassNames.label),
|
|
273
|
+
style: (0, styles_1.default)(fixedStyles.label),
|
|
274
|
+
}, labelProvider(position)))))));
|
|
275
|
+
});
|
|
276
|
+
var SliderTrack = function (_a) {
|
|
277
|
+
var props = __rest(_a, []);
|
|
278
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
279
|
+
};
|
|
280
|
+
exports.SliderTrack = SliderTrack;
|
|
281
|
+
var SliderKnob = function (_a) {
|
|
282
|
+
var props = __rest(_a, []);
|
|
283
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
284
|
+
};
|
|
285
|
+
exports.SliderKnob = SliderKnob;
|
|
286
|
+
var SliderLabel = function (_a) {
|
|
287
|
+
var props = __rest(_a, []);
|
|
288
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
289
|
+
};
|
|
290
|
+
exports.SliderLabel = SliderLabel;
|
|
191
291
|
//# sourceMappingURL=Slider.js.map
|
package/lib/Slider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.js","sourceRoot":"/","sources":["Slider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA4E;AAC5E,+BAA4B;AAC5B,qEAA+C;AAC/C,wEAAiD;AAEjD,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,cAAO,CAAC,CAAA;AA6EnG;;;;;;;;;;;;GAYG;AACH,SAAwB,MAAM,CAAC,EAcvB;IAbN,IAA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,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,+KAE3B,4DAGU,EAA2D,qCAE5D,EAA2D,KACrE,KAHW,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAlD,CAAkD,EAE5D,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAlD,CAAkD,CACrE,CAAA","sourcesContent":["import classNames from 'classnames'\nimport React, { HTMLAttributes, MouseEvent, useEffect, useRef } from 'react'\nimport { Rect } from 'spase'\nimport styled, { css } from 'styled-components'\nimport useDragEffect from './hooks/useDragEffect'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:slider') : () => {}\n\nexport type Props = HTMLAttributes<HTMLDivElement> & {\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the slider and 1 being the\n * end. Switching on this flag inverts this behavior, where 0 becomes the end of the slider and 1\n * being the start.\n */\n isInverted?: boolean\n\n /**\n * Specifies if the track is clickable to set the position of the knob.\n */\n isTrackInteractive?: boolean\n\n /**\n * Indicates if position change events are dispatched only when dragging ends. When disabled,\n * aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * A function that returns the label to be displayed at a given slider position.\n *\n * @param position - The current slider position.\n *\n * @returns The label.\n */\n labelProvider?: (position: number) => string\n\n /**\n * Padding between the track and the knob in pixels.\n */\n trackPadding?: number\n\n /**\n * Height of the knob in pixels.\n */\n knobHeight?: number\n\n /**\n * Width of the knob in pixels.\n */\n knobWidth?: number\n\n /**\n * Orientation of the slider.\n */\n orientation?: 'horizontal' | 'vertical'\n\n /**\n * The current position.\n */\n position?: number\n\n /**\n * Handler invoked when position changes. This can either be invoked from the `position` prop\n * being changed or from the slider being dragged. Note that if the event is emitted at the end of\n * dragging due to `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`.\n *\n * @param position - The current slider position.\n * @param isDragging - Specifies if the position change is due to dragging.\n */\n onPositionChange?: (position: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * Handler invoked when dragging begins.\n */\n onDragStart?: () => void\n}\n\n/**\n * A slider component supporting both horizontal and vertical orientations whose sliding position (a\n * decimal between 0.0 and 1.0, inclusive) can be two-way binded. The component consists of four\n * customizable elements: a draggable knob, a label on the knob, a scroll track before the knob and\n * a scroll track after the knob. While the width and height of the slider is inferred from its CSS\n * rules, the width and height of the knob are set via props (`knobWidth` and `knobHeight`,\n * respectively). The size of the knob does not impact the size of the slider.\n *\n * @exports SliderKnob - The component for the knob.\n * @exports SliderKnobLabel - The component for the label on the knob.\n * @exports SliderStartingTrack - The component for the slide track before the knob.\n * @exports SliderEndingTrack - The component for the slide track after the knob.\n */\nexport default function Slider({\n isInverted = false,\n isTrackInteractive = true,\n onlyDispatchesOnDragEnd = false,\n trackPadding = 0,\n knobHeight = 30,\n knobWidth = 30,\n orientation = 'vertical',\n position: externalPosition = 0,\n labelProvider,\n onDragEnd,\n onDragStart,\n onPositionChange,\n ...props\n}: Props) {\n const mapDragPositionToSliderPosition = (currentPosition: number, dx: number, dy: number): number => {\n const rect = Rect.from(rootRef.current) ?? new Rect()\n const naturalPosition = isInverted ? 1 - currentPosition : currentPosition\n const naturalNewPositionX = naturalPosition * rect.width + dx\n const naturalNewPositionY = naturalPosition * rect.height + dy\n const naturalNewPosition = (orientation === 'vertical') ? Math.max(0, Math.min(1, naturalNewPositionY / rect.height)) : Math.max(0, Math.min(1, naturalNewPositionX / rect.width))\n const newPosition = isInverted ? 1 - naturalNewPosition : naturalNewPosition\n return newPosition\n }\n\n const onTrackClick = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(rootRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const position = (event.clientX - rect.left) / rect.width\n const naturalPosition = isInverted ? 1 - position : position\n setPosition(naturalPosition)\n break\n }\n case 'vertical': {\n const position = (event.clientY - rect.top) / rect.height\n const naturalPosition = isInverted ? 1 - position : position\n setPosition(naturalPosition)\n break\n }\n }\n }\n\n const rootRef = useRef<HTMLDivElement>(null)\n const knobRef = useRef<HTMLButtonElement>(null)\n\n const { isDragging: [isDragging], value: [position, setPosition] } = useDragEffect(knobRef, {\n initialValue: externalPosition,\n transform: mapDragPositionToSliderPosition,\n onDragStart,\n onDragEnd,\n })\n\n // debug('Rendering...', 'OK')\n\n // Natural position is the position after taking `isInverted` into account.\n const naturalPosition = isInverted ? 1 - position : position\n\n useEffect(() => {\n if (isDragging || externalPosition === position) return\n\n debug('Updating drag effect value from position prop...', 'OK', `prop=${externalPosition}, effect=${position}`)\n\n setPosition(externalPosition)\n }, [externalPosition])\n\n useEffect(() => {\n if (isDragging && onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, isDragging)\n }, [position])\n\n useEffect(() => {\n if (isDragging || !onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, true)\n }, [isDragging])\n\n return (\n <StyledRoot {...props} ref={rootRef} orientation={orientation}>\n <SliderStartingTrack orientation={orientation} isClickable={isTrackInteractive} onClick={event => onTrackClick(event)}\n style={orientation === 'vertical' ? {\n top: 0,\n height: `calc(${naturalPosition*100}% - ${trackPadding <= 0 ? 0 : knobHeight*.5}px - ${trackPadding}px)`,\n } : {\n left: 0,\n width: `calc(${naturalPosition*100}% - ${trackPadding <= 0 ? 0 : knobWidth*.5}px - ${trackPadding}px)`,\n }}\n />\n <StyledKnobContainer ref={knobRef} style={{\n transform: 'translate3d(-50%, -50%, 0)',\n ...(orientation === 'vertical' ? {\n left: '50%',\n top: `${naturalPosition*100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${naturalPosition*100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n }),\n }}>\n <SliderKnob\n className={classNames({\n 'at-end': isInverted ? (position === 0) : (position === 1),\n 'at-start': isInverted ? (position === 1) : (position === 0),\n 'dragging': isDragging === true,\n })}\n style={{\n height: `${knobHeight}px`,\n width: `${knobWidth}px`,\n }}\n >\n {labelProvider && (\n <SliderKnobLabel knobHeight={knobHeight}>{labelProvider(position)}</SliderKnobLabel>\n )}\n </SliderKnob>\n </StyledKnobContainer>\n <SliderEndingTrack orientation={orientation} isClickable={isTrackInteractive} onClick={event => onTrackClick(event)}\n style={orientation === 'vertical' ? {\n bottom: 0,\n height: `calc(${(1 - naturalPosition)*100}% - ${trackPadding <= 0 ? 0 : knobHeight*.5}px - ${trackPadding}px)`,\n } : {\n right: 0,\n width: `calc(${(1 - naturalPosition)*100}% - ${trackPadding <= 0 ? 0 : knobWidth*.5}px - ${trackPadding}px)`,\n }}\n />\n </StyledRoot>\n )\n}\n\nexport const SliderStartingTrack = styled.div<{\n orientation: NonNullable<Props['orientation']>\n isClickable: boolean\n}>`\n background: #fff;\n cursor: ${props => props.isClickable ? 'pointer' : 'auto' };\n pointer-events: ${props => props.isClickable ? 'auto' : 'none' };\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ${props => props.orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)'};\n width: 100%;\n }\n\n ${props => props.orientation === 'vertical' ? css`\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n ` : css`\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n `}\n`\n\nexport const SliderEndingTrack = styled.div<{\n orientation: NonNullable<Props['orientation']>\n isClickable: boolean\n}>`\n background: #fff;\n cursor: ${props => props.isClickable ? 'pointer' : 'auto' };\n pointer-events: ${props => props.isClickable ? 'auto' : 'none' };;\n position: absolute;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &::after {\n content: '';\n height: 100%;\n min-height: 20px;\n min-width: 20px;\n position: absolute;\n transform: ${props => props.orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)'};\n width: 100%;\n }\n\n ${props => props.orientation === 'vertical' ? css`\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n ` : css`\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n `}\n`\n\nexport const SliderKnob = styled.div`\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n justify-content: center;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n`\n\nexport const SliderKnobLabel = styled.label<{ knobHeight: NonNullable<Props['knobHeight']> }>`\n color: #000;\n font-size: ${props => props.knobHeight * .5}px;\n pointer-events: none;\n user-select: none;\n`\n\nconst StyledKnobContainer = styled.button`\n position: absolute;\n z-index: 1;\n`\n\nconst StyledRoot = styled.div<{\n orientation: Props['orientation']\n}>`\n box-sizing: border-box;\n display: block;\n height: ${props => props.orientation === 'vertical' ? '300px' : '4px'};\n position: relative;\n width: ${props => props.orientation === 'vertical' ? '4px' : '300px'};\n`\n"]}
|
|
1
|
+
{"version":3,"file":"Slider.js","sourceRoot":"/","sources":["Slider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA2G;AAC3G,+BAA4B;AAC5B,wEAAiD;AACjD,4EAAqD;AACrD,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAiFnC;;;;;;;;;;;;;GAaG;AACH,kBAAe,IAAA,kBAAU,EAA8B,UAAC,EAgBvD,EAAE,GAAG;;IAfJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,kBAAkB,EAAlB,UAAU,mBA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C5C,KAAK,EAAE,IAAA,gBAAM,EAAC,WAAW,CAAC,KAAK,CAAC;aACjC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CACrB,CACL,CACF,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEK,IAAM,WAAW,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAjF,QAAA,WAAW,eAAsE;AAEvF,IAAM,UAAU,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAhF,QAAA,UAAU,cAAsE;AAEtF,IAAM,WAAW,GAAG,UAAC,EAA4C;QAAvC,KAAK,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAjF,QAAA,WAAW,eAAsE","sourcesContent":["import classNames from 'classnames'\nimport React, { forwardRef, HTMLAttributes, MouseEvent, PropsWithChildren, useEffect, useRef } from 'react'\nimport { Rect } from 'spase'\nimport useDragEffect from './hooks/useDragEffect'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * By default the position is a value from 0 - 1, 0 being the start of the\n * slider and 1 being the end. Switching on this flag inverts this behavior,\n * where 0 becomes the end of the slider and 1 being the start.\n */\n isInverted?: boolean\n\n /**\n * Specifies if the track is clickable to set the position of the knob.\n */\n isTrackInteractive?: boolean\n\n /**\n * Indicates if position change events are dispatched only when dragging ends.\n * When disabled, aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Padding between the track and the knob in pixels.\n */\n trackPadding?: number\n\n /**\n * Height of the knob in pixels.\n */\n knobHeight?: number\n\n /**\n * Width of the knob in pixels.\n */\n knobWidth?: number\n\n /**\n * Orientation of the slider.\n */\n orientation?: Orientation\n\n /**\n * The current position.\n */\n position?: number\n\n /**\n * A function that returns the label to be displayed at a given slider\n * position.\n *\n * @param position - The current slider position.\n *\n * @returns The label.\n */\n labelProvider?: (position: number) => string\n\n /**\n * Handler invoked when position changes. This can either be invoked from the\n * `position` prop being changed or from the slider being dragged. Note that\n * if the event is emitted at the end of dragging due to\n * `onlyDispatchesOnDragEnd` set to `true`, the `isDragging` parameter here is\n * still `true`.\n *\n * @param position - The current slider position.\n * @param isDragging - Specifies if the position change is due to dragging.\n */\n onPositionChange?: (position: number, isDragging: boolean) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * Handler invoked when dragging begins.\n */\n onDragStart?: () => void\n}>\n\n/**\n * A slider component supporting both horizontal and vertical orientations whose\n * sliding position (a decimal between 0.0 and 1.0, inclusive) can be two-way\n * binded. The component consists of three customizable elements: a draggable\n * knob, a label on the knob, and a scroll track on either side of the knob.\n * While the width and height of the slider is inferred from its CSS rules, the\n * width and height of the knob are set via props (`knobWidth` and `knobHeight`,\n * respectively). The size of the knob does not impact the size of the slider.\n *\n * @exports SliderKnob - The component for the knob.\n * @exports SliderLabel - The component for the label on the knob.\n * @exports SliderTrack - The component for the slide track on either side of\n * the knob.\n */\nexport default forwardRef<HTMLDivElement, SliderProps>(({\n children,\n className,\n isInverted = false,\n isTrackInteractive = true,\n knobHeight = 30,\n knobWidth = 30,\n labelProvider,\n onlyDispatchesOnDragEnd = false,\n orientation = 'vertical',\n position: externalPosition = 0,\n trackPadding = 0,\n onDragEnd,\n onDragStart,\n onPositionChange,\n ...props\n}, ref) => {\n const mapDragValueToPosition = (value: number, dx: number, dy: number) => {\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n const truePosition = isInverted ? 1 - value : value\n const trueNewPositionX = truePosition * rect.width + dx\n const trueNewPositionY = truePosition * rect.height + dy\n const trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width))\n const normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition\n\n return normalizedPosition\n }\n\n const trackClickHandler = (event: MouseEvent) => {\n if (!isTrackInteractive) return\n\n const rect = Rect.from(bodyRef.current) ?? new Rect()\n\n switch (orientation) {\n case 'horizontal': {\n const trackPosition = (event.clientX - rect.left) / rect.width\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n case 'vertical': {\n const trackPosition = (event.clientY - rect.top) / rect.height\n const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition\n setPosition(normalizedPosition)\n break\n }\n default: break\n }\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const knobContainerRef = useRef<HTMLButtonElement>(null)\n\n const { isDragging: [isDragging], isReleasing: [isReleasing], value: [position, setPosition] } = useDragEffect(knobContainerRef, {\n initialValue: externalPosition,\n transform: mapDragValueToPosition,\n onDragStart,\n onDragEnd,\n })\n\n // Natural position is the position affecting internal components accounting\n // for `isInverted`.\n const naturalPosition = isInverted ? 1 - position : position\n const isAtEnd = isInverted ? position === 0 : position === 1\n const isAtStart = isInverted ? position === 1 : position === 0\n\n useEffect(() => {\n if (isDragging || externalPosition === position) return\n setPosition(externalPosition)\n }, [externalPosition])\n\n useEffect(() => {\n if (isDragging && onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, isDragging)\n }, [position])\n\n useEffect(() => {\n if (isDragging || !onlyDispatchesOnDragEnd) return\n onPositionChange?.(position, true)\n }, [isDragging])\n\n const components = asComponentDict(children, {\n knob: SliderKnob,\n label: SliderLabel,\n track: SliderTrack,\n })\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n track: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n knob: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n label: classNames(orientation, {\n 'at-end': isAtEnd,\n 'at-start': isAtStart,\n 'dragging': isDragging,\n 'releasing': isReleasing,\n }),\n })\n\n const fixedStyles = asStyleDict({\n body: {\n height: '100%',\n width: '100%',\n },\n knobContainer: {\n background: 'none',\n border: 'none',\n outline: 'none',\n position: 'absolute',\n transform: 'translate3d(-50%, -50%, 0)',\n zIndex: '1',\n ...orientation === 'vertical' ? {\n left: '50%',\n top: `${naturalPosition * 100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${naturalPosition * 100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n },\n },\n knob: {\n height: `${knobHeight}px`,\n touchAction: 'none',\n width: `${knobWidth}px`,\n },\n label: {\n pointerEvents: 'none',\n userSelect: 'none',\n },\n track: {\n cursor: isTrackInteractive ? 'pointer' : 'auto',\n pointerEvents: isTrackInteractive ? 'auto' : 'none',\n position: 'absolute',\n ...orientation === 'vertical' ? {\n left: '0',\n margin: '0 auto',\n right: '0',\n width: '100%',\n } : {\n bottom: '0',\n height: '100%',\n margin: 'auto 0',\n top: '0',\n },\n },\n trackHitbox: {\n height: '100%',\n minHeight: '20px',\n minWidth: '20px',\n position: 'absolute',\n transform: orientation === 'horizontal' ? 'translate3d(0, -50%, 0)' : 'translate3d(-50%, 0, 0)',\n width: '100%',\n },\n })\n\n const defaultStyles = asStyleDict({\n knob: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n display: 'flex',\n justifyContent: 'center',\n },\n label: {\n color: '#000',\n fontSize: '12px',\n lineHeight: `${knobHeight}px`,\n },\n track: {\n background: '#fff',\n },\n })\n\n return (\n <div {...props} ref={ref} className={classNames(className, fixedClassNames.root)}>\n <div ref={bodyRef} style={fixedStyles.body}>\n {cloneStyledElement(components.track ?? <SliderTrack style={defaultStyles.track}/>, {\n className: classNames('start', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n height: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n top: '0',\n } : {\n left: '0',\n width: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n {cloneStyledElement(components.track ?? <SliderTrack style={defaultStyles.track}/>, {\n className: classNames('end', fixedClassNames.track),\n style: styles(fixedStyles.track, orientation === 'vertical' ? {\n bottom: '0',\n height: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,\n } : {\n right: '0',\n width: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,\n }),\n onClick: trackClickHandler,\n }, <div style={fixedStyles.trackHitbox}/>)}\n <button ref={knobContainerRef} style={fixedStyles.knobContainer}>\n {cloneStyledElement(components.knob ?? <SliderKnob style={defaultStyles.knob}/>, {\n className: classNames(fixedClassNames.knob),\n style: styles(fixedStyles.knob),\n }, labelProvider && cloneStyledElement(components.label ?? <SliderLabel style={defaultStyles.label}/>, {\n className: classNames(fixedClassNames.label),\n style: styles(fixedStyles.label),\n }, labelProvider(position)))}\n </button>\n </div>\n </div>\n )\n})\n\nexport const SliderTrack = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const SliderKnob = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n\nexport const SliderLabel = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n"]}
|