2024-02-14 04:53:44 +00:00
|
|
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
2023-06-20 03:37:45 +00:00
|
|
|
import style from "./styles/search.scss"
|
|
|
|
// @ts-ignore
|
|
|
|
import script from "./scripts/search.inline"
|
2024-01-30 05:51:13 +00:00
|
|
|
import { classNames } from "../util/lang"
|
2024-02-05 04:57:10 +00:00
|
|
|
import { i18n } from "../i18n"
|
2023-06-20 03:37:45 +00:00
|
|
|
|
2024-01-31 09:16:14 +00:00
|
|
|
export interface SearchOptions {
|
|
|
|
enablePreview: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: SearchOptions = {
|
|
|
|
enablePreview: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ((userOpts?: Partial<SearchOptions>) => {
|
2024-02-14 04:53:44 +00:00
|
|
|
const Search: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
2024-01-31 09:16:14 +00:00
|
|
|
const opts = { ...defaultOptions, ...userOpts }
|
2024-02-05 04:57:10 +00:00
|
|
|
const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder
|
2023-07-23 00:27:41 +00:00
|
|
|
return (
|
2024-01-30 05:51:13 +00:00
|
|
|
<div class={classNames(displayClass, "search")}>
|
2024-08-10 01:46:50 +00:00
|
|
|
<button class="search-button" id="search-button">
|
2024-02-05 04:57:10 +00:00
|
|
|
<p>{i18n(cfg.locale).components.search.title}</p>
|
2024-08-10 01:46:50 +00:00
|
|
|
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7">
|
|
|
|
<title>Search</title>
|
2023-07-23 00:27:41 +00:00
|
|
|
<g class="search-path" fill="none">
|
|
|
|
<path stroke-linecap="square" d="M18.5 18.3l-5.4-5.4" />
|
|
|
|
<circle cx="8" cy="8" r="7" />
|
|
|
|
</g>
|
|
|
|
</svg>
|
2024-08-10 01:46:50 +00:00
|
|
|
</button>
|
2023-07-23 00:27:41 +00:00
|
|
|
<div id="search-container">
|
|
|
|
<div id="search-space">
|
|
|
|
<input
|
|
|
|
autocomplete="off"
|
|
|
|
id="search-bar"
|
|
|
|
name="search"
|
|
|
|
type="text"
|
2024-02-05 04:57:10 +00:00
|
|
|
aria-label={searchPlaceholder}
|
|
|
|
placeholder={searchPlaceholder}
|
2023-07-23 00:27:41 +00:00
|
|
|
/>
|
2024-01-31 09:16:14 +00:00
|
|
|
<div id="search-layout" data-preview={opts.enablePreview}></div>
|
2023-06-20 03:37:45 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-23 00:27:41 +00:00
|
|
|
)
|
2023-06-20 03:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Search.afterDOMLoaded = script
|
|
|
|
Search.css = style
|
|
|
|
|
|
|
|
return Search
|
|
|
|
}) satisfies QuartzComponentConstructor
|