Replies: 3 comments 7 replies
-
aside: typically there may not be many class names used in an element at once, if we are concerned about the memory footprint of a hash map, my original idea was to use a |
Beta Was this translation helpful? Give feedback.
-
This seems good to me. I'm currently working on a css parser which will return a CSSOM but I'm not sure how we will combine the two parsers together? |
Beta Was this translation helpful? Give feedback.
-
It's often possible to cast impl ElementClass {
/// Check if class name exists
pub fn contains(&self, name: &str);
/// Add a new class (if already exists, does nothing)
pub fn add(&self, name: &str);
/// Remove a class (does nothing if not exists)
pub fn remove(&self, name: &str);
/// Toggle a class active/inactive
pub fn toggle(&self, name: &str);
/// Set explicitly if a class is active or not
pub fn set_active(&self, is_active: bool);
}
// in calling code, just an example ...
let name = "one".to_owned(); // name is String
if klass.contains(&name) {
// ...
} |
Beta Was this translation helpful? Give feedback.
-
I know there was someone interested in working on the CSS parser (not sure at what point, but also low priority right now) which made me think about the current ability to handle class names in an element.
I think the next contribution I planned to make was adding a couple utilities for checking, adding/removing classes from an element.
For instance,
This element has three classes, but we could also programmatically (through javascript later) add/remove/toggle classes.
My proposal is adding a new struct
If I'm not mistaken, in the current implementation of the parser (as of 01 Oct 23)
class
would be an attribute, so my thought is after a tag is closed (in the above example, when</div>
is reached) maybe we take the value of theclass
attribute and use that to construct theElementClass
instance which can be stored in theNode
as a propertyThen we'd be able to use it when we're trying to apply CSS classes, something like:
Are there any thoughts/suggestions/issues on this before I start the work on it?
Beta Was this translation helpful? Give feedback.
All reactions