Skip to content

Commit 78872d9

Browse files
committed
Use pure functional components. Use standard style.
1 parent 5bdacb5 commit 78872d9

File tree

4 files changed

+61
-65
lines changed

4 files changed

+61
-65
lines changed

src/FullscreenDialog.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const getStyles = (props, theme) => ({
2525
}
2626
})
2727

28-
export function FullscreenDialog (props, { muiTheme }) {
28+
export default function FullscreenDialog (props, { muiTheme }) {
2929
const styles = getStyles(props, muiTheme)
3030

3131
const {
@@ -52,7 +52,7 @@ export function FullscreenDialog (props, { muiTheme }) {
5252
style={{ ...styles.appBar, ...appBarStyle }}
5353
iconElementLeft={(
5454
<IconButton onTouchTap={onRequestClose}>
55-
{closeIcon || <NavigationCloseIcon />}
55+
{closeIcon || <NavigationCloseIcon />}
5656
</IconButton>
5757
)}
5858
iconElementRight={actionButton}

src/FullscreenDialogFrame.js

+52-60
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PropTypes, Component } from 'react'
22
import ReactTransitionGroup from 'react-addons-transition-group'
33

4-
const getStyles = (props) => ({
4+
const styles = {
55
root: {
66
width: '100vw',
77
height: '100vh',
@@ -11,106 +11,98 @@ const getStyles = (props) => ({
1111
zIndex: 1500,
1212
background: '#fafafa'
1313
}
14-
})
14+
}
1515

1616
class TransitionItem extends Component {
17-
static propTypes = {
18-
children: PropTypes.node,
19-
style: PropTypes.object,
20-
};
21-
22-
state = {
23-
style: {
24-
opacity: 0,
25-
transition: 'all 225ms cubic-bezier(0.0, 0.0, 0.2, 1)',
26-
transform: 'translate(0, 56px)'
27-
},
28-
};
17+
constructor (props) {
18+
super(props)
19+
this.state = {
20+
style: {
21+
opacity: 0,
22+
transition: 'all 225ms cubic-bezier(0.0, 0.0, 0.2, 1)',
23+
transform: 'translate(0, 56px)'
24+
}
25+
}
26+
}
2927

30-
componentWillUnmount() {
31-
clearTimeout(this.enterTimeout);
32-
clearTimeout(this.leaveTimeout);
28+
componentWillUnmount () {
29+
clearTimeout(this.enterTimeout)
30+
clearTimeout(this.leaveTimeout)
3331
}
3432

35-
componentWillEnter(callback) {
36-
this.componentWillAppear(callback);
33+
componentWillEnter (callback) {
34+
this.componentWillAppear(callback)
3735
}
3836

39-
componentWillAppear(callback) {
37+
componentWillAppear (callback) {
4038
this.enterTimeout = setTimeout(() => {
4139
this.setState({
4240
style: {
4341
opacity: 1,
4442
transition: 'all 225ms cubic-bezier(0.0, 0.0, 0.2, 1)',
45-
transform: 'translate(0, 0px)',
43+
transform: 'translate(0, 0px)'
4644
}
4745
})
48-
this.enterTimeout = setTimeout(callback, 225); // matches transition duration
46+
this.enterTimeout = setTimeout(callback, 225) // matches transition duration
4947
})
5048
}
5149

52-
componentWillLeave(callback) {
50+
componentWillLeave (callback) {
5351
this.setState({
5452
style: {
5553
opacity: 0,
5654
transition: 'all 195ms cubic-bezier(0.4, 0.0, 1, 1)',
5755
transform: 'translate(0, 56px)'
58-
},
59-
});
56+
}
57+
})
6058

61-
this.leaveTimeout = setTimeout(callback, 195); // matches transition duration
59+
this.leaveTimeout = setTimeout(callback, 195) // matches transition duration
6260
}
6361

64-
render() {
62+
render () {
6563
const {
6664
style,
6765
children,
6866
...other
69-
} = this.props;
67+
} = this.props
7068

7169
return (
7270
<div {...other} style={{ ...style, ...this.state.style }}>
7371
{children}
7472
</div>
75-
);
73+
)
7674
}
7775
}
7876

79-
export default class FullscreenDialogFrame extends Component {
80-
render () {
81-
const styles = getStyles(this.props)
82-
83-
const {
84-
children,
85-
style,
86-
title,
87-
titleStyle,
88-
} = this.props
77+
TransitionItem.propTypes = {
78+
children: PropTypes.node,
79+
style: PropTypes.object
80+
}
8981

90-
return (
91-
<ReactTransitionGroup
92-
component='div'
93-
transitionAppear={true}
94-
transitionAppearTimeout={225}
95-
transitionEnter={true}
96-
transitionEnterTimeout={225}
97-
>
98-
{this.props.open && (
99-
<TransitionItem style={{
100-
...styles.root,
101-
...style
102-
}}
103-
>
104-
{this.props.children}
105-
</TransitionItem>
106-
)}
107-
</ReactTransitionGroup>
108-
)
109-
}
82+
export default function FullscreenDialogFrame ({ children, open, style }) {
83+
return (
84+
<ReactTransitionGroup
85+
component='div'
86+
transitionAppear
87+
transitionAppearTimeout={225}
88+
transitionEnter
89+
transitionEnterTimeout={225}
90+
>
91+
{open && (
92+
<TransitionItem style={{
93+
...styles.root,
94+
...style
95+
}}
96+
>
97+
{children}
98+
</TransitionItem>
99+
)}
100+
</ReactTransitionGroup>
101+
)
110102
}
111103

112104
FullscreenDialogFrame.propTypes = {
113-
children: PropTypes.node,
105+
children: PropTypes.node,
114106
open: PropTypes.bool.isRequired,
115107
style: PropTypes.object
116108
}

stories/FullscreenDialogDemo.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import { action } from '@kadira/storybook'
23
import RaisedButton from 'material-ui/RaisedButton'
34
import FlatButton from 'material-ui/FlatButton'
45
import TextField from 'material-ui/TextField'
@@ -18,7 +19,10 @@ export default class extends React.Component {
1819
<div>
1920
<FullscreenDialog
2021
open={this.state.open}
21-
onRequestClose={() => this.setState({ open: false })}
22+
onRequestClose={(...args) => {
23+
action('onRequestClose')(...args)
24+
this.setState({ open: false })
25+
}}
2226
title='Some demo dialog'
2327
actionButton={<FlatButton
2428
label='Done'

stories/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react'
2-
import { storiesOf, action, linkTo } from '@kadira/storybook'
2+
import { storiesOf } from '@kadira/storybook'
33
import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'
44
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
55
import getMuiTheme from 'material-ui/styles/getMuiTheme'
66
import FullscreenDialogDemo from './FullscreenDialogDemo'
77

8-
function themed(children) {
8+
function themed (children) {
99
return (
1010
<MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}>
1111
<div style={{ fontFamily: 'Roboto, sans-serif' }}>

0 commit comments

Comments
 (0)