Debian Codegraph @

babel-preset-modules/test/integration/react-hooks-demo/Button.js

raw symbols SCIP
1 import React, { useState, useEffect, useRef } from "react";
2 import styled, { keyframes } from "styled-components";
3
4 function Button(props) {
5 const button = useRef();
6 const [clicked, setClicked] = useState(false);
7
8 function animate(e) {
9 var d = document.createElement("div");
10 d.className = "circle";
11 const x = e.nativeEvent.offsetX;
12 const y = e.nativeEvent.offsetY;
13 d.style.left = `${x}px`;
14 d.style.top = `${y}px`;
15 button.current.appendChild(d);
16 d.addEventListener("animationend", function() {
17 d.parentElement.removeChild(d);
18 });
19 }
20
21 return (
22 <button
23 {...props}
24 ref={button}
25 onClick={e => {
26 animate(e);
27 }}
28 >
29 {props.children}
30 </button>
31 );
32 }
33
34 export default styled(Button)`
35 overflow: hidden;
36 position: relative;
37 display: block;
38 font-weight: bold;
39 width: fit-content;
40 height: fit-content;
41 color: #ffffff;
42 cursor: pointer;
43 padding: 6px 16px;
44 border: none;
45 border-radius: 4px;
46 background: #4f9eed;
47 transition: 0.1s ease 0s;
48
49 -webkit-touch-callout: none; /* iOS Safari */
50 -webkit-user-select: none; /* Safari */
51 -khtml-user-select: none; /* Konqueror HTML */
52 -moz-user-select: none; /* Firefox */
53 -ms-user-select: none; /* Internet Explorer/Edge */
54 user-select: none; /* Non-prefixed version, currently
55 supported by Chrome and Opera */
56
57 &:hover {
58 background: #2e78c2;
59 }
60
61 .circle {
62 position: absolute;
63   box-sizing: border-box;
64 background: white;
65   border-radius: 50%;
66   animation: clickEffect 0.4s ease-out;
67   z-index: 99999;
68 }
69
70 @keyframes clickEffect{
71   0% {
72     opacity: 1;
73     width: 0.5em;
74 height: 0.5em;
75     margin: -0.25em;
76     border-width: 0.5em;
77   }
78
79   100% {
80 opacity: 0;
81 width: 15em;
82 height: 15em;
83 margin: -7.5em;
84 border-width: 0.03em;
85 }
86 }
87 `;