Skip to content

Commit d99b7d9

Browse files
Revathyvenugopal162pyansys-ci-botjorgepiloto
authored
feat: implement default search bar expansion behavior (#496)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Jorge Martínez <[email protected]>
1 parent 1156b8d commit d99b7d9

File tree

11 files changed

+352
-181
lines changed

11 files changed

+352
-181
lines changed

doc/changelog.d/496.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: implement default search bar expansion behavior

src/ansys_sphinx_theme/search/fuse_search.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ def create_search_index(app, exception):
100100
if exception:
101101
return
102102

103-
if not app.config.html_theme_options.get("static_search", {}):
104-
return
105-
106103
switcher_version = app.config.html_theme_options.get("switcher", {}).get("version_match", "")
107104
version_url_prefix = f"version/{switcher_version}/" if switcher_version else ""
108105

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
<link rel="stylesheet" href="{{ pathto('_static/css/fuse-search.css', 1) }}">
3+
4+
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
6+
7+
{% set theme_static_search = theme_static_search | default({}) %}
8+
{% set theme_limit = theme_static_search.limit | default(10) %}
9+
{% set min_chars_for_search = theme_static_search.min_chars_for_search | default(1) %}
10+
11+
<script>
12+
var theme_static_search = JSON.parse('{{ theme_static_search | tojson | safe }}');
13+
var theme_limit = "{{ theme_limit }}";
14+
var min_chars_for_search = "{{ min_chars_for_search }}";
15+
16+
</script>
17+
18+
<script src="{{ pathto('_static/js/fuse_search.js', 1) }}"></script>
19+
<script src="{{ pathto('_static/js/fuse_extension.js', 1) }}"></script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
<div class="search-bar" id="search-bar">
3+
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
4+
<i class="fa-solid fa-magnifying-glass"></i>
5+
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
6+
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
7+
autocapitalize="off" spellcheck="false"/>
8+
<span class="search-button__kbd-shortcut">
9+
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
10+
</span>
11+
</form>
12+
<!-- Search results container -->
13+
<div id="results" class="results" style="display: none;" tabindex="0">
14+
</div>

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/components/search-field.html

Lines changed: 0 additions & 149 deletions
This file was deleted.
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
{%- extends "pydata_sphinx_theme/layout.html" -%} {# Append our custom CSS after
2-
the bootstrap stylesheet so we can override where necessary #} {%- block css %}
3-
{{ super() }} {% if theme_show_breadcrumbs %}
4-
<link href="{{ pathto('_static/css/breadcrumbs.css', 1) }}" rel="stylesheet" />
5-
{% endif %} {%- endblock %}{% block docs_navbar %} {{ super() }} {% if
6-
theme_switcher %} {% include 'components/announcement_version.html' %} {% endif
7-
%} {% endblock %}
1+
{%- extends "pydata_sphinx_theme/layout.html" -%}
2+
3+
{# Append our custom CSS after the bootstrap stylesheet so we can override where necessary #}
4+
{%- block css %}
5+
{{ super() }}
6+
{% if theme_show_breadcrumbs %}
7+
<link href="{{ pathto('_static/css/breadcrumbs.css', 1) }}" rel="stylesheet" />
8+
{% endif %}
9+
{%- endblock %}
10+
11+
{% block docs_navbar %}
12+
{{ super() }}
13+
{% if theme_switcher %}
14+
{% include 'components/announcement_version.html' %}
15+
{% endif %}
16+
{% endblock %}
17+
18+
{%- block content %}
19+
{{ super() }}
20+
{%- include "components/ast-search-button.html" %}
21+
{%- endblock %}

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/search.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/fuse-search.css

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
.results {
2-
margin-top: 3rem !important;
32
display: flex;
43
flex-direction: column;
5-
flex-wrap: wrap;
64
align-content: flex-start;
75
justify-content: center;
86
position: absolute;
97
background-color: white;
10-
width: 800px;
11-
padding: 0 10px;
8+
width: 700px;
9+
padding: 10px;
1210
border: 1px solid #ddd; /* Optional: Add border for better visibility */
1311
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Optional: Add shadow for better visibility */
12+
overflow: auto;
13+
height: 500px;
1414
}
1515
.search-button__wrapper.show .search-button__search-container {
1616
overflow: auto;
1717
}
1818
.result-item {
1919
margin-bottom: 1rem;
2020
cursor: pointer; /* Indicate that the item is clickable */
21+
transition: box-shadow 0.3s ease; /* Smooth transition */
2122
}
2223

2324
.result-title {
@@ -27,12 +28,37 @@
2728
font-family: "Open Sans", sans-serif;
2829
}
2930

31+
.result-title:focus,
32+
.result-title:focus-visible,
33+
.result-text:focus,
34+
.result-text:focus-visible {
35+
box-shadow: var(--ast-ring-shadow-focused);
36+
}
37+
38+
.result-item.selected {
39+
box-shadow: var(--ast-ring-shadow-focused);
40+
}
41+
3042
.result-text {
3143
font-size: 12px;
3244
font-family: "Open Sans", sans-serif;
3345
color: var(--ast-search-bar-enable-text);
3446
}
3547

48+
.result-item:focus-visible,
49+
.result-item:focus {
50+
outline: none; /* Remove default focus outline */
51+
cursor: pointer;
52+
box-shadow: var(--ast-ring-shadow-focused);
53+
z-index: 1;
54+
}
55+
56+
.result-item:hover {
57+
background-color: var(
58+
--ast-color-hover-card-background
59+
); /* Background when hovered */
60+
}
61+
3662
.no-results {
3763
font-style: italic;
3864
color: #777;
@@ -51,29 +77,22 @@ html[data-theme="light"] .highlight {
5177
color: var(--ast-search-bar-enable-text);
5278
font-size: 14px;
5379
outline-color: var(--ast-search-bar-enable-border);
54-
border: 0.5px solid var(--ast-search-bar-enable-border);
55-
width: 670px;
80+
border: 0px solid var(--ast-search-bar-enable-border);
81+
width: 300px;
82+
transition: max-width 0.3s ease;
5683
max-width: 200%;
5784
height: 40px;
58-
margin-left: 5px;
5985
}
6086

6187
.search-button__wrapper.show input,
6288
.search-button__wrapper.show svg {
6389
font-size: 14px;
6490
}
6591

66-
.bd-search {
67-
gap: 8px;
68-
background-color: var(--ast-search-bar-enable-background);
69-
border: 0px solid var(--ast-search-bar-enable-border);
70-
margin-bottom: 300px;
71-
}
72-
7392
.bd-search .search-button__kbd-shortcut {
7493
background-color: var(--ast-search-bar-enable-background) !important;
7594
box-shadow: none !important;
76-
height: 40px;
95+
height: 36px;
7796
display: flex;
7897
flex-wrap: wrap;
7998
align-content: center;
@@ -105,3 +124,39 @@ html[data-theme="light"] .highlight {
105124
.form-control:focus {
106125
box-shadow: none;
107126
}
127+
128+
/* Button Styling */
129+
.search-button__button {
130+
transition: width 0.3s ease;
131+
width: 50px; /* Initial width */
132+
}
133+
134+
/* Result Container Styling */
135+
.bd-search {
136+
gap: 8px;
137+
background-color: var(--ast-search-bar-enable-background);
138+
border: 1px solid var(--ast-search-bar-enable-border);
139+
margin-bottom: 0px;
140+
}
141+
142+
@media (max-width: 768px) {
143+
.form-control:focus,
144+
.form-control:focus-visible,
145+
.form-control {
146+
width: 100px;
147+
}
148+
.bd-search input.expanded {
149+
width: 200px;
150+
}
151+
.bd-search .search-button__kbd-shortcut {
152+
display: none;
153+
}
154+
}
155+
156+
.bd-search input.expanded {
157+
width: 600px;
158+
}
159+
160+
.search-icon {
161+
cursor: pointer;
162+
}

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/pydata-sphinx-theme-custom.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ a.headerlink {
277277
*/
278278
.bd-header .navbar-header-items__start {
279279
width: fit-content;
280-
padding-right: 3rem;
280+
padding-right: 2rem;
281281
}
282282
/**
283283
* header logo

0 commit comments

Comments
 (0)