etudes 0.29.0 → 0.30.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
@@ -19,7 +19,7 @@ export declare type Props = {
19
19
  knobHeight?: number;
20
20
  knobWidth?: number;
21
21
  orientation?: Orientation;
22
- defaultPosition?: number;
22
+ position?: number;
23
23
  onDragEnd?: () => void;
24
24
  onDragStart?: () => void;
25
25
  onPositionChange?: (position: number) => void;
@@ -29,8 +29,8 @@ export declare type Props = {
29
29
  labelCSS?: CSSProp<any>;
30
30
  breakpoints?: readonly number[];
31
31
  autoSnap?: boolean;
32
- defaultIndex?: number;
32
+ index?: number;
33
33
  onIndexChange?: (index: number) => void;
34
34
  };
35
35
  export declare function generateBreakpoints(length: number): readonly number[];
36
- export default function Slider({ id, className, style, isInverted, onlyDispatchesOnDragEnd, gutterPadding, knobHeight, knobWidth, orientation, defaultPosition, isLabelVisible, labelProvider, onDragEnd, onDragStart, onPositionChange, startingGutterCSS, endingGutterCSS, knobCSS, labelCSS, breakpoints, autoSnap, defaultIndex, onIndexChange, }: Props): JSX.Element;
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
@@ -72,11 +72,7 @@ function generateBreakpoints(length) {
72
72
  }
73
73
  exports.generateBreakpoints = generateBreakpoints;
74
74
  function Slider(_a) {
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.defaultPosition, defaultPosition = _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 ? false : _k, defaultIndex = _a.defaultIndex, onIndexChange = _a.onIndexChange;
76
- function setLivePosition(value) {
77
- livePosition.current = value;
78
- setPosition(value);
79
- }
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;
80
76
  function getClosestIndex() {
81
77
  if (!breakpoints)
82
78
  return -1;
@@ -84,7 +80,7 @@ function Slider(_a) {
84
80
  var minDelta = NaN;
85
81
  for (var i = 0, n = breakpoints.length; i < n; i++) {
86
82
  var breakpoint = getPositionByIndex(i);
87
- var delta = Math.abs(position - breakpoint);
83
+ var delta = Math.abs(livePosition.current - breakpoint);
88
84
  if (isNaN(minDelta) || (delta < minDelta)) {
89
85
  minDelta = delta;
90
86
  index = i;
@@ -97,6 +93,12 @@ function Slider(_a) {
97
93
  return NaN;
98
94
  return breakpoints[index];
99
95
  }
96
+ function setLivePosition(value) {
97
+ livePosition.current = value;
98
+ _setPosition(value);
99
+ if (breakpoints)
100
+ _setIndex(getClosestIndex());
101
+ }
100
102
  function initInteractivity() {
101
103
  var knob = knobRef.current;
102
104
  if (!knob || interactjs_1.default.isSet(knob))
@@ -124,7 +126,7 @@ function Slider(_a) {
124
126
  function onKnobDragMove(delta) {
125
127
  var _a;
126
128
  var rect = (_a = spase_1.Rect.from(rootRef.current)) !== null && _a !== void 0 ? _a : new spase_1.Rect();
127
- var naturalPosition = isInverted ? (1 - livePosition.current) : livePosition.current;
129
+ var naturalPosition = isInverted ? 1 - livePosition.current : livePosition.current;
128
130
  var naturalNewPositionX = naturalPosition * rect.width + delta;
129
131
  var naturalNewPositionY = naturalPosition * rect.height + delta;
130
132
  var naturalNewPosition = (orientation === 'vertical') ? Math.max(0, Math.min(1, naturalNewPositionY / rect.height)) : Math.max(0, Math.min(1, naturalNewPositionX / rect.width));
@@ -145,10 +147,11 @@ function Slider(_a) {
145
147
  }
146
148
  var rootRef = (0, react_1.useRef)(null);
147
149
  var knobRef = (0, react_1.useRef)(null);
148
- var livePosition = (0, react_1.useRef)(((breakpoints !== undefined) && (defaultIndex !== undefined)) ? getPositionByIndex(defaultIndex) : defaultPosition);
149
- var _l = __read((0, react_1.useState)(livePosition.current), 2), position = _l[0], setPosition = _l[1];
150
- var _m = __read((0, react_1.useState)(undefined), 2), isDragging = _m[0], setIsDragging = _m[1];
151
- var naturalPosition = isInverted ? 1 - position : position;
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;
152
155
  (0, react_1.useEffect)(function () {
153
156
  initInteractivity();
154
157
  return function () {
@@ -156,15 +159,35 @@ function Slider(_a) {
156
159
  };
157
160
  }, []);
158
161
  (0, react_1.useEffect)(function () {
159
- snapToClosestBreakpointIfNeeded();
160
- }, [autoSnap]);
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]);
161
178
  (0, react_1.useEffect)(function () {
162
179
  if (onlyDispatchesOnDragEnd && isDragging)
163
180
  return;
164
- onPositionChange === null || onPositionChange === void 0 ? void 0 : onPositionChange(position);
165
- if (breakpoints)
166
- onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(getClosestIndex());
167
- }, [position]);
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]);
188
+ (0, react_1.useEffect)(function () {
189
+ snapToClosestBreakpointIfNeeded();
190
+ }, [autoSnap]);
168
191
  return (react_1.default.createElement(StyledRoot, { ref: rootRef, id: id, className: className, orientation: orientation, style: style },
169
192
  react_1.default.createElement(StyledGutter, { orientation: orientation, css: startingGutterCSS, style: orientation === 'vertical' ? {
170
193
  top: 0,
@@ -175,22 +198,22 @@ function Slider(_a) {
175
198
  } }),
176
199
  react_1.default.createElement(StyledKnobContainer, { ref: knobRef, style: __assign({ transform: 'translate3d(-50%, -50%, 0)' }, (orientation === 'vertical' ? {
177
200
  left: '50%',
178
- top: "".concat(position * 100, "%"),
201
+ top: "".concat(_position * 100, "%"),
179
202
  transition: isDragging === false ? 'top 100ms ease-out' : 'none',
180
203
  } : {
181
- left: "".concat(position * 100, "%"),
204
+ left: "".concat(_position * 100, "%"),
182
205
  top: '50%',
183
206
  transition: isDragging === false ? 'left 100ms ease-out' : 'none',
184
207
  })) },
185
208
  react_1.default.createElement(StyledKnob, { className: (0, classnames_1.default)({
186
- 'at-end': isInverted ? (position === 0) : (position === 1),
187
- 'at-start': isInverted ? (position === 1) : (position === 0),
209
+ 'at-end': isInverted ? (_position === 0) : (_position === 1),
210
+ 'at-start': isInverted ? (_position === 1) : (_position === 0),
188
211
  'dragging': isDragging === true,
189
212
  'idle': isDragging === false,
190
213
  }), css: knobCSS, style: {
191
214
  height: "".concat(knobHeight, "px"),
192
215
  width: "".concat(knobWidth, "px"),
193
- } }, breakpoints && isLabelVisible && labelProvider && (react_1.default.createElement(StyledLabel, { knobHeight: knobHeight, css: labelCSS }, labelProvider(position, getClosestIndex()))))),
216
+ } }, breakpoints && isLabelVisible && labelProvider && (react_1.default.createElement(StyledLabel, { knobHeight: knobHeight, css: labelCSS }, labelProvider(_position, getClosestIndex()))))),
194
217
  react_1.default.createElement(StyledGutter, { orientation: orientation, css: endingGutterCSS, style: orientation === 'vertical' ? {
195
218
  bottom: 0,
196
219
  height: "calc(".concat((1 - naturalPosition) * 100, "% - ").concat(knobHeight * .5, "px - ").concat(gutterPadding, "px)"),
package/lib/Slider.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.js","sourceRoot":"/","sources":["Slider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;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ourcesContent":["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 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 * @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 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 * @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 defaultPosition = 0,\n isLabelVisible = true,\n labelProvider,\n onDragEnd,\n onDragStart,\n onPositionChange,\n startingGutterCSS,\n endingGutterCSS,\n knobCSS,\n labelCSS,\n breakpoints,\n autoSnap = false,\n defaultIndex,\n onIndexChange,\n}: Props) {\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 setLivePosition(value: number) {\n livePosition.current = value\n setPosition(value)\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 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(position - 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 * 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 const livePosition = useRef(((breakpoints !== undefined) && (defaultIndex !== undefined)) ? getPositionByIndex(defaultIndex) : defaultPosition)\n\n const [position, setPosition] = useState(livePosition.current)\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 snapToClosestBreakpointIfNeeded()\n }, [autoSnap])\n\n useEffect(() => {\n if (onlyDispatchesOnDragEnd && isDragging) return\n onPositionChange?.(position)\n if (breakpoints) onIndexChange?.(getClosestIndex())\n }, [position])\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\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\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\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,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GAAG,2BAAM,CAAC,GAAG,6KAE3B,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 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\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\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\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.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "A study of styled React components",
5
5
  "main": "lib",
6
6
  "scripts": {