I want to be able to conditionally add some styling depending on a particular typescript variable in a layout or component.
For example, say I have a boolean const redTitles = true in a Base.astro layout.
I want to be able to write some SCSS (not just plain CSS) that only activates when this variable is true. So far I've tried these two approaches:
---
const redTitles = true
---
{redTitles && <style lang="scss">
main {
h1, h2, h3, h4, h5, h6 {
color: red;
}
}
</style>}
This just puts the raw style tag with lang="scss" and without transpiling the code to css into the final html page, and of course since it's scss and not css it doesn't work.
I've also tried this:
---
const redTitles = true
---
<style lang="scss" define:vars={{hasRedTitles: redTitles}}>
@if $hasRedTitles {main {
h1, h2, h3, h4, h5, h6 {
color: red;
}
}}
</style>
This just errors out, the scss compiler says that there is no variable called hasRedTitles.