-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(StepIndicator): Add Step Indicator and Step (#199)
Add the `StepIndicator` and associated `Step` components from Rivet
- Loading branch information
Showing
11 changed files
with
234 additions
and
25 deletions.
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
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 @@ | ||
`Step` contains the individual steps in a step indicator. See the examples in [StepIndicator](/#/Page%20Content?id=StepIndicator) |
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,50 @@ | ||
/* | ||
Copyright (C) 2019 The Trustees of Indiana University | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
import { mount } from 'enzyme'; | ||
import * as React from 'react'; | ||
|
||
import Step from './Step' | ||
|
||
describe('<Step />', () => { | ||
describe('Rendering and styling', () =>{ | ||
it('should render without throwing an error', () => { | ||
const cut = mount(<Step indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} />); | ||
expect(cut.find('li')).toHaveLength(1); | ||
}); | ||
it('should pass attributes through', () => { | ||
const cut = mount(<Step id="the_id" indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} />); | ||
expect(cut.find('li').prop('id')).toEqual('the_id'); | ||
}); | ||
it('should apply custom classes', () => { | ||
const cut = mount(<Step className="foo" indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} />); | ||
expect(cut.find('li').hasClass('foo')).toBe(true); | ||
}); | ||
|
||
it('should set aria-current when current is set', () => { | ||
const cut = mount(<Step current indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} />); | ||
expect(cut.find('span[aria-current]')).toHaveLength(1); | ||
}); | ||
|
||
it('should set aria-current when current is set in an href', () => { | ||
const cut = mount(<Step current href="https://foo.com" indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} />); | ||
expect(cut.find('[aria-current="step"]')).toHaveLength(1); | ||
}); | ||
|
||
it('should not set aria-current when current is not set', () => { | ||
const cut = mount(<Step indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} />); | ||
expect(cut.find('span[aria-current]')).toHaveLength(0); | ||
}); | ||
|
||
it('should provide a link when href is set', () => { | ||
const cut = mount(<Step indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} href="https://foo.com" />); | ||
expect(cut.find('a')).toHaveLength(1); | ||
}); | ||
|
||
it('should set a variant if the variant property is set', () => { | ||
const cut = mount(<Step indicator={<span>1</span>} screenReaderIndicator="1" label={<span>Step</span>} variant="warning"/>); | ||
expect(cut.find('span .rvt-steps__indicator--warning')).toHaveLength(1) | ||
}); | ||
}); | ||
}); |
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,76 @@ | ||
/* | ||
Copyright (C) 2019 The Trustees of Indiana University | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
import * as classNames from 'classnames'; | ||
import * as React from 'react' | ||
|
||
|
||
export interface StepProps { | ||
/** | ||
* Defines whether the indicated step is the current step | ||
*/ | ||
current?: boolean; | ||
|
||
/** | ||
* An optional URL that can be used to create a link from this step to another location | ||
*/ | ||
href?: string; | ||
|
||
/** | ||
* A visual indicator to identify this step | ||
*/ | ||
indicator: JSX.Element; | ||
|
||
/** | ||
* A label for this step | ||
*/ | ||
label: JSX.Element; | ||
|
||
/** | ||
* An textual indicator to be used by screenreaders since the visual indicator may not include text | ||
*/ | ||
screenReaderIndicator: string | ||
|
||
/** | ||
* An optional variant to be applied to the indicator | ||
*/ | ||
variant?: 'success' | 'warning' | 'danger'; | ||
} | ||
|
||
const indicatorClass = 'rvt-steps__indicator'; | ||
|
||
const variantClass = (variant) => variant && `${indicatorClass}--${variant}`; | ||
|
||
const Step : React.SFC <StepProps & React.HTMLAttributes<HTMLLIElement>> = | ||
({ current, href, indicator, label, screenReaderIndicator, variant, ...attrs}) => { | ||
const content = ( | ||
<> | ||
<span className="rvt-steps__label">{label}</span> | ||
<span className={classNames(indicatorClass, variantClass(variant))}> | ||
<span className="rvt-sr-only">{screenReaderIndicator}</span> {indicator} | ||
</span> | ||
</> | ||
); | ||
let wrapper = ( | ||
<span className="rvt-steps__item-content" aria-current={current && 'step'}> | ||
{content} | ||
</span> | ||
); | ||
if (href) { | ||
wrapper = ( | ||
<a href={href} className="rvt-steps__item-content" aria-current={current && 'step'}> | ||
{content} | ||
</a> | ||
); | ||
} | ||
|
||
return ( | ||
<li className="rvt-steps__item" {...attrs}> | ||
{wrapper} | ||
</li> | ||
) | ||
}; | ||
Step.displayName = 'Step'; | ||
|
||
export default Step; |
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,24 @@ | ||
Use the step indicator component to help users keep track of their progress in a multi-step process, such as an application form. | ||
|
||
View the [Rivet documentation for Step Indicator](https://rivet.iu.edu/components/page-content/step-indicator/) | ||
|
||
### Basic step indicator | ||
|
||
```jsx | ||
<StepIndicator> | ||
<Step href="#" label="Personal Information" indicator="1" screenReaderIndicator="Step"/> | ||
<Step label="Records & transcripts" indicator="2" screenReaderIndicator="Step" current /> | ||
<Step label="Confirmation" indicator="3" screenReaderIndicator="Step" variant="success" /> | ||
</StepIndicator> | ||
``` | ||
|
||
### Vertical Step Indicator | ||
|
||
```jsx | ||
<StepIndicator vertical> | ||
<Step href="#" label="Personal Information" indicator="1" screenReaderIndicator="Step"/> | ||
<Step label="Records & transcripts" indicator="2" screenReaderIndicator="Step" current /> | ||
<Step label="Confirmation" indicator="3" screenReaderIndicator="Step" variant="success" /> | ||
</StepIndicator> | ||
|
||
``` |
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,35 @@ | ||
/* | ||
Copyright (C) 2019 The Trustees of Indiana University | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
import { mount } from 'enzyme'; | ||
import * as React from 'react'; | ||
|
||
import StepIndicator from './StepIndicator' | ||
|
||
describe('<StepIndicator />', () => { | ||
describe('Rendering and styling', () =>{ | ||
it('should render without throwing an error', () => { | ||
const cut = mount(<StepIndicator />); | ||
expect(cut.find('ol')).toHaveLength(1); | ||
}); | ||
it('should pass attributes through', () => { | ||
const cut = mount(<StepIndicator id="the_id" />); | ||
expect(cut.find('ol').prop('id')).toEqual('the_id'); | ||
}); | ||
it('should apply custom classes', () => { | ||
const cut = mount(<StepIndicator className="foo" />); | ||
expect(cut.find('ol').hasClass('foo')).toBe(true); | ||
}); | ||
|
||
it('should apply vertical styling if the vertical property is set', () => { | ||
const cut = mount(<StepIndicator vertical />); | ||
expect(cut.find('ol').hasClass('rvt-steps--vertical')).toBe(true); | ||
}); | ||
|
||
it('should not apply vertical styling if the vertical property is set', () => { | ||
const cut = mount(<StepIndicator />); | ||
expect(cut.find('ol').hasClass('rvt-steps--vertical')).toBe(false); | ||
}); | ||
}); | ||
}); |
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,26 @@ | ||
/* | ||
Copyright (C) 2019 The Trustees of Indiana University | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
import * as classNames from 'classnames'; | ||
import * as React from 'react'; | ||
import * as Rivet from '../util/Rivet'; | ||
|
||
export interface StepIndicatorProps { | ||
/** | ||
* Defines whether the step indicator should use the alternate vertical styling | ||
*/ | ||
vertical?: boolean | ||
} | ||
|
||
const componentClass = 'rvt-steps'; | ||
|
||
export const StepIndicator: React.SFC<StepIndicatorProps & React.HTMLAttributes<HTMLOListElement>> = | ||
({ className, children, vertical, id = Rivet.shortuid(), ...attrs }) => ( | ||
<ol id={id} className={classNames(componentClass, { 'rvt-steps--vertical': vertical}, className)} {...attrs}> | ||
{children} | ||
</ol> | ||
); | ||
StepIndicator.displayName = 'StepIndicator'; | ||
|
||
export default Rivet.rivetize(StepIndicator); |
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,6 @@ | ||
/* | ||
Copyright (C) 2019 The Trustees of Indiana University | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
export { default as Step } from './Step'; | ||
export { default as StepIndicator } from './StepIndicator'; |
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