@chayns-components/swipeable-wrapper 5.0.0-beta.441 → 5.0.0-beta.443
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/components/swipeable-wrapper/SwipeableWrapper.js +32 -40
- package/lib/components/swipeable-wrapper/SwipeableWrapper.js.map +1 -1
- package/lib/components/swipeable-wrapper/SwipeableWrapper.styles.js +4 -11
- package/lib/components/swipeable-wrapper/SwipeableWrapper.styles.js.map +1 -1
- package/lib/components/swipeable-wrapper/swipeable-action/SwipeableAction.js +11 -19
- package/lib/components/swipeable-wrapper/swipeable-action/SwipeableAction.js.map +1 -1
- package/lib/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js +6 -14
- package/lib/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js.map +1 -1
- package/lib/index.js +1 -13
- package/lib/index.js.map +1 -1
- package/lib/utils/threshold.js +3 -10
- package/lib/utils/threshold.js.map +1 -1
- package/package.json +10 -10
|
@@ -1,61 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
var _chaynsApi = require("chayns-api");
|
|
8
|
-
var _framerMotion = require("framer-motion");
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _threshold = require("../../utils/threshold");
|
|
11
|
-
var _SwipeableAction = _interopRequireWildcard(require("./swipeable-action/SwipeableAction"));
|
|
12
|
-
var _SwipeableWrapper = require("./SwipeableWrapper.styles");
|
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
1
|
+
import { vibrate } from 'chayns-api';
|
|
2
|
+
import { animate, useMotionValue } from 'framer-motion';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { calcThreshold } from '../../utils/threshold';
|
|
5
|
+
import SwipeableAction, { SWIPEABLE_ACTION_WIDTH } from './swipeable-action/SwipeableAction';
|
|
6
|
+
import { StyledMotionSwipeableWrapper, StyledSwipeableWrapperContent } from './SwipeableWrapper.styles';
|
|
15
7
|
const SwipeableWrapper = _ref => {
|
|
16
8
|
let {
|
|
17
9
|
children,
|
|
18
10
|
leftActions = [],
|
|
19
11
|
rightActions = []
|
|
20
12
|
} = _ref;
|
|
21
|
-
const [leftThreshold, setLeftThreshold] =
|
|
13
|
+
const [leftThreshold, setLeftThreshold] = useState(calcThreshold({
|
|
22
14
|
actionCount: leftActions.length,
|
|
23
15
|
direction: 'left',
|
|
24
16
|
width: window.innerWidth
|
|
25
17
|
}));
|
|
26
|
-
const [rightThreshold, setRightThreshold] =
|
|
18
|
+
const [rightThreshold, setRightThreshold] = useState(calcThreshold({
|
|
27
19
|
actionCount: rightActions.length,
|
|
28
20
|
direction: 'right',
|
|
29
21
|
width: window.innerWidth
|
|
30
22
|
}));
|
|
31
|
-
const swipeableWrapperRef =
|
|
32
|
-
const listItemXOffset =
|
|
33
|
-
const close =
|
|
34
|
-
void
|
|
23
|
+
const swipeableWrapperRef = useRef(null);
|
|
24
|
+
const listItemXOffset = useMotionValue(0);
|
|
25
|
+
const close = useCallback(() => {
|
|
26
|
+
void animate(listItemXOffset, 0);
|
|
35
27
|
}, [listItemXOffset]);
|
|
36
|
-
const open =
|
|
28
|
+
const open = useCallback(direction => {
|
|
37
29
|
switch (direction) {
|
|
38
30
|
case 'left':
|
|
39
|
-
void
|
|
31
|
+
void animate(listItemXOffset, SWIPEABLE_ACTION_WIDTH * leftActions.length);
|
|
40
32
|
break;
|
|
41
33
|
case 'right':
|
|
42
|
-
void
|
|
34
|
+
void animate(listItemXOffset, -SWIPEABLE_ACTION_WIDTH * rightActions.length);
|
|
43
35
|
break;
|
|
44
36
|
default:
|
|
45
37
|
break;
|
|
46
38
|
}
|
|
47
39
|
}, [leftActions.length, listItemXOffset, rightActions.length]);
|
|
48
|
-
|
|
40
|
+
useEffect(() => {
|
|
49
41
|
const width = swipeableWrapperRef.current?.parentElement?.offsetWidth;
|
|
50
42
|
|
|
51
43
|
// This check was deliberately chosen because a width of 0 is also not permitted.
|
|
52
44
|
if (width) {
|
|
53
|
-
setLeftThreshold(
|
|
45
|
+
setLeftThreshold(calcThreshold({
|
|
54
46
|
actionCount: leftActions.length,
|
|
55
47
|
direction: 'left',
|
|
56
48
|
width
|
|
57
49
|
}));
|
|
58
|
-
setRightThreshold(
|
|
50
|
+
setRightThreshold(calcThreshold({
|
|
59
51
|
actionCount: rightActions.length,
|
|
60
52
|
direction: 'right',
|
|
61
53
|
width
|
|
@@ -64,7 +56,7 @@ const SwipeableWrapper = _ref => {
|
|
|
64
56
|
}, [leftActions.length, rightActions.length]);
|
|
65
57
|
|
|
66
58
|
// Close an opened menu when anything outside it is tapped
|
|
67
|
-
|
|
59
|
+
useEffect(() => {
|
|
68
60
|
function closeCallback(event) {
|
|
69
61
|
const eventTarget = event.target;
|
|
70
62
|
|
|
@@ -82,25 +74,25 @@ const SwipeableWrapper = _ref => {
|
|
|
82
74
|
}, [close]);
|
|
83
75
|
|
|
84
76
|
// Vibrate when the threshold is passed
|
|
85
|
-
|
|
77
|
+
useEffect(() => listItemXOffset.onChange(newValue => {
|
|
86
78
|
const previous = listItemXOffset.getPrevious();
|
|
87
79
|
const hasCrossedLeftThreshold = previous < leftThreshold && newValue >= leftThreshold || previous > leftThreshold && newValue <= leftThreshold;
|
|
88
80
|
const hasCrossedRightThreshold = previous < rightThreshold && newValue >= rightThreshold || previous > rightThreshold && newValue <= rightThreshold;
|
|
89
81
|
if (hasCrossedLeftThreshold || hasCrossedRightThreshold) {
|
|
90
|
-
void
|
|
82
|
+
void vibrate({
|
|
91
83
|
iOSFeedbackVibration: 6,
|
|
92
84
|
pattern: [150]
|
|
93
85
|
});
|
|
94
86
|
}
|
|
95
87
|
}), [leftThreshold, listItemXOffset, rightThreshold]);
|
|
96
|
-
const handlePan =
|
|
88
|
+
const handlePan = useCallback((_, info) => {
|
|
97
89
|
const currentXOffset = listItemXOffset.get();
|
|
98
90
|
const dampingFactor = info.offset.x > 0 && leftActions.length > 0 || info.offset.x < 0 && rightActions.length > 0 || currentXOffset > 0 && info.delta.x < 0 || currentXOffset < 0 && info.delta.x > 0 ? 1 : 0.75 / (Math.abs(info.offset.x) / 9);
|
|
99
91
|
if (Math.abs(info.offset.x) > 30 || currentXOffset > 0) {
|
|
100
92
|
listItemXOffset.set(currentXOffset + info.delta.x * dampingFactor);
|
|
101
93
|
}
|
|
102
94
|
}, [leftActions.length, listItemXOffset, rightActions.length]);
|
|
103
|
-
const handlePanEnd =
|
|
95
|
+
const handlePanEnd = useCallback(() => {
|
|
104
96
|
const offset = listItemXOffset.get();
|
|
105
97
|
if (offset > leftThreshold) {
|
|
106
98
|
leftActions[0]?.action();
|
|
@@ -121,23 +113,23 @@ const SwipeableWrapper = _ref => {
|
|
|
121
113
|
// eslint-disable-next-line default-case
|
|
122
114
|
switch (state) {
|
|
123
115
|
case 'left-open':
|
|
124
|
-
if (offset <
|
|
116
|
+
if (offset < SWIPEABLE_ACTION_WIDTH) {
|
|
125
117
|
close();
|
|
126
118
|
} else {
|
|
127
119
|
open('left');
|
|
128
120
|
}
|
|
129
121
|
break;
|
|
130
122
|
case 'right-open':
|
|
131
|
-
if (offset > -
|
|
123
|
+
if (offset > -SWIPEABLE_ACTION_WIDTH) {
|
|
132
124
|
close();
|
|
133
125
|
} else {
|
|
134
126
|
open('right');
|
|
135
127
|
}
|
|
136
128
|
break;
|
|
137
129
|
case 'closed':
|
|
138
|
-
if (offset >
|
|
130
|
+
if (offset > SWIPEABLE_ACTION_WIDTH) {
|
|
139
131
|
open('left');
|
|
140
|
-
} else if (offset < -
|
|
132
|
+
} else if (offset < -SWIPEABLE_ACTION_WIDTH) {
|
|
141
133
|
open('right');
|
|
142
134
|
} else {
|
|
143
135
|
close();
|
|
@@ -145,7 +137,7 @@ const SwipeableWrapper = _ref => {
|
|
|
145
137
|
}
|
|
146
138
|
}
|
|
147
139
|
}, [close, leftActions, leftThreshold, listItemXOffset, open, rightActions, rightThreshold]);
|
|
148
|
-
const leftActionElements =
|
|
140
|
+
const leftActionElements = useMemo(() => Array.from(leftActions).reverse().map((item, index) => /*#__PURE__*/React.createElement(SwipeableAction, {
|
|
149
141
|
activationThreshold: leftThreshold,
|
|
150
142
|
close: close,
|
|
151
143
|
index: index,
|
|
@@ -155,7 +147,7 @@ const SwipeableWrapper = _ref => {
|
|
|
155
147
|
position: "left",
|
|
156
148
|
totalActionCount: leftActions.length
|
|
157
149
|
})), [close, leftActions, leftThreshold, listItemXOffset]);
|
|
158
|
-
const rightActionElements =
|
|
150
|
+
const rightActionElements = useMemo(() => rightActions.map((item, index) => /*#__PURE__*/React.createElement(SwipeableAction, {
|
|
159
151
|
activationThreshold: rightThreshold,
|
|
160
152
|
close: close,
|
|
161
153
|
index: index,
|
|
@@ -165,15 +157,15 @@ const SwipeableWrapper = _ref => {
|
|
|
165
157
|
position: "right",
|
|
166
158
|
totalActionCount: rightActions.length
|
|
167
159
|
})), [close, rightActions, rightThreshold, listItemXOffset]);
|
|
168
|
-
return /*#__PURE__*/
|
|
160
|
+
return /*#__PURE__*/React.createElement(StyledMotionSwipeableWrapper, {
|
|
169
161
|
onPan: handlePan,
|
|
170
162
|
onPanEnd: handlePanEnd,
|
|
171
163
|
ref: swipeableWrapperRef,
|
|
172
164
|
style: {
|
|
173
165
|
x: listItemXOffset
|
|
174
166
|
}
|
|
175
|
-
}, leftActionElements, /*#__PURE__*/
|
|
167
|
+
}, leftActionElements, /*#__PURE__*/React.createElement(StyledSwipeableWrapperContent, null, children), rightActionElements);
|
|
176
168
|
};
|
|
177
169
|
SwipeableWrapper.displayName = 'SwipeableWrapper';
|
|
178
|
-
|
|
170
|
+
export default SwipeableWrapper;
|
|
179
171
|
//# sourceMappingURL=SwipeableWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeableWrapper.js","names":["_chaynsApi","require","_framerMotion","_react","_interopRequireWildcard","_threshold","_SwipeableAction","_SwipeableWrapper","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SwipeableWrapper","_ref","children","leftActions","rightActions","leftThreshold","setLeftThreshold","useState","calcThreshold","actionCount","length","direction","width","window","innerWidth","rightThreshold","setRightThreshold","swipeableWrapperRef","useRef","listItemXOffset","useMotionValue","close","useCallback","animate","open","SWIPEABLE_ACTION_WIDTH","useEffect","current","parentElement","offsetWidth","closeCallback","event","eventTarget","target","contains","document","addEventListener","removeEventListener","onChange","newValue","previous","getPrevious","hasCrossedLeftThreshold","hasCrossedRightThreshold","vibrate","iOSFeedbackVibration","pattern","handlePan","_","info","currentXOffset","dampingFactor","offset","x","delta","Math","abs","handlePanEnd","action","state","leftActionElements","useMemo","Array","from","reverse","map","item","index","createElement","activationThreshold","key","position","totalActionCount","rightActionElements","StyledMotionSwipeableWrapper","onPan","onPanEnd","ref","style","StyledSwipeableWrapperContent","displayName","_default","exports"],"sources":["../../../src/components/swipeable-wrapper/SwipeableWrapper.tsx"],"sourcesContent":["import { vibrate } from 'chayns-api';\nimport { animate, PanInfo, useMotionValue } from 'framer-motion';\nimport React, {\n CSSProperties,\n FC,\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { calcThreshold } from '../../utils/threshold';\nimport SwipeableAction, { SWIPEABLE_ACTION_WIDTH } from './swipeable-action/SwipeableAction';\nimport {\n StyledMotionSwipeableWrapper,\n StyledSwipeableWrapperContent,\n} from './SwipeableWrapper.styles';\n\nexport type SwipeableActionItem = {\n action: VoidFunction;\n backgroundColor: CSSProperties['backgroundColor'];\n color: CSSProperties['color'];\n text?: ReactNode;\n icon: ReactNode;\n key: string;\n};\n\nexport type SwipeableWrapperProps = {\n /**\n * The content of the Swipeable item.\n */\n children: ReactNode;\n /**\n * The left-side actions, ordered from the left to the right.\n */\n leftActions?: SwipeableActionItem[];\n /**\n * The right-side actions, ordered from left to the right.\n */\n rightActions?: SwipeableActionItem[];\n};\n\nconst SwipeableWrapper: FC<SwipeableWrapperProps> = ({\n children,\n leftActions = [],\n rightActions = [],\n}) => {\n const [leftThreshold, setLeftThreshold] = useState(\n calcThreshold({\n actionCount: leftActions.length,\n direction: 'left',\n width: window.innerWidth,\n }),\n );\n\n const [rightThreshold, setRightThreshold] = useState(\n calcThreshold({\n actionCount: rightActions.length,\n direction: 'right',\n width: window.innerWidth,\n }),\n );\n\n const swipeableWrapperRef = useRef<HTMLDivElement | null>(null);\n\n const listItemXOffset = useMotionValue(0);\n\n const close = useCallback(() => {\n void animate(listItemXOffset, 0);\n }, [listItemXOffset]);\n\n const open = useCallback(\n (direction: 'left' | 'right') => {\n switch (direction) {\n case 'left':\n void animate(listItemXOffset, SWIPEABLE_ACTION_WIDTH * leftActions.length);\n break;\n case 'right':\n void animate(listItemXOffset, -SWIPEABLE_ACTION_WIDTH * rightActions.length);\n break;\n default:\n break;\n }\n },\n [leftActions.length, listItemXOffset, rightActions.length],\n );\n\n useEffect(() => {\n const width = swipeableWrapperRef.current?.parentElement?.offsetWidth;\n\n // This check was deliberately chosen because a width of 0 is also not permitted.\n if (width) {\n setLeftThreshold(\n calcThreshold({\n actionCount: leftActions.length,\n direction: 'left',\n width,\n }),\n );\n\n setRightThreshold(\n calcThreshold({\n actionCount: rightActions.length,\n direction: 'right',\n width,\n }),\n );\n }\n }, [leftActions.length, rightActions.length]);\n\n // Close an opened menu when anything outside it is tapped\n useEffect(() => {\n function closeCallback(event: MouseEvent | TouchEvent) {\n const eventTarget = event.target;\n\n // @ts-expect-error: Pretty sure that the event target is always a Node.\n if (eventTarget && !swipeableWrapperRef.current?.contains(eventTarget)) {\n close();\n }\n }\n\n document.addEventListener('mousedown', closeCallback);\n document.addEventListener('touchstart', closeCallback);\n\n return () => {\n document.removeEventListener('mousedown', closeCallback);\n document.removeEventListener('touchstart', closeCallback);\n };\n }, [close]);\n\n // Vibrate when the threshold is passed\n useEffect(\n () =>\n listItemXOffset.onChange((newValue: number) => {\n const previous = listItemXOffset.getPrevious();\n\n const hasCrossedLeftThreshold =\n (previous < leftThreshold && newValue >= leftThreshold) ||\n (previous > leftThreshold && newValue <= leftThreshold);\n\n const hasCrossedRightThreshold =\n (previous < rightThreshold && newValue >= rightThreshold) ||\n (previous > rightThreshold && newValue <= rightThreshold);\n\n if (hasCrossedLeftThreshold || hasCrossedRightThreshold) {\n void vibrate({ iOSFeedbackVibration: 6, pattern: [150] });\n }\n }),\n [leftThreshold, listItemXOffset, rightThreshold],\n );\n\n const handlePan = useCallback(\n (_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {\n const currentXOffset = listItemXOffset.get();\n\n const dampingFactor =\n (info.offset.x > 0 && leftActions.length > 0) ||\n (info.offset.x < 0 && rightActions.length > 0) ||\n (currentXOffset > 0 && info.delta.x < 0) ||\n (currentXOffset < 0 && info.delta.x > 0)\n ? 1\n : 0.75 / (Math.abs(info.offset.x) / 9);\n\n if (Math.abs(info.offset.x) > 30 || currentXOffset > 0) {\n listItemXOffset.set(currentXOffset + info.delta.x * dampingFactor);\n }\n },\n [leftActions.length, listItemXOffset, rightActions.length],\n );\n\n const handlePanEnd = useCallback(() => {\n const offset = listItemXOffset.get();\n\n if (offset > leftThreshold) {\n leftActions[0]?.action();\n close();\n } else if (offset < rightThreshold) {\n rightActions[rightActions.length - 1]?.action();\n close();\n } else {\n let state: 'left-open' | 'right-open' | 'closed';\n\n if (offset > 2) {\n state = 'left-open';\n } else if (offset < -2) {\n state = 'right-open';\n } else {\n state = 'closed';\n }\n\n // eslint-disable-next-line default-case\n switch (state) {\n case 'left-open':\n if (offset < SWIPEABLE_ACTION_WIDTH) {\n close();\n } else {\n open('left');\n }\n break;\n case 'right-open':\n if (offset > -SWIPEABLE_ACTION_WIDTH) {\n close();\n } else {\n open('right');\n }\n break;\n case 'closed':\n if (offset > SWIPEABLE_ACTION_WIDTH) {\n open('left');\n } else if (offset < -SWIPEABLE_ACTION_WIDTH) {\n open('right');\n } else {\n close();\n }\n }\n }\n }, [close, leftActions, leftThreshold, listItemXOffset, open, rightActions, rightThreshold]);\n\n const leftActionElements = useMemo(\n () =>\n Array.from(leftActions)\n .reverse()\n .map((item, index) => (\n <SwipeableAction\n activationThreshold={leftThreshold}\n close={close}\n index={index}\n item={item}\n key={item.key}\n listItemXOffset={listItemXOffset}\n position=\"left\"\n totalActionCount={leftActions.length}\n />\n )),\n [close, leftActions, leftThreshold, listItemXOffset],\n );\n\n const rightActionElements = useMemo(\n () =>\n rightActions.map((item, index) => (\n <SwipeableAction\n activationThreshold={rightThreshold}\n close={close}\n index={index}\n item={item}\n key={item.key}\n listItemXOffset={listItemXOffset}\n position=\"right\"\n totalActionCount={rightActions.length}\n />\n )),\n [close, rightActions, rightThreshold, listItemXOffset],\n );\n\n return (\n <StyledMotionSwipeableWrapper\n onPan={handlePan}\n onPanEnd={handlePanEnd}\n ref={swipeableWrapperRef}\n style={{ x: listItemXOffset }}\n >\n {leftActionElements}\n <StyledSwipeableWrapperContent>{children}</StyledSwipeableWrapperContent>\n {rightActionElements}\n </StyledMotionSwipeableWrapper>\n );\n};\n\nSwipeableWrapper.displayName = 'SwipeableWrapper';\n\nexport default SwipeableWrapper;\n"],"mappings":";;;;;;AAAA,IAAAA,U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I,CAACI,GAAI;IACdnD,eAAe,EAAEA,eAAgB;IACjCoD,QAAQ,EAAC,OAAO;IAChBC,gBAAgB,EAAEpE,YAAY,CAACM;EAAO,CACzC,CACJ,CAAC,EACN,CAACW,KAAK,EAAEjB,YAAY,EAAEW,cAAc,EAAEI,eAAe,CACzD,CAAC;EAED,oBACI7C,MAAA,CAAAW,OAAA,CAAAmF,aAAA,CAAC1F,iBAAA,CAAAgG,4BAA4B;IACzBC,KAAK,EAAE5B,SAAU;IACjB6B,QAAQ,EAAEnB,YAAa;IACvBoB,GAAG,EAAE5D,mBAAoB;IACzB6D,KAAK,EAAE;MAAEzB,CAAC,EAAElC;IAAgB;EAAE,GAE7ByC,kBAAkB,eACnBtF,MAAA,CAAAW,OAAA,CAAAmF,aAAA,CAAC1F,iBAAA,CAAAqG,6BAA6B,QAAE7E,QAAwC,CAAC,EACxEuE,mBACyB,CAAC;AAEvC,CAAC;AAEDzE,gBAAgB,CAACgF,WAAW,GAAG,kBAAkB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAjG,OAAA,GAEnCe,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.js","names":["vibrate","animate","useMotionValue","React","useCallback","useEffect","useMemo","useRef","useState","calcThreshold","SwipeableAction","SWIPEABLE_ACTION_WIDTH","StyledMotionSwipeableWrapper","StyledSwipeableWrapperContent","SwipeableWrapper","_ref","children","leftActions","rightActions","leftThreshold","setLeftThreshold","actionCount","length","direction","width","window","innerWidth","rightThreshold","setRightThreshold","swipeableWrapperRef","listItemXOffset","close","open","current","parentElement","offsetWidth","closeCallback","event","eventTarget","target","contains","document","addEventListener","removeEventListener","onChange","newValue","previous","getPrevious","hasCrossedLeftThreshold","hasCrossedRightThreshold","iOSFeedbackVibration","pattern","handlePan","_","info","currentXOffset","get","dampingFactor","offset","x","delta","Math","abs","set","handlePanEnd","action","state","leftActionElements","Array","from","reverse","map","item","index","createElement","activationThreshold","key","position","totalActionCount","rightActionElements","onPan","onPanEnd","ref","style","displayName"],"sources":["../../../src/components/swipeable-wrapper/SwipeableWrapper.tsx"],"sourcesContent":["import { vibrate } from 'chayns-api';\nimport { animate, PanInfo, useMotionValue } from 'framer-motion';\nimport React, {\n CSSProperties,\n FC,\n ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { calcThreshold } from '../../utils/threshold';\nimport SwipeableAction, { SWIPEABLE_ACTION_WIDTH } from './swipeable-action/SwipeableAction';\nimport {\n StyledMotionSwipeableWrapper,\n StyledSwipeableWrapperContent,\n} from './SwipeableWrapper.styles';\n\nexport type SwipeableActionItem = {\n action: VoidFunction;\n backgroundColor: CSSProperties['backgroundColor'];\n color: CSSProperties['color'];\n text?: ReactNode;\n icon: ReactNode;\n key: string;\n};\n\nexport type SwipeableWrapperProps = {\n /**\n * The content of the Swipeable item.\n */\n children: ReactNode;\n /**\n * The left-side actions, ordered from the left to the right.\n */\n leftActions?: SwipeableActionItem[];\n /**\n * The right-side actions, ordered from left to the right.\n */\n rightActions?: SwipeableActionItem[];\n};\n\nconst SwipeableWrapper: FC<SwipeableWrapperProps> = ({\n children,\n leftActions = [],\n rightActions = [],\n}) => {\n const [leftThreshold, setLeftThreshold] = useState(\n calcThreshold({\n actionCount: leftActions.length,\n direction: 'left',\n width: window.innerWidth,\n }),\n );\n\n const [rightThreshold, setRightThreshold] = useState(\n calcThreshold({\n actionCount: rightActions.length,\n direction: 'right',\n width: window.innerWidth,\n }),\n );\n\n const swipeableWrapperRef = useRef<HTMLDivElement | null>(null);\n\n const listItemXOffset = useMotionValue(0);\n\n const close = useCallback(() => {\n void animate(listItemXOffset, 0);\n }, [listItemXOffset]);\n\n const open = useCallback(\n (direction: 'left' | 'right') => {\n switch (direction) {\n case 'left':\n void animate(listItemXOffset, SWIPEABLE_ACTION_WIDTH * leftActions.length);\n break;\n case 'right':\n void animate(listItemXOffset, -SWIPEABLE_ACTION_WIDTH * rightActions.length);\n break;\n default:\n break;\n }\n },\n [leftActions.length, listItemXOffset, rightActions.length],\n );\n\n useEffect(() => {\n const width = swipeableWrapperRef.current?.parentElement?.offsetWidth;\n\n // This check was deliberately chosen because a width of 0 is also not permitted.\n if (width) {\n setLeftThreshold(\n calcThreshold({\n actionCount: leftActions.length,\n direction: 'left',\n width,\n }),\n );\n\n setRightThreshold(\n calcThreshold({\n actionCount: rightActions.length,\n direction: 'right',\n width,\n }),\n );\n }\n }, [leftActions.length, rightActions.length]);\n\n // Close an opened menu when anything outside it is tapped\n useEffect(() => {\n function closeCallback(event: MouseEvent | TouchEvent) {\n const eventTarget = event.target;\n\n // @ts-expect-error: Pretty sure that the event target is always a Node.\n if (eventTarget && !swipeableWrapperRef.current?.contains(eventTarget)) {\n close();\n }\n }\n\n document.addEventListener('mousedown', closeCallback);\n document.addEventListener('touchstart', closeCallback);\n\n return () => {\n document.removeEventListener('mousedown', closeCallback);\n document.removeEventListener('touchstart', closeCallback);\n };\n }, [close]);\n\n // Vibrate when the threshold is passed\n useEffect(\n () =>\n listItemXOffset.onChange((newValue: number) => {\n const previous = listItemXOffset.getPrevious();\n\n const hasCrossedLeftThreshold =\n (previous < leftThreshold && newValue >= leftThreshold) ||\n (previous > leftThreshold && newValue <= leftThreshold);\n\n const hasCrossedRightThreshold =\n (previous < rightThreshold && newValue >= rightThreshold) ||\n (previous > rightThreshold && newValue <= rightThreshold);\n\n if (hasCrossedLeftThreshold || hasCrossedRightThreshold) {\n void vibrate({ iOSFeedbackVibration: 6, pattern: [150] });\n }\n }),\n [leftThreshold, listItemXOffset, rightThreshold],\n );\n\n const handlePan = useCallback(\n (_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {\n const currentXOffset = listItemXOffset.get();\n\n const dampingFactor =\n (info.offset.x > 0 && leftActions.length > 0) ||\n (info.offset.x < 0 && rightActions.length > 0) ||\n (currentXOffset > 0 && info.delta.x < 0) ||\n (currentXOffset < 0 && info.delta.x > 0)\n ? 1\n : 0.75 / (Math.abs(info.offset.x) / 9);\n\n if (Math.abs(info.offset.x) > 30 || currentXOffset > 0) {\n listItemXOffset.set(currentXOffset + info.delta.x * dampingFactor);\n }\n },\n [leftActions.length, listItemXOffset, rightActions.length],\n );\n\n const handlePanEnd = useCallback(() => {\n const offset = listItemXOffset.get();\n\n if (offset > leftThreshold) {\n leftActions[0]?.action();\n close();\n } else if (offset < rightThreshold) {\n rightActions[rightActions.length - 1]?.action();\n close();\n } else {\n let state: 'left-open' | 'right-open' | 'closed';\n\n if (offset > 2) {\n state = 'left-open';\n } else if (offset < -2) {\n state = 'right-open';\n } else {\n state = 'closed';\n }\n\n // eslint-disable-next-line default-case\n switch (state) {\n case 'left-open':\n if (offset < SWIPEABLE_ACTION_WIDTH) {\n close();\n } else {\n open('left');\n }\n break;\n case 'right-open':\n if (offset > -SWIPEABLE_ACTION_WIDTH) {\n close();\n } else {\n open('right');\n }\n break;\n case 'closed':\n if (offset > SWIPEABLE_ACTION_WIDTH) {\n open('left');\n } else if (offset < -SWIPEABLE_ACTION_WIDTH) {\n open('right');\n } else {\n close();\n }\n }\n }\n }, [close, leftActions, leftThreshold, listItemXOffset, open, rightActions, rightThreshold]);\n\n const leftActionElements = useMemo(\n () =>\n Array.from(leftActions)\n .reverse()\n .map((item, index) => (\n <SwipeableAction\n activationThreshold={leftThreshold}\n close={close}\n index={index}\n item={item}\n key={item.key}\n listItemXOffset={listItemXOffset}\n position=\"left\"\n totalActionCount={leftActions.length}\n />\n )),\n [close, leftActions, leftThreshold, listItemXOffset],\n );\n\n const rightActionElements = useMemo(\n () =>\n rightActions.map((item, index) => (\n <SwipeableAction\n activationThreshold={rightThreshold}\n close={close}\n index={index}\n item={item}\n key={item.key}\n listItemXOffset={listItemXOffset}\n position=\"right\"\n totalActionCount={rightActions.length}\n />\n )),\n [close, rightActions, rightThreshold, listItemXOffset],\n );\n\n return (\n <StyledMotionSwipeableWrapper\n onPan={handlePan}\n onPanEnd={handlePanEnd}\n ref={swipeableWrapperRef}\n style={{ x: listItemXOffset }}\n >\n {leftActionElements}\n <StyledSwipeableWrapperContent>{children}</StyledSwipeableWrapperContent>\n {rightActionElements}\n </StyledMotionSwipeableWrapper>\n );\n};\n\nSwipeableWrapper.displayName = 'SwipeableWrapper';\n\nexport default SwipeableWrapper;\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,SAASC,OAAO,EAAWC,cAAc,QAAQ,eAAe;AAChE,OAAOC,KAAK,IAIRC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,aAAa,QAAQ,uBAAuB;AACrD,OAAOC,eAAe,IAAIC,sBAAsB,QAAQ,oCAAoC;AAC5F,SACIC,4BAA4B,EAC5BC,6BAA6B,QAC1B,2BAA2B;AA0BlC,MAAMC,gBAA2C,GAAGC,IAAA,IAI9C;EAAA,IAJ+C;IACjDC,QAAQ;IACRC,WAAW,GAAG,EAAE;IAChBC,YAAY,GAAG;EACnB,CAAC,GAAAH,IAAA;EACG,MAAM,CAACI,aAAa,EAAEC,gBAAgB,CAAC,GAAGZ,QAAQ,CAC9CC,aAAa,CAAC;IACVY,WAAW,EAAEJ,WAAW,CAACK,MAAM;IAC/BC,SAAS,EAAE,MAAM;IACjBC,KAAK,EAAEC,MAAM,CAACC;EAClB,CAAC,CACL,CAAC;EAED,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGpB,QAAQ,CAChDC,aAAa,CAAC;IACVY,WAAW,EAAEH,YAAY,CAACI,MAAM;IAChCC,SAAS,EAAE,OAAO;IAClBC,KAAK,EAAEC,MAAM,CAACC;EAClB,CAAC,CACL,CAAC;EAED,MAAMG,mBAAmB,GAAGtB,MAAM,CAAwB,IAAI,CAAC;EAE/D,MAAMuB,eAAe,GAAG5B,cAAc,CAAC,CAAC,CAAC;EAEzC,MAAM6B,KAAK,GAAG3B,WAAW,CAAC,MAAM;IAC5B,KAAKH,OAAO,CAAC6B,eAAe,EAAE,CAAC,CAAC;EAC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,YAAY,CAACqD,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,kBACzBtE,KAAA,CAAAuE,aAAA,CAAChE,eAAe;IACZiE,mBAAmB,EAAEhD,cAAe;IACpCI,KAAK,EAAEA,KAAM;IACb0C,KAAK,EAAEA,KAAM;IACbD,IAAI,EAAEA,IAAK;IACXI,GAAG,EAAEJ,IAAI,CAACI,GAAI;IACd9C,eAAe,EAAEA,eAAgB;IACjC+C,QAAQ,EAAC,OAAO;IAChBC,gBAAgB,EAAE5D,YAAY,CAACI;EAAO,CACzC,CACJ,CAAC,EACN,CAACS,KAAK,EAAEb,YAAY,EAAES,cAAc,EAAEG,eAAe,CACzD,CAAC;EAED,oBACI3B,KAAA,CAAAuE,aAAA,CAAC9D,4BAA4B;IACzBoE,KAAK,EAAE5B,SAAU;IACjB6B,QAAQ,EAAEjB,YAAa;IACvBkB,GAAG,EAAErD,mBAAoB;IACzBsD,KAAK,EAAE;MAAExB,CAAC,EAAE7B;IAAgB;EAAE,GAE7BqC,kBAAkB,eACnBhE,KAAA,CAAAuE,aAAA,CAAC7D,6BAA6B,QAAEG,QAAwC,CAAC,EACxE+D,mBACyB,CAAC;AAEvC,CAAC;AAEDjE,gBAAgB,CAACsE,WAAW,GAAG,kBAAkB;AAEjD,eAAetE,gBAAgB"}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.StyledSwipeableWrapperContent = exports.StyledMotionSwipeableWrapper = void 0;
|
|
7
|
-
var _framerMotion = require("framer-motion");
|
|
8
|
-
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const StyledMotionSwipeableWrapper = exports.StyledMotionSwipeableWrapper = (0, _styledComponents.default)(_framerMotion.motion.div)`
|
|
1
|
+
import { motion } from 'framer-motion';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
export const StyledMotionSwipeableWrapper = styled(motion.div)`
|
|
11
4
|
position: relative;
|
|
12
5
|
touch-action: pan-y;
|
|
13
6
|
user-select: none;
|
|
14
7
|
`;
|
|
15
|
-
const StyledSwipeableWrapperContent =
|
|
8
|
+
export const StyledSwipeableWrapperContent = styled.div`
|
|
16
9
|
overflow: hidden;
|
|
17
10
|
width: 100%;
|
|
18
11
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeableWrapper.styles.js","names":["
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.styles.js","names":["motion","styled","StyledMotionSwipeableWrapper","div","StyledSwipeableWrapperContent"],"sources":["../../../src/components/swipeable-wrapper/SwipeableWrapper.styles.ts"],"sourcesContent":["import type { FramerMotionBugFix } from '@chayns-components/core';\nimport { motion } from 'framer-motion';\nimport styled from 'styled-components';\n\nexport const StyledMotionSwipeableWrapper = styled(motion.div)<FramerMotionBugFix>`\n position: relative;\n touch-action: pan-y;\n user-select: none;\n`;\n\nexport const StyledSwipeableWrapperContent = styled.div`\n overflow: hidden;\n width: 100%;\n`;\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,4BAA4B,GAAGD,MAAM,CAACD,MAAM,CAACG,GAAG,CAAsB;AACnF;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,6BAA6B,GAAGH,MAAM,CAACE,GAAI;AACxD;AACA;AACA,CAAC"}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.SWIPEABLE_ACTION_WIDTH = void 0;
|
|
7
|
-
var _framerMotion = require("framer-motion");
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _SwipeableAction = require("./SwipeableAction.styles");
|
|
10
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
-
const SWIPEABLE_ACTION_WIDTH = exports.SWIPEABLE_ACTION_WIDTH = 72;
|
|
1
|
+
import { useSpring, useTransform } from 'framer-motion';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import { StyledMotionSwipeableAction, StyledSwipeableActionButton } from './SwipeableAction.styles';
|
|
4
|
+
export const SWIPEABLE_ACTION_WIDTH = 72;
|
|
13
5
|
const SwipeableAction = _ref => {
|
|
14
6
|
let {
|
|
15
7
|
activationThreshold,
|
|
@@ -29,7 +21,7 @@ const SwipeableAction = _ref => {
|
|
|
29
21
|
* By default, the action sticks to the content of the swipeable item. This
|
|
30
22
|
* makes it move outwards to reveal the inner items.
|
|
31
23
|
*/
|
|
32
|
-
const actionOffset =
|
|
24
|
+
const actionOffset = useTransform(listItemXOffset, newValue => {
|
|
33
25
|
const maxOffset = SWIPEABLE_ACTION_WIDTH * index;
|
|
34
26
|
const fractionalOffset = -newValue / totalActionCount * index;
|
|
35
27
|
switch (position) {
|
|
@@ -46,7 +38,7 @@ const SwipeableAction = _ref => {
|
|
|
46
38
|
* Brings the item in again if past the threshold. Only relevant for
|
|
47
39
|
* outermost items.
|
|
48
40
|
*/
|
|
49
|
-
const actionOverlayOffset =
|
|
41
|
+
const actionOverlayOffset = useSpring(0, {
|
|
50
42
|
bounce: 0
|
|
51
43
|
});
|
|
52
44
|
|
|
@@ -54,7 +46,7 @@ const SwipeableAction = _ref => {
|
|
|
54
46
|
* Combines the two values above to create the correct X transform that has
|
|
55
47
|
* to be applied to the action.
|
|
56
48
|
*/
|
|
57
|
-
const actionX =
|
|
49
|
+
const actionX = useTransform([actionOffset, actionOverlayOffset], _ref2 => {
|
|
58
50
|
let [x, y] = _ref2;
|
|
59
51
|
if (position === 'left') {
|
|
60
52
|
return Math.min((x ?? 0) + (y ?? 0), 0);
|
|
@@ -63,7 +55,7 @@ const SwipeableAction = _ref => {
|
|
|
63
55
|
});
|
|
64
56
|
|
|
65
57
|
// Animate to the middle after passing threshold if outermost item
|
|
66
|
-
|
|
58
|
+
useEffect(() => {
|
|
67
59
|
const isOuterMost = index === totalActionCount - 1;
|
|
68
60
|
if (!isOuterMost) return undefined;
|
|
69
61
|
return listItemXOffset.onChange(newValue => {
|
|
@@ -87,18 +79,18 @@ const SwipeableAction = _ref => {
|
|
|
87
79
|
}
|
|
88
80
|
});
|
|
89
81
|
}, [actionOverlayOffset, activationThreshold, index, listItemXOffset, position, totalActionCount]);
|
|
90
|
-
return /*#__PURE__*/
|
|
82
|
+
return /*#__PURE__*/React.createElement(StyledMotionSwipeableAction, {
|
|
91
83
|
backgroundColor: item.backgroundColor,
|
|
92
84
|
position: position,
|
|
93
85
|
style: {
|
|
94
86
|
x: actionX
|
|
95
87
|
}
|
|
96
|
-
}, /*#__PURE__*/
|
|
88
|
+
}, /*#__PURE__*/React.createElement(StyledSwipeableActionButton, {
|
|
97
89
|
color: item.color,
|
|
98
90
|
onClick: handleButtonClick,
|
|
99
91
|
width: `${SWIPEABLE_ACTION_WIDTH}px`
|
|
100
92
|
}, item.icon, item.text));
|
|
101
93
|
};
|
|
102
94
|
SwipeableAction.displayName = 'SwipeableAction';
|
|
103
|
-
|
|
95
|
+
export default SwipeableAction;
|
|
104
96
|
//# sourceMappingURL=SwipeableAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeableAction.js","names":["
|
|
1
|
+
{"version":3,"file":"SwipeableAction.js","names":["useSpring","useTransform","React","useEffect","StyledMotionSwipeableAction","StyledSwipeableActionButton","SWIPEABLE_ACTION_WIDTH","SwipeableAction","_ref","activationThreshold","close","index","item","listItemXOffset","position","totalActionCount","handleButtonClick","action","actionOffset","newValue","maxOffset","fractionalOffset","Math","max","min","actionOverlayOffset","bounce","actionX","_ref2","x","y","isOuterMost","undefined","onChange","lastValue","getPrevious","set","createElement","backgroundColor","style","color","onClick","width","icon","text","displayName"],"sources":["../../../../src/components/swipeable-wrapper/swipeable-action/SwipeableAction.tsx"],"sourcesContent":["import { MotionValue, useSpring, useTransform } from 'framer-motion';\nimport React, { FC, useEffect } from 'react';\nimport type { SwipeableActionItem } from '../SwipeableWrapper';\nimport { StyledMotionSwipeableAction, StyledSwipeableActionButton } from './SwipeableAction.styles';\n\nexport const SWIPEABLE_ACTION_WIDTH = 72;\n\nexport type SwipeableActionProps = {\n activationThreshold: number;\n close: VoidFunction;\n index: number;\n item: SwipeableActionItem;\n listItemXOffset: MotionValue<number>;\n position: 'left' | 'right';\n totalActionCount: number;\n};\n\nconst SwipeableAction: FC<SwipeableActionProps> = ({\n activationThreshold,\n close,\n index,\n item,\n listItemXOffset,\n position,\n totalActionCount,\n}) => {\n const handleButtonClick = () => {\n item.action();\n close();\n };\n\n /**\n * By default, the action sticks to the content of the swipeable item. This\n * makes it move outwards to reveal the inner items.\n */\n const actionOffset = useTransform(listItemXOffset, (newValue) => {\n const maxOffset = SWIPEABLE_ACTION_WIDTH * index;\n const fractionalOffset = (-newValue / totalActionCount) * index;\n\n switch (position) {\n case 'left':\n return Math.max(-maxOffset, fractionalOffset);\n case 'right':\n return Math.min(maxOffset, fractionalOffset);\n default:\n return 0;\n }\n });\n\n /**\n * Brings the item in again if past the threshold. Only relevant for\n * outermost items.\n */\n const actionOverlayOffset = useSpring(0, {\n bounce: 0,\n }) as MotionValue<number>;\n\n /**\n * Combines the two values above to create the correct X transform that has\n * to be applied to the action.\n */\n const actionX = useTransform<number, number>([actionOffset, actionOverlayOffset], ([x, y]) => {\n if (position === 'left') {\n return Math.min((x ?? 0) + (y ?? 0), 0);\n }\n\n return Math.max((x ?? 0) + (y ?? 0), 0);\n });\n\n // Animate to the middle after passing threshold if outermost item\n useEffect(() => {\n const isOuterMost = index === totalActionCount - 1;\n\n if (!isOuterMost) return undefined;\n\n return listItemXOffset.onChange((newValue) => {\n const lastValue = listItemXOffset.getPrevious();\n\n // eslint-disable-next-line default-case\n switch (position) {\n case 'left':\n if (newValue > activationThreshold && lastValue <= activationThreshold) {\n actionOverlayOffset.set(SWIPEABLE_ACTION_WIDTH * index);\n } else if (newValue < activationThreshold && lastValue >= activationThreshold) {\n actionOverlayOffset.set(0);\n }\n break;\n case 'right':\n if (newValue < activationThreshold && lastValue >= activationThreshold) {\n actionOverlayOffset.set(SWIPEABLE_ACTION_WIDTH * -1 * index);\n } else if (newValue > activationThreshold && lastValue <= activationThreshold) {\n actionOverlayOffset.set(0);\n }\n }\n });\n }, [\n actionOverlayOffset,\n activationThreshold,\n index,\n listItemXOffset,\n position,\n totalActionCount,\n ]);\n\n return (\n <StyledMotionSwipeableAction\n backgroundColor={item.backgroundColor}\n position={position}\n style={{ x: actionX }}\n >\n <StyledSwipeableActionButton\n color={item.color}\n onClick={handleButtonClick}\n width={`${SWIPEABLE_ACTION_WIDTH}px`}\n >\n {item.icon}\n {item.text}\n </StyledSwipeableActionButton>\n </StyledMotionSwipeableAction>\n );\n};\n\nSwipeableAction.displayName = 'SwipeableAction';\n\nexport default SwipeableAction;\n"],"mappings":"AAAA,SAAsBA,SAAS,EAAEC,YAAY,QAAQ,eAAe;AACpE,OAAOC,KAAK,IAAQC,SAAS,QAAQ,OAAO;AAE5C,SAASC,2BAA2B,EAAEC,2BAA2B,QAAQ,0BAA0B;AAEnG,OAAO,MAAMC,sBAAsB,GAAG,EAAE;AAY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AS;IACnByB,KAAK,EAAE;MAAEV,CAAC,EAAEF;IAAQ;EAAE,gBAEtBzB,KAAA,CAAAmC,aAAA,CAAChC,2BAA2B;IACxBmC,KAAK,EAAE5B,IAAI,CAAC4B,KAAM;IAClBC,OAAO,EAAEzB,iBAAkB;IAC3B0B,KAAK,EAAG,GAAEpC,sBAAuB;EAAI,GAEpCM,IAAI,CAAC+B,IAAI,EACT/B,IAAI,CAACgC,IACmB,CACJ,CAAC;AAEtC,CAAC;AAEDrC,eAAe,CAACsC,WAAW,GAAG,iBAAiB;AAE/C,eAAetC,eAAe"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.StyledSwipeableActionButton = exports.StyledMotionSwipeableAction = void 0;
|
|
7
|
-
var _framerMotion = require("framer-motion");
|
|
8
|
-
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
-
const StyledMotionSwipeableAction = exports.StyledMotionSwipeableAction = (0, _styledComponents.default)(_framerMotion.motion.div)`
|
|
1
|
+
import { motion } from 'framer-motion';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
export const StyledMotionSwipeableAction = styled(motion.div)`
|
|
12
4
|
background-color: ${_ref => {
|
|
13
5
|
let {
|
|
14
6
|
backgroundColor
|
|
@@ -26,18 +18,18 @@ const StyledMotionSwipeableAction = exports.StyledMotionSwipeableAction = (0, _s
|
|
|
26
18
|
position
|
|
27
19
|
} = _ref2;
|
|
28
20
|
if (position === 'left') {
|
|
29
|
-
return
|
|
21
|
+
return css`
|
|
30
22
|
justify-content: flex-end;
|
|
31
23
|
right: 100%;
|
|
32
24
|
`;
|
|
33
25
|
}
|
|
34
|
-
return
|
|
26
|
+
return css`
|
|
35
27
|
justify-content: flex-start;
|
|
36
28
|
left: 100%;
|
|
37
29
|
`;
|
|
38
30
|
}}
|
|
39
31
|
`;
|
|
40
|
-
const StyledSwipeableActionButton =
|
|
32
|
+
export const StyledSwipeableActionButton = styled.button`
|
|
41
33
|
align-items: center;
|
|
42
34
|
appearance: none;
|
|
43
35
|
background: none;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeableAction.styles.js","names":["
|
|
1
|
+
{"version":3,"file":"SwipeableAction.styles.js","names":["motion","styled","css","StyledMotionSwipeableAction","div","_ref","backgroundColor","_ref2","position","StyledSwipeableActionButton","button","_ref3","color","_ref4","width"],"sources":["../../../../src/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport type { CSSProperties } from 'react';\nimport styled, { css } from 'styled-components';\nimport type { SwipeableActionItem } from '../SwipeableWrapper';\nimport type { SwipeableActionProps } from './SwipeableAction';\n\ntype StyledSwipeableActionProps = Pick<SwipeableActionProps, 'position'> &\n Pick<SwipeableActionItem, 'backgroundColor'>;\n\nexport const StyledMotionSwipeableAction = styled(motion.div)<StyledSwipeableActionProps>`\n background-color: ${({ backgroundColor }) => backgroundColor};\n display: flex;\n height: 100%;\n position: absolute;\n top: 0;\n width: 200vw;\n\n ${({ position }) => {\n if (position === 'left') {\n return css`\n justify-content: flex-end;\n right: 100%;\n `;\n }\n return css`\n justify-content: flex-start;\n left: 100%;\n `;\n }}\n`;\n\ntype StyledSwipeableActionButtonsProps = Pick<SwipeableActionItem, 'color'> & {\n width: CSSProperties['width'];\n};\n\nexport const StyledSwipeableActionButton = styled.button<StyledSwipeableActionButtonsProps>`\n align-items: center;\n appearance: none;\n background: none;\n box-shadow: none;\n color: ${({ color }) => color};\n display: flex;\n flex-direction: column;\n font-size: 88%;\n gap: 4px;\n height: 100%;\n justify-content: center;\n margin: 0;\n padding: 0;\n width: ${({ width }) => width};\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AAEtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAO/C,OAAO,MAAMC,2BAA2B,GAAGF,MAAM,CAACD,MAAM,CAACI,GAAG,CAA8B;AAC1F,wBAAwBC,IAAA;EAAA,IAAC;IAAEC;EAAgB,CAAC,GAAAD,IAAA;EAAA,OAAKC,eAAe;AAAA,CAAC;AACjE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAA,IAAkB;EAAA,IAAjB;IAAEC;EAAS,CAAC,GAAAD,KAAA;EACX,IAAIC,QAAQ,KAAK,MAAM,EAAE;IACrB,OAAON,GAAI;AACvB;AACA;AACA,aAAa;EACL;EACA,OAAOA,GAAI;AACnB;AACA;AACA,SAAS;AACL,CAAE;AACN,CAAC;AAMD,OAAO,MAAMO,2BAA2B,GAAGR,MAAM,CAACS,MAA0C;AAC5F;AACA;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEC;EAAM,CAAC,GAAAD,KAAA;EAAA,OAAKC,KAAK;AAAA,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEC;EAAM,CAAC,GAAAD,KAAA;EAAA,OAAKC,KAAK;AAAA,CAAC;AAClC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "SwipeableWrapper", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _SwipeableWrapper.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _SwipeableWrapper = _interopRequireDefault(require("./components/swipeable-wrapper/SwipeableWrapper"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
export { default as SwipeableWrapper } from './components/swipeable-wrapper/SwipeableWrapper';
|
|
14
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","SwipeableWrapper"],"sources":["../src/index.ts"],"sourcesContent":["export { default as SwipeableWrapper } from './components/swipeable-wrapper/SwipeableWrapper';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,gBAAgB,QAAQ,iDAAiD"}
|
package/lib/utils/threshold.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.calcThreshold = void 0;
|
|
7
|
-
var _SwipeableAction = require("../components/swipeable-wrapper/swipeable-action/SwipeableAction");
|
|
8
|
-
const calcThreshold = _ref => {
|
|
1
|
+
import { SWIPEABLE_ACTION_WIDTH } from '../components/swipeable-wrapper/swipeable-action/SwipeableAction';
|
|
2
|
+
export const calcThreshold = _ref => {
|
|
9
3
|
let {
|
|
10
4
|
actionCount,
|
|
11
5
|
direction,
|
|
12
6
|
width
|
|
13
7
|
} = _ref;
|
|
14
|
-
return Math.max(width / 2,
|
|
8
|
+
return Math.max(width / 2, SWIPEABLE_ACTION_WIDTH * actionCount) * (direction === 'left' ? 1 : -1);
|
|
15
9
|
};
|
|
16
|
-
exports.calcThreshold = calcThreshold;
|
|
17
10
|
//# sourceMappingURL=threshold.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threshold.js","names":["
|
|
1
|
+
{"version":3,"file":"threshold.js","names":["SWIPEABLE_ACTION_WIDTH","calcThreshold","_ref","actionCount","direction","width","Math","max"],"sources":["../../src/utils/threshold.ts"],"sourcesContent":["import { SWIPEABLE_ACTION_WIDTH } from '../components/swipeable-wrapper/swipeable-action/SwipeableAction';\n\ninterface CalcThresholdOptions {\n actionCount: number;\n direction: 'left' | 'right';\n width: number;\n}\n\nexport const calcThreshold = ({ actionCount, direction, width }: CalcThresholdOptions) =>\n Math.max(width / 2, SWIPEABLE_ACTION_WIDTH * actionCount) * (direction === 'left' ? 1 : -1);\n"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,kEAAkE;AAQzG,OAAO,MAAMC,aAAa,GAAGC,IAAA;EAAA,IAAC;IAAEC,WAAW;IAAEC,SAAS;IAAEC;EAA4B,CAAC,GAAAH,IAAA;EAAA,OACjFI,IAAI,CAACC,GAAG,CAACF,KAAK,GAAG,CAAC,EAAEL,sBAAsB,GAAGG,WAAW,CAAC,IAAIC,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/swipeable-wrapper",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.443",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -33,24 +33,24 @@
|
|
|
33
33
|
"url": "https://github.com/TobitSoftware/chayns-components/issues"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@babel/cli": "^7.23.
|
|
37
|
-
"@babel/core": "^7.23.
|
|
38
|
-
"@babel/preset-env": "^7.23.
|
|
36
|
+
"@babel/cli": "^7.23.9",
|
|
37
|
+
"@babel/core": "^7.23.9",
|
|
38
|
+
"@babel/preset-env": "^7.23.9",
|
|
39
39
|
"@babel/preset-react": "^7.23.3",
|
|
40
40
|
"@babel/preset-typescript": "^7.23.3",
|
|
41
|
-
"@types/react": "^18.2.
|
|
42
|
-
"@types/react-dom": "^18.2.
|
|
41
|
+
"@types/react": "^18.2.55",
|
|
42
|
+
"@types/react-dom": "^18.2.19",
|
|
43
43
|
"@types/styled-components": "^5.1.34",
|
|
44
|
-
"@types/uuid": "^9.0.
|
|
44
|
+
"@types/uuid": "^9.0.8",
|
|
45
45
|
"babel-loader": "^9.1.3",
|
|
46
|
-
"lerna": "^8.
|
|
46
|
+
"lerna": "^8.1.2",
|
|
47
47
|
"react": "^18.2.0",
|
|
48
48
|
"react-dom": "^18.2.0",
|
|
49
49
|
"styled-components": "^6.1.8",
|
|
50
50
|
"typescript": "^5.3.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@chayns-components/core": "^5.0.0-beta.
|
|
53
|
+
"@chayns-components/core": "^5.0.0-beta.443"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"chayns-api": ">=1.0.50",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "3f3e8b424de86b8597fd4670766a496a767ee1ba"
|
|
66
66
|
}
|