ColorEditor.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { useState } from 'react';
  2. import {View , Text, TextInput, Button,StyleSheet} from 'react-native';
  3. import { Icon } from 'react-native-elements'
  4. import SketchPicker from 'react-color';
  5. let rgbaTemplate = /rgba\([ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*,[ ]*([0-9.]+)[ ]*\)/;
  6. export default function ColorEditor(props) {
  7. /*let [number , setNumber] = useState(props.number || '')
  8. let title = props.title || "Input";*/
  9. let matches = rgbaTemplate.exec(props.text || '');
  10. let defaultColor = {
  11. r: matches && parseFloat(matches[1]) || 0,
  12. g: matches && parseFloat(matches)[2] || 0,
  13. b: matches && parseFloat(matches)[3] || 0,
  14. a: matches && parseFloat(matches)[4] || 1
  15. };
  16. console.log(matches);
  17. console.log(defaultColor);
  18. let [color, setColor] = useState(defaultColor);
  19. let title = props.title || "Input";
  20. return(
  21. <View style={styles.container}>
  22. <Text> Color Picker </Text>
  23. <SketchPicker
  24. color={color}
  25. width="180px" onChangeComplete ={(newColor) => {
  26. props.onChange && props.onChange(`rgba(${newColor.rgb.r},${newColor.rgb.g},${newColor.rgb.b},${newColor.rgb.a})`);
  27. setColor(newColor.rgb);
  28. }}
  29. />
  30. </View>
  31. )
  32. }
  33. const styles = StyleSheet.create({
  34. container:{
  35. padding:10
  36. },
  37. defaultInput: {
  38. marginTop:6,
  39. borderWidth:1,
  40. width:100
  41. },
  42. title: {
  43. }
  44. })