@rspress/core 0.0.12 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/index.js +34 -26
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +2 -0
  4. package/dist/loader.js +24 -49
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.d.ts +8 -0
  7. package/dist/runtime/Content.d.ts +6 -0
  8. package/dist/runtime/NoSSR.d.ts +4 -0
  9. package/dist/runtime/clientEntry.d.ts +1 -0
  10. package/dist/runtime/hooks.d.ts +22 -0
  11. package/dist/runtime/index.d.ts +6 -0
  12. package/dist/runtime/ssrEntry.d.ts +6 -0
  13. package/dist/runtime/tsconfig.json +9 -0
  14. package/dist/runtime/utils.d.ts +6 -0
  15. package/dist/theme/bundle.css +85 -52
  16. package/dist/theme/bundle.d.ts +24 -2
  17. package/dist/theme/bundle.js +1425 -897
  18. package/dist/theme/bundle.js.map +1 -1
  19. package/package.json +14 -16
  20. package/src/runtime/global.d.ts +49 -0
  21. package/src/runtime/tsconfig.json +9 -0
  22. package/src/theme-default/components/LocalSideBar/{index.module.scss → index.scss} +6 -5
  23. package/src/theme-default/components/LocalSideBar/index.tsx +4 -4
  24. package/src/theme-default/components/PackageManagerTabs/icons/Bun.tsx +101 -0
  25. package/src/theme-default/components/PackageManagerTabs/icons/Npm.tsx +16 -0
  26. package/src/theme-default/components/PackageManagerTabs/icons/Pnpm.tsx +22 -0
  27. package/src/theme-default/components/PackageManagerTabs/icons/Yarn.tsx +18 -0
  28. package/src/theme-default/components/PackageManagerTabs/index.scss +5 -0
  29. package/src/theme-default/components/PackageManagerTabs/index.tsx +110 -0
  30. package/src/theme-default/components/Search/SearchPanel.tsx +339 -0
  31. package/src/theme-default/components/Search/index.tsx +6 -326
  32. package/src/theme-default/components/Tabs/index.module.scss +1 -0
  33. package/src/theme-default/components/Tabs/index.tsx +30 -41
  34. package/src/theme-default/components/Toc/index.css +18 -0
  35. package/src/theme-default/components/Toc/index.tsx +42 -0
  36. package/src/theme-default/index.ts +8 -7
  37. package/src/theme-default/layout/DocLayout/docComponents/code.tsx +1 -1
  38. package/src/theme-default/layout/DocLayout/index.module.scss +6 -3
  39. package/src/theme-default/layout/DocLayout/index.tsx +9 -7
  40. package/src/theme-default/logic/useAppearance.ts +0 -1
@@ -0,0 +1,339 @@
1
+ import { createPortal } from 'react-dom';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { groupBy, debounce } from 'lodash-es';
4
+ import { onSearch } from 'virtual-search-hooks';
5
+ import { SearchOptions } from '@rspress/shared';
6
+ import { getSidebarGroupData } from '../../logic/useSidebarData';
7
+ import { useLocaleSiteData } from '../../logic/useLocaleSiteData';
8
+ import { Tabs, Tab } from '../Tabs';
9
+ import styles from './index.module.scss';
10
+ import SearchSvg from './assets/search.svg';
11
+ import LoadingSvg from './assets/loading.svg';
12
+ import CloseSvg from './assets/close.svg';
13
+ import { MatchResult, MatchResultItem, PageSearcher } from './logic/search';
14
+ import { SuggestItem } from './SuggestItem';
15
+ import { normalizeSearchIndexes, removeDomain } from './logic/util';
16
+ import { NoSearchResult } from './NoSearchResult';
17
+ import { isProduction, usePageData } from '@/runtime';
18
+
19
+ const KEY_CODE = {
20
+ ARROW_UP: 'ArrowUp',
21
+ ARROW_DOWN: 'ArrowDown',
22
+ ENTER: 'Enter',
23
+ SEARCH: 'KeyK',
24
+ ESC: 'Escape',
25
+ };
26
+
27
+ const RECOMMEND_WORD: Record<string, string> = {
28
+ zh: '其它站点推荐结果',
29
+ en: 'Other Site Search Results',
30
+ };
31
+
32
+ export interface SearchPanelProps {
33
+ focused: boolean;
34
+ setFocused: (focused: boolean) => void;
35
+ }
36
+
37
+ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
38
+ const [query, setQuery] = useState('');
39
+ const [searchResult, setSearchResult] = useState<MatchResult>({
40
+ current: [],
41
+ others: [],
42
+ });
43
+ const searchInputRef = useRef<HTMLInputElement | null>(null);
44
+ const [initing, setIniting] = useState(true);
45
+ const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
46
+ const pageSearcherRef = useRef<PageSearcher | null>(null);
47
+ const {
48
+ siteData,
49
+ page: { lang },
50
+ } = usePageData();
51
+ const { sidebar } = useLocaleSiteData();
52
+ const { search } = siteData;
53
+
54
+ const suggestions = [
55
+ ...searchResult.current,
56
+ ...searchResult.others.map(item => item.items),
57
+ ].flat();
58
+
59
+ // We need to extract the group name by the link so that we can divide the search result into different groups.
60
+ const extractGroupName = (link: string) =>
61
+ getSidebarGroupData(sidebar, link).group;
62
+
63
+ async function initPageSearcher() {
64
+ if (search === false) {
65
+ return;
66
+ }
67
+ const pageSearcher = new PageSearcher({
68
+ ...search,
69
+ currentLang: lang,
70
+ extractGroupName,
71
+ });
72
+ pageSearcherRef.current = pageSearcher;
73
+ await pageSearcherRef.current.init();
74
+ setIniting(false);
75
+ const query = searchInputRef.current?.value;
76
+ if (query) {
77
+ const matched = await pageSearcherRef.current?.match(query);
78
+ setSearchResult(matched || { current: [], others: [] });
79
+ }
80
+ }
81
+
82
+ useEffect(() => {
83
+ const onKeyDown = (e: KeyboardEvent) => {
84
+ switch (e.code) {
85
+ case KEY_CODE.SEARCH:
86
+ if (e.ctrlKey || e.metaKey) {
87
+ e.preventDefault();
88
+ setFocused(!focused);
89
+ }
90
+ break;
91
+ case KEY_CODE.ARROW_DOWN:
92
+ if (focused) {
93
+ e.preventDefault();
94
+ setCurrentSuggestionIndex(
95
+ (currentSuggestionIndex + 1) % suggestions.length,
96
+ );
97
+ }
98
+ break;
99
+ case KEY_CODE.ARROW_UP:
100
+ if (focused) {
101
+ e.preventDefault();
102
+ setCurrentSuggestionIndex(
103
+ (currentSuggestionIndex - 1 + suggestions.length) %
104
+ suggestions.length,
105
+ );
106
+ }
107
+ break;
108
+ case KEY_CODE.ENTER:
109
+ if (currentSuggestionIndex >= 0) {
110
+ const suggestion = suggestions[currentSuggestionIndex];
111
+ const isCurrent =
112
+ currentSuggestionIndex < searchResult.current.length;
113
+ if (isCurrent) {
114
+ window.location.href = isProduction()
115
+ ? suggestion.link
116
+ : removeDomain(suggestion.link);
117
+ setFocused(false);
118
+ } else {
119
+ window.open(suggestion.link);
120
+ }
121
+ }
122
+ break;
123
+ case KEY_CODE.ESC:
124
+ setFocused(false);
125
+ break;
126
+ default:
127
+ break;
128
+ }
129
+ };
130
+ document.addEventListener('keydown', onKeyDown);
131
+ return () => {
132
+ document.removeEventListener('keydown', onKeyDown);
133
+ };
134
+ }, [
135
+ setCurrentSuggestionIndex,
136
+ setFocused,
137
+ suggestions,
138
+ currentSuggestionIndex,
139
+ ]);
140
+
141
+ useEffect(() => {
142
+ if (focused) {
143
+ setSearchResult({ current: [], others: [] });
144
+ if (!pageSearcherRef.current) {
145
+ initPageSearcher();
146
+ }
147
+ }
148
+ }, [focused]);
149
+
150
+ useEffect(() => {
151
+ !initing && initPageSearcher();
152
+ // init pageSearcher again when lang changed
153
+ }, [lang]);
154
+
155
+ const onQueryChanged = async (e: React.ChangeEvent<HTMLInputElement>) => {
156
+ const newQuery = e.target.value;
157
+ setQuery(newQuery);
158
+ if (newQuery) {
159
+ await onSearch(newQuery);
160
+ const matched = await pageSearcherRef.current?.match(newQuery);
161
+ setSearchResult(matched || { current: [], others: [] });
162
+ }
163
+ };
164
+
165
+ const normalizeSuggestions = (suggestions: MatchResultItem[]) =>
166
+ groupBy(suggestions, 'group');
167
+
168
+ // accumulateIndex is used to calculate the index of the suggestion in the whole list.
169
+ let accumulateIndex = -1;
170
+
171
+ const renderSearchResult = (
172
+ result: MatchResult,
173
+ searchOptions: SearchOptions,
174
+ ) => {
175
+ if (!suggestions.length && !initing) {
176
+ return <NoSearchResult query={query} />;
177
+ }
178
+
179
+ const hasOtherResult =
180
+ searchResult.others.map(item => item.items).flat().length > 0;
181
+
182
+ const tabValues = result.others.map(item => {
183
+ if (!searchOptions || searchOptions.mode !== 'remote') {
184
+ return item;
185
+ }
186
+ const indexItem = normalizeSearchIndexes(
187
+ searchOptions.searchIndexes || [],
188
+ ).find(indexInfo => indexInfo.value === item.index);
189
+ return indexItem.label;
190
+ }) as string[];
191
+
192
+ return (
193
+ <div>
194
+ {/* current index */}
195
+ {renderSearchResultItem(result.current)}
196
+ {/* other indexes */}
197
+ {hasOtherResult && (
198
+ <h2 className={styles.groupTitle}>{RECOMMEND_WORD[lang]}</h2>
199
+ )}
200
+ <div style={{ marginTop: '-12px' }}>
201
+ <Tabs values={tabValues} tabContainerClassName={styles.tabClassName}>
202
+ {result.others.map(item => (
203
+ <Tab key={item.index}>
204
+ {renderSearchResultItem(item.items, false)}
205
+ </Tab>
206
+ ))}
207
+ </Tabs>
208
+ </div>
209
+ </div>
210
+ );
211
+ };
212
+
213
+ const renderSearchResultItem = (
214
+ suggestionList: MatchResultItem[],
215
+ isCurrent = true,
216
+ ) => {
217
+ // if no result, show no result
218
+ if (suggestionList.length === 0 && !initing) {
219
+ return (
220
+ <div className="mt-4 flex-center">
221
+ <div
222
+ className="p-2 font-bold text-md"
223
+ style={{
224
+ color: '#2c3e50',
225
+ }}
226
+ >
227
+ No results found
228
+ </div>
229
+ </div>
230
+ );
231
+ }
232
+ const normalizedSuggestions = normalizeSuggestions(suggestionList);
233
+ return (
234
+ <ul className={styles.suggestList}>
235
+ {Object.keys(normalizedSuggestions).map(group => {
236
+ const groupSuggestions = normalizedSuggestions[group] || [];
237
+ return (
238
+ <li key={group}>
239
+ {isCurrent && <h2 className={styles.groupTitle}>{group}</h2>}
240
+ <ul className="pb-2">
241
+ {groupSuggestions.map(suggestion => {
242
+ accumulateIndex++;
243
+ const suggestionIndex = accumulateIndex;
244
+ return (
245
+ <SuggestItem
246
+ key={`${suggestion.title}-${suggestionIndex}`}
247
+ suggestion={suggestion}
248
+ isCurrent={suggestionIndex === currentSuggestionIndex}
249
+ setCurrentSuggestionIndex={() => {
250
+ setCurrentSuggestionIndex(suggestionIndex);
251
+ }}
252
+ closeSearch={() => setFocused(false)}
253
+ inCurrentDocIndex={
254
+ suggestionIndex < searchResult.current.length
255
+ }
256
+ />
257
+ );
258
+ })}
259
+ </ul>
260
+ </li>
261
+ );
262
+ })}
263
+ </ul>
264
+ );
265
+ };
266
+
267
+ return (
268
+ <>
269
+ {focused &&
270
+ createPortal(
271
+ <div className={styles.mask} onClick={() => setFocused(false)}>
272
+ <div
273
+ className={`${styles.modal}`}
274
+ onClick={e => {
275
+ setFocused(true);
276
+ e.stopPropagation();
277
+ }}
278
+ >
279
+ <div className="flex items-center">
280
+ <div className={styles.inputForm}>
281
+ <label>
282
+ <SearchSvg />
283
+ </label>
284
+ <input
285
+ className={styles.input}
286
+ ref={searchInputRef}
287
+ placeholder="Search Docs"
288
+ aria-label="Search"
289
+ autoComplete="off"
290
+ autoFocus
291
+ onChange={debounce(onQueryChanged, 150)}
292
+ />
293
+ <label>
294
+ <CloseSvg
295
+ className={styles.close}
296
+ onClick={e => {
297
+ if (searchInputRef.current) {
298
+ e.stopPropagation();
299
+ if (!query) {
300
+ setFocused(false);
301
+ } else {
302
+ searchInputRef.current.value = '';
303
+ setQuery('');
304
+ }
305
+ }
306
+ }}
307
+ />
308
+ </label>
309
+ </div>
310
+ <h2
311
+ className="text-brand ml-2 sm:hidden cursor-pointer"
312
+ onClick={e => {
313
+ e.stopPropagation();
314
+ setFocused(false);
315
+ }}
316
+ >
317
+ Cancel
318
+ </h2>
319
+ </div>
320
+
321
+ {query ? (
322
+ <div className={`${styles.searchHits} rspress-scrollbar`}>
323
+ {renderSearchResult(searchResult, search)}
324
+ </div>
325
+ ) : null}
326
+ {initing && (
327
+ <div className="flex-center">
328
+ <div className="p-2 text-sm">
329
+ <LoadingSvg />
330
+ </div>
331
+ </div>
332
+ )}
333
+ </div>
334
+ </div>,
335
+ document.getElementById('search-container')!,
336
+ )}
337
+ </>
338
+ );
339
+ }
@@ -1,265 +1,10 @@
1
- import { createPortal } from 'react-dom';
2
- import { useEffect, useRef, useState } from 'react';
3
- import { groupBy, debounce } from 'lodash-es';
4
- import { onSearch } from 'virtual-search-hooks';
5
- import { SearchOptions } from '@rspress/shared';
6
- import { getSidebarGroupData } from '../../logic/useSidebarData';
7
- import { useLocaleSiteData } from '../../logic/useLocaleSiteData';
8
- import { Tabs, Tab } from '../Tabs';
9
- import styles from './index.module.scss';
1
+ import { useState } from 'react';
10
2
  import SearchSvg from './assets/search.svg';
11
- import LoadingSvg from './assets/loading.svg';
12
- import CloseSvg from './assets/close.svg';
13
- import { MatchResult, MatchResultItem, PageSearcher } from './logic/search';
14
- import { SuggestItem } from './SuggestItem';
15
- import { normalizeSearchIndexes, removeDomain } from './logic/util';
16
- import { NoSearchResult } from './NoSearchResult';
17
- import { isProduction, usePageData } from '@/runtime';
18
-
19
- const KEY_CODE = {
20
- ARROW_UP: 'ArrowUp',
21
- ARROW_DOWN: 'ArrowDown',
22
- ENTER: 'Enter',
23
- SEARCH: 'KeyK',
24
- ESC: 'Escape',
25
- };
26
-
27
- const RECOMMEND_WORD: Record<string, string> = {
28
- zh: '其它站点推荐结果',
29
- en: 'Other Site Search Results',
30
- };
3
+ import styles from './index.module.scss';
4
+ import { SearchPanel } from './SearchPanel';
31
5
 
32
6
  export function Search() {
33
- const [query, setQuery] = useState('');
34
- const [searchResult, setSearchResult] = useState<MatchResult>({
35
- current: [],
36
- others: [],
37
- });
38
7
  const [focused, setFocused] = useState(false);
39
- const searchInputRef = useRef<HTMLInputElement | null>(null);
40
- const [initing, setIniting] = useState(true);
41
- const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
42
- const pageSearcherRef = useRef<PageSearcher | null>(null);
43
- const {
44
- siteData,
45
- page: { lang },
46
- } = usePageData();
47
- const { sidebar } = useLocaleSiteData();
48
- const { search } = siteData;
49
-
50
- const suggestions = [
51
- ...searchResult.current,
52
- ...searchResult.others.map(item => item.items),
53
- ].flat();
54
-
55
- // We need to extract the group name by the link so that we can divide the search result into different groups.
56
- const extractGroupName = (link: string) =>
57
- getSidebarGroupData(sidebar, link).group;
58
-
59
- async function initPageSearcher() {
60
- if (search === false) {
61
- return;
62
- }
63
- const pageSearcher = new PageSearcher({
64
- ...search,
65
- currentLang: lang,
66
- extractGroupName,
67
- });
68
- pageSearcherRef.current = pageSearcher;
69
- await pageSearcherRef.current.init();
70
- setIniting(false);
71
- const query = searchInputRef.current?.value;
72
- if (query) {
73
- const matched = await pageSearcherRef.current?.match(query);
74
- setSearchResult(matched || { current: [], others: [] });
75
- }
76
- }
77
-
78
- useEffect(() => {
79
- const onKeyDown = (e: KeyboardEvent) => {
80
- switch (e.code) {
81
- case KEY_CODE.SEARCH:
82
- if (e.ctrlKey || e.metaKey) {
83
- e.preventDefault();
84
- setFocused(!focused);
85
- }
86
- break;
87
- case KEY_CODE.ARROW_DOWN:
88
- if (focused) {
89
- e.preventDefault();
90
- setCurrentSuggestionIndex(
91
- (currentSuggestionIndex + 1) % suggestions.length,
92
- );
93
- }
94
- break;
95
- case KEY_CODE.ARROW_UP:
96
- if (focused) {
97
- e.preventDefault();
98
- setCurrentSuggestionIndex(
99
- (currentSuggestionIndex - 1 + suggestions.length) %
100
- suggestions.length,
101
- );
102
- }
103
- break;
104
- case KEY_CODE.ENTER:
105
- if (currentSuggestionIndex >= 0) {
106
- const suggestion = suggestions[currentSuggestionIndex];
107
- const isCurrent =
108
- currentSuggestionIndex < searchResult.current.length;
109
- if (isCurrent) {
110
- window.location.href = isProduction()
111
- ? suggestion.link
112
- : removeDomain(suggestion.link);
113
- setFocused(false);
114
- } else {
115
- window.open(suggestion.link);
116
- }
117
- }
118
- break;
119
- case KEY_CODE.ESC:
120
- setFocused(false);
121
- break;
122
- default:
123
- break;
124
- }
125
- };
126
- document.addEventListener('keydown', onKeyDown);
127
- return () => {
128
- document.removeEventListener('keydown', onKeyDown);
129
- };
130
- }, [
131
- setCurrentSuggestionIndex,
132
- setFocused,
133
- suggestions,
134
- currentSuggestionIndex,
135
- ]);
136
-
137
- useEffect(() => {
138
- if (focused) {
139
- setSearchResult({ current: [], others: [] });
140
- if (!pageSearcherRef.current) {
141
- initPageSearcher();
142
- }
143
- }
144
- }, [focused]);
145
-
146
- useEffect(() => {
147
- !initing && initPageSearcher();
148
- // init pageSearcher again when lang changed
149
- }, [lang]);
150
-
151
- const onQueryChanged = async (e: React.ChangeEvent<HTMLInputElement>) => {
152
- const newQuery = e.target.value;
153
- setQuery(newQuery);
154
- if (newQuery) {
155
- await onSearch(newQuery);
156
- const matched = await pageSearcherRef.current?.match(newQuery);
157
- setSearchResult(matched || { current: [], others: [] });
158
- }
159
- };
160
-
161
- const normalizeSuggestions = (suggestions: MatchResultItem[]) =>
162
- groupBy(suggestions, 'group');
163
-
164
- // accumulateIndex is used to calculate the index of the suggestion in the whole list.
165
- let accumulateIndex = -1;
166
-
167
- const renderSearchResult = (
168
- result: MatchResult,
169
- searchOptions: SearchOptions,
170
- ) => {
171
- if (!suggestions.length && !initing) {
172
- return <NoSearchResult query={query} />;
173
- }
174
-
175
- const hasOtherResult =
176
- searchResult.others.map(item => item.items).flat().length > 0;
177
-
178
- const tabValues = result.others.map(item => {
179
- if (!searchOptions || searchOptions.mode !== 'remote') {
180
- return item;
181
- }
182
- const indexItem = normalizeSearchIndexes(
183
- searchOptions.searchIndexes || [],
184
- ).find(indexInfo => indexInfo.value === item.index);
185
- return indexItem.label;
186
- }) as string[];
187
-
188
- return (
189
- <div>
190
- {/* current index */}
191
- {renderSearchResultItem(result.current)}
192
- {/* other indexes */}
193
- {hasOtherResult && (
194
- <h2 className={styles.groupTitle}>{RECOMMEND_WORD[lang]}</h2>
195
- )}
196
- <div style={{ marginTop: '-12px' }}>
197
- <Tabs values={tabValues} tabContainerClassName={styles.tabClassName}>
198
- {result.others.map(item => (
199
- <Tab key={item.index}>
200
- {renderSearchResultItem(item.items, false)}
201
- </Tab>
202
- ))}
203
- </Tabs>
204
- </div>
205
- </div>
206
- );
207
- };
208
-
209
- const renderSearchResultItem = (
210
- suggestionList: MatchResultItem[],
211
- isCurrent = true,
212
- ) => {
213
- // if no result, show no result
214
- if (suggestionList.length === 0 && !initing) {
215
- return (
216
- <div className="mt-4 flex-center">
217
- <div
218
- className="p-2 font-bold text-md"
219
- style={{
220
- color: '#2c3e50',
221
- }}
222
- >
223
- No results found
224
- </div>
225
- </div>
226
- );
227
- }
228
- const normalizedSuggestions = normalizeSuggestions(suggestionList);
229
- return (
230
- <ul className={styles.suggestList}>
231
- {Object.keys(normalizedSuggestions).map(group => {
232
- const groupSuggestions = normalizedSuggestions[group] || [];
233
- return (
234
- <li key={group}>
235
- {isCurrent && <h2 className={styles.groupTitle}>{group}</h2>}
236
- <ul className="pb-2">
237
- {groupSuggestions.map(suggestion => {
238
- accumulateIndex++;
239
- const suggestionIndex = accumulateIndex;
240
- return (
241
- <SuggestItem
242
- key={`${suggestion.title}-${suggestionIndex}`}
243
- suggestion={suggestion}
244
- isCurrent={suggestionIndex === currentSuggestionIndex}
245
- setCurrentSuggestionIndex={() => {
246
- setCurrentSuggestionIndex(suggestionIndex);
247
- }}
248
- closeSearch={() => setFocused(false)}
249
- inCurrentDocIndex={
250
- suggestionIndex < searchResult.current.length
251
- }
252
- />
253
- );
254
- })}
255
- </ul>
256
- </li>
257
- );
258
- })}
259
- </ul>
260
- );
261
- };
262
-
263
8
  return (
264
9
  <>
265
10
  <div className={styles.navSearchButton} onClick={() => setFocused(true)}>
@@ -278,74 +23,9 @@ export function Search() {
278
23
  >
279
24
  <SearchSvg />
280
25
  </div>
281
- {focused &&
282
- createPortal(
283
- <div className={styles.mask} onClick={() => setFocused(false)}>
284
- <div
285
- className={`${styles.modal}`}
286
- onClick={e => {
287
- setFocused(true);
288
- e.stopPropagation();
289
- }}
290
- >
291
- <div className="flex items-center">
292
- <div className={styles.inputForm}>
293
- <label>
294
- <SearchSvg />
295
- </label>
296
- <input
297
- className={styles.input}
298
- ref={searchInputRef}
299
- placeholder="Search Docs"
300
- aria-label="Search"
301
- autoComplete="off"
302
- autoFocus
303
- onChange={debounce(onQueryChanged, 150)}
304
- />
305
- <label>
306
- <CloseSvg
307
- className={styles.close}
308
- onClick={e => {
309
- if (searchInputRef.current) {
310
- e.stopPropagation();
311
- if (!query) {
312
- setFocused(false);
313
- } else {
314
- searchInputRef.current.value = '';
315
- setQuery('');
316
- }
317
- }
318
- }}
319
- />
320
- </label>
321
- </div>
322
- <h2
323
- className="text-brand ml-2 sm:hidden cursor-pointer"
324
- onClick={e => {
325
- e.stopPropagation();
326
- setFocused(false);
327
- }}
328
- >
329
- Cancel
330
- </h2>
331
- </div>
332
-
333
- {query ? (
334
- <div className={`${styles.searchHits} rspress-scrollbar`}>
335
- {renderSearchResult(searchResult, search)}
336
- </div>
337
- ) : null}
338
- {initing && (
339
- <div className="flex-center">
340
- <div className="p-2 text-sm">
341
- <LoadingSvg />
342
- </div>
343
- </div>
344
- )}
345
- </div>
346
- </div>,
347
- document.getElementById('search-container')!,
348
- )}
26
+ <SearchPanel focused={focused} setFocused={setFocused} />
349
27
  </>
350
28
  );
351
29
  }
30
+
31
+ export { SearchPanel };
@@ -28,6 +28,7 @@
28
28
  margin-bottom: -1px;
29
29
  user-select: none;
30
30
  transition: all 0.2s ease-in-out;
31
+ cursor: pointer;
31
32
  }
32
33
 
33
34
  .tab:last-child {