Skip to content

Commit

Permalink
Reimplement doc search and theme switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
colepeters committed Nov 17, 2023
1 parent d33caaf commit 992bad4
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/elements/docs/layout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function DocsLayout({ html, state }) {
<docs-symbols class="hidden"></docs-symbols>
<div id="sidebar" class="hidden block-lg pi-2 pbe2">
<docs-nav aria-label="sidebar"></docs-nav>
<docs-nav aria-label="sidebar" searchid="search-widescreen"></docs-nav>
</div>
<div id="content" class="pbs0 pbs-none-lg pbe2">
Expand Down
37 changes: 31 additions & 6 deletions app/elements/docs/nav.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ function Description(item, classes = []) {
}

export default function DocsNav({ html, state }) {
const { store } = state
const { attrs, store } = state
const { navData } = store
const { searchid } = attrs

return html`
<style>
Expand All @@ -61,28 +62,52 @@ export default function DocsNav({ html, state }) {
margin-inline: calc(var(--space--4) * -1 - 4px);
padding-inline: var(--space--4);
border-inline-start: 4px solid transparent;
color: var(--rift-princess);
}
li a:hover,
li a.active {
background-color: var(--cloud-ateneo);
border-color: var(--purple-princess);
background-color: var(--lily);
border-color: var(--purple);
}
.category-label {
color: var(--purple-white);
color: var(--purple);
}
.description {
color: var(--inky-lily);
color: var(--inky);
}
.hasChildren ul {
padding-inline-start: var(--space--2);
}
@media screen and (min-width: 56em) {
li a {
color: var(--rift-princess);
}
li a:hover,
li a.active {
background-color: var(--cloud-ateneo);
border-color: var(--purple-princess);
}
.category-label {
color: var(--purple-white);
}
.description {
color: var(--inky-lily);
}
}
</style>
<div class="pbs2 flex gap0 align-items-center">
<docs-search searchid="${searchid}"></docs-search>
<docs-theme-toggle></docs-theme-toggle>
</div>
<nav>${List(navData)}</nav>
`
}
122 changes: 122 additions & 0 deletions app/elements/docs/search.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
export default function DocsSearch({ html, state }) {
const { attrs, store } = state
const { searchTerm } = store
const { searchid } = attrs

const darkModeExtras = `
--docsearch-footer-background: var(--smoke-halite);
--docsearch-hit-background: var(--white-denim);
--docsearch-hit-color: var(--white);
--docsearch-modal-background: var(--smoke-halite);
--docsearch-searchbox-background: hsla(0deg 0% 0% / 0.5);
--docsearch-searchbox-focus-background: var(--white-denim);
--docsearch-text-color: var(--rift-white);
--mobile-nav-background: hsla(0deg 0% 0% / 0.66);
`

return html`
<style scope="global">
/* Docsearch overrides */
:root {
--docsearch-footer-background: var(--smoke);
--docsearch-footer-shadow: none;
--docsearch-highlight-color: var(--purple);
--docsearch-hit-background: var(--white);
--docsearch-hit-color: var(--rift);
--docsearch-hit-shadow: 0 1px 2px hsla(0deg 0% 0% / 0.125);
--docsearch-modal-background: var(--smoke);
--docsearch-modal-shadow: 0 2px 6px hsla(0deg 0% 0% / 0.5);
--docsearch-searchbox-background: hsla(0deg 0% 0% / 0.075);
--docsearch-searchbox-focus-background: var(--white);
--docsearch-searchbox-shadow: inset 0 0 0 2px var(--purple);
--docsearch-text-color: var(--rift);
--mobile-nav-background: hsla(0deg 0% 100% / 0.85);
}
/* Only use dark styles in widescreen; search shown in global nav docs subnav < 56em */
@media screen and (min-width:56em) and (prefers-color-scheme: dark) {
:root {
${darkModeExtras}
}
}
@media screen and (min-width: 56em) {
:root[data-force-theme="dark"] {
${darkModeExtras}
}
}
.DocSearch-Button {
font-weight: 400;
margin-inline-start: 0;
}
.DocSearch-Button:focus {
box-shadow: none;
outline: 2px auto Highlight;
outline: 2px auto -webkit-focus-ring-color;
}
/* Docsearch media query */
@media screen and (max-width: 768px) {
.DocSearch-Button {
background: var(--lily);
}
}
.DocSearch-Button-Keys {
min-inline-size: calc(32px + 0.8em);
}
.DocSearch-Button-Key {
font-weight: 400;
font-size: 0.75em;
inline-size: 16px;
}
.DocSearch-Container {
backdrop-filter: blur(2px) contrast(50%);
-webkit-backdrop-filter: blur(2px) contrast(50%);
font-size: var(--text-0);
}
/* unset Enhance Styles */
.DocSearch-Input:focus-visible {
outline: unset;
box-shadow: unset;
}
.DocSearch-Hit-content-wrapper {
font-weight: 400;
}
.DocSearch-Hit[aria-selected='true'] a {
background: var(--dark-purple);
}
.DocSearch-Hits mark {
font-weight: 600;
}
</style>
<style>
:host {
display: block;
}
</style>
<search id="${searchid}"></search>
<script type="module">
import docsearch from '/_static/bundles/docsearch-js.mjs'
docsearch({
appId: '1QR8CXPN0C',
apiKey: '781b7bc665ad54b682ab4a31a5ccb55e',
indexName: 'enhance',
container: '#${searchid}',
initialQuery: ${searchTerm ? `'${searchTerm}'` : 'null'},
})
</script>
`
}
25 changes: 22 additions & 3 deletions app/elements/docs/theme-toggle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,36 @@ export default function DocsThemeToggle({ html }) {
height: ${size}px;
width: ${size}px;
}
input + svg {
padding-bottom: 2px;
color: var(--purple-princess);
color: var(--purple);
}
input:hover + svg,
input:checked + svg {
opacity: 1;
color: var(--rift-white);
color: var(--rift);
}
input:checked + svg {
border-bottom: 2px solid var(--rift-white);
border-bottom: 2px solid var(--rift);
}
/* Allow dark mode styles when shown in widescreen layout */
@media screen and (min-width: 56em) {
input + svg {
color: var(--purple-princess);
}
input:hover + svg,
input:checked + svg {
color: var(--rift-white);
}
input:checked + svg {
border-bottom: 2px solid var(--rift-white);
}
}
</style>
Expand Down
2 changes: 1 addition & 1 deletion app/elements/product-nav.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ProductNav({ html }) {
<h2 class="semibold">
<a href="/docs">Docs</a>
</h2>
<docs-nav></docs-nav>
<docs-nav searchid="search-mobile"></docs-nav>
</masthead-slice>
`
}
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 992bad4

Please sign in to comment.