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

Rewrite search #298

Merged
merged 1 commit into from
Sep 9, 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
4 changes: 1 addition & 3 deletions lib/rdoc/generator/template/rails/_head.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
<link rel="stylesheet" href="/css/highlight.css" type="text/css" media="screen" />

<script src="/js/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="/js/main.js" type="text/javascript"></script>
<script src="/js/main.js" type="module"></script>
<script src="/js/@hotwired--turbo.js" type="module"></script>
<script src="/js/search_index.js" type="text/javascript"></script>
<script src="/js/searcher.js" type="text/javascript"></script>
<script src="/panel/tree.js" type="text/javascript"></script>
<script src="/js/searchdoc.js" type="text/javascript"></script>
<meta name="data-tree-keys" content='<%= tree_keys %>'>
Expand Down
9 changes: 4 additions & 5 deletions lib/rdoc/generator/template/rails/_panel.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
<input id="panel__state" type="checkbox">

<div id="panel__tray" class="panel__tray" data-turbo-permanent>
<input id="search" type="text" autocomplete="off" tabindex="-1" autosave="searchdoc" results="10"
<input id="search" class="panel__search" type="text"
tabindex="-1" autocomplete="off" autosave="searchdoc"
placeholder="Search (/) for a class, method, ...">

<div id="results" class="panel__results"></div>

<div class="panel__tree">
<div class="result hidden">
<ul>
</ul>
</div>
<div class="tree">
<ul>
</ul>
Expand Down
160 changes: 123 additions & 37 deletions lib/rdoc/generator/template/rails/resources/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ a {
}
}

a:has(> code:only-child) {
a:has(> code):not(:has(> :not(code))) {
text-decoration: none;
}

Expand All @@ -67,10 +67,6 @@ a code {
background-size: 1.1em;
}

.hidden {
display: none;
}

.kind {
font-family: monospace;
font-weight: bold;
Expand Down Expand Up @@ -199,7 +195,9 @@ a.back-to-top.show {
*/

html {
--panel-width: 100dvw;
--banner-height: 3.5rem;
--search-height: calc(0.70 * var(--banner-height));
scroll-padding-top: calc(var(--banner-height) + 1rem);
}

Expand All @@ -208,14 +206,18 @@ html {
top: 0;
left: 0;
z-index: 90;
width: 100dvw;
width: var(--panel-width);
}

#panel__state {
display: none;
}


/*
* Navigation panel - Banner
*/

.banner {
height: var(--banner-height);
background-color: var(--brand-color);
Expand Down Expand Up @@ -257,24 +259,25 @@ html {
}


/*
* Navigation panel - Tray
*/

.panel__tray {
background: var(--body-bg);

position: fixed;
top: var(--banner-height);
width: inherit;
position: absolute;

overflow-y: hidden;
transition: max-height 0.2s ease-in-out;
max-height: 0;
transition: height 0.2s ease-in-out;
height: 0;
}

#panel__state:checked ~ .panel__tray {
max-height: 100dvh;
height: 100dvh;
}

#search {
height: calc(0.70 * var(--banner-height));
.panel__search {
height: var(--search-height);
width: 100%;

background: url('../i/search.svg') no-repeat;
Expand All @@ -284,51 +287,133 @@ html {
color: inherit;

border: 0;
box-shadow: -1px 1px 3px rgba(0, 0, 0, 0.2);
box-shadow: 1px 1px 4px color-mix(in srgb, currentColor 50%, transparent) inset;
}

.panel__tree {
height: calc(100dvh - 1.70 * var(--banner-height));
overflow-x: hidden;
.panel__results, .panel__tree {
position: relative;
height: calc(100dvh - var(--banner-height) - var(--search-height));
width: var(--panel-width);
transition: opacity 0.15s ease-in-out;

overflow-y: auto;
overscroll-behavior: contain;
}

/* Always contain scroll events in .panel__tree (on mobile) */
.panel__tree .tree {
height: calc(100% + 1px);
/* Force scrolling in order to always contain scroll events (on mobile) */
:is(.panel__results, .panel__tree)::after {
content: "";
height: 1px;
width: 1px;
position: absolute;
bottom: -1px;
z-index: -1;
}

.panel__results:not(.active),
.panel__search:placeholder-shown ~ .panel__results,
.panel__search:not(:placeholder-shown) ~ .panel__results.active ~ .panel__tree {
/* `display: none` disables animations, so simulate it instead */
max-height: 0;
max-width: 0;
padding: 0;

opacity: 0;
}

.panel__tree .result:not(.hidden) ~ .tree {
display: none;
.panel__tree {
overflow-x: hidden;
}


@media (min-width: 600px) {
html {
scroll-padding-top: 1rem;
/*
* Navigation panel - Search results
*/

.panel__results {
font-size: 0.95em;
padding: var(--space) var(--space-sm);
scroll-padding: var(--space) 0;
}

.panel__results:empty::before {
content: "No results.";
font-style: italic;
}

.results__result:not(:first-child) {
margin-top: var(--space-lg);
}

.results__result {
border-left: 5px solid color-mix(in srgb, currentColor 10%, transparent);
border-radius: 5px;
padding-left: var(--space-sm);
}

/* Assume physical keyboard exists when not `pointer: coarse` */
@media not (pointer: coarse) {
.results__result.cursor {
border-color: var(--link-color);
}
}

#panel {
height: 0;
width: 300px;
@media (hover: hover) {
.results__result:has(.result__link:hover) {
border-color: var(--link-hover-color);
}
}

#content {
margin-left: 300px;
.result__link {
display: flex;
flex-direction: column;
}

.result__method {
display: flex;
}

.result__method::before {
content: "\221F";
font-size: 1.25em;
margin: -0.3em 0.2em;
color: var(--text-color);
}

.result__summary {
margin: var(--space-sm) 0 0 0;
}

:is(.result__method, .result__summary):empty {
display: none;
}


/*
* Navigation panel on desktop
*/

@media (min-width: 600px) {
html {
--panel-width: 300px;
scroll-padding-top: 1rem;
}

.banner__segment:first-child {
display: none;
}

.panel__tray {
min-height: 100dvh;
height: unset;
border-right: 1px solid color-mix(in srgb, currentColor 25%, transparent);
}

.panel__tree .tree {
height: unset;
.panel__results.active {
width: 60ch;
}

:is(.panel__results, .panel__tree)::after {
display: none;
}
}

Expand All @@ -343,6 +428,8 @@ html {

@media (min-width: 600px) {
#content {
margin-top: calc(-1 * var(--banner-height));
margin-left: var(--panel-width);
padding: var(--space-lg) var(--space-xl);
}
}
Expand Down Expand Up @@ -555,8 +642,7 @@ html {
font-style: italic;
}

.description pre,
.description p code {
.description :is(code, pre) {
background: var(--code-bg);
}

Expand Down
Loading