-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#25: made pageNavigation component more simple and independence of ch…
…ildren Fixed tests; Replaced NavButton with more common LinkButton
- Loading branch information
Igor Poplavsky
committed
Jun 11, 2020
1 parent
a625fb5
commit 2733bc2
Showing
8 changed files
with
75 additions
and
143 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
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
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 |
---|---|---|
@@ -1,70 +1,9 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import NavButton from './NavButton'; | ||
import Button from '../button/Button'; | ||
import './PageNavigation.scss'; | ||
|
||
const TYPE = { | ||
BACK: 'back', | ||
CENTER: 'center', | ||
FORWARD: 'forward', | ||
}; | ||
const VARIANTS = { | ||
[TYPE.BACK]: 'outlined', | ||
[TYPE.CENTER]: 'contained', | ||
[TYPE.FORWARD]: 'contained', | ||
}; | ||
|
||
function PageNavigation(props) { | ||
const { back, forward, center } = props; | ||
return ( | ||
<nav className="page-navigation"> | ||
<section className="page-navigation__start">{getComponent(back, TYPE.BACK)}</section> | ||
<section className="page-navigation__center">{getComponent(center, TYPE.CENTER)}</section> | ||
<section className="page-navigation__end">{getComponent(forward, TYPE.FORWARD)}</section> | ||
</nav> | ||
); | ||
} | ||
|
||
function getComponent(componentObject, type) { | ||
if (React.isValidElement(componentObject)) { | ||
return componentObject; | ||
} | ||
|
||
if (componentObject?.to) { | ||
return ( | ||
<NavButton to={componentObject.to} type={type} disabled={componentObject.disabled} variant={VARIANTS[type]}> | ||
{componentObject.label} | ||
</NavButton> | ||
); | ||
} | ||
|
||
if (componentObject?.onClick) { | ||
return ( | ||
<Button | ||
variant={VARIANTS[type]} | ||
color="primary" | ||
disabled={componentObject.disabled} | ||
onClick={componentObject.onClick} | ||
> | ||
{componentObject.label} | ||
</Button> | ||
); | ||
} | ||
import './PageNavigation.scss'; | ||
|
||
return null; | ||
function PageNavigation({ children }) { | ||
return <nav className="page-navigation">{children}</nav>; | ||
} | ||
|
||
const ButtonInterface = PropTypes.shape({ | ||
to: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.func]), | ||
label: PropTypes.string.isRequired, | ||
disabled: PropTypes.bool, | ||
onClick: PropTypes.func, | ||
}); | ||
|
||
PageNavigation.propTypes = { | ||
back: PropTypes.oneOfType([ButtonInterface, PropTypes.element]), | ||
forward: PropTypes.oneOfType([ButtonInterface, PropTypes.element]), | ||
}; | ||
|
||
export default PageNavigation; |
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 |
---|---|---|
@@ -1,17 +1,7 @@ | ||
.page-navigation { | ||
display: flex; | ||
padding: 20px 0 10px 0; | ||
|
||
section { | ||
display: flex; | ||
flex-grow: 1; | ||
flex-basis: 0; | ||
justify-content: center; | ||
align-items: start; | ||
|
||
.app-link { | ||
color: inherit; | ||
display: flex; | ||
} | ||
} | ||
justify-content: space-between; | ||
width: 80%; | ||
margin: auto; | ||
} |