Skip to content

Commit 23bb25d

Browse files
committed
create reusable form
1 parent c6048e9 commit 23bb25d

File tree

16 files changed

+343
-262
lines changed

16 files changed

+343
-262
lines changed

src/client/App.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CSSTransitionGroup } from 'react-transition-group';
55
import { showLoadingMessage, showErrorMessage, hideLoadingMessage, getErrorMessage } from './components/Store/Actions.js';
66

77
import TopNavBar from './components/TopNavBar/TopNavBar';
8+
import Form from './components/Form/Form';
89
import Tab from './components/Tab/Tab';
910
import MessageComp from './components/MessageComp/MessageComp';
1011
import SettingsBar from './components/SettingsBar/SettingsBar';
@@ -30,7 +31,7 @@ const mapDispatchToProps = dispatch => {
3031
}
3132
}
3233

33-
class ConnectedApp extends React.Component {
34+
class App extends React.Component {
3435
constructor(props) {
3536
super(props);
3637

@@ -152,11 +153,16 @@ class ConnectedApp extends React.Component {
152153

153154
return (
154155
<div className={styles['app']}>
155-
<TopNavBar
156-
onInputChange={(e) => this.handleInputChange(e)}
157-
onInputSubmit={() => this.handleInputSubmit()}
158-
onIconClick={() => this.handleSettingsiconClick()}
159-
/>
156+
<TopNavBar onIconClick={() => this.handleSettingsiconClick()}>
157+
<Form
158+
submitButton={true}
159+
inputTypes={[{ name: 'contractsPath', placeholder: 'Insert contracts path'}]}
160+
buttonValue='Load contracts from URI'
161+
onInputChange={(e) => this.handleInputChange(e)}
162+
onSubmitForm={() => this.handleInputSubmit()}
163+
onInputKeyUp={() => this.handleInputSubmit()}
164+
/>
165+
</TopNavBar>
160166
<div ref={node => { this.node = node; }}>
161167
<SettingsBar
162168
active={!!settingsVisible}
@@ -208,8 +214,6 @@ class ConnectedApp extends React.Component {
208214
}
209215
}
210216

211-
const App = connect(mapStateToProps, mapDispatchToProps)(ConnectedApp);
212-
213217
App.displayName = 'App';
214218

215-
export default App;
219+
export default connect(mapStateToProps, mapDispatchToProps)(App);;

src/client/components/Form/Form.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React from 'react';
2+
import classnames from 'classnames/bind';
3+
4+
const cx = classnames.bind(styles);
5+
6+
import styles from './Form.scss';
7+
8+
class Form extends React.Component {
9+
constructor(props) {
10+
super(props);
11+
12+
this.state = {
13+
value: '',
14+
}
15+
}
16+
17+
handleInputChange(event) {
18+
const { name, value } = event.target;
19+
20+
this.setState({
21+
[name]: value,
22+
});
23+
24+
this.props.onInputChange(event);
25+
}
26+
27+
handleKeyDown(event) {
28+
if(event.keyCode === 13) {
29+
event.preventDefault();
30+
}
31+
}
32+
33+
handleKeyUp(event) {
34+
event.preventDefault();
35+
36+
if(event.keyCode !== 13) {
37+
return;
38+
}
39+
40+
this.props.onInputKeyUp();
41+
}
42+
43+
handleSubmit(event) {
44+
event.preventDefault();
45+
46+
this.props.onSubmitForm();
47+
}
48+
49+
render() {
50+
51+
const { inputTypes, submitButton, settingsBarForm, buttonValue } = this.props;
52+
53+
const inputClasses = cx({
54+
'settings-bar__item': !!settingsBarForm
55+
});
56+
57+
return (
58+
<form className={styles['form']} onSubmit={(e) => this.handleSubmit(e)}>
59+
<div className={styles['form__inputs']}>
60+
{
61+
inputTypes.map(item => {
62+
return (
63+
<div key={item.name} className={styles['form__inputs__item']}>
64+
<input
65+
name={item.name}
66+
placeholder={item.placeholder}
67+
onChange={(e) => this.handleInputChange(e)}
68+
onKeyDown={(e) => this.handleKeyDown(e)}
69+
onKeyUp={(e) => this.handleKeyUp(e)}
70+
/>
71+
</div>
72+
)
73+
})
74+
}
75+
</div>
76+
{
77+
submitButton &&
78+
<div className={styles['form__button']}>
79+
<button type='submit'><span>{buttonValue}</span></button>
80+
</div>
81+
}
82+
</form>
83+
)
84+
}
85+
}
86+
87+
export default Form;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.form {
2+
display: flex;
3+
justify-content: space-between;
4+
align-items: center;
5+
6+
&__inputs {
7+
flex: 1 1 auto;
8+
9+
&__item {
10+
padding: 5px 10px;
11+
12+
input {
13+
width: 100%;
14+
padding: 10px 0;
15+
font-size: 14px;
16+
background: transparent;
17+
color: $color-light-grey;
18+
border-bottom: 1px dotted $color-light-grey;
19+
transition: border-color 0.2s;
20+
21+
&:focus {
22+
border-color: $color-green;
23+
outline: 0 none;
24+
}
25+
}
26+
}
27+
}
28+
29+
button {
30+
padding: 10px;
31+
border-radius: 5px;
32+
background: transparent;
33+
border: 1px solid $color-light-grey;
34+
cursor: pointer;
35+
transition: opacity 0.7, border-color 0.2s;
36+
37+
&:last-of-type {
38+
margin-left: 10px;
39+
}
40+
41+
&:focus {
42+
border-color: $color-green;
43+
outline: 0 none;
44+
45+
span {
46+
color: $color-green;
47+
}
48+
}
49+
50+
&:hover {
51+
opacity: 0.7;
52+
}
53+
54+
span {
55+
color: $color-light-grey;
56+
font-size: 14px;
57+
transition: color 0.2s;
58+
}
59+
}
60+
}

src/client/components/InnerTab/InnerTabPanel/InnerTabPanel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import TransactionDebugger from '../../TransactionDebugger/TransactionDebugger';
44
import Disassembler from '../../Disassembler/Disassembler';
55
import ControlFlowGraph from '../../ControlFlowGraph/ControlFlowGraph';
6+
import Storage from '../../Storage/Storage';
67

78
import styles from './InnerTabPanel.scss';
89

@@ -38,6 +39,10 @@ const InnerTabPanel = ({ type, active, contractName, contractCode, contractPath,
3839
graphResponse={graphResponse}
3940
/>
4041
}
42+
{type === 'View Storage' &&
43+
<Storage
44+
/>
45+
}
4146
</div>
4247
);
4348
}

src/client/components/Input/Input.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/client/components/Input/Input.scss

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/client/components/Modal/Modal.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
22

33
import Icon from '../Icon/Icon';
4-
import Input from '../Input/Input';
54

65
import styles from './Modal.scss';
76

8-
const Modal = ({ onIconClick, onInputChange, onInputSubmit }) => {
7+
const Modal = ({ onIconClick, children }) => {
98

109
return (
1110
<div className={styles['modal']}>
@@ -15,13 +14,8 @@ const Modal = ({ onIconClick, onInputChange, onInputSubmit }) => {
1514
<Icon iconName='Cross' />
1615
</button>
1716
</div>
18-
<div className={styles['modal__main__input']}>
19-
<Input
20-
placeholder='Transaction hash'
21-
buttonValue='Debug'
22-
onChange={onInputChange}
23-
onSubmit={onInputSubmit}
24-
/>
17+
<div className={styles['modal__main__body']}>
18+
{children}
2519
</div>
2620
</div>
2721
</div>

src/client/components/Modal/Modal.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
}
4141

42-
&__input {
42+
&__body {
4343
width: 100%;
4444
}
4545
}

0 commit comments

Comments
 (0)