Skip to content

Instantly share code, notes, and snippets.

@developit
Last active November 10, 2020 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developit/f1d6b235cb299e330fc76d0dce415196 to your computer and use it in GitHub Desktop.
Save developit/f1d6b235cb299e330fc76d0dce415196 to your computer and use it in GitHub Desktop.
package-lock.json
node_modules
.cache
dist
.drag {
display: grid;
background: #abc;
border-radius: 16px;
height: 80px;
width: 80px;
z-index: 10000;
position: relative;
cursor: -webkit-grab;
cursor: grab;
touch-action: none;
user-select: none;
color: #333;
place-items: center;
}
import { h, FunctionalComponent } from "preact";
import { useSpring, animated } from "react-spring";
import { useDrag } from "react-use-gesture";
import styles from './app.module.css';
const Slide : FunctionalComponent = () => {
const [props, set] = useSpring(() => ({ left: 0, top: 0 }));
const bind = useDrag(({ down, movement: [mx, my] }) => {
set({ left: down ? mx : 0, top: down ? my : 0 });
});
return <animated.div {...bind()} style={props} class={styles.drag} />;
};
export default Slide;
<!DOCTYPE html>
<html>
<head>
<title>useSpring</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<script type="module" src="/index.js"></script>
</body>
</html>
import { render } from 'preact';
import App from './app.tsx';
render(<App />, document.body);
{
"version": "0.0.1",
"scripts": {
"start": "wmr",
"build:prod": "wmr build"
},
"engines": {
"node": "12.x"
},
"alias": {
"react": "preact/compat",
"react-dom": "preact/compat"
},
"devDependencies": {
"wmr": "^0.0.11"
}
}
html,
body {
font: 100% system-ui;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment