Inwerpsel / use-theme-editor

A React theme editor
GNU General Public License v3.0
4 stars 0 forks source link

A general way to force elements into hover/focus/active/... state #31

Open Inwerpsel opened 1 year ago

Inwerpsel commented 1 year ago

Some styles only apply to these states which currently have to be triggered by doing the corresponding interaction in the frame. As a result, you cannot quickly make changes and preview them, you have to go back and forth.

Previously, a solution for this was included, however it was not a general solution: it only worked for custom properties, and they had to have a specific naming scheme. The related code was preserved partially as a comment because it still gives a good idea of the intended behavior.

With the CSS parser almost ready, it should become possible to trigger these states in a reliable way for all CSS.

To do this, the relevant CSS rules can be adapted to change any instance of :hover with :is(:hover,._force-hover) (same for other states). See https://github.com/Inwerpsel/use-theme-editor/blob/8ec7c5a71ea9d2c78ce846228dca4f330c575d7e/src/functions/parseCss.js#L443

Then, hovering any style property that applies only to such state, would result in a message sent to the frame to add the forced class to the inspected element and/or its parents.

Open questions

Where to add the classes?

A few options:

The first options seems best if there's no significant performance impact.