import React from 'react'; import Select, { AbstractSelectProps, OptionProps, OptGroupProps } from '../select'; import { Option, OptGroup } from 'rc-select'; import classNames from 'classnames'; export interface SelectedValue { key: string; label: React.ReactNode; } export interface DataSourceItemObject { value: string; text: string; }; export type DataSourceItemType = string | DataSourceItemObject; export interface AutoCompleteProps extends AbstractSelectProps { dataSource: DataSourceItemType[]; defaultValue?: string | Array | SelectedValue | Array; value?: string | Array | SelectedValue | Array; onChange?: (value: string | Array | SelectedValue | Array) => void; onSelect?: (value: string | Array | SelectedValue | Array, option: Object) => any; } export default class AutoComplete extends React.Component { static Option = Option as React.ClassicComponentClass; static OptGroup = OptGroup as React.ClassicComponentClass; static defaultProps = { prefixCls: 'ant-select', transitionName: 'slide-up', optionLabelProp: 'children', choiceTransitionName: 'zoom', showSearch: false, }; static contextTypes = { antLocale: React.PropTypes.object, }; render() { let { size, className = '', notFoundContent, prefixCls, optionLabelProp, dataSource, children, } = this.props; const cls = classNames({ [`${prefixCls}-lg`]: size === 'large', [`${prefixCls}-sm`]: size === 'small', [className]: !!className, [`${prefixCls}-show-search`]: true, }); const options = children || (dataSource ? dataSource.map((item) => { switch (typeof item) { case 'string': return ; case 'object': return ( ); default: throw new Error('AutoComplete[dataSource] only supports type `string[] | Object[]`.'); } }) : []); return ( ); } }