Maintaining flexbox styling when using higher order components like react-reveal











up vote
2
down vote

favorite












I am using flexbox with styled-components to layout and size the elements in my app. I want to add a reveal animation and am using the react-reveal module. According to the documentation it is supposed to work out of the box with styled-components.



The problem is that the HOC wraps an extra div around the inner component which breaks the flexbox parent->child relationship.



Here is how I add the animation.



const Card = styled.div`
/* style */
min-height: 400px;
min-width: 100px;
max-width: 400px;
background-color: white;

/* flex */
display: flex;
flex-basis: 25%;
flex-direction: column;
justify-content: flex-start;
align-items: center;
`;

/* apply fade in animation */
const Card = withReveal(card, <Fade bottom />)


This div is one of 3 divs inside a containing div that looks like



const InnerContainer = styled.div`
width: 80%;
max-width: 1200px;
padding: 100px;

display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
`


Without applying the animation this layout works correctly, but when I use the HOC withReveal it wraps another div around the Card Component which messes up the flex layout.



I've tried using other animation modules but this technique of using a HOC component is the one used by almost every reactjs animation or styling module.



I tried wrapping the HOC component in a styled() and adding display: contents to try and pass through the CSS to the children but this seems to mess up the layout even further.










share|improve this question




























    up vote
    2
    down vote

    favorite












    I am using flexbox with styled-components to layout and size the elements in my app. I want to add a reveal animation and am using the react-reveal module. According to the documentation it is supposed to work out of the box with styled-components.



    The problem is that the HOC wraps an extra div around the inner component which breaks the flexbox parent->child relationship.



    Here is how I add the animation.



    const Card = styled.div`
    /* style */
    min-height: 400px;
    min-width: 100px;
    max-width: 400px;
    background-color: white;

    /* flex */
    display: flex;
    flex-basis: 25%;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    `;

    /* apply fade in animation */
    const Card = withReveal(card, <Fade bottom />)


    This div is one of 3 divs inside a containing div that looks like



    const InnerContainer = styled.div`
    width: 80%;
    max-width: 1200px;
    padding: 100px;

    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: center;
    `


    Without applying the animation this layout works correctly, but when I use the HOC withReveal it wraps another div around the Card Component which messes up the flex layout.



    I've tried using other animation modules but this technique of using a HOC component is the one used by almost every reactjs animation or styling module.



    I tried wrapping the HOC component in a styled() and adding display: contents to try and pass through the CSS to the children but this seems to mess up the layout even further.










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am using flexbox with styled-components to layout and size the elements in my app. I want to add a reveal animation and am using the react-reveal module. According to the documentation it is supposed to work out of the box with styled-components.



      The problem is that the HOC wraps an extra div around the inner component which breaks the flexbox parent->child relationship.



      Here is how I add the animation.



      const Card = styled.div`
      /* style */
      min-height: 400px;
      min-width: 100px;
      max-width: 400px;
      background-color: white;

      /* flex */
      display: flex;
      flex-basis: 25%;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;
      `;

      /* apply fade in animation */
      const Card = withReveal(card, <Fade bottom />)


      This div is one of 3 divs inside a containing div that looks like



      const InnerContainer = styled.div`
      width: 80%;
      max-width: 1200px;
      padding: 100px;

      display: flex;
      flex-direction: row;
      justify-content: space-evenly;
      align-items: center;
      `


      Without applying the animation this layout works correctly, but when I use the HOC withReveal it wraps another div around the Card Component which messes up the flex layout.



      I've tried using other animation modules but this technique of using a HOC component is the one used by almost every reactjs animation or styling module.



      I tried wrapping the HOC component in a styled() and adding display: contents to try and pass through the CSS to the children but this seems to mess up the layout even further.










      share|improve this question















      I am using flexbox with styled-components to layout and size the elements in my app. I want to add a reveal animation and am using the react-reveal module. According to the documentation it is supposed to work out of the box with styled-components.



      The problem is that the HOC wraps an extra div around the inner component which breaks the flexbox parent->child relationship.



      Here is how I add the animation.



      const Card = styled.div`
      /* style */
      min-height: 400px;
      min-width: 100px;
      max-width: 400px;
      background-color: white;

      /* flex */
      display: flex;
      flex-basis: 25%;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;
      `;

      /* apply fade in animation */
      const Card = withReveal(card, <Fade bottom />)


      This div is one of 3 divs inside a containing div that looks like



      const InnerContainer = styled.div`
      width: 80%;
      max-width: 1200px;
      padding: 100px;

      display: flex;
      flex-direction: row;
      justify-content: space-evenly;
      align-items: center;
      `


      Without applying the animation this layout works correctly, but when I use the HOC withReveal it wraps another div around the Card Component which messes up the flex layout.



      I've tried using other animation modules but this technique of using a HOC component is the one used by almost every reactjs animation or styling module.



      I tried wrapping the HOC component in a styled() and adding display: contents to try and pass through the CSS to the children but this seems to mess up the layout even further.







      javascript css reactjs flexbox higher-order-components






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 1:23









      Michael_B

      141k44225335




      141k44225335










      asked Nov 18 at 20:24









      Michael Sutherland

      876




      876
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can write your own nested styles with styled-components



          Try this



          const InnerContainer = styled.div`
          width: 80%;
          max-width: 1200px;
          padding: 100px;

          > div {
          display: flex;
          flex-direction: row;
          justify-content: space-evenly;
          align-items: center;
          }
          `





          share|improve this answer





















            Your Answer






            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: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53365085%2fmaintaining-flexbox-styling-when-using-higher-order-components-like-react-reveal%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
            0
            down vote













            You can write your own nested styles with styled-components



            Try this



            const InnerContainer = styled.div`
            width: 80%;
            max-width: 1200px;
            padding: 100px;

            > div {
            display: flex;
            flex-direction: row;
            justify-content: space-evenly;
            align-items: center;
            }
            `





            share|improve this answer

























              up vote
              0
              down vote













              You can write your own nested styles with styled-components



              Try this



              const InnerContainer = styled.div`
              width: 80%;
              max-width: 1200px;
              padding: 100px;

              > div {
              display: flex;
              flex-direction: row;
              justify-content: space-evenly;
              align-items: center;
              }
              `





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                You can write your own nested styles with styled-components



                Try this



                const InnerContainer = styled.div`
                width: 80%;
                max-width: 1200px;
                padding: 100px;

                > div {
                display: flex;
                flex-direction: row;
                justify-content: space-evenly;
                align-items: center;
                }
                `





                share|improve this answer












                You can write your own nested styles with styled-components



                Try this



                const InnerContainer = styled.div`
                width: 80%;
                max-width: 1200px;
                padding: 100px;

                > div {
                display: flex;
                flex-direction: row;
                justify-content: space-evenly;
                align-items: center;
                }
                `






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 1:28









                Dinesh Pandiyan

                1,379722




                1,379722






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365085%2fmaintaining-flexbox-styling-when-using-higher-order-components-like-react-reveal%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

                    Ottavio Pratesi

                    Tricia Helfer

                    15 giugno