Can we override scss variables vai react props?Is it possible?












0














Its been 2 whole days i can't find any solutions.I have no solutions yets:( I'm having color states. I'll select from color picker a color, I'll update that particular color state:
Requirement is if I pick from color picker it must be passed from react js property or variables to scss variable n override them. it must be done via reacrjs to scss if it can be done from js to css then it can be done from reacr js to scss whats that one thing which m missing on it.



App.js



{
primary: '#1976D2',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FFC107'
}


ex: primary: '#1976D2' I'll pick in update to primary: '#ffffff' something like:



App.js



changeColor(e){
this.setState({primary:e.target.value}) // the value is updated to #ffffff
}


Now, I need to pass this.props.primary to .scss something like:



variables.scss



$primary:this.props.primary


login.scss



.btn{ 
background-color:$primary
}


my need is it must be dynamic if i pick from color picker it must be passed from react js property or variables to scss variable n override them



We can do it inline styling but I wanna do it the way defined above (via .scss).
Is it possible?or is the any better way?



something like this



https://vuetifyjs.com/en/style/theme



vuejs uses theme thats overides to scss variables



Vue.use(Vuetify, {
theme: {
primary: '#3f51b5',
secondary: '#b0bec5',
accent: '#8c9eff',
error: '#b71c1c'
}
})


can anyone please explain me how they r doing I'm not understanding










share|improve this question




















  • 1




    scss is compiled ahead of runtime, what is react supposed to do about it as it can operate on runtime only? If you need variables at runtime, you'll have to take a look at CSS variables.
    – connexo
    Nov 21 '18 at 14:32












  • then how do i do something dynamically or any good option any good link for css variable at runtime to learn quick ?
    – Tested
    Nov 21 '18 at 14:35












  • As stated in the latter part of my comment.
    – connexo
    Nov 21 '18 at 14:36












  • Take a look at: stackoverflow.com/questions/52491779/…
    – Zim
    Nov 21 '18 at 15:45










  • @Zim i dont want sass-vars-to-js my need is i pick a color i.e., via js pass to sass
    – Tested
    Nov 21 '18 at 15:59
















0














Its been 2 whole days i can't find any solutions.I have no solutions yets:( I'm having color states. I'll select from color picker a color, I'll update that particular color state:
Requirement is if I pick from color picker it must be passed from react js property or variables to scss variable n override them. it must be done via reacrjs to scss if it can be done from js to css then it can be done from reacr js to scss whats that one thing which m missing on it.



App.js



{
primary: '#1976D2',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FFC107'
}


ex: primary: '#1976D2' I'll pick in update to primary: '#ffffff' something like:



App.js



changeColor(e){
this.setState({primary:e.target.value}) // the value is updated to #ffffff
}


Now, I need to pass this.props.primary to .scss something like:



variables.scss



$primary:this.props.primary


login.scss



.btn{ 
background-color:$primary
}


my need is it must be dynamic if i pick from color picker it must be passed from react js property or variables to scss variable n override them



We can do it inline styling but I wanna do it the way defined above (via .scss).
Is it possible?or is the any better way?



something like this



https://vuetifyjs.com/en/style/theme



vuejs uses theme thats overides to scss variables



Vue.use(Vuetify, {
theme: {
primary: '#3f51b5',
secondary: '#b0bec5',
accent: '#8c9eff',
error: '#b71c1c'
}
})


can anyone please explain me how they r doing I'm not understanding










share|improve this question




















  • 1




    scss is compiled ahead of runtime, what is react supposed to do about it as it can operate on runtime only? If you need variables at runtime, you'll have to take a look at CSS variables.
    – connexo
    Nov 21 '18 at 14:32












  • then how do i do something dynamically or any good option any good link for css variable at runtime to learn quick ?
    – Tested
    Nov 21 '18 at 14:35












  • As stated in the latter part of my comment.
    – connexo
    Nov 21 '18 at 14:36












  • Take a look at: stackoverflow.com/questions/52491779/…
    – Zim
    Nov 21 '18 at 15:45










  • @Zim i dont want sass-vars-to-js my need is i pick a color i.e., via js pass to sass
    – Tested
    Nov 21 '18 at 15:59














0












0








0







Its been 2 whole days i can't find any solutions.I have no solutions yets:( I'm having color states. I'll select from color picker a color, I'll update that particular color state:
Requirement is if I pick from color picker it must be passed from react js property or variables to scss variable n override them. it must be done via reacrjs to scss if it can be done from js to css then it can be done from reacr js to scss whats that one thing which m missing on it.



App.js



{
primary: '#1976D2',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FFC107'
}


ex: primary: '#1976D2' I'll pick in update to primary: '#ffffff' something like:



App.js



changeColor(e){
this.setState({primary:e.target.value}) // the value is updated to #ffffff
}


Now, I need to pass this.props.primary to .scss something like:



variables.scss



$primary:this.props.primary


login.scss



.btn{ 
background-color:$primary
}


my need is it must be dynamic if i pick from color picker it must be passed from react js property or variables to scss variable n override them



We can do it inline styling but I wanna do it the way defined above (via .scss).
Is it possible?or is the any better way?



something like this



https://vuetifyjs.com/en/style/theme



vuejs uses theme thats overides to scss variables



Vue.use(Vuetify, {
theme: {
primary: '#3f51b5',
secondary: '#b0bec5',
accent: '#8c9eff',
error: '#b71c1c'
}
})


can anyone please explain me how they r doing I'm not understanding










share|improve this question















Its been 2 whole days i can't find any solutions.I have no solutions yets:( I'm having color states. I'll select from color picker a color, I'll update that particular color state:
Requirement is if I pick from color picker it must be passed from react js property or variables to scss variable n override them. it must be done via reacrjs to scss if it can be done from js to css then it can be done from reacr js to scss whats that one thing which m missing on it.



App.js



{
primary: '#1976D2',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FFC107'
}


ex: primary: '#1976D2' I'll pick in update to primary: '#ffffff' something like:



App.js



changeColor(e){
this.setState({primary:e.target.value}) // the value is updated to #ffffff
}


Now, I need to pass this.props.primary to .scss something like:



variables.scss



$primary:this.props.primary


login.scss



.btn{ 
background-color:$primary
}


my need is it must be dynamic if i pick from color picker it must be passed from react js property or variables to scss variable n override them



We can do it inline styling but I wanna do it the way defined above (via .scss).
Is it possible?or is the any better way?



something like this



https://vuetifyjs.com/en/style/theme



vuejs uses theme thats overides to scss variables



Vue.use(Vuetify, {
theme: {
primary: '#3f51b5',
secondary: '#b0bec5',
accent: '#8c9eff',
error: '#b71c1c'
}
})


can anyone please explain me how they r doing I'm not understanding







reactjs sass bootstrap-4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 8:36







Tested

















asked Nov 21 '18 at 14:29









TestedTested

1741216




1741216








  • 1




    scss is compiled ahead of runtime, what is react supposed to do about it as it can operate on runtime only? If you need variables at runtime, you'll have to take a look at CSS variables.
    – connexo
    Nov 21 '18 at 14:32












  • then how do i do something dynamically or any good option any good link for css variable at runtime to learn quick ?
    – Tested
    Nov 21 '18 at 14:35












  • As stated in the latter part of my comment.
    – connexo
    Nov 21 '18 at 14:36












  • Take a look at: stackoverflow.com/questions/52491779/…
    – Zim
    Nov 21 '18 at 15:45










  • @Zim i dont want sass-vars-to-js my need is i pick a color i.e., via js pass to sass
    – Tested
    Nov 21 '18 at 15:59














  • 1




    scss is compiled ahead of runtime, what is react supposed to do about it as it can operate on runtime only? If you need variables at runtime, you'll have to take a look at CSS variables.
    – connexo
    Nov 21 '18 at 14:32












  • then how do i do something dynamically or any good option any good link for css variable at runtime to learn quick ?
    – Tested
    Nov 21 '18 at 14:35












  • As stated in the latter part of my comment.
    – connexo
    Nov 21 '18 at 14:36












  • Take a look at: stackoverflow.com/questions/52491779/…
    – Zim
    Nov 21 '18 at 15:45










  • @Zim i dont want sass-vars-to-js my need is i pick a color i.e., via js pass to sass
    – Tested
    Nov 21 '18 at 15:59








1




1




scss is compiled ahead of runtime, what is react supposed to do about it as it can operate on runtime only? If you need variables at runtime, you'll have to take a look at CSS variables.
– connexo
Nov 21 '18 at 14:32






scss is compiled ahead of runtime, what is react supposed to do about it as it can operate on runtime only? If you need variables at runtime, you'll have to take a look at CSS variables.
– connexo
Nov 21 '18 at 14:32














then how do i do something dynamically or any good option any good link for css variable at runtime to learn quick ?
– Tested
Nov 21 '18 at 14:35






then how do i do something dynamically or any good option any good link for css variable at runtime to learn quick ?
– Tested
Nov 21 '18 at 14:35














As stated in the latter part of my comment.
– connexo
Nov 21 '18 at 14:36






As stated in the latter part of my comment.
– connexo
Nov 21 '18 at 14:36














Take a look at: stackoverflow.com/questions/52491779/…
– Zim
Nov 21 '18 at 15:45




Take a look at: stackoverflow.com/questions/52491779/…
– Zim
Nov 21 '18 at 15:45












@Zim i dont want sass-vars-to-js my need is i pick a color i.e., via js pass to sass
– Tested
Nov 21 '18 at 15:59




@Zim i dont want sass-vars-to-js my need is i pick a color i.e., via js pass to sass
– Tested
Nov 21 '18 at 15:59












2 Answers
2






active

oldest

votes


















1














I would use Styled Components instead. There you can pass your styling by props



https://www.styled-components.com/docs/advanced






share|improve this answer





















  • Or just styles defined in components
    – Sulthan
    Nov 23 '18 at 7:19










  • nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
    – Tested
    Nov 23 '18 at 7:39



















0














First. Just to clarify. You are not able to change SASS variables from browser. Because how it works: SASS code -> compiled into CSS -> CSS is sent from server to browser -> . So we actually should searching "how to override by JS something that was SASS variable in consistent way".



The only way I see doing that is using CSS custom properties. Take a look into spec to understand their caveats(e.g. it cannot be used as part of size value in @media) and about support in browsers.



I'm not really sure if SASS supports compiling variables into CSS custom properties. Take a look into css-vars mixin. With using



$css-vars-use-native: true;


you will get your variables exported as CSS custom properties. Unfortunately it means you need to change you existing styles to use var() from mixin for variables you want being able to override later



Then your code will be able to override any of custom properties as easy as



document.body.style.setProperty('--primaryColor', myColorValueFromDatePicker)


Take a look into fine and short article on how to change custom properties with JS



NB since custom properties uses the same cascade approach as any CSS you additional get ability to apply changed value on any part of DOM:



document.querySelector('#previewBlock').style.setProperty(....);





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',
    autoActivateHeartbeat: false,
    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%2f53414299%2fcan-we-override-scss-variables-vai-react-propsis-it-possible%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I would use Styled Components instead. There you can pass your styling by props



    https://www.styled-components.com/docs/advanced






    share|improve this answer





















    • Or just styles defined in components
      – Sulthan
      Nov 23 '18 at 7:19










    • nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
      – Tested
      Nov 23 '18 at 7:39
















    1














    I would use Styled Components instead. There you can pass your styling by props



    https://www.styled-components.com/docs/advanced






    share|improve this answer





















    • Or just styles defined in components
      – Sulthan
      Nov 23 '18 at 7:19










    • nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
      – Tested
      Nov 23 '18 at 7:39














    1












    1








    1






    I would use Styled Components instead. There you can pass your styling by props



    https://www.styled-components.com/docs/advanced






    share|improve this answer












    I would use Styled Components instead. There you can pass your styling by props



    https://www.styled-components.com/docs/advanced







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 15:36









    weibenfalkweibenfalk

    52117




    52117












    • Or just styles defined in components
      – Sulthan
      Nov 23 '18 at 7:19










    • nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
      – Tested
      Nov 23 '18 at 7:39


















    • Or just styles defined in components
      – Sulthan
      Nov 23 '18 at 7:19










    • nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
      – Tested
      Nov 23 '18 at 7:39
















    Or just styles defined in components
    – Sulthan
    Nov 23 '18 at 7:19




    Or just styles defined in components
    – Sulthan
    Nov 23 '18 at 7:19












    nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
    – Tested
    Nov 23 '18 at 7:39




    nope it must be dynamic if i pick from color picker it must be passed from js to scss variable n override them
    – Tested
    Nov 23 '18 at 7:39













    0














    First. Just to clarify. You are not able to change SASS variables from browser. Because how it works: SASS code -> compiled into CSS -> CSS is sent from server to browser -> . So we actually should searching "how to override by JS something that was SASS variable in consistent way".



    The only way I see doing that is using CSS custom properties. Take a look into spec to understand their caveats(e.g. it cannot be used as part of size value in @media) and about support in browsers.



    I'm not really sure if SASS supports compiling variables into CSS custom properties. Take a look into css-vars mixin. With using



    $css-vars-use-native: true;


    you will get your variables exported as CSS custom properties. Unfortunately it means you need to change you existing styles to use var() from mixin for variables you want being able to override later



    Then your code will be able to override any of custom properties as easy as



    document.body.style.setProperty('--primaryColor', myColorValueFromDatePicker)


    Take a look into fine and short article on how to change custom properties with JS



    NB since custom properties uses the same cascade approach as any CSS you additional get ability to apply changed value on any part of DOM:



    document.querySelector('#previewBlock').style.setProperty(....);





    share|improve this answer


























      0














      First. Just to clarify. You are not able to change SASS variables from browser. Because how it works: SASS code -> compiled into CSS -> CSS is sent from server to browser -> . So we actually should searching "how to override by JS something that was SASS variable in consistent way".



      The only way I see doing that is using CSS custom properties. Take a look into spec to understand their caveats(e.g. it cannot be used as part of size value in @media) and about support in browsers.



      I'm not really sure if SASS supports compiling variables into CSS custom properties. Take a look into css-vars mixin. With using



      $css-vars-use-native: true;


      you will get your variables exported as CSS custom properties. Unfortunately it means you need to change you existing styles to use var() from mixin for variables you want being able to override later



      Then your code will be able to override any of custom properties as easy as



      document.body.style.setProperty('--primaryColor', myColorValueFromDatePicker)


      Take a look into fine and short article on how to change custom properties with JS



      NB since custom properties uses the same cascade approach as any CSS you additional get ability to apply changed value on any part of DOM:



      document.querySelector('#previewBlock').style.setProperty(....);





      share|improve this answer
























        0












        0








        0






        First. Just to clarify. You are not able to change SASS variables from browser. Because how it works: SASS code -> compiled into CSS -> CSS is sent from server to browser -> . So we actually should searching "how to override by JS something that was SASS variable in consistent way".



        The only way I see doing that is using CSS custom properties. Take a look into spec to understand their caveats(e.g. it cannot be used as part of size value in @media) and about support in browsers.



        I'm not really sure if SASS supports compiling variables into CSS custom properties. Take a look into css-vars mixin. With using



        $css-vars-use-native: true;


        you will get your variables exported as CSS custom properties. Unfortunately it means you need to change you existing styles to use var() from mixin for variables you want being able to override later



        Then your code will be able to override any of custom properties as easy as



        document.body.style.setProperty('--primaryColor', myColorValueFromDatePicker)


        Take a look into fine and short article on how to change custom properties with JS



        NB since custom properties uses the same cascade approach as any CSS you additional get ability to apply changed value on any part of DOM:



        document.querySelector('#previewBlock').style.setProperty(....);





        share|improve this answer












        First. Just to clarify. You are not able to change SASS variables from browser. Because how it works: SASS code -> compiled into CSS -> CSS is sent from server to browser -> . So we actually should searching "how to override by JS something that was SASS variable in consistent way".



        The only way I see doing that is using CSS custom properties. Take a look into spec to understand their caveats(e.g. it cannot be used as part of size value in @media) and about support in browsers.



        I'm not really sure if SASS supports compiling variables into CSS custom properties. Take a look into css-vars mixin. With using



        $css-vars-use-native: true;


        you will get your variables exported as CSS custom properties. Unfortunately it means you need to change you existing styles to use var() from mixin for variables you want being able to override later



        Then your code will be able to override any of custom properties as easy as



        document.body.style.setProperty('--primaryColor', myColorValueFromDatePicker)


        Take a look into fine and short article on how to change custom properties with JS



        NB since custom properties uses the same cascade approach as any CSS you additional get ability to apply changed value on any part of DOM:



        document.querySelector('#previewBlock').style.setProperty(....);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 8:00









        skyboyerskyboyer

        3,33611128




        3,33611128






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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.





            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%2fstackoverflow.com%2fquestions%2f53414299%2fcan-we-override-scss-variables-vai-react-propsis-it-possible%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

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...