Skip to content

Commit e3f0a2c

Browse files
committed
factor out search to its own component
1 parent fd395ae commit e3f0a2c

File tree

6 files changed

+39
-19
lines changed

6 files changed

+39
-19
lines changed

site/_core/DocsSidebar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
var React = require('react');
1010

11+
var Search = require('./Search');
12+
1113
var DocsSidebar = React.createClass({
1214
render: function() {
1315
return <div className="nav-docs">
14-
<div className="algolia-search-wrapper">
15-
<input id="algolia-doc-search" type="text" placeholder="Search docs..." />
16-
</div>
16+
<Search />
1717
{getCategories(this.props.site).map((category) =>
1818
<div className="nav-docs-section" key={category.name}>
1919
<h3>{category.name}</h3>

site/_core/Search.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
var React = require('react');
10+
11+
var Search = React.createClass({
12+
render: function() {
13+
return <div className="algolia-search-wrapper">
14+
<input id="algolia-doc-search" type="text" placeholder="Search docs..." />
15+
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
16+
<script dangerouslySetInnerHTML={{__html: `
17+
docsearch({
18+
apiKey: 'd103541f3e6041148aade2e746ed4d61',
19+
indexName: 'graphql',
20+
inputSelector: '#algolia-doc-search'
21+
});
22+
`}} />
23+
</div>;
24+
}
25+
});
26+
27+
module.exports = Search;

site/_core/Site.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ var Site = React.createClass({
5050
©2016 Facebook Inc.
5151
</footer>
5252

53-
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
54-
<script dangerouslySetInnerHTML={{__html: `
55-
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
56-
docsearch({
57-
apiKey: 'd103541f3e6041148aade2e746ed4d61',
58-
indexName: 'graphql',
59-
inputSelector: '#algolia-doc-search'
60-
});
61-
`}} />
6253
<script dangerouslySetInnerHTML={{__html: `
6354
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
6455
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

site/_css/algolia.less

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
div.algolia-search-wrapper {
66
display: inline-block;
77
vertical-align: top;
8-
/*margin-left: 15px;*/
98
}
109

1110
.algolia-autocomplete .aa-dropdown-menu {
12-
/*margin-left: -110px;*/
11+
.body-font();
1312
margin-top: -4px;
1413
}
1514

@@ -27,12 +26,12 @@ input#algolia-doc-search {
2726
padding-left: 35px;
2827
margin-top: 9px;
2928
height: 30px;
30-
.body-font(@color: white);
29+
.headline-font(@size: 15px, @color: white);
3130
background-color: #555;
3231
border-radius: 4px;
3332
outline: none;
3433
border: none;
35-
width: 170px;
34+
width: 200px;
3635
}
3736

3837
.algolia-autocomplete {

site/help/index.html.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ var Help = React.createClass({
3333
<p><a href="https://twitter.com/search?q=%23graphql" target="_blank"><strong>#graphql</strong> hash tag on Twitter</a> is used to keep up with the latest GraphQL news.</p>
3434

3535
<p><center><a className="twitter-timeline" data-dnt="true" href="https://twitter.com/hashtag/graphql" data-widget-id="633776128688193537" data-chrome="nofooter noheader transparent">#graphql Tweets</a></center></p>
36+
<script dangerouslySetInnerHTML={{__html: `
37+
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
38+
`}} />
39+
3640
</div>
3741
</section>
3842

site/index.html.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Site = require('./_core/Site');
33
var SiteData = require('./_core/SiteData');
44
var HeaderLinks = require('./_core/HeaderLinks');
55
var Marked = require('./_core/Marked');
6+
var Search = require('./_core/Search');
67

78
var index = React.createClass({
89
render: function() {
@@ -13,9 +14,7 @@ var index = React.createClass({
1314

1415
<header aria-hidden>
1516
<section>
16-
<div className="algolia-search-wrapper">
17-
<input id="algolia-doc-search" type="text" placeholder="Search docs..." />
18-
</div>
17+
<Search />
1918
<HeaderLinks section={this.props.section} />
2019
</section>
2120
</header>

0 commit comments

Comments
 (0)