www: add search button island (#949)
This commit is contained in:
@@ -77,7 +77,7 @@ jobs:
|
|||||||
run: deno check --remote init.ts
|
run: deno check --remote init.ts
|
||||||
|
|
||||||
- name: Type check website
|
- name: Type check website
|
||||||
run: deno check --remote main.ts dev.ts
|
run: deno check main.ts dev.ts
|
||||||
working-directory: www/
|
working-directory: www/
|
||||||
|
|
||||||
- name: Type check examples/counter
|
- name: Type check examples/counter
|
||||||
|
|||||||
@@ -28,5 +28,5 @@ jobs:
|
|||||||
working-directory: www/
|
working-directory: www/
|
||||||
|
|
||||||
- name: Type check website
|
- name: Type check website
|
||||||
run: deno check --remote main.ts dev.ts
|
run: deno check main.ts dev.ts
|
||||||
working-directory: www/
|
working-directory: www/
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
deno.lock
|
||||||
@@ -1,16 +1,52 @@
|
|||||||
|
import { Head } from "$fresh/runtime.ts";
|
||||||
import {
|
import {
|
||||||
CATEGORIES,
|
CATEGORIES,
|
||||||
TableOfContentsCategory,
|
TableOfContentsCategory,
|
||||||
TableOfContentsCategoryEntry,
|
TableOfContentsCategoryEntry,
|
||||||
} from "../data/docs.ts";
|
} from "../data/docs.ts";
|
||||||
|
import SearchButton from "../islands/SearchButton.tsx";
|
||||||
|
|
||||||
export default function DocsSidebar(props: { path: string }) {
|
export default function DocsSidebar(props: { path: string; mobile?: boolean }) {
|
||||||
|
const id = String(Math.random()).replaceAll(".", "");
|
||||||
return (
|
return (
|
||||||
<ol class="list-decimal list-inside font-semibold nested">
|
<>
|
||||||
{CATEGORIES.map((category) => (
|
{props.mobile
|
||||||
<SidebarCategory path={props.path} category={category} />
|
? (
|
||||||
))}
|
<button
|
||||||
</ol>
|
type="button"
|
||||||
|
class="bg-gray-200 font-bold text-gray-400 rounded-full py-1 px-2 w-full mb-2"
|
||||||
|
// @ts-ignore: Inline event handler
|
||||||
|
onClick={`document.querySelector(".DocSearch.DocSearch-Button").click()`}
|
||||||
|
>
|
||||||
|
<span class="DocSearch-Button-Container">
|
||||||
|
<svg
|
||||||
|
width="20"
|
||||||
|
height="20"
|
||||||
|
class="DocSearch-Search-Icon"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
|
||||||
|
stroke="currentColor"
|
||||||
|
fill="none"
|
||||||
|
fill-rule="evenodd"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
</path>
|
||||||
|
</svg>
|
||||||
|
<span class="DocSearch-Button-Placeholder">Search</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
: <SearchButton />}
|
||||||
|
|
||||||
|
<ol class="list-decimal list-inside font-semibold nested">
|
||||||
|
{CATEGORIES.map((category) => (
|
||||||
|
<SidebarCategory path={props.path} category={category} />
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import * as $$0 from "./islands/ComponentGallery.tsx";
|
|||||||
import * as $$1 from "./islands/CopyArea.tsx";
|
import * as $$1 from "./islands/CopyArea.tsx";
|
||||||
import * as $$2 from "./islands/Counter.tsx";
|
import * as $$2 from "./islands/Counter.tsx";
|
||||||
import * as $$3 from "./islands/LemonDrop.tsx";
|
import * as $$3 from "./islands/LemonDrop.tsx";
|
||||||
|
import * as $$4 from "./islands/SearchButton.tsx";
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
@@ -34,6 +35,7 @@ const manifest = {
|
|||||||
"./islands/CopyArea.tsx": $$1,
|
"./islands/CopyArea.tsx": $$1,
|
||||||
"./islands/Counter.tsx": $$2,
|
"./islands/Counter.tsx": $$2,
|
||||||
"./islands/LemonDrop.tsx": $$3,
|
"./islands/LemonDrop.tsx": $$3,
|
||||||
|
"./islands/SearchButton.tsx": $$4,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
config,
|
config,
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { Head } from "$fresh/runtime.ts";
|
||||||
|
import { useEffect, useRef } from "preact/hooks";
|
||||||
|
import docsearch from "https://esm.sh/@docsearch/js@3";
|
||||||
|
|
||||||
|
export default function SearchButton() {
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
if (ref.current) {
|
||||||
|
docsearch({
|
||||||
|
appId: "CWUS37S0PK",
|
||||||
|
apiKey: "caa591b6dcb2c9308551361d954a728b",
|
||||||
|
indexName: "fresh",
|
||||||
|
container: ref.current,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [ref.current]);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="/docsearch.css"
|
||||||
|
/>
|
||||||
|
</Head>
|
||||||
|
<div class="h-9 mb-6" ref={ref}></div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -128,8 +128,8 @@ function MobileSidebar(props: { path: string }) {
|
|||||||
<div class="p-4 border(b-2 gray-100) bg-green-300">
|
<div class="p-4 border(b-2 gray-100) bg-green-300">
|
||||||
<DocsTitle title="docs" />
|
<DocsTitle title="docs" />
|
||||||
</div>
|
</div>
|
||||||
<nav class="pt-2 pb-16 px-4 overflow-x-auto">
|
<nav class="pt-6 pb-16 px-4 overflow-x-auto">
|
||||||
<DocsSidebar path={props.path} />
|
<DocsSidebar mobile path={props.path} />
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user