@chayns-components/swipeable-wrapper 5.0.0-beta.614 → 5.0.0-beta.615

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.
@@ -15,7 +15,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
15
15
  const SwipeableWrapper = ({
16
16
  children,
17
17
  leftActions = [],
18
- rightActions = []
18
+ rightActions = [],
19
+ shouldUseOpacityAnimation
19
20
  }) => {
20
21
  const [leftThreshold, setLeftThreshold] = (0, _react.useState)((0, _threshold.calcThreshold)({
21
22
  actionCount: leftActions.length,
@@ -156,8 +157,9 @@ const SwipeableWrapper = ({
156
157
  key: item.key,
157
158
  listItemXOffset: listItemXOffset,
158
159
  position: "left",
160
+ shouldUseOpacityAnimation: shouldUseOpacityAnimation,
159
161
  totalActionCount: leftActions.length
160
- })), [close, leftActions, leftThreshold, listItemXOffset]);
162
+ })), [close, leftActions, leftThreshold, listItemXOffset, shouldUseOpacityAnimation]);
161
163
  const rightActionElements = (0, _react.useMemo)(() => rightActions.map((item, index) => /*#__PURE__*/_react.default.createElement(_SwipeableAction.default, {
162
164
  activationThreshold: rightThreshold,
163
165
  close: close,
@@ -166,8 +168,9 @@ const SwipeableWrapper = ({
166
168
  key: item.key,
167
169
  listItemXOffset: listItemXOffset,
168
170
  position: "right",
171
+ shouldUseOpacityAnimation: shouldUseOpacityAnimation,
169
172
  totalActionCount: rightActions.length
170
- })), [close, rightActions, rightThreshold, listItemXOffset]);
173
+ })), [rightActions, rightThreshold, close, listItemXOffset, shouldUseOpacityAnimation]);
171
174
  return /*#__PURE__*/_react.default.createElement(_SwipeableWrapper.StyledMotionSwipeableWrapper, {
172
175
  onPan: handlePan,
173
176
  onPanEnd: handlePanEnd,
@@ -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","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,wBAA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jB,YAAY,EAAEW,cAAc,EAAEI,eAAe,CACzD,CAAC;EAED,oBACI3C,MAAA,CAAAW,OAAA,CAAAqF,aAAA,CAAC5F,iBAAA,CAAAkG,4BAA4B;IACzBC,KAAK,EAAE9B,SAAU;IACjB+B,QAAQ,EAAErB,YAAa;IACvBsB,GAAG,EAAEhE,mBAAoB;IACzBiE,KAAK,EAAE;MAAE3B,CAAC,EAAEpC;IAAgB;EAAE,GAE7B6C,kBAAkB,eACnBxF,MAAA,CAAAW,OAAA,CAAAqF,aAAA,CAAC5F,iBAAA,CAAAuG,6BAA6B,QAAEjF,QAAwC,CAAC,EACxE2E,mBACyB,CAAC;AAEvC,CAAC;AAED5E,gBAAgB,CAACmF,WAAW,GAAG,kBAAkB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAnG,OAAA,GAEnCc,gBAAgB","ignoreList":[]}
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","shouldUseOpacityAnimation","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 * Whether the opacity should be animated when swiping in the actions.\n */\n shouldUseOpacityAnimation?: boolean;\n};\n\nconst SwipeableWrapper: FC<SwipeableWrapperProps> = ({\n children,\n leftActions = [],\n rightActions = [],\n shouldUseOpacityAnimation,\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 shouldUseOpacityAnimation={shouldUseOpacityAnimation}\n totalActionCount={leftActions.length}\n />\n )),\n [close, leftActions, leftThreshold, listItemXOffset, shouldUseOpacityAnimation],\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 shouldUseOpacityAnimation={shouldUseOpacityAnimation}\n totalActionCount={rightActions.length}\n />\n )),\n [rightActions, rightThreshold, close, listItemXOffset, shouldUseOpacityAnimation],\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,M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,CAAC,EAAEpC;IAAgB;EAAE,GAE7B6C,kBAAkB,eACnBzF,MAAA,CAAAW,OAAA,CAAAsF,aAAA,CAAC7F,iBAAA,CAAAwG,6BAA6B,QAAElF,QAAwC,CAAC,EACxE4E,mBACyB,CAAC;AAEvC,CAAC;AAED7E,gBAAgB,CAACoF,WAAW,GAAG,kBAAkB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAApG,OAAA,GAEnCc,gBAAgB","ignoreList":[]}
@@ -13,7 +13,6 @@ const StyledMotionSwipeableWrapper = exports.StyledMotionSwipeableWrapper = (0,
13
13
  user-select: none;
14
14
  `;
15
15
  const StyledSwipeableWrapperContent = exports.StyledSwipeableWrapperContent = _styledComponents.default.div`
16
- overflow: hidden;
17
16
  width: 100%;
18
17
  `;
19
18
  //# sourceMappingURL=SwipeableWrapper.styles.js.map
@@ -1 +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":[]}
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 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,CAAC","ignoreList":[]}
@@ -17,6 +17,7 @@ const SwipeableAction = ({
17
17
  item,
18
18
  listItemXOffset,
19
19
  position,
20
+ shouldUseOpacityAnimation,
20
21
  totalActionCount
21
22
  }) => {
22
23
  const handleButtonClick = () => {
@@ -59,6 +60,7 @@ const SwipeableAction = ({
59
60
  }
60
61
  return Math.max((x ?? 0) + (y ?? 0), 0);
61
62
  });
63
+ const opacity = (0, _framerMotion.useTransform)(listItemXOffset, x => Math.max(0, Math.min(1, Math.abs(x) / 72)));
62
64
 
63
65
  // Animate to the middle after passing threshold if outermost item
64
66
  (0, _react.useEffect)(() => {
@@ -89,7 +91,8 @@ const SwipeableAction = ({
89
91
  $backgroundColor: item.backgroundColor,
90
92
  $position: position,
91
93
  style: {
92
- x: actionX
94
+ x: actionX,
95
+ opacity: shouldUseOpacityAnimation ? opacity : 1
93
96
  }
94
97
  }, /*#__PURE__*/_react.default.createElement(_SwipeableAction.StyledSwipeableActionButton, {
95
98
  $color: item.color,
@@ -1 +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,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,gBAAA,GAAAH,OAAA;AAAoG,SAAAI,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,SAAAH,wBAAAG,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,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAA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C;UAC9B;MACR;IACJ,CAAC,CAAC;EACN,CAAC,EAAE,CACCqB,mBAAmB,EACnBjB,mBAAmB,EACnBE,KAAK,EACLE,eAAe,EACfC,QAAQ,EACRC,gBAAgB,CACnB,CAAC;EAEF,oBACIhC,MAAA,CAAAS,OAAA,CAAA8C,aAAA,CAACrD,gBAAA,CAAAsD,2BAA2B;IACxBC,gBAAgB,EAAE5B,IAAI,CAAC6B,eAAgB;IACvCC,SAAS,EAAE5B,QAAS;IACpB6B,KAAK,EAAE;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":[]}
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","shouldUseOpacityAnimation","totalActionCount","handleButtonClick","action","actionOffset","useTransform","newValue","maxOffset","fractionalOffset","Math","max","min","actionOverlayOffset","useSpring","bounce","actionX","x","y","opacity","abs","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 shouldUseOpacityAnimation?: boolean;\n totalActionCount: number;\n};\n\nconst SwipeableAction: FC<SwipeableActionProps> = ({\n activationThreshold,\n close,\n index,\n item,\n listItemXOffset,\n position,\n shouldUseOpacityAnimation,\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 const opacity = useTransform(listItemXOffset, (x) =>\n Math.max(0, Math.min(1, Math.abs(x) / 72)),\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, opacity: shouldUseOpacityAnimation ? opacity : 1 }}\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,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,gBAAA,GAAAH,OAAA;AAAoG,SAAAI,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,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CA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AA,CAAA8D,2BAA2B;IACxBC,MAAM,EAAEpC,IAAI,CAACqC,KAAM;IACnBC,OAAO,EAAEjC,iBAAkB;IAC3BkC,MAAM,EAAG,GAAE7C,sBAAuB;EAAI,GAErCM,IAAI,CAACwC,IAAI,EACTxC,IAAI,CAACyC,IACmB,CACJ,CAAC;AAEtC,CAAC;AAED7C,eAAe,CAAC8C,WAAW,GAAG,iBAAiB;AAAC,IAAAC,QAAA,GAAAhD,OAAA,CAAAf,OAAA,GAEjCgB,eAAe","ignoreList":[]}
@@ -8,7 +8,8 @@ const SwipeableWrapper = _ref => {
8
8
  let {
9
9
  children,
10
10
  leftActions = [],
11
- rightActions = []
11
+ rightActions = [],
12
+ shouldUseOpacityAnimation
12
13
  } = _ref;
13
14
  const [leftThreshold, setLeftThreshold] = useState(calcThreshold({
14
15
  actionCount: leftActions.length,
@@ -145,8 +146,9 @@ const SwipeableWrapper = _ref => {
145
146
  key: item.key,
146
147
  listItemXOffset: listItemXOffset,
147
148
  position: "left",
149
+ shouldUseOpacityAnimation: shouldUseOpacityAnimation,
148
150
  totalActionCount: leftActions.length
149
- })), [close, leftActions, leftThreshold, listItemXOffset]);
151
+ })), [close, leftActions, leftThreshold, listItemXOffset, shouldUseOpacityAnimation]);
150
152
  const rightActionElements = useMemo(() => rightActions.map((item, index) => /*#__PURE__*/React.createElement(SwipeableAction, {
151
153
  activationThreshold: rightThreshold,
152
154
  close: close,
@@ -155,8 +157,9 @@ const SwipeableWrapper = _ref => {
155
157
  key: item.key,
156
158
  listItemXOffset: listItemXOffset,
157
159
  position: "right",
160
+ shouldUseOpacityAnimation: shouldUseOpacityAnimation,
158
161
  totalActionCount: rightActions.length
159
- })), [close, rightActions, rightThreshold, listItemXOffset]);
162
+ })), [rightActions, rightThreshold, close, listItemXOffset, shouldUseOpacityAnimation]);
160
163
  return /*#__PURE__*/React.createElement(StyledMotionSwipeableWrapper, {
161
164
  onPan: handlePan,
162
165
  onPanEnd: handlePanEnd,
@@ -1 +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,CAC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AEG,QAAwC,CAAC,EACxE+D,mBACyB,CAAC;AAEvC,CAAC;AAEDjE,gBAAgB,CAACsE,WAAW,GAAG,kBAAkB;AAEjD,eAAetE,gBAAgB","ignoreList":[]}
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","shouldUseOpacityAnimation","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 * Whether the opacity should be animated when swiping in the actions.\n */\n shouldUseOpacityAnimation?: boolean;\n};\n\nconst SwipeableWrapper: FC<SwipeableWrapperProps> = ({\n children,\n leftActions = [],\n rightActions = [],\n shouldUseOpacityAnimation,\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 shouldUseOpacityAnimation={shouldUseOpacityAnimation}\n totalActionCount={leftActions.length}\n />\n )),\n [close, leftActions, leftThreshold, listItemXOffset, shouldUseOpacityAnimation],\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 shouldUseOpacityAnimation={shouldUseOpacityAnimation}\n totalActionCount={rightActions.length}\n />\n )),\n [rightActions, rightThreshold, close, listItemXOffset, shouldUseOpacityAnimation],\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,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;IAChB3D,yBAAyB,EAAEA,yBAA0B;IACrD4D,gBAAgB,EAAE7D,YAAY,CAACK;EAAO,CACzC,CACJ,CAAC,EACN,CAACL,YAAY,EAAEU,cAAc,EAAEI,KAAK,EAAED,eAAe,EAAEZ,yBAAyB,CACpF,CAAC;EAED,oBACIhB,KAAA,CAAAwE,aAAA,CAAC/D,4BAA4B;IACzBqE,KAAK,EAAE5B,SAAU;IACjB6B,QAAQ,EAAEjB,YAAa;IACvBkB,GAAG,EAAErD,mBAAoB;IACzBsD,KAAK,EAAE;MAAExB,CAAC,EAAE7B;IAAgB;EAAE,GAE7BqC,kBAAkB,eACnBjE,KAAA,CAAAwE,aAAA,CAAC9D,6BAA6B,QAAEG,QAAwC,CAAC,EACxEgE,mBACyB,CAAC;AAEvC,CAAC;AAEDlE,gBAAgB,CAACuE,WAAW,GAAG,kBAAkB;AAEjD,eAAevE,gBAAgB","ignoreList":[]}
@@ -6,7 +6,6 @@ export const StyledMotionSwipeableWrapper = styled(motion.div)`
6
6
  user-select: none;
7
7
  `;
8
8
  export const StyledSwipeableWrapperContent = styled.div`
9
- overflow: hidden;
10
9
  width: 100%;
11
10
  `;
12
11
  //# sourceMappingURL=SwipeableWrapper.styles.js.map
@@ -1 +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":[]}
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 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,CAAC","ignoreList":[]}
@@ -10,6 +10,7 @@ const SwipeableAction = _ref => {
10
10
  item,
11
11
  listItemXOffset,
12
12
  position,
13
+ shouldUseOpacityAnimation,
13
14
  totalActionCount
14
15
  } = _ref;
15
16
  const handleButtonClick = () => {
@@ -53,6 +54,7 @@ const SwipeableAction = _ref => {
53
54
  }
54
55
  return Math.max((x ?? 0) + (y ?? 0), 0);
55
56
  });
57
+ const opacity = useTransform(listItemXOffset, x => Math.max(0, Math.min(1, Math.abs(x) / 72)));
56
58
 
57
59
  // Animate to the middle after passing threshold if outermost item
58
60
  useEffect(() => {
@@ -83,7 +85,8 @@ const SwipeableAction = _ref => {
83
85
  $backgroundColor: item.backgroundColor,
84
86
  $position: position,
85
87
  style: {
86
- x: actionX
88
+ x: actionX,
89
+ opacity: shouldUseOpacityAnimation ? opacity : 1
87
90
  }
88
91
  }, /*#__PURE__*/React.createElement(StyledSwipeableActionButton, {
89
92
  $color: item.color,
@@ -1 +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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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
+ {"version":3,"file":"SwipeableAction.js","names":["useSpring","useTransform","React","useEffect","StyledMotionSwipeableAction","StyledSwipeableActionButton","SWIPEABLE_ACTION_WIDTH","SwipeableAction","_ref","activationThreshold","close","index","item","listItemXOffset","position","shouldUseOpacityAnimation","totalActionCount","handleButtonClick","action","actionOffset","newValue","maxOffset","fractionalOffset","Math","max","min","actionOverlayOffset","bounce","actionX","_ref2","x","y","opacity","abs","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 shouldUseOpacityAnimation?: boolean;\n totalActionCount: number;\n};\n\nconst SwipeableAction: FC<SwipeableActionProps> = ({\n activationThreshold,\n close,\n index,\n item,\n listItemXOffset,\n position,\n shouldUseOpacityAnimation,\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 const opacity = useTransform(listItemXOffset, (x) =>\n Math.max(0, Math.min(1, Math.abs(x) / 72)),\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, opacity: shouldUseOpacityAnimation ? opacity : 1 }}\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;AAaxC,MAAMC,eAAyC,GAAGC,IAAA,IAS5C;EAAA,IAT6C;IAC/CC,mBAAmB;IACnBC,KAAK;IACLC,KAAK;IACLC,IAAI;IACJC,eAAe;IACfC,QAAQ;IACRC,yBAAyB;IACzBC;EACJ,CAAC,GAAAR,IAAA;EACG,MAAMS,iBAAiB,GAAGA,CAAA,KAAM;IAC5BL,IAAI,CAACM,MAAM,CAAC,CAAC;IACbR,KAAK,CAAC,CAAC;EACX,CAAC;;EAED;AACJ;AACA;AACA;EACI,MAAMS,YAAY,GAAGlB,YAAY,CAACY,eAAe,EAAGO,QAAQ,IAAK;IAC7D,MAAMC,SAAS,GAAGf,sBAAsB,GAAGK,KAAK;IAChD,MAAMW,gBAAgB,GAAI,CAACF,QAAQ,GAAGJ,gBAAgB,GAAIL,KAAK;IAE/D,QAAQG,QAAQ;MACZ,KAAK,MAAM;QACP,OAAOS,IAAI,CAACC,GAAG,CAAC,CAACH,SAAS,EAAEC,gBAAgB,CAAC;MACjD,KAAK,OAAO;QACR,OAAOC,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[]}
@@ -20,6 +20,10 @@ export type SwipeableWrapperProps = {
20
20
  * The right-side actions, ordered from left to the right.
21
21
  */
22
22
  rightActions?: SwipeableActionItem[];
23
+ /**
24
+ * Whether the opacity should be animated when swiping in the actions.
25
+ */
26
+ shouldUseOpacityAnimation?: boolean;
23
27
  };
24
28
  declare const SwipeableWrapper: FC<SwipeableWrapperProps>;
25
29
  export default SwipeableWrapper;
@@ -9,6 +9,7 @@ export type SwipeableActionProps = {
9
9
  item: SwipeableActionItem;
10
10
  listItemXOffset: MotionValue<number>;
11
11
  position: 'left' | 'right';
12
+ shouldUseOpacityAnimation?: boolean;
12
13
  totalActionCount: number;
13
14
  };
14
15
  declare const SwipeableAction: FC<SwipeableActionProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/swipeable-wrapper",
3
- "version": "5.0.0-beta.614",
3
+ "version": "5.0.0-beta.615",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "f465b7122014d3ac426b01ea0bbf039b3d0d5681"
82
+ "gitHead": "82562af35683ce3653c6467ce1c6bc492003fe5b"
83
83
  }