Skip to content

Commit

Permalink
feat: add overlay menu for mobile device
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Oct 6, 2022
1 parent 4409d28 commit 87ececb
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 16 deletions.
10 changes: 10 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="vite/client" />
import type { Alpine } from "alpinejs";

export {};

declare global {
interface Window {
Alpine: Alpine;
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@iconify/json": "^2.1.118",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/typography": "^0.5.7",
"@types/alpinejs": "^3.7.0",
"@types/node": "16",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
Expand All @@ -55,6 +56,7 @@
"vite-plugin-purge-icons": "^0.9.1"
},
"dependencies": {
"@iconify/iconify": "^3.0.0"
"@iconify/iconify": "^3.0.0",
"alpinejs": "^3.10.3"
}
}
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

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

6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import "./styles/tailwind.css";
import "./styles/main.css";
import "@purge-icons/generated";

import Alpine from "alpinejs";

window.Alpine = Alpine;

Alpine.start();

const onScroll = () => {
const headerMenu = document.getElementById("header-menu");
if (window.scrollY > 0) {
Expand Down
8 changes: 6 additions & 2 deletions templates/assets/dist/main.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion templates/assets/dist/style.css

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions templates/modules/footer.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<footer class="mt-10 bg-white py-8">
<div class="container mx-auto sm:flex sm:items-center sm:justify-between">
<a
href="https://halo.run/"
href="/"
class="mb-4 flex items-center justify-center sm:mb-0 sm:justify-start"
>
<img src="https://halo.run/logo" class="mr-3 h-8" alt="Halo Logo" />
<span class="self-center whitespace-nowrap text-2xl font-semibold">
Halo
<img th:src="${site.logo}" class="mr-3 h-8" th:alt="${site.title}" />
<span
class="self-center whitespace-nowrap text-2xl font-semibold"
th:text="${site.title}"
>
</span>
</a>
<ul
Expand All @@ -29,7 +31,8 @@
<hr class="my-6 border-gray-100 sm:mx-auto lg:my-8" />
<span class="container mx-auto block text-center text-sm text-gray-500">
© 2022
<a href="https://halo.run" class="hover:underline">Halo</a>. All Rights
Reserved.
<a href="/" class="hover:underline" th:text="${site.title}"></a>. All Rights
Reserved. Powered by
<a href="https://halo.run" class="hover:underline" target="_blank">Halo</a>.
</span>
</footer>
8 changes: 7 additions & 1 deletion templates/modules/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<ul
th:if="${menu != null} and ${not #lists.isEmpty(menu.menuItems)}"
class="flex items-center gap-6 text-white"
class="hidden items-center gap-6 text-white sm:flex"
>
<li
th:each="menuItem : ${menu.menuItems}"
Expand All @@ -31,6 +31,12 @@
</div>
<div class="flex items-center">
<ul class="flex items-center gap-4">
<li class="sm:hidden" x-on:click="overlayMenu = true">
<span
data-icon="tabler:menu-2"
class="iconify text-lg text-white"
></span>
</li>
<li>
<span
data-icon="tabler:brightness-2"
Expand Down
5 changes: 3 additions & 2 deletions templates/modules/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
th:href="@{/assets/dist/style.css}"
href="./assets/dist/style.css"
/>
<script th:src="@{/assets/dist/main.iife.js}"></script>
<script th:src="@{/assets/dist/main.iife.js}" defer></script>
<th:block th:if="${head != null}">
<th:block th:replace="${head}" />
</th:block>
</head>
<body>
<body x-data="{ overlayMenu: false }">
<th:block th:replace="modules/header" />
<section class="container mx-auto"></section>
<section
Expand All @@ -34,5 +34,6 @@
<th:block th:if="${footer != null}">
<th:block th:replace="${footer}" />
</th:block>
<th:block th:replace="modules/overlay-menu" />
</body>
</html>
177 changes: 177 additions & 0 deletions templates/modules/overlay-menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<div class="relative z-10" role="dialog" aria-modal="true" x-show="overlayMenu">
<div
x-show="overlayMenu"
x-on:click="overlayMenu = false"
class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"
x-transition:enter="ease-in-out duration-300"
x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100"
x-transition:leave="ease-in-out duration-300"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
></div>

<div class="fixed inset-0 overflow-hidden">
<div class="absolute inset-0 overflow-hidden">
<div
class="pointer-events-none fixed inset-y-0 left-0 flex max-w-full pr-20"
>
<div
x-show="overlayMenu"
class="pointer-events-auto w-screen max-w-md"
x-transition:enter="transform transition ease-in-out duration-300"
x-transition:enter-start="-translate-x-full"
x-transition:enter-end="translate-x-0"
x-transition:leave="transform transition ease-in-out duration-300"
x-transition:leave-start="translate-x-0"
x-transition:leave-end="-translate-x-full"
>
<div
class="flex h-full flex-col overflow-y-auto bg-white py-6 shadow-xl"
>
<div class="flex items-center justify-end px-4 sm:px-6">
<button
x-on:click="overlayMenu = false"
type="button"
class="rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none"
>
<span data-icon="tabler:x" class="iconify text-lg"></span>
</button>
</div>
<div class="relative mt-6 flex-1 px-4 sm:px-6">
<div class="absolute inset-0 px-4 sm:px-6">
<div class="flex h-full flex-col items-center gap-4">
<div class="relative h-24 w-24">
<img
th:src="${site.logo}"
th:alt="${site.title}"
class="h-full w-full rounded-full"
/>
<span
class="absolute right-0 bottom-0 flex h-7 w-7 items-center justify-center rounded-full border bg-white p-0.5"
>
🌚
</span>
</div>
<div>
<h1
class="text-2xl font-medium"
th:text="${site.title}"
></h1>
</div>
<div th:if="${not #strings.isEmpty(site.subtitle)}">
<p
class="text-center text-sm text-gray-700"
th:text="${site.subtitle}"
></p>
</div>
<div class="grid grid-cols-4 gap-5">
<div class="inline-flex flex-col items-center">
<span
class="text-xl font-medium tabular-nums text-gray-900"
>97</span
><span class="text-xs font-light text-gray-600"
>文章数</span
>
</div>
<div class="inline-flex flex-col items-center">
<span
class="text-xl font-medium tabular-nums text-gray-900"
>18</span
><span class="text-xs font-light text-gray-600"
>分类数</span
>
</div>
<div class="inline-flex flex-col items-center">
<span
class="text-xl font-medium tabular-nums text-gray-900"
>117</span
><span class="text-xs font-light text-gray-600"
>评论数</span
>
</div>
<div class="inline-flex flex-col items-center">
<span
class="text-xl font-medium tabular-nums text-gray-900"
>92392</span
><span class="text-xs font-light text-gray-600"
>访问量</span
>
</div>
</div>
<div class="grid grid-cols-6 items-center gap-5">
<div
class="flex cursor-pointer items-center justify-center rounded p-1 hover:bg-gray-100"
>
<span
data-icon="simple-icons:wechat"
class="iconify text-[#07C160]"
></span>
</div>
<div
class="flex cursor-pointer items-center justify-center rounded p-1 hover:bg-gray-100"
>
<span
data-icon="simple-icons:bilibili"
class="iconify text-[#00A1D6]"
></span>
</div>
<div
class="flex cursor-pointer items-center justify-center rounded p-1 hover:bg-gray-100"
>
<span
data-icon="simple-icons:github"
class="iconify text-[#181717]"
></span>
</div>
<div
class="flex cursor-pointer items-center justify-center rounded p-1 hover:bg-gray-100"
>
<span
data-icon="simple-icons:twitter"
class="iconify text-[#1DA1F2]"
></span>
</div>
<div
class="flex cursor-pointer items-center justify-center rounded p-1 hover:bg-gray-100"
>
<span
data-icon="simple-icons:telegram"
class="iconify text-[#26A5E4]"
></span>
</div>
<div
class="flex cursor-pointer items-center justify-center rounded p-1 hover:bg-gray-100"
>
<span
data-icon="simple-icons:feedly"
class="iconify text-[#2BB24C]"
></span>
</div>
</div>
<div
class="w-full"
th:with="menu = ${menuFinder.getDefault()}"
>
<ul
th:if="${menu != null} and ${not #lists.isEmpty(menu.menuItems)}"
class="flex w-full flex-col gap-1"
>
<li th:each="menuItem : ${menu.menuItems}" class="w-full">
<a
th:href="${menuItem.status.href}"
th:text="${menuItem.status.displayName}"
class="flex h-full w-full rounded px-3 py-2 text-sm text-gray-900 hover:bg-gray-100"
></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
8 changes: 6 additions & 2 deletions templates/modules/widgets/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
>
<div class="flex flex-col items-center justify-center gap-4">
<div class="relative h-24 w-24">
<img src="https://halo.run/logo" class="h-full w-full rounded-full" />
<img
th:src="${site.logo}"
th:alt="${site.title}"
class="h-full w-full rounded-full"
/>
<span
class="absolute right-0 bottom-0 flex h-7 w-7 items-center justify-center rounded-full border bg-white p-0.5"
>
🌚
</span>
</div>
<div><h1 class="text-2xl font-medium" th:text="${site.title}"></h1></div>
<div>
<div th:if="${not #strings.isEmpty(site.subtitle)}">
<p
class="text-center text-sm text-gray-700"
th:text="${site.subtitle}"
Expand Down
Loading

0 comments on commit 87ececb

Please sign in to comment.