Skip to content

Commit

Permalink
[stepper] Implement StepContent component and start cleaning up CSS a…
Browse files Browse the repository at this point in the history
…cross all components to match material guidelines. (mui#4799)
  • Loading branch information
alexhayes committed Sep 7, 2017
1 parent 2e531ad commit e86d351
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 38 deletions.
74 changes: 44 additions & 30 deletions docs/src/pages/component-demos/stepper/VerticalLinearStepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { withStyles, createStyleSheet } from "material-ui/styles";
import { Step, Stepper, StepLabel } from "material-ui/Stepper";
import { Step, Stepper, StepLabel, StepContent } from "material-ui/Stepper";
import Button from "material-ui/Button";
import Paper from "material-ui/Paper";
import Typography from "material-ui/Typography";

const styleSheet = createStyleSheet("VerticalLinearStepper", theme => ({
root: {
width: '90%'
},
backButton: {
marginRight: theme.spacing.unit
}
button: {
marginRight: theme.spacing.unit,
},
actionsContainer: {
marginTop: theme.spacing.unit,
},
resetContainer: {
marginTop: 0,
padding: theme.spacing.unit * 3, // TODO: See TODO note on Stepper
},
}));

class VerticalLinearStepper extends Component {
Expand Down Expand Up @@ -45,11 +54,16 @@ class VerticalLinearStepper extends Component {
getStepContent(stepIndex) {
switch (stepIndex) {
case 0:
return "Select campaign settings...";
return `For each ad campaign that you create, you can control how much
you're willing to spend on clicks and conversions, which networks
and geographical locations you want your ads to show on, and more.`;
case 1:
return "What is an ad group anyways?";
return "An ad group contains one or more ads which target a shared set of keywords.";
case 2:
return "This is the bit I really care about!";
return `Try out different ad text to see what brings in the most customers,
and learn how to enhance your ads using features like ad extensions.
If you run into any problems with your ads, find out how to tell if
they're running and how to resolve approval issues.`;
}
}

Expand All @@ -61,33 +75,33 @@ class VerticalLinearStepper extends Component {
return (
<div className={classes.root}>
<Stepper activeStep={activeStep} orientation="vertical">
{steps.map((label, i) => (
<Step key={i}>
{steps.map((label, step) => (
<Step key={step}>
<StepLabel>{label}</StepLabel>
<StepContent>
<Typography type="body1">{this.getStepContent(step)}</Typography>
<div className={classes.actionsContainer}>
<div>
<Button disabled={activeStep === 0} onClick={this.handleBack} className={classes.button}>
Back
</Button>
<Button raised color="primary" onClick={this.handleNext} className={classes.button}>
{activeStep === steps.length - 1 ? "Finish" : "Next"}
</Button>
</div>
</div>
</StepContent>
</Step>
))}
</Stepper>
<div>
{activeStep === steps.length
? <div>
<p>All steps completed - you're finished</p>
<Button onClick={this.handleReset} className={classes.button}>
Reset
</Button>
</div>
: <div>
<p>{this.getStepContent(activeStep)}</p>
<div>
<Button disabled={activeStep === 0} onClick={this.handleBack} className={classes.button}>
Back
</Button>
<Button raised color="primary" onClick={this.handleNext} className={classes.button}>
{activeStep === steps.length - 1 ? "Finish" : "Next"}
</Button>
</div>
</div>
}
</div>
{activeStep === steps.length &&
<Paper square elevation={0} className={classes.resetContainer}>
<Typography type="body1">All steps completed - you're finished</Typography>
<Button onClick={this.handleReset} className={classes.button}>
Reset
</Button>
</Paper>
}
</div>
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Stepper/Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ export const styleSheet = createStyleSheet("MuiStep", theme => ({
flex: "0 0 auto"
},
horizontal: {
marginLeft: -6,
},
vertical: {
marginLeft: -14,
},
alternativeLabel: {
flex: 1,
Expand Down
8 changes: 4 additions & 4 deletions src/Stepper/StepConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const styleSheet = createStyleSheet("MuiStepConnector", theme => ({
borderColor: theme.palette.line.stepper,
},
rootVertical: {
marginLeft: theme.spacing.unit + 4,
padding: `${theme.spacing.unit}px 0`,
marginLeft: 12, // half icon
padding: `0 0 ${theme.spacing.unit}px`,
},
lineHorizontal: {
marginLeft: -6,
Expand All @@ -26,7 +26,7 @@ export const styleSheet = createStyleSheet("MuiStepConnector", theme => ({
lineVertical: {
borderLeftStyle: "solid",
borderLeftWidth: 1,
minHeight: 28,
minHeight: 24,
},
alternativeLabelRoot: {
position: "absolute",
Expand Down Expand Up @@ -89,7 +89,7 @@ StepConnector.propTypes = {
/**
* @ignore
*/
orientation: PropTypes.oneOf(["horizontal", "vertical"]).isRequired
orientation: PropTypes.oneOf(["horizontal", "vertical"]).isRequired,
};

export default withStyles(styleSheet)(StepConnector);
114 changes: 114 additions & 0 deletions src/Stepper/StepContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import warning from 'warning';
import classNames from "classnames";
import { createStyleSheet } from "jss-theme-reactor";
import TransitionComponent from '../internal/ExpandTransition';
import withStyles from "../styles/withStyles";

function ExpandTransition(props) {
return <TransitionComponent {...props} />;
}

export const styleSheet = createStyleSheet("MuiStepContent", theme => ({
root: {
marginTop: theme.spacing.unit,
marginLeft: 12, // half icon
marginBottom: 0,
paddingTop: 0,
paddingLeft: theme.spacing.unit + 12, // margin + half icon
paddingRight: theme.spacing.unit,
overflow: 'hidden',
borderLeft: `1px solid ${theme.palette.line.stepper}`,
},
last: {
borderLeft: 'none',
}
}));


function StepContent(props) {
const {
active,
children,
className: classNameProp,
classes,
completed, // eslint-disable-line no-unused-vars
last, // eslint-disable-line no-unused-vars
transition,
transitionDuration,
orientation,
...other
} = props;

if (orientation !== 'vertical') {
warning(false, 'Material-UI: <StepContent /> is only designed for use with the vertical stepper.');
return null;
}

const className = classNames(
classes.root,
{
[classes.last]: last,
},
classNameProp
);

const transitionProps = {
enterDelay: transitionDuration,
transitionDuration: transitionDuration,
open: active,
};

return (
<div className={className} {...other}>
{React.createElement(transition, transitionProps, <div style={{overflow: 'hidden'}}>{children}</div>)}
</div>
);
}

StepContent.propTypes = {
/**
* Expands the content
*/
active: PropTypes.bool,
/**
* Step content
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to the component.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* @ignore
*/
completed: PropTypes.bool,
/**
* @ignore
*/
last: PropTypes.bool,
/**
* @ignore
*/
orientation: PropTypes.oneOf(["vertical"]).isRequired,
/**
* ReactTransitionGroup component.
*/
transition: PropTypes.func,
/**
* Adjust the duration of the content expand transition. Passed as a prop to the transition component.
*/
transitionDuration: PropTypes.number,
};

StepContent.defaultProps = {
transition: ExpandTransition,
transitionDuration: 450,
};

export default withStyles(styleSheet)(StepContent);
2 changes: 0 additions & 2 deletions src/Stepper/StepLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const styleSheet = createStyleSheet("MuiStepLabel", theme => ({
root: {
display: 'flex',
alignItems: 'center',
paddingLeft: 14,
paddingRight: 14,
},
horizontal: {
// height: 72,
Expand Down
1 change: 1 addition & 0 deletions src/Stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export Step from './Step';
export StepButton from './StepButton';
export StepContent from './StepContent';
// export StepContent from './StepContent';
export StepLabel from './StepLabel';
export Stepper from './Stepper';
73 changes: 73 additions & 0 deletions src/internal/ExpandTransition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import ReactTransitionGroup from 'react-transition-group/TransitionGroup';
import ExpandTransitionChild from './ExpandTransitionChild';

class ExpandTransition extends Component {
static propTypes = {
children: PropTypes.node,
enterDelay: PropTypes.number,
loading: PropTypes.bool,
open: PropTypes.bool,
style: PropTypes.object,
transitionDelay: PropTypes.number,
transitionDuration: PropTypes.number,
};

static defaultProps = {
enterDelay: 0,
transitionDelay: 0,
transitionDuration: 450,
loading: false,
open: false,
};

renderChildren(children) {
const {enterDelay, transitionDelay, transitionDuration} = this.props;
return React.Children.map(children, (child) => {
return (
<ExpandTransitionChild
enterDelay={enterDelay}
transitionDelay={transitionDelay}
transitionDuration={transitionDuration}
key={child.key}
>
{child}
</ExpandTransitionChild>
);
}, this);
}

render() {
const {
children,
enterDelay, // eslint-disable-line no-unused-vars
loading,
open,
style,
transitionDelay, // eslint-disable-line no-unused-vars
transitionDuration, // eslint-disable-line no-unused-vars
...other
} = this.props;

const mergedRootStyles = Object.assign({}, {
position: 'relative',
overflow: 'hidden',
height: 'auto',
}, style);

const newChildren = loading ? [] : this.renderChildren(children);

return (
<ReactTransitionGroup
style={mergedRootStyles}
component="div"
{...other}
>
{open && newChildren}
</ReactTransitionGroup>
);
}
}

export default ExpandTransition;
Loading

0 comments on commit e86d351

Please sign in to comment.