diff --git a/.gitignore b/.gitignore index 0e5d6b8..82acbf3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules example/bundle* npm-debug.log + +.idea \ No newline at end of file diff --git a/README.md b/README.md index db69b92..67b86c1 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,14 @@ See full example [here](https://github.com/mu29/react-stepper/blob/master/exampl |activeBorderStyle|Style of border surrounding active circle|solid|string| |defaultBarColor|Default color of bar separating circles|#E0E0E0|string| |completeBarColor|Color of bar connected to a completed step|#E0E0E0|string| +|lineMarginOffset|Offset for line margin|4|number| +|defaultBorderWidth|Default Border Width|3|number| ### Step Objects | name | description | default | type | |----------|----------------|------------|--------| |title|Displayed text of the step below the number|undefined|string| +|icon|Displayed icon of the step|undefined|image/object| |href|Link to send them to on click|undefined|string| |onClick|Event handler for when the step is clicked|undefined|function| diff --git a/lib/Step.js b/lib/Step.js index a974cdf..5bed137 100644 --- a/lib/Step.js +++ b/lib/Step.js @@ -63,7 +63,9 @@ var Step = function (_Component) { activeBorderColor = _props.activeBorderColor, defaultBorderStyle = _props.defaultBorderStyle, completeBorderStyle = _props.completeBorderStyle, - activeBorderStyle = _props.activeBorderStyle; + activeBorderStyle = _props.activeBorderStyle, + lineMarginOffset = _props.lineMarginOffset, + defaultBorderWidth = _props.defaultBorderWidth; return { @@ -85,21 +87,21 @@ var Step = function (_Component) { color: circleFontColor, display: 'block', opacity: defaultOpacity, - borderWidth: defaultBorderColor ? 3 : 0, + borderWidth: defaultBorderColor ? defaultBorderWidth : 0, borderColor: defaultBorderColor, borderStyle: defaultBorderStyle }, activeCircle: { backgroundColor: activeColor, opacity: activeOpacity, - borderWidth: activeBorderColor ? 3 : 0, + borderWidth: activeBorderColor ? defaultBorderWidth : 0, borderColor: activeBorderColor, borderStyle: activeBorderStyle }, completedCircle: { backgroundColor: completeColor, opacity: completeOpacity, - borderWidth: completeBorderColor ? 3 : 0, + borderWidth: completeBorderColor ? defaultBorderWidth : 0, borderColor: completeBorderColor, borderStyle: completeBorderStyle }, @@ -133,7 +135,7 @@ var Step = function (_Component) { borderTopColor: defaultBarColor, left: 0, right: '50%', - marginRight: size / 2 + 4, + marginRight: size / 2 + lineMarginOffset, opacity: defaultOpacity }, rightBar: { @@ -145,7 +147,7 @@ var Step = function (_Component) { borderTopColor: defaultBarColor, right: 0, left: '50%', - marginLeft: size / 2 + 4, + marginLeft: size / 2 + lineMarginOffset, opacity: defaultOpacity }, completedBar: { @@ -161,6 +163,7 @@ var Step = function (_Component) { value: function render() { var _props2 = this.props, title = _props2.title, + icon = _props2.icon, index = _props2.index, active = _props2.active, completed = _props2.completed, @@ -176,6 +179,8 @@ var Step = function (_Component) { var leftStyle = Object.assign(styles.leftBar, active || completed ? styles.completedBar : {}); var rightStyle = Object.assign(styles.rightBar, completed ? styles.completedBar : {}); + var stepContent = icon ? _react2.default.createElement('img', { src: icon, alt: index + 1 }) : index + 1; + return _react2.default.createElement( 'div', { style: styles.step }, @@ -185,11 +190,11 @@ var Step = function (_Component) { active || completed ? _react2.default.createElement( 'a', { href: href, onClick: onClick, style: styles.index }, - index + 1 + stepContent ) : _react2.default.createElement( 'span', { style: styles.index }, - index + 1 + stepContent ) ), active || completed ? _react2.default.createElement( @@ -228,7 +233,9 @@ Step.defaultProps = { titleTop: 8, defaultBarColor: '#E0E0E0', barStyle: 'solid', - borderStyle: 'solid' + borderStyle: 'solid', + lineMarginOffset: 4, + defaultBorderWidth: 3 }; Step.propTypes = { @@ -265,5 +272,7 @@ Step.propTypes = { activeBorderColor: _propTypes.PropTypes.string, defaultBorderStyle: _propTypes.PropTypes.string, completeBorderStyle: _propTypes.PropTypes.string, - activeBorderStyle: _propTypes.PropTypes.string + activeBorderStyle: _propTypes.PropTypes.string, + lineMarginOffset: _propTypes.PropTypes.number, + defaultBorderWidth: _propTypes.PropTypes.number }; \ No newline at end of file diff --git a/lib/Stepper.js b/lib/Stepper.js index dfb6dcb..16ac51c 100644 --- a/lib/Stepper.js +++ b/lib/Stepper.js @@ -59,7 +59,9 @@ function Stepper(_ref) { completeBorderStyle = _ref.completeBorderStyle, activeBorderStyle = _ref.activeBorderStyle, defaultBarColor = _ref.defaultBarColor, - completeBarColor = _ref.completeBarColor; + completeBarColor = _ref.completeBarColor, + lineMarginOffset = _ref.lineMarginOffset, + defaultBorderWidth = _ref.defaultBorderWidth; return _react2.default.createElement( 'div', @@ -72,6 +74,7 @@ function Stepper(_ref) { key: index, width: 100 / steps.length, title: step.title, + icon: step.icon, href: step.href, onClick: step.onClick, active: !(disabledSteps || []).includes(index) && index === activeStep, @@ -102,10 +105,12 @@ function Stepper(_ref) { completeBorderColor: completeBorderColor, activeBorderColor: activeBorderColor, defaultBorderStyle: defaultBorderStyle, + defaultBorderWidth: defaultBorderWidth, completeBorderStyle: completeBorderStyle, activeBorderStyle: activeBorderStyle, defaultBarColor: defaultBarColor, - completeBarColor: completeBarColor + completeBarColor: completeBarColor, + lineMarginOffset: lineMarginOffset }); }) ) @@ -145,7 +150,9 @@ Stepper.propTypes = { activeBorderColor: _propTypes.PropTypes.string, defaultBorderStyle: _propTypes.PropTypes.string, completeBorderStyle: _propTypes.PropTypes.string, - activeBorderStyle: _propTypes.PropTypes.string + activeBorderStyle: _propTypes.PropTypes.string, + lineMarginOffset: _propTypes.PropTypes.number, + defaultBorderWidth: _propTypes.PropTypes.number }; exports.default = Stepper; \ No newline at end of file diff --git a/src/Step.js b/src/Step.js index 401c1d1..ad4856f 100644 --- a/src/Step.js +++ b/src/Step.js @@ -15,7 +15,7 @@ export default class Step extends Component { circleTop, titleTop, width, completeOpacity, activeOpacity, defaultOpacity, completeTitleOpacity, activeTitleOpacity, defaultTitleOpacity, barStyle, defaultBarColor, completeBarColor, defaultBorderColor, completeBorderColor, activeBorderColor, - defaultBorderStyle,completeBorderStyle, activeBorderStyle + defaultBorderStyle,completeBorderStyle, activeBorderStyle, lineMarginOffset, defaultBorderWidth } = this.props; return { @@ -37,21 +37,21 @@ export default class Step extends Component { color: circleFontColor, display: 'block', opacity: defaultOpacity, - borderWidth: (defaultBorderColor ? 3 : 0), + borderWidth: (defaultBorderColor ? defaultBorderWidth : 0), borderColor: defaultBorderColor, borderStyle: defaultBorderStyle }, activeCircle: { backgroundColor: activeColor, opacity: activeOpacity, - borderWidth: (activeBorderColor ? 3 : 0), + borderWidth: (activeBorderColor ? defaultBorderWidth : 0), borderColor: activeBorderColor, borderStyle: activeBorderStyle, }, completedCircle: { backgroundColor: completeColor, opacity: completeOpacity, - borderWidth: (completeBorderColor ? 3 : 0), + borderWidth: (completeBorderColor ? defaultBorderWidth : 0), borderColor: completeBorderColor, borderStyle: completeBorderStyle, }, @@ -85,7 +85,7 @@ export default class Step extends Component { borderTopColor: defaultBarColor, left: 0, right: '50%', - marginRight: size / 2 + 4, + marginRight: size / 2 + lineMarginOffset, opacity: defaultOpacity, }, rightBar: { @@ -97,7 +97,7 @@ export default class Step extends Component { borderTopColor: defaultBarColor, right: 0, left: '50%', - marginLeft: size / 2 + 4, + marginLeft: size / 2 + lineMarginOffset, opacity: defaultOpacity, }, completedBar: { @@ -110,7 +110,7 @@ export default class Step extends Component { } render() { - const { title, index, active, completed, first, isLast, href, onClick } = this.props; + const { title, icon, index, active, completed, first, isLast, href, onClick } = this.props; const styles = this.getStyles(); const circleStyle = Object.assign( @@ -126,13 +126,15 @@ export default class Step extends Component { const leftStyle = Object.assign(styles.leftBar, (active || completed) ? styles.completedBar : {}); const rightStyle = Object.assign(styles.rightBar, completed ? styles.completedBar : {}); + const stepContent = icon ? : index + 1; + return (