-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[StepConnector] Customize connector based on internal states #13023
Merged
oliviertassinari
merged 9 commits into
mui:master
from
spirosikmd:step-connector-customize
Sep 29, 2018
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
82a6ed2
[StepConnector] Introduce active, completed, and disabled properties
spirosikmd 18ea782
[Stepper] Pass active, completed, disabled props to connectors
spirosikmd 77476fe
[StepConnector] Update api docs
spirosikmd 8999947
[Stepper] Use state object for control and connector
spirosikmd 4e952f1
[StepConnector] Remove default boolean state values
spirosikmd f9862d3
[StepConnector] Apply state classes to root element
spirosikmd b98213b
let's merge
oliviertassinari e443828
Update steppers.md
oliviertassinari f07f664
remove regressions
oliviertassinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,142 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import Stepper from '@material-ui/core/Stepper'; | ||
import Step from '@material-ui/core/Step'; | ||
import StepLabel from '@material-ui/core/StepLabel'; | ||
import StepConnector from '@material-ui/core/StepConnector'; | ||
import Button from '@material-ui/core/Button'; | ||
import Typography from '@material-ui/core/Typography'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
width: '90%', | ||
}, | ||
button: { | ||
marginRight: theme.spacing.unit, | ||
}, | ||
instructions: { | ||
marginTop: theme.spacing.unit, | ||
marginBottom: theme.spacing.unit, | ||
}, | ||
connectorActive: { | ||
'& $line': { | ||
borderColor: theme.palette.secondary.main, | ||
}, | ||
}, | ||
connectorCompleted: { | ||
'& $line': { | ||
borderColor: theme.palette.primary.main, | ||
}, | ||
}, | ||
line: {}, | ||
}); | ||
|
||
function getSteps() { | ||
return ['Select campaign settings', 'Create an ad group', 'Create an ad']; | ||
} | ||
|
||
function getStepContent(step) { | ||
switch (step) { | ||
case 0: | ||
return 'Select campaign settings...'; | ||
case 1: | ||
return 'What is an ad group anyways?'; | ||
case 2: | ||
return 'This is the bit I really care about!'; | ||
default: | ||
return 'Unknown step'; | ||
} | ||
} | ||
|
||
class CustomizedStepper extends React.Component { | ||
state = { | ||
activeStep: 0, | ||
}; | ||
|
||
handleNext = () => { | ||
this.setState(state => ({ | ||
activeStep: state.activeStep + 1, | ||
})); | ||
}; | ||
|
||
handleBack = () => { | ||
this.setState(state => ({ | ||
activeStep: state.activeStep - 1, | ||
})); | ||
}; | ||
|
||
handleReset = () => { | ||
this.setState({ | ||
activeStep: 0, | ||
}); | ||
}; | ||
|
||
render() { | ||
const { classes } = this.props; | ||
const { activeStep } = this.state; | ||
const steps = getSteps(); | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<Stepper | ||
activeStep={activeStep} | ||
connector={ | ||
<StepConnector | ||
classes={{ | ||
active: classes.connectorActive, | ||
completed: classes.connectorCompleted, | ||
line: classes.line, | ||
}} | ||
/> | ||
} | ||
> | ||
{steps.map(label => ( | ||
<Step key={label}> | ||
<StepLabel>{label}</StepLabel> | ||
</Step> | ||
))} | ||
</Stepper> | ||
<div> | ||
{activeStep === steps.length ? ( | ||
<div> | ||
<Typography className={classes.instructions}> | ||
All steps completed - you"re finished | ||
</Typography> | ||
<Button onClick={this.handleReset} className={classes.button}> | ||
Reset | ||
</Button> | ||
</div> | ||
) : ( | ||
<div> | ||
<Typography className={classes.instructions}>{getStepContent(activeStep)}</Typography> | ||
<div> | ||
<Button | ||
disabled={activeStep === 0} | ||
onClick={this.handleBack} | ||
className={classes.button} | ||
> | ||
Back | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
onClick={this.handleNext} | ||
className={classes.button} | ||
> | ||
{activeStep === steps.length - 1 ? 'Finish' : 'Next'} | ||
</Button> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
CustomizedStepper.propTypes = { | ||
classes: PropTypes.object, | ||
}; | ||
|
||
export default withStyles(styles)(CustomizedStepper); |
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text is a bit off now that we moved it to its own section. Maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!