refactor(header/notice): convert JS to stimulus
This commit is contained in:
parent
a2c32b44c0
commit
55fd4307a1
5 changed files with 18 additions and 24 deletions
|
@ -1,9 +1,9 @@
|
||||||
.fr-notice.fr-notice--info
|
.fr-notice.fr-notice--info{ "data-dsfr-header-target": "notice" }
|
||||||
.fr-container
|
.fr-container
|
||||||
.fr-notice__body
|
.fr-notice__body
|
||||||
%p.fr-notice__title
|
%p.fr-notice__title
|
||||||
= title
|
= title
|
||||||
|
|
||||||
- if closable?
|
- if closable?
|
||||||
%button.fr-btn--close.fr-btn{ title: t('.close_notice'), onclick: 'javascript:DS.closeNoticeInfo(event)' }
|
%button.fr-btn--close.fr-btn{ title: t('.close_notice'), data: { action: "dsfr-header#closeNotice" } }
|
||||||
= t('.close_notice')
|
= t('.close_notice')
|
||||||
|
|
13
app/javascript/controllers/dsfr_header_controller.ts
Normal file
13
app/javascript/controllers/dsfr_header_controller.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { ApplicationController } from './application_controller';
|
||||||
|
|
||||||
|
export class DSFRHeaderController extends ApplicationController {
|
||||||
|
static targets = ['notice'];
|
||||||
|
|
||||||
|
declare readonly noticeTarget: HTMLElement;
|
||||||
|
|
||||||
|
closeNotice() {
|
||||||
|
this.noticeTarget.parentNode?.removeChild(this.noticeTarget);
|
||||||
|
|
||||||
|
this.element.classList.remove('fr-header__with-notice-info');
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,8 +37,6 @@ import {
|
||||||
showNewAccountPasswordConfirmation
|
showNewAccountPasswordConfirmation
|
||||||
} from '../new_design/fc-fusion';
|
} from '../new_design/fc-fusion';
|
||||||
|
|
||||||
import { closeNoticeInfo } from '../new_design/header';
|
|
||||||
|
|
||||||
const application = Application.start();
|
const application = Application.start();
|
||||||
registerControllers(application);
|
registerControllers(application);
|
||||||
|
|
||||||
|
@ -54,8 +52,7 @@ const DS = {
|
||||||
showNewAccountPasswordConfirmation,
|
showNewAccountPasswordConfirmation,
|
||||||
replaceSemicolonByComma,
|
replaceSemicolonByComma,
|
||||||
acceptEmailSuggestion,
|
acceptEmailSuggestion,
|
||||||
discardEmailSuggestionBox,
|
discardEmailSuggestionBox
|
||||||
closeNoticeInfo
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start Rails helpers
|
// Start Rails helpers
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
export function closeNoticeInfo(event) {
|
|
||||||
// DSFR usptream code
|
|
||||||
const notice = event.target.parentNode.parentNode.parentNode;
|
|
||||||
notice.parentNode.removeChild(notice);
|
|
||||||
|
|
||||||
// Update class accordingly because
|
|
||||||
// header style is slightly different with or without notice
|
|
||||||
if (document.querySelector) {
|
|
||||||
const klass = 'fr-header__with-notice-info';
|
|
||||||
const header = document.querySelector('.' + klass);
|
|
||||||
|
|
||||||
if (header) {
|
|
||||||
header.classList.remove(klass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@
|
||||||
- is_expert_context = nav_bar_profile == :expert && expert_signed_in?
|
- is_expert_context = nav_bar_profile == :expert && expert_signed_in?
|
||||||
- is_user_context = nav_bar_profile == :user
|
- is_user_context = nav_bar_profile == :user
|
||||||
- is_search_enabled = [params[:controller] == 'recherche', is_instructeur_context, is_expert_context, is_user_context && current_user.dossiers.count].any?
|
- is_search_enabled = [params[:controller] == 'recherche', is_instructeur_context, is_expert_context, is_user_context && current_user.dossiers.count].any?
|
||||||
%header{ class: ["fr-header", content_for?(:notice_info) && "fr-header__with-notice-info"], role: "banner" }
|
%header{ class: ["fr-header", content_for?(:notice_info) && "fr-header__with-notice-info"], role: "banner", "data-controller": "dsfr-header" }
|
||||||
.fr-header__body
|
.fr-header__body
|
||||||
.fr-container
|
.fr-container
|
||||||
.fr-header__body-row
|
.fr-header__body-row
|
||||||
|
@ -101,5 +101,5 @@
|
||||||
- if current_user.expert && current_expert.avis_summary[:total] > 0
|
- if current_user.expert && current_expert.avis_summary[:total] > 0
|
||||||
= render partial: 'layouts/header/avis_tab', locals: { current_expert: current_expert }
|
= render partial: 'layouts/header/avis_tab', locals: { current_expert: current_expert }
|
||||||
|
|
||||||
= yield(:notice_info)
|
= yield(:notice_info)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue