1+ import React , { Component } from 'react' ;
2+ import Navbar from "./navbar" ;
3+ import FlipMove from 'react-flip-move' ;
4+ import SvgLines from 'react-mt-svg-lines' ;
5+ import '../helpers/array_helpers' ;
6+ import './style.css' ;
7+ import { times } from 'lodash' ;
8+
9+ const FLIP_DURATION = 750 ;
10+
11+ class Puzzle extends Component {
12+ constructor ( ) {
13+ super ( ) ;
14+ this . state = {
15+ squares : times ( 16 , i => ( {
16+ value : i
17+ } ) ) ,
18+ } ;
19+ }
20+
21+ balsal = async ( ) => {
22+ for ( let i = 0 ; i < 15 ; i ++ ) {
23+ this . setState ( {
24+ squares : this . state . squares . slice ( ) . swap ( i , i + 1 )
25+ } ) ;
26+ await sleep ( 500 ) ;
27+ }
28+
29+ }
30+
31+ render ( ) {
32+ let classNames ;
33+ return (
34+ < div style = { { backgroundColor : "#57407c" , height : '100' } }
35+ className = { 'full-height' }
36+ >
37+ < Navbar />
38+ < center className = { 'justify-content-around ' }
39+ style = { { textAlign : "Center" } } >
40+ < div style = { { textAlign : "center" , height : "440px" , width : "440px" , margin : 'auto' } }
41+ className = { "m-5" } >
42+ < FlipMove
43+ duration = { FLIP_DURATION }
44+ easing = "cubic-bezier(.12,.36,.14,1.2)"
45+ >
46+ { this . state . squares . map ( ( stt ) =>
47+ < div key = { stt . value }
48+ className = { stt . value === 0 ? "square " : stt . value % 2 === 0 ? 'square shadow correct pt-1' : 'square shadow painted pt-1' }
49+ >
50+ { stt . value === 0 ? "" : stt . value }
51+ </ div >
52+ ) }
53+ < br />
54+ </ FlipMove >
55+ < button className = { "btn btn-secondary" } onClick = { this . balsal } > Animate</ button >
56+ </ div >
57+
58+ { /*<FlipMove*/ }
59+ { /* duration={FLIP_DURATION}*/ }
60+ { /* easing="cubic-bezier(.12,.36,.14,1.2)" >*/ }
61+ { /* <line key={5464} style={{strokeWidth: "3px", stroke: '#999'}} x2={299} y2={186}*/ }
62+ { /* x1={(this.state.squares[0].value + 1) * 50}*/ }
63+ { /* y1={(this.state.squares[0].value + 1) * 50}></line>*/ }
64+ { /* <div key={this.state.squares[0].value}*/ }
65+ { /* className={'square shadow correct pt-1'}>*/ }
66+ { /* {this.state.squares[0].value}*/ }
67+ { /* </div>*/ }
68+ { /* <div key={this.state.squares[1].value}*/ }
69+ { /* className={'square shadow correct pt-1'}>*/ }
70+ { /* {this.state.squares[1].value}*/ }
71+ { /* </div>*/ }
72+ { /*</FlipMove>*/ }
73+ { /*/!*<SvgLines animate={true} duration={1000}>*!/*/ }
74+ { /*/!* <svg viewBox="0 0 960 500">*!/*/ }
75+ { /*/!* <line key={5464} style={{strokeWidth: "3px", stroke: '#999'}} x2={299} y2={186}*!/*/ }
76+ { /*/!* x1={(this.state.squares[0].value + 1) * 50}*!/*/ }
77+ { /*/!* y1={(this.state.squares[0].value + 1) * 50}></line>*!/*/ }
78+ { /*/!* </svg>*!/*/ }
79+ { /*/!*</SvgLines>*!/*/ }
80+ </ center >
81+
82+ </ div >
83+ ) ;
84+ }
85+ }
86+
87+ function sleep ( ms ) {
88+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
89+ }
90+
91+ export default Puzzle ;
0 commit comments