Volumetrics-io / mrjs

An extensible WebComponents library for the Spatial Web
https://mrjs.io
MIT License
148 stars 9 forks source link

add ability to access `:root` css variables #605

Closed hanbollar closed 2 months ago

hanbollar commented 2 months ago

Linking

Fix https://github.com/Volumetrics-io/mrjs/issues/594

Problem

cant access css root var

Solution

make a way to access css root var

Breaking Change

nope

Notes

see https://github.com/Volumetrics-io/mrjs/pull/605#issuecomment-2089379516


Required to Merge

render[bot] commented 2 months ago

Your Render PR Server URL is https://examples-mrjs-pr-605.onrender.com.

Follow its progress at https://dashboard.render.com/static/srv-copeohi0si5c739a0v2g.

hanbollar commented 2 months ago

@michaelthatsit vvv

this does add a utils function --> is there a better way to add this in for users instead of a one-off-function, but still allow use with threejs?

the biggest issue is the setStyle function going directly to threejs, so we'd need an in between grabber, which leads to the need for the function anyway

lmk your thoughts ~

hanbollar commented 2 months ago

demo of it working is if you click on the change color button on the main index - it changes from the default color of the button to a specified var

Screenshot 2024-05-01 at 6 30 45 PM
document.querySelector("#button").style.backgroundColor = mrjsUtils.css.getVarFromRoot('--accent');

i'll remove this addition before closing ^^^

michaelthatsit commented 2 months ago

@hanbollar I'm confused as to what this resolves but it looks good.

Does compStyle note resolve colors set via :root variables? It should.

hanbollar commented 2 months ago

@hanbollar I'm confused as to what this resolves but it looks good.

Does compStyle note resolve colors set via :root variables? It should.

@michaelthatsit oh yea it does, that's why im using the getComputedStyle function

it's just that mr-entity.compStyle stored variable will only show the inherited items and items of that mr-entity (ie ones that are already css parameters like root's padding, margin, etc)

but it wont show the new variables a user can create in :root for future use (like in this case --accent or --nav) since those are handled directly by html/css to already convert them from --item to value using var(--item) within the css directly

[[sanity checked by visually reading through items of the following in the sample: console.log(document.querySelector("#button").compStyle);]]

Clearer explanation: this pr is to create a way to access the :root directly s.t. you can access the key:map of variable names to values for use of the css within the js more clearly.

lmk if this makes sense ~

hanbollar commented 2 months ago

related to #612 - do we want this to be a bigger feature or small one-off is fine