From ff9d52e3e03d706a1f9f91b6505e85d0c884c824 Mon Sep 17 00:00:00 2001 From: ChristianEdwardPadilla Date: Thu, 9 May 2019 20:58:05 -0400 Subject: [PATCH 1/5] no changes --- src/components/Props.tsx | 193 +++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 98 deletions(-) diff --git a/src/components/Props.tsx b/src/components/Props.tsx index 6f3749b0f..67d8e4e8b 100644 --- a/src/components/Props.tsx +++ b/src/components/Props.tsx @@ -1,16 +1,16 @@ -import React, { Component, Fragment } from "react"; -import { connect } from "react-redux"; -import { withStyles } from "@material-ui/core/styles"; -import FormControl from "@material-ui/core/FormControl"; -import Grid from "@material-ui/core/Grid"; -import TextField from "@material-ui/core/TextField"; -import Button from "@material-ui/core/Button"; -import Select from "@material-ui/core/Select"; -import Switch from "@material-ui/core/Switch"; -import InputLabel from "@material-ui/core/InputLabel"; -import { addProp, deleteProp } from "../actions/components.ts"; -import DataTable from "./DataTable.tsx"; -import { ComponentInt } from "../utils/interfaces"; +import React, { Component, Fragment } from 'react'; +import { connect } from 'react-redux'; +import { withStyles } from '@material-ui/core/styles'; +import FormControl from '@material-ui/core/FormControl'; +import Grid from '@material-ui/core/Grid'; +import TextField from '@material-ui/core/TextField'; +import Button from '@material-ui/core/Button'; +import Select from '@material-ui/core/Select'; +import Switch from '@material-ui/core/Switch'; +import InputLabel from '@material-ui/core/InputLabel'; +import { addProp, deleteProp } from '../actions/components.ts'; +import DataTable from './DataTable.tsx'; +import { ComponentInt } from '../utils/interfaces'; interface PropInt { addProp: any; @@ -21,48 +21,48 @@ interface PropInt { const styles = (theme: any): any => ({ root: { - display: "flex", - justifyContent: "center", - flexWrap: "wrap" + display: 'flex', + justifyContent: 'center', + flexWrap: 'wrap', }, chip: { - color: "#eee", - backgroundColor: "#333333" + color: '#eee', + backgroundColor: '#333333', }, column: { - display: "inline-flex", - alignItems: "baseline" + display: 'inline-flex', + alignItems: 'baseline', }, icon: { - fontSize: "20px", - color: "#eee", - opacity: "0.7", - transition: "all .2s ease", + fontSize: '20px', + color: '#eee', + opacity: '0.7', + transition: 'all .2s ease', - "&:hover": { - color: "red" - } + '&:hover': { + color: 'red', + }, }, cssLabel: { - color: "white", + color: 'white', - "&$cssFocused": { - color: "green" - } + '&$cssFocused': { + color: 'green', + }, }, cssFocused: {}, input: { - color: "#eee", - marginBottom: "10px", - width: "60%" + color: '#eee', + marginBottom: '10px', + width: '60%', }, light: { - color: "#eee" + color: '#eee', }, avatar: { - color: "#eee", - fontSize: "10px" - } + color: '#eee', + fontSize: '10px', + }, }); const mapDispatchToProps = (dispatch: any) => ({ @@ -70,76 +70,77 @@ const mapDispatchToProps = (dispatch: any) => ({ key, value, required, - type + type, }: { - key: string; - value: string; - required: boolean; - type: string; - }) => - dispatch( - addProp({ - key, - value, - required, - type - }) - ), - deleteProp: (propId: number) => dispatch(deleteProp(propId)) + key: string; + value: string; + required: boolean; + type: string; + }) => dispatch( + addProp({ + key, + value, + required, + type, + }), + ), + deleteProp: (propId: number) => dispatch(deleteProp(propId)), }); const mapStateToProps = (store: any) => ({ - focusComponent: store.workspace.focusComponent + focusComponent: store.workspace.focusComponent, }); const availablePropTypes = { - string: "STR", - number: "NUM", - object: "OBJ", - array: "ARR", - boolean: "BOOL", - function: "FUNC", + string: 'STR', + number: 'NUM', + object: 'OBJ', + array: 'ARR', + boolean: 'BOOL', + function: 'FUNC', // symbol: 'SYM', - node: "NODE", - element: "ELEM", - any: "ANY", - tuple: "TUP", - enum: "ENUM" + node: 'NODE', + element: 'ELEM', + any: 'ANY', + tuple: 'TUP', + enum: 'ENUM', }; const typeOptions = [ - )) + )), ]; class Props extends Component { state = { - propKey: "", - propValue: "", + propKey: '', + propValue: '', propRequired: true, - propType: "" + propType: '', }; handleChange = (event: any) => { this.setState({ - [event.target.id]: event.target.value.trim() + [event.target.id]: event.target.value.trim(), }); }; togglePropRequired = () => { this.setState({ - propRequired: !this.state.propRequired + propRequired: !this.state.propRequired, }); }; handleAddProp = (event: any) => { event.preventDefault(); - const { propKey, propValue, propRequired, propType } = this.state; + const { + propKey, propValue, propRequired, propType, + } = this.state; // check if prop exists with same key. CANNOT have duplicates const savedPropKeys = this.props.focusComponent.props.map(p => p.key); @@ -150,7 +151,7 @@ class Props extends Component { // check if prop starts with digits. Digits at string start breaks indexedDB if (/^\d/.test(propKey)) { - window.alert("Props are not allowed to begin with digits"); + window.alert('Props are not allowed to begin with digits'); return; } @@ -158,42 +159,44 @@ class Props extends Component { key: propKey, value: propValue, required: propRequired, - type: propType + type: propType, }); this.setState({ - propKey: "", - propValue: "", + propKey: '', + propValue: '', propRequired: true, - propType: "" + propType: '', }); }; render() { - const { focusComponent, classes, deleteProp, addProp } = this.props; + const { + focusComponent, classes, deleteProp, addProp, + } = this.props; - const rowHeader = ["_Key", "Value", "Type", "Required"]; + const rowHeader = ['_Key', 'Value', 'Type', 'Required']; // prepare the saved Props in a nice way, so you can sent them to TableData const propsRows = focusComponent.props.map(prop => ({ _Key: prop.key, Value: prop.value, Type: prop.type, Required: prop.required, - id: prop.id + id: prop.id, })); return ( -
- {" "} +
+ {' '} {Object.keys(focusComponent).length < 1 ? ( -
+
Click a component to view its props.
) : (
@@ -209,10 +212,10 @@ class Props extends Component { value={this.state.propKey} required InputProps={{ - className: classes.input + className: classes.input, }} InputLabelProps={{ - className: classes.input + className: classes.input, }} /> @@ -223,20 +226,17 @@ class Props extends Component { margin="normal" onChange={this.handleChange} InputProps={{ - className: classes.input + className: classes.input, }} InputLabelProps={{ - className: classes.input + className: classes.input, }} value={this.state.propValue} /> - + Type