- Issue created by @yassrzg
- Status changed to Postponed: needs info
2 months ago 2:43pm 16 April 2024 - π«π·France pdureau Paris
Hi Yassine,
That's a good idea, but:
- let's avoid a constant value in an HTML ID attribute:
{% set block_id = 'fr-notice--block-id' %}
- let's avoid using random() function outside a default() filter:
{% set block_id = 'fr-notice--' ~ random() %}
- the name of the new prop must not be
isBlock
but something likepermanent_state
, because of the expected feature
So, a proposal:
permanent_state: type: boolean label: Permanent state? description: If true, the notice will remember its state in between page reloads. Expect a non random block_id value. preview: false
The wording proposal may change.
With:
{% set block_id = block_id|default('fr-notice--' ~ random()) %} {% set attributes =attributes.setAttribute("id", block_id) %} {% set attributes = permanent_state ? attributes.setAtttibute("data-permanent-state", "true") : attributes %} <div{{ attributes.addClass('fr-notice').addClass('fr-notice--' ~ variant)}}>
So:
- Can you rebuild your script around this proposal?
- Do you think upstream DSFR will accept such a proposal?
- I will need to ask other people to validate such a proposal because we are at the limit between application state and design system.
- let's avoid a constant value in an HTML ID attribute:
- Status changed to Needs work
2 months ago 8:15am 22 April 2024 - Status changed to Needs review
2 months ago 8:18am 22 April 2024 I have adapted the JavaScript script and added a new CSS file 'notice.css'.
I initialized .fr-notice[data-permanent-state="true"] { display: none; }, to prevent the notice from flickering every time the page changes.
I added the JavaScript and CSS files to the .libraries.yml file.- π«π·France just_like_good_vibes PARIS
Hello,
I have a comment about the Javascript code added.
why a vanilla JS code instead of a proper drupal JS behavior?
The JS file is added to the global theme library, therefore in my understanding it should follow best practices β .
what do you think?
i can help in writing the code if needed.
thank you - Status changed to Needs work
about 1 month ago 5:15pm 21 May 2024 - π«π·France pdureau Paris
There are interesting talks in the Drupal community about using WebComponent (with the is attributes instead of the "custom element" syntax) to leverage WebComponents as a standard JS behaviours container where the lifecycle is managed by the browser.
Do you want to try?