materializecss / materialize

Materialize, a web framework based on Material Design
https://materializeweb.com/
MIT License
913 stars 105 forks source link

Creating Components via JavaScript #466

Closed wuda-io closed 2 months ago

wuda-io commented 7 months ago

Before submitting...

Context

Parsing components from the DOM Tree is at the moment the only direction to go. What do you think of the other direction, and create Components via JS. Also we can then make like Configurators for each Component in the Documentation. What do you think? I will try to inplement a proof of concept for the Button Component soon.

First i thought to implement this via webcomponents, but i think it should always work without javascript too. And as far as i know, webcomponents do not work without JS. So this would be a good compromise i think.

Looking forward for your feedback! Thank you guys

Current Behavior

Only parsing components from the Dom is possible.

Expected behavior

Going both directions would be awesome. Parsing from Dom and creating Dom Elements.

Possible Solutions or Causes

const btn = M.Button.create();

Your Environment

warrenspe commented 7 months ago

It's funny because I often find myself irked when I need to access some bit of configuration (like accordion mode for collapsibles) that can only be accessed by initializing an element via JS; where there's no way to set it via the DOM.

But I'm sure that some folks would find this useful

wuda-io commented 7 months ago

Hey, thanks for your comment. Yes, the current process via initializing it after the html is a bit complicated and often creates additional confusion. I think of it in 2 ways:

  1. parsing/init from the DOM and reconfigurating
  2. Creating DOMElements from JS Side I think it also would be cool for generating Templates.
danice commented 7 months ago

Some thoughts:

I think we should be very cautious with webcomponents, as they completely change the look of html. Most of materialize components could be thought as extesions of existing html elements as \

wuda-io commented 7 months ago

@danice yes, I mean to not use webcomponents at all, just to generate the html for the Components via Js.

The problem with webcomponents is, that we depend on JS, so thats not what we should aim for. We should always prefer a CSS Solution over JS.

So i mean an opposite of the Init function. Like a Create function or so.