|
@@ -4,38 +4,59 @@ import { Icon } from 'react-native-elements'
|
|
import SketchPicker from 'react-color';
|
|
import SketchPicker from 'react-color';
|
|
|
|
|
|
let rgbaTemplate = /rgba\([ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*\)/;
|
|
let rgbaTemplate = /rgba\([ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*\)/;
|
|
-export default function ColorEditor(props) {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /*let [number , setNumber] = useState(props.number || '')
|
|
|
|
- let title = props.title || "Input";*/
|
|
|
|
-
|
|
|
|
- let matches = rgbaTemplate.exec(props.text || '');
|
|
|
|
|
|
+export default class ColorEditor extends React.Component {
|
|
|
|
+ constructor(props){
|
|
|
|
+ super(props)
|
|
|
|
+ this.state = {
|
|
|
|
+ open:false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ render(){
|
|
|
|
+ let matches = rgbaTemplate.exec(this.props.text || '');
|
|
let defaultColor = {
|
|
let defaultColor = {
|
|
r: matches && parseFloat(matches[1]) || 0,
|
|
r: matches && parseFloat(matches[1]) || 0,
|
|
g: matches && parseFloat(matches)[2] || 0,
|
|
g: matches && parseFloat(matches)[2] || 0,
|
|
b: matches && parseFloat(matches)[3] || 0,
|
|
b: matches && parseFloat(matches)[3] || 0,
|
|
a: matches && parseFloat(matches)[4] || 1
|
|
a: matches && parseFloat(matches)[4] || 1
|
|
};
|
|
};
|
|
- console.log(matches);
|
|
|
|
- console.log(defaultColor);
|
|
|
|
|
|
|
|
- let [color, setColor] = useState(defaultColor);
|
|
|
|
- let title = props.title || "Input";
|
|
|
|
|
|
+ let color = this.state.color || defaultColor;
|
|
|
|
+ let title = this.props.title || "Input";
|
|
|
|
+
|
|
|
|
+ let open = this.state.open ? (
|
|
|
|
+ <View style={styles.container}>
|
|
|
|
+ <View style={styles.prevCont}>
|
|
|
|
+ <Text> Color Fill </Text>
|
|
|
|
+ <View onClick = {(e) => this.setState({open:false})} style={[{backgroundColor:this.props.text},styles.preview]}></View>
|
|
|
|
+ </View>
|
|
|
|
+ <SketchPicker
|
|
|
|
+ color={color}
|
|
|
|
+ width="180px" onChangeComplete ={(newColor) => {
|
|
|
|
+ this.props.onChange && this.props.onChange(`rgba(${newColor.rgb.r},${newColor.rgb.g},${newColor.rgb.b},${newColor.rgb.a})`);
|
|
|
|
+ this.setState({color:newColor.rgb});
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ </View>
|
|
|
|
+ ):(
|
|
|
|
+ <View key={Math.random()} style={styles.prevCont}>
|
|
|
|
+ <Text>Color Fill</Text>
|
|
|
|
+ <View onClick = {(e) => this.setState({open:true})} style={[{backgroundColor:this.props.text},styles.preview]}></View>
|
|
|
|
+ </View>
|
|
|
|
+ )
|
|
return(
|
|
return(
|
|
- <View style={styles.container}>
|
|
|
|
- <Text> Color Picker </Text>
|
|
|
|
- <SketchPicker
|
|
|
|
- color={color}
|
|
|
|
- width="180px" onChangeComplete ={(newColor) => {
|
|
|
|
- props.onChange && props.onChange(`rgba(${newColor.rgb.r},${newColor.rgb.g},${newColor.rgb.b},${newColor.rgb.a})`);
|
|
|
|
- setColor(newColor.rgb);
|
|
|
|
- }}
|
|
|
|
- />
|
|
|
|
-
|
|
|
|
- </View>
|
|
|
|
|
|
+ <View>
|
|
|
|
+ <Text>{this.props.title}</Text>
|
|
|
|
+ {open}
|
|
|
|
+ </View>
|
|
|
|
+
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
const styles = StyleSheet.create({
|
|
@@ -47,8 +68,17 @@ const styles = StyleSheet.create({
|
|
borderWidth:1,
|
|
borderWidth:1,
|
|
width:100
|
|
width:100
|
|
},
|
|
},
|
|
- title: {
|
|
|
|
-
|
|
|
|
|
|
+ prevCont:{
|
|
|
|
+ flex:1,
|
|
|
|
+ flexDirection:'row'
|
|
|
|
+ },
|
|
|
|
+ preview:{
|
|
|
|
+ width: 43,
|
|
|
|
+ height: 19,
|
|
|
|
+ boxShadow: '0px 3px 6px #00000029',
|
|
|
|
+ border: '1px solid #FFFFFF',
|
|
|
|
+ borderRadius: 14,
|
|
|
|
+ opacity: 1
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|