Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "sidebar UI changes (#341)" #384

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 63 additions & 100 deletions public/style.css
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
:root {
--theme-background: rgb(255, 255, 255);
--theme-background-alt: rgb(255, 255, 255);
--theme-foreground: #1C1C1C;
--theme-foreground-highlight: #001B440D;
--theme-background-alt: color-mix(in srgb, var(--theme-background) 95%, black);
--theme-foreground: rgb(27, 30, 35);
--theme-foreground-alt: color-mix(in srgb, var(--theme-foreground) 90%, var(--theme-background));
--theme-foreground-muted: color-mix(in srgb, var(--theme-foreground) 70%, var(--theme-background));
--theme-foreground-faint: color-mix(in srgb, var(--theme-foreground) 50%, var(--theme-background));
--theme-foreground-fainter: color-mix(in srgb, var(--theme-foreground) 30%, var(--theme-background));
--theme-foreground-faintest: #E2E2E2;
--theme-foreground-focus: #3B5FC0;
--theme-foreground-faintest: color-mix(in srgb, var(--theme-foreground) 10%, var(--theme-background));
--theme-foreground-focus: #3182bd;
--monospace: Menlo, Consolas, monospace;
--monospace-font: 14px/1.5 var(--monospace);
--serif: "Source Serif Pro", "Iowan Old Style", "Apple Garamond", "Palatino Linotype", "Times New Roman", "Droid Serif", Times, serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
--sans-serif: -apple-system, BlinkMacSystemFont, "avenir next", avenir, helvetica, "helvetica neue", ubuntu, roboto, noto, "segoe ui", arial, sans-serif;
color-scheme: light dark;

--black-dark-gray: #454545;
--black-light-gray: #E2E2E2;
--black-mid-gray: #6E6E6E;
--black-near-black: #1C1C1C;
--black-white: #FFFFFF;
--blue-blue: #3B5FC0;

--down-caret: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M5 7L8.125 9.5L11.25 7' stroke='%23454545' stroke-width='1.5' stroke-linecap='round' fill='none'/%3E%3C/svg%3E");
--sidebar-toggle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m10.5,11 2.5-3-2.5-3 M6,8h7' fill='none' stroke='%23929292' stroke-width='2'/%3E%3Crect x='2' y='2' fill='%23929292' height='12' rx='.5' width='2'/%3E%3C/svg%3E");
--sidebar-toggle-close: translate(0,-5px) rotate(180deg);
}

@media (prefers-color-scheme: dark) {
:root {
--theme-foreground: rgb(223, 223, 214);
--theme-foreground-highlight: rgba(218, 228, 255, 0.10);
--theme-foreground-faintest: color-mix(in srgb, var(--theme-foreground) 10%, var(--theme-background));
--theme-background: rgb(31, 31, 31);
--theme-background-alt: color-mix(in srgb, var(--theme-background) 70%, black);
--theme-foreground-focus: #20bbfc;
Expand Down Expand Up @@ -92,6 +78,9 @@ body {
font-size: 14px;
}

#observablehq-footer nav a:hover span {
text-decoration: underline;
}

#observablehq-footer nav a:hover {
border-color: var(--theme-foreground-focus);
Expand Down Expand Up @@ -126,16 +115,15 @@ body {
#observablehq-sidebar {
position: fixed;
background: var(--theme-background-alt);
border-right: 1px solid var(--theme-foreground-faintest);
color: var(--theme-foreground-muted);
font: 14px var(--sans-serif);
font-weight: 400;
width: 272px;
font-weight: 500;
width: 240px;
z-index: 2;
top: 0;
bottom: 0;
left: calc(-272px - 2rem);
padding: 1rem 0;
left: calc(-240px - 2rem);
padding: 1rem;
overflow-y: auto;
}

Expand All @@ -146,51 +134,34 @@ body {
padding: 0;
}

#observablehq-sidebar > ol:first-child {
border-top: none;
font-weight: 700;
margin: 0;
color: var(--theme-foreground);
#observablehq-sidebar > ol,
#observablehq-sidebar > details {
position: relative;
padding: 0.5rem 0 0;
margin: 0.5rem 0;
}

#observablehq-sidebar ol {
padding: 8px 8px 8px 4px;
padding-bottom: 1rem;
}

#observablehq-sidebar > ol,
#observablehq-sidebar > details {
position: relative;
}

#observablehq-sidebar > details {
border-top: solid 1px var(--theme-foreground-faintest);
}

#observablehq-sidebar > details:last-of-type {
border-bottom: solid 1px var(--theme-foreground-faintest);
}

#observablehq-sidebar details[open] summary:after {
transform: rotate(180deg);
}

#observablehq-sidebar details .observablehq-link a {
display: block;
padding: 8px 8px 8px 16px;
#observablehq-sidebar > ol:first-child {
border-top: none;
font-weight: 700;
padding: 0;
margin: 0;
color: var(--theme-foreground);
}


#observablehq-sidebar summary {
display: block;
font-weight: 400;
font-weight: 700;
color: var(--theme-foreground);
cursor: pointer;
padding: 8px 8px 8px 16px;
margin: 8px 0;
}

#observablehq-sidebar details[open] summary {
margin-bottom: 0;
}

#observablehq-sidebar summary::-webkit-details-marker,
Expand All @@ -202,68 +173,62 @@ body {
position: absolute;
right: 1rem;
margin-top: -0.25rem;
content: var(--down-caret);
font-weight: 700;
font-size: 20px;
content: "⟩";
transition: transform 250ms ease;
transform-origin: 50% 50%;
color: var(--theme-foreground-muted);
}

/* TODO - change hover behavior */
#observablehq-sidebar summary:hover::after {
color: var(--theme-foreground);
}


.observablehq-link a {
display: block;
padding: 8px 8px 8px 12px;
cursor: pointer;
#observablehq-sidebar details[open] summary:after {
transform: rotate(90deg);
}

#observablehq-sidebar-toggle {
position: fixed;
top: calc(1rem + 7px);
left: 235px;
height: 33px;
width: 29px;
top: 0;
left: 0;
height: 100%;
width: 1rem;
appearance: none;
display: flex;
align-items: center;
justify-content: center;
margin: 0;
padding: 4px;
padding: 2px;
cursor: pointer;
z-index: 3;
background: none;
color: var(--theme-foreground-muted);
font-weight: 700;
font-size: 20px;
}

#observablehq-sidebar-toggle::before {
content: var(--sidebar-toggle);
content: "⟩";
}

#observablehq-sidebar-toggle:checked::before {
transform: var(--sidebar-toggle-close);
content: "⟨";
}

#observablehq-sidebar-toggle:not(:checked):not(:indeterminate) {
top: 0;
left: 0;
height: 100%;
align-items: center;
#observablehq-sidebar summary,
.observablehq-link a {
display: block;
padding: 0.5rem 1rem;
}

@media (max-width: calc(640px + 4rem + 272px + 2rem)) {
#observablehq-sidebar-toggle {
transition: left 300ms ease;
}
#observablehq-sidebar-toggle:indeterminate {
top: 0;
left: 0;
height: 100%;
display: flex;
align-items: center;
}
#observablehq-sidebar summary:hover,
.observablehq-link a:hover {
background: var(--theme-background);
}


.observablehq-link a[href]:hover {
.observablehq-link a:hover {
color: var(--theme-foreground-focus);
}

Expand Down Expand Up @@ -302,10 +267,6 @@ body {
color: inherit;
}

.observablehq-link-active {
background: var(--theme-foreground-highlight)
}

.observablehq-link-active,
.observablehq-secondary-link-active {
position: relative;
Expand All @@ -315,14 +276,14 @@ body {
.observablehq-secondary-link-highlight {
content: "";
position: absolute;
width: 4px;
width: 3px;
background: var(--theme-foreground-focus);
}

.observablehq-link-active::before {
top: 0;
bottom: 0;
left: -4px;
left: -1rem;
}

.observablehq-secondary-link-highlight {
Expand All @@ -344,7 +305,7 @@ a[href],
}

#observablehq-sidebar {
transition: left 300ms ease;
transition: left 150ms ease;
}

#observablehq-sidebar-backdrop {
Expand All @@ -367,12 +328,12 @@ a[href],
}
}

@media (min-width: calc(640px + 4rem + 272px + 2rem)) {
@media (min-width: calc(640px + 4rem + 240px + 2rem)) {
#observablehq-sidebar {
transition: none;
}
#observablehq-sidebar-toggle:indeterminate::before {
transform: var(--sidebar-toggle-close);
content: "⟨";
}
#observablehq-sidebar-toggle:checked ~ #observablehq-sidebar-backdrop {
display: none;
Expand All @@ -384,7 +345,7 @@ a[href],
}
#observablehq-sidebar-toggle:checked ~ #observablehq-center,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-center {
padding-left: calc(272px + 3rem);
padding-left: calc(240px + 3rem);
padding-right: 1rem;
}
pre {
Expand All @@ -404,14 +365,14 @@ a[href],
}
}

@media (min-width: calc(640px + 4rem + 272px + 2rem)) {
@media (min-width: calc(640px + 4rem + 240px + 2rem)) {
#observablehq-sidebar-toggle:checked ~ #observablehq-toc,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc {
display: none;
}
}

@media (min-width: calc(640px + 4rem + 272px + 2rem + 160px + 2rem)) {
@media (min-width: calc(640px + 4rem + 240px + 2rem + 160px + 2rem)) {
#observablehq-sidebar-toggle:checked ~ #observablehq-toc,
#observablehq-sidebar-toggle:indeterminate ~ #observablehq-toc,
#observablehq-toc {
Expand All @@ -428,10 +389,9 @@ a[href],
#observablehq-sidebar-toggle:not(:checked):not(:hover)::before {
content: "";
}
@media (min-width: calc(640px + 4rem + 272px + 2rem)) {
@media (min-width: calc(640px + 4rem + 240px + 2rem)) {
#observablehq-sidebar-toggle:indeterminate:not(:checked):not(:hover)::before {
content: var(--sidebar-toggle);
transform: var(--sidebar-toggle-close);
content: "⟨";
}
}
}
Expand Down Expand Up @@ -504,6 +464,9 @@ a[href] {
text-decoration: none;
}

a[href]:hover {
text-decoration: underline;
}

h1 code,
h2 code,
Expand Down
2 changes: 1 addition & 1 deletion src/client/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const toggle = document.querySelector("#observablehq-sidebar-toggle");
if (toggle) {
let indeterminate = toggle.indeterminate;
toggle.onclick = () => {
const matches = matchMedia("(min-width: calc(640px + 17px * 4 + 272px + 17px * 2))").matches;
const matches = matchMedia("(min-width: calc(640px + 17px * 4 + 240px + 17px * 2))").matches;
if (indeterminate) (toggle.checked = !matches), (indeterminate = false);
else if (toggle.checked === matches) indeterminate = true;
toggle.indeterminate = indeterminate;
Expand Down
2 changes: 1 addition & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ${renderFooter(path, options)}
}

async function renderSidebar(title = "Home", pages: (Page | Section)[], path: string): Promise<Html> {
return html`<input id="observablehq-sidebar-toggle" type="checkbox" title="toggle sidebar">
return html`<input id="observablehq-sidebar-toggle" type="checkbox">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
<ol>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/archives/tar.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}});

</script>
<input id="observablehq-sidebar-toggle" type="checkbox" title="toggle sidebar">
<input id="observablehq-sidebar-toggle" type="checkbox">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
<ol>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/archives/zip.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}});

</script>
<input id="observablehq-sidebar-toggle" type="checkbox" title="toggle sidebar">
<input id="observablehq-sidebar-toggle" type="checkbox">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
<ol>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/closed/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import "../_observablehq/client.js";

</script>
<input id="observablehq-sidebar-toggle" type="checkbox" title="toggle sidebar">
<input id="observablehq-sidebar-toggle" type="checkbox">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
<ol>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import "./_observablehq/client.js";

</script>
<input id="observablehq-sidebar-toggle" type="checkbox" title="toggle sidebar">
<input id="observablehq-sidebar-toggle" type="checkbox">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
<ol>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import "./_observablehq/client.js";

</script>
<input id="observablehq-sidebar-toggle" type="checkbox" title="toggle sidebar">
<input id="observablehq-sidebar-toggle" type="checkbox">
<label id="observablehq-sidebar-backdrop" for="observablehq-sidebar-toggle"></label>
<nav id="observablehq-sidebar">
<ol>
Expand Down
Loading