Navigation bar React component, with a “back” and a “close” variant
up vote
1
down vote
favorite
I am working on a component for a navigation bar. This navigation bar currently has two variations: a "back" version, and a "close" version.
I have come up with three different implementations but I am uncertain of which one is the best. Currently, I am leaning towards this implementation as it reads the best in my opinion.
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
NavigationBar.Close = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.close} />
)
NavigationBar.Back = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.back} />
)
// Usage: <NavigationBar.Close linkTo="/" />
This is similar to the first one, but you need to import the object that holds the navigation bar types:
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar type={NAVIGATION_BAR_TYPE.back} linkTo="/" />
Or this one, leveraging props:
const NavigationBar = ({ back, close, text, linkTo }) => {
const navigationType = back ? 'back' : 'close'
return (
<div className={`navigation-button ${navigationType}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar back linkTo="/" />
I don't like the third solution because if I need to add more variations, I feel like it clutters the props. And I don't like the second solution because then you are importing this enum-like object to define the type.
comparative-review react.js jsx
New contributor
add a comment |
up vote
1
down vote
favorite
I am working on a component for a navigation bar. This navigation bar currently has two variations: a "back" version, and a "close" version.
I have come up with three different implementations but I am uncertain of which one is the best. Currently, I am leaning towards this implementation as it reads the best in my opinion.
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
NavigationBar.Close = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.close} />
)
NavigationBar.Back = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.back} />
)
// Usage: <NavigationBar.Close linkTo="/" />
This is similar to the first one, but you need to import the object that holds the navigation bar types:
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar type={NAVIGATION_BAR_TYPE.back} linkTo="/" />
Or this one, leveraging props:
const NavigationBar = ({ back, close, text, linkTo }) => {
const navigationType = back ? 'back' : 'close'
return (
<div className={`navigation-button ${navigationType}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar back linkTo="/" />
I don't like the third solution because if I need to add more variations, I feel like it clutters the props. And I don't like the second solution because then you are importing this enum-like object to define the type.
comparative-review react.js jsx
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am working on a component for a navigation bar. This navigation bar currently has two variations: a "back" version, and a "close" version.
I have come up with three different implementations but I am uncertain of which one is the best. Currently, I am leaning towards this implementation as it reads the best in my opinion.
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
NavigationBar.Close = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.close} />
)
NavigationBar.Back = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.back} />
)
// Usage: <NavigationBar.Close linkTo="/" />
This is similar to the first one, but you need to import the object that holds the navigation bar types:
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar type={NAVIGATION_BAR_TYPE.back} linkTo="/" />
Or this one, leveraging props:
const NavigationBar = ({ back, close, text, linkTo }) => {
const navigationType = back ? 'back' : 'close'
return (
<div className={`navigation-button ${navigationType}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar back linkTo="/" />
I don't like the third solution because if I need to add more variations, I feel like it clutters the props. And I don't like the second solution because then you are importing this enum-like object to define the type.
comparative-review react.js jsx
New contributor
I am working on a component for a navigation bar. This navigation bar currently has two variations: a "back" version, and a "close" version.
I have come up with three different implementations but I am uncertain of which one is the best. Currently, I am leaning towards this implementation as it reads the best in my opinion.
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
NavigationBar.Close = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.close} />
)
NavigationBar.Back = (props) => (
<NavigationBar { ...props } type={NAVIGATION_BAR_TYPE.back} />
)
// Usage: <NavigationBar.Close linkTo="/" />
This is similar to the first one, but you need to import the object that holds the navigation bar types:
const NAVIGATION_BAR_TYPE = {
back: "back",
close: "close",
}
const NavigationBar = ({ type = NAVIGATION_BAR_TYPE.back, text, linkTo }) => {
return (
<div className={`navigation-button ${type}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar type={NAVIGATION_BAR_TYPE.back} linkTo="/" />
Or this one, leveraging props:
const NavigationBar = ({ back, close, text, linkTo }) => {
const navigationType = back ? 'back' : 'close'
return (
<div className={`navigation-button ${navigationType}`}>
<Link to={linkTo}>{text}</Link>
</div>
)
}
// Usage: <NavigationBar back linkTo="/" />
I don't like the third solution because if I need to add more variations, I feel like it clutters the props. And I don't like the second solution because then you are importing this enum-like object to define the type.
comparative-review react.js jsx
comparative-review react.js jsx
New contributor
New contributor
edited 2 days ago
200_success
127k15148412
127k15148412
New contributor
asked 2 days ago
Nitsew
1083
1083
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Without knowing the context of how this navigation bar is used in your app its hard to say which one would be more preferable. Does the navigation type dictate only the styling of the navigation bar or also some type of action too? Is the navigation type only tied to some sort of button within the navigation bar that displays differently and points to a different direction? Maybe doing something like this would work for that:
<NavigationBar>
<NavigationBar.ActionButton type='back' />
</NavigationBar>
All the variants you provided seem like good solutions, I think you are in best judgement here to decide what fits your apps needs.
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call theUINavigationBar
and you set thebackBarButtonItem
. I could achieve this using abackButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!
– Nitsew
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Without knowing the context of how this navigation bar is used in your app its hard to say which one would be more preferable. Does the navigation type dictate only the styling of the navigation bar or also some type of action too? Is the navigation type only tied to some sort of button within the navigation bar that displays differently and points to a different direction? Maybe doing something like this would work for that:
<NavigationBar>
<NavigationBar.ActionButton type='back' />
</NavigationBar>
All the variants you provided seem like good solutions, I think you are in best judgement here to decide what fits your apps needs.
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call theUINavigationBar
and you set thebackBarButtonItem
. I could achieve this using abackButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!
– Nitsew
yesterday
add a comment |
up vote
1
down vote
accepted
Without knowing the context of how this navigation bar is used in your app its hard to say which one would be more preferable. Does the navigation type dictate only the styling of the navigation bar or also some type of action too? Is the navigation type only tied to some sort of button within the navigation bar that displays differently and points to a different direction? Maybe doing something like this would work for that:
<NavigationBar>
<NavigationBar.ActionButton type='back' />
</NavigationBar>
All the variants you provided seem like good solutions, I think you are in best judgement here to decide what fits your apps needs.
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call theUINavigationBar
and you set thebackBarButtonItem
. I could achieve this using abackButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!
– Nitsew
yesterday
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Without knowing the context of how this navigation bar is used in your app its hard to say which one would be more preferable. Does the navigation type dictate only the styling of the navigation bar or also some type of action too? Is the navigation type only tied to some sort of button within the navigation bar that displays differently and points to a different direction? Maybe doing something like this would work for that:
<NavigationBar>
<NavigationBar.ActionButton type='back' />
</NavigationBar>
All the variants you provided seem like good solutions, I think you are in best judgement here to decide what fits your apps needs.
Without knowing the context of how this navigation bar is used in your app its hard to say which one would be more preferable. Does the navigation type dictate only the styling of the navigation bar or also some type of action too? Is the navigation type only tied to some sort of button within the navigation bar that displays differently and points to a different direction? Maybe doing something like this would work for that:
<NavigationBar>
<NavigationBar.ActionButton type='back' />
</NavigationBar>
All the variants you provided seem like good solutions, I think you are in best judgement here to decide what fits your apps needs.
answered yesterday
ByteSettlement
132210
132210
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call theUINavigationBar
and you set thebackBarButtonItem
. I could achieve this using abackButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!
– Nitsew
yesterday
add a comment |
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call theUINavigationBar
and you set thebackBarButtonItem
. I could achieve this using abackButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!
– Nitsew
yesterday
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call the
UINavigationBar
and you set the backBarButtonItem
. I could achieve this using a backButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!– Nitsew
yesterday
It's a mix of styling and functionality. For instance: the "back" variant should expect a linkTo prop, but the "close" variant could be used on a modal, so that would expect a callback function. I think a solution like you posted may be a better. I have also considered taking an approach similar to how it is handled in iOS's UIKit. You call the
UINavigationBar
and you set the backBarButtonItem
. I could achieve this using a backButton
prop that expects a component, and pass it either a link, or a button for instance. Thanks for the input!– Nitsew
yesterday
add a comment |
Nitsew is a new contributor. Be nice, and check out our Code of Conduct.
Nitsew is a new contributor. Be nice, and check out our Code of Conduct.
Nitsew is a new contributor. Be nice, and check out our Code of Conduct.
Nitsew is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208731%2fnavigation-bar-react-component-with-a-back-and-a-close-variant%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown