dropdown: refactor to make the button an actual button

This commit is contained in:
Pierre de La Morinerie 2018-09-11 17:51:44 +02:00 committed by Paul Chavard
parent 3ede25e1b0
commit cd938b4c36
16 changed files with 92 additions and 86 deletions

View file

@ -6,6 +6,7 @@
padding: 8px 16px;
border-radius: 30px;
border: 1px solid $border-grey;
font-family: "Muli";
font-size: 14px;
line-height: 20px;
background-color: #FFFFFF;
@ -113,9 +114,20 @@
margin-right: $default-spacer;
}
&.dropdown {
position: relative;
&.icon-only {
padding: 9px 16px;
.icon {
margin-right: 0;
}
}
}
.dropdown {
display: inline-block;
position: relative;
.dropdown-button {
&::after {
content: "";
margin-left: $default-spacer;
@ -128,24 +140,14 @@
color: $blue;
}
}
.dropdown-content {
display: none;
}
&.open {
.dropdown-content {
display: block;
}
}
}
&.icon-only {
padding: 9px 16px;
.dropdown-content {
display: none;
}
.icon {
margin-right: 0;
}
&.open .dropdown-content {
display: block;
}
}

View file

@ -159,6 +159,19 @@ $landing-breakpoint: 1040px;
}
}
.header-menu-button {
border: none;
padding: 0;
&:hover {
background: none;
}
&::after {
display: none;
}
}
.header-menu {
display: none;
position: absolute;

View file

@ -1,13 +0,0 @@
import $ from 'jquery';
$(document).on('click', 'body', () => {
$('.button.dropdown').removeClass('open');
});
$(document).on('click', '.button.dropdown', event => {
event.stopPropagation();
const $target = $(event.target);
if ($target.hasClass('button', 'dropdown')) {
$target.toggleClass('open');
}
});

View file

@ -1,10 +0,0 @@
import $ from 'jquery';
$(document).on('click', 'body', () => {
$('.print-menu').removeClass('open fade-in-down');
});
export function togglePrintMenu(event) {
event.stopPropagation();
$('.print-menu').toggleClass('open fade-in-down');
}

View file

@ -0,0 +1,19 @@
import Rails from 'rails-ujs';
const { delegate } = Rails;
delegate(document, 'body', 'click', event => {
if (!event.target.closest('.dropdown')) {
[...document.querySelectorAll('.dropdown')].forEach(element =>
element.classList.remove('open', 'fade-in-down')
);
}
});
delegate(document, '.dropdown-button', 'click', event => {
event.stopPropagation();
const parent = event.target.closest('.dropdown-button').parentElement;
if (parent.classList.contains('dropdown')) {
parent.classList.toggle('open');
}
});

View file

@ -1,10 +0,0 @@
import $ from 'jquery';
$(document).on('click', 'body', () => {
$('.header-menu').removeClass('open fade-in-down');
});
export function toggleHeaderMenu(event) {
event.stopPropagation();
$('.header-menu').toggleClass('open fade-in-down');
}

View file

@ -13,7 +13,7 @@ import '../shared/autocomplete';
import '../shared/remote-input';
import '../new_design/spinner';
import '../new_design/buttons';
import '../new_design/dropdown';
import '../new_design/form-validation';
import '../new_design/carto';
import '../new_design/select2';
@ -21,8 +21,6 @@ import '../new_design/select2';
import '../new_design/champs/linked-drop-down-list';
import { toggleCondidentielExplanation } from '../new_design/avis';
import { togglePrintMenu } from '../new_design/dossier';
import { toggleHeaderMenu } from '../new_design/header';
import { scrollMessagerie } from '../new_design/messagerie';
import { showMotivation, motivationCancel } from '../new_design/state-button';
import { toggleChart } from '../new_design/toggle-chart';
@ -30,8 +28,6 @@ import { toggleChart } from '../new_design/toggle-chart';
// This is the global application namespace where we expose helpers used from rails views
const DS = {
toggleCondidentielExplanation,
togglePrintMenu,
toggleHeaderMenu,
scrollMessagerie,
showMotivation,
motivationCancel,

View file

@ -1,10 +1,11 @@
%span.button.dropdown.invite-user-action
%span.icon.person
- if dossier.invites.count > 0
Voir les personnes invitées
%span.badge= dossier.invites.count
- else
Inviter une personne à modifier ce dossier
%span.dropdown.invite-user-action
%button.button.dropdown-button
%span.icon.person
- if dossier.invites.count > 0
Voir les personnes invitées
%span.badge= dossier.invites.count
- else
Inviter une personne à modifier ce dossier
.dropdown-content.fade-in-down
= render partial: "invites/form", locals: { dossier: dossier }

View file

@ -57,9 +57,10 @@
- if gestionnaire_signed_in? || user_signed_in?
%li
.header-menu-opener
= image_tag "icons/account-circle.svg", onclick: "javascript:DS.toggleHeaderMenu(event);", title: "Mon compte"
%ul.header-menu
%span.dropdown.header-menu-opener
%button.button.dropdown-button.header-menu-button
= image_tag "icons/account-circle.svg", title: "Mon compte"
%ul.header-menu.dropdown-content
%li
.menu-item{ title: current_email }
= current_email

View file

@ -7,13 +7,14 @@
%li
= "Dossier nº #{dossier.id}"
.mixed-buttons-bar
.button.dropdown.icon-only.print-menu-opener{ onclick: "javascript:DS.togglePrintMenu(event);" }
%span.icon.printer
%ul.print-menu
%span.dropdown.print-menu-opener
%button.button.dropdown-button.icon-only
%span.icon.printer
%ul.print-menu.dropdown-content
%li
= link_to "Tout le dossier", print_gestionnaire_dossier_path(dossier.procedure, dossier), target: "_blank", class: "menu-item menu-link"
%li
= link_to "Uniquement cet onglet", "#", onclick: "DS.togglePrintMenu; window.print()", class: "menu-item menu-link"
= link_to "Uniquement cet onglet", "#", onclick: "window.print()", class: "menu-item menu-link"
= render partial: "new_gestionnaire/procedures/dossier_actions", locals: { procedure: dossier.procedure, dossier: dossier, dossier_is_followed: current_gestionnaire&.follow?(dossier) }
= render partial: "state_button", locals: { dossier: dossier }

View file

@ -1,6 +1,7 @@
- if dossier.en_construction? || dossier.en_instruction?
%span.button.primary.dropdown
= dossier.decorate.display_state
%span.dropdown
%button.button.primary.dropdown-button
= dossier.decorate.display_state
.dropdown-content.fade-in-down
%ul.dropdown-items
- if dossier.en_construction?
@ -49,8 +50,9 @@
- else
- if dossier.motivation.present? || dossier.attestation.present?
%span.button.dropdown{ class: button_or_label_class(dossier) }
= dossier.statut
%span.dropdown
%button.button.dropdown-button{ class: button_or_label_class(dossier) }
= dossier.statut
.dropdown-content.fade-in-down.terminated
- if dossier.motivation.present?
%h4 Motivation

View file

@ -1,6 +1,7 @@
- if procedure.dossiers.state_not_brouillon.any?
%span.button.dropdown
Télécharger tous les dossiers
%span.dropdown
%button.button.dropdown-button
Télécharger tous les dossiers
.dropdown-content.fade-in-down
%ul.dropdown-items
%li

View file

@ -43,8 +43,9 @@
.container
- if @dossiers.present? || @current_filters.count > 0
%span.button.dropdown
Filtrer
%span.dropdown
%button.button.dropdown-button
Filtrer
.dropdown-content.left-aligned.fade-in-down
= form_tag add_filter_gestionnaire_procedure_path(@procedure), method: :post, class: 'dropdown-form large' do
= label_tag :field, "Colonne"
@ -78,8 +79,9 @@
= render partial: "header_field", locals: { field: { "label" => "Statut", "table" => "self", "column" => "state" }, classname: "status-col" }
%th.follow-col
%span.button.dropdown
Personnaliser
%span.dropdown
%button.button.dropdown-button
Personnaliser
.dropdown-content.fade-in-down
= form_tag update_displayed_fields_gestionnaire_procedure_path(@procedure), method: :patch, class: 'dropdown-form columns-form' do
= select_tag :values,

View file

@ -13,8 +13,9 @@
= link_to "Télécharger", pj.content_url, class: "link", target: :blank
- if pjs.present?
%br
%span.button.dropdown
anciennes versions
%span.dropdown
%button.button.dropdown-button
anciennes versions
.dropdown-content.fade-in-down
%ul.dropdown-items
- pjs.each do |pj|

View file

@ -82,23 +82,23 @@ feature "procedure filters" do
end
def add_filter(column_name, filter_value)
find(:xpath, "//span[contains(text(), 'Filtrer')]").click
click_on 'Filtrer'
select column_name, from: "Colonne"
fill_in "Valeur", with: filter_value
click_button "Ajouter le filtre"
end
def add_column(column_name)
find(:xpath, "//span[contains(text(), 'Personnaliser')]").click
click_on 'Personnaliser'
find("span.select2-container").click
find(:xpath, "//li[text()='#{column_name}']").click
click_button "Enregistrer"
end
def remove_column(column_name)
find(:xpath, "//span[contains(text(), 'Personnaliser')]").click
click_on 'Personnaliser'
find(:xpath, "//li[contains(@title, '#{column_name}')]/span[contains(text(), '×')]").click
find(:xpath, "//span[contains(text(), 'Personnaliser')]//span[contains(@class, 'select2-container')]").click
find(:xpath, "//form[contains(@class, 'columns-form')]//span[contains(@class, 'select2-container')]").click
click_button "Enregistrer"
end
end

View file

@ -178,7 +178,7 @@ feature 'Invitations' do
end
def send_invite_to(invited_email)
find('.button.invite-user-action').click()
click_on "Inviter une personne à modifier ce dossier"
expect(page).to have_button("Envoyer une invitation", visible: true)
fill_in 'invite_email', with: invited_email