Skip to content

Commit

Permalink
Remove renderItemsContainerData
Browse files Browse the repository at this point in the history
  • Loading branch information
moroshko committed Feb 21, 2017
1 parent e9cd66f commit 1b35b7b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
70 changes: 39 additions & 31 deletions demo/src/components/App/components/Example11/Example11.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styles from './Example11.less';

import React, { PropTypes } from 'react';
import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';
import { updateInputValue } from '../../redux';
import Autowhatever from 'Autowhatever';
Expand Down Expand Up @@ -62,13 +62,13 @@ const theme = {
const exampleId = '11';
const file = `demo/src/components/App/components/Example${exampleId}/Example${exampleId}.js`;

const renderItemsContainer = ({ children, containerProps, data }) => (
const renderItemsContainer = ({ children, containerProps, query }) => (
<div {...containerProps}>
{children}
<div className={styles.footer}>
{
data.query
? <span>Press Enter to search <strong>{data.query}</strong></span>
query
? <span>Press Enter to search <strong>{query}</strong></span>
: <span>Powered by react-autowhatever</span>
}
</div>
Expand Down Expand Up @@ -101,36 +101,44 @@ function renderItem(item) {
);
}

const Example = props => {
const { value, onChange } = props;
const inputProps = {
placeholder: 'Custom items container',
value,
onChange
class Example extends Component {
static propTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired
};
const renderItemsContainerData = {
query: value.trim()

renderItemsContainer = ({ children, containerProps }) => {
const { value } = this.props;

return renderItemsContainer({
children,
containerProps,
query: value.trim()
});
};

return (
<div>
<Autowhatever
id={exampleId}
renderItemsContainer={renderItemsContainer}
renderItemsContainerData={renderItemsContainerData}
items={items}
renderItem={renderItem}
inputProps={inputProps}
theme={theme}
/>
<SourceCodeLink file={file} />
</div>
);
};
render() {
const { value, onChange } = this.props;
const inputProps = {
placeholder: 'Custom items container',
value,
onChange
};

Example.propTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired
};
return (
<div>
<Autowhatever
id={exampleId}
renderItemsContainer={this.renderItemsContainer}
items={items}
renderItem={renderItem}
inputProps={inputProps}
theme={theme}
/>
<SourceCodeLink file={file} />
</div>
);
}
}

export default connect(mapStateToProps, mapDispatchToProps)(Example);
7 changes: 2 additions & 5 deletions src/Autowhatever.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default class Autowhatever extends Component {
multiSection: PropTypes.bool, // Indicates whether a multi section layout should be rendered.
renderInputComponent: PropTypes.func, // When specified, it is used to render the input element.
renderItemsContainer: PropTypes.func, // Renders the items container.
renderItemsContainerData: PropTypes.object, // Arbitrary data that will be passed to renderItemsContainer()
items: PropTypes.array.isRequired, // Array of items or sections to render.
renderItem: PropTypes.func, // This function renders a single item.
renderItemData: PropTypes.object, // Arbitrary data that will be passed to renderItem()
Expand All @@ -56,7 +55,6 @@ export default class Autowhatever extends Component {
multiSection: false,
renderInputComponent: defaultRenderInputComponent,
renderItemsContainer: defaultRenderItemsContainer,
renderItemsContainerData: emptyObject,
shouldRenderSection: alwaysTrue,
renderItem: () => {
throw new Error('`renderItem` must be provided');
Expand Down Expand Up @@ -305,7 +303,7 @@ export default class Autowhatever extends Component {
const { theme } = this;
const {
id, multiSection, renderInputComponent, renderItemsContainer,
renderItemsContainerData, highlightedSectionIndex, highlightedItemIndex
highlightedSectionIndex, highlightedItemIndex
} = this.props;
const { isInputFocused } = this.state;
const renderedItems = multiSection ? this.renderSections() : this.renderItems();
Expand Down Expand Up @@ -349,8 +347,7 @@ export default class Autowhatever extends Component {
isOpen && 'itemsContainerOpen'
),
ref: this.storeItemsContainerReference
},
data: renderItemsContainerData
}
});

return (
Expand Down
3 changes: 1 addition & 2 deletions test/render-items-container/Autowhatever.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ describe('Autowhatever with renderItemsContainer', () => {
expect(renderItemsContainer).to.have.been.calledOnce;
expect(renderItemsContainer).to.be.calledWith({
children: childrenMatcher,
containerProps: containerPropsMatcher,
data: { foo: 'bar' }
containerProps: containerPropsMatcher
});
});
});
1 change: 0 additions & 1 deletion test/render-items-container/AutowhateverApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default class AutowhateverApp extends Component {
<Autowhatever
id="my-id"
renderItemsContainer={renderItemsContainer}
renderItemsContainerData={{ foo: 'bar' }}
items={items}
renderItem={renderItem}
inputProps={inputProps}
Expand Down

0 comments on commit 1b35b7b

Please sign in to comment.