etudes 0.27.0 → 0.31.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/lib/Slider.d.ts CHANGED
@@ -1,43 +1,36 @@
1
1
  import { CSSProperties } from 'react';
2
- import { ExtendedCSSFunction, Orientation } from './types';
3
- export declare type KnobCSSProps = Readonly<{
4
- isAtBeginning: boolean;
5
- isAtEnd: boolean;
6
- isDragging?: boolean;
7
- }>;
2
+ import { CSSProp } from 'styled-components';
3
+ import { Orientation } from './types';
8
4
  export declare type GutterCSSProps = Readonly<{
9
5
  orientation: Orientation;
10
6
  }>;
11
7
  export declare type LabelCSSProps = Readonly<{
12
8
  knobHeight: number;
13
9
  }>;
14
- export declare type BreakpointDescriptor = {
15
- label?: string;
16
- position?: number;
17
- };
18
10
  export declare type Props = {
19
11
  id?: string;
20
12
  className?: string;
21
13
  style?: CSSProperties;
22
14
  isInverted?: boolean;
23
15
  onlyDispatchesOnDragEnd?: boolean;
16
+ isLabelVisible?: boolean;
17
+ labelProvider?: (position: number, index: number) => string;
24
18
  gutterPadding?: number;
25
19
  knobHeight?: number;
26
20
  knobWidth?: number;
27
21
  orientation?: Orientation;
28
- defaultPosition?: number;
22
+ position?: number;
29
23
  onDragEnd?: () => void;
30
24
  onDragStart?: () => void;
31
25
  onPositionChange?: (position: number) => void;
32
- startingGutterCSS?: ExtendedCSSFunction<GutterCSSProps>;
33
- endingGutterCSS?: ExtendedCSSFunction<GutterCSSProps>;
34
- knobCSS?: ExtendedCSSFunction<KnobCSSProps>;
35
- labelCSS?: ExtendedCSSFunction<LabelCSSProps>;
36
- breakpoints?: readonly BreakpointDescriptor[];
26
+ startingGutterCSS?: CSSProp<any>;
27
+ endingGutterCSS?: CSSProp<any>;
28
+ knobCSS?: CSSProp<any>;
29
+ labelCSS?: CSSProp<any>;
30
+ breakpoints?: readonly number[];
37
31
  autoSnap?: boolean;
38
- isLabelVisible?: boolean;
39
- defaultIndex?: number;
32
+ index?: number;
40
33
  onIndexChange?: (index: number) => void;
41
34
  };
42
- export declare function sliderBreakpointsFactory(length: number, labelIterator?: (index: number, position: number) => string): readonly BreakpointDescriptor[];
43
- export default function Slider({ id, className, style, isInverted, onlyDispatchesOnDragEnd, gutterPadding, knobHeight, knobWidth, orientation, defaultPosition, onDragEnd, onDragStart, onPositionChange, startingGutterCSS, endingGutterCSS, knobCSS, labelCSS, breakpoints, autoSnap, isLabelVisible, defaultIndex, onIndexChange, }: Props): JSX.Element;
35
+ export declare function generateBreakpoints(length: number): readonly number[];
36
+ export default function Slider({ id, className, style, isInverted, onlyDispatchesOnDragEnd, gutterPadding, knobHeight, knobWidth, orientation, position, isLabelVisible, labelProvider, onDragEnd, onDragStart, onPositionChange, startingGutterCSS, endingGutterCSS, knobCSS, labelCSS, breakpoints, autoSnap, index, onIndexChange, }: Props): JSX.Element;
package/lib/Slider.js CHANGED
@@ -53,93 +53,51 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
53
53
  return (mod && mod.__esModule) ? mod : { "default": mod };
54
54
  };
55
55
  Object.defineProperty(exports, "__esModule", { value: true });
56
- exports.sliderBreakpointsFactory = void 0;
56
+ exports.generateBreakpoints = void 0;
57
+ var classnames_1 = __importDefault(require("classnames"));
57
58
  var interactjs_1 = __importDefault(require("interactjs"));
58
59
  var react_1 = __importStar(require("react"));
59
60
  var spase_1 = require("spase");
60
61
  var styled_components_1 = __importStar(require("styled-components"));
61
- function sliderBreakpointsFactory(length, labelIterator) {
62
+ function generateBreakpoints(length) {
62
63
  if (length <= 1)
63
64
  throw new Error('`length` value must be greater than or equal to 2');
64
65
  if (Math.round(length) !== length)
65
66
  throw new Error('`length` value must be an integer');
66
67
  var interval = 1 / (length - 1);
67
68
  return Array(length).fill(null).map(function (v, i) {
68
- var _a;
69
69
  var pos = interval * i;
70
- return {
71
- label: (_a = labelIterator === null || labelIterator === void 0 ? void 0 : labelIterator(i, pos)) !== null && _a !== void 0 ? _a : undefined,
72
- position: pos,
73
- };
70
+ return pos;
74
71
  });
75
72
  }
76
- exports.sliderBreakpointsFactory = sliderBreakpointsFactory;
73
+ exports.generateBreakpoints = generateBreakpoints;
77
74
  function Slider(_a) {
78
- var _b;
79
- var id = _a.id, className = _a.className, _c = _a.style, style = _c === void 0 ? {} : _c, _d = _a.isInverted, isInverted = _d === void 0 ? false : _d, _e = _a.onlyDispatchesOnDragEnd, onlyDispatchesOnDragEnd = _e === void 0 ? false : _e, _f = _a.gutterPadding, gutterPadding = _f === void 0 ? 0 : _f, _g = _a.knobHeight, knobHeight = _g === void 0 ? 30 : _g, _h = _a.knobWidth, knobWidth = _h === void 0 ? 30 : _h, _j = _a.orientation, orientation = _j === void 0 ? 'vertical' : _j, _k = _a.defaultPosition, defaultPosition = _k === void 0 ? 0 : _k, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, onPositionChange = _a.onPositionChange, _l = _a.startingGutterCSS, startingGutterCSS = _l === void 0 ? function (props) { return (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""]))); } : _l, _m = _a.endingGutterCSS, endingGutterCSS = _m === void 0 ? function (props) { return (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject([""], [""]))); } : _m, _o = _a.knobCSS, knobCSS = _o === void 0 ? function (props) { return (0, styled_components_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject([""], [""]))); } : _o, _p = _a.labelCSS, labelCSS = _p === void 0 ? function (props) { return (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject([""], [""]))); } : _p, _q = _a.breakpoints, breakpoints = _q === void 0 ? sliderBreakpointsFactory(10, function (index, position) { return "".concat(index); }) : _q, _r = _a.autoSnap, autoSnap = _r === void 0 ? true : _r, _s = _a.isLabelVisible, isLabelVisible = _s === void 0 ? true : _s, defaultIndex = _a.defaultIndex, onIndexChange = _a.onIndexChange;
80
- function updateRect() {
81
- var _a;
82
- setRect((_a = spase_1.Rect.from(rootRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect());
83
- }
84
- function updateKnobPosition() {
85
- var naturalPosition = getPosition(true);
86
- if (orientation === 'vertical') {
87
- setKnobPosition(naturalPosition * rect.height);
88
- }
89
- else {
90
- setKnobPosition(naturalPosition * rect.width);
91
- }
92
- }
93
- function getPosition(natural) {
94
- if (natural === void 0) { natural = false; }
95
- if (natural) {
96
- return isInverted ? (1 - position.current) : position.current;
97
- }
98
- else {
99
- return position.current;
100
- }
101
- }
102
- function setPosition(value) {
103
- position.current = value;
104
- updateKnobPosition();
105
- if (onlyDispatchesOnDragEnd && isDragging)
106
- return;
107
- onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange(position.current);
108
- if (breakpoints)
109
- onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(getClosestIndex());
110
- }
111
- function getStartingGutterLength() {
112
- var naturalPosition = getPosition(true);
113
- var knobLength = orientation === 'vertical' ? knobHeight : knobWidth;
114
- var sliderLength = orientation === 'vertical' ? rect.height : rect.width;
115
- return Math.max(0, naturalPosition * sliderLength - (knobLength / 2) - gutterPadding);
116
- }
117
- function getEndingGutterLength() {
118
- var naturalPosition = getPosition(true);
119
- var knobLength = orientation === 'vertical' ? knobHeight : knobWidth;
120
- var sliderLength = orientation === 'vertical' ? rect.height : rect.width;
121
- return Math.max(0, (1 - naturalPosition) * sliderLength - (knobLength / 2) - gutterPadding);
122
- }
75
+ var id = _a.id, className = _a.className, style = _a.style, _b = _a.isInverted, isInverted = _b === void 0 ? false : _b, _c = _a.onlyDispatchesOnDragEnd, onlyDispatchesOnDragEnd = _c === void 0 ? false : _c, _d = _a.gutterPadding, gutterPadding = _d === void 0 ? 0 : _d, _e = _a.knobHeight, knobHeight = _e === void 0 ? 30 : _e, _f = _a.knobWidth, knobWidth = _f === void 0 ? 30 : _f, _g = _a.orientation, orientation = _g === void 0 ? 'vertical' : _g, _h = _a.position, position = _h === void 0 ? 0 : _h, _j = _a.isLabelVisible, isLabelVisible = _j === void 0 ? true : _j, labelProvider = _a.labelProvider, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, onPositionChange = _a.onPositionChange, startingGutterCSS = _a.startingGutterCSS, endingGutterCSS = _a.endingGutterCSS, knobCSS = _a.knobCSS, labelCSS = _a.labelCSS, breakpoints = _a.breakpoints, _k = _a.autoSnap, autoSnap = _k === void 0 ? true : _k, index = _a.index, onIndexChange = _a.onIndexChange;
123
76
  function getClosestIndex() {
124
77
  if (!breakpoints)
125
78
  return -1;
126
- var idx = 0;
127
- var delta = NaN;
79
+ var index = 0;
80
+ var minDelta = NaN;
128
81
  for (var i = 0, n = breakpoints.length; i < n; i++) {
129
82
  var breakpoint = getPositionByIndex(i);
130
- var d = Math.abs(getPosition() - breakpoint);
131
- if (isNaN(delta) || (d < delta)) {
132
- delta = d;
133
- idx = i;
83
+ var delta = Math.abs(livePosition.current - breakpoint);
84
+ if (isNaN(minDelta) || (delta < minDelta)) {
85
+ minDelta = delta;
86
+ index = i;
134
87
  }
135
88
  }
136
- return idx;
89
+ return index;
137
90
  }
138
91
  function getPositionByIndex(index) {
139
- var _a;
140
92
  if (!breakpoints)
141
93
  return NaN;
142
- return (_a = breakpoints[index].position) !== null && _a !== void 0 ? _a : (index / (breakpoints.length - 1));
94
+ return breakpoints[index];
95
+ }
96
+ function setLivePosition(value) {
97
+ livePosition.current = value;
98
+ _setPosition(value);
99
+ if (breakpoints)
100
+ _setIndex(getClosestIndex());
143
101
  }
144
102
  function initInteractivity() {
145
103
  var knob = knobRef.current;
@@ -166,13 +124,15 @@ function Slider(_a) {
166
124
  onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart();
167
125
  }
168
126
  function onKnobDragMove(delta) {
169
- var naturalPosition = getPosition(true);
127
+ var _a;
128
+ var rect = (_a = spase_1.Rect.from(rootRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
129
+ var naturalPosition = isInverted ? 1 - livePosition.current : livePosition.current;
170
130
  var naturalNewPositionX = naturalPosition * rect.width + delta;
171
131
  var naturalNewPositionY = naturalPosition * rect.height + delta;
172
132
  var naturalNewPosition = (orientation === 'vertical') ? Math.max(0, Math.min(1, naturalNewPositionY / rect.height)) : Math.max(0, Math.min(1, naturalNewPositionX / rect.width));
173
133
  var newPosition = isInverted ? (1 - naturalNewPosition) : naturalNewPosition;
174
134
  setIsDragging(true);
175
- setPosition(newPosition);
135
+ setLivePosition(newPosition);
176
136
  }
177
137
  function onKnobDragStop() {
178
138
  setIsDragging(false);
@@ -183,52 +143,90 @@ function Slider(_a) {
183
143
  if (!autoSnap || !breakpoints)
184
144
  return;
185
145
  var position = getPositionByIndex(getClosestIndex());
186
- setPosition(position);
146
+ setLivePosition(position);
187
147
  }
188
148
  var rootRef = (0, react_1.useRef)(null);
189
149
  var knobRef = (0, react_1.useRef)(null);
190
- var position = (0, react_1.useRef)(((breakpoints !== undefined) && (defaultIndex !== undefined)) ? getPositionByIndex(defaultIndex) : defaultPosition);
191
- var _t = __read((0, react_1.useState)(new spase_1.Rect()), 2), rect = _t[0], setRect = _t[1];
192
- var _u = __read((0, react_1.useState)(undefined), 2), isDragging = _u[0], setIsDragging = _u[1];
193
- var _v = __read((0, react_1.useState)(NaN), 2), knobPosition = _v[0], setKnobPosition = _v[1];
194
- (0, react_1.useEffect)(function () {
195
- updateRect();
196
- }, [orientation, rootRef]);
150
+ var livePosition = (0, react_1.useRef)((breakpoints !== undefined && index !== undefined) ? getPositionByIndex(index) : position);
151
+ var _l = __read((0, react_1.useState)(livePosition.current), 2), _position = _l[0], _setPosition = _l[1];
152
+ var _m = __read((0, react_1.useState)(getClosestIndex()), 2), _index = _m[0], _setIndex = _m[1];
153
+ var _o = __read((0, react_1.useState)(undefined), 2), isDragging = _o[0], setIsDragging = _o[1];
154
+ var naturalPosition = isInverted ? 1 - _position : _position;
197
155
  (0, react_1.useEffect)(function () {
198
156
  initInteractivity();
199
- updateKnobPosition();
200
157
  return function () {
201
158
  deinitInteractivity();
202
159
  };
203
- }, [rect]);
160
+ }, []);
161
+ (0, react_1.useEffect)(function () {
162
+ if (breakpoints && index !== undefined)
163
+ return;
164
+ if (position === livePosition.current)
165
+ return;
166
+ setIsDragging(undefined);
167
+ setLivePosition(position);
168
+ }, [position]);
169
+ (0, react_1.useEffect)(function () {
170
+ if (!breakpoints || index === undefined)
171
+ return;
172
+ var position = getPositionByIndex(index);
173
+ if (position === livePosition.current)
174
+ return;
175
+ setIsDragging(undefined);
176
+ setLivePosition(position);
177
+ }, [index]);
178
+ (0, react_1.useEffect)(function () {
179
+ if (onlyDispatchesOnDragEnd && isDragging)
180
+ return;
181
+ onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange(_position);
182
+ }, [_position]);
183
+ (0, react_1.useEffect)(function () {
184
+ if (onlyDispatchesOnDragEnd && isDragging)
185
+ return;
186
+ onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(_index);
187
+ }, [_index]);
204
188
  (0, react_1.useEffect)(function () {
205
189
  snapToClosestBreakpointIfNeeded();
206
190
  }, [autoSnap]);
207
191
  return (react_1.default.createElement(StyledRoot, { ref: rootRef, id: id, className: className, orientation: orientation, style: style },
208
- react_1.default.createElement(StyledGutter, { orientation: orientation, extendedCSS: startingGutterCSS, style: orientation === 'vertical' ? {
192
+ react_1.default.createElement(StyledGutter, { orientation: orientation, css: startingGutterCSS, style: orientation === 'vertical' ? {
209
193
  top: 0,
210
- height: "".concat(getStartingGutterLength(), "px"),
194
+ height: "calc(".concat(naturalPosition * 100, "% - ").concat(knobHeight * .5, "px - ").concat(gutterPadding, "px)"),
211
195
  } : {
212
196
  left: 0,
213
- width: "".concat(getStartingGutterLength(), "px"),
197
+ width: "calc(".concat(naturalPosition * 100, "% - ").concat(knobWidth * .5, "px - ").concat(gutterPadding, "px)"),
214
198
  } }),
215
- react_1.default.createElement(StyledKnob, { ref: knobRef, isAtEnd: isInverted ? (position.current === 0) : (position.current === 1), isAtBeginning: isInverted ? (position.current === 1) : (position.current === 0), isDragging: isDragging, extendedCSS: knobCSS, style: __assign({ height: "".concat(knobHeight, "px"), position: 'absolute', width: "".concat(knobWidth, "px"), zIndex: 1 }, (orientation === 'vertical' ? {
216
- margin: "".concat(-knobHeight / 2 + knobPosition, "px 0 0 ").concat((rect.width - knobWidth) / 2, "px"),
199
+ react_1.default.createElement(StyledKnobContainer, { ref: knobRef, style: __assign({ transform: 'translate3d(-50%, -50%, 0)' }, (orientation === 'vertical' ? {
200
+ left: '50%',
201
+ top: "".concat(_position * 100, "%"),
202
+ transition: isDragging === false ? 'top 100ms ease-out' : 'none',
217
203
  } : {
218
- margin: "".concat((rect.height - knobHeight) / 2, "px 0 0 ").concat(-knobWidth / 2 + knobPosition, "px"),
219
- })) }, breakpoints && isLabelVisible && (react_1.default.createElement(StyledLabel, { knobHeight: knobHeight, extendedCSS: labelCSS }, (_b = breakpoints[getClosestIndex()].label) !== null && _b !== void 0 ? _b : ''))),
220
- react_1.default.createElement(StyledGutter, { orientation: orientation, extendedCSS: endingGutterCSS, style: orientation === 'vertical' ? {
204
+ left: "".concat(_position * 100, "%"),
205
+ top: '50%',
206
+ transition: isDragging === false ? 'left 100ms ease-out' : 'none',
207
+ })) },
208
+ react_1.default.createElement(StyledKnob, { className: (0, classnames_1.default)({
209
+ 'at-end': isInverted ? (_position === 0) : (_position === 1),
210
+ 'at-start': isInverted ? (_position === 1) : (_position === 0),
211
+ 'dragging': isDragging === true,
212
+ 'idle': isDragging === false,
213
+ }), css: knobCSS, style: {
214
+ height: "".concat(knobHeight, "px"),
215
+ width: "".concat(knobWidth, "px"),
216
+ } }, breakpoints && isLabelVisible && labelProvider && (react_1.default.createElement(StyledLabel, { knobHeight: knobHeight, css: labelCSS }, labelProvider(_position, getClosestIndex()))))),
217
+ react_1.default.createElement(StyledGutter, { orientation: orientation, css: endingGutterCSS, style: orientation === 'vertical' ? {
221
218
  bottom: 0,
222
- height: "".concat(getEndingGutterLength(), "px"),
219
+ height: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(knobHeight * .5, "px - ").concat(gutterPadding, "px)"),
223
220
  } : {
224
221
  right: 0,
225
- width: "".concat(getEndingGutterLength(), "px"),
222
+ width: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(knobWidth * .5, "px - ").concat(gutterPadding, "px)"),
226
223
  } })));
227
224
  }
228
225
  exports.default = Slider;
229
- var StyledGutter = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n background: #fff;\n position: absolute;\n\n ", "\n\n ", "\n"], ["\n background: #fff;\n position: absolute;\n\n ", "\n\n ", "\n"])), function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "], ["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "]))) : (0, styled_components_1.css)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "], ["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "]))); }, function (props) { return props.extendedCSS(props); });
230
- var StyledLabel = styled_components_1.default.label(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n color: #000;\n font-size: ", "px;\n pointer-events: none;\n user-select: none;\n\n ", "\n"], ["\n color: #000;\n font-size: ", "px;\n pointer-events: none;\n user-select: none;\n\n ", "\n"])), function (props) { return props.knobHeight * .5; }, function (props) { return props.extendedCSS(props); });
231
- var StyledKnob = styled_components_1.default.div(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: ", ";\n touch-action: none;\n transition-duration: 100ms;\n transition-property: ", ";\n transition-timing-function: ease-out;\n\n ", "\n"], ["\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: ", ";\n touch-action: none;\n transition-duration: 100ms;\n transition-property: ", ";\n transition-timing-function: ease-out;\n\n ", "\n"])), function (props) { return props.isDragging ? .6 : 1; }, function (props) { return props.isDragging === false ? 'background, color, opacity, margin, transform' : 'background, color, transform, opacity'; }, function (props) { return props.extendedCSS(props); });
232
- var StyledRoot = styled_components_1.default.div(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n box-sizing: border-box;\n display: block;\n height: ", ";\n position: relative;\n width: ", ";\n"], ["\n box-sizing: border-box;\n display: block;\n height: ", ";\n position: relative;\n width: ", ";\n"])), function (props) { return props.orientation === 'vertical' ? '300px' : '4px'; }, function (props) { return props.orientation === 'vertical' ? '4px' : '300px'; });
233
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
226
+ var StyledGutter = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background: #fff;\n position: absolute;\n\n ", "\n\n ", "\n"], ["\n background: #fff;\n position: absolute;\n\n ", "\n\n ", "\n"])), function (props) { return props.orientation === 'vertical' ? (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "], ["\n left: 0;\n margin: 0 auto;\n right: 0;\n width: 100%;\n "]))) : (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "], ["\n bottom: 0;\n height: 100%;\n margin: auto 0;\n top: 0;\n "]))); }, function (props) { return props.css; });
227
+ var StyledLabel = styled_components_1.default.label(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n color: #000;\n font-size: ", "px;\n pointer-events: none;\n user-select: none;\n\n ", "\n"], ["\n color: #000;\n font-size: ", "px;\n pointer-events: none;\n user-select: none;\n\n ", "\n"])), function (props) { return props.knobHeight * .5; }, function (props) { return props.css; });
228
+ var StyledKnobContainer = styled_components_1.default.button(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n position: absolute;\n z-index: 1;\n transition-duration: 100ms;\n transition-property: top;\n transition-timing-function: ease-out;\n"], ["\n position: absolute;\n z-index: 1;\n transition-duration: 100ms;\n transition-property: top;\n transition-timing-function: ease-out;\n"])));
229
+ var StyledKnob = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: 1;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &.idle {\n opacity: 1;\n transition-property: background, color, opacity, margin, transform;\n }\n\n &.dragging {\n opacity: .6;\n transition-property: background, color, transform, opacity;\n }\n\n ", "\n"], ["\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: 1;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &.idle {\n opacity: 1;\n transition-property: background, color, opacity, margin, transform;\n }\n\n &.dragging {\n opacity: .6;\n transition-property: background, color, transform, opacity;\n }\n\n ", "\n"])), function (props) { return props.css; });
230
+ var StyledRoot = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n box-sizing: border-box;\n display: block;\n height: ", ";\n position: relative;\n width: ", ";\n"], ["\n box-sizing: border-box;\n display: block;\n height: ", ";\n position: relative;\n width: ", ";\n"])), function (props) { return props.orientation === 'vertical' ? '300px' : '4px'; }, function (props) { return props.orientation === 'vertical' ? '4px' : '300px'; });
231
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
234
232
  //# sourceMappingURL=Slider.js.map
package/lib/Slider.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.js","sourceRoot":"/","sources":["Slider.tsx"],"names":[],"m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,CAAC,KAAK,sKAAiD,iCAElE,EAA8B,0DAIzC,EAAiC,IACpC,KALc,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,UAAU,GAAG,EAAE,EAArB,CAAqB,EAIzC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,EAAxB,CAAwB,CACpC,CAAA;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,qYAA+C,oLAQ/D,EAAkC,kFAGtB,EAA+H,kDAGpJ,EAAiC,IACpC,KAPY,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAzB,CAAyB,EAGtB,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,uCAAuC,EAAtH,CAAsH,EAGpJ,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,EAAxB,CAAwB,CACpC,CAAA;AAED,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 interact from 'interactjs'\nimport React, { CSSProperties, useEffect, useRef, useState } from 'react'\nimport { Rect } from 'spase'\nimport styled, { css } from 'styled-components'\nimport { ExtendedCSSFunction, ExtendedCSSProps, Orientation } from './types'\n\nexport type KnobCSSProps = Readonly<{\n isAtBeginning: boolean\n isAtEnd: boolean\n isDragging?: boolean\n}>\n\nexport type GutterCSSProps = Readonly<{\n orientation: Orientation\n}>\n\nexport type LabelCSSProps = Readonly<{\n knobHeight: number\n}>\n\nexport type BreakpointDescriptor = {\n label?: string\n position?: number\n}\n\nexport type Props = {\n /**\n * ID attribute of the root element.\n */\n id?: string\n\n /**\n * Class attribute of the root element.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style?: CSSProperties\n\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 * Indicates if position/index change events are dispatched only when dragging ends. When\n * disabled, aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Padding between the gutter and the knob in pixels.\n */\n gutterPadding?: 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 default position. This is ignored if `defaultIndex` and breakpoints are provided.\n */\n defaultPosition?: number\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 * Handler invoked when position changes.\n */\n onPositionChange?: (position: number) => void\n\n /**\n * Custom CSS provided to the gutter before the knob.\n */\n startingGutterCSS?: ExtendedCSSFunction<GutterCSSProps>\n\n /**\n * Custom CSS provided to the gutter after the knob.\n */\n endingGutterCSS?: ExtendedCSSFunction<GutterCSSProps>\n\n /**\n * Custom CSS provided to the knob.\n */\n knobCSS?: ExtendedCSSFunction<KnobCSSProps>\n\n /**\n * Custom CSS provided to the label inside the knob.\n */\n labelCSS?: ExtendedCSSFunction<LabelCSSProps>\n\n // The following props are only used if `breakpoints` are provided.\n\n /**\n * An array of breakpoint descriptors. A breakpoint is a position (0 - 1 inclusive) on the gutter\n * where the knob should snap to if dragging stops near it. You can associate a label with a\n * breakpoint so it can be displayed in the knob. If breakpoints are to be specified, ensure that\n * there are at least two: one for the start of the gutter and one for the end.\n */\n breakpoints?: readonly BreakpointDescriptor[]\n\n /**\n * Indicates whether the knob automatically snaps to the nearest breakpoint, if breakpoints are\n * provided.\n */\n autoSnap?: boolean\n\n /**\n * Indicates if the breakpoint label is visible by the knob. Note that this is only applicable if\n * breakpoints are provided.\n */\n isLabelVisible?: boolean\n\n /**\n * The default index. This is only used if breakpoints are provided. On the other hand, if\n * breakpoints are provided, the default position will be calculated based on this value, making\n * `defaultPosition` irrelevant.\n */\n defaultIndex?: number\n\n /**\n * Handler invoked when index changes. This happens simultaneously with `onPositionChange`. Note\n * that this is only invoked if breakpoints are provided, because otherwise there will be no\n * indexes.\n */\n onIndexChange?: (index: number) => void\n}\n\n/**\n * Generates a set of breakpoints compatible with this component.\n *\n * @param length - The number of breakpoints. This must be at least 2 because you must include the\n * starting and ending points.\n * @param labelIterator - Iterator function used for generating the label for each breakpoint.\n *\n * @returns An array of breakpoints.\n */\nexport function sliderBreakpointsFactory(length: number, labelIterator?: (index: number, position: number) => string): readonly BreakpointDescriptor[] {\n if (length <= 1) throw new Error('`length` value must be greater than or equal to 2')\n if (Math.round(length) !== length) throw new Error('`length` value must be an integer')\n\n const interval = 1 / (length - 1)\n\n return Array(length).fill(null).map((v, i) => {\n const pos = interval * i\n\n return {\n label: labelIterator?.(i, pos) ?? undefined,\n position: pos,\n }\n })\n}\n\n/**\n * A slider component that divides the scroll gutter into two different elements—one that is before\n * the knob and one that is after the knob. This allows for individual styling customizations. The\n * width and height of the root element of this component is taken from the aggregated rect of both\n * gutter parts. The dimension of the knob itself does not impact that of the root element. In\n * addition to the tranditional behavior of a scrollbar, this component allows you to provide\n * breakpoints along the gutter so the knob can automatically snap to them (if feature is enabled)\n * when dragging ends near the breakpoint positions. You can also supply a label to each breakpoint\n * and have it display on the knob when the current position is close to the breakpoint. This\n * component supports both horizontal and vertical orientations.\n */\nexport default function Slider({\n id,\n className,\n style = {},\n isInverted = false,\n onlyDispatchesOnDragEnd = false,\n gutterPadding = 0,\n knobHeight = 30,\n knobWidth = 30,\n orientation = 'vertical',\n defaultPosition = 0,\n onDragEnd,\n onDragStart,\n onPositionChange,\n startingGutterCSS = props => css``,\n endingGutterCSS = props => css``,\n knobCSS = props => css``,\n labelCSS = props => css``,\n breakpoints = sliderBreakpointsFactory(10, (index: number, position: number) => `${index}`),\n autoSnap = true,\n isLabelVisible = true,\n defaultIndex,\n onIndexChange,\n}: Props) {\n /**\n * Updates the calculated rect of this slider. If the root element is not rendered yet, the\n * calculated rect will be zero.\n */\n function updateRect() {\n setRect(Rect.from(rootRef.current) ?? new Rect())\n }\n\n /**\n * Updates the current knob position of the slider.\n */\n function updateKnobPosition() {\n const naturalPosition = getPosition(true)\n\n if (orientation === 'vertical') {\n setKnobPosition(naturalPosition * rect.height)\n }\n else {\n setKnobPosition(naturalPosition * rect.width)\n }\n }\n\n /**\n * Gets the current position. If `natural` is `true`, the uninverted (if `isInverted` is set to\n * `true`) position will be returned.\n *\n * @param natural - Specifies if the natural position should be returned in case `isInverted` is\n * specified.\n *\n * @returns The current position.\n */\n function getPosition(natural = false): number {\n if (natural) {\n return isInverted ? (1 - position.current) : position.current\n }\n else {\n return position.current\n }\n }\n\n /**\n * Sets the current position. The position should be normalized. That is, inversion should be\n * taken care of prior to passing the new value to this method if `isInverted` is `true`.\n *\n * @param value - The value to set the position to.\n */\n function setPosition(value: number) {\n position.current = value\n updateKnobPosition()\n\n if (onlyDispatchesOnDragEnd && isDragging) return\n\n onPositionChange?.(position.current)\n\n if (breakpoints) onIndexChange?.(getClosestIndex())\n }\n\n /**\n * Length of the gutter before the knob in pixels. If the orientation of the slider is horizontal,\n * this refers to the width, else this refers to the height.\n *\n * @returns The gutter length.\n */\n function getStartingGutterLength(): number {\n const naturalPosition = getPosition(true)\n const knobLength = orientation === 'vertical' ? knobHeight : knobWidth\n const sliderLength = orientation === 'vertical' ? rect.height : rect.width\n return Math.max(0, naturalPosition * sliderLength - (knobLength / 2) - gutterPadding)\n }\n\n /**\n * Length of the gutter after the knob in pixels. If the orientation of the slider is horizontal,\n * this refers to the width, else this refers to the height.\n *\n * @returns The gutter length.\n */\n function getEndingGutterLength(): number {\n const naturalPosition = getPosition(true)\n const knobLength = orientation === 'vertical' ? knobHeight : knobWidth\n const sliderLength = orientation === 'vertical' ? rect.height : rect.width\n return Math.max(0, (1 - naturalPosition) * sliderLength - (knobLength / 2) - gutterPadding)\n }\n\n /**\n * Gets the index of the breakpoint of which the current position is closest to. If for whatever\n * reason the index cannot be computed (i.e. no breakpoints were provided), -1 is returned.\n *\n * @returns The closest index.\n */\n function getClosestIndex(): number {\n if (!breakpoints) return -1\n\n let idx = 0\n let delta = NaN\n\n for (let i = 0, n = breakpoints.length; i < n; i++) {\n const breakpoint = getPositionByIndex(i)\n const d = Math.abs(getPosition() - breakpoint)\n\n if (isNaN(delta) || (d < delta)) {\n delta = d\n idx = i\n }\n }\n\n return idx\n }\n\n /**\n * Gets the position by breakpoint index. This value ranges between 0 - 1, inclusive.\n *\n * @param index - The breakpoint index.\n *\n * @returns The position. If for whatever reason the position cannot be determined, NaN is\n * returned.\n */\n function getPositionByIndex(index: number): number {\n if (!breakpoints) return NaN\n return breakpoints[index].position ?? (index / (breakpoints.length - 1))\n }\n\n /**\n * Initializes input interactivity of the knob.\n */\n function initInteractivity() {\n const knob = knobRef.current\n if (!knob || interact.isSet(knob)) return\n\n interact(knob).draggable({\n inertia: true,\n onstart: () => onKnobDragStart(),\n onmove: ({ dx, dy }) => onKnobDragMove(orientation === 'vertical' ? dy : dx),\n onend: () => onKnobDragStop(),\n })\n }\n\n /**\n * Deinitializes input interactivity of the knob.\n */\n function deinitInteractivity() {\n const knob = knobRef.current\n if (!knob) return\n\n interact(knob).unset()\n }\n\n /**\n * Handler invoked when the knob starts dragging.\n */\n function onKnobDragStart() {\n setIsDragging(true)\n\n onDragStart?.()\n }\n\n /**\n * Handler invoked when the knob moves.\n *\n * @param delta - The distance traveled (in pixels) since the last invocation of this handler.\n */\n function onKnobDragMove(delta: number) {\n const naturalPosition = getPosition(true)\n const naturalNewPositionX = naturalPosition * rect.width + delta\n const naturalNewPositionY = naturalPosition * rect.height + delta\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\n setIsDragging(true)\n\n setPosition(newPosition)\n }\n\n /**\n * Handler invoked when the knob stops dragging.\n */\n function onKnobDragStop() {\n setIsDragging(false)\n snapToClosestBreakpointIfNeeded()\n\n onDragEnd?.()\n }\n\n /**\n * Snaps the knob to the closest breakpoint. Note that if there are no breakpoints or\n * auto-snapping feature is disabled, this method does nothing.\n */\n function snapToClosestBreakpointIfNeeded() {\n if (!autoSnap || !breakpoints) return\n const position = getPositionByIndex(getClosestIndex())\n setPosition(position)\n }\n\n const rootRef = useRef(null)\n const knobRef = useRef(null)\n const position = useRef(((breakpoints !== undefined) && (defaultIndex !== undefined)) ? getPositionByIndex(defaultIndex) : defaultPosition)\n\n const [rect, setRect] = useState(new Rect())\n const [isDragging, setIsDragging] = useState<boolean | undefined>(undefined)\n const [knobPosition, setKnobPosition] = useState(NaN)\n\n useEffect(() => {\n updateRect()\n }, [orientation, rootRef])\n\n useEffect(() => {\n initInteractivity()\n updateKnobPosition()\n\n return () => {\n deinitInteractivity()\n }\n }, [rect])\n\n useEffect(() => {\n snapToClosestBreakpointIfNeeded()\n }, [autoSnap])\n\n return (\n <StyledRoot ref={rootRef} id={id} className={className} orientation={orientation} style={style}>\n <StyledGutter orientation={orientation} extendedCSS={startingGutterCSS} style={orientation === 'vertical' ? {\n top: 0,\n height: `${getStartingGutterLength()}px`,\n } : {\n left: 0,\n width: `${getStartingGutterLength()}px`,\n }}\n />\n <StyledKnob\n ref={knobRef}\n isAtEnd={isInverted ? (position.current === 0) : (position.current === 1)}\n isAtBeginning={isInverted ? (position.current === 1) : (position.current === 0)}\n isDragging={isDragging}\n extendedCSS={knobCSS}\n style={{\n height: `${knobHeight}px`,\n position: 'absolute',\n width: `${knobWidth}px`,\n zIndex: 1,\n ...(orientation === 'vertical' ? {\n margin: `${-knobHeight / 2 + knobPosition}px 0 0 ${(rect.width - knobWidth) / 2}px`,\n } : {\n margin: `${(rect.height - knobHeight) / 2}px 0 0 ${-knobWidth / 2 + knobPosition}px`,\n }),\n }}\n >\n {breakpoints && isLabelVisible && (\n <StyledLabel knobHeight={knobHeight} extendedCSS={labelCSS}>{breakpoints[getClosestIndex()].label ?? ''}</StyledLabel>\n )}\n </StyledKnob>\n <StyledGutter orientation={orientation} extendedCSS={endingGutterCSS} style={orientation === 'vertical' ? {\n bottom: 0,\n height: `${getEndingGutterLength()}px`,\n } : {\n right: 0,\n width: `${getEndingGutterLength()}px`,\n }}\n />\n </StyledRoot>\n )\n}\n\nconst StyledGutter = styled.div<GutterCSSProps & ExtendedCSSProps<GutterCSSProps>>`\n background: #fff;\n position: absolute;\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 ${props => props.extendedCSS(props)}\n`\n\nconst StyledLabel = styled.label<LabelCSSProps & ExtendedCSSProps<LabelCSSProps>>`\n color: #000;\n font-size: ${props => props.knobHeight * .5}px;\n pointer-events: none;\n user-select: none;\n\n ${props => props.extendedCSS(props)}\n`\n\nconst StyledKnob = styled.div<KnobCSSProps & ExtendedCSSProps<KnobCSSProps>>`\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: ${props => props.isDragging ? .6 : 1};\n touch-action: none;\n transition-duration: 100ms;\n transition-property: ${props => props.isDragging === false ? 'background, color, opacity, margin, transform' : 'background, color, transform, opacity'};\n transition-timing-function: ease-out;\n\n ${props => props.extendedCSS(props)}\n`\n\nconst StyledRoot = styled.div<{\n orientation: 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,0DAAiC;AACjC,6CAAyE;AACzE,+BAA4B;AAC5B,qEAAwD;AAgKxD,SAAgB,mBAAmB,CAAC,MAAc;IAChD,IAAI,MAAM,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IACrF,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IAEvF,IAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEjC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC;QACvC,IAAM,GAAG,GAAG,QAAQ,GAAG,CAAC,CAAA;QACxB,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC,CAAA;AACJ,CAAC;AAVD,kDAUC;AAaD,SAAwB,MAAM,CAAC,EAwBvB;QAvBN,EAAE,QAAA,EACF,SAAS,eAAA,EACT,KAAK,WAAA,EACL,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,+BAA+B,EAA/B,uBAAuB,mBAAG,KAAK,KAAA,EAC/B,qBAAiB,EAAjB,aAAa,mBAAG,CAAC,KAAA,EACjB,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EACf,iBAAc,EAAd,SAAS,mBAAG,EAAE,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AC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAlD,CAAkD,CACrE,CAAA","sourcesContent":["import classNames from 'classnames'\nimport interact from 'interactjs'\nimport React, { CSSProperties, useEffect, useRef, useState } from 'react'\nimport { Rect } from 'spase'\nimport styled, { css, CSSProp } from 'styled-components'\nimport { Orientation } from './types'\n\nexport type GutterCSSProps = Readonly<{\n orientation: Orientation\n}>\n\nexport type LabelCSSProps = Readonly<{\n knobHeight: number\n}>\n\nexport type Props = {\n /**\n * ID attribute of the root element.\n */\n id?: string\n\n /**\n * Class attribute of the root element.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style?: CSSProperties\n\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 * Indicates if position/index change events are dispatched only when dragging ends. When\n * disabled, aforementioned events are fired repeatedly while dragging.\n */\n onlyDispatchesOnDragEnd?: boolean\n\n /**\n * Indicates if the label is visible by the knob. Note that this is only applicable if\n * `labelProvider` is set.\n */\n isLabelVisible?: boolean\n\n /**\n * A function that returns the label to be displayed (if `isLabelVisible` is `true`) at a given\n * slider position and cloest breakpoint index (if breakpoints are provided).\n *\n * @param position - The current slider position.\n * @praam index - The nearest breakpoint index (if breakpoints are provided), or -1 if no\n * breakpoints are provided.\n *\n * @returns The label.\n */\n labelProvider?: (position: number, index: number) => string\n\n /**\n * Padding between the gutter and the knob in pixels.\n */\n gutterPadding?: 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. This is ignored if `index` and `breakpoints` are provided.\n */\n position?: number\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 * Handler invoked when position changes.\n *\n * @param position - The current slider position.\n */\n onPositionChange?: (position: number) => void\n\n /**\n * Custom CSS provided to the gutter before the knob.\n */\n startingGutterCSS?: CSSProp<any>\n\n /**\n * Custom CSS provided to the gutter after the knob.\n */\n endingGutterCSS?: CSSProp<any>\n\n /**\n * Custom CSS provided to the knob.\n */\n knobCSS?: CSSProp<any>\n\n /**\n * Custom CSS provided to the label inside the knob.\n */\n labelCSS?: CSSProp<any>\n\n // The following props are only used if `breakpoints` are provided.\n\n /**\n * An array of breakpoint descriptors. A breakpoint is a position (0 - 1 inclusive) on the gutter\n * where the knob should snap to if dragging stops near it. If breakpoints are to be specified,\n * ensure that there are at least two: one for the start of the gutter and one for the end.\n */\n breakpoints?: readonly number[]\n\n /**\n * Indicates whether the knob automatically snaps to the nearest breakpoint, if breakpoints are\n * provided.\n */\n autoSnap?: boolean\n\n /**\n * The current index. This is only used if breakpoints are provided. On the other hand, if\n * breakpoints are provided, the current position will be calculated based on this value, making\n * `position` irrelevant.\n */\n index?: number\n\n /**\n * Handler invoked when index changes. This happens simultaneously with `onPositionChange`. Note\n * that this is only invoked if breakpoints are provided, because otherwise there will be no\n * indexes.\n *\n * @param index - The current breakpoint index.\n */\n onIndexChange?: (index: number) => void\n}\n\n/**\n * Generates a set of breakpoints compatible with this component.\n *\n * @param length - The number of breakpoints. This must be at least 2 because you must include the\n * starting and ending points.\n *\n * @returns An array of breakpoints.\n */\nexport function generateBreakpoints(length: number): readonly number[] {\n if (length <= 1) throw new Error('`length` value must be greater than or equal to 2')\n if (Math.round(length) !== length) throw new Error('`length` value must be an integer')\n\n const interval = 1 / (length - 1)\n\n return Array(length).fill(null).map((v, i) => {\n const pos = interval * i\n return pos\n })\n}\n\n/**\n * A slider component that divides the scroll gutter into two different elements—one that is before\n * the knob and one that is after the knob. This allows for individual styling customizations. The\n * width and height of the root element of this component is taken from the aggregated rect of both\n * gutter parts. The dimension of the knob itself does not impact that of the root element. In\n * addition to the tranditional behavior of a scrollbar, this component allows you to provide\n * breakpoints along the gutter so the knob can automatically snap to them (if feature is enabled)\n * when dragging ends near the breakpoint positions. You can also supply a label to each breakpoint\n * and have it display on the knob when the current position is close to the breakpoint. This\n * component supports both horizontal and vertical orientations.\n */\nexport default function Slider({\n id,\n className,\n style,\n isInverted = false,\n onlyDispatchesOnDragEnd = false,\n gutterPadding = 0,\n knobHeight = 30,\n knobWidth = 30,\n orientation = 'vertical',\n position = 0,\n isLabelVisible = true,\n labelProvider,\n onDragEnd,\n onDragStart,\n onPositionChange,\n startingGutterCSS,\n endingGutterCSS,\n knobCSS,\n labelCSS,\n breakpoints,\n autoSnap = true,\n index,\n onIndexChange,\n}: Props) {\n /**\n * Gets the index of the breakpoint of which the current position is closest to. If for whatever\n * reason the index cannot be computed (i.e. no breakpoints were provided), -1 is returned.\n *\n * @returns The closest index.\n */\n function getClosestIndex(): number {\n if (!breakpoints) return -1\n\n let index = 0\n let minDelta = NaN\n\n for (let i = 0, n = breakpoints.length; i < n; i++) {\n const breakpoint = getPositionByIndex(i)\n const delta = Math.abs(livePosition.current - breakpoint)\n\n if (isNaN(minDelta) || (delta < minDelta)) {\n minDelta = delta\n index = i\n }\n }\n\n return index\n }\n\n /**\n * Gets the position by breakpoint index. This value ranges between 0 - 1, inclusive.\n *\n * @param index - The breakpoint index.\n *\n * @returns The position. If for whatever reason the position cannot be determined, NaN is\n * returned.\n */\n function getPositionByIndex(index: number): number {\n if (!breakpoints) return NaN\n return breakpoints[index]\n }\n\n /**\n * Sets the current live position. The live position is different from the position state value.\n * Because states are asynchronous by nature, this live position value is used to record position\n * changes when drag event happens. This position should be normalized. That is, inversion should\n * be taken care of prior to passing the new value to this method if `isInverted` is `true`.\n *\n * @param value - The value to set the position to.\n */\n function setLivePosition(value: number) {\n livePosition.current = value\n _setPosition(value)\n if (breakpoints) _setIndex(getClosestIndex())\n }\n\n /**\n * Initializes input interactivity of the knob.\n */\n function initInteractivity() {\n const knob = knobRef.current\n if (!knob || interact.isSet(knob)) return\n\n interact(knob).draggable({\n inertia: true,\n onstart: () => onKnobDragStart(),\n onmove: ({ dx, dy }) => onKnobDragMove(orientation === 'vertical' ? dy : dx),\n onend: () => onKnobDragStop(),\n })\n }\n\n /**\n * Deinitializes input interactivity of the knob.\n */\n function deinitInteractivity() {\n const knob = knobRef.current\n if (!knob) return\n\n interact(knob).unset()\n }\n\n /**\n * Handler invoked when the knob starts dragging.\n */\n function onKnobDragStart() {\n setIsDragging(true)\n\n onDragStart?.()\n }\n\n /**\n * Handler invoked when the knob moves.\n *\n * @param delta - The distance traveled (in pixels) since the last invocation of this handler.\n */\n function onKnobDragMove(delta: number) {\n const rect = Rect.from(rootRef.current) ?? new Rect()\n const naturalPosition = isInverted ? 1 - livePosition.current : livePosition.current\n const naturalNewPositionX = naturalPosition * rect.width + delta\n const naturalNewPositionY = naturalPosition * rect.height + delta\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\n setIsDragging(true)\n setLivePosition(newPosition)\n }\n\n /**\n * Handler invoked when the knob stops dragging.\n */\n function onKnobDragStop() {\n setIsDragging(false)\n snapToClosestBreakpointIfNeeded()\n\n onDragEnd?.()\n }\n\n /**\n * Snaps the knob to the closest breakpoint. Note that if there are no breakpoints or\n * auto-snapping feature is disabled, this method does nothing.\n */\n function snapToClosestBreakpointIfNeeded() {\n if (!autoSnap || !breakpoints) return\n const position = getPositionByIndex(getClosestIndex())\n setLivePosition(position)\n }\n\n const rootRef = useRef<HTMLDivElement>(null)\n const knobRef = useRef<HTMLButtonElement>(null)\n\n const livePosition = useRef((breakpoints !== undefined && index !== undefined) ? getPositionByIndex(index) : position)\n\n const [_position, _setPosition] = useState(livePosition.current)\n const [_index, _setIndex] = useState(getClosestIndex())\n const [isDragging, setIsDragging] = useState<boolean | undefined>(undefined)\n\n const naturalPosition = isInverted ? 1 - _position : _position\n\n useEffect(() => {\n initInteractivity()\n\n return () => {\n deinitInteractivity()\n }\n }, [])\n\n useEffect(() => {\n if (breakpoints && index !== undefined) return\n if (position === livePosition.current) return\n\n setIsDragging(undefined)\n setLivePosition(position)\n }, [position])\n\n useEffect(() => {\n if (!breakpoints || index === undefined) return\n\n const position = getPositionByIndex(index)\n\n if (position === livePosition.current) return\n\n setIsDragging(undefined)\n setLivePosition(position)\n }, [index])\n\n useEffect(() => {\n if (onlyDispatchesOnDragEnd && isDragging) return\n onPositionChange?.(_position)\n }, [_position])\n\n useEffect(() => {\n if (onlyDispatchesOnDragEnd && isDragging) return\n onIndexChange?.(_index)\n }, [_index])\n\n useEffect(() => {\n snapToClosestBreakpointIfNeeded()\n }, [autoSnap])\n\n return (\n <StyledRoot ref={rootRef} id={id} className={className} orientation={orientation} style={style}>\n <StyledGutter orientation={orientation} css={startingGutterCSS}\n style={orientation === 'vertical' ? {\n top: 0,\n height: `calc(${naturalPosition*100}% - ${knobHeight*.5}px - ${gutterPadding}px)`,\n } : {\n left: 0,\n width: `calc(${naturalPosition*100}% - ${knobWidth*.5}px - ${gutterPadding}px)`,\n }}\n />\n <StyledKnobContainer ref={knobRef} style={{\n transform: 'translate3d(-50%, -50%, 0)',\n ...(orientation === 'vertical' ? {\n left: '50%',\n top: `${_position*100}%`,\n transition: isDragging === false ? 'top 100ms ease-out' : 'none',\n } : {\n left: `${_position*100}%`,\n top: '50%',\n transition: isDragging === false ? 'left 100ms ease-out' : 'none',\n }),\n }}>\n <StyledKnob\n className={classNames({\n 'at-end': isInverted ? (_position === 0) : (_position === 1),\n 'at-start': isInverted ? (_position === 1) : (_position === 0),\n 'dragging': isDragging === true,\n 'idle': isDragging === false,\n })}\n css={knobCSS}\n style={{\n height: `${knobHeight}px`,\n width: `${knobWidth}px`,\n }}\n >\n {breakpoints && isLabelVisible && labelProvider && (\n <StyledLabel knobHeight={knobHeight} css={labelCSS}>{labelProvider(_position, getClosestIndex())}</StyledLabel>\n )}\n </StyledKnob>\n </StyledKnobContainer>\n <StyledGutter orientation={orientation} css={endingGutterCSS}\n style={orientation === 'vertical' ? {\n bottom: 0,\n height: `calc(${(1 - naturalPosition)*100}% - ${knobHeight*.5}px - ${gutterPadding}px)`,\n } : {\n right: 0,\n width: `calc(${(1 - naturalPosition)*100}% - ${knobWidth*.5}px - ${gutterPadding}px)`,\n }}\n />\n </StyledRoot>\n )\n}\n\nconst StyledGutter = styled.div<GutterCSSProps>`\n background: #fff;\n position: absolute;\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 ${props => props.css}\n`\n\nconst StyledLabel = styled.label<LabelCSSProps>`\n color: #000;\n font-size: ${props => props.knobHeight * .5}px;\n pointer-events: none;\n user-select: none;\n\n ${props => props.css}\n`\n\nconst StyledKnobContainer = styled.button`\n position: absolute;\n z-index: 1;\n transition-duration: 100ms;\n transition-property: top;\n transition-timing-function: ease-out;\n`\n\nconst StyledKnob = styled.div`\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n justify-content: center;\n opacity: 1;\n touch-action: none;\n transition-duration: 100ms;\n transition-property: background, color, opacity, transform;\n transition-timing-function: ease-out;\n\n &.idle {\n opacity: 1;\n transition-property: background, color, opacity, margin, transform;\n }\n\n &.dragging {\n opacity: .6;\n transition-property: background, color, transform, opacity;\n }\n\n ${props => props.css}\n`\n\nconst StyledRoot = styled.div<{\n orientation: 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "0.27.0",
3
+ "version": "0.31.0",
4
4
  "description": "A study of styled React components",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "prebuild": "npm run lint",
9
9
  "build": "npm run clean && tsc -p tsconfig.json",
10
10
  "pages": "rimraf .gh-pages && webpack --config demo/config/build.conf.ts",
11
- "demo": "cross-env NODE_ENV=development webpack-cli serve --mode development --hot --config demo/config/build.conf.ts",
11
+ "demo": "npm run clean && concurrently \"npm run build -- --watch\" \"wait-on lib && cross-env NODE_ENV=development webpack-cli serve --mode development --hot --config demo/config/build.conf.ts\"",
12
12
  "test": "echo \"No tests yet :)\"",
13
13
  "lint": "eslint --ext .ts --ext .tsx src demo",
14
14
  "lint:fix": "npm run lint -- --fix"
@@ -48,6 +48,7 @@
48
48
  "@typescript-eslint/parser": "^5.4.0",
49
49
  "babel-loader": "^8.2.3",
50
50
  "babel-plugin-styled-components": "^2.0.1",
51
+ "concurrently": "^6.4.0",
51
52
  "cross-env": "^7.0.3",
52
53
  "debug": "^4.3.2",
53
54
  "dirty-dom": "^7.0.0",
@@ -67,6 +68,7 @@
67
68
  "ts-node": "^10.4.0",
68
69
  "typescript": "^4.5.2",
69
70
  "url-loader": "^4.1.1",
71
+ "wait-on": "^6.0.0",
70
72
  "webpack": "^5.64.3",
71
73
  "webpack-cli": "^4.9.1",
72
74
  "webpack-dev-server": "^4.5.0"
@@ -79,5 +81,8 @@
79
81
  "dirty-dom": "^7.0.0",
80
82
  "interactjs": "1.10.11",
81
83
  "spase": "^6.2.0"
84
+ },
85
+ "dependencies": {
86
+ "classnames": "^2.3.1"
82
87
  }
83
88
  }