Skip to content
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

Step status props #673

Merged
merged 3 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `0.0.42`.
- Added `status` prop to `EuiStep` for additional styling ([#673](https://github.com/elastic/eui/pull/673))

## [`0.0.42`](https://github.com/elastic/eui/tree/v0.0.42)

Expand Down
69 changes: 69 additions & 0 deletions src-docs/src/views/steps/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import React, {
Component,
Fragment,
} from 'react';

import {
EuiSpacer,
EuiSteps,
EuiButton,
} from '../../../../src/components';

export default class extends Component {

constructor(props) {
super(props);

this.state = {
status: 'incomplete',
};

this.handleComplete = this.handleComplete.bind(this);
}

handleComplete() {
this.setState({
status: 'complete',
});
}

render() {

let button;
if (this.state.status === "incomplete") {
button = (
<EuiButton onClick={this.handleComplete}>You complete me</EuiButton>
);
}

const firstSetOfSteps = [
{
title: 'Normal step',
children: <p>Do this first</p>,
},
{
title: 'Push the button to complete this final step',
children: (
<Fragment>
<p>
I am a fancy button just waiting to be pushed!
</p>
<EuiSpacer />
{button}
</Fragment>
),
status: this.state.status,
},
];

return (
<div>
<EuiSteps
steps={firstSetOfSteps}
/>

</div>
);
}
}
22 changes: 22 additions & 0 deletions src-docs/src/views/steps/steps_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import StepsHorizontal from './steps_horizontal';
const stepsHorizontalSource = require('!!raw-loader!./steps_horizontal');
const stepsHorizontalHtml = renderToHtml(StepsHorizontal);

import Status from './status';
const statusSource = require('!!raw-loader!./status');
const statusHtml = renderToHtml(Steps);

export const StepsExample = {
title: 'Steps',
sections: [{
Expand Down Expand Up @@ -87,6 +91,24 @@ export const StepsExample = {
),
demo: <HeadingElementSteps />,
},
{
title: 'Steps status',
source: [{
type: GuideSectionTypes.JS,
code: statusSource,
}, {
type: GuideSectionTypes.HTML,
code: statusHtml,
}],
text: (
<p>
Steps can optionally include <EuiCode>status</EuiCode> prop with
a value of <EuiCode>complete</EuiCode> or <EuiCode>incomplete</EuiCode>. This
is used mostly as a final step when you need to make some sort of final check.
</p>
),
demo: <Status />,
},
{
title: 'Horizontal',
source: [{
Expand Down
6 changes: 5 additions & 1 deletion src/components/steps/__snapshots__/step.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ exports[`EuiStep is rendered 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
1
</div>
<h3
class="euiTitle euiTitle--small euiStep__title"
data-step-num="1"
>
First step
</h3>
Expand Down
54 changes: 45 additions & 9 deletions src/components/steps/__snapshots__/steps.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ exports[`EuiSteps renders step title inside "headingElement" element 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
1
</div>
<h2
class="euiTitle euiTitle--small euiStep__title"
data-step-num="1"
>
first title
</h2>
Expand All @@ -36,9 +40,13 @@ exports[`EuiSteps renders step title inside "headingElement" element 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
2
</div>
<h2
class="euiTitle euiTitle--small euiStep__title"
data-step-num="2"
>
second title
</h2>
Expand All @@ -58,9 +66,13 @@ exports[`EuiSteps renders step title inside "headingElement" element 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
3
</div>
<h2
class="euiTitle euiTitle--small euiStep__title"
data-step-num="3"
>
third title
</h2>
Expand Down Expand Up @@ -89,9 +101,13 @@ exports[`EuiSteps renders steps 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
1
</div>
<p
class="euiTitle euiTitle--small euiStep__title"
data-step-num="1"
>
first title
</p>
Expand All @@ -111,9 +127,13 @@ exports[`EuiSteps renders steps 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
2
</div>
<p
class="euiTitle euiTitle--small euiStep__title"
data-step-num="2"
>
second title
</p>
Expand All @@ -133,9 +153,13 @@ exports[`EuiSteps renders steps 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
3
</div>
<p
class="euiTitle euiTitle--small euiStep__title"
data-step-num="3"
>
third title
</p>
Expand Down Expand Up @@ -164,9 +188,13 @@ exports[`EuiSteps renders steps with firstStepNumber 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
10
</div>
<p
class="euiTitle euiTitle--small euiStep__title"
data-step-num="10"
>
first title
</p>
Expand All @@ -186,9 +214,13 @@ exports[`EuiSteps renders steps with firstStepNumber 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
11
</div>
<p
class="euiTitle euiTitle--small euiStep__title"
data-step-num="11"
>
second title
</p>
Expand All @@ -208,9 +240,13 @@ exports[`EuiSteps renders steps with firstStepNumber 1`] = `
>
Step
</span>
<div
class="euiStep__circle"
>
12
</div>
<p
class="euiTitle euiTitle--small euiStep__title"
data-step-num="12"
>
third title
</p>
Expand Down
30 changes: 22 additions & 8 deletions src/components/steps/_steps.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,33 @@
line-height: $euiStepNumberSize; /* 1 */
}

.euiStep__title {
font-weight: $euiFontWeightMedium;
.euiStep__circle {
@include createStepsNumber();

margin-right: $euiStepNumberMargin;
vertical-align: top; /* 1 */

&::before {
content: attr(data-step-num); // Get the number from the data attribute
@include createStepsNumber();
&.euiStep__circle--incomplete {
background-color: transparent;
border: solid 2px $euiColorPrimary;
color: $euiColorDarkShade;
}

&.euiStep__circle--complete {
animation: euiGrow $euiAnimSpeedFast ease-in;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would the bounce easing matrix look?

}

margin-right: $euiStepNumberMargin;
vertical-align: top; /* 1 */
.euiStep__circleIcon {
position: relative;
top: -2px;
}
}

.euiStep__title {
font-weight: $euiFontWeightMedium;
display: inline-block;
}

.euiStep__content {
border-left: $euiBorderThick;
padding: $euiSize $euiSize $euiSizeXL;
Expand All @@ -36,4 +51,3 @@
margin-left: ($euiStepNumberSize/2) - 1px;
}
}

36 changes: 35 additions & 1 deletion src/components/steps/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,35 @@ import {
EuiTitle,
} from '../title';

import {
EuiIcon,
} from '../icon';

export const EuiStep = ({
className,
children,
headingElement,
step,
title,
status,
...rest
}) => {
const classes = classNames('euiStep', className);
const circleClasses = classNames(
'euiStep__circle',
{
'euiStep__circle--complete': (status === "complete"),
'euiStep__circle--incomplete': (status === "incomplete"),
}
);

let numberOrIcon;
if (status === "complete") {
numberOrIcon = <EuiIcon type="check" color="ghost" className="euiStep__circleIcon" />;
} else if (status !== "incomplete") {
numberOrIcon = step;
}

return (
<div
className={classes}
Expand All @@ -27,7 +47,11 @@ export const EuiStep = ({

<EuiScreenReaderOnly><span>Step</span></EuiScreenReaderOnly>

<EuiTitle size="s" className="euiStep__title" data-step-num={step}>
<div className={circleClasses}>
{numberOrIcon}
</div>

<EuiTitle size="s" className="euiStep__title">
{React.createElement(headingElement, null, title)}
</EuiTitle>

Expand All @@ -41,8 +65,18 @@ export const EuiStep = ({

EuiStep.propTypes = {
children: PropTypes.node.isRequired,
/**
* Will replace the number provided in props.step with alternate styling
*/
status: PropTypes.oneOf(['complete', 'incomplete']),
/**
* The number of the step in the list of steps
*/
step: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
/**
* The HTML tag used for the title
*/
headingElement: PropTypes.string.isRequired,
};

Expand Down
2 changes: 2 additions & 0 deletions src/components/steps/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function renderSteps(steps, firstStepNumber, headingElement) {
className,
children,
title,
status,
...rest
} = step;

Expand All @@ -19,6 +20,7 @@ function renderSteps(steps, firstStepNumber, headingElement) {
headingElement={headingElement}
step={firstStepNumber + index}
title={title}
status={status}
{...rest}
>
{children}
Expand Down