Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit 3b97832

Browse files
Added script for promoting example dev code back to src directory. Renamed example scripts so that they are prefaced with example- rather than the action. Promoted example code to src
1 parent 6472ebd commit 3b97832

File tree

14 files changed

+636
-2
lines changed

14 files changed

+636
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"build": "webpack --env build",
3030
"dev": "webpack --progress --colors --watch --env dev",
3131
"example": "npm run start --prefix example",
32-
"example:seed": "sh scripts/seed-example",
32+
"example:seed": "sh scripts/example-seed",
33+
"example:promote": "sh scripts/example-promote",
3334
"test": "mocha --compilers js:babel-core/register --colors ./test/*.spec.js",
3435
"test:watch": "mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js",
3536
"lint": "eslint src test build",

scripts/example-promote

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
rm -rf src;
3+
cp -r example/src/dev src;
File renamed without changes.

src/components/DatBoolean.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import isString from 'lodash.isstring';
55
import result from 'lodash.result';
66

77
export default class DatBoolean extends Component {
8-
98
static propTypes = {
109
data: PropTypes.object,
1110
path: PropTypes.string,

src/components/DatColor.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import React, { Component } from 'react';
2+
3+
import ColorPicker from './Picker/';
4+
import PropTypes from 'prop-types';
5+
import isString from 'lodash.isstring';
6+
import reactCSS from 'reactcss';
7+
import result from 'lodash.result';
8+
9+
export default class DatColor extends Component {
10+
static propTypes = {
11+
data: PropTypes.object,
12+
path: PropTypes.string,
13+
label: PropTypes.string,
14+
labelWidth: PropTypes.number,
15+
liveUpdate: PropTypes.bool,
16+
onUpdate: PropTypes.func,
17+
_onUpdateValue: PropTypes.func,
18+
};
19+
20+
state = {
21+
value: this.getValue(),
22+
displayColorPicker: false,
23+
}
24+
25+
componentWillMount() {
26+
this.setState({
27+
value: this.getValue()
28+
});
29+
}
30+
31+
componentWillReceiveProps(nextProps) {
32+
this.setState({
33+
value: this.getValue(nextProps)
34+
});
35+
}
36+
37+
getValue(props = this.props) {
38+
return result(props.data, props.path);
39+
}
40+
41+
handleClick = () => {
42+
this.setState({
43+
displayColorPicker: !this.state.displayColorPicker
44+
});
45+
};
46+
47+
handleClose = () => {
48+
this.setState({
49+
displayColorPicker: false
50+
});
51+
};
52+
53+
handleChange = color => {
54+
const value = isString(color) ? color : color.hex;
55+
56+
this.setState({ value }, () => {
57+
this.props.liveUpdate && this.update();
58+
});
59+
}
60+
61+
update() {
62+
const { value } = this.state;
63+
64+
this.props._onUpdateValue && this.props._onUpdateValue(this.props.path, value);
65+
this.props.onUpdate && this.props.onUpdate(value);
66+
}
67+
68+
renderPicker(styles) {
69+
const { value, displayColorPicker } = this.state;
70+
71+
return (!displayColorPicker) ? null : (
72+
<div style={ styles.popover }>
73+
<div style={ styles.cover } onClick={ this.handleClose }/>
74+
<ColorPicker color={ value } onChange={ this.handleChange } />
75+
</div>
76+
);
77+
}
78+
79+
render() {
80+
const { path, label, labelWidth } = this.props;
81+
const { value } = this.state;
82+
const labelText = isString(label) ? label : path;
83+
const styles = reactCSS({
84+
'default': {
85+
color: {
86+
width: '36px',
87+
height: '14px',
88+
borderRadius: '2px',
89+
backgroundColor: `${value}`,
90+
},
91+
swatch: {
92+
padding: '5px',
93+
background: '#fff',
94+
borderRadius: '1px',
95+
boxShadow: '0 0 0 1px rgba(0,0,0,.1)',
96+
display: 'inline-block',
97+
cursor: 'pointer',
98+
},
99+
popover: {
100+
position: 'absolute',
101+
zIndex: '2',
102+
right: '4px'
103+
},
104+
cover: {
105+
position: 'fixed',
106+
top: '0px',
107+
right: '0px',
108+
bottom: '0px',
109+
left: '0px',
110+
},
111+
},
112+
});
113+
114+
return (
115+
<li className="cr color" style={{borderLeftColor: `${value}`}}>
116+
<label>
117+
<span className="label-text" style={{ width: `${labelWidth}%` }}>{labelText}</span>
118+
<div style={{ width: `${100 - labelWidth}%`, backgroundColor: `${value}` }}>
119+
<div className='swatch' onClick={ this.handleClick }>
120+
{value}
121+
</div>
122+
{this.renderPicker(styles)}
123+
</div>
124+
</label>
125+
</li>
126+
);
127+
}
128+
}

src/components/Picker/Fields.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { Component } from 'react';
2+
3+
import { EditableInput } from 'react-color/lib/components/common';
4+
import color from 'react-color/lib/helpers/color';
5+
6+
export default class Fields extends Component {
7+
handleChange = (value, e) => {
8+
color.isValidHex(value) && this.props.onChange({
9+
hex: value,
10+
source: 'hex',
11+
}, e);
12+
}
13+
14+
render() {
15+
return (
16+
<div className="flexbox-fix fields-wrap">
17+
<div className="flexbox-fix fields">
18+
<div className='field'>
19+
<EditableInput
20+
value={this.props.hex}
21+
onChange={this.handleChange}
22+
/>
23+
</div>
24+
</div>
25+
</div>
26+
);
27+
}
28+
}

src/components/Picker/Pointer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
const Pointer = () => <div className='pointer' />;
4+
5+
export default Pointer;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
const PointerCircle = () => <div className='pointer-circle' />;
4+
5+
export default PointerCircle;

src/components/Picker/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ColorWrap, Hue, Saturation } from 'react-color/lib/components/common';
2+
3+
import Fields from './Fields';
4+
import Pointer from './Pointer';
5+
import PointerCircle from './PointerCircle';
6+
import PropTypes from 'prop-types';
7+
import React from 'react';
8+
9+
const Picker = ({
10+
onChange,
11+
hsl,
12+
hsv,
13+
hex,
14+
className = ''
15+
}) => {
16+
return (
17+
<div className={`picker ${className}`}>
18+
<div className='saturation-wrap'>
19+
<Saturation
20+
className='saturation'
21+
hsl={hsl}
22+
hsv={hsv}
23+
pointer={PointerCircle}
24+
onChange={onChange}
25+
/>
26+
</div>
27+
<div className='body'>
28+
<div className="controls">
29+
<div className='toggles'>
30+
<div className='hue-wrap'>
31+
<Hue
32+
className='hue'
33+
hsl={hsl}
34+
pointer={Pointer}
35+
onChange={onChange}
36+
/>
37+
</div>
38+
</div>
39+
</div>
40+
<Fields
41+
hex={hex}
42+
onChange={onChange}
43+
/>
44+
</div>
45+
</div>
46+
);
47+
};
48+
49+
Picker.propTypes = {
50+
disableAlpha: PropTypes.bool,
51+
};
52+
53+
Picker.defaultProps = {
54+
disableAlpha: false,
55+
};
56+
57+
export default ColorWrap(Picker);

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ export { default as DatBoolean } from './components/DatBoolean';
6666
export { default as DatButton } from './components/DatButton';
6767
export { default as DatFolder } from './components/DatFolder';
6868
export { default as DatSelect } from './components/DatSelect';
69+
export { default as DatColor } from './components/DatColor';

0 commit comments

Comments
 (0)