This repository was archived by the owner on May 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +15
-16
lines changed Expand file tree Collapse file tree 5 files changed +15
-16
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,6 @@ import cloneDeep from 'lodash.clonedeep';
4
4
import isUndefined from 'lodash.isundefined' ;
5
5
import React , { PropTypes , cloneElement } from 'react' ;
6
6
7
- function uuid ( a ) {
8
- // https://gist.github.com/jed/982883
9
- return a ? ( a ^ Math . random ( ) * 16 >> a / 4 ) . toString ( 16 ) : ( [ 1e7 ] + - 1e3 + - 4e3 + - 8e3 + - 1e11 ) . replace ( / [ 0 1 8 ] / g, uuid ) ;
10
- }
11
-
12
7
class Dat extends React . Component {
13
8
14
9
static propTypes = {
@@ -25,6 +20,7 @@ class Dat extends React.Component {
25
20
liveUpdate : true ,
26
21
} ;
27
22
23
+
28
24
constructor ( props , context ) {
29
25
super ( props , context ) ;
30
26
this . handleUpdateValue = this . handleUpdateValue . bind ( this ) ;
@@ -41,7 +37,6 @@ class Dat extends React.Component {
41
37
return React . Children . toArray ( children ) . map ( ( child , i ) => {
42
38
const liveUpdate = isUndefined ( child . props . liveUpdate ) ? this . props . liveUpdate : child . props . liveUpdate ;
43
39
return cloneElement ( child , {
44
- id : uuid ( ) ,
45
40
key : i ,
46
41
data,
47
42
liveUpdate,
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ import result from 'lodash.result';
2
2
import isFinite from 'lodash.isfinite' ;
3
3
import isString from 'lodash.isstring' ;
4
4
import React , { PropTypes } from 'react' ;
5
+ import { createId } from '../utils' ;
5
6
6
7
class DatBoolean extends React . Component {
7
8
8
9
static propTypes = {
9
- id : PropTypes . string ,
10
10
data : PropTypes . object ,
11
11
path : PropTypes . string ,
12
12
label : PropTypes . string ,
@@ -25,6 +25,7 @@ class DatBoolean extends React.Component {
25
25
26
26
componentWillMount ( ) {
27
27
this . setState ( {
28
+ id : createId ( ) ,
28
29
value : this . getValue ( )
29
30
} ) ;
30
31
}
@@ -52,8 +53,7 @@ class DatBoolean extends React.Component {
52
53
}
53
54
54
55
render ( ) {
55
- const { id } = this . props ;
56
- const { value } = this . state ;
56
+ const { value, id } = this . state ;
57
57
const label = isString ( this . props . label ) ? this . props . label : this . props . path ;
58
58
return (
59
59
< li className = "cr boolean" >
Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ import result from 'lodash.result';
4
4
import isFinite from 'lodash.isfinite' ;
5
5
import isString from 'lodash.isstring' ;
6
6
import React , { PropTypes } from 'react' ;
7
+ import { createId } from '../utils' ;
7
8
8
9
class DatNumber extends React . Component {
9
10
10
11
static propTypes = {
11
- id : PropTypes . string ,
12
12
data : PropTypes . object ,
13
13
path : PropTypes . string ,
14
14
label : PropTypes . string ,
@@ -31,13 +31,13 @@ class DatNumber extends React.Component {
31
31
this . handleMouseMove = this . handleMouseMove . bind ( this ) ;
32
32
this . handleMouseUp = this . handleMouseUp . bind ( this ) ;
33
33
this . state = {
34
- value : 0 ,
35
34
isSliderActive : false ,
36
35
} ;
37
36
}
38
37
39
38
componentWillMount ( ) {
40
39
this . setState ( {
40
+ id : createId ( ) ,
41
41
value : this . getValue ( )
42
42
} ) ;
43
43
}
@@ -144,8 +144,8 @@ class DatNumber extends React.Component {
144
144
}
145
145
146
146
render ( ) {
147
- const { id , min, max, _labelWidth } = this . props ;
148
- const { value, isSliderActive } = this . state ;
147
+ const { min, max, _labelWidth } = this . props ;
148
+ const { value, isSliderActive, id } = this . state ;
149
149
const label = isString ( this . props . label ) ? this . props . label : this . props . path ;
150
150
const hasSlider = isFinite ( min ) && isFinite ( min ) ;
151
151
const labelStyle = _labelWidth ? { width : `${ _labelWidth } %` } : { } ;
Original file line number Diff line number Diff line change 1
1
import result from 'lodash.result' ;
2
2
import isString from 'lodash.isstring' ;
3
3
import React , { PropTypes } from 'react' ;
4
+ import { createId } from '../utils' ;
4
5
5
6
class DatString extends React . Component {
6
7
7
8
static propTypes = {
8
- id : PropTypes . string ,
9
9
data : PropTypes . object ,
10
10
path : PropTypes . string ,
11
11
label : PropTypes . string ,
@@ -23,6 +23,7 @@ class DatString extends React.Component {
23
23
24
24
componentWillMount ( ) {
25
25
this . setState ( {
26
+ id : createId ( ) ,
26
27
value : this . getValue ( )
27
28
} ) ;
28
29
}
@@ -56,8 +57,8 @@ class DatString extends React.Component {
56
57
}
57
58
58
59
render ( ) {
59
- const { id , _labelWidth } = this . props ;
60
- const { value } = this . state ;
60
+ const { _labelWidth } = this . props ;
61
+ const { value, id } = this . state ;
61
62
const label = isString ( this . props . label ) ? this . props . label : this . props . path ;
62
63
const labelStyle = _labelWidth ? { width : `${ _labelWidth } %` } : { } ;
63
64
const inputStyle = _labelWidth ? { width : `${ 100 - _labelWidth } %` } : { } ;
Original file line number Diff line number Diff line change
1
+ let currentId = 0 ;
2
+
3
+ export const createId = ( ) => `__react_dat_gui_${ currentId ++ } __` ;
You can’t perform that action at this time.
0 commit comments