-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTestApp.tsx
More file actions
295 lines (284 loc) · 9.27 KB
/
Copy pathTestApp.tsx
File metadata and controls
295 lines (284 loc) · 9.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import * as React from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import ReactDice, { ReactDiceRef } from '../lib/ReactDice'
const TestApp = () => {
const [defaultRoll, setDefaultRoll] = useState(1)
const [diceTotal, setDiceTotal] = useState()
const [dieCornerRadius, setDieCornerRadius] = useState(5)
const [dieSize, setDieSize] = useState(60)
const [disableIndividual, setDisableIndividual] = useState(false)
const [disableRandom, setDisableRandom] = useState(false)
const [dotColor, setDotColor] = useState('#1eff00')
const [faceColor, setFaceColor] = useState('#FF00AC')
const [margin, setMargin] = useState(15)
const [numDice, setNumDice] = useState(1)
const [outline, setOutline] = useState(false)
const [outlineColor, setOutlineColor] = useState('#000000')
const [rolling, setRolling] = useState(false)
const [rollTime, setRollTime] = useState(2)
const [sides, setSides] = useState(6)
const reactDice = useRef<ReactDiceRef>(null)
const rollDone = (value, values) => {
setRolling(false)
setDiceTotal(value)
}
const handleOnRoll = () => {
console.log('Rolling...');
}
const rollAll = () => {
reactDice.current?.rollAll()
setRolling(true)
}
useEffect(() => {
if (window.innerWidth < 576) {
document.getElementById('collapseForm')?.classList.remove('show')
} else {
document.getElementById('collapseForm')?.classList.add('show')
}
}, [])
const getDice = useCallback(() => {
return (
<ReactDice
defaultRoll={defaultRoll}
dieCornerRadius={dieCornerRadius}
dieSize={dieSize}
disableIndividual={disableIndividual}
disableRandom={disableRandom}
dotColor={dotColor}
faceColor={faceColor}
margin={margin}
numDice={numDice}
outline={outline}
outlineColor={outlineColor}
ref={reactDice}
onRoll={handleOnRoll}
rollDone={rollDone}
rollTime={rollTime}
sides={sides}
/>
)
}, [
defaultRoll,
dieCornerRadius,
dieSize,
disableIndividual,
disableRandom,
dotColor,
faceColor,
margin,
numDice,
outline,
outlineColor,
handleOnRoll,
rollDone,
rollTime,
sides,
])
let colorStyle = { height: '2.375rem' }
return (
<div className='dice-test'>
<a
className='row card card-header collapse-title hidden-sm-up'
data-toggle='collapse'
href='#collapseForm'
aria-expanded='false'
aria-controls='collapseForm'
>
Show Config Options ▼
</a>
<div className='collapse' id='collapseForm'>
<form className='row controls align-items-end'>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='numDice'>Dice</label>
<input
type='number'
name='numDice'
id='numDice'
className='form-control'
value={numDice}
onChange={(e) => setNumDice(parseInt(e.target.value, 10))}
min='1'
max='100'
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='faceColor'>Face Color</label>
<input
type='color'
name='faceColor'
id='faceColor'
className='form-control'
style={colorStyle}
value={faceColor}
onChange={(e) => setFaceColor(e.target.value)}
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='dotColor'>Dot Color</label>
<input
type='color'
name='dotColor'
id='dotColor'
className='form-control'
style={colorStyle}
value={dotColor}
onChange={(e) => setDotColor(e.target.value)}
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='dieSize'>Die Size (px)</label>
<input
type='number'
name='dieSize'
id='dieSize'
className='form-control'
value={dieSize}
onChange={(e) => setDieSize(parseInt(e.target.value, 10))}
min='30'
max='200'
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='dieSize'>Margin Between (px)</label>
<input
type='number'
name='margin'
id='margin'
className='form-control'
value={margin}
onChange={(e) => setMargin(parseInt(e.target.value, 10))}
min='0'
max='200'
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='dieSize'>Corner Radius (px)</label>
<input
type='number'
name='dieCornerRadius'
id='dieCornerRadius'
className='form-control'
value={dieCornerRadius}
onChange={(e) => setDieCornerRadius(parseInt(e.target.value, 10))}
min='0'
max='200'
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<label htmlFor='rollTime'>Roll Time (seconds)</label>
<input
type='number'
name='rollTime'
id='rollTime'
className='form-control'
value={rollTime}
onChange={(e) => setRollTime(parseInt(e.target.value, 10))}
min='1'
max='4'
/>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<div className='form-check'>
<label className='form-check-label'>
<input
type='checkbox'
className='form-check-input'
name='outline'
id='outline'
checked={outline}
onChange={() => setOutline(!outline)}
/>
{' '}Outline
</label>
</div>
<div>
<input
type='color'
name='outlineColor'
id='outlineColor'
className='form-control'
style={colorStyle}
value={outlineColor}
onChange={(e) => setOutlineColor(e.target.value)}
disabled={!outline}
/>
</div>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<div className='form-check'>
<label className='form-check-label'>
<input
type='checkbox'
className='form-check-input'
name='disableIndividual'
id='disableIndividual'
checked={disableIndividual}
onChange={() => setDisableIndividual(!disableIndividual)}
/>{' '}
Disable individual roll on click
</label>
</div>
</fieldset>
<fieldset className='form-group col-xs-6 col-sm-4 col-md-3'>
<div className='form-check'>
<label className='form-check-label'>
<input
type='checkbox'
className='form-check-input'
name='disableRandom'
id='disableRandom'
checked={disableRandom}
onChange={() => setDisableRandom(!disableRandom)}
/>{' '}
Disable random rolls
</label>
</div>
</fieldset>
</form>
</div>
<div className='row info'>
<div className='col'>
<h4>
<button className='btn btn-primary' onClick={rollAll}>
Roll All
</button>
{' '} or click individual dice
</h4>
</div>
<div className='col'>
<h4 className='text-primary'>
Dice Total:
<span
style={{
display: rolling ? 'none' : 'inline-block',
paddingLeft: '5px',
}}
>
{diceTotal || '...'}
</span>
<div
className='sk-cube-grid'
style={{
display: rolling ? 'inline-block' : 'none',
}}
>
<div className='sk-cube sk-cube1' />
<div className='sk-cube sk-cube2' />
<div className='sk-cube sk-cube3' />
<div className='sk-cube sk-cube4' />
<div className='sk-cube sk-cube5' />
<div className='sk-cube sk-cube6' />
<div className='sk-cube sk-cube7' />
<div className='sk-cube sk-cube8' />
<div className='sk-cube sk-cube9' />
</div>
</h4>
</div>
</div>
<div className='row dice'>
<div className='col'>{getDice()}</div>
</div>
</div>
)
}
export default TestApp