Skip to content

Commit eba79f4

Browse files
authored
feat: upgrade docusaurus + style a bit (#1993)
1 parent e3bb988 commit eba79f4

File tree

8 files changed

+15557
-303
lines changed

8 files changed

+15557
-303
lines changed

www/package-lock.json

+15,336-143
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"generate-providers": "node ./scripts/generate-providers.js"
1515
},
1616
"dependencies": {
17-
"@docusaurus/core": "2.0.0-alpha.75",
18-
"@docusaurus/preset-classic": "2.0.0-alpha.75",
17+
"@docusaurus/core": "2.0.0-beta.0",
18+
"@docusaurus/preset-classic": "2.0.0-beta.0",
1919
"classnames": "^2.3.1",
2020
"docusaurus-lunr-search": "^2.1.14",
2121
"jose": "^2.0.5",

www/src/css/index.css

+17-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434

3535
html[data-theme="dark"]:root {
3636
--ifm-color-link: #289ef9;
37-
--ifm-footer-background-color: #111;
37+
--ifm-footer-background-color: #000;
3838
--ifm-html-background-color: #242526;
39-
--ifm-background-color: #000000;
39+
--ifm-background-color: #090909;
4040
--ifm-hero-background-color: #111111;
4141
--ifm-navbar-background-color: rgba(0, 0, 0, 0.95);
4242
}
@@ -198,6 +198,21 @@ html[data-theme="dark"] hr {
198198
background-repeat: no-repeat;
199199
}
200200

201+
.navbar__items .react-toggle {
202+
margin-right: 10px;
203+
}
204+
205+
.navbar__search-input:focus {
206+
outline: none;
207+
box-shadow: rgb(255, 255, 255) 0px 0px 0px 0px,
208+
rgba(19, 19, 19, 0.2) 0px 0px 0px 4px, rgba(0, 0, 0, 0) 0px 0px 0px 0px;
209+
transition: box-shadow 350ms ease-in-out;
210+
}
211+
html[data-theme="dark"] .navbar__search-input:focus {
212+
box-shadow: rgb(255, 255, 255) 0px 0px 0px 0px,
213+
rgba(29, 29, 29, 0.5) 0px 0px 0px 4px, rgba(0, 0, 0, 0) 0px 0px 0px 0px;
214+
}
215+
201216
html[data-theme="dark"] .navbar__item.navbar__link[href*="github"]:before {
202217
background-image: url("/img/brand-github-inverted.svg");
203218
}

www/src/theme/SearchBar/algolia.css

+6-6
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
margin-right: -4px;
149149
height: 100%;
150150
vertical-align: middle;
151-
content: '';
151+
content: "";
152152
}
153153

154154
.searchbox__submit:hover,
@@ -237,7 +237,7 @@
237237
.algolia-autocomplete .ds-dropdown-menu:before {
238238
display: block;
239239
position: absolute;
240-
content: '';
240+
content: "";
241241
width: 14px;
242242
height: 14px;
243243
background: #373940;
@@ -308,7 +308,7 @@
308308
cursor: pointer;
309309
}
310310

311-
.algolia-autocomplete .ds-dropdown-menu [class^='ds-dataset-'] {
311+
.algolia-autocomplete .ds-dropdown-menu [class^="ds-dataset-"] {
312312
position: relative;
313313
border-radius: 4px;
314314
overflow: auto;
@@ -369,7 +369,7 @@
369369
}
370370

371371
.algolia-autocomplete .algolia-docsearch-suggestion--content:before {
372-
content: '';
372+
content: "";
373373
position: absolute;
374374
display: block;
375375
top: 0;
@@ -413,7 +413,7 @@
413413
}
414414

415415
.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column:before {
416-
content: '';
416+
content: "";
417417
position: absolute;
418418
display: block;
419419
top: 0;
@@ -484,7 +484,7 @@
484484
color: #222222;
485485
background-color: #ebebeb;
486486
border-radius: 3px;
487-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
487+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
488488
monospace;
489489
}
490490

www/src/theme/SearchBar/index.js

+64-31
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
import React, { useRef, useCallback } from "react";
10-
import classnames from "classnames";
11-
import { useHistory } from "@docusaurus/router";
12-
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
13-
let loaded = false;
9+
import React, { useRef, useCallback, useEffect } from "react"
10+
import classnames from "classnames"
11+
import { useHistory } from "@docusaurus/router"
12+
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"
13+
import "./styles.css"
14+
15+
let loaded = false
1416
const Search = (props) => {
15-
const initialized = useRef(false);
16-
const searchBarRef = useRef(null);
17-
const history = useHistory();
18-
const { siteConfig = {} } = useDocusaurusContext();
19-
const { baseUrl } = siteConfig;
17+
const initialized = useRef(false)
18+
const searchBarRef = useRef(null)
19+
const history = useHistory()
20+
const { siteConfig = {} } = useDocusaurusContext()
21+
const { baseUrl } = siteConfig
2022
const initAlgolia = () => {
2123
if (!initialized.current) {
2224
new window.DocSearch({
@@ -25,25 +27,25 @@ const Search = (props) => {
2527
// Override algolia's default selection event, allowing us to do client-side
2628
// navigation and avoiding a full page refresh.
2729
handleSelected: (_input, _event, suggestion) => {
28-
const url = baseUrl + suggestion.url;
30+
const url = baseUrl + suggestion.url
2931
// Use an anchor tag to parse the absolute url into a relative url
3032
// Alternatively, we can use new URL(suggestion.url) but its not supported in IE
31-
const a = document.createElement("a");
32-
a.href = url;
33+
const a = document.createElement("a")
34+
a.href = url
3335
// Algolia use closest parent element id #__docusaurus when a h1 page title does not have an id
3436
// So, we can safely remove it. See https://github.com/facebook/docusaurus/issues/1828 for more details.
3537

36-
history.push(url);
38+
history.push(url)
3739
},
38-
});
39-
initialized.current = true;
40+
})
41+
initialized.current = true
4042
}
41-
};
43+
}
4244

4345
const getSearchData = () =>
4446
process.env.NODE_ENV === "production"
4547
? fetch(`${baseUrl}search-doc.json`).then((content) => content.json())
46-
: Promise.resolve([]);
48+
: Promise.resolve([])
4749

4850
const loadAlgolia = () => {
4951
if (!loaded) {
@@ -52,26 +54,38 @@ const Search = (props) => {
5254
import("./lib/DocSearch"),
5355
import("./algolia.css"),
5456
]).then(([searchData, { default: DocSearch }]) => {
55-
loaded = true;
56-
window.searchData = searchData;
57-
window.DocSearch = DocSearch;
58-
initAlgolia();
59-
});
57+
loaded = true
58+
window.searchData = searchData
59+
window.DocSearch = DocSearch
60+
initAlgolia()
61+
})
6062
} else {
61-
initAlgolia();
63+
initAlgolia()
6264
}
63-
};
65+
}
6466

6567
const toggleSearchIconClick = useCallback(
6668
(e) => {
6769
if (!searchBarRef.current.contains(e.target)) {
68-
searchBarRef.current.focus();
70+
searchBarRef.current.focus()
6971
}
7072

71-
props.handleSearchBarToggle(!props.isSearchBarExpanded);
73+
props.handleSearchBarToggle &&
74+
props.handleSearchBarToggle(!props.isSearchBarExpanded)
7275
},
7376
[props.isSearchBarExpanded]
74-
);
77+
)
78+
79+
useEffect(() => {
80+
document.addEventListener("keypress", (e) => {
81+
if (document.activeElement === searchBarRef.current) return
82+
if (e.key === "/") {
83+
e.preventDefault()
84+
searchBarRef.current.focus()
85+
}
86+
})
87+
return () => document.removeEventListener("keypress")
88+
}, [])
7589

7690
return (
7791
<div className="navbar__search" key="search-box">
@@ -101,8 +115,27 @@ const Search = (props) => {
101115
onBlur={toggleSearchIconClick}
102116
ref={searchBarRef}
103117
/>
118+
119+
<svg
120+
x="0px"
121+
y="0px"
122+
width="19px"
123+
height="20px"
124+
viewBox="0 0 19 20"
125+
className={classnames("search-icon-keyboard", {
126+
"search-icon-hidden": props.isSearchBarExpanded,
127+
})}
128+
>
129+
<path
130+
fill="none"
131+
stroke="#979A9C"
132+
opacity="0.4"
133+
d="M3.5,0.5h12c1.7,0,3,1.3,3,3v13c0,1.7-1.3,3-3,3h-12c-1.7,0-3-1.3-3-3v-13C0.5,1.8,1.8,0.5,3.5,0.5z"
134+
/>
135+
<path fill="#979a9c" d="M11.8,6L8,15.1H7.1L10.8,6L11.8,6z" />
136+
</svg>
104137
</div>
105-
);
106-
};
138+
)
139+
}
107140

108-
export default Search;
141+
export default Search

0 commit comments

Comments
 (0)