@@ -13,7 +13,8 @@ export default class Cube extends React.Component {
13
13
this . state = {
14
14
x : 0 ,
15
15
y : 0 ,
16
- z : 0
16
+ z : 0 ,
17
+ iteration : 0 ,
17
18
} ;
18
19
}
19
20
@@ -47,7 +48,7 @@ export default class Cube extends React.Component {
47
48
rotateY(${ y } deg)
48
49
rotateZ(${ z } deg)`
49
50
} } >
50
- { this . _getFaces ( ) }
51
+ { this . _getFaces ( 'outer' ) }
51
52
</ figure >
52
53
< figure
53
54
className = "cube__inner"
@@ -60,7 +61,7 @@ export default class Cube extends React.Component {
60
61
rotateY(${ - y } deg)
61
62
rotateZ(${ - z } deg)`
62
63
} } >
63
- { this . _getFaces ( ) }
64
+ { this . _getFaces ( 'inner' ) }
64
65
</ figure >
65
66
</ span >
66
67
</ div >
@@ -80,14 +81,9 @@ export default class Cube extends React.Component {
80
81
81
82
this . _interval = setInterval ( ( ) => {
82
83
let obj = { } ;
83
- let sign = Math . random ( ) < 0.5 ? - 1 : 1 ;
84
-
85
84
obj [ axis ] = degrees += 90 ;
86
85
87
- // axis = axis === 'x' ? 'y' : axis === 'y' ? 'z' : 'x';
88
-
89
- this . setState ( obj ) ;
90
- console . log ( 'cube spin' ) ;
86
+ this . setState ( { ...obj , iteration : ( this . state . iteration + 1 ) % 4 } ) ;
91
87
} , repeatDelay ) ;
92
88
}
93
89
}
@@ -107,9 +103,53 @@ export default class Cube extends React.Component {
107
103
/**
108
104
* Get all faces for a cube
109
105
*
106
+ * @param {'inner' | 'outer' } type
110
107
* @return {array } - An array of nodes
111
108
*/
112
- _getFaces ( ) {
109
+ _getFaces ( type ) {
110
+ let { iteration } = this . state ;
111
+
112
+ // Keep the thicker border on
113
+ // the outside on each iteration
114
+ const borderWidthMap = {
115
+ 0 : {
116
+ left : [ 1 , 1 , 1 , 6 ] ,
117
+ right : [ 6 , 1 , 1 , 1 ] ,
118
+ top : [ 1 , 1 , 1 , 1 ] ,
119
+ bottom : [ 6 , 1 , 1 , 6 ] ,
120
+ } ,
121
+ 1 : {
122
+ left : [ 1 , 1 , 1 , 1 ] ,
123
+ right : [ 1 , 1 , 1 , 1 ] ,
124
+ top : [ 1 , 1 , 1 , 1 ] ,
125
+ bottom : [ 1 , 1 , 1 , 1 ] ,
126
+ } ,
127
+ 2 : {
128
+ left : [ 1 , 1 , 6 , 6 ] ,
129
+ right : [ 6 , 6 , 1 , 1 ] ,
130
+ top : [ 6 , 1 , 1 , 6 ] ,
131
+ bottom : [ 1 , 6 , 6 , 1 ] ,
132
+ } ,
133
+ 3 : {
134
+ left : [ 6 , 1 , 1 , 1 ] ,
135
+ right : [ 1 , 6 , 1 , 1 ] ,
136
+ top : [ 1 , 1 , 1 , 1 ] ,
137
+ bottom : [ 6 , 6 , 1 , 1 ] ,
138
+ } ,
139
+ 4 : {
140
+ left : [ 1 , 1 , 6 , 1 ] ,
141
+ right : [ 1 , 1 , 1 , 6 ] ,
142
+ top : [ 1 , 1 , 1 , 1 ] ,
143
+ bottom : [ 1 , 1 , 6 , 6 ] ,
144
+ } ,
145
+ 5 : {
146
+ left : [ 1 , 6 , 1 , 1 ] ,
147
+ right : [ 1 , 1 , 6 , 1 ] ,
148
+ top : [ 1 , 1 , 1 , 1 ] ,
149
+ bottom : [ 1 , 6 , 6 , 1 ] ,
150
+ }
151
+ } ;
152
+
113
153
return [
114
154
'rotateX(0deg)' ,
115
155
'rotateX(-90deg)' ,
@@ -118,12 +158,20 @@ export default class Cube extends React.Component {
118
158
'rotateY(90deg)' ,
119
159
'rotateY(180deg)'
120
160
] . map ( ( rotation , i ) => {
161
+ const borderStyles = type === 'outer' ? {
162
+ borderTopWidth : borderWidthMap [ i ] . top [ iteration ] ,
163
+ borderRightWidth : borderWidthMap [ i ] . right [ iteration ] ,
164
+ borderBottomWidth : borderWidthMap [ i ] . bottom [ iteration ] ,
165
+ borderLeftWidth : borderWidthMap [ i ] . left [ iteration ] ,
166
+ } : { } ;
167
+
121
168
return (
122
169
< section
123
170
key = { i }
124
171
className = "cube__face"
125
- style = { {
126
- transform : `${ rotation } translateZ(${ this . props . depth / 2 } px)`
172
+ style = { {
173
+ transform : `${ rotation } translateZ(${ this . props . depth / 2 } px)` ,
174
+ ...borderStyles ,
127
175
} } />
128
176
) ;
129
177
} ) ;
0 commit comments