Skip to content

Commit

Permalink
setting up navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
surjithctly committed Nov 2, 2022
1 parent c755263 commit ee30a40
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": false,
"bracketSameLine": true
}
5 changes: 4 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { defineConfig } from 'astro/config';
// https://astro.build/config
import tailwind from "@astrojs/tailwind";

// https://astro.build/config
import alpinejs from "@astrojs/alpinejs";

// https://astro.build/config
export default defineConfig({
integrations: [tailwind()]
integrations: [tailwind(), alpinejs()]
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/alpinejs": "^0.1.2",
"@astrojs/tailwind": "^2.1.1",
"@types/alpinejs": "^3.0.0",
"alpinejs": "^3.0.0",
"astro": "^1.6.0",
"tailwindcss": "^3.0.24"
}
Expand Down
48 changes: 48 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/components/container.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
const { class: className } = Astro.props;
---

<div class:list={["max-w-screen-xl mx-auto px-5", className]}>
<slot />
</div>
32 changes: 32 additions & 0 deletions src/components/navbar/dropdown.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
const { title, children } = Astro.props;
---

<div @click.away="open = false" class="relative" x-data="{ open: false }">
<button @click="open = !open" class="flex">
<span>{title}</span>
<svg
fill="currentColor"
viewBox="0 0 20 20"
:class="{'rotate-180': open, 'rotate-0': !open}"
class="inline w-4 h-4 mt-1 ml-1 transition-transform duration-200 transform md:-mt-1"
><path
fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd"></path>
</svg>
</button>
<div
x-show="open"
x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="transform lg:opacity-0 lg:scale-95"
x-transition:enter-end="transform lg:opacity-100 lg:scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform lg:opacity-100 lg:scale-100"
x-transition:leave-end="transform lg:opacity-0 lg:scale-95"
class="lg:absolute lg:right-0 w-full mt-2 origin-top-right lg:w-48">
<div class="px-2 py-2 lg:bg-white lg:rounded-md lg:shadow">
{children.map((item) => <div>{item.title}</div>)}
</div>
</div>
</div>
87 changes: 87 additions & 0 deletions src/components/navbar/navbar.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
import Container from "@components/container.astro";
import Dropdown from "./dropdown.astro";
const menuitems = [
{
title: "Features",
path: "#",
children: [
{ title: "Action", path: "#" },
{ title: "Another action", path: "#" },
{ title: "Dropdown Submenu", path: "#" },
],
},
{
title: "Pricing",
path: "/pricing",
},
{
title: "About",
path: "/about",
},
{
title: "Blog",
path: "/blog",
},
{
title: "Resources",
path: "#",
children: [
{ title: "Action", path: "#" },
{ title: "Another action", path: "#" },
{ title: "Dropdown Submenu", path: "#" },
],
},
];
---

<Container>
<header
class="flex justify-between my-5"
x-data="{ open: false }"
x-init="$watch('open', value => console.log(value))">
<div>Astroship</div>
<nav
class="lg:block"
:class="{ 'block': open, 'hidden': !open }"
x-show.transition="true">
<ul class="flex flex-col lg:flex-row gap-3">
{
menuitems.map((item) => (
<li>
{item.children && (
<Dropdown title={item.title} children={item.children} />
)}
{!item.children && <a href={item.path}>{item.title}</a>}
</li>
))
}
</ul>
</nav>
<div>
<div class="block lg:hidden">
<button @click="open = !open" class="text-gray-800">
<svg
fill="currentColor"
class="w-4 h-4"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg">
<title>Menu</title>
<path
x-show="open"
fill-rule="evenodd"
clip-rule="evenodd"
d="M18.278 16.864a1 1 0 01-1.414 1.414l-4.829-4.828-4.828 4.828a1 1 0 01-1.414-1.414l4.828-4.829-4.828-4.828a1 1 0 011.414-1.414l4.829 4.828 4.828-4.828a1 1 0 111.414 1.414l-4.828 4.829 4.828 4.828z"
></path>
<path
x-show="!open"
fill-rule="evenodd"
d="M4 5h16a1 1 0 010 2H4a1 1 0 110-2zm0 6h16a1 1 0 010 2H4a1 1 0 010-2zm0 6h16a1 1 0 010 2H4a1 1 0 010-2z"
></path>
</svg>
</button>
</div> login
</div>
</header>
</Container>
46 changes: 21 additions & 25 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
---
import Navbar from "@components/navbar/navbar.astro";
export interface Props {
title: string;
title: string;
}
const { title } = Astro.props;
---

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
</body>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title} {title && "|"} Astro Ship</title>
</head>
<body>
<Navbar />
<slot />
<style is:global>
// Improve Page speed
// https://css-tricks.com/almanac/properties/c/content-visibility/
img {
content-visibility: auto;
}
</style>
</body>
</html>
<style is:global>
:root {
--accent: 124, 58, 237;
--accent-gradient: linear-gradient(45deg, rgb(var(--accent)), #da62c4 30%, white 60%);
}
html {
font-family: system-ui, sans-serif;
background-color: #F6F6F6;
}
code {
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
</style>
14 changes: 13 additions & 1 deletion src/pages/about.astro
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
about
<div>about</div>

<div
class="max-w-lg p-5 mt-10 text-sm text-left text-gray-600 border max-h-14"
>
<p>
Thank you for being an early customer. We are still working on our
collection of components &amp; templates. It will take some time.
By buying early, you will get 50% discount on the original price +
all future updates for lifetime free! Sweet isn't it? It's a gift
for you.
</p>
</div>
Loading

0 comments on commit ee30a40

Please sign in to comment.