<commit_before>import React, { PropTypes } from 'react';
import uuid from 'uuid';
import classNames from 'classnames';
import Autowhatever from 'react-autowhatever';
import theme from './Typeahead.scss';
import {
	renderItemsContainer,
	renderInputComponent,
	renderSectionTitle,
	renderItem,
} from './Typeahead.component.renderers';
import { Action } from '../Actions';

/**
 * Show suggestions for search bar
 * @example
 *
 * <Typeahead {...props} />
 */
function Typeahead({ onToggle, icon, position, ...rest }) {
	if (onToggle) {
		return (
			<Action
				onClick={onToggle}
				label={icon.title}
				hideLabel
				icon={icon.name}
				bsStyle={icon.bsStyle}
				className={theme['only-icon-cls']}
			/>
		);
	}

	const containerClass = classNames(
		theme['tc-typeahead-container'],
		(position === 'right') && theme.right,
	);

	const autowhateverProps = {
		...rest,
		inputProps: {
			value: rest.value,
			placeholder: rest.placeholder,
			onBlur: rest.onBlur,
			onChange: rest.onChange && (event => rest.onChange(event, { value: event.target.value })),
			debounceMinLength: rest.debounceMinLength,
			debounceTimeout: rest.debounceTimeout,
			icon,
		},
		itemProps: {
			onClick: rest.onSelect,
		},
		renderInputComponent,
		renderItemsContainer: renderItemsContainer(
			rest.items, rest.noResultText, rest.searching, rest.searchingText),
		renderSectionTitle,
		renderItem,
		multiSection: true,
		getSectionItems: section => section.suggestions,
		theme: {
			container: containerClass,
			containerOpen: theme['container-open'],
			highlight: theme['highlight-match'],
			input: theme['typeahead-input'],
			itemFocused: theme['item-focused'],
			itemsContainer: theme['items-container'],
			itemsList: theme.items,
			sectionContainer: theme['section-container'],
		},
		items: rest.items || [],
		renderItemData: { value: rest.value },
	};

	return (
		<Autowhatever {...autowhateverProps} />
	);
}

Typeahead.defaultProps = {
	id: uuid.v4(),
	position: 'left',
	items: null,
	noResultText: 'No result.',
	searching: false,
	searchingText: 'Searching for matches…',
};

Typeahead.propTypes = {
	id: PropTypes.string,
	onToggle: PropTypes.func,
	icon: PropTypes.shape({
		name: PropTypes.string,
		title: PropTypes.string,
		bsStyle: PropTypes.string,
	}),
	position: PropTypes.oneOf(['left', 'right']),
	value: PropTypes.string,
	placeholder: PropTypes.string,
	onBlur: PropTypes.func,
	onChange: PropTypes.func,
	onSelect: PropTypes.func,
	items: PropTypes.arrayOf(
		PropTypes.shape({
			title: PropTypes.string,
			description: PropTypes.string,
			suggestions: PropTypes.arrayOf(
				PropTypes.shape({
					title: PropTypes.string,
					description: PropTypes.string,
				}),
			),
		}),
	),
	noResultText: PropTypes.string,
	searching: PropTypes.bool,
	searchingText: PropTypes.string,
	debounceMinLength: PropTypes.number,
	debounceTimeout: PropTypes.number,
};

export default Typeahead;
<commit_msg>fix(typeahead): be able to add more props (#185)<commit_after>import React, { PropTypes } from 'react';
import uuid from 'uuid';
import classNames from 'classnames';
import Autowhatever from 'react-autowhatever';
import theme from './Typeahead.scss';
import {
	renderItemsContainer,
	renderInputComponent,
	renderSectionTitle,
	renderItem,
} from './Typeahead.component.renderers';
import { Action } from '../Actions';

/**
 * Show suggestions for search bar
 * @example
 *
 * <Typeahead {...props} />
 */
function Typeahead({ onToggle, icon, position, ...rest }) {
	if (onToggle) {
		return (
			<Action
				onClick={onToggle}
				label={icon.title}
				hideLabel
				icon={icon.name}
				bsStyle={icon.bsStyle}
				className={theme['only-icon-cls']}
			/>
		);
	}

	const containerClass = classNames(
		theme['tc-typeahead-container'],
		(position === 'right') && theme.right,
	);

	const autowhateverProps = {
		...rest,
		inputProps: {
			value: rest.value,
			placeholder: rest.placeholder,
			onBlur: rest.onBlur,
			onChange: rest.onChange && (event => rest.onChange(event, { value: event.target.value })),
			onKeyDown: rest.onKeyDown,
			debounceMinLength: rest.debounceMinLength,
			debounceTimeout: rest.debounceTimeout,
			icon,
		},
		itemProps: {
			onClick: rest.onSelect,
		},
		renderInputComponent,
		renderItemsContainer: renderItemsContainer(
			rest.items, rest.noResultText, rest.searching, rest.searchingText),
		renderSectionTitle,
		renderItem,
		multiSection: true,
		getSectionItems: section => section.suggestions,
		theme: {
			...rest.theme,
			container: containerClass,
			containerOpen: theme['container-open'],
			highlight: theme['highlight-match'],
			input: theme['typeahead-input'],
			itemFocused: theme['item-focused'],
			itemsContainer: theme['items-container'],
			itemsList: theme.items,
			sectionContainer: theme['section-container'],
		},
		focusedSectionIndex: rest.focusedSectionIndex,
		focusedItemIndex: rest.focusedItemIndex,
		items: rest.items || [],
		renderItemData: { value: rest.value },
	};

	return (
		<Autowhatever {...autowhateverProps} />
	);
}

Typeahead.defaultProps = {
	id: uuid.v4(),
	position: 'left',
	items: null,
	noResultText: 'No result.',
	searching: false,
	searchingText: 'Searching for matches…',
};

Typeahead.propTypes = {
	id: PropTypes.string,
	onToggle: PropTypes.func,
	icon: PropTypes.shape({
		name: PropTypes.string,
		title: PropTypes.string,
		bsStyle: PropTypes.string,
	}),
	position: PropTypes.oneOf(['left', 'right']),
	value: PropTypes.string,
	placeholder: PropTypes.string,
	onBlur: PropTypes.func,
	onChange: PropTypes.func,
	onSelect: PropTypes.func,
	onKeyDown: PropTypes.func,
	focusedSectionIndex: PropTypes.number,
	focusedItemIndex: PropTypes.number,
	items: PropTypes.arrayOf(
		PropTypes.shape({
			title: PropTypes.string,
			description: PropTypes.string,
			suggestions: PropTypes.arrayOf(
				PropTypes.shape({
					title: PropTypes.string,
					description: PropTypes.string,
				}),
			),
		}),
	),
	noResultText: PropTypes.string,
	searching: PropTypes.bool,
	searchingText: PropTypes.string,
	debounceMinLength: PropTypes.number,
	debounceTimeout: PropTypes.number,
};

export default Typeahead;

{'fraction_non_alphanumeric': 0.13925081433224756, 'fraction_numerical': 0.0008143322475570033, 'mean_word_length': 4.377408056042031, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232274', 'n_tokens_mistral': 2203, 'n_tokens_neox': 1990, 'n_words': 410}