what is the scope of style variables?

  • /attachments/1453524356125692028/1453524357912596715/image.png

    Ben H

    15 days ago

    can someone clarify the expected scope of style variables?

    i declared some style variables at the root element of the page i'm working in. inside that root div, i can see them available in the style panel as expected. however, in children of this div, sometimes they seem available and sometimes not.

    for example, inside one child component, referencing --font-color works as expected.

    however, in a different child component, referencing --font-color-secondary is not working.

    are there rules regarding where these declared style variables can be used?
    image.png
    image.png
    image.png
  • what is the scope of style variables?
  • Jacob Kofoed

    14 days ago

    We are working on a new version of CSS variables that will release very soon. In the new version you can declare variables globally, making them available everywhere.

    However, if not declared globally the variables are only available inside a component (this is how the current system works, always). The reason that you do not see the variable in sub-components is that the component has no way of knowing who their parent may be, as a component may be used by multiple parent elements. At compile-time, a component knows its children, but not parents, so we cannot show the inherited variables in the dropdown.

    In addition to defining variables globally, the new CSS variable system has other options to declare what variables a component should be able to use. We will write documentation on this before release 🙂
    🤶1
  • I cannot explain why it seems to sometimes be available and sometimes not in your examples though 🤔
    🎅1
  • Ben H

    14 days ago

    Thanks Jacob! That confirms my understanding - my CSS variables declared in the root div of my page should be available to all child components (just not the dropdown menus in the UI). Must be a bug in my code then 🙂 (edit: can confirm was me being dumb again)
  • Ben H

    14 days ago

    New global variables sound cool too but I think for my use case page-scoped variables are most appropriate

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.