Skip to content

Commit f17c7a2

Browse files
authored
Update search to use rem units where possible (#22970)
* Update search to use rem units where possible * Use more primer classes * Move more search to primer classes
1 parent 347bdbf commit f17c7a2

3 files changed

Lines changed: 36 additions & 47 deletions

File tree

components/Search.module.scss

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,47 @@
1+
/* TODO remove mark styling if https://github.com/primer/css/pull/1756 ships */
12
.resultsContainer mark {
23
background: none;
34
color: inherit;
45
}
56

6-
.searchResultContent {
7-
max-height: 4rem;
8-
}
9-
107
.searchResultContent mark {
118
color: var(--color-fg-default);
129
background-color: var(--color-attention-subtle);
1310
}
11+
/* end TODO */
1412

15-
.searchResultTitle em {
16-
font-style: normal;
17-
text-decoration: underline;
13+
.searchResultContent {
14+
max-height: 4rem;
1815
}
1916

2017
.resultsContainerHeader {
21-
display: none;
22-
position: absolute;
23-
top: 0;
24-
right: 0;
2518
width: 0;
26-
border-radius: 0 0 0 3px;
27-
background: var(--color-canvas-default);
28-
box-shadow: 0 1px 15px rgba(0, 0, 0, 0.15);
19+
border-radius: 0 0 0 4px; // primer rounded-1
2920
transition: width 0.3s ease-in-out;
30-
padding-top: 64px;
31-
}
32-
33-
.resultsContainerOpen {
34-
display: block;
3521
}
3622

3723
.resultsContainerOpen.resultsContainerHeader {
3824
width: 60vw;
39-
max-width: 760px;
25+
max-width: 48rem;
4026
}
4127

4228
.searchInput {
4329
transition: width 0.3s ease-in-out;
4430
}
4531

4632
.searchInputHeader {
47-
max-width: 690px;
48-
width: 256px;
49-
}
50-
51-
.searchInputExpanded {
52-
width: 53vw;
53-
position: absolute;
54-
right: 0;
55-
top: 0;
33+
width: 16rem;
5634
}
5735

5836
.headerSearchOpen {
5937
background: var(--color-primer-canvas-backdrop);
60-
position: fixed;
61-
top: 0;
62-
right: 0;
63-
bottom: 0;
64-
left: 0;
65-
display: block;
38+
}
39+
40+
.searchInputExpanded {
41+
width: 54vw;
42+
max-width: 43rem;
6643
}
6744

6845
.headerSearchResults {
69-
overflow-y: auto;
7046
max-height: 80vh;
7147
}

components/Search.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ export function Search({
170170
id="search-results-container"
171171
className={cx(
172172
'z-1 pb-5 px-3',
173-
isHeaderSearch && 'pt-9',
173+
isHeaderSearch &&
174+
'pt-9 color-bg-default color-shadow-medium position-absolute top-0 right-0',
174175
styles.resultsContainer,
175176
isHeaderSearch && styles.resultsContainerHeader,
177+
query ? 'd-block' : 'd-none',
176178
query && styles.resultsContainerOpen
177179
)}
178180
>
@@ -189,7 +191,13 @@ export function Search({
189191
</div>
190192
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
191193
<div
192-
className={cx('-z-1', isHeaderSearch && query ? styles.headerSearchOpen : 'd-none')}
194+
className={cx(
195+
'-z-1',
196+
isHeaderSearch && query
197+
? 'position-fixed top-0 right-0 bottom-0 left-0 d-block'
198+
: 'd-none',
199+
isHeaderSearch && query && styles.headerSearchOpen
200+
)}
193201
onClick={closeSearch}
194202
/>
195203
</>
@@ -210,7 +218,8 @@ export function Search({
210218
variant === 'expanded' && 'py-3',
211219
isHeaderSearch && styles.searchInputHeader,
212220
!isHeaderSearch && 'width-full',
213-
isHeaderSearch && query && styles.searchInputExpanded
221+
isHeaderSearch && query && styles.searchInputExpanded,
222+
isHeaderSearch && query && 'position-absolute top-0 right-0'
214223
)}
215224
style={{
216225
background: `var(--color-canvas-default) url("/assets/images/octicons/search-${iconSize}.svg") no-repeat ${
@@ -325,7 +334,11 @@ function ShowSearchResults({
325334
const ActionListResults = (
326335
<div
327336
data-testid="search-results"
328-
className={cx('mt-3', isHeaderSearch && styles.headerSearchResults)}
337+
className={cx(
338+
'mt-3',
339+
isHeaderSearch && styles.headerSearchResults,
340+
isHeaderSearch && 'overflow-auto'
341+
)}
329342
>
330343
<div className="my-4">
331344
<p className="mx-4">
@@ -372,7 +385,7 @@ function ShowSearchResults({
372385
</small>
373386
)}
374387
<div
375-
className={cx(styles.searchResultTitle, 'mt-2 d-block f4 text-semibold')}
388+
className={cx('mt-2 d-block f4 text-semibold')}
376389
dangerouslySetInnerHTML={{
377390
__html: title,
378391
}}

pages/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,23 @@ function LandingPage(props: LandingPageProps) {
9191
return (
9292
<div>
9393
{/* <!-- Hero --> */}
94-
<section id="landing" className="color-bg-subtle">
94+
<section id="landing" className="color-bg-subtle p-6">
9595
{/* eslint-disable-next-line jsx-a11y/no-autofocus */}
9696
<Search iconSize={24} variant="expanded">
9797
{({ SearchInput, SearchResults }) => {
9898
return (
99-
<div className="container-xl px-3 px-md-6 pb-6 pb-lg-0">
100-
<div className="gutter gutter-xl-spacious pt-6 pt-lg-0 d-lg-flex flex-row-reverse flex-items-center">
99+
<div className="container-xl">
100+
<div className="gutter gutter-xl-spacious d-lg-flex flex-row-reverse flex-items-center">
101101
<div className="col-lg-7">
102102
<OctocatHeader />
103103
</div>
104-
<div className="col-lg-5 mt-6">
105-
<h1 className="text-semibold mb-3">{t('search:need_help')}</h1>
104+
<div className="col-lg-5">
105+
<h1 className="text-semibold">{t('search:need_help')}</h1>
106106
{SearchInput}
107107
</div>
108108
</div>
109109

110-
<div className="mt-3">{SearchResults}</div>
110+
<div>{SearchResults}</div>
111111
</div>
112112
)
113113
}}

0 commit comments

Comments
 (0)