Skip to content

Commit 70a46c2

Browse files
committed
Auto merge of #4026 - Turbo87:hero-header, r=locks
Header: Implement `@hero` mode for the `index` route <img width="1210" alt="Bildschirmfoto 2021-10-18 um 22 56 48" src="https://user-images.githubusercontent.com/141300/137805754-afcdda3a-13ef-4c70-8a3d-f85cc308acdc.png"> <img width="325" alt="Bildschirmfoto 2021-10-18 um 22 57 10" src="https://user-images.githubusercontent.com/141300/137805759-2592bb20-d2e3-488e-9759-73dc5957c0e5.png">
2 parents fd73d15 + 06aee0c commit 70a46c2

File tree

10 files changed

+180
-99
lines changed

10 files changed

+180
-99
lines changed

app/components/header.hbs

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,17 @@
1-
<header local-class="header">
1+
<header local-class="header {{if @hero "hero"}}">
22
<div local-class="header-inner">
33
<LinkTo @route="index" local-class="index-link">
44
<img src="/assets/Cargo-Logo-Small.png" role="presentation" alt="" local-class="logo">
55
<h1>crates.io</h1>
66
</LinkTo>
77

8-
<form local-class="search-form" action='/search' role="search" {{on "submit" (prevent-default this.search)}} data-test-search-form>
9-
{{! template-lint-disable require-input-label}}
10-
{{! disabled due to https://github.com/ember-template-lint/ember-template-lint/issues/2141 }}
11-
<input
12-
type="text"
13-
local-class="search-input-lg"
14-
name="q"
15-
id="cargo-desktop-search"
16-
placeholder="Click or press 'S' to search..."
17-
value={{this.header.searchValue}}
18-
oninput={{this.updateSearchValue}}
19-
autocorrect="off"
20-
autocapitalize="off"
21-
autofocus="autofocus"
22-
spellcheck="false"
23-
required
24-
aria-label="Search"
25-
data-test-search-input
26-
>
8+
<div local-class="search-form">
9+
<h1 local-class="hero-title">
10+
The Rust community&rsquo;s crate registry
11+
</h1>
2712

28-
{{! Second input fields for narrow screens because CSS does not allow us to change the placeholder }}
29-
<input
30-
type="text"
31-
local-class="search-input-sm"
32-
name="q"
33-
placeholder="Search"
34-
value={{this.header.searchValue}}
35-
oninput={{this.updateSearchValue}}
36-
autocorrect="off"
37-
required
38-
aria-label="Search"
39-
>
40-
41-
{{! Hidden submit button to enable enter-to-submit behavior for form with multiple inputs }}
42-
<button type="submit" local-class="submit-button">Submit</button>
43-
44-
{{on-key 's' (focus '#cargo-desktop-search')}}
45-
{{on-key 'S' (focus '#cargo-desktop-search')}}
46-
{{on-key 'shift+s' (focus '#cargo-desktop-search')}}
47-
</form>
13+
<SearchForm @size={{if @hero "big"}} />
14+
</div>
4815

4916
<nav local-class='nav'>
5017
<LinkTo @route="crates" @query={{hash letter=null page=1}} data-test-all-crates-link>

app/components/header.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
import { action } from '@ember/object';
21
import { inject as service } from '@ember/service';
32
import Component from '@glimmer/component';
43

54
export default class Header extends Component {
6-
@service header;
7-
@service router;
85
@service session;
9-
10-
@action updateSearchValue(event) {
11-
let { value } = event.target;
12-
this.header.searchValue = value;
13-
}
14-
15-
@action search() {
16-
this.router.transitionTo('search', {
17-
queryParams: {
18-
q: this.header.searchValue,
19-
page: 1,
20-
},
21-
});
22-
}
236
}

app/components/header.module.css

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@
3232
"search search" auto /
3333
auto 1fr;
3434
}
35+
36+
.hero & {
37+
grid-template:
38+
"logo nav" auto
39+
"search search" auto /
40+
auto 1fr;
41+
42+
@media only screen and (max-width: 900px) {
43+
grid-template:
44+
"logo menu" auto
45+
"search search" auto /
46+
auto 1fr;
47+
}
48+
}
3549
}
3650

3751
.index-link {
@@ -54,55 +68,40 @@
5468

5569
.search-form {
5670
grid-area: search;
57-
display: flex;
58-
}
59-
60-
.search-input {
61-
font-size: 90%;
62-
border: none;
63-
color: black;
64-
width: 100%;
65-
padding: 5px 5px 5px 25px;
66-
background-color: white;
67-
background-image: url('/assets/search.png');
68-
background-repeat: no-repeat;
69-
background-position: 6px 6px;
70-
background-size: 14px 15px;
71-
border-radius: 15px;
72-
box-shadow: none;
73-
transition: box-shadow 150ms;
71+
padding: 0 16px;
7472

75-
&:focus {
76-
outline: none;
77-
box-shadow: 0 0 0 4px var(--yellow500);
73+
@media only screen and (max-width: 820px) {
74+
padding: 10px 0;
7875
}
79-
}
8076

81-
.search-input-lg {
82-
composes: search-input;
83-
margin-left: 16px;
84-
margin-right: 16px;
77+
.hero & {
78+
justify-self: center;
79+
padding: 40px 0 60px;
8580

86-
@media only screen and (max-width: 820px) {
87-
display: none;
81+
@media only screen and (max-width: 450px) {
82+
padding: 40px 0 30px;
83+
}
8884
}
8985
}
9086

91-
.search-input-sm {
92-
composes: search-input;
87+
.hero-title {
9388
display: none;
94-
margin: 10px 0;
89+
margin: 0 0 20px;
90+
font-size: 45px;
91+
color: #dfffdb;
92+
text-align: center;
93+
94+
.hero & {
95+
display: block;
96+
}
9597

9698
@media only screen and (max-width: 820px) {
97-
display: unset;
99+
font-size: 30px;
98100
}
99-
}
100101

101-
.submit-button {
102-
position: absolute;
103-
visibility: hidden;
104-
width: 0;
105-
height: 0;
102+
@media only screen and (max-width: 550px) {
103+
font-size: 24px;
104+
}
106105
}
107106

108107
.sep {
@@ -119,7 +118,7 @@
119118
grid-area: nav;
120119
display: flex;
121120
align-items: center;
122-
text-align: right;
121+
justify-self: end;
123122

124123
@media only screen and (max-width: 900px) {
125124
display: none;
@@ -128,7 +127,7 @@
128127

129128
.menu {
130129
grid-area: menu;
131-
text-align: right;
130+
justify-self: end;
132131
display: none;
133132

134133
@media only screen and (max-width: 900px) {

app/components/search-form.hbs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<form
2+
local-class="form {{if (eq @size "big") "size-big"}}"
3+
action="/search"
4+
role="search"
5+
data-test-search-form
6+
...attributes
7+
{{on "submit" (prevent-default this.search)}}
8+
>
9+
{{! template-lint-disable require-input-label}}
10+
{{! disabled due to https://github.com/ember-template-lint/ember-template-lint/issues/2141 }}
11+
<input
12+
type="text"
13+
local-class="input-lg"
14+
name="q"
15+
id="cargo-desktop-search"
16+
placeholder="Click or press 'S' to search..."
17+
value={{this.header.searchValue}}
18+
oninput={{this.updateSearchValue}}
19+
autocorrect="off"
20+
autocapitalize="off"
21+
autofocus="autofocus"
22+
spellcheck="false"
23+
required
24+
aria-label="Search"
25+
data-test-search-input
26+
>
27+
28+
{{! Second input fields for narrow screens because CSS does not allow us to change the placeholder }}
29+
<input
30+
type="text"
31+
local-class="input-sm"
32+
name="q"
33+
placeholder="Search"
34+
value={{this.header.searchValue}}
35+
oninput={{this.updateSearchValue}}
36+
autocorrect="off"
37+
required
38+
aria-label="Search"
39+
>
40+
41+
{{! Hidden submit button to enable enter-to-submit behavior for form with multiple inputs }}
42+
<button type="submit" local-class="submit-button">Submit</button>
43+
44+
{{on-key 's' (focus '#cargo-desktop-search')}}
45+
{{on-key 'S' (focus '#cargo-desktop-search')}}
46+
{{on-key 'shift+s' (focus '#cargo-desktop-search')}}
47+
</form>

app/components/search-form.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { action } from '@ember/object';
2+
import { inject as service } from '@ember/service';
3+
import Component from '@glimmer/component';
4+
5+
export default class Header extends Component {
6+
@service header;
7+
@service router;
8+
9+
@action updateSearchValue(event) {
10+
let { value } = event.target;
11+
this.header.searchValue = value;
12+
}
13+
14+
@action search() {
15+
this.router.transitionTo('search', {
16+
queryParams: {
17+
q: this.header.searchValue,
18+
page: 1,
19+
},
20+
});
21+
}
22+
}

app/components/search-form.module.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.form {
2+
display: flex;
3+
}
4+
5+
.input {
6+
font-size: 90%;
7+
border: none;
8+
color: black;
9+
width: 100%;
10+
padding: 5px 5px 5px 25px;
11+
background-color: white;
12+
background-image: url('/assets/search.png');
13+
background-repeat: no-repeat;
14+
background-position: 6px 6px;
15+
background-size: 14px 15px;
16+
border-radius: 15px;
17+
box-shadow: none;
18+
transition: box-shadow 150ms;
19+
20+
.size-big & {
21+
font-size: 125%;
22+
padding: 5px 5px 5px 35px;
23+
background-position: 10px 7px;
24+
background-size: 20px 21px;
25+
}
26+
27+
&:focus {
28+
outline: none;
29+
box-shadow: 0 0 0 4px var(--yellow500);
30+
}
31+
}
32+
33+
.input-lg {
34+
composes: input;
35+
36+
@media only screen and (max-width: 820px) {
37+
display: none;
38+
}
39+
}
40+
41+
.input-sm {
42+
composes: input;
43+
display: none;
44+
45+
@media only screen and (max-width: 820px) {
46+
display: unset;
47+
}
48+
}
49+
50+
.submit-button {
51+
position: absolute;
52+
visibility: hidden;
53+
width: 0;
54+
height: 0;
55+
}

app/controllers/application.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ import { inject as service } from '@ember/service';
44
export default class ApplicationController extends Controller {
55
@service design;
66
@service progress;
7+
@service router;
8+
9+
get isIndex() {
10+
return this.router.currentRouteName === 'index';
11+
}
712
}

app/styles/index.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
.title-header {
22
text-align: center;
33
border-bottom: 5px solid var(--gray-border);
4+
margin-top: 25px;
45
padding-bottom: 40px;
56

7+
@media only screen and (max-width: 570px) {
8+
margin-top: 0;
9+
}
10+
611
h1 {
712
font-size: 50px;
813
@media only screen and (max-width: 370px) {

app/templates/application.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ProgressBar/>
66
<NotificationContainer @position="top-right"/>
77

8-
<Header/>
8+
<Header @hero={{this.isIndex}} />
99

1010
<main local-class="main">
1111
<div local-class="inner-main">

app/templates/index.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<div local-class='title-header'>
2-
<h1>The Rust community&rsquo;s crate registry</h1>
3-
42
<div local-class='links'>
53
<a href="https://doc.rust-lang.org/cargo/getting-started/installation.html" local-class="hero-button" data-test-install-cargo-link>
64
{{svg-jar "download-arrow" local-class="icon"}}

0 commit comments

Comments
 (0)