ActionEditor.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React, { useState } from 'react';
  2. import { View, Text, TextInput, StyleSheet } from 'react-native';
  3. import InjectionSystem from 'trapilib/dist/lib/systems/InjectionSystem';
  4. import { Picker } from 'react-native';
  5. export default function ActionEditor(props) {
  6. let [action, setAction] = useState(props.value || {});
  7. let ActionSystem = InjectionSystem.inject('Actions');
  8. let RoutingSystem = InjectionSystem.inject('Routing');
  9. let Routes = RoutingSystem.topology.nodes
  10. if (!action.data || typeof action.data !== "object") action.data = {};
  11. if (!action.type) action.type = ActionSystem.constructor.Actions[0].id
  12. return (
  13. <View style={styles.container}>
  14. <Text>{props.title}</Text>
  15. <View style={styles.row}>
  16. <Text>Action</Text>
  17. <Picker
  18. selectedValue={action.id}
  19. style={styles.picker}
  20. onValueChange={(itemValue, itemIndex) => {
  21. action.type = itemValue;
  22. props.onChange && props.onChange(action);
  23. setAction(action)
  24. }}>
  25. {ActionSystem.constructor.Actions.map((itemAction, index) => {
  26. return <Picker.Item label={itemAction.id} value={itemAction.id} key={index} />
  27. })}
  28. </Picker>
  29. </View>
  30. <View style={styles.row}>
  31. <Text>Page</Text>
  32. <Picker
  33. selectedValue={action.data.route}
  34. style={styles.picker}
  35. onValueChange={(itemValue, itemIndex) => {
  36. action.data.route = itemValue;
  37. props.onChange && props.onChange(action);
  38. setAction(action)
  39. }}>
  40. {Object.keys(Routes).map((k, index) => {
  41. return <Picker.Item label={k} value={k} key={index} />
  42. })}
  43. </Picker>
  44. </View>
  45. </View>
  46. );
  47. }
  48. const styles = StyleSheet.create({
  49. container: {
  50. flexDirection: 'column',
  51. borderBottomWidth: 1,
  52. borderColor: '#cecece'
  53. },
  54. capFirst: {
  55. fontSize: 14,
  56. fontFamily: 'roboto-light',
  57. textTransform: 'capitalize'
  58. },
  59. row:{
  60. flexDirection:'row',
  61. justifyContent:"space-between",
  62. alignItems:"center"
  63. },
  64. picker: {
  65. marginTop: 6,
  66. borderWidth: 1,
  67. backgroundColor: 'white',
  68. boxShadow: '0px 3px 6px #00000029',
  69. borderColor: '#FFFFFF66',
  70. borderRadius: 14
  71. },
  72. title: {
  73. }
  74. })