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

Header #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails

const toggles = Array.from(document.querySelectorAll("[data-toggle]"));
const header = document.querySelector("header > div");
const nav = document.querySelector("nav");

const toggleClasses = (items, classes) =>
[items].flat().forEach((l) => classes.forEach((c) => l.classList.toggle(c)));

const toggleMenu = () => {
toggleClasses(header, ["bg-brand-dark", "bg-blue-100", "text-white"]);
toggleClasses(nav, ["translate-y-0", "-translate-y-full"]);
toggleClasses(toggles, ["hidden"]);
}



toggles.forEach((toggle) => toggle.addEventListener("click", toggleMenu));

// toggles.forEach(function (t) {
// t.addEventListener("click", function () {
// toggleClasses(header, ["bg-brand-dark", "bg-blue-100", "text-white"]);
// toggleClasses(nav, ["translate-y-0", "-translate-y-full"]);
// toggleClasses(toggles, ["hidden"]);
// });
// });

// menu.classList.remove("hidden");

// const close = document.querySelector("#close");

// close.addEventListener("click", function () {
// const header = document.querySelector("header");
// header.classList.toggle("bg-brand-dark");
// header.classList.toggle("text-white");
// close.classList.toggle("hidden");
// document.querySelector("nav").classList.toggle("scale-0");
// document.querySelector("nav").classList.toggle("scale-100");

// menu.classList.toggle("hidden");
// });
40 changes: 26 additions & 14 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>

<%= javascript_importmap_tags %>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
Expand All @@ -17,27 +17,39 @@
<meta name="theme-color" content="#ffffff">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">

<% if Rails.application.config.real_env.production? %>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2309414464751824"
crossorigin="anonymous"></script>
<% end %>
</head>

<body class="bg-blue-100 text-purple-500 text-base">
<header class="flex p-3 max-w-screen-lg mx-auto">
<%= link_to root_url, class: "mr-2" do %>
<%= image_tag "Logo.svg", class: "w-14 h-14", alt: "logo" %>
<% end %>
<h1 class="flex font-bold text-2xl items-center" >
<%= link_to root_url do %>
Menon
<% end %>
</h1>
<header class="flex max-w-screen-lg mx-auto flex-col ">
<div class="flex justify-between p-3 z-10 bg-blue-100 transition-all duration-300 ease-in">
<div class="flex flex-row">
<%= link_to root_url, class: "mr-2" do %>
<%= image_tag "Logo.svg", class: "w-14 h-14", alt: "logo" %>
<% end %>
<h1 class="flex font-bold text-2xl items-center" >
<%= link_to root_url do %>
Menon
<% end %>
</h1>
</div>
<button class="transition-all duration-300 ease-in font-bold text-xl uppercase" data-toggle="menu">Menu</button>
<button class="transition-all duration-300 ease-in font-bold text-xl uppercase hidden text-white" data-toggle="menu">Close <span class="font-extralight">X</span></button>
</div>
<div class="relative">
<nav class="-translate-y-full flex flex-col origin-top duration-300 ease-in transition-all justify-between bg-brand-dark border-t border-gray-500 p-3 pt-2 text-right inset-x-0 absolute">
<ul>
<li class="py-1"><%= link_to 'Sign Up', root_url, class:'text-white text-sm' %></li>
<li class="py-1"><%= link_to 'Languages', root_url, class:'text-white text-sm' %></li>
<li class="py-1"><%= link_to 'Categories', root_url, class:'text-white text-sm' %></li>
<li class="py-1"><%= link_to 'Contact', root_url, class:'text-white text-sm' %></li>
</ul>
</nav>
</div>
</header>

<%= yield %>

<footer class="p-3 max-w-screen-lg mx-auto">
</footer>
</body>
Expand Down
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pin npm packages by running ./bin/importmap

# pin "application", preload: true
pin "application", preload: true
# pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
# pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
# pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
Expand Down