[ci] yarn format
This commit is contained in:
parent
09fefead88
commit
59cf6dcca8
3 changed files with 26 additions and 38 deletions
|
@ -2,8 +2,5 @@ export default {
|
||||||
buildOptions: {
|
buildOptions: {
|
||||||
site: 'https://docs.astro.build/',
|
site: 'https://docs.astro.build/',
|
||||||
},
|
},
|
||||||
renderers: [
|
renderers: ['@astrojs/renderer-preact', '@astrojs/renderer-react'],
|
||||||
'@astrojs/renderer-preact',
|
|
||||||
'@astrojs/renderer-react',
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -90,4 +90,4 @@
|
||||||
.search-hint {
|
.search-hint {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,30 @@
|
||||||
/* jsxImportSource: react */
|
/* jsxImportSource: react */
|
||||||
import { useState, useCallback, useRef } from 'react'
|
import { useState, useCallback, useRef } from 'react';
|
||||||
import { createPortal } from 'react-dom'
|
import { createPortal } from 'react-dom';
|
||||||
import { DocSearchModal, useDocSearchKeyboardEvents } from '@docsearch/react'
|
import { DocSearchModal, useDocSearchKeyboardEvents } from '@docsearch/react';
|
||||||
import '@docsearch/css//dist/style.css';
|
import '@docsearch/css//dist/style.css';
|
||||||
import './Search.css';
|
import './Search.css';
|
||||||
|
|
||||||
|
|
||||||
export function Search() {
|
export function Search() {
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const searchButtonRef = useRef()
|
const searchButtonRef = useRef();
|
||||||
const [initialQuery, setInitialQuery] = useState(null)
|
const [initialQuery, setInitialQuery] = useState(null);
|
||||||
|
|
||||||
const onOpen = useCallback(() => {
|
const onOpen = useCallback(() => {
|
||||||
setIsOpen(true)
|
setIsOpen(true);
|
||||||
}, [setIsOpen])
|
}, [setIsOpen]);
|
||||||
|
|
||||||
const onClose = useCallback(() => {
|
const onClose = useCallback(() => {
|
||||||
setIsOpen(false)
|
setIsOpen(false);
|
||||||
}, [setIsOpen])
|
}, [setIsOpen]);
|
||||||
|
|
||||||
const onInput = useCallback(
|
const onInput = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
setIsOpen(true)
|
setIsOpen(true);
|
||||||
setInitialQuery(e.key)
|
setInitialQuery(e.key);
|
||||||
},
|
},
|
||||||
[setIsOpen, setInitialQuery]
|
[setIsOpen, setInitialQuery]
|
||||||
)
|
);
|
||||||
|
|
||||||
useDocSearchKeyboardEvents({
|
useDocSearchKeyboardEvents({
|
||||||
isOpen,
|
isOpen,
|
||||||
|
@ -33,7 +32,7 @@ export function Search() {
|
||||||
onClose,
|
onClose,
|
||||||
onInput,
|
onInput,
|
||||||
searchButtonRef,
|
searchButtonRef,
|
||||||
})
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -43,11 +42,7 @@ export function Search() {
|
||||||
onClick={onOpen}
|
onClick={onOpen}
|
||||||
className="search-input"
|
className="search-input"
|
||||||
>
|
>
|
||||||
<svg
|
<svg width="24" height="24" fill="none">
|
||||||
width="24"
|
|
||||||
height="24"
|
|
||||||
fill="none"
|
|
||||||
>
|
|
||||||
<path
|
<path
|
||||||
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
|
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
|
@ -56,12 +51,8 @@ export function Search() {
|
||||||
strokeLinejoin="round"
|
strokeLinejoin="round"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
<span>
|
<span>Search</span>
|
||||||
Search
|
<span className="search-hint">
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
className="search-hint"
|
|
||||||
>
|
|
||||||
<span className="sr-only">Press </span>
|
<span className="sr-only">Press </span>
|
||||||
<kbd>/</kbd>
|
<kbd>/</kbd>
|
||||||
<span className="sr-only"> to search</span>
|
<span className="sr-only"> to search</span>
|
||||||
|
@ -79,19 +70,19 @@ export function Search() {
|
||||||
return items.map((item) => {
|
return items.map((item) => {
|
||||||
// We transform the absolute URL into a relative URL to
|
// We transform the absolute URL into a relative URL to
|
||||||
// work better on localhost, preview URLS.
|
// work better on localhost, preview URLS.
|
||||||
const a = document.createElement('a')
|
const a = document.createElement('a');
|
||||||
a.href = item.url
|
a.href = item.url;
|
||||||
console.log(a.hash);
|
console.log(a.hash);
|
||||||
const hash = a.hash === '#overview' ? '' : a.hash
|
const hash = a.hash === '#overview' ? '' : a.hash;
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
url: `${a.pathname}${hash}`,
|
url: `${a.pathname}${hash}`,
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
}}
|
}}
|
||||||
/>,
|
/>,
|
||||||
document.body
|
document.body
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue