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.










share|improve this question




























    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.










    share|improve this question


























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 at 23:55









      200_success

      127k15149412




      127k15149412










      asked Nov 29 at 23:45









      Nitsew

      1083




      1083






















          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.






          share|improve this answer





















          • 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
            Nov 30 at 17:05











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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.






          share|improve this answer





















          • 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
            Nov 30 at 17:05















          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.






          share|improve this answer





















          • 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
            Nov 30 at 17:05













          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 30 at 16:17









          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 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
            Nov 30 at 17:05


















          • 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
            Nov 30 at 17:05
















          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
          Nov 30 at 17:05




          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
          Nov 30 at 17:05


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Список кардиналов, возведённых папой римским Каликстом III

          Deduzione

          Mysql.sock missing - “Can't connect to local MySQL server through socket”