Skip to content

Commit 690a98c

Browse files
authored
Merge pull request #5 from innFactory/feature/responsive
Feature/responsive
2 parents 1a11fbb + 850093a commit 690a98c

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

src/App.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AppBar, Badge, createStyles, Divider, Drawer, Hidden, IconButton, List, ListItem, ListItemIcon, ListItemText, Theme, Toolbar, Typography, WithStyles, withStyles } from '@material-ui/core';
2+
import withWidth, { WithWidthProps } from '@material-ui/core/withWidth';
23
import TodoIcon from '@material-ui/icons/FormatListNumbered';
34
import HomeIcon from '@material-ui/icons/Home';
45
import MenuIcon from '@material-ui/icons/Menu';
@@ -10,10 +11,11 @@ import { Todo } from './model/model';
1011
import HomePage from './pages/HomePage';
1112
import TodoPage from './pages/TodoPage';
1213
import { RootState } from './reducers/index';
14+
import { isSmartphone } from './responsive';
1315
import withRoot from './withRoot';
1416

1517
export namespace App {
16-
export interface Props extends RouteComponentProps<void>, WithStyles<typeof styles> {
18+
export interface Props extends RouteComponentProps<void>, WithStyles<typeof styles>, WithWidthProps {
1719
todoList: Todo[];
1820
}
1921

@@ -40,6 +42,8 @@ class App extends React.Component<App.Props, App.State> {
4042

4143
render() {
4244

45+
const { width } = this.props;
46+
4347
let drawer = (
4448
<div>
4549
<div className={this.props.classes.drawerHeader} />
@@ -79,7 +83,7 @@ class App extends React.Component<App.Props, App.State> {
7983
>
8084
<MenuIcon />
8185
</IconButton>
82-
<Typography variant="title" color="inherit" noWrap>
86+
<Typography variant="title" color="inherit" noWrap={!isSmartphone(width)}>
8387
Create-React-App with Material-UI, Typescritpt, Redux and Routing
8488
</Typography>
8589
</Toolbar>
@@ -190,4 +194,4 @@ function mapStateToProps(state: RootState) {
190194
};
191195
}
192196

193-
export default (withRoot(withStyles(styles)<{}>(connect(mapStateToProps)(App))));
197+
export default (withRoot(withStyles(styles)<{}>(connect(mapStateToProps)(withWidth()(App)))));

src/components/TodoDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TodoDialog extends React.Component<TodoDialog.Props> {
6363

6464
const styles = (theme: Theme) => createStyles({
6565
textField: {
66-
width: 400,
66+
width: '80%',
6767
margin: 20
6868
}
6969
});

src/components/TodoTable.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class TodoTable extends React.Component<TodoTable.Props> {
3333
<Table className={classes.table}>
3434
<TableHead>
3535
<TableRow>
36-
<TableCell>Completed</TableCell>
37-
<TableCell>Text</TableCell>
38-
<TableCell>Delete</TableCell>
36+
<TableCell padding="dense">Completed</TableCell>
37+
<TableCell padding="dense">Text</TableCell>
38+
<TableCell padding="dense">Delete</TableCell>
3939
</TableRow>
4040
</TableHead>
4141
<TableBody>
@@ -46,11 +46,11 @@ class TodoTable extends React.Component<TodoTable.Props> {
4646
hover
4747
onClick={event => this.onRowClick(n)}
4848
>
49-
<TableCell padding="checkbox">
49+
<TableCell padding="dense">
5050
<Checkbox checked={n.completed} />
5151
</TableCell>
52-
<TableCell>{n.text}</TableCell>
53-
<TableCell padding="checkbox">
52+
<TableCell padding="dense">{n.text}</TableCell>
53+
<TableCell padding="dense">
5454
<IconButton
5555
aria-label="Delete"
5656
color="default"
@@ -71,12 +71,12 @@ class TodoTable extends React.Component<TodoTable.Props> {
7171

7272
const styles = (theme: Theme) => createStyles({
7373
paper: {
74-
maxWidth: 1000,
75-
minWidth: 1000,
74+
width: '100%',
75+
minWidth: 260,
7676
display: 'inline-block'
7777
},
7878
table: {
79-
maxWidth: 1000,
79+
width: '100%'
8080
},
8181
});
8282

src/pages/HomePage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const styles = (theme: Theme) => createStyles({
2828
root: {
2929
textAlign: 'center',
3030
paddingTop: theme.spacing.unit * 20,
31+
paddingLeft: 15,
32+
paddingRight: 15,
3133
},
3234
});
3335

src/pages/TodoPage.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Button, createStyles, Grid, Theme, Typography, WithStyles, withStyles } from '@material-ui/core';
1+
import { Button, createStyles, Grid, Theme, Typography, WithStyles, withStyles, withWidth } from '@material-ui/core';
2+
import { WithWidthProps } from '@material-ui/core/withWidth';
23
import * as React from 'react';
34
import { connect } from 'react-redux';
45
import { RouteComponentProps } from 'react-router';
@@ -8,9 +9,10 @@ import TodoTable from '../components';
89
import TodoDialog from '../components/TodoDialog';
910
import { Todo } from '../model/model';
1011
import { RootState } from '../reducers/index';
12+
import { isSmartphone } from '../responsive';
1113

1214
export namespace TodoPage {
13-
export interface Props extends RouteComponentProps<void>, WithStyles<typeof styles> {
15+
export interface Props extends RouteComponentProps<void>, WithStyles<typeof styles>, WithWidthProps {
1416
todoList: Todo[];
1517
actions: typeof TodoActions;
1618
}
@@ -26,12 +28,12 @@ class TodoPage extends React.Component<TodoPage.Props, TodoPage.State> {
2628
};
2729

2830
render() {
29-
const { classes, actions, todoList } = this.props;
31+
const { classes, actions, todoList, width } = this.props;
3032

3133
return (
3234
<Grid
3335
container
34-
className={classes.root}
36+
className={isSmartphone(width) ? classes.mobileRoot : classes.root}
3537
alignItems={'flex-start'}
3638
justify={'flex-start'}
3739
>
@@ -40,13 +42,13 @@ class TodoPage extends React.Component<TodoPage.Props, TodoPage.State> {
4042
open={this.state.open}
4143
onClose={() => this.setState({ open: false })}
4244
/>
43-
<Grid item xs={2}>
45+
<Grid item xs={12}>
4446
<Typography variant="display1" gutterBottom>
4547
Todo List
4648
</Typography>
4749
</Grid>
48-
<Grid item xs={2}>
49-
<Button variant="raised" color="secondary" onClick={this.handleAddTodo}>
50+
<Grid item xs={12}>
51+
<Button className={classes.button} variant="raised" color="secondary" onClick={this.handleAddTodo}>
5052
Add Todo
5153
</Button>
5254
</Grid>
@@ -65,6 +67,16 @@ const styles = (theme: Theme) => createStyles({
6567
root: {
6668
padding: theme.spacing.unit * 10,
6769
},
70+
71+
mobileRoot: {
72+
paddingTop: 50,
73+
paddingLeft: 15,
74+
paddingRight: 15,
75+
},
76+
77+
button: {
78+
marginBottom: 15,
79+
},
6880
});
6981

7082
function mapStateToProps(state: RootState) {
@@ -79,4 +91,4 @@ function mapDispatchToProps(dispatch: any) {
7991
};
8092
}
8193

82-
export default (withStyles(styles)<{}>(connect(mapStateToProps, mapDispatchToProps)(TodoPage)));
94+
export default (withStyles(styles)<{}>(connect(mapStateToProps, mapDispatchToProps)(withWidth()(TodoPage))));

src/responsive.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
2+
import { isWidthDown, isWidthUp } from '@material-ui/core/withWidth';
3+
4+
const allowMobile = true;
5+
export function isSmartphone(width: Breakpoint): boolean {
6+
return allowMobile && isWidthDown('xs', width);
7+
}
8+
9+
export function isTablet(width: Breakpoint): boolean {
10+
return allowMobile && isWidthDown('sm', width);
11+
}
12+
13+
export function isMobile(width: Breakpoint): boolean {
14+
return allowMobile && isTablet(width);
15+
}
16+
17+
export function isDesktop(width: Breakpoint): boolean {
18+
return !allowMobile || isWidthUp('md', width);
19+
}

0 commit comments

Comments
 (0)