Skip to content

Commit ca5519d

Browse files
CodeSandwichKrinkle
authored andcommitted
CSS: Add variables for listbox size
* Make the listbox size explicitly configurable with custom CSS variables. This includes the width and the height, but also a toggle for forcing the scaling of the listbox to the left. This should make the default CSS easily usable on pages with a wide range of search box locations. The demo page is updated to present this. * Remove the `@media` sections. They were very opinionated, the current approach is more flexible. The viewport width ranges didn't match each other, so there were actually 3 width ranges, each of them with a different set of CSS attributes. The result was that only in the wide viewport the listbox was flexible and good looking, and narrowing it caused glitches. * Move `.tsmb-form--slash::after` sections closer to each other, so it's easier to follow the slash icon behavior. * Clean up white spaces. Closes #2.
1 parent b86d70c commit ca5519d

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

API-Style.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Misc sizes:
2525
* `--tsmb-size-edge`: Line thickness of edges, e.g. border-width.
2626
* `--tsmb-size-radius`: Roundness, e.g. border-radius.
2727
* `--tsmb-size-highlight`: Line thickness of cursor highlight, e.g. border-left-width.
28+
* `--tsmb-size-listbox-width`: The maximum width of the listbox. The minimum is always the width of the input field.
29+
* `--tsmb-size-listbox-max-height`: The maximum height of the listbox.
30+
* `--tsmb-size-listbox-right`: Set to `0` to create a right-aligned listbox that expands to the left.
2831

2932
Base layout, for idle or inactive input field:
3033
* `--tsmb-color-base-background`: Background color, e.g. white in lightmode.
@@ -34,12 +37,12 @@ Base layout, for idle or inactive input field:
3437

3538
Active layout, for active input field and result box. Defaults to the same colors as above.
3639
* `--tsmb-color-focus-background`: Background color, e.g. white in lightmode.
37-
* `--tsmb-color-focus30`: Hard contrast (focussed input text).
38-
* `--tsmb-color-focus50`: Medium contrast (for search result excerpt, focussed placeholder, footer).
40+
* `--tsmb-color-focus30`: Hard contrast (focussed input text).
41+
* `--tsmb-color-focus50`: Medium contrast (for search result excerpt, focussed placeholder, footer).
3942
* `--tsmb-color-focus90`: Subtle contrast (for result borders).
4043

4144
Primary colors, by default only used in the active layout:
42-
* `--tsmb-color-primary30`: Hard contrast, for colorful dark background or dark text.
45+
* `--tsmb-color-primary30`: Hard contrast, for colorful dark background or dark text.
4346
* `--tsmb-color-primary50`: Medium contrast, for colorful links or buttons.
4447
* `--tsmb-color-primary90`: Subtle contrast, for selection background.
4548

demo/demo-theme.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ header > * {
2222
}
2323

2424
header .tsmb-form {
25+
width: 30em;
2526
--tsmb-color-base-background: #691c69;
2627
--tsmb-color-base30: var(--tsmb-color-primary90);
2728
--tsmb-color-base50: #c090c0;
2829
--tsmb-color-base90: #c090c0;
30+
--tsmb-size-listbox-width: calc(min(50rem, 80vw));
2931
}
3032
header .tsmb-form:not(:focus-within)::before {
3133
filter: invert();

demo/demo.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,9 @@ main {
6262

6363
.demo-right-form {
6464
margin-left: auto;
65+
--tsmb-size-listbox-right: 0;
6566
}
6667

67-
.demo-right-form [role="listbox"] {
68-
right: 0;
69-
}
70-
71-
7268
.demo-stylecontrol fieldset {
7369
background: #fff;
7470
}

typesense-minibar.css

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
--tsmb-size-sm: 0.8rem;
88
--tsmb-size-half: calc(var(--tsmb-size-sm)/2);
99
--tsmb-size-input: calc(var(--tsmb-size-base) * 1.2);
10+
--tsmb-size-listbox-right: auto;
11+
--tsmb-size-listbox-width: calc(min(30rem, 60vw));
12+
--tsmb-size-listbox-max-height: 70vh;
1013

1114
--tsmb-color-base-background: #fff;
1215
--tsmb-color-base30: #333;
@@ -51,9 +54,11 @@
5154
.tsmb-form:focus-within {
5255
color: var(--tsmb-color-focus30);
5356
}
57+
5458
.tsmb-form:focus-within input[type=search] {
5559
background: var(--tsmb-color-focus-background);
5660
}
61+
5762
.tsmb-form:focus-within input[type=search]::placeholder {
5863
color: var(--tsmb-color-focus50);
5964
}
@@ -100,6 +105,10 @@
100105
display: block !important;
101106
}
102107

108+
.tsmb-form--slash::after {
109+
display: none;
110+
}
111+
103112
.tsmb-form--slash:not(.tsmb-form--open):not(:focus-within)::after {
104113
content: '/';
105114
display: inline-block;
@@ -122,13 +131,16 @@
122131
.tsmb-form [role=listbox] {
123132
position: absolute;
124133
z-index: 10;
125-
134+
right: var(--tsmb-size-listbox-right);
126135
background: var(--tsmb-color-focus-background);
127136
color: var(--tsmb-color-focus30);
128-
width: 100%;
129-
max-height: 70vh;
137+
margin-top: var(--tsmb-size-half);
138+
min-width: 100%;
139+
width: var(--tsmb-size-listbox-width);
140+
max-height: var(--tsmb-size-listbox-max-height);
130141
overflow: auto;
131142
border: var(--tsmb-size-edge) solid var(--tsmb-color-focus90);
143+
border-radius: var(--tsmb-size-radius);
132144
box-shadow: 0 var(--tsmb-size-sm) 20px rgba(0,0,0,0.12);
133145
}
134146

@@ -143,9 +155,11 @@
143155
text-decoration: none;
144156
border-left: var(--tsmb-size-highlight) solid transparent;
145157
}
158+
146159
.tsmb-form:not([data-group=true]) [role=option]:not(:first-child) a {
147160
border-top: var(--tsmb-size-edge) solid var(--tsmb-color-focus90);
148161
}
162+
149163
.tsmb-form[data-group=true] [role=option] a {
150164
margin: 0 var(--tsmb-size-base);
151165
padding: var(--tsmb-size-sm);
@@ -199,33 +213,13 @@
199213
box-shadow: 0 0 10px rgba(0,0,0,0.12);
200214
text-decoration: none;
201215
}
216+
202217
.tsmb-foot::before {
203218
content: 'Search by';
204219
color: var(--tsmb-color-focus50);
205220
}
221+
206222
.tsmb-foot::after {
207223
content: ' Typesense';
208224
color: #0300b0;
209225
}
210-
211-
@media (max-width: 480px) {
212-
.tsmb-form {
213-
width: 100%;
214-
}
215-
216-
.tsmb-form input[type=search] {
217-
border-radius: 0;
218-
}
219-
}
220-
221-
@media (min-width: 768px) {
222-
.tsmb-form [role=listbox] {
223-
border-radius: var(--tsmb-size-radius);
224-
min-width: 500px;
225-
margin-top: var(--tsmb-size-half);
226-
}
227-
228-
.tsmb-form--slash::after {
229-
display: none;
230-
}
231-
}

0 commit comments

Comments
 (0)