Skip to content

Commit d910467

Browse files
committed
feat: search modal & highlight
1 parent 4a43f70 commit d910467

File tree

3 files changed

+482
-6
lines changed

3 files changed

+482
-6
lines changed

assets/search.css

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/* Ensure [hidden] attribute hides the modal even if other rules set display */
2+
.search-modal[hidden] {
3+
display: none !important;
4+
}
5+
6+
/* search modal and result styles */
7+
.search-modal {
8+
position: fixed;
9+
inset: 0;
10+
z-index: 9999;
11+
display: flex;
12+
align-items: flex-start;
13+
justify-content: center;
14+
padding: 48px 16px;
15+
/* Ensure the modal covers full viewport and prevent scroll chaining to background */
16+
height: 100vh;
17+
overscroll-behavior: none; /* 阻止滚动穿透到页面主体 */
18+
-webkit-overflow-scrolling: touch;
19+
}
20+
.search-overlay {
21+
position: absolute;
22+
inset: 0;
23+
background: rgba(0, 0, 0, 0.45);
24+
/* also prevent scroll chaining on the overlay */
25+
overscroll-behavior: none;
26+
}
27+
.search-panel {
28+
position: relative;
29+
width: 100%;
30+
max-width: 1100px;
31+
}
32+
.search-panel .container {
33+
background: var(--bg);
34+
color: var(--fg);
35+
border-radius: 6px;
36+
padding: 18px;
37+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
38+
}
39+
.search-header {
40+
display: flex;
41+
gap: 8px;
42+
align-items: center;
43+
}
44+
#search-input {
45+
flex: 1;
46+
padding: 10px 12px;
47+
font-size: 16px;
48+
background: var(--bg);
49+
color: var(--fg);
50+
border: 1px solid var(--border);
51+
border-radius: 4px;
52+
transition: border-color 0.2s ease, box-shadow 0.2s ease;
53+
}
54+
55+
#search-input:focus {
56+
outline: none;
57+
border-color: #0066cc;
58+
box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
59+
}
60+
#search-close {
61+
background: transparent;
62+
border: 0;
63+
font-size: 20px;
64+
cursor: pointer;
65+
color: var(--fg);
66+
}
67+
#search-results {
68+
margin-top: 12px;
69+
max-height: 60vh;
70+
padding-right: 10px;
71+
overflow: auto;
72+
}
73+
.search-item {
74+
padding: 10px 8px;
75+
border-bottom: 1px solid var(--border);
76+
display: flex;
77+
justify-content: space-between;
78+
gap: 12px;
79+
align-items: flex-start;
80+
transition: background-color 0.2s ease;
81+
}
82+
83+
.search-item:hover,
84+
.search-item:focus-within {
85+
background-color: rgba(0, 0, 0, 0.03);
86+
}
87+
88+
.search-item a {
89+
color: inherit;
90+
text-decoration: none;
91+
flex: 1;
92+
border-radius: 2px;
93+
padding: 2px;
94+
}
95+
96+
.search-item h4 {
97+
margin: 0;
98+
font-size: 16px;
99+
}
100+
.search-item p {
101+
margin: 6px 0 0 0;
102+
font-size: 13px;
103+
color: #3c3c3c;
104+
display: -webkit-box;
105+
-webkit-line-clamp: 3;
106+
line-clamp: 3;
107+
-webkit-box-orient: vertical;
108+
overflow: hidden;
109+
text-overflow: ellipsis;
110+
word-wrap: break-word;
111+
}
112+
.search-item .label {
113+
font-size: 12px;
114+
padding: 2px 6px;
115+
border-radius: 4px;
116+
background: var(--bg);
117+
color: var(--border);
118+
}
119+
.search-highlight {
120+
background: #fff5c2;
121+
transition: background 1.2s ease;
122+
}
123+
124+
@media (max-width: 767px) and (orientation: portrait) {
125+
.search-modal {
126+
padding: 0;
127+
align-items: stretch;
128+
}
129+
.search-panel {
130+
display: flex;
131+
flex-direction: column;
132+
}
133+
/* 使 container 占满可视高度,内部结果区做独立滚动,避免背景滚动 */
134+
.search-panel .container {
135+
border-radius: 0;
136+
display: flex;
137+
flex-direction: column;
138+
padding: 16px;
139+
max-height: 100vh;
140+
}
141+
142+
#search-results {
143+
overflow: auto;
144+
flex: 0.98;
145+
max-height: none;
146+
}
147+
}
148+
149+
@media (min-width: 768px) {
150+
.search-panel .container {
151+
max-width: 800px;
152+
margin: 0 auto;
153+
}
154+
}
155+
156+
/* search button in header */
157+
#search-btn {
158+
background: transparent;
159+
border: 0;
160+
cursor: pointer;
161+
color: currentColor;
162+
margin-left: 20px;
163+
padding: 8px;
164+
}
165+
166+
/* align SVG icon with text baseline */
167+
#search-btn svg {
168+
vertical-align: middle;
169+
}
170+
171+
/* dark mode support */
172+
@media (prefers-color-scheme: dark) {
173+
.search-item p {
174+
color: #e6e6e69f;
175+
}
176+
.search-item .label {
177+
color: #6c757d;
178+
}
179+
/* dark-mode highlight for search results and matched elements */
180+
.search-highlight {
181+
background: #665c00;
182+
transition: background 1.2s ease;
183+
}
184+
185+
.search-item:hover,
186+
.search-item:focus-within {
187+
background-color: rgba(255, 255, 255, 0.05);
188+
}
189+
190+
#search-input:focus {
191+
border-color: #4d9eff;
192+
box-shadow: 0 0 0 2px rgba(77, 158, 255, 0.2);
193+
}
194+
195+
.search-item a:focus {
196+
outline-color: #4d9eff;
197+
}
198+
}

0 commit comments

Comments
 (0)