@dtdot/lego 0.16.0 → 0.16.1
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { motion, useMotionValue, useTransform } from 'framer-motion';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
3
|
import styled, { useTheme } from 'styled-components';
|
|
4
|
+
import useMeasure from 'react-use-measure';
|
|
4
5
|
import { responsive } from '../..';
|
|
5
6
|
import getThemeStatusColour from '../../theme/helpers/getThemeStatusColour';
|
|
6
7
|
import InlineCardContent from './_InlineCardContent.component';
|
|
@@ -77,18 +78,23 @@ const CardActionBackground = styled(motion.div) `
|
|
|
77
78
|
const InlineCard = ({ children, size, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }) => {
|
|
78
79
|
const theme = useTheme();
|
|
79
80
|
const x = useMotionValue(0);
|
|
81
|
+
const [ref, bounds] = useMeasure();
|
|
80
82
|
const xInput = [-70, 0];
|
|
81
83
|
const gestureLeftTheme = getThemeStatusColour(gestureLeftVariant || 'info', theme);
|
|
84
|
+
const [gestureLeftActivated, setGestureLeftActivated] = useState(false);
|
|
82
85
|
const opacity = useTransform(x, xInput, ['1', '0']);
|
|
83
86
|
const handleDragEnd = (e, panInfo) => {
|
|
84
87
|
// approx xInputMin * 3
|
|
85
88
|
if (panInfo.offset.x < -180 && onGestureLeft) {
|
|
89
|
+
setGestureLeftActivated(true);
|
|
86
90
|
onGestureLeft();
|
|
87
91
|
}
|
|
88
92
|
};
|
|
89
93
|
return (React.createElement(CardWrapper, { size: size },
|
|
90
94
|
React.createElement(CardActionBackground, { style: { opacity, backgroundColor: gestureLeftTheme.main } }, gestureLeftIcon && (React.createElement(FontAwesomeIcon, { style: { fontSize: '20px', color: gestureLeftTheme.contrast }, icon: gestureLeftIcon }))),
|
|
91
|
-
React.createElement(CardOuter, { drag: onGestureLeft ? 'x' : undefined, onDragEnd: handleDragEnd, style: { x },
|
|
95
|
+
React.createElement(CardOuter, { drag: onGestureLeft ? 'x' : undefined, onDragEnd: handleDragEnd, ref: ref, style: { x }, animate: { x: gestureLeftActivated ? -bounds.width : undefined, opacity: gestureLeftActivated ? 0 : undefined },
|
|
96
|
+
// animate={{ x: '-100%' }}
|
|
97
|
+
dragConstraints: { left: 0, right: 0 }, usePointer: !!onClick, onClick: onClick }, children)));
|
|
92
98
|
};
|
|
93
99
|
InlineCard.Media = InlineCardMedia;
|
|
94
100
|
InlineCard.Content = InlineCardContent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtdot/lego",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Some reusable components for building my applications",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"identicon.js": "^2.3.3",
|
|
61
61
|
"qrcode": "^1.4.4",
|
|
62
62
|
"react-spring": "^8.0.27",
|
|
63
|
+
"react-use-measure": "^2.1.1",
|
|
63
64
|
"spark-md5": "^3.0.1"
|
|
64
65
|
}
|
|
65
66
|
}
|