MainBar.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import React from 'react';
  2. import {StyleSheet, View, Text , Button } from 'react-native';
  3. import { Icon } from 'react-native-elements'
  4. import { TextInput } from 'react-native';
  5. import BaseSystem from './System'
  6. import { Ionicons } from '@expo/vector-icons';
  7. class Menu extends BaseSystem {
  8. constructor() {
  9. super();
  10. this.items = [];
  11. }
  12. addItem(item) {
  13. this.items.push(item);
  14. return this;
  15. }
  16. show() { this.visible = true; this.forceUpdate() }
  17. hide() { this.visible = false; this.forceUpdate() }
  18. toggle() { this.visible = !this.visible; this.forceUpdate() }
  19. render() {
  20. return this.visible ? <div style={{position:'relative', left: 0, top: 50}}
  21. onMouseLeave={() => this.hide()}>
  22. <View style={styles.menu}>
  23. {this.items.map((item) => {
  24. let {
  25. text,
  26. ...rest
  27. } = item;
  28. return <View style={{cursor: 'pointer'}} {...rest}>
  29. <Text>{item.text}</Text>
  30. </View>
  31. })}
  32. </View>
  33. </div> : null;
  34. }
  35. }
  36. export default class MainBar extends BaseSystem {
  37. constructor(CS){
  38. super();
  39. this.__save = null
  40. this.CoreSystem = CS;
  41. this.Menu = new Menu();
  42. this.Menu.addItem({
  43. text: "New page",
  44. onClick: () => this.createPage()
  45. }).addItem({
  46. text: "Save",
  47. onClick: () => this.save()
  48. }).addItem({
  49. text: "Export",
  50. onClick: () => this.export()
  51. }).onUpdate(() => this.forceUpdate());
  52. }
  53. export() {
  54. let json = JSON.stringify(this.CoreSystem.export());
  55. console.log(json);
  56. }
  57. onSave(fn){
  58. this.__save = fn;
  59. }
  60. save(){
  61. this.__save && this.__save();
  62. }
  63. triggerSave(){
  64. this.save();
  65. }
  66. createPage() {
  67. // think!
  68. // Create a new page on CoreSystem
  69. // switch to it as active view
  70. // Decide how page switching works
  71. }
  72. none(){
  73. }
  74. toggleMenu() {
  75. this.Menu.toggle();
  76. }
  77. showMenu() {
  78. this.Menu.show();
  79. }
  80. hideMenu() {
  81. this.Menu.hide();
  82. }
  83. render(){
  84. return (
  85. <View style={styles.container}>
  86. <View style={ styles.innerContainer }>
  87. <Text style={styles.item}>
  88. <Icon
  89. name='menu'
  90. color="#606060"
  91. onPress={(e) => this.toggleMenu()}
  92. />
  93. </Text>
  94. <Text style={styles.item}>
  95. <Icon
  96. name='home'
  97. color="#606060"
  98. />
  99. </Text>
  100. <Text style={[styles.item, styles.selectedItem]}>
  101. Design
  102. </Text>
  103. <Text style={styles.item}>
  104. Structure
  105. </Text>
  106. </View>
  107. <View style={ styles.innerContainer }>
  108. <Text style={[styles.item, {fontSize: 18, lineHeight: 24}]}
  109. onPress={(e) => this.triggerSave()}
  110. title="Save"
  111. color="#606060"
  112. >Save</Text>
  113. <Text style={[styles.item, {fontSize: 18, lineHeight: 24}]}
  114. onPress={(e) => this.export()}
  115. title="Export"
  116. color="#606060"
  117. >Export</Text>
  118. <Text style={[styles.item, {fontSize: 18, lineHeight: 24}]}>
  119. Giorgos Markou
  120. </Text>
  121. <Text style={styles.item}>
  122. <Icon name="account-circle" color="#606060"/>
  123. </Text>
  124. </View>
  125. {this.Menu.render()}
  126. </View>)
  127. }
  128. }
  129. const styles = StyleSheet.create({
  130. container:{
  131. flex:1,
  132. paddingRight:8,
  133. paddingLeft:8,
  134. paddingTop: 8,
  135. paddingBottom: 8,
  136. flexDirection:'row',
  137. justifyContent: 'space-between'
  138. },
  139. innerContainer: {
  140. flexDirection: 'row',
  141. paddingTop: 4,
  142. paddingLeft: 0,
  143. paddingRight: 0,
  144. paddingBottom: 4
  145. },
  146. item: {
  147. paddingLeft: 8,
  148. paddingRight: 8,
  149. fontFamily: 'thin',
  150. lineHeight: 25,
  151. cursor: 'pointer'
  152. },
  153. selectedItem: {
  154. borderColor: '#36BBAD',
  155. borderBottomWidth: 1
  156. },
  157. menu: {
  158. height:100,
  159. width: 200,
  160. backgroundColor: 'gray'
  161. }
  162. })