-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Circular] Add interactive integration in the docs (#8586)
- Loading branch information
1 parent
e66d4c4
commit 022b05c
Showing
4 changed files
with
115 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { withStyles } from 'material-ui/styles'; | ||
import { CircularProgress } from 'material-ui/Progress'; | ||
import green from 'material-ui/colors/green'; | ||
import Button from 'material-ui/Button'; | ||
import CheckIcon from 'material-ui-icons/Check'; | ||
import SaveIcon from 'material-ui-icons/Save'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
wrapper: { | ||
margin: theme.spacing.unit, | ||
position: 'relative', | ||
}, | ||
buttonSuccess: { | ||
backgroundColor: green[500], | ||
'&:hover': { | ||
backgroundColor: green[700], | ||
}, | ||
}, | ||
fabProgress: { | ||
color: green[500], | ||
position: 'absolute', | ||
top: -2, | ||
left: -2, | ||
}, | ||
buttonProgress: { | ||
color: green[500], | ||
position: 'absolute', | ||
top: '50%', | ||
left: '50%', | ||
marginTop: -12, | ||
marginLeft: -12, | ||
}, | ||
}); | ||
|
||
class CircularIntegration extends React.Component { | ||
state = { | ||
loading: false, | ||
success: false, | ||
}; | ||
|
||
componentWillUnmount() { | ||
clearTimeout(this.timer); | ||
} | ||
|
||
handleButtonClick = () => { | ||
if (!this.state.loading) { | ||
this.setState( | ||
{ | ||
success: false, | ||
loading: true, | ||
}, | ||
() => { | ||
this.timer = setTimeout(() => { | ||
this.setState({ | ||
loading: false, | ||
success: true, | ||
}); | ||
}, 2000); | ||
}, | ||
); | ||
} | ||
}; | ||
|
||
timer = undefined; | ||
|
||
render() { | ||
const { loading, success } = this.state; | ||
const { classes } = this.props; | ||
const buttonClassname = classNames({ | ||
[classes.buttonSuccess]: success, | ||
}); | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<div className={classes.wrapper}> | ||
<Button fab color="primary" className={buttonClassname} onClick={this.handleButtonClick}> | ||
{success ? <CheckIcon /> : <SaveIcon />} | ||
</Button> | ||
{loading && <CircularProgress size={60} className={classes.fabProgress} />} | ||
</div> | ||
<div className={classes.wrapper}> | ||
<Button | ||
raised | ||
color="primary" | ||
className={buttonClassname} | ||
disabled={loading} | ||
onClick={this.handleButtonClick} | ||
> | ||
Accept terms | ||
</Button> | ||
{loading && <CircularProgress size={24} className={classes.buttonProgress} />} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
CircularIntegration.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(CircularIntegration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters