Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sticky header hide and show on scroll and visible login access #72

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
06563ee
remove stiky menu mobile
ElviaBth May 21, 2024
c507c87
remove sticky menu mobile view
ElviaBth May 21, 2024
372ae8c
remove main-bar__links-mobile from spec
ElviaBth May 21, 2024
ccd1b84
fix spec lint error
ElviaBth May 21, 2024
b4ed07b
add login next to mobile menu
ElviaBth May 23, 2024
9d4dab3
apply new design for header_defautl and header_login_ photo
ElviaBth May 24, 2024
246f4f7
install stylelint
ElviaBth May 24, 2024
e25693a
create mobile_header_spec file
ElviaBth May 24, 2024
a12d869
add mobile search block
ElviaBth May 27, 2024
d821882
add trailing newline
ElviaBth May 27, 2024
c5c3b8e
remove dupliacate id
ElviaBth May 27, 2024
3644fc7
add missing tag
ElviaBth May 27, 2024
1ec12b6
add search to the menu
ElviaBth May 28, 2024
e46fd38
hide last svg when dropdown is close
ElviaBth May 28, 2024
232bfbc
add language-chooser to mobile-menu
ElviaBth May 29, 2024
86784ac
hide login when dropdown open
ElviaBth May 29, 2024
3cf1b0a
add spec to test header features
ElviaBth May 29, 2024
d931c58
Merge branch 'develop' into feature/sticky_header
ElviaBth May 29, 2024
c61a529
add trailing newlines
ElviaBth May 29, 2024
4e3ce3f
configure sticky header
ElviaBth May 30, 2024
44b7ccb
change spelling
ElviaBth May 30, 2024
9991010
change spelling
ElviaBth May 30, 2024
b8755a3
Merge remote-tracking branch 'upstream' into feature/sticky_header
ElviaBth May 30, 2024
2c9e942
remove duplicate id
ElviaBth May 30, 2024
88f6422
resolve review comments
ElviaBth May 30, 2024
6d4bf11
display flash messages
ElviaBth May 30, 2024
86dfb36
remove unused code
ElviaBth May 31, 2024
45a0b54
fix duplicated ids
ElviaBth May 31, 2024
a20d217
change ids name
ElviaBth May 31, 2024
32bba9a
check spelling
ElviaBth May 31, 2024
67c594a
check spelling
ElviaBth May 31, 2024
e27e1f8
add dinamics ids
ElviaBth May 31, 2024
a9edc2a
separate desktop and mobile dropdowns
ElviaBth May 31, 2024
13e8094
fix specs
ElviaBth May 31, 2024
d7c8da7
add guard clause for sticky header
ElviaBth Jun 1, 2024
f7d9882
adjust header width
ElviaBth Jun 3, 2024
d653521
switch of logo to favicon on mobile
ElviaBth Jun 3, 2024
a9b1ac9
display favicon when mobile
ElviaBth Jun 3, 2024
3b07126
add user_initials helper spec check
ElviaBth Jun 3, 2024
7fd3bb5
include application helper in devise_controller
ElviaBth Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions decidim-core/app/packs/src/decidim/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import "src/decidim/gallery"
import "src/decidim/direct_uploads/upload_field"
import "src/decidim/data_consent"
import "src/decidim/sw"
import "src/decidim/sticky_header"

// local deps that require initialization
import formDatePicker from "src/decidim/datepicker/form_datepicker"
Expand Down
17 changes: 17 additions & 0 deletions decidim-core/app/packs/src/decidim/sticky_header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let prevScroll = window.scrollY;
const stickyHeader = document.getElementById("sticky-header");

document.addEventListener("scroll", () => {
// if a subelement is not visible it has no offsetParent
const header = document.getElementById("main-bar").offsetParent;
if (header) {
let currentScroll = window.scrollY;
if (prevScroll > currentScroll || currentScroll < stickyHeader.offsetHeight) {
stickyHeader.style.top = 0;
} else {
stickyHeader.style.top = `-${stickyHeader.offsetHeight}px`;
console.log(header.offsetHeight);
}
prevScroll = currentScroll;
}
});
18 changes: 18 additions & 0 deletions decidim-core/app/packs/stylesheets/decidim/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
}
}

[data-target*="dropdown-menu-language-chooser"] {
& > span {
@apply block font-semibold text-black text-xs;
}

> svg {
@apply w-5 h-6 flex-none text-xs font-normal text-black fill-current;
}

& > ul {
@apply w-6 bg-gray;

> li {
@apply w-6 bg-gray;
}
}
}

.dropdown {
@apply absolute border-2 border-gray-3 rounded min-w-max p-4 drop-shadow-md text-left z-10;

Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/packs/stylesheets/decidim/_filters.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

&-search {
@apply w-full relative;
@apply w-full relative bg-gray;

input {
@apply w-full;
Expand Down
2 changes: 0 additions & 2 deletions decidim-core/app/packs/stylesheets/decidim/_footer.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
footer {
@apply mb-16 lg:mb-0;

.main-footer {
@apply bg-gray-4;

Expand Down
8 changes: 8 additions & 0 deletions decidim-core/app/packs/stylesheets/decidim/_forms.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#form-search_dropdownmenu{
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
@apply py-1.5 px-4 bg-gray-6 rounded-sm;

input[type="text"] {
@apply bg-gray-6;
}
}

.form-defaults {
/* text-like inputs */
input[type="date"],
Expand Down
88 changes: 41 additions & 47 deletions decidim-core/app/packs/stylesheets/decidim/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,32 @@ header {
}
}

#flash-messages-container {
@apply mt-28 md:mt-0;
}

#menu-bar-container {
@apply mt-24 md:mt-0;
}

&.with-admin-bar {
#flash-messages-container {
@apply mt-40 md:mt-0;
}

#menu-bar-container {
@apply mt-[140px] md:mt-0;
}
}

#sticky-header {
@apply fixed top-0 shadow-lg z-40 bg-white md:relative;

transition: top 0.3s;
}

.main-bar {
@apply container grid grid-cols-4 md:grid-cols-8 lg:grid-cols-12 gap-4 items-center py-5;
@apply container grid grid-cols-4 md:grid-cols-8 lg:grid-cols-12 gap-4 items-center py-5 h-24;

&__container {
@apply relative w-full;
Expand Down Expand Up @@ -81,10 +105,10 @@ header {
@apply fixed bottom-0 left-0 z-40 bg-white w-full px-4 py-3 flex justify-between text-secondary shadow-[0_-4px_6px_rgba(198,198,198,0.25)];

&__trigger {
@apply flex flex-col items-center text-secondary cursor-pointer p-2;
@apply flex flex-col items-center text-secondary cursor-pointer pl-4 border-l border-gray-3;

svg {
@apply w-5 h-5 fill-current;
@apply w-6 h-6 fill-current;
}

span {
Expand All @@ -96,6 +120,10 @@ header {
@apply absolute top-full left-0 z-30 bg-white;
}

&__dropdown-before {
@apply before:block before:absolute before:-top-8 before:right-12 before:content-[""] before:bg-white before:w-32 before:h-8 before:-mt-8;
}

&__account {
@apply fixed top-0 left-0 w-full h-full z-30 bg-white;

Expand All @@ -122,42 +150,17 @@ header {

&__search {
@apply fixed top-0 left-0 w-full h-full z-30 bg-white;

&-block {
@apply container h-full flex flex-col justify-center;
}

.main-bar {
@apply border-b border-gray;
}

label {
@apply block mb-4 text-black;
}

form {
@apply relative;
}
}

&__item {
@apply w-1/4 flex flex-col items-center relative;
&__login {
@apply w-20 h-full flex flex-row items-center relative text-secondary gap-1;

svg {
@apply w-8 h-8 fill-current;
@apply w-8 h-6 fill-current;
}

svg + span {
@apply text-sm first-letter:uppercase;
}

/* overwrite default dropdown styles */
&[data-target*="dropdown"] {
@apply p-0 gap-0;

> span {
@apply block font-normal text-sm first-letter:uppercase;
}
@apply text-sm first-letter:uppercase pr-4;
}
}
}
Expand All @@ -183,7 +186,7 @@ header {
}

&__avatar {
@apply block w-8 h-8 rounded-full border border-secondary overflow-hidden;
@apply block w-6 h-6 rounded-full border border-secondary overflow-hidden mr-2;

span {
@apply w-full h-full rounded-full overflow-hidden;
Expand All @@ -202,14 +205,10 @@ header {
@apply md:hidden;
}
}

[data-target*="dropdown"] {
@apply last-of-type:[&>svg]:block;
}
}

.menu-bar {
@apply container h-full flex justify-between items-center lg:relative;
@apply container h-full flex justify-between items-center lg:relative last-of-type:[&>svg]:hidden;

&__container {
@apply bg-primary relative h-14;
Expand Down Expand Up @@ -342,22 +341,17 @@ header {
}
}

&__language-chooser {
@apply absolute top-full left-0 bg-white rounded w-full bg-gray-5;
}

&__main-dropdown {
@apply bg-white divide-y divide-gray-3 rounded-b shadow-lg text-black w-full lg:w-[1280px];

&__bottom,
&__top {
@apply flex flex-col md:flex-row justify-between p-4 md:p-8 gap-x-8;

&-left {
@apply w-full md:w-1/2;

/* Overwrite default size */
.card__highlight-text {
@apply text-md;
}
}

&-right {
@apply hidden md:block md:w-1/2;
}
Expand Down
22 changes: 13 additions & 9 deletions decidim-core/app/views/layouts/decidim/_wrapper.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ end
%>

<div class="layout-container">
<header>
<%= render partial: "layouts/decidim/admin_links" if current_user&.admin %>
<%= render partial: "layouts/decidim/header/main" %>
<% if display_flash_messages.present? %>
<div class="container">
<%= display_flash_messages %>
</div>
<% end %>
<%= render partial: "layouts/decidim/header/menu" unless controller_name == "homepage" %>
<header <%= "class=with-admin-bar" if current_user&.admin %>>
<div id="sticky-header">
<%= render partial: "layouts/decidim/admin_links" if current_user&.admin %>
<%= render partial: "layouts/decidim/header/main" %>
</div>
<div id="menu-bar-container">
<% if display_flash_messages.present? %>
<div id="flash-messages-container" class="container">
<%= display_flash_messages %>
</div>
<% end %>
<%= render partial: "layouts/decidim/header/menu" unless controller_name == "homepage" %>
</div>
</header>

<div id="content" data-content>
Expand Down
29 changes: 16 additions & 13 deletions decidim-core/app/views/layouts/decidim/header/_main.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
<%= render partial: "layouts/decidim/logo", locals: { organization: current_organization } %>
</div>
<div class="main-bar__search">
<%= render partial: "layouts/decidim/header/main_search" %>
<%= render partial: "layouts/decidim/header/main_search", locals: { id: "search-mobile" } %>
</div>
<div class="main-bar__links-desktop">
<%= render partial: "layouts/decidim/header/main_links_desktop" %>
</div>

<div class="lg:hidden">
<%# Main dropdown mobile %>
<button id="main-dropdown-summary-mobile" class="main-bar__links-mobile__trigger"
data-component="dropdown"
data-target="dropdown-menu-main-mobile">
<%= icon "menu-line" %><span class="sr-only"><%= t("main_menu", scope: "layouts.decidim.header") %></span>
</button>
<div class="flex flex-row-reverse items-center">
<%# Main dropdown mobile %>
<button id="main-dropdown-summary-mobile" class="main-bar__links-mobile__trigger p-0"
data-component="dropdown"
data-target="dropdown-menu-main-mobile">
<%= icon "menu-line" %><span class="sr-only"><%= t("main_menu", scope: "layouts.decidim.header") %></span>
<%= icon "close-line" %>
</button>

<div id="dropdown-menu-main-mobile" class="main-bar__links-mobile__dropdown" aria-hidden="true">
<%= render partial: "layouts/decidim/header/menu_breadcrumb_main_dropdown", locals: { id: "breadcrumb-main-dropdown-mobile" } %>
</div>
<div id="dropdown-menu-main-mobile" class="main-bar__links-mobile__dropdown main-bar__links-mobile__dropdown-before" aria-hidden="true">
<%= render partial: "layouts/decidim/header/menu_breadcrumb_main_dropdown", locals: { id: "breadcrumb-main-dropdown-mobile" } %>
</div>

<%# Sticky menu mobile %>
<div class="main-bar__links-mobile">
<%= render partial: "layouts/decidim/header/main_links_mobile" %>
<%# Main mobile login %>
<div>
<%= render partial: "layouts/decidim/header/main_links_mobile_item_account" %>
</div>
</div>

<%# Overlay menus mobile %>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<% if current_user %>
<button id="dropdown-trigger-links-mobile" class="main-bar__links-mobile__item" data-component="dropdown" data-target="dropdown-menu-account-mobile">
<% if current_user.notifications.any? %>
<span class="main-bar__notification"></span>
<% end %>
<% if current_user.avatar.attached? %>
<span class="main-bar__avatar">
<%= image_tag(
current_user.attached_uploader(:avatar).path(variant: :thumb),
alt: t("decidim.author.avatar", name: decidim_sanitize(current_user.avatar.name))
) %>
</span>
<% else %>
<%= icon "user-smile-line" %>
<% end %>

</button>
<% else %>
<%= link_to decidim.new_user_session_path, class: "main-bar__links-mobile__login" do %>
<%= icon "user-line" %><span><%= t("layouts.decidim.header.log_in") %></span>
<% end %>
<% end %>
ElviaBth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,4 @@
</div>
</div>
</div>

<div class="main-bar__links-mobile__search-block">
<div class="-translate-y-full">
<label class="h4" for="input-search-mobile"><%= t("decidim.search.term_input_placeholder") %></label>
<%= form_tag(decidim.search_path, method: :get, class: "filter-search") do %>
<%= text_field_tag(
:term,
nil,
id: "input-search-mobile",
value: params[:term] || params.dig(:filter, :term),
placeholder: t("decidim.search.term_input_placeholder"),
title: t("decidim.search.term_input_placeholder"),
"aria-label": t("decidim.search.term_input_placeholder"),
tabindex: "0"
) %>
<button type="submit" aria-label="<%= t("decidim.search.term_input_placeholder") %>">
<%= icon "search-line" %>
</button>
<% end %>
</div>
</div>
</div>
Loading
Loading