From 82e3b82c496203e952964cd950b583032e7b864b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 12:52:21 -0400 Subject: [PATCH 01/12] nest styles --- .../site-kit/src/lib/search/SearchBox.svelte | 171 +++++++++--------- packages/site-kit/src/lib/styles/base.css | 5 +- 2 files changed, 87 insertions(+), 89 deletions(-) diff --git a/packages/site-kit/src/lib/search/SearchBox.svelte b/packages/site-kit/src/lib/search/SearchBox.svelte index 8af9747bdf..22efce9aca 100644 --- a/packages/site-kit/src/lib/search/SearchBox.svelte +++ b/packages/site-kit/src/lib/search/SearchBox.svelte @@ -265,36 +265,34 @@ It appears when the user clicks on the `Search` component or presses the corresp } input { - font-family: inherit; font-size: 1.6rem; width: 100%; padding: 1rem 6rem 0.5rem 1rem; height: 5rem; border: none; border-bottom: 1px solid var(--sk-back-3); - font-weight: 600; flex-shrink: 0; background: var(--sk-back-2); color: var(--sk-text-1); - } - input::selection { - background-color: var(--sk-back-translucent); - } + &::selection { + background-color: var(--sk-back-translucent); + } - input::placeholder { - color: var(--sk-text-3); - opacity: 0.3; - } + &::placeholder { + color: var(--sk-text-3); + opacity: 0.3; + } - input:focus-visible { - background: var(--sk-theme-2); - color: white; - outline: none; - } + &:focus-visible { + background: var(--sk-theme-2); + color: white; + outline: none; + } - input:focus-visible::placeholder { - color: rgba(255, 255, 255, 0.5); + &:focus-visible::placeholder { + color: rgba(255, 255, 255, 0.5); + } } button[aria-label='Close'] { @@ -306,16 +304,16 @@ It appears when the user clicks on the `Search` component or presses the corresp height: 5rem; background: none; color: var(--sk-text-2); - } - button[aria-label='Close']:focus-visible { - background: var(--sk-theme-2); - color: var(--sk-back-1); - outline: none; - } + &:focus-visible { + background: var(--sk-theme-2); + color: var(--sk-back-1); + outline: none; + } - input:focus-visible + button[aria-label='Close'] { - color: var(--sk-back-1); + input:focus-visible + & { + color: var(--sk-back-1); + } } ul { @@ -324,6 +322,10 @@ It appears when the user clicks on the `Search` component or presses the corresp .modal { position: fixed; + display: flex; + justify-content: center; + align-items: center; + pointer-events: none; left: 0; top: 0; width: 100%; @@ -331,13 +333,6 @@ It appears when the user clicks on the `Search` component or presses the corresp z-index: 9999; } - .modal { - display: flex; - justify-content: center; - align-items: center; - pointer-events: none; - } - .search-box { position: relative; height: calc(100% - 2rem); @@ -349,10 +344,10 @@ It appears when the user clicks on the `Search` component or presses the corresp display: flex; flex-direction: column; overflow: hidden; - } - .search-box > * { - pointer-events: all; + & > * { + pointer-events: all; + } } .results { @@ -384,54 +379,54 @@ It appears when the user clicks on the `Search` component or presses the corresp text-decoration: none; line-height: 1; padding: 1rem; - } - a:hover { - background: rgba(0, 0, 0, 0.05); - } + &:hover { + background: rgba(0, 0, 0, 0.05); + } - a:focus { - background: var(--sk-theme-2); - color: var(--sk-back-1); - outline: none; - } + &:focus { + background: var(--sk-theme-2); + color: var(--sk-back-1); + outline: none; + } - a small, - a strong { - display: block; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - line-height: 1; - } + & small, + & strong { + display: block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + line-height: 1; + } - a small { - font-size: 1rem; - text-transform: uppercase; - font-weight: 600; - color: var(--sk-text-3); - } + & small { + font-size: 1rem; + text-transform: uppercase; + font-weight: 600; + color: var(--sk-text-3); + } - a strong { - font-size: 1.6rem; - color: var(--sk-text-2); - margin: 0.4rem 0; - } + & strong { + font-size: 1.6rem; + color: var(--sk-text-2); + margin: 0.4rem 0; + } - a:focus small { - color: white; - opacity: 0.6; - } + &:focus small { + color: white; + opacity: 0.6; + } - a:focus strong { - color: white; - } + &:focus strong { + color: white; + } - a strong :global(mark) { - background: var(--sk-theme-2); - color: var(--sk-text-3); - text-decoration: none; - border-radius: 1px; + & strong :global(mark) { + background: var(--sk-theme-2); + color: var(--sk-text-3); + text-decoration: none; + border-radius: 1px; + } } li { @@ -446,21 +441,21 @@ It appears when the user clicks on the `Search` component or presses the corresp height: 100%; color: var(--sk-text-2); opacity: 0.1; - } - a:focus + [aria-label='Delete'] { - color: var(--sk-back-1); - } + &:hover { + opacity: 1; + outline: none; + } - button[aria-label='Delete']:hover { - opacity: 1; - outline: none; - } + &:focus-visible { + background: var(--sk-theme-2); + color: var(--sk-text-1); + opacity: 1; + outline: none; + } - button[aria-label='Delete']:focus-visible { - background: var(--sk-theme-2); - color: var(--sk-text-1); - opacity: 1; - outline: none; + a:focus + & { + color: var(--sk-back-1); + } } diff --git a/packages/site-kit/src/lib/styles/base.css b/packages/site-kit/src/lib/styles/base.css index dadf47e148..4e2a98e5d0 100644 --- a/packages/site-kit/src/lib/styles/base.css +++ b/packages/site-kit/src/lib/styles/base.css @@ -146,9 +146,12 @@ blockquote :last-child { } /* buttons -------------------------------- */ -button { +input, button { font-family: var(--sk-font-ui); font-size: inherit; +} + +button { background-color: transparent; border: none; color: currentColor; From 3b88272ca2e9f4be95304da19d098c6e705ae63b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 13:07:20 -0400 Subject: [PATCH 02/12] start tweaking styles --- .../site-kit/src/lib/search/SearchBox.svelte | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/site-kit/src/lib/search/SearchBox.svelte b/packages/site-kit/src/lib/search/SearchBox.svelte index 22efce9aca..aeb5368766 100644 --- a/packages/site-kit/src/lib/search/SearchBox.svelte +++ b/packages/site-kit/src/lib/search/SearchBox.svelte @@ -272,7 +272,7 @@ It appears when the user clicks on the `Search` component or presses the corresp border: none; border-bottom: 1px solid var(--sk-back-3); flex-shrink: 0; - background: var(--sk-back-2); + background: var(--sk-back-3); color: var(--sk-text-1); &::selection { @@ -280,18 +280,13 @@ It appears when the user clicks on the `Search` component or presses the corresp } &::placeholder { - color: var(--sk-text-3); + color: var(--sk-text-2); opacity: 0.3; } &:focus-visible { - background: var(--sk-theme-2); - color: white; - outline: none; - } - - &:focus-visible::placeholder { - color: rgba(255, 255, 255, 0.5); + border-radius: var(--sk-border-radius); + outline-offset: -3px; } } @@ -303,16 +298,13 @@ It appears when the user clicks on the `Search` component or presses the corresp width: 5rem; height: 5rem; background: none; + border-radius: var(--sk-border-radius); color: var(--sk-text-2); + opacity: 0.3; &:focus-visible { - background: var(--sk-theme-2); - color: var(--sk-back-1); - outline: none; - } - - input:focus-visible + & { - color: var(--sk-back-1); + opacity: 1; + outline-offset: -3px; } } @@ -363,6 +355,7 @@ It appears when the user clicks on the `Search` component or presses the corresp .info { padding: 1rem; + font-family: var(--sk-font-ui); font-size: 1.2rem; font-weight: normal; text-transform: uppercase; From 803454d269a5eca0be21bbd83357ca8d6192317e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 16:19:49 -0400 Subject: [PATCH 03/12] tweak styles --- .../src/routes/content.json/+server.ts | 1 + packages/site-kit/src/lib/actions/focus.ts | 2 +- .../site-kit/src/lib/search/SearchBox.svelte | 69 +---- .../src/lib/search/SearchResultList.svelte | 239 ++++++++++-------- packages/site-kit/src/lib/search/search.ts | 23 +- packages/site-kit/src/lib/search/types.d.ts | 5 + 6 files changed, 179 insertions(+), 160 deletions(-) diff --git a/apps/svelte.dev/src/routes/content.json/+server.ts b/apps/svelte.dev/src/routes/content.json/+server.ts index 65e5efbf18..169ba018da 100644 --- a/apps/svelte.dev/src/routes/content.json/+server.ts +++ b/apps/svelte.dev/src/routes/content.json/+server.ts @@ -31,6 +31,7 @@ async function content() { for (const document of docs) { const { slug, body, metadata } = document; + const breadcrumbs = document.breadcrumbs.map((x) => x.title); const sections = body.trim().split(/^## /m); const intro = sections?.shift()?.trim()!; diff --git a/packages/site-kit/src/lib/actions/focus.ts b/packages/site-kit/src/lib/actions/focus.ts index 1a9a6a36ab..15528e63ac 100644 --- a/packages/site-kit/src/lib/actions/focus.ts +++ b/packages/site-kit/src/lib/actions/focus.ts @@ -1,7 +1,7 @@ export function focusable_children(node: HTMLElement) { const nodes: HTMLElement[] = Array.from( node.querySelectorAll( - 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])' + 'a[href], button, input, textarea, select, [tabindex]:not([tabindex="-1"])' ) ); diff --git a/packages/site-kit/src/lib/search/SearchBox.svelte b/packages/site-kit/src/lib/search/SearchBox.svelte index aeb5368766..470f92f8d0 100644 --- a/packages/site-kit/src/lib/search/SearchBox.svelte +++ b/packages/site-kit/src/lib/search/SearchBox.svelte @@ -217,8 +217,7 @@ It appears when the user clicks on the `Search` component or presses the corresp {#each recent_searches as search}
  • navigate(search.href)} href={search.href}> - {search.breadcrumbs.join('/')} - {search.breadcrumbs.at(-1)} + {search.breadcrumbs.at(-1)} @@ -305,6 +306,10 @@ It appears when the user clicks on the `Search` component or presses the corresp opacity: 1; outline-offset: -3px; } + + kbd { + text-transform: uppercase; + } } ul { diff --git a/packages/site-kit/src/lib/search/SearchResultList.svelte b/packages/site-kit/src/lib/search/SearchResultList.svelte index ad8dfb7282..7d4952d142 100644 --- a/packages/site-kit/src/lib/search/SearchResultList.svelte +++ b/packages/site-kit/src/lib/search/SearchResultList.svelte @@ -81,7 +81,7 @@ &::after { content: ''; position: absolute; - right: 1rem; + right: 1.6rem; top: calc(50% - 1rem); width: 2rem; height: 2rem; From 0692e38ce3ebc40760feb5f0b07a5f72a086e6bd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 16:31:55 -0400 Subject: [PATCH 05/12] tweaks --- packages/site-kit/src/lib/search/SearchResultList.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/site-kit/src/lib/search/SearchResultList.svelte b/packages/site-kit/src/lib/search/SearchResultList.svelte index 7d4952d142..f13ca3cec4 100644 --- a/packages/site-kit/src/lib/search/SearchResultList.svelte +++ b/packages/site-kit/src/lib/search/SearchResultList.svelte @@ -70,7 +70,7 @@ position: sticky; top: 0; display: block; - background: var(--sk-back-1); + background: var(--sk-back-2); color: var(--sk-text-4); text-transform: uppercase; padding: 1rem 1rem 0.5rem 1rem; @@ -102,7 +102,7 @@ } a { - --background: var(--sk-back-1); + --background: var(--sk-back-2); display: block; text-decoration: none; line-height: 1; From b5e9b16dd32c883e9444eae8f88648bcdc974553 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 16:40:39 -0400 Subject: [PATCH 06/12] prettier --- packages/site-kit/src/lib/styles/base.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/site-kit/src/lib/styles/base.css b/packages/site-kit/src/lib/styles/base.css index 4e2a98e5d0..407970ab3a 100644 --- a/packages/site-kit/src/lib/styles/base.css +++ b/packages/site-kit/src/lib/styles/base.css @@ -146,7 +146,8 @@ blockquote :last-child { } /* buttons -------------------------------- */ -input, button { +input, +button { font-family: var(--sk-font-ui); font-size: inherit; } From d399a394921e344b3419cb2683cf07d0fcb14d9b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 17:11:04 -0400 Subject: [PATCH 07/12] fix keyboard activation --- packages/site-kit/src/lib/search/Search.svelte | 3 ++- packages/site-kit/src/lib/search/SearchBox.svelte | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/site-kit/src/lib/search/Search.svelte b/packages/site-kit/src/lib/search/Search.svelte index e59992d097..bde300397c 100644 --- a/packages/site-kit/src/lib/search/Search.svelte +++ b/packages/site-kit/src/lib/search/Search.svelte @@ -12,9 +12,10 @@ Renders a search widget which when clicked (or the corresponding keyboard shortc { - $searching = true; $search_query = e.currentTarget.value; + $searching = true; e.currentTarget.value = ''; + e.currentTarget.blur(); }} onmousedown={(event) => { event.preventDefault(); diff --git a/packages/site-kit/src/lib/search/SearchBox.svelte b/packages/site-kit/src/lib/search/SearchBox.svelte index a564422e80..94ca423782 100644 --- a/packages/site-kit/src/lib/search/SearchBox.svelte +++ b/packages/site-kit/src/lib/search/SearchBox.svelte @@ -75,6 +75,8 @@ It appears when the user clicks on the `Search` component or presses the corresp document.body.focus(); document.body.removeAttribute('tabindex'); window.scrollTo(0, scroll); + + $search_query = ''; } search = null; @@ -110,11 +112,8 @@ It appears when the user clicks on the `Search` component or presses the corresp document.body.style.position = 'fixed'; $overlay_open = true; - resetSearchQuery(); } }); - - const resetSearchQuery = () => ($search_query = ''); Date: Tue, 1 Oct 2024 17:32:26 -0400 Subject: [PATCH 08/12] various --- .../src/routes/content.json/+server.ts | 2 +- .../site-kit/src/lib/icons/document-dark.svg | 20 +++++++++ .../site-kit/src/lib/icons/document-light.svg | 20 +++++++++ packages/site-kit/src/lib/icons/hash-dark.svg | 23 ++++++++++ .../site-kit/src/lib/icons/hash-light.svg | 23 ++++++++++ .../src/lib/search/SearchResultList.svelte | 43 ++++++++++++++++--- packages/site-kit/src/lib/search/index.ts | 2 +- packages/site-kit/src/lib/search/search.ts | 29 +------------ packages/site-kit/src/lib/search/types.d.ts | 7 --- 9 files changed, 126 insertions(+), 43 deletions(-) create mode 100644 packages/site-kit/src/lib/icons/document-dark.svg create mode 100644 packages/site-kit/src/lib/icons/document-light.svg create mode 100644 packages/site-kit/src/lib/icons/hash-dark.svg create mode 100644 packages/site-kit/src/lib/icons/hash-light.svg diff --git a/apps/svelte.dev/src/routes/content.json/+server.ts b/apps/svelte.dev/src/routes/content.json/+server.ts index 169ba018da..cd0c458328 100644 --- a/apps/svelte.dev/src/routes/content.json/+server.ts +++ b/apps/svelte.dev/src/routes/content.json/+server.ts @@ -31,7 +31,7 @@ async function content() { for (const document of docs) { const { slug, body, metadata } = document; - const breadcrumbs = document.breadcrumbs.map((x) => x.title); + const breadcrumbs = document.breadcrumbs.map((x) => removeMarkdown(x.title)); const sections = body.trim().split(/^## /m); const intro = sections?.shift()?.trim()!; diff --git a/packages/site-kit/src/lib/icons/document-dark.svg b/packages/site-kit/src/lib/icons/document-dark.svg new file mode 100644 index 0000000000..6b610950eb --- /dev/null +++ b/packages/site-kit/src/lib/icons/document-dark.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + diff --git a/packages/site-kit/src/lib/icons/document-light.svg b/packages/site-kit/src/lib/icons/document-light.svg new file mode 100644 index 0000000000..68cfbd95c0 --- /dev/null +++ b/packages/site-kit/src/lib/icons/document-light.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + diff --git a/packages/site-kit/src/lib/icons/hash-dark.svg b/packages/site-kit/src/lib/icons/hash-dark.svg new file mode 100644 index 0000000000..8b1a0bf688 --- /dev/null +++ b/packages/site-kit/src/lib/icons/hash-dark.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/packages/site-kit/src/lib/icons/hash-light.svg b/packages/site-kit/src/lib/icons/hash-light.svg new file mode 100644 index 0000000000..205fd7882f --- /dev/null +++ b/packages/site-kit/src/lib/icons/hash-light.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/packages/site-kit/src/lib/search/SearchResultList.svelte b/packages/site-kit/src/lib/search/SearchResultList.svelte index f13ca3cec4..227209943b 100644 --- a/packages/site-kit/src/lib/search/SearchResultList.svelte +++ b/packages/site-kit/src/lib/search/SearchResultList.svelte @@ -43,8 +43,12 @@