form: make the radio button larger and hoverable

As a bonus, the implementation of vertical radio buttons is now closer
from the default horizontal one.
This commit is contained in:
Pierre de La Morinerie 2020-02-10 18:16:00 +00:00
parent f42977e40a
commit 1531b69f5a
3 changed files with 71 additions and 34 deletions

View file

@ -70,26 +70,21 @@
visibility: visible; visibility: visible;
} }
// Align checkboxes on the top-left side of the label // Move checkbox to the top-left side of the label
&.editable-champ-checkbox, &.editable-champ-checkbox,
&.editable-champ-radio.vertical,
&.editable-champ-engagement { &.editable-champ-engagement {
p, p,
label { label {
padding-left: 28px; padding-left: 28px;
} }
input[type=checkbox], input[type=checkbox] {
input[type=radio] {
position: absolute; position: absolute;
top: 3px; top: 3px;
left: 0px; left: 0px;
} }
}
// When the (eventual) notice is displayed after the input, give it some bottom margin // When an (eventual) notice is displayed after the input, give it some bottom margin.
&.editable-champ-checkbox,
&.editable-champ-engagement {
.notice { .notice {
margin-bottom: $default-fields-spacer; margin-bottom: $default-fields-spacer;
} }
@ -97,13 +92,58 @@
} }
.radios { .radios {
display: flex;
// Horizontal layout (default)
flex-direction: row;
align-items: flex-start;
label { label {
display: inline; margin-right: $default-padding;
margin-left: $default-padding; }
// Vertical layout
&.vertical {
flex-direction: column;
align-items: stretch;
label {
margin-right: 0;
}
}
label {
padding: $default-padding $default-padding $default-padding $default-spacer;
border: 1px solid $border-grey;
border-radius: 4px;
font-weight: normal;
background: $white;
user-select: none;
&:last-of-type {
margin-bottom: $default-fields-spacer;
}
&:hover {
background: $light-grey;
cursor: pointer;
}
&:active {
border-color: darken($border-grey, 10);
}
&:first-child { &:first-child {
margin-left: 0; margin-left: 0;
} }
input[type=radio] {
margin-bottom: 0;
}
.notice {
margin: 4px 0 0 27px;
}
} }
} }
@ -190,16 +230,14 @@
input[type=radio] { input[type=radio] {
@extend %outline; @extend %outline;
margin-left: 5px; // Firefox tends to display some controls smaller than other browsers.
margin-right: 4px;
margin-bottom: $default-fields-spacer;
}
input[type=checkbox] {
// Firefox tends to display checkbox controls smaller than other browsers.
// Ensure a consistency of size between browsers. // Ensure a consistency of size between browsers.
width: 16px; width: 16px;
height: 16px; height: 16px;
margin-left: 5px;
margin-right: 4px;
margin-bottom: $default-fields-spacer;
} }
input[type=date] { input[type=date] {

View file

@ -78,18 +78,17 @@
- if !@procedure.locked? - if !@procedure.locked?
%h2.header-section À qui sadresse ma démarche ? %h2.header-section À qui sadresse ma démarche ?
.editable-champ.editable-champ-radio.vertical .radios.vertical
= f.label :for_individual, value: true do = f.label :for_individual, value: true do
= f.radio_button :for_individual, true
Ma démarche sadresse à un particulier Ma démarche sadresse à un particulier
%p.notice En choisissant cette option, lusager devra renseigner son nom et prénom avant daccéder au formulaire %p.notice En choisissant cette option, lusager devra renseigner son nom et prénom avant daccéder au formulaire
= f.radio_button :for_individual, true
.editable-champ.editable-champ-radio.vertical
= f.label :for_individual, value: false do = f.label :for_individual, value: false do
= f.radio_button :for_individual, false
Ma démarche sadresse à une personne morale Ma démarche sadresse à une personne morale
%p.notice %p.notice
En choisissant cette option, lusager devra renseigner son n° SIRET.<br>Grâce à lAPI Entreprise, les informations sur la personne morale (raison sociale, adresse du siège, etc.) seront automatiquement renseignées. En choisissant cette option, lusager devra renseigner son n° SIRET.<br>Grâce à lAPI Entreprise, les informations sur la personne morale (raison sociale, adresse du siège, etc.) seront automatiquement renseignées.
= f.radio_button :for_individual, false
%p.explication %p.explication
Si votre démarche sadresse indifféremment à une personne morale ou un particulier, choisissez l'option « Particuliers ». Vous pourrez ajouter un champ SIRET directement dans le formulaire. Si votre démarche sadresse indifféremment à une personne morale ou un particulier, choisissez l'option « Particuliers ». Vous pourrez ajouter un champ SIRET directement dans le formulaire.

View file

@ -52,16 +52,16 @@
%label Mot de passe %label Mot de passe
%input{ type: "password", value: "12345678" } %input{ type: "password", value: "12345678" }
%h2.header-section Bouton radio verticaux %h3.header-subsection Bouton radio verticaux
.editable-champ.editable-champ-radio.vertical .radios.vertical
= f.label :archived, 'Option A', value: true = f.label :archived, value: true do
%p.notice Une option tout à fait valable.
= f.radio_button :archived, true = f.radio_button :archived, true
Option A
.editable-champ.editable-champ-radio.vertical %p.notice Une option tout à fait valable.
= f.label :archived, 'Option B', value: false = f.label :archived, value: false do
%p.notice Une autre option, pas mal non plus.
= f.radio_button :archived, false = f.radio_button :archived, false
Option B
%p.notice Une autre option, pas mal non plus.
.send-wrapper .send-wrapper
= f.submit 'Enregistrer un brouillon (formnovalidate)', formnovalidate: true, class: 'button send' = f.submit 'Enregistrer un brouillon (formnovalidate)', formnovalidate: true, class: 'button send'