Skip to content

Commit ec6edac

Browse files
committed
feat: show Modal for detail
1 parent e410fa2 commit ec6edac

File tree

5 files changed

+68
-16
lines changed

5 files changed

+68
-16
lines changed

src/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@import "tailwindcss";
22

3+
@theme {
4+
--font-sans: "Songti SC", "STSong", serif;
5+
}
6+
37
body {
48
@apply bg-[color:var(--bgColor,#52AC6A)] m-0 p-0 overflow-hidden;
59
}

src/assets/close.svg

Lines changed: 5 additions & 0 deletions
Loading

src/assets/scroll.svg

Lines changed: 15 additions & 0 deletions
Loading

src/components/WikiHeader.svelte

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import {onMount, onDestroy} from 'svelte';
33
import {currentPage} from '../store';
44
import {wikis} from '../config';
5+
import {fade, fly} from 'svelte/transition';
6+
import Scroll from '../assets/scroll.svg?raw';
7+
import Close from '../assets/close.svg?raw';
58
import gsap from 'gsap';
69
710
let visible = true;
@@ -46,20 +49,38 @@
4649
}
4750
4851
onMount(() => {
52+
document.addEventListener('click', handleClick);
4953
setTimeout(scroll, 50);
54+
return () => {
55+
document.removeEventListener('click', handleClick);
56+
};
5057
});
51-
5258
onDestroy(() => {
5359
if (ticker) ticker.kill();
5460
});
61+
62+
function handleClick(event: MouseEvent) {
63+
const isTextInteraction = window.getSelection()?.toString();
64+
if (showModal && (event.target as HTMLElement).closest('#wiki-modal') && !isTextInteraction) {
65+
showModal = false;
66+
}
67+
}
5568
</script>
5669

5770
{#if visible && wikiText}
58-
<div class="fixed top-0 left-0 w-full bg-white/70 backdrop-blur-sm shadow-xs z-10 h-8 flex items-center">
71+
<div
72+
class="fixed top-0 left-0 w-full text-[var(--textColor)] bg-white/70 backdrop-blur-sm shadow-xs z-10 h-8 flex items-center"
73+
>
74+
<button
75+
class="pl-1 w-9 cursor-pointer"
76+
on:click={() => (showModal = true)}
77+
>
78+
{@html Scroll}
79+
</button>
5980
<div class="relative overflow-hidden flex-1 h-full">
6081
<div
6182
bind:this={textEl}
62-
class="absolute whitespace-nowrap text-sm lg:text-base will-change-transform text-[var(--textColor)] top-0 left-24 h-full flex items-center"
83+
class="absolute whitespace-nowrap text-sm lg:text-base will-change-transform top-0 left-12 h-full flex items-center"
6384
>
6485
{#each Array(2) as _}
6586
{#each lines as line}
@@ -69,21 +90,28 @@
6990
{/each}
7091
</div>
7192
</div>
93+
<button
94+
class="pr-1 w-8 cursor-pointer"
95+
on:click={() => (visible = false)}
96+
>
97+
{@html Close}
98+
</button>
7299
</div>
73100
{/if}
74-
75101
{#if showModal}
76-
<div class="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
77-
<div class="bg-white rounded-lg shadow-lg max-w-lg w-full p-6">
78-
<div class="text-lg font-semibold mb-4">Wiki</div>
79-
<pre class="whitespace-pre-wrap text-sm text-gray-700">{wikiText}</pre>
80-
<div class="mt-4 text-right">
81-
<button
82-
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
83-
on:click={() => (showModal = false)}
84-
>
85-
close
86-
</button>
102+
<div
103+
class="fixed inset-0 bg-black/60 flex items-center justify-center z-50 backdrop-blur-lg"
104+
id="wiki-modal"
105+
transition:fade={{duration: 150}}
106+
>
107+
<div
108+
class="rounded-lg px-4 md:px-20 text-[var(--textColor)] text-center overflow-y-auto py-6 max-h-[90vh]"
109+
transition:fly={{y: 20, duration: 300}}
110+
>
111+
<div class="space-y-4 text-2xl lg:text-4xl leading-9 md:leading-14 font-sans italic">
112+
{#each lines as line}
113+
<p>{line}</p>
114+
{/each}
87115
</div>
88116
</div>
89117
</div>

src/lib/BookScene.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class BookScene {
7474
this.container.appendChild(this.renderer.domElement);
7575

7676
this.setUpLight();
77-
this.setupLightControls();
77+
// this.setupLightControls();
7878

7979
this.handleResize(); //FIXME: 现在这个 handleResize 不可以放在后面执行
8080
window.addEventListener('resize', () => this.handleResize());

0 commit comments

Comments
 (0)