@chayns-components/swipeable-wrapper 5.0.0-beta.577 → 5.0.0-beta.578
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/cjs/components/swipeable-wrapper/SwipeableWrapper.js +182 -0
- package/lib/cjs/components/swipeable-wrapper/SwipeableWrapper.js.map +1 -0
- package/lib/cjs/components/swipeable-wrapper/SwipeableWrapper.styles.js +19 -0
- package/lib/cjs/components/swipeable-wrapper/SwipeableWrapper.styles.js.map +1 -0
- package/lib/cjs/components/swipeable-wrapper/swipeable-action/SwipeableAction.js +102 -0
- package/lib/cjs/components/swipeable-wrapper/swipeable-action/SwipeableAction.js.map +1 -0
- package/lib/cjs/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js +56 -0
- package/lib/cjs/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js.map +1 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/utils/threshold.js +14 -0
- package/lib/cjs/utils/threshold.js.map +1 -0
- package/lib/esm/components/swipeable-wrapper/SwipeableWrapper.js.map +1 -0
- package/lib/esm/components/swipeable-wrapper/SwipeableWrapper.styles.js.map +1 -0
- package/lib/esm/components/swipeable-wrapper/swipeable-action/SwipeableAction.js.map +1 -0
- package/lib/esm/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js.map +1 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/utils/threshold.js.map +1 -0
- package/lib/{components → types/components}/swipeable-wrapper/SwipeableWrapper.styles.d.ts +1 -1
- package/package.json +17 -7
- package/lib/components/swipeable-wrapper/SwipeableWrapper.js.map +0 -1
- package/lib/components/swipeable-wrapper/SwipeableWrapper.styles.js.map +0 -1
- package/lib/components/swipeable-wrapper/swipeable-action/SwipeableAction.js.map +0 -1
- package/lib/components/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/utils/threshold.js.map +0 -1
- /package/lib/{components → esm/components}/swipeable-wrapper/SwipeableWrapper.js +0 -0
- /package/lib/{components → esm/components}/swipeable-wrapper/SwipeableWrapper.styles.js +0 -0
- /package/lib/{components → esm/components}/swipeable-wrapper/swipeable-action/SwipeableAction.js +0 -0
- /package/lib/{components → esm/components}/swipeable-wrapper/swipeable-action/SwipeableAction.styles.js +0 -0
- /package/lib/{index.js → esm/index.js} +0 -0
- /package/lib/{utils → esm/utils}/threshold.js +0 -0
- /package/lib/{components → types/components}/swipeable-wrapper/SwipeableWrapper.d.ts +0 -0
- /package/lib/{components → types/components}/swipeable-wrapper/swipeable-action/SwipeableAction.d.ts +0 -0
- /package/lib/{components → types/components}/swipeable-wrapper/swipeable-action/SwipeableAction.styles.d.ts +0 -0
- /package/lib/{index.d.ts → types/index.d.ts} +0 -0
- /package/lib/{utils → types/utils}/threshold.d.ts +0 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
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 && {}.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; }
|
|
15
|
+
const SwipeableWrapper = ({
|
|
16
|
+
children,
|
|
17
|
+
leftActions = [],
|
|
18
|
+
rightActions = []
|
|
19
|
+
}) => {
|
|
20
|
+
const [leftThreshold, setLeftThreshold] = (0, _react.useState)((0, _threshold.calcThreshold)({
|
|
21
|
+
actionCount: leftActions.length,
|
|
22
|
+
direction: 'left',
|
|
23
|
+
width: window.innerWidth
|
|
24
|
+
}));
|
|
25
|
+
const [rightThreshold, setRightThreshold] = (0, _react.useState)((0, _threshold.calcThreshold)({
|
|
26
|
+
actionCount: rightActions.length,
|
|
27
|
+
direction: 'right',
|
|
28
|
+
width: window.innerWidth
|
|
29
|
+
}));
|
|
30
|
+
const swipeableWrapperRef = (0, _react.useRef)(null);
|
|
31
|
+
const listItemXOffset = (0, _framerMotion.useMotionValue)(0);
|
|
32
|
+
const close = (0, _react.useCallback)(() => {
|
|
33
|
+
void (0, _framerMotion.animate)(listItemXOffset, 0);
|
|
34
|
+
}, [listItemXOffset]);
|
|
35
|
+
const open = (0, _react.useCallback)(direction => {
|
|
36
|
+
switch (direction) {
|
|
37
|
+
case 'left':
|
|
38
|
+
void (0, _framerMotion.animate)(listItemXOffset, _SwipeableAction.SWIPEABLE_ACTION_WIDTH * leftActions.length);
|
|
39
|
+
break;
|
|
40
|
+
case 'right':
|
|
41
|
+
void (0, _framerMotion.animate)(listItemXOffset, -_SwipeableAction.SWIPEABLE_ACTION_WIDTH * rightActions.length);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}, [leftActions.length, listItemXOffset, rightActions.length]);
|
|
47
|
+
(0, _react.useEffect)(() => {
|
|
48
|
+
var _swipeableWrapperRef$;
|
|
49
|
+
const width = (_swipeableWrapperRef$ = swipeableWrapperRef.current) === null || _swipeableWrapperRef$ === void 0 || (_swipeableWrapperRef$ = _swipeableWrapperRef$.parentElement) === null || _swipeableWrapperRef$ === void 0 ? void 0 : _swipeableWrapperRef$.offsetWidth;
|
|
50
|
+
|
|
51
|
+
// This check was deliberately chosen because a width of 0 is also not permitted.
|
|
52
|
+
if (width) {
|
|
53
|
+
setLeftThreshold((0, _threshold.calcThreshold)({
|
|
54
|
+
actionCount: leftActions.length,
|
|
55
|
+
direction: 'left',
|
|
56
|
+
width
|
|
57
|
+
}));
|
|
58
|
+
setRightThreshold((0, _threshold.calcThreshold)({
|
|
59
|
+
actionCount: rightActions.length,
|
|
60
|
+
direction: 'right',
|
|
61
|
+
width
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}, [leftActions.length, rightActions.length]);
|
|
65
|
+
|
|
66
|
+
// Close an opened menu when anything outside it is tapped
|
|
67
|
+
(0, _react.useEffect)(() => {
|
|
68
|
+
function closeCallback(event) {
|
|
69
|
+
var _swipeableWrapperRef$2;
|
|
70
|
+
const eventTarget = event.target;
|
|
71
|
+
|
|
72
|
+
// @ts-expect-error: Pretty sure that the event target is always a Node.
|
|
73
|
+
if (eventTarget && !((_swipeableWrapperRef$2 = swipeableWrapperRef.current) !== null && _swipeableWrapperRef$2 !== void 0 && _swipeableWrapperRef$2.contains(eventTarget))) {
|
|
74
|
+
close();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
document.addEventListener('mousedown', closeCallback);
|
|
78
|
+
document.addEventListener('touchstart', closeCallback);
|
|
79
|
+
return () => {
|
|
80
|
+
document.removeEventListener('mousedown', closeCallback);
|
|
81
|
+
document.removeEventListener('touchstart', closeCallback);
|
|
82
|
+
};
|
|
83
|
+
}, [close]);
|
|
84
|
+
|
|
85
|
+
// Vibrate when the threshold is passed
|
|
86
|
+
(0, _react.useEffect)(() => listItemXOffset.onChange(newValue => {
|
|
87
|
+
const previous = listItemXOffset.getPrevious();
|
|
88
|
+
const hasCrossedLeftThreshold = previous < leftThreshold && newValue >= leftThreshold || previous > leftThreshold && newValue <= leftThreshold;
|
|
89
|
+
const hasCrossedRightThreshold = previous < rightThreshold && newValue >= rightThreshold || previous > rightThreshold && newValue <= rightThreshold;
|
|
90
|
+
if (hasCrossedLeftThreshold || hasCrossedRightThreshold) {
|
|
91
|
+
void (0, _chaynsApi.vibrate)({
|
|
92
|
+
iOSFeedbackVibration: 6,
|
|
93
|
+
pattern: [150]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}), [leftThreshold, listItemXOffset, rightThreshold]);
|
|
97
|
+
const handlePan = (0, _react.useCallback)((_, info) => {
|
|
98
|
+
const currentXOffset = listItemXOffset.get();
|
|
99
|
+
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);
|
|
100
|
+
if (Math.abs(info.offset.x) > 30 || currentXOffset > 0) {
|
|
101
|
+
listItemXOffset.set(currentXOffset + info.delta.x * dampingFactor);
|
|
102
|
+
}
|
|
103
|
+
}, [leftActions.length, listItemXOffset, rightActions.length]);
|
|
104
|
+
const handlePanEnd = (0, _react.useCallback)(() => {
|
|
105
|
+
const offset = listItemXOffset.get();
|
|
106
|
+
if (offset > leftThreshold) {
|
|
107
|
+
var _leftActions$;
|
|
108
|
+
(_leftActions$ = leftActions[0]) === null || _leftActions$ === void 0 || _leftActions$.action();
|
|
109
|
+
close();
|
|
110
|
+
} else if (offset < rightThreshold) {
|
|
111
|
+
var _rightActions;
|
|
112
|
+
(_rightActions = rightActions[rightActions.length - 1]) === null || _rightActions === void 0 || _rightActions.action();
|
|
113
|
+
close();
|
|
114
|
+
} else {
|
|
115
|
+
let state;
|
|
116
|
+
if (offset > 2) {
|
|
117
|
+
state = 'left-open';
|
|
118
|
+
} else if (offset < -2) {
|
|
119
|
+
state = 'right-open';
|
|
120
|
+
} else {
|
|
121
|
+
state = 'closed';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// eslint-disable-next-line default-case
|
|
125
|
+
switch (state) {
|
|
126
|
+
case 'left-open':
|
|
127
|
+
if (offset < _SwipeableAction.SWIPEABLE_ACTION_WIDTH) {
|
|
128
|
+
close();
|
|
129
|
+
} else {
|
|
130
|
+
open('left');
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case 'right-open':
|
|
134
|
+
if (offset > -_SwipeableAction.SWIPEABLE_ACTION_WIDTH) {
|
|
135
|
+
close();
|
|
136
|
+
} else {
|
|
137
|
+
open('right');
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case 'closed':
|
|
141
|
+
if (offset > _SwipeableAction.SWIPEABLE_ACTION_WIDTH) {
|
|
142
|
+
open('left');
|
|
143
|
+
} else if (offset < -_SwipeableAction.SWIPEABLE_ACTION_WIDTH) {
|
|
144
|
+
open('right');
|
|
145
|
+
} else {
|
|
146
|
+
close();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}, [close, leftActions, leftThreshold, listItemXOffset, open, rightActions, rightThreshold]);
|
|
151
|
+
const leftActionElements = (0, _react.useMemo)(() => Array.from(leftActions).reverse().map((item, index) => /*#__PURE__*/_react.default.createElement(_SwipeableAction.default, {
|
|
152
|
+
activationThreshold: leftThreshold,
|
|
153
|
+
close: close,
|
|
154
|
+
index: index,
|
|
155
|
+
item: item,
|
|
156
|
+
key: item.key,
|
|
157
|
+
listItemXOffset: listItemXOffset,
|
|
158
|
+
position: "left",
|
|
159
|
+
totalActionCount: leftActions.length
|
|
160
|
+
})), [close, leftActions, leftThreshold, listItemXOffset]);
|
|
161
|
+
const rightActionElements = (0, _react.useMemo)(() => rightActions.map((item, index) => /*#__PURE__*/_react.default.createElement(_SwipeableAction.default, {
|
|
162
|
+
activationThreshold: rightThreshold,
|
|
163
|
+
close: close,
|
|
164
|
+
index: index,
|
|
165
|
+
item: item,
|
|
166
|
+
key: item.key,
|
|
167
|
+
listItemXOffset: listItemXOffset,
|
|
168
|
+
position: "right",
|
|
169
|
+
totalActionCount: rightActions.length
|
|
170
|
+
})), [close, rightActions, rightThreshold, listItemXOffset]);
|
|
171
|
+
return /*#__PURE__*/_react.default.createElement(_SwipeableWrapper.StyledMotionSwipeableWrapper, {
|
|
172
|
+
onPan: handlePan,
|
|
173
|
+
onPanEnd: handlePanEnd,
|
|
174
|
+
ref: swipeableWrapperRef,
|
|
175
|
+
style: {
|
|
176
|
+
x: listItemXOffset
|
|
177
|
+
}
|
|
178
|
+
}, leftActionElements, /*#__PURE__*/_react.default.createElement(_SwipeableWrapper.StyledSwipeableWrapperContent, null, children), rightActionElements);
|
|
179
|
+
};
|
|
180
|
+
SwipeableWrapper.displayName = 'SwipeableWrapper';
|
|
181
|
+
var _default = exports.default = SwipeableWrapper;
|
|
182
|
+
//# sourceMappingURL=SwipeableWrapper.js.map
|
|
@@ -0,0 +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","hasOwnProperty","call","i","set","SwipeableWrapper","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","_swipeableWrapperRef$","current","parentElement","offsetWidth","closeCallback","event","_swipeableWrapperRef$2","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","_leftActions$","action","_rightActions","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,UAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AAUA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAF,uBAAA,CAAAH,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAGmC,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,I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AAG,kBAAkB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAnG,OAAA,GAEnCc,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
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)`
|
|
11
|
+
position: relative;
|
|
12
|
+
touch-action: pan-y;
|
|
13
|
+
user-select: none;
|
|
14
|
+
`;
|
|
15
|
+
const StyledSwipeableWrapperContent = exports.StyledSwipeableWrapperContent = _styledComponents.default.div`
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
width: 100%;
|
|
18
|
+
`;
|
|
19
|
+
//# sourceMappingURL=SwipeableWrapper.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableWrapper.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireDefault","obj","__esModule","default","StyledMotionSwipeableWrapper","exports","styled","motion","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,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAuC,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEhC,MAAMG,4BAA4B,GAAAC,OAAA,CAAAD,4BAAA,GAAG,IAAAE,yBAAM,EAACC,oBAAM,CAACC,GAAG,CAAsB;AACnF;AACA;AACA;AACA,CAAC;AAEM,MAAMC,6BAA6B,GAAAJ,OAAA,CAAAI,6BAAA,GAAGH,yBAAM,CAACE,GAAI;AACxD;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
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 && {}.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;
|
|
13
|
+
const SwipeableAction = ({
|
|
14
|
+
activationThreshold,
|
|
15
|
+
close,
|
|
16
|
+
index,
|
|
17
|
+
item,
|
|
18
|
+
listItemXOffset,
|
|
19
|
+
position,
|
|
20
|
+
totalActionCount
|
|
21
|
+
}) => {
|
|
22
|
+
const handleButtonClick = () => {
|
|
23
|
+
item.action();
|
|
24
|
+
close();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* By default, the action sticks to the content of the swipeable item. This
|
|
29
|
+
* makes it move outwards to reveal the inner items.
|
|
30
|
+
*/
|
|
31
|
+
const actionOffset = (0, _framerMotion.useTransform)(listItemXOffset, newValue => {
|
|
32
|
+
const maxOffset = SWIPEABLE_ACTION_WIDTH * index;
|
|
33
|
+
const fractionalOffset = -newValue / totalActionCount * index;
|
|
34
|
+
switch (position) {
|
|
35
|
+
case 'left':
|
|
36
|
+
return Math.max(-maxOffset, fractionalOffset);
|
|
37
|
+
case 'right':
|
|
38
|
+
return Math.min(maxOffset, fractionalOffset);
|
|
39
|
+
default:
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Brings the item in again if past the threshold. Only relevant for
|
|
46
|
+
* outermost items.
|
|
47
|
+
*/
|
|
48
|
+
const actionOverlayOffset = (0, _framerMotion.useSpring)(0, {
|
|
49
|
+
bounce: 0
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Combines the two values above to create the correct X transform that has
|
|
54
|
+
* to be applied to the action.
|
|
55
|
+
*/
|
|
56
|
+
const actionX = (0, _framerMotion.useTransform)([actionOffset, actionOverlayOffset], ([x, y]) => {
|
|
57
|
+
if (position === 'left') {
|
|
58
|
+
return Math.min((x ?? 0) + (y ?? 0), 0);
|
|
59
|
+
}
|
|
60
|
+
return Math.max((x ?? 0) + (y ?? 0), 0);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Animate to the middle after passing threshold if outermost item
|
|
64
|
+
(0, _react.useEffect)(() => {
|
|
65
|
+
const isOuterMost = index === totalActionCount - 1;
|
|
66
|
+
if (!isOuterMost) return undefined;
|
|
67
|
+
return listItemXOffset.onChange(newValue => {
|
|
68
|
+
const lastValue = listItemXOffset.getPrevious();
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line default-case
|
|
71
|
+
switch (position) {
|
|
72
|
+
case 'left':
|
|
73
|
+
if (newValue > activationThreshold && lastValue <= activationThreshold) {
|
|
74
|
+
actionOverlayOffset.set(SWIPEABLE_ACTION_WIDTH * index);
|
|
75
|
+
} else if (newValue < activationThreshold && lastValue >= activationThreshold) {
|
|
76
|
+
actionOverlayOffset.set(0);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case 'right':
|
|
80
|
+
if (newValue < activationThreshold && lastValue >= activationThreshold) {
|
|
81
|
+
actionOverlayOffset.set(SWIPEABLE_ACTION_WIDTH * -1 * index);
|
|
82
|
+
} else if (newValue > activationThreshold && lastValue <= activationThreshold) {
|
|
83
|
+
actionOverlayOffset.set(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}, [actionOverlayOffset, activationThreshold, index, listItemXOffset, position, totalActionCount]);
|
|
88
|
+
return /*#__PURE__*/_react.default.createElement(_SwipeableAction.StyledMotionSwipeableAction, {
|
|
89
|
+
$backgroundColor: item.backgroundColor,
|
|
90
|
+
$position: position,
|
|
91
|
+
style: {
|
|
92
|
+
x: actionX
|
|
93
|
+
}
|
|
94
|
+
}, /*#__PURE__*/_react.default.createElement(_SwipeableAction.StyledSwipeableActionButton, {
|
|
95
|
+
$color: item.color,
|
|
96
|
+
onClick: handleButtonClick,
|
|
97
|
+
$width: `${SWIPEABLE_ACTION_WIDTH}px`
|
|
98
|
+
}, item.icon, item.text));
|
|
99
|
+
};
|
|
100
|
+
SwipeableAction.displayName = 'SwipeableAction';
|
|
101
|
+
var _default = exports.default = SwipeableAction;
|
|
102
|
+
//# sourceMappingURL=SwipeableAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableAction.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_SwipeableAction","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","SWIPEABLE_ACTION_WIDTH","exports","SwipeableAction","activationThreshold","close","index","item","listItemXOffset","position","totalActionCount","handleButtonClick","action","actionOffset","useTransform","newValue","maxOffset","fractionalOffset","Math","max","min","actionOverlayOffset","useSpring","bounce","actionX","x","y","useEffect","isOuterMost","undefined","onChange","lastValue","getPrevious","createElement","StyledMotionSwipeableAction","$backgroundColor","backgroundColor","$position","style","StyledSwipeableActionButton","$color","color","onClick","$width","icon","text","displayName","_default"],"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,IAAAA,aAAA,GAAAC,OAAA;AACA,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;MAAEb,CAAC,EAAED;IAAQ;EAAE,gBAEtB9C,MAAA,CAAAS,OAAA,CAAA8C,aAAA,CAACrD,gBAAA,CAAA2D,2BAA2B;IACxBC,MAAM,EAAEjC,IAAI,CAACkC,KAAM;IACnBC,OAAO,EAAE/B,iBAAkB;IAC3BgC,MAAM,EAAG,GAAE1C,sBAAuB;EAAI,GAErCM,IAAI,CAACqC,IAAI,EACTrC,IAAI,CAACsC,IACmB,CACJ,CAAC;AAEtC,CAAC;AAED1C,eAAe,CAAC2C,WAAW,GAAG,iBAAiB;AAAC,IAAAC,QAAA,GAAA7C,OAAA,CAAAf,OAAA,GAEjCgB,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
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 && {}.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)`
|
|
12
|
+
background-color: ${({
|
|
13
|
+
$backgroundColor
|
|
14
|
+
}) => $backgroundColor};
|
|
15
|
+
display: flex;
|
|
16
|
+
height: 100%;
|
|
17
|
+
position: absolute;
|
|
18
|
+
top: 0;
|
|
19
|
+
width: 200vw;
|
|
20
|
+
|
|
21
|
+
${({
|
|
22
|
+
$position
|
|
23
|
+
}) => {
|
|
24
|
+
if ($position === 'left') {
|
|
25
|
+
return (0, _styledComponents.css)`
|
|
26
|
+
justify-content: flex-end;
|
|
27
|
+
right: 100%;
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
return (0, _styledComponents.css)`
|
|
31
|
+
justify-content: flex-start;
|
|
32
|
+
left: 100%;
|
|
33
|
+
`;
|
|
34
|
+
}}
|
|
35
|
+
`;
|
|
36
|
+
const StyledSwipeableActionButton = exports.StyledSwipeableActionButton = _styledComponents.default.button`
|
|
37
|
+
align-items: center;
|
|
38
|
+
appearance: none;
|
|
39
|
+
background: none;
|
|
40
|
+
box-shadow: none;
|
|
41
|
+
color: ${({
|
|
42
|
+
$color
|
|
43
|
+
}) => $color};
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
font-size: 88%;
|
|
47
|
+
gap: 4px;
|
|
48
|
+
height: 100%;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
margin: 0;
|
|
51
|
+
padding: 0;
|
|
52
|
+
width: ${({
|
|
53
|
+
$width
|
|
54
|
+
}) => $width};
|
|
55
|
+
`;
|
|
56
|
+
//# sourceMappingURL=SwipeableAction.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeableAction.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","StyledMotionSwipeableAction","exports","styled","motion","div","$backgroundColor","$position","css","StyledSwipeableActionButton","button","$color","$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';\n\ntype StyledSwipeableActionProps = {\n $position: 'left' | 'right';\n $backgroundColor: CSSProperties['backgroundColor'];\n};\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 = {\n $width: CSSProperties['width'];\n $color: CSSProperties['color'];\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,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAgD,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,O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;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,CAAC;EAAEC;AAAO,CAAC,KAAKA,MAAO;AACpC,CAAC","ignoreList":[]}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
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 }; }
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_SwipeableWrapper","_interopRequireDefault","require","obj","__esModule","default"],"sources":["../../src/index.ts"],"sourcesContent":["export { default as SwipeableWrapper } from './components/swipeable-wrapper/SwipeableWrapper';\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8F,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
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 = ({
|
|
9
|
+
actionCount,
|
|
10
|
+
direction,
|
|
11
|
+
width
|
|
12
|
+
}) => Math.max(width / 2, _SwipeableAction.SWIPEABLE_ACTION_WIDTH * actionCount) * (direction === 'left' ? 1 : -1);
|
|
13
|
+
exports.calcThreshold = calcThreshold;
|
|
14
|
+
//# sourceMappingURL=threshold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threshold.js","names":["_SwipeableAction","require","calcThreshold","actionCount","direction","width","Math","max","SWIPEABLE_ACTION_WIDTH","exports"],"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,IAAAA,gBAAA,GAAAC,OAAA;AAQO,MAAMC,aAAa,GAAGA,CAAC;EAAEC,WAAW;EAAEC,SAAS;EAAEC;AAA4B,CAAC,KACjFC,IAAI,CAACC,GAAG,CAACF,KAAK,GAAG,CAAC,EAAEG,uCAAsB,GAAGL,WAAW,CAAC,IAAIC,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAACK,OAAA,CAAAP,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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;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,eAAgB;IACjC+C,QAAQ,EAAC,MAAM;IACfC,gBAAgB,EAAE7D,WAAW,CAACK;EAAO,CACxC,CACJ,CAAC,EACV,CAACS,KAAK,EAAEd,WAAW,EAAEE,aAAa,EAAEW,eAAe,CACvD,CAAC;EAED,MAAMiD,mBAAmB,GAAGzE,OAAO,CAC/B,MACIY,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","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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","backgroundColor","$position","style","$color","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;AAYxC,MAAMC,eAAyC,GAAGC,IAAA,IAQ5C;EAAA,IAR6C;IAC/CC,mBAAmB;IACnBC,KAAK;IACLC,KAAK;IACLC,IAAI;IACJC,eAAe;IACfC,QAAQ;IACRC;EACJ,CAAC,GAAAP,IAAA;EACG,MAAMQ,iBAAiB,GAAGA,CAAA,KAAM;IAC5BJ,IAAI,CAACK,MAAM,CAAC,CAAC;IACbP,KAAK,CAAC,CAAC;EACX,CAAC;;EAED;AACJ;AACA;AACA;EACI,MAAMQ,YAAY,GAAGjB,YAAY,CAACY,eAAe,EAAGM,QAAQ,IAAK;IAC7D,MAAMC,SAAS,GAAGd,sBAAsB,GAAGK,KAAK;IAChD,MAAMU,gBAAgB,GAAI,CAACF,QAAQ,GAAGJ,gBAAgB,GAAIJ,KAAK;IAE/D,QAAQG,QAAQ;MACZ,KAAK,MAAM;QACP,OAAOQ,IAAI,CAACC,GAAG,CAAC,CAACH,SAAS,EAAEC,gBAAgB,CAAC;MACjD,KAAK,OAAO;QACR,OAAOC,IAAI,CAACE,GAAG,CAACJ,SAAS,EAAEC,gBAAgB,CAAC;MAChD;QACI,OAAO,CAAC;IAChB;EACJ,CAAC,CAAC;;EAEF;AACJ;AACA;AACA;EACI,MAAMI,mBAAmB,GAAGzB,SAAS,CAA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BAAsB,GAAG,CAAC,CAAC,GAAGK,KAAK,CAAC;UAChE,CAAC,MAAM,IAAIQ,QAAQ,GAAGV,mBAAmB,IAAIyB,SAAS,IAAIzB,mBAAmB,EAAE;YAC3EgB,mBAAmB,CAACW,GAAG,CAAC,CAAC,CAAC;UAC9B;MACR;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CACCX,mBAAmB,EACnBhB,mBAAmB,EACnBE,KAAK,EACLE,eAAe,EACfC,QAAQ,EACRC,gBAAgB,CACnB,CAAC;EAEF,oBACIb,KAAA,CAAAmC,aAAA,CAACjC,2BAA2B;IACxBkC,gBAAgB,EAAE1B,IAAI,CAAC2B,eAAgB;IACvCC,SAAS,EAAE1B,QAAS;IACpB2B,KAAK,EAAE;MAAEZ,CAAC,EAAEF;IAAQ;EAAE,gBAEtBzB,KAAA,CAAAmC,aAAA,CAAChC,2BAA2B;IACxBqC,MAAM,EAAE9B,IAAI,CAAC+B,KAAM;IACnBC,OAAO,EAAE5B,iBAAkB;IAC3B6B,MAAM,EAAG,GAAEvC,sBAAuB;EAAI,GAErCM,IAAI,CAACkC,IAAI,EACTlC,IAAI,CAACmC,IACmB,CACJ,CAAC;AAEtC,CAAC;AAEDxC,eAAe,CAACyC,WAAW,GAAG,iBAAiB;AAE/C,eAAezC,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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';\n\ntype StyledSwipeableActionProps = {\n $position: 'left' | 'right';\n $backgroundColor: CSSProperties['backgroundColor'];\n};\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 = {\n $width: CSSProperties['width'];\n $color: CSSProperties['color'];\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;EAAiB,CAAC,GAAAD,IAAA;EAAA,OAAKC,gBAAgB;AAAA,CAAC;AACnE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAA,IAAmB;EAAA,IAAlB;IAAEC;EAAU,CAAC,GAAAD,KAAA;EACZ,IAAIC,SAAS,KAAK,MAAM,EAAE;IACtB,OAAON,GAAI;AACvB;AACA;AACA,aAAa;EACL;EACA,OAAOA,GAAI;AACnB;AACA;AACA,SAAS;AACL,CAAE;AACN,CAAC;AAOD,OAAO,MAAMO,2BAA2B,GAAGR,MAAM,CAACS,MAA0C;AAC5F;AACA;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEC;EAAO,CAAC,GAAAD,KAAA;EAAA,OAAKC,MAAM;AAAA,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEC;EAAO,CAAC,GAAAD,KAAA;EAAA,OAAKC,MAAM;AAAA,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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","ignoreList":[]}
|
|
@@ -263,6 +263,6 @@ export declare const StyledMotionSwipeableWrapper: import("styled-components").I
|
|
|
263
263
|
} & import("framer-motion").MotionProps & import("react").RefAttributes<HTMLDivElement>, "ref"> & {
|
|
264
264
|
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
265
265
|
}, {
|
|
266
|
-
theme: import("@chayns-components/core/lib/components/color-scheme-provider/ColorSchemeProvider").Theme;
|
|
266
|
+
theme: import("@chayns-components/core/lib/types/components/color-scheme-provider/ColorSchemeProvider").Theme;
|
|
267
267
|
}>> & Omit<import("framer-motion").ForwardRefComponent<HTMLDivElement, import("framer-motion").HTMLMotionProps<"div">>, keyof import("react").Component<any, {}, any>>;
|
|
268
268
|
export declare const StyledSwipeableWrapperContent: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
|
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.578",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -17,8 +17,16 @@
|
|
|
17
17
|
"author": "Tobit.Software",
|
|
18
18
|
"homepage": "https://github.com/TobitSoftware/chayns-components/tree/main/packages/swipeable-wrapper#readme",
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"main": "lib/index.js",
|
|
21
|
-
"
|
|
20
|
+
"main": "lib/cjs/index.js",
|
|
21
|
+
"module": "lib/esm/index.js",
|
|
22
|
+
"types": "lib/types/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": "./lib/cjs/index.js",
|
|
26
|
+
"import": "./lib/esm/index.js",
|
|
27
|
+
"types": "./lib/types/index.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
22
30
|
"directories": {
|
|
23
31
|
"lib": "lib",
|
|
24
32
|
"test": "__tests__"
|
|
@@ -31,9 +39,10 @@
|
|
|
31
39
|
"url": "git+https://github.com/TobitSoftware/chayns-components.git"
|
|
32
40
|
},
|
|
33
41
|
"scripts": {
|
|
34
|
-
"build": "npm run build:
|
|
35
|
-
"build:js": "babel src --out-dir lib --extensions=.ts,.tsx --source-maps --ignore=src/stories",
|
|
42
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
36
43
|
"build:types": "tsc",
|
|
44
|
+
"build:cjs": "cross-env NODE_ENV=cjs babel src --out-dir lib/cjs --extensions=.ts,.tsx --source-maps --ignore=src/stories",
|
|
45
|
+
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir lib/esm --extensions=.ts,.tsx --source-maps --ignore=src/stories",
|
|
37
46
|
"prepublishOnly": "npm run build"
|
|
38
47
|
},
|
|
39
48
|
"bugs": {
|
|
@@ -50,6 +59,7 @@
|
|
|
50
59
|
"@types/styled-components": "^5.1.34",
|
|
51
60
|
"@types/uuid": "^9.0.8",
|
|
52
61
|
"babel-loader": "^9.1.3",
|
|
62
|
+
"cross-env": "^7.0.3",
|
|
53
63
|
"lerna": "^8.1.2",
|
|
54
64
|
"react": "^18.2.0",
|
|
55
65
|
"react-dom": "^18.2.0",
|
|
@@ -57,7 +67,7 @@
|
|
|
57
67
|
"typescript": "^5.4.5"
|
|
58
68
|
},
|
|
59
69
|
"dependencies": {
|
|
60
|
-
"@chayns-components/core": "^5.0.0-beta.
|
|
70
|
+
"@chayns-components/core": "^5.0.0-beta.578"
|
|
61
71
|
},
|
|
62
72
|
"peerDependencies": {
|
|
63
73
|
"chayns-api": ">=1.0.50",
|
|
@@ -69,5 +79,5 @@
|
|
|
69
79
|
"publishConfig": {
|
|
70
80
|
"access": "public"
|
|
71
81
|
},
|
|
72
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "c3d65c0781ca6b8e053ccc6ce359b1074b0fcb1e"
|
|
73
83
|
}
|
|
@@ -1 +0,0 @@
|
|
|
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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BAAgB","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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","backgroundColor","$position","style","$color","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;AAYxC,MAAMC,eAAyC,GAAGC,IAAA,IAQ5C;EAAA,IAR6C;IAC/CC,mBAAmB;IACnBC,KAAK;IACLC,KAAK;IACLC,IAAI;IACJC,eAAe;IACfC,QAAQ;IACRC;EACJ,CAAC,GAAAP,IAAA;EACG,MAAMQ,iBAAiB,GAAGA,CAAA,KAAM;IAC5BJ,IAAI,CAACK,MAAM,CAAC,CAAC;IACbP,KAAK,CAAC,CAAC;EACX,CAAC;;EAED;AACJ;AACA;AACA;EACI,MAAMQ,YAAY,GAAGjB,YAAY,CAACY,eAAe,EAAGM,QAAQ,IAAK;IAC7D,MAAMC,SAAS,GAAGd,sBAAsB,GAAGK,KAAK;IAChD,MAAMU,gBAAgB,GAAI,CAACF,QAAQ,GAAGJ,gBAAgB,GAAIJ,KAAK;IAE/D,QAAQG,QAAQ;MACZ,KAAK,MAAM;QACP,OAAOQ,IAAI,CAACC,GAAG,CAAC,CAACH,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SAAS,IAAIzB,mBAAmB,EAAE;YAC3EgB,mBAAmB,CAACW,GAAG,CAAC,CAAC,CAAC;UAC9B;UACA;QACJ,KAAK,OAAO;UACR,IAAIjB,QAAQ,GAAGV,mBAAmB,IAAIyB,SAAS,IAAIzB,mBAAmB,EAAE;YACpEgB,mBAAmB,CAACW,GAAG,CAAC9B,sBAAsB,GAAG,CAAC,CAAC,GAAGK,KAAK,CAAC;UAChE,CAAC,MAAM,IAAIQ,QAAQ,GAAGV,mBAAmB,IAAIyB,SAAS,IAAIzB,mBAAmB,EAAE;YAC3EgB,mBAAmB,CAACW,GAAG,CAAC,CAAC,CAAC;UAC9B;MACR;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CACCX,mBAAmB,EACnBhB,mBAAmB,EACnBE,KAAK,EACLE,eAAe,EACfC,QAAQ,EACRC,gBAAgB,CACnB,CAAC;EAEF,oBACIb,KAAA,CAAAmC,aAAA,CAACjC,2BAA2B;IACxBkC,gBAAgB,EAAE1B,IAAI,CAAC2B,eAAgB;IACvCC,SAAS,EAAE1B,QAAS;IACpB2B,KAAK,EAAE;MAAEZ,CAAC,EAAEF;IAAQ;EAAE,gBAEtBzB,KAAA,CAAAmC,aAAA,CAAChC,2BAA2B;IACxBqC,MAAM,EAAE9B,IAAI,CAAC+B,KAAM;IACnBC,OAAO,EAAE5B,iBAAkB;IAC3B6B,MAAM,EAAG,GAAEvC,sBAAuB;EAAI,GAErCM,IAAI,CAACkC,IAAI,EACTlC,IAAI,CAACmC,IACmB,CACJ,CAAC;AAEtC,CAAC;AAEDxC,eAAe,CAACyC,WAAW,GAAG,iBAAiB;AAE/C,eAAezC,eAAe","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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';\n\ntype StyledSwipeableActionProps = {\n $position: 'left' | 'right';\n $backgroundColor: CSSProperties['backgroundColor'];\n};\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 = {\n $width: CSSProperties['width'];\n $color: CSSProperties['color'];\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;EAAiB,CAAC,GAAAD,IAAA;EAAA,OAAKC,gBAAgB;AAAA,CAAC;AACnE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAA,IAAmB;EAAA,IAAlB;IAAEC;EAAU,CAAC,GAAAD,KAAA;EACZ,IAAIC,SAAS,KAAK,MAAM,EAAE;IACtB,OAAON,GAAI;AACvB;AACA;AACA,aAAa;EACL;EACA,OAAOA,GAAI;AACnB;AACA;AACA,SAAS;AACL,CAAE;AACN,CAAC;AAOD,OAAO,MAAMO,2BAA2B,GAAGR,MAAM,CAACS,MAA0C;AAC5F;AACA;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEC;EAAO,CAAC,GAAAD,KAAA;EAAA,OAAKC,MAAM;AAAA,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAaC,KAAA;EAAA,IAAC;IAAEC;EAAO,CAAC,GAAAD,KAAA;EAAA,OAAKC,MAAM;AAAA,CAAC;AACpC,CAAC","ignoreList":[]}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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","ignoreList":[]}
|
|
File without changes
|
|
File without changes
|
/package/lib/{components → esm/components}/swipeable-wrapper/swipeable-action/SwipeableAction.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib/{components → types/components}/swipeable-wrapper/swipeable-action/SwipeableAction.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|