Skip to content

Commit b49c309

Browse files
author
Alban
authored
Merge pull request linode#10 from linode/DLC-146
DLC-146 Mobile updates to API docs Gatsby (WIP)
2 parents 90df461 + 4107893 commit b49c309

File tree

4 files changed

+93
-23
lines changed

4 files changed

+93
-23
lines changed

src/components/2_molecules/search-header.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,57 @@ import React from "react";
22
import { graphql, StaticQuery } from "gatsby";
33
import Search from "./search";
44

5-
const SearchHeader = () => (
6-
<StaticQuery
7-
query={graphql`
8-
query SearchIndexQuery {
9-
siteSearchIndex {
10-
index
11-
}
12-
}
13-
`}
14-
render={data => (
15-
<header className="md:mb-4">
16-
<Search searchIndex={data.siteSearchIndex.index} />
17-
</header>
18-
)}
19-
/>
20-
);
5+
class SearchHeader extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
searchIsFixed: false
10+
};
11+
this.handleScroll = this.handleScroll.bind(this);
12+
}
13+
14+
componentDidMount() {
15+
window.addEventListener("scroll", this.handleScroll);
16+
}
17+
18+
componentWillUnmount() {
19+
window.removeEventListener("scroll", this.handleScroll);
20+
}
21+
22+
handleScroll() {
23+
if (window.innerWidth >= 640) {
24+
this.setState({ searchIsFixed: false });
25+
} else if (window.scrollY <= 30 && this.state.searchIsFixed === true) {
26+
this.setState({ searchIsFixed: false });
27+
} else if (window.scrollY > 30 && this.state.searchIsFixed !== true) {
28+
this.setState({ searchIsFixed: true });
29+
}
30+
}
31+
32+
render() {
33+
const { searchIsFixed } = this.state;
34+
35+
return (
36+
<StaticQuery
37+
query={graphql`
38+
query SearchIndexQuery {
39+
siteSearchIndex {
40+
index
41+
}
42+
}
43+
`}
44+
render={data => (
45+
<header
46+
className={`md:mb-4 search-header ${
47+
searchIsFixed ? "search-header--fixed" : ""
48+
}`}
49+
>
50+
<Search searchIndex={data.siteSearchIndex.index} />
51+
</header>
52+
)}
53+
/>
54+
);
55+
}
56+
}
2157

2258
export default SearchHeader;

src/components/2_molecules/search.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@ export default class Search extends Component {
2323
onChange={this.search}
2424
placeholder="Search"
2525
/>
26-
<ul className="p-0">
26+
<ul className="p-0 search-results-list">
2727
{this.state.results.map((n, i) => {
2828
const { query } = this.state;
2929
return (
30-
<div key={i}>
30+
<React.Fragment key={i}>
3131
{n.getSummary &&
3232
n.getSummary.toLowerCase().includes(query.toLowerCase()) && (
33-
<li className="list-reset">
33+
<li className="list-reset p-1 px-4 md:p-0 md:px-0">
3434
<Link to={`/api/v4/${_.kebabCase(n.name)}`}>
3535
{n.getSummary}
3636
</Link>
3737
</li>
3838
)}
3939
{n.postSummary &&
4040
n.postSummary.toLowerCase().includes(query.toLowerCase()) && (
41-
<li className="list-reset">
41+
<li className="list-reset p-1 px-4 md:p-0 md:px-0">
4242
<Link to={`/api/v4/${_.kebabCase(n.name)}/#post`}>
4343
{n.postSummary}
4444
</Link>
4545
</li>
4646
)}
4747
{n.putSummary &&
4848
n.putSummary.toLowerCase().includes(query.toLowerCase()) && (
49-
<li className="list-reset">
49+
<li className="list-reset p-1 px-4 md:p-0 md:px-0">
5050
<Link to={`/api/v4/${_.kebabCase(n.name)}/#put`}>
5151
{n.putSummary}
5252
</Link>
@@ -56,13 +56,13 @@ export default class Search extends Component {
5656
n.deleteSummary
5757
.toLowerCase()
5858
.includes(query.toLowerCase()) && (
59-
<li className="list-reset">
59+
<li className="list-reset p-1 px-4 md:p-0 md:px-0">
6060
<Link to={`/api/v4/${_.kebabCase(n.name)}/#delete`}>
6161
{n.deleteSummary}
6262
</Link>
6363
</li>
6464
)}
65-
</div>
65+
</React.Fragment>
6666
);
6767
})}
6868
{this.state.query && this.state.results.length === 0 && (

src/css/components/4_pages/api-page.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@
105105
@apply border-grey-light;
106106
}
107107

108+
.search-header {
109+
position: relative;
110+
top: 0;
111+
width: auto;
112+
transition: all 0.15s cubic-bezier(0, 0, 0.2, 1);
113+
}
114+
115+
.search-header.search-header--fixed {
116+
position: fixed;
117+
top: 65px;
118+
left: 0;
119+
width: 100%;
120+
z-index: 1;
121+
padding: 1rem;
122+
background-color: #fff;
123+
}
124+
125+
.search-results-list {
126+
background-color: #fff;
127+
}
128+
129+
.search-header--fixed .search-results-list {
130+
max-height: 250px;
131+
height: 100%;
132+
overflow-y: scroll;
133+
box-shadow: 0px 5px 8px -2px rgba(0, 0, 0, 0.5);
134+
}
135+
108136
@screen md {
109137
.api-content-wrapper {
110138
margin-left: 300px;
@@ -133,4 +161,9 @@
133161
width: 300px;
134162
padding: 2rem;
135163
}
164+
165+
.search-results-list {
166+
box-shadow: none;
167+
background-color: none;
168+
}
136169
}

tailwind.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ config.colors["ThemeTagGrey"] = "#e1e8eC";
66
config.colors["ThemeTagGreyLight"] = "#fbfbfb";
77
config.colors["BaseGreenLight"] = "#f1f9f5";
88
config.colors["BaseRedLight"] = "#fdF1ef";
9+
config.colors["white"] = "#fff";
910

1011
config.borderWidths["5"] = "5px";
1112

0 commit comments

Comments
 (0)