-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
485 additions
and
12 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,31 @@ | ||
import PropTypes from 'prop-types'; | ||
import {useIntl} from 'react-intl'; | ||
|
||
import FAIcon from 'components/FAIcon'; | ||
|
||
const CompletionMark = ({completed = false}) => { | ||
const intl = useIntl(); | ||
// Wrapper may be a DOM element, which can't handle <FormattedMessage /> | ||
const ariaLabel = intl.formatMessage({ | ||
description: 'Step completion marker icon label', | ||
defaultMessage: 'Completed', | ||
}); | ||
|
||
if (!completed) return null; | ||
|
||
// provide a text alternative with aria-hidden="true" attribute on the icon and include text with an | ||
// additional element, such as a <span>, with appropriate CSS to visually hide the element while keeping it | ||
// accessible to assistive technologies. Only here where the Completion mark icon actually has a meaning. | ||
return ( | ||
<> | ||
<FAIcon icon="check" modifiers={['small']} aria-label={ariaLabel} title={ariaLabel} /> | ||
<span className="sr-only">{ariaLabel}</span> | ||
</> | ||
); | ||
}; | ||
|
||
CompletionMark.propTypes = { | ||
completed: PropTypes.bool, | ||
}; | ||
|
||
export default CompletionMark; |
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,43 @@ | ||
import PropTypes from 'prop-types'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import FAIcon from 'components/FAIcon'; | ||
import {getBEMClassName} from 'utils'; | ||
|
||
const MobileButton = ({ | ||
ariaIconLabel, | ||
accessibleToggleStepsLabel, | ||
formTitle, | ||
expanded, | ||
onExpandClick, | ||
}) => { | ||
return ( | ||
<button | ||
className={getBEMClassName('progress-indicator__mobile-header')} | ||
aria-pressed={expanded ? 'true' : 'false'} | ||
onClick={onExpandClick} | ||
> | ||
<FAIcon | ||
icon={expanded ? 'chevron-up' : 'chevron-down'} | ||
modifiers={['normal']} | ||
aria-label={ariaIconLabel} | ||
/> | ||
<span | ||
className={getBEMClassName('progress-indicator__form-title')} | ||
aria-label={accessibleToggleStepsLabel} | ||
> | ||
{formTitle} | ||
</span> | ||
</button> | ||
); | ||
}; | ||
|
||
MobileButton.propTypes = { | ||
ariaIconLabel: PropTypes.string.isRequired, | ||
accessibleToggleStepsLabel: PropTypes.oneOfType([PropTypes.string, FormattedMessage]), | ||
formTitle: PropTypes.string.isRequired, | ||
expanded: PropTypes.bool.isRequired, | ||
onExpandClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default MobileButton; |
76 changes: 76 additions & 0 deletions
76
src/components/ProgressIndicatorNew/ProgressIndicatorItem.js
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 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import Body from 'components/Body'; | ||
import Link from 'components/Link'; | ||
import {STEP_LABELS} from 'components/constants'; | ||
import {getBEMClassName} from 'utils'; | ||
|
||
import CompletionMark from './CompletionMark'; | ||
|
||
const ProgressIndicatorItem = ({ | ||
text, | ||
href, | ||
isActive, | ||
isCompleted, | ||
canNavigateTo, | ||
isApplicable, | ||
fixedText = null, | ||
}) => { | ||
const getLinkModifiers = (isActive, isApplicable) => { | ||
return [ | ||
'inherit', | ||
'hover', | ||
isActive ? 'active' : undefined, | ||
isApplicable ? undefined : 'muted', | ||
].filter(mod => mod !== undefined); | ||
}; | ||
|
||
return ( | ||
<div className={getBEMClassName('progress-indicator-item')}> | ||
<div className={getBEMClassName('progress-indicator-item__marker')}> | ||
<CompletionMark completed={isCompleted} /> | ||
</div> | ||
<div className={getBEMClassName('progress-indicator-item__label')}> | ||
{isApplicable && canNavigateTo ? ( | ||
<Link | ||
to={href} | ||
placeholder={!canNavigateTo} | ||
modifiers={getLinkModifiers(isActive, isApplicable)} | ||
aria-label={text} | ||
> | ||
<FormattedMessage | ||
description="Step label in progress indicator" | ||
defaultMessage={` | ||
{isApplicable, select, | ||
false {{label} (n/a)} | ||
other {{label}} | ||
}`} | ||
values={{ | ||
label: fixedText || text, | ||
isApplicable: isApplicable, | ||
}} | ||
/> | ||
</Link> | ||
) : ( | ||
<Body component="span" modifiers={isCompleted ? ['big'] : ['big', 'muted']}> | ||
{fixedText || text} | ||
</Body> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
ProgressIndicatorItem.propTypes = { | ||
text: PropTypes.string.isRequired, | ||
href: PropTypes.string, | ||
isActive: PropTypes.bool, | ||
isCompleted: PropTypes.bool, | ||
canNavigateTo: PropTypes.bool, | ||
isApplicable: PropTypes.bool, | ||
fixedText: PropTypes.oneOf(Object.values(STEP_LABELS)), | ||
}; | ||
|
||
export default ProgressIndicatorItem; |
20 changes: 20 additions & 0 deletions
20
src/components/ProgressIndicatorNew/ProgressIndicatorItem.stories.js
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,20 @@ | ||
import {withRouter} from 'storybook-addon-react-router-v6'; | ||
|
||
import ProgressIndicatorItem from './ProgressIndicatorItem'; | ||
|
||
export default { | ||
title: 'Private API / ProgressIndicatorNew / ProgressIndicatorItem', | ||
component: ProgressIndicatorItem, | ||
decorators: [withRouter], | ||
args: { | ||
text: 'Stap 1', | ||
href: '#', | ||
isActive: false, | ||
isCompleted: true, | ||
canNavigateTo: false, | ||
isApplicable: true, | ||
fixedText: null, | ||
}, | ||
}; | ||
|
||
export const Default = {}; |
Oops, something went wrong.