Active-CSS / active-css

The epic event-driven browser language for UI with functionality in one-liner CSS. Over 100 incredible CSS commands for DOM manipulation, ajax, reactive variables, single-page application routing, and lots more. Could CSS be the JavaScript framework of the future?
https://activecss.org
Other
41 stars 7 forks source link

New toggle-take-class command #326

Closed bob2517-whiteline closed 10 months ago

bob2517-whiteline commented 1 year ago

Proposed example syntax (with a sample example scope):

mySelector:click {
    toggle-take-class: .aDisplayClass scope(& < table);
}

It's either going to be that syntax or this (I need to try it out and see which one feels more intuitive - there are arguments for both syntaxes):

mySelector:click {
    take-class: .aDisplayClass scope(& < table) toggle;
}

This command will either act like the take-class command and take the class from all other elements within the optional specified scope, but if the class is already there on the element being clicked or mouseovered, or whatever, it just removes it from the element.

The issue with the second syntax example, just adding it to the take-class command, is that it hides the option from a glance over the commands available, so to that degree it might get missed by devs looking for something like it. It doesn't have full "readability clarity". So I'm leaning towards making both syntaxes work, and having the docs for toggle-take-class point to the shorthand take-class command docs. Internally the code will run "take-class" and the code for the toggle will be in there. But personally I'd rather use the toggle-take-class command in config because it's easier to read and search for in my text editor.

bob2517-whiteline commented 1 year ago

Note to self: While my mind is on it, a couple of other ideas for commands that would make DOM manipulation a bit easier for toggly-type scenarios - replace-class: .oneClass with .twoClass, toggle-replace-class: .oneClass .twoClass, toggle-content-after: "cheese" "bread"; (for toggling content used after/before an element - I dunno if it's possible to manipulate this in JS - could be good though - would have replace-content-after replace-content-beforecommands to go along with that).

bob2517 commented 11 months ago

toggle-take-class now on 2.14.0 branch.

bob2517 commented 10 months ago

Closing in preparation for release.