Skip to content

Commit

Permalink
feat(searchBox): add poweredBy option, disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerska committed Sep 22, 2015
1 parent 5ebfe75 commit c9da165
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ search.addWidget(
container: '#search-box',
placeholder: 'Search for products',
// cssClass
// poweredBy: boolean
})
);
```
Expand Down
Binary file added components/PoweredBy/algolia_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions components/PoweredBy/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.as-powered-by {
text-align: right;
line-height: 18px;
font-size: 12px;
}

.as-powered-by--image {
height: 16px;
margin-bottom: 2px;
}
32 changes: 32 additions & 0 deletions components/PoweredBy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var React = require('react');
var bem = require('../BemHelper')('as-powered-by');
var logo = require('url?limit=10000!./algolia_logo.png');

require('style?prepend!raw!./index.css');

class PoweredBy extends React.Component {
render() {
var poweredByDisplay = (this.props.display === true) ? 'block' : 'none';

return (
<div
className={bem()}
style={{display: poweredByDisplay}}
>
Powered by
<a href="https://www.algolia.com/">
<img
className={bem('image')}
src={logo}
/>
</a>
</div>
);
}
}

PoweredBy.propTypes = {
display: React.PropTypes.bool
};

module.exports = PoweredBy;
23 changes: 14 additions & 9 deletions components/SearchBox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var React = require('react');
var PoweredBy = require('./PoweredBy');
var bem = require('./BemHelper')('as-search-box');
var cx = require('classnames');

Expand All @@ -12,15 +13,18 @@ class SearchBox {
var classNames = cx(bem('input'), this.props.inputClass);

return (
<input type="text"
placeholder={this.props.placeholder}
name="algolia-query"
className={classNames}
autoComplete="off"
autoFocus="autofocus"
onChange={this.handleChange.bind(this)}
role="textbox"
/>
<div>
<input type="text"
placeholder={this.props.placeholder}
name="algolia-query"
className={classNames}
autoComplete="off"
autoFocus="autofocus"
onChange={this.handleChange.bind(this)}
role="textbox"
/>
<PoweredBy display={this.props.poweredBy} />
</div>
);
}
}
Expand All @@ -31,6 +35,7 @@ SearchBox.propTypes = {
React.PropTypes.string,
React.PropTypes.array
]),
poweredBy: React.PropTypes.bool,
setQuery: React.PropTypes.func,
search: React.PropTypes.func
};
Expand Down
3 changes: 2 additions & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-box',
placeholder: 'Search for products',
cssClass: 'form-control'
cssClass: 'form-control',
poweredBy: true
})
);

Expand Down
62 changes: 44 additions & 18 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"tap-spec": "4.1.0",
"tape": "4.2.0",
"uglifyjs": "2.4.10",
"url-loader": "^0.5.6",
"webpack": "1.12.2",
"webpack-dev-server": "1.11.0"
},
Expand Down
1 change: 1 addition & 0 deletions widgets/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function searchbox(params) {
search={helper.search.bind(helper)}
placeholder={params.placeholder}
inputClass={params.cssClass}
poweredBy={params.poweredBy}
/>,
container
);
Expand Down

0 comments on commit c9da165

Please sign in to comment.