Skip to content

Build your personal knowledge base with Trilium Notes

refactor(quick_search): move styles into quick_search.css

Elian Dorane9ba13048916
diff --git a/apps/client/src/widgets/quick_search.css b/apps/client/src/widgets/quick_search.css
new file mode 100644
index 0000000000..445aee4406
--- /dev/null
+++ b/apps/client/src/widgets/quick_search.css
@@ -0,0 +1,136 @@
+.quick-search {
+ padding: 10px 10px 10px 0px;
+ height: 50px;
+
+ button, .search-string {
+ border: 0;
+ font-size: 100% !important;
+ }
+
+ .search-string {
+ display: flex;
+ align-items: center;
+ min-width: 0;
+
+ .cm-editor {
+ width: 100%;
+ }
+
+ /* Overrides the shared `pre-wrap`, which wraps a long query and grows the field. */
+ .cm-line {
+ white-space: pre;
+ }
+ }
+
+ .dropdown-menu {
+ --quick-search-item-delimiter-color: var(--dropdown-border-color);
+
+ max-height: 80vh;
+ min-width: 400px;
+ max-width: 720px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ box-shadow: -30px 50px 93px -50px black;
+
+ /* Bootstrap opens the menu by setting `display`, so the column layout applies only to `.show`. */
+ &.show {
+ display: flex;
+ flex-direction: column;
+ }
+ }
+
+ .quick-search-results {
+ flex: 1 1 auto;
+ min-height: 0;
+ overflow-y: auto;
+ overflow-x: hidden;
+ }
+
+ .quick-search-footer {
+ flex: 0 0 auto;
+ }
+
+ .dropdown-item {
+ white-space: normal;
+ padding: 12px 16px;
+ line-height: 1.4;
+ position: relative;
+
+ & + .dropdown-item::after {
+ content: '';
+ position: absolute;
+ inset-inline-start: 0;
+ top: 0;
+ width: 100%;
+ height: 1px;
+ border-bottom: 1px solid var(--quick-search-item-delimiter-color);
+ }
+
+ &:last-child::after,
+ &.disabled::after {
+ display: none;
+ }
+
+ /* Hover and keyboard focus share the active-item fill used by other menus. */
+ &:not(.disabled):hover,
+ &:not(.disabled):focus {
+ background-color: var(--active-item-background-color);
+ color: var(--active-item-text-color);
+ outline: none;
+ }
+ }
+
+ .quick-search-item {
+ width: 100%;
+ }
+
+ .quick-search-item-header {
+ padding: 0 8px;
+ }
+
+ .quick-search-item-icon {
+ margin-inline-end: 2px;
+ }
+
+ .search-result-title {
+ font-weight: 500;
+ }
+
+ .search-result-attributes {
+ opacity: .5;
+ padding: 0 8px;
+ font-size: .75em;
+ }
+
+ .search-result-content {
+ margin-top: 8px;
+ padding: 8px;
+ background-color: var(--accented-background-color);
+ color: var(--main-text-color);
+ font-size: .85em;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ /* Uses the same highlight variables as SearchResultsList.css and ListOrGridView.css. */
+ :is(.search-result-title, .search-result-content, .search-result-attributes) b {
+ background: var(--note-list-view-search-result-highlight-background, transparent);
+ color: var(--note-list-view-search-result-highlight-color, var(--admonition-warning-accent-color));
+ font-weight: 600;
+ text-decoration: underline;
+
+ &.search-fuzzy-match {
+ color: var(--quick-search-result-fuzzy-highlight-color, #e47b19);
+ font-weight: 400;
+ text-decoration: underline dotted;
+ }
+ }
+
+ .dropdown-divider {
+ margin: 0;
+ }
+
+ .bx-loader {
+ margin-inline-end: 4px;
+ }
+}
diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsx
index fb2185b8dd..92c931373d 100644
--- a/apps/client/src/widgets/quick_search.tsx
+++ b/apps/client/src/widgets/quick_search.tsx
@@ -1,3 +1,5 @@
+import "./quick_search.css";
+
export default function QuickSearch() {
return <div className="quick-search">Hello world</div>;
}
diff --git a/apps/client/src/widgets/quick_search_old.ts b/apps/client/src/widgets/quick_search_old.ts
index 7119ff3b0a..650e4cf0f1 100644
--- a/apps/client/src/widgets/quick_search_old.ts
+++ b/apps/client/src/widgets/quick_search_old.ts
@@ -13,157 +13,6 @@ import { createSearchFieldEditor, SEARCH_FIELD_EDITOR_CLASS } from "./search_fie
const TPL = /*html*/`
<div class="quick-search input-group input-group-sm">
- <style>
- .quick-search {
- padding: 10px 10px 10px 0px;
- height: 50px;
- }
-
- .quick-search button, .quick-search .search-string {
- border: 0;
- font-size: 100% !important;
- }
-
- .quick-search .search-string {
- display: flex;
- align-items: center;
- min-width: 0;
- }
-
- .quick-search .search-string .cm-editor {
- width: 100%;
- }
-
- /* Outweighs the pre-wrap the shared stylesheet sets, which would wrap a long query onto a
- second visual line and grow the field. */
- .quick-search .search-string .cm-line {
- white-space: pre;
- }
-
- .quick-search .dropdown-menu {
- --quick-search-item-delimiter-color: var(--dropdown-border-color);
-
- max-height: 80vh;
- min-width: 400px;
- max-width: 720px;
- overflow: hidden;
- text-overflow: ellipsis;
- box-shadow: -30px 50px 93px -50px black;
- }
-
- /* Bootstrap opens the menu by switching display, so the column only applies to the open menu. */
- .quick-search .dropdown-menu.show {
- display: flex;
- flex-direction: column;
- }
-
- .quick-search .quick-search-results {
- flex: 1 1 auto;
- min-height: 0;
- overflow-y: auto;
- overflow-x: hidden;
- }
-
- .quick-search .quick-search-footer {
- flex: 0 0 auto;
- }
-
- .quick-search .dropdown-item {
- white-space: normal;
- padding: 12px 16px;
- line-height: 1.4;
- position: relative;
- }
-
- .quick-search .dropdown-item + .dropdown-item::after {
- content: '';
- position: absolute;
- inset-inline-start: 0;
- top: 0;
- width: 100%;
- height: 1px;
- border-bottom: 1px solid var(--quick-search-item-delimiter-color);
- }
-
- .quick-search .dropdown-item:last-child::after {
- display: none;
- }
-
- .quick-search .dropdown-item.disabled::after {
- display: none;
- }
-
- /* Mouse hover and the ArrowDown keyboard selection share the "active item" fill the rest
- of the menus use, so pointing at a result and arrowing to it look the same. */
- .quick-search .dropdown-item:not(.disabled):hover,
- .quick-search .dropdown-item:not(.disabled):focus {
- background-color: var(--active-item-background-color);
- color: var(--active-item-text-color);
- outline: none;
- }
-
- .quick-search .quick-search-item {
- width: 100%;
- }
-
- .quick-search .quick-search-item-header {
- padding: 0 8px;
- }
-
- .quick-search .quick-search-item-icon {
- margin-inline-end: 2px;
- }
-
- .quick-search .search-result-title {
- font-weight: 500;
- }
-
- .quick-search .search-result-attributes {
- opacity: .5;
- padding: 0 8px;
- font-size: .75em;
- }
-
- .quick-search .search-result-content {
- margin-top: 8px;
- padding: 8px;
- background-color: var(--accented-background-color);
- color: var(--main-text-color);
- font-size: .85em;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- /* Search result highlighting: point at the same highlight vars the snippet cards
- (SearchResultsList.css / ListOrGridView.css) use, falling back to the pre-existing
- colors if a theme hasn't defined them. */
- .quick-search .search-result-title b,
- .quick-search .search-result-content b,
- .quick-search .search-result-attributes b {
- background: var(--note-list-view-search-result-highlight-background, transparent);
- color: var(--note-list-view-search-result-highlight-color, var(--admonition-warning-accent-color));
- font-weight: 600;
- text-decoration: underline;
- }
-
- .quick-search .search-result-title b.search-fuzzy-match,
- .quick-search .search-result-content b.search-fuzzy-match,
- .quick-search .search-result-attributes b.search-fuzzy-match {
- color: var(--quick-search-result-fuzzy-highlight-color, #e47b19);
- font-weight: 400;
- text-decoration: underline dotted;
- }
-
- .quick-search .dropdown-divider {
- margin: 0;
- }
-
- .quick-search .bx-loader {
- margin-inline-end: 4px;
- }
-
- </style>
-
<div class="input-group-prepend">
<button class="btn btn-outline-secondary search-button" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="bx bx-search"></span>