epfl-si / elements

Charte graphique Web EPFL
https://epfl-si.github.io/elements
22 stars 12 forks source link

Streamline data and state management #611

Open domq opened 1 year ago

domq commented 1 year ago

Like every program of some size, the JavaScript code in epfl-elements takes a number of parameters and manages state.

Right now, the following flavors of parameters and state are used:

We might want to provide uniformity here.

domq commented 1 year ago

Since the data-foo use cases enable declarative (JavaScript-free) use-cases, and they are parameters (inbound) only, they should probably stay the way they are.

Since we already have a $.fn.epflElements, this sounds like as good a place as any to start. We propose to make the following getters / setters work:

const svgPath = $('body').epflElements("svgPath");
$('body').epflElements("svgPath", "/icons/foo.svg");

const consented = $('body').epflElements("cookieConsent");
$('body').epflElements("cookieConsent", "notRequired");

The latter would address #610.

In addition to (or instead of) that, we could turn window.svgPath, window.featherSvgPath and window.cookieconsent into data-epfl-elements-icons-uri, data-epfl-elements-feather-icons-uri and data-epfl-cookieconsent attributes of the <body> tag, respectively.