Skip to content

Commit

Permalink
SearchBar: support for actionProps and uiProps
Browse files Browse the repository at this point in the history
  • Loading branch information
topless committed Oct 12, 2020
1 parent 52daccd commit b41faf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 0 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export default {
sourcemap: true,
},
],
context: 'null',
moduleContext: 'null',
plugins: [
peerDepsExternal(),
postcss({
Expand Down
14 changes: 13 additions & 1 deletion src/lib/components/SearchBar/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ class SearchBar extends Component {

render() {
const {
actionProps,
autofocus,
executeSearch,
onBtnSearchClick,
onInputChange,
onKeyPress,
overridableId,
placeholder,
uiProps,
} = this.props;
return (
<Element
actionProps={actionProps}
autofocus={autofocus}
executeSearch={executeSearch || this.executeSearch}
onBtnSearchClick={onBtnSearchClick || this.onBtnSearchClick}
Expand All @@ -61,12 +64,14 @@ class SearchBar extends Component {
overridableId={overridableId}
placeholder={placeholder}
queryString={this.state.currentValue}
uiProps={uiProps}
/>
);
}
}

SearchBar.propTypes = {
actionProps: PropTypes.object,
autofocus: PropTypes.bool,
executeSearch: PropTypes.func,
onBtnSearchClick: PropTypes.func,
Expand All @@ -76,17 +81,20 @@ SearchBar.propTypes = {
placeholder: PropTypes.string,
queryString: PropTypes.string,
updateQueryString: PropTypes.func.isRequired,
uiProps: PropTypes.object,
};

SearchBar.defaultProps = {
autofocus: true,
actionProps: null,
autofocus: false,
executeSearch: null,
onBtnSearchClick: null,
onInputChange: null,
onKeyPress: null,
overridableId: '',
placeholder: '',
queryString: '',
uiProps: null,
};

// NOTE: Adding the key prop, will recreate the SearchBar in order to update
Expand All @@ -106,12 +114,14 @@ class Element extends Component {

render() {
const {
actionProps,
onBtnSearchClick,
onInputChange,
onKeyPress,
overridableId,
placeholder,
queryString,
uiProps,
} = this.props;

return (
Expand All @@ -123,8 +133,10 @@ class Element extends Component {
action={{
content: 'Search',
onClick: onBtnSearchClick,
...actionProps,
}}
fluid
{...uiProps}
placeholder={placeholder || 'Type something'}
onChange={(event, { value }) => {
onInputChange(value);
Expand Down

0 comments on commit b41faf5

Please sign in to comment.