use material-ui for controls

This commit is contained in:
2018-06-06 18:12:49 +03:00
parent 7f98f2200d
commit 3c6cc8ea9d
13 changed files with 110 additions and 74 deletions

View File

@@ -116,18 +116,6 @@ li button.todo {
box-shadow: none; box-shadow: none;
} }
.delete {
background-color: pink;
}
.edit {
background-color: lightcyan;
}
.save {
background-color: lightgreen;
}
ul { ul {
margin: 0; margin: 0;
padding: 0; padding: 0;

View File

@@ -1,12 +1,14 @@
#form { #form {
padding: 2rem 1rem; margin: 2rem;
display: flex;
justify-content: center;
} }
input { form {
border: none; max-width: 80%;
border-bottom: 1px solid #999999; display: flex;
margin-left: 1rem; flex-direction: column;
height: 2rem; width: 20rem;
} }
.error { .error {
@@ -14,9 +16,8 @@ input {
color: red; color: red;
} }
form button { #submitbutton {
padding: 0.25rem 1rem; margin: auto;
background: #f5f5f5; margin-top: 1rem;
border: 1px solid #f0f0f0; margin-right: 0.5rem;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.1);
} }

View File

@@ -1,5 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Button } from '@material-ui/core';
function Input(props) { function Input(props) {
let input; let input;
@@ -25,9 +26,9 @@ function Input(props) {
} }
}} }}
/> />
<button id="add" onClick={() => submit()}> <Button id="add" onClick={() => submit()}>
add add
</button> </Button>
</div> </div>
); );
} }

View File

@@ -10,6 +10,7 @@ const button = {
width: 24, width: 24,
height: 24, height: 24,
padding: 0, padding: 0,
margin: 3,
}; };
const icon = { const icon = {

View File

@@ -1,6 +1,6 @@
#listselector { #listselector {
display: flex; display: flex;
margin-left: 0.2rem; margin-left: 1rem;
overflow: hidden; overflow: hidden;
align-self: center; align-self: center;
background-color: #fbfbfb; background-color: #fbfbfb;

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { IconButton } from '@material-ui/core'; import { IconButton, Select, MenuItem } from '@material-ui/core';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import CheckIcon from '@material-ui/icons/Check'; import CheckIcon from '@material-ui/icons/Check';
@@ -78,13 +78,17 @@ export default function Selector({
if (list) { if (list) {
return ( return (
<div id="listselector"> <div id="listselector">
<select value={list} onChange={e => onChange(e.target.value)}> <Select
style={{ fontSize: '1.5rem' }}
value={list}
onChange={e => onChange(e.target.value)}
>
{Object.values(lists.lists).map(elem => ( {Object.values(lists.lists).map(elem => (
<option key={elem.id} value={elem.id}> <MenuItem key={elem.id} value={elem.id}>
{elem.name} {elem.name}
</option> </MenuItem>
))} ))}
</select> </Select>
</div> </div>
); );
} }

View File

@@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { animated } from 'react-spring'; import { animated } from 'react-spring';
import { ButtonBase } from '@material-ui/core';
import DeleteIcon from '@material-ui/icons/Delete'; import DeleteIcon from '@material-ui/icons/Delete';
import EditIcon from '@material-ui/icons/Edit'; import EditIcon from '@material-ui/icons/Edit';
import CheckIcon from '@material-ui/icons/Check'; import CheckIcon from '@material-ui/icons/Check';
@@ -57,15 +58,10 @@ class Todo extends React.Component {
editClasses.push('disabled'); editClasses.push('disabled');
} }
const todoClasses = ['todo'];
if (this.props.todo.completed) {
todoClasses.push('done');
}
let input; let input;
const text = this.state.editing ? ( const text = this.state.editing ? (
<div className={todoClasses.join(' ')}> <div className="todo">
<textarea <textarea
className="todo--input" className="todo--input"
defaultValue={this.props.todo.text} defaultValue={this.props.todo.text}
@@ -75,38 +71,48 @@ class Todo extends React.Component {
/> />
</div> </div>
) : ( ) : (
<button <ButtonBase
className={todoClasses.join(' ')} style={{
justifyContent: 'left',
paddingLeft: '1.5rem',
borderTop: '1px solid #f0f0f0',
textDecoration: this.props.todo.completed ? 'line-through' : 'none',
color: this.props.todo.completed ? '#888888' : 'black',
}}
className="todo"
onClick={this.state.hover ? this.props.toggleTodo : null} onClick={this.state.hover ? this.props.toggleTodo : null}
> >
{this.props.todo.text} {this.props.todo.text}
</button> </ButtonBase>
); );
const buttons = this.state.editing const ButtonBases = this.state.editing
? [ ? [
<animated.button <ButtonBase
key="save" key="save"
style={{ backgroundColor: 'lightgreen' }}
className="save" className="save"
onClick={() => this.stopEdit(input.value)} onClick={() => this.stopEdit(input.value)}
> >
<CheckIcon style={icon} /> <CheckIcon style={icon} />
</animated.button>, </ButtonBase>,
] ]
: [ : [
<animated.button <ButtonBase
key="remove" key="remove"
style={{ backgroundColor: 'pink' }}
className={deleteClasses.join(' ')} className={deleteClasses.join(' ')}
onClick={this.props.removeTodo} onClick={this.props.removeTodo}
> >
<DeleteIcon style={icon} /> <DeleteIcon style={icon} />
</animated.button>, </ButtonBase>,
<animated.button <ButtonBase
key="edit" key="edit"
style={{ backgroundColor: 'lightcyan' }}
className={editClasses.join(' ')} className={editClasses.join(' ')}
onClick={this.startEdit} onClick={this.startEdit}
> >
<EditIcon style={icon} /> <EditIcon style={icon} />
</animated.button>, </ButtonBase>,
]; ];
return ( return (
<animated.li <animated.li
@@ -116,7 +122,7 @@ class Todo extends React.Component {
onMouseOut={this.onMouseOut} onMouseOut={this.onMouseOut}
onBlur={this.onMouseOut} onBlur={this.onMouseOut}
> >
{buttons} {ButtonBases}
{text} {text}
</animated.li> </animated.li>
); );

View File

@@ -16,9 +16,9 @@ export default function TodosContainer({
native native
items={todos} items={todos}
keys={todo => todo.id} keys={todo => todo.id}
from={{ height: 0, borderColor: '#f0f0f0', opacity: 0.9 }} from={{ height: 0, borderColor: '#f0f0f0', opacity: 0.7 }}
enter={{ height: 60, borderColor: '#f0f0f0', opacity: 1 }} enter={{ height: 60, borderColor: '#f0f0f0', opacity: 1 }}
leave={{ height: 0, borderColor: '#ffffff', opacity: 0.5 }} leave={{ height: 0, borderColor: '#ffffff', opacity: 0.3 }}
> >
{todos.map(todo => styles => ( {todos.map(todo => styles => (
<Todo <Todo

View File

@@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { TextField } from '@material-ui/core';
export default function InputField({ export default function InputField({
required, required,
@@ -9,12 +10,10 @@ export default function InputField({
type, type,
}) { }) {
return ( return (
<div> <React.Fragment>
<label htmlFor={input.name}> <TextField label={label} required={required} {...input} type={type} />
{label} <input required={required} {...input} type={type} />
</label>
{touched && error && <span className="error">{error}</span>} {touched && error && <span className="error">{error}</span>}
</div> </React.Fragment>
); );
} }

View File

@@ -3,10 +3,12 @@ import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ButtonBase, Button } from '@material-ui/core';
import InputField from './InputField'; import InputField from './InputField';
import UserErrors from './UserErrors';
import '../Form.css'; import '../Form.css';
import UserErrors from './UserErrors';
import { login, reset } from '../../actions/user'; import { login, reset } from '../../actions/user';
@@ -15,20 +17,25 @@ function LoginForm({ handleSubmit, onLogin, user, history, resetUser }) {
history.push('/'); history.push('/');
} }
return ( return (
<div> <React.Fragment>
<div id="user-header"> <div id="user-header">
<button <ButtonBase
style={{
marginRight: '1rem',
padding: '0 0.5rem',
borderRadius: '7px',
}}
onClick={() => { onClick={() => {
resetUser(); resetUser();
history.push('/signup'); history.push('/signup');
}} }}
> >
signup signup
</button> </ButtonBase>
</div> </div>
<div id="form"> <div id="form">
<UserErrors user={user} />
<form onSubmit={handleSubmit(onLogin)}> <form onSubmit={handleSubmit(onLogin)}>
<UserErrors user={user} />
<Field <Field
label="username" label="username"
name="username" name="username"
@@ -43,10 +50,14 @@ function LoginForm({ handleSubmit, onLogin, user, history, resetUser }) {
component={InputField} component={InputField}
type="password" type="password"
/> />
<button type="submit">Login</button> <div id="submitbutton">
<Button variant="contained" color="primary" type="submit">
Login
</Button>
</div>
</form> </form>
</div> </div>
</div> </React.Fragment>
); );
} }

View File

@@ -3,6 +3,7 @@ import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ButtonBase, Button } from '@material-ui/core';
import InputField from './InputField'; import InputField from './InputField';
import UserErrors from './UserErrors'; import UserErrors from './UserErrors';
@@ -14,7 +15,7 @@ import { signup, reset } from '../../actions/user';
function validate(values) { function validate(values) {
const errors = {}; const errors = {};
if (values.password !== values.passwordRepeat) { if (values.password !== values.passwordRepeat) {
errors.passwordRepeat = 'Invalid'; errors.passwordRepeat = 'Passwords should match';
} }
return errors; return errors;
} }
@@ -24,20 +25,25 @@ function SignupForm({ handleSubmit, onSignup, user, history, resetUser }) {
history.push('/'); history.push('/');
} }
return ( return (
<div> <React.Fragment>
<div id="user-header"> <div id="user-header">
<button <ButtonBase
style={{
marginRight: '1rem',
padding: '0 0.5rem',
borderRadius: '7px',
}}
onClick={() => { onClick={() => {
resetUser(); resetUser();
history.push('/login'); history.push('/login');
}} }}
> >
login login
</button> </ButtonBase>
</div> </div>
<div id="form"> <div id="form">
<UserErrors user={user} />
<form onSubmit={handleSubmit(onSignup)}> <form onSubmit={handleSubmit(onSignup)}>
<UserErrors user={user} />
<Field <Field
label="username" label="username"
name="username" name="username"
@@ -59,10 +65,14 @@ function SignupForm({ handleSubmit, onSignup, user, history, resetUser }) {
component={InputField} component={InputField}
type="password" type="password"
/> />
<button type="submit">Signup</button> <div id="submitbutton">
<Button variant="contained" color="primary" type="submit">
Signup
</Button>
</div>
</form> </form>
</div> </div>
</div> </React.Fragment>
); );
} }

View File

@@ -1,6 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ButtonBase } from '@material-ui/core';
import { setVisibilityFilter } from '../actions/todos'; import { setVisibilityFilter } from '../actions/todos';
function Link({ active, onClick, children }) { function Link({ active, onClick, children }) {
@@ -9,7 +10,12 @@ function Link({ active, onClick, children }) {
classes.push('filter--active'); classes.push('filter--active');
} }
return ( return (
<button <ButtonBase
style={{
margin: '0 0.2rem',
padding: '1rem 0.3rem',
borderRadius: '7px',
}}
className={classes.join(' ')} className={classes.join(' ')}
onClick={e => { onClick={e => {
e.preventDefault(); e.preventDefault();
@@ -17,7 +23,7 @@ function Link({ active, onClick, children }) {
}} }}
> >
{children} {children}
</button> </ButtonBase>
); );
} }
@@ -39,4 +45,7 @@ function mapDispatchToProps(dispatch, ownProps) {
}; };
} }
export default connect(mapStateToProps, mapDispatchToProps)(Link); export default connect(
mapStateToProps,
mapDispatchToProps,
)(Link);

View File

@@ -1,13 +1,19 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ButtonBase } from '@material-ui/core';
import { logout } from '../actions/user'; import { logout } from '../actions/user';
function Link({ onClick, children }) { function Link({ onClick, children }) {
const classes = ['logout']; const classes = ['logout'];
return ( return (
<button <ButtonBase
style={{
marginRight: '1rem',
padding: '0 0.5rem',
borderRadius: '7px',
}}
className={classes.join(' ')} className={classes.join(' ')}
onClick={e => { onClick={e => {
e.preventDefault(); e.preventDefault();
@@ -15,7 +21,7 @@ function Link({ onClick, children }) {
}} }}
> >
{children} {children}
</button> </ButtonBase>
); );
} }