Notice pattern evolution

Created on 16 April 2024, about 1 year ago

Our functional team requests that upon clicking the notice close button, it should save to prevent it from reappearing when changing pages.

Steps to reproduce

When i place my notice block, upon clicking, the notice closes, but upon changing the page, it reappears.

Proposed resolution

I propose modifications to the twig as follows :
{% set variant = variant|default('info') %}

{% if isBlock %}
{% set block_id = 'fr-notice--block-id' %}
{% else %}
{% set block_id = 'fr-notice--' ~ random() %}
{% endif %}

{% if title %}
{{ title }}

{% endif %}
{% if dismissible %}
{% set close_title = close_title|default('Close'|t) %}
{% set event = "const notice = this.parentNode.parentNode.parentNode; notice.parentNode.removeChild(notice); sessionStorage.setItem('is>

{{ close_title }}

{% endif %}

OR

{% set variant = variant|default('info') %}

{% if title %}
{{ title }}

{% endif %}
{% if dismissible %}
{% set close_title = close_title|default('Close'|t) %}
{% set event = "const notice = this.parentNode.parentNode.parentNode; notice.parentNode.removeChild(notice); sessionStorage.setItem('is>

{{ close_title }}

{% endif %}

and the .yml like this :

notice:
label: Notice
description: Draws the user's attention to information without interrupting his current task. https://www.systeme-de-design.gouv.fr/element>
variants:
info:
label: Information
settings:
block_id:
type: token
label: ID
description: "Must start with a letter. Randomly generated if empty."
dismissible:
type: boolean
label: Dismissible?
description: It’s possible to dismiss any notice inline.
preview: true
isBlock:
type: boolean
label: Block?
description: If true, the notice will be assigned a predefined, hard-coded ID attribute.
preview: false
close_title:
type: token
label: Close button text
description: Optional. Will be used only if notice is dismissible.
preview: Hide message
fields:
title:
type: text
label: Title
preview: "Notice: Title of an notice"

OR

notice:
label: Notice
description: Draws the user's attention to information without interrupting his current task. https://www.systeme-de-design.gouv.fr/element>
variants:
info:
label: Information
settings:
dismissible:
type: boolean
label: Dismissible?
description: It’s possible to dismiss any notice inline.
preview: true
isBlock:
type: boolean
label: Block?
description: If true, the notice will be assigned a predefined, hard-coded ID attribute.
preview: false
close_title:
type: token
label: Close button text
description: Optional. Will be used only if notice is dismissible.
preview: Hide message
fields:
title:
type: text
label: Title
preview: "Notice: Title of an notice"

AND add a JasavaScript script:

document.addEventListener ('DOMContentLoaded', function() {

let noticeContainer = document.getElementById ('fr-notice--block-id');

if (noticeContainer) {
let isClose = sessionStorage.getItem('isOpen') === 'false';
if(isClose) {
noticeContainer.remove()
}
}

});

Thank you.

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024